22 #include "libmesh/getpot.h"    23 #include "libmesh/dirichlet_boundaries.h"    24 #include "libmesh/dof_map.h"    25 #include "libmesh/fe_base.h"    26 #include "libmesh/fe_interface.h"    27 #include "libmesh/fem_context.h"    28 #include "libmesh/mesh.h"    29 #include "libmesh/quadrature.h"    30 #include "libmesh/string_to_enum.h"    31 #include "libmesh/zero_function.h"    32 #include "libmesh/elem.h"    51     : _u_var(u_var), _v_var(v_var), _w_var(w_var), _Re(Reynolds)
    52   { this->_initialized = 
true; }
    55   { libmesh_not_implemented(); }
    57   virtual void operator() (
const Point & p,
    62     const Real x=p(0), y=p(1), z=p(2);
    63     output(_u_var) = (_Re+1)*(y*y + z*z);
    64     output(_v_var) = (_Re+1)*(x*x + z*z);
    65     output(_w_var) = (_Re+1)*(x*x + y*y);
    68   virtual std::unique_ptr<FunctionBase<Number>> 
clone()
 const    69   { 
return std::make_unique<BdyFunction>(_u_var, _v_var, _w_var, _Re); }
    72   const unsigned int _u_var, _v_var, 
_w_var;
    79   const unsigned int dim = this->get_mesh().mesh_dimension();
    83   GetPot infile(
"navier.in");
    84   Reynolds = infile(
"Reynolds", 1.);
    85   application = infile(
"application", 0);
    86   unsigned int pressure_p = infile(
"pressure_p", 1);
    87   std::string fe_family = infile(
"fe_family", std::string(
"LAGRANGE"));
    94   FEFamily fefamily = Utility::string_to_enum<FEFamily>(fe_family);
    98   u_var = this->add_variable (
"u", static_cast<Order>(pressure_p+1),
   100   v_var = this->add_variable (
"v",
   101                               static_cast<Order>(pressure_p+1),
   105     w_var = this->add_variable (
"w",
   106                                 static_cast<Order>(pressure_p+1),
   114   p_var = this->add_variable (
"p",
   115                               static_cast<Order>(pressure_p),
   120   this->time_evolving(u_var, 1);
   121   this->time_evolving(v_var, 1);
   123     this->time_evolving(w_var, 1);
   127   this->verify_analytic_jacobians = infile(
"verify_analytic_jacobians", 0.);
   128   this->print_jacobians = infile(
"print_jacobians", 
false);
   129   this->print_element_jacobians = infile(
"print_element_jacobians", 
false);
   132 #ifdef LIBMESH_ENABLE_DIRICHLET   135   std::set<boundary_id_type> top_bdys { 
top_id };
   138   std::set<boundary_id_type> all_bdys(all_ids, all_ids+(
dim*2));
   140   std::set<boundary_id_type> nontop_bdys = all_bdys;
   141   nontop_bdys.erase(
top_id);
   143   std::vector<unsigned int> uvw {u_var, v_var, w_var};
   148   if (application == 0)
   150       this->get_dof_map().add_dirichlet_boundary
   152       this->get_dof_map().add_dirichlet_boundary
   154       this->get_dof_map().add_dirichlet_boundary
   158   else if (application == 1)
   160       this->get_dof_map().add_dirichlet_boundary
   164   else if (application == 2)
   167       this->get_dof_map().add_dirichlet_boundary
   170 #endif // LIBMESH_ENABLE_DIRICHLET   180   FEMContext & c = cast_ref<FEMContext &>(context);
   192   u_elem_fe->get_JxW();
   193   u_elem_fe->get_phi();
   194   u_elem_fe->get_dphi();
   195   u_elem_fe->get_xyz();
   213   FEMContext & c = cast_ref<FEMContext &>(context);
   225   const std::vector<Real> & JxW = u_elem_fe->get_JxW();
   228   const std::vector<std::vector<Real>> & phi = u_elem_fe->get_phi();
   232   const std::vector<std::vector<RealGradient>> & dphi = u_elem_fe->get_dphi();
   236   const std::vector<std::vector<Real>> & psi = p_elem_fe->
get_phi();
   239   const std::vector<Point> & qpoint = u_elem_fe->get_xyz();
   246   const unsigned int dim = this->get_mesh().mesh_dimension();
   252   std::reference_wrapper<DenseSubMatrix<Number>> K[3][3] =
   263   std::reference_wrapper<DenseSubMatrix<Number>> 
B[3] =
   274   std::reference_wrapper<DenseSubVector<Number>> F[3] =
   298   for (
unsigned int qp=0; qp != n_qpoints; qp++)
   310       Point f = this->forcing(qpoint[qp]);
   315       for (
unsigned int i=0; i != n_u_dofs; i++)
   317           for (
unsigned int d = 0; d < 
dim; ++d)
   319               (-Reynolds*(U*grad_uvw[d])*phi[i][qp] + 
   321                (grad_uvw[d]*dphi[i][qp]) +            
   331               for (
unsigned int j=0; j != n_u_dofs; j++)
   332                 for (
unsigned int k = 0; k < 
dim; ++k)
   333                   for (
unsigned int l = 0; l < 
dim; ++l)
   337                         K[k][k](i,j) += JxW[qp] *
   338                           (-Reynolds*(U*dphi[j][qp])*phi[i][qp] - 
   339                            (dphi[i][qp]*dphi[j][qp]));            
   342                       K[k][l](i,j) += JxW[qp] * -Reynolds*grad_uvw[k](l)*phi[i][qp]*phi[j][qp];
   346               for (
unsigned int j=0; j != n_p_dofs; j++)
   347                 for (
unsigned int k = 0; k < 
dim; ++k)
   348                   B[k](i,j) += JxW[qp]*psi[j][qp]*dphi[i][qp](k);
   353   return request_jacobian;
   361   FEMContext & c = cast_ref<FEMContext &>(context);
   373   const std::vector<Real> & JxW = u_elem_fe->get_JxW();
   377   const std::vector<std::vector<RealGradient>> & dphi = u_elem_fe->get_dphi();
   381   const std::vector<std::vector<Real>> & psi = p_elem_fe->
get_phi();
   388   const unsigned int dim = this->get_mesh().mesh_dimension();
   392   std::reference_wrapper<DenseSubMatrix<Number>> 
B[3] =
   408   for (
unsigned int qp=0; qp != n_qpoints; qp++)
   417       for (
unsigned int i=0; i != n_p_dofs; i++)
   419           for (
unsigned int k = 0; k < 
dim; ++k)
   420             Fp(i) += JxW[qp] * psi[i][qp] * grad_uvw[k](k);
   426               for (
unsigned int j=0; j != n_u_dofs; j++)
   427                 for (
unsigned int k = 0; k < 
dim; ++k)
   428                   B[k](i,j) += JxW[qp]*psi[i][qp]*dphi[j][qp](k);
   433   return request_jacobian;
   441   FEMContext & c = cast_ref<FEMContext &>(context);
   453       const Real penalty = 1.e9;
   464       unsigned int dim = get_mesh().mesh_dimension();
   465       FEType fe_type = p_elem_fe->get_fe_type();
   468       std::vector<Real> point_phi(n_p_dofs);
   469       for (
unsigned int i=0; i != n_p_dofs; i++)
   474       for (
unsigned int i=0; i != n_p_dofs; i++)
   476           Fp(i) += penalty * (p - p_value) * point_phi[i];
   481               for (
unsigned int j=0; j != n_p_dofs; j++)
   482                 Kpp(i,j) += penalty * point_phi[i] * point_phi[j];
   487   return request_jacobian;
   501   FEMContext & c = cast_ref<FEMContext &>(context);
   508   const unsigned int dim = this->get_mesh().mesh_dimension();
   511   const std::vector<Real> & JxW = u_elem_fe->get_JxW();
   514   const std::vector<std::vector<Real>> & phi = u_elem_fe->get_phi();
   517   std::reference_wrapper<DenseSubVector<Number>> F[3] =
   525   std::reference_wrapper<DenseSubMatrix<Number>> Kdiag[3] =
   538   std::array<Number, 3> accel;
   540   for (
unsigned int qp = 0; qp != n_qpoints; ++qp)
   548       Number JxWxRe = JxW[qp] * Reynolds;
   549       for (
unsigned int k = 0; k < 
dim; ++k)
   552       for (
unsigned int i = 0; i != n_u_dofs; ++i)
   554           for (
unsigned int k = 0; k < 
dim; ++k)
   555             F[k](i) -= accel[k] * phi[i][qp];
   561               Number JxWxRexPhiI = JxWxRe * phi[i][qp];
   562               Number JxWxRexPhiII = -JxWxRexPhiI * phi[i][qp];
   563               for (
unsigned int k = 0; k < 
dim; ++k)
   564                 Kdiag[k](i,i) += JxWxRexPhiII;
   569               for (
unsigned int j = i+1; j != n_u_dofs; ++j)
   571                   Number Kij = -JxWxRexPhiI * phi[j][qp];
   573                   for (
unsigned int k = 0; k < 
dim; ++k)
   575                       Kdiag[k](i,j) += Kij;
   576                       Kdiag[k](j,i) += Kij;
   583   return request_jacobian;
   590   const unsigned int dim = this->get_mesh().mesh_dimension();
   592   Point p(1./3., 1./3.);
   593   Number u = point_value(u_var, p),
   594     v = point_value(v_var, p),
   595     w = (
dim == 3) ? point_value(w_var, p) : 0;
   615         return Point(0.,0.,0.);
   621         const unsigned int dim = this->get_mesh().mesh_dimension();
   648         libmesh_assert_not_equal_to (1, this->get_mesh().mesh_dimension());
   649         const Real x=p(0), y=p(1), z=p(2);
   651           u=(Reynolds+1)*(y*y + z*z),
   652           v=(Reynolds+1)*(x*x + z*z),
   653           w=(Reynolds+1)*(x*x + y*y);
   655         if (this->get_mesh().mesh_dimension() == 2)
   656           return 2*Reynolds*(Reynolds+1)*
Point(v*y,
   659           return 2*Reynolds*(Reynolds+1)*
Point(v*y + w*z,
   665       libmesh_error_msg(
"Invalid application id = " << application);
 class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Real get_elem_solution_derivative() const
The derivative of the current elem_solution w.r.t. 
const DenseMatrix< Number > & get_elem_jacobian() const
Const accessor for element Jacobian. 
Number interior_value(unsigned int var, unsigned int qp) const
This class provides all data required for a physics package (e.g. 
void get_side_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for edge/face (2D/3D) finite element object for variable var for the largest dimension in th...
virtual void zero() override final
Set every element in the vector to 0. 
ConstFunction that simply returns 0. 
Point forcing(const Point &p)
const Elem & get_elem() const
Accessor for current Elem object. 
static Point inverse_map(const unsigned int dim, const Elem *elem, const Point &p, const Real tolerance=TOLERANCE, const bool secure=true, const bool extra_checks=true)
virtual bool side_constraint(bool request_jacobian, DiffContext &context)
Adds the constraint contribution on side of elem to elem_residual. 
unsigned int n_dof_indices() const
Total number of dof indices on the element. 
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space. 
The libMesh namespace provides an interface to certain functionality in the library. 
Number point_value(unsigned int var, const Point &p) const
Defines a dense subvector for use in finite element computations. 
Gradient interior_gradient(unsigned int var, unsigned int qp) const
virtual bool contains_point(const Point &p, Real tol=TOLERANCE) const
virtual std::unique_ptr< FunctionBase< Number > > clone() const
virtual void init_data()
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used...
static Real shape(const unsigned int dim, const FEType &fe_t, const ElemType t, const unsigned int i, const Point &p)
Defines a dense submatrix for use in Finite Element-type computations. 
Real elem_solution_derivative
The derivative of elem_solution with respect to the current nonlinear solution. 
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used...
const unsigned int _w_var
virtual_for_inffe const std::vector< Real > & get_JxW() const
This class provides all data required for a physics package (e.g. 
unsigned int n_points() const
virtual_for_inffe const std::vector< Point > & get_xyz() const
const boundary_id_type top_id
const DenseVector< Number > & get_elem_residual() const
Const accessor for element residual. 
BdyFunction(unsigned int u_var, unsigned int v_var, unsigned int w_var, Real Reynolds)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void init_context(DiffContext &context)
Function that returns a single value that never changes. 
void get_element_fe(unsigned int var, FEGenericBase< OutputShape > *&fe) const
Accessor for interior finite element object for variable var for the largest dimension in the mesh...
virtual bool mass_residual(bool request_jacobian, DiffContext &context)
Subtracts a mass vector contribution on elem from elem_residual. 
FEFamily
defines an enum for finite element families. 
Base class for functors that can be evaluated at a point and (optionally) time. 
void interior_rate(unsigned int var, unsigned int qp, OutputType &u) const
A Point defines a location in LIBMESH_DIM dimensional Real space. 
virtual bool element_constraint(bool request_jacobian, DiffContext &context)
Adds the constraint contribution on elem to elem_residual. 
This class forms the foundation from which generic finite elements may be derived. 
const QBase & get_element_qrule() const
Accessor for element interior quadrature rule for the dimension of the current _elem. 
virtual bool element_time_derivative(bool request_jacobian, DiffContext &context)
Adds the time derivative contribution on elem to elem_residual. 
virtual void postprocess()
Runs a postprocessing loop over all elements, and if postprocess_sides is true over all sides...
const std::vector< std::vector< OutputShape > > & get_phi() const