18 #include "libmesh/getpot.h" 
   22 #include "libmesh/dirichlet_boundaries.h" 
   23 #include "libmesh/dof_map.h" 
   24 #include "libmesh/fe_base.h" 
   25 #include "libmesh/fe_interface.h" 
   26 #include "libmesh/fem_context.h" 
   27 #include "libmesh/mesh.h" 
   28 #include "libmesh/quadrature.h" 
   29 #include "libmesh/string_to_enum.h" 
   30 #include "libmesh/zero_function.h" 
   31 #include "libmesh/elem.h" 
   32 #include "libmesh/auto_ptr.h"  
   46     : _u_var(u_var), _v_var(v_var), _w_var(w_var), _Re(Reynolds)
 
   47   { this->_initialized = 
true; }
 
   50   { libmesh_not_implemented(); }
 
   52   virtual void operator() (
const Point & p,
 
   57     const Real x=p(0), y=p(1), z=p(2);
 
   58     output(_u_var) = (_Re+1)*(y*y + z*z);
 
   59     output(_v_var) = (_Re+1)*(x*x + z*z);
 
   60     output(_w_var) = (_Re+1)*(x*x + y*y);
 
   63   virtual std::unique_ptr<FunctionBase<Number>> 
clone()
 const 
   64   { 
return libmesh_make_unique<BdyFunction>(_u_var, _v_var, _w_var, _Re); }
 
   67   const unsigned int _u_var, _v_var, 
_w_var;
 
   74   const unsigned int dim = this->get_mesh().mesh_dimension();
 
   78   GetPot infile(
"navier.in");
 
   79   Reynolds = infile(
"Reynolds", 1.);
 
   80   application = infile(
"application", 0);
 
   81   unsigned int pressure_p = infile(
"pressure_p", 1);
 
   82   std::string fe_family = infile(
"fe_family", std::string(
"LAGRANGE"));
 
   89   FEFamily fefamily = Utility::string_to_enum<FEFamily>(fe_family);
 
   93   u_var = this->add_variable (
"u", static_cast<Order>(pressure_p+1),
 
   95   v_var = this->add_variable (
"v",
 
   96                               static_cast<Order>(pressure_p+1),
 
  100     w_var = this->add_variable (
"w",
 
  101                                 static_cast<Order>(pressure_p+1),
 
  109   p_var = this->add_variable (
"p",
 
  110                               static_cast<Order>(pressure_p),
 
  115   this->time_evolving(u_var, 1);
 
  116   this->time_evolving(v_var, 1);
 
  118     this->time_evolving(w_var, 1);
 
  122   this->verify_analytic_jacobians = infile(
"verify_analytic_jacobians", 0.);
 
  123   this->print_jacobians = infile(
"print_jacobians", 
false);
 
  124   this->print_element_jacobians = infile(
"print_element_jacobians", 
false);
 
  127 #ifdef LIBMESH_ENABLE_DIRICHLET 
  130   std::set<boundary_id_type> top_bdys;
 
  131   top_bdys.insert(top_id);
 
  134   std::set<boundary_id_type> all_bdys(all_ids, all_ids+(
dim*2));
 
  136   std::set<boundary_id_type> nontop_bdys = all_bdys;
 
  137   nontop_bdys.erase(top_id);
 
  139   std::vector<unsigned int> u_only(1, u_var);
 
  140   std::vector<unsigned int> vw(1, v_var), uvw(1, u_var);
 
  141   uvw.push_back(v_var);
 
  145       uvw.push_back(w_var);
 
  151   if (application == 0)
 
  153       this->get_dof_map().add_dirichlet_boundary
 
  155       this->get_dof_map().add_dirichlet_boundary
 
  157       this->get_dof_map().add_dirichlet_boundary
 
  161   else if (application == 1)
 
  163       this->get_dof_map().add_dirichlet_boundary
 
  167   else if (application == 2)
 
  170       this->get_dof_map().add_dirichlet_boundary
 
  173 #endif // LIBMESH_ENABLE_DIRICHLET 
  183   FEMContext & c = cast_ref<FEMContext &>(context);
 
  211   FEMContext & c = cast_ref<FEMContext &>(context);
 
  223   const std::vector<Real> & JxW = u_elem_fe->
get_JxW();
 
  226   const std::vector<std::vector<Real>> & phi = u_elem_fe->
get_phi();
 
  230   const std::vector<std::vector<RealGradient>> & dphi = u_elem_fe->
get_dphi();
 
  234   const std::vector<std::vector<Real>> & psi = p_elem_fe->
get_phi();
 
  237   const std::vector<Point> & qpoint = u_elem_fe->
get_xyz();
 
  245   const unsigned int dim = this->get_mesh().mesh_dimension();
 
  274   for (
unsigned int qp=0; qp != n_qpoints; qp++)
 
  290       const Number u_x = grad_u(0);
 
  291       const Number u_y = grad_u(1);
 
  292       const Number u_z = (
dim == 3) ? grad_u(2) : 0;
 
  293       const Number v_x = grad_v(0);
 
  294       const Number v_y = grad_v(1);
 
  295       const Number v_z = (
dim == 3) ? grad_v(2) : 0;
 
  296       const Number w_x = (
dim == 3) ? grad_w(0) : 0;
 
  297       const Number w_y = (
dim == 3) ? grad_w(1) : 0;
 
  298       const Number w_z = (
dim == 3) ? grad_w(2) : 0;
 
  301       Point f = this->forcing(qpoint[qp]);
 
  306       for (
unsigned int i=0; i != n_u_dofs; i++)
 
  309             (-Reynolds*(U*grad_u)*phi[i][qp] + 
 
  311              (grad_u*dphi[i][qp]) +            
 
  317             (-Reynolds*(U*grad_v)*phi[i][qp] + 
 
  319              (grad_v*dphi[i][qp]) +            
 
  326               (-Reynolds*(U*grad_w)*phi[i][qp] + 
 
  328                (grad_w*dphi[i][qp]) +            
 
  341               for (
unsigned int j=0; j != n_u_dofs; j++)
 
  343                   Kuu(i,j) += JxW[qp] *
 
  344                           (-Reynolds*(U*dphi[j][qp])*phi[i][qp] -
 
  345                                                        (dphi[i][qp]*dphi[j][qp]) -
 
  346                                                        Reynolds*u_x*phi[i][qp]*phi[j][qp]);
 
  348                   Kuv(i,j) += JxW[qp] *
 
  349                           -Reynolds*u_y*phi[i][qp]*phi[j][qp];
 
  351                   Kvv(i,j) += JxW[qp] *
 
  352                           (-Reynolds*(U*dphi[j][qp])*phi[i][qp] -
 
  353                                                        (dphi[i][qp]*dphi[j][qp]) -
 
  354                                                        Reynolds*v_y*phi[i][qp]*phi[j][qp]);
 
  356                   Kvu(i,j) += JxW[qp] *
 
  357                           -Reynolds*v_x*phi[i][qp]*phi[j][qp];
 
  360                       Kww(i,j) += JxW[qp] *
 
  361                                   (-Reynolds*(U*dphi[j][qp])*phi[i][qp] -
 
  362                                                                    (dphi[i][qp]*dphi[j][qp]) -
 
  363                                                                    Reynolds*w_z*phi[i][qp]*phi[j][qp]);
 
  364                       Kuw(i,j) += JxW[qp] *
 
  365                               -Reynolds*u_z*phi[i][qp]*phi[j][qp];
 
  366                       Kvw(i,j) += JxW[qp] *
 
  367                               -Reynolds*v_z*phi[i][qp]*phi[j][qp];
 
  368                       Kwu(i,j) += JxW[qp] *
 
  369                               -Reynolds*w_x*phi[i][qp]*phi[j][qp];
 
  370                       Kwv(i,j) += JxW[qp] *
 
  371                               -Reynolds*w_y*phi[i][qp]*phi[j][qp];
 
  376               for (
unsigned int j=0; j != n_p_dofs; j++)
 
  378                   Kup(i,j) += JxW[qp]*psi[j][qp]*dphi[i][qp](0);
 
  379                   Kvp(i,j) += JxW[qp]*psi[j][qp]*dphi[i][qp](1);
 
  381                     Kwp(i,j) += JxW[qp]*psi[j][qp]*dphi[i][qp](2);
 
  387   return request_jacobian;
 
  395   FEMContext & c = cast_ref<FEMContext &>(context);
 
  407   const std::vector<Real> & JxW = u_elem_fe->
get_JxW();
 
  411   const std::vector<std::vector<RealGradient>> & dphi = u_elem_fe->
get_dphi();
 
  415   const std::vector<std::vector<Real>> & psi = p_elem_fe->
get_phi();
 
  422   const unsigned int dim = this->get_mesh().mesh_dimension();
 
  434   for (
unsigned int qp=0; qp != n_qpoints; qp++)
 
  443       for (
unsigned int i=0; i != n_p_dofs; i++)
 
  445           Fp(i) += JxW[qp] * psi[i][qp] *
 
  446             (grad_u(0) + grad_v(1));
 
  448             Fp(i) += JxW[qp] * psi[i][qp] *
 
  455               for (
unsigned int j=0; j != n_u_dofs; j++)
 
  457                   Kpu(i,j) += JxW[qp]*psi[i][qp]*dphi[j][qp](0);
 
  458                   Kpv(i,j) += JxW[qp]*psi[i][qp]*dphi[j][qp](1);
 
  460                     Kpw(i,j) += JxW[qp]*psi[i][qp]*dphi[j][qp](2);
 
  466   return request_jacobian;
 
  474   FEMContext & c = cast_ref<FEMContext &>(context);
 
  486       const Real penalty = 1.e9;
 
  497       unsigned int dim = get_mesh().mesh_dimension();
 
  501       std::vector<Real> point_phi(n_p_dofs);
 
  502       for (
unsigned int i=0; i != n_p_dofs; i++)
 
  507       for (
unsigned int i=0; i != n_p_dofs; i++)
 
  509           Fp(i) += penalty * (p - p_value) * point_phi[i];
 
  514               for (
unsigned int j=0; j != n_p_dofs; j++)
 
  515                 Kpp(i,j) += penalty * point_phi[i] * point_phi[j];
 
  520   return request_jacobian;
 
  534   FEMContext & c = cast_ref<FEMContext &>(context);
 
  541   const unsigned int dim = this->get_mesh().mesh_dimension();
 
  544   const std::vector<Real> & JxW = u_elem_fe->
get_JxW();
 
  547   const std::vector<std::vector<Real>> & phi = u_elem_fe->
get_phi();
 
  563   Number u_dot, v_dot, w_dot;
 
  565   for (
unsigned int qp = 0; qp != n_qpoints; ++qp)
 
  573       Number JxWxRe   = JxW[qp] * Reynolds;
 
  574       Number JxWxRexU = JxWxRe * u_dot;
 
  575       Number JxWxRexV = JxWxRe * v_dot;
 
  576       Number JxWxRexW = JxWxRe * w_dot;
 
  578       for (
unsigned int i = 0; i != n_u_dofs; ++i)
 
  580           Fu(i) -= JxWxRexU * phi[i][qp];
 
  581           Fv(i) -= JxWxRexV * phi[i][qp];
 
  583             Fw(i) -= JxWxRexW * phi[i][qp];
 
  589               Number JxWxRexPhiI = JxWxRe * phi[i][qp];
 
  590               Number JxWxRexPhiII = -JxWxRexPhiI * phi[i][qp];
 
  591               Kuu(i,i) += JxWxRexPhiII;
 
  592               Kvv(i,i) += JxWxRexPhiII;
 
  594                 Kww(i,i) += JxWxRexPhiII;
 
  599               for (
unsigned int j = i+1; j != n_u_dofs; ++j)
 
  601                   Number Kij = -JxWxRexPhiI * phi[j][qp];
 
  616   return request_jacobian;
 
  623   const unsigned int dim = this->get_mesh().mesh_dimension();
 
  625   Point p(1./3., 1./3.);
 
  626   Number u = point_value(u_var, p),
 
  627     v = point_value(v_var, p),
 
  628     w = (
dim == 3) ? point_value(w_var, p) : 0;
 
  648         return Point(0.,0.,0.);
 
  654         const unsigned int dim = this->get_mesh().mesh_dimension();
 
  681         libmesh_assert_not_equal_to (1, this->get_mesh().mesh_dimension());
 
  682         const Real x=p(0), y=p(1), z=p(2);
 
  684           u=(Reynolds+1)*(y*y + z*z),
 
  685           v=(Reynolds+1)*(x*x + z*z),
 
  686           w=(Reynolds+1)*(x*x + y*y);
 
  688         if (this->get_mesh().mesh_dimension() == 2)
 
  689           return 2*Reynolds*(Reynolds+1)*
Point(v*y,
 
  692           return 2*Reynolds*(Reynolds+1)*
Point(v*y + w*z,
 
  698       libmesh_error_msg(
"Invalid application id = " << application);