29 #include "libmesh/string_to_enum.h" 30 #include "libmesh/petsc_macro.h" 33 #include "libmesh/enum_solver_package.h" 36 #include "libmesh/mesh.h" 37 #include "libmesh/mesh_generation.h" 38 #include "libmesh/mesh_modification.h" 41 #include "libmesh/dense_matrix.h" 42 #include "libmesh/sparse_matrix.h" 43 #include "libmesh/dense_vector.h" 44 #include "libmesh/numeric_vector.h" 47 #include "libmesh/fe.h" 48 #include "libmesh/elem.h" 51 #include "libmesh/quadrature_gauss.h" 54 #include "libmesh/dof_map.h" 57 #include "libmesh/equation_systems.h" 58 #include "libmesh/linear_implicit_system.h" 61 #include "libmesh/exact_solution.h" 62 #include "libmesh/enum_norm_type.h" 63 #include "solution_function.h" 66 #include "libmesh/getpot.h" 67 #include "libmesh/exodusII_io.h" 82 const std::string & system_name);
84 int main (
int argc,
char ** argv)
91 "--enable-petsc, --enable-trilinos, or --enable-eigen");
94 GetPot infile(
"vector_fe_ex10.in");
97 infile.parse_command_line(argc, argv);
100 #if PETSC_VERSION_LESS_THAN(3, 12, 2) || !defined(LIBMESH_HAVE_PETSC_HYPRE) 101 libmesh_example_requires(!infile.search(
"ams") && !infile.search(
"ads"),
102 "PETSc 3.12.2 or above with hypre support enabled");
106 const unsigned int dimension = infile(
"dim", 2);
107 const unsigned int grid_size = infile(
"grid_size", 15);
110 libmesh_example_requires(dimension <= LIBMESH_DIM, dimension <<
"D support");
119 const std::string elem_str = infile(
"element_type", std::string(
"TRI6"));
121 libmesh_error_msg_if((dimension == 2 && elem_str !=
"TRI6" && elem_str !=
"TRI7" && elem_str !=
"QUAD8" && elem_str !=
"QUAD9") ||
122 (dimension == 3 && elem_str !=
"TET14" && elem_str !=
"HEX27"),
123 "You selected " << elem_str <<
124 " but this example must be run with TRI6, TRI7, QUAD8, or QUAD9 in 2d" <<
125 " or with TET14, or HEX27 in 3d.");
133 Utility::string_to_enum<ElemType>(elem_str));
134 else if (dimension == 3)
142 Utility::string_to_enum<ElemType>(elem_str));
150 const Real phi = infile(
"phi", 0.), theta = infile(
"theta", 0.), psi = infile(
"psi", 0.);
163 const Order vector_order =
static_cast<Order>(infile(
"order", 1u));
165 libmesh_error_msg_if(vector_order < FIRST || vector_order > ((dimension == 3) ?
FIRST :
FIFTH),
166 "You selected: " << vector_order <<
167 " but this example must be run with either 1 <= order <= 5 in 2d" 168 " or with order 1 in 3d.");
178 equation_systems.
init();
194 std::vector<FunctionBase<Number> *> sols(1, &soln_func);
195 std::vector<FunctionBase<Gradient> *> grads(1, &soln_grad);
201 int extra_error_quadrature = infile(
"extra_error_quadrature", 2);
211 << exact_sol.
l2_error(
"GradDiv",
"u")
220 #ifdef LIBMESH_HAVE_EXODUS_API 225 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 239 const std::string & libmesh_dbg_var(system_name))
244 libmesh_assert_equal_to (system_name,
"GradDiv");
276 vector_fe->attach_quadrature_rule (&qrule);
286 vector_fe_face->attach_quadrature_rule (&qface);
292 const std::vector<Real> & JxW = vector_fe->get_JxW();
297 const std::vector<Point> & q_point = vector_fe->get_xyz();
300 const std::vector<std::vector<RealGradient>> & vector_phi = vector_fe->get_phi();
304 const std::vector<std::vector<Real>> & div_vector_phi = vector_fe->get_div_phi();
318 std::vector<dof_id_type> dof_indices;
336 for (
const auto & elem :
mesh.active_local_element_ptr_range())
342 dof_map.dof_indices (elem, dof_indices);
349 const unsigned int n_dofs =
350 cast_int<unsigned int>(dof_indices.size());
356 vector_fe->reinit (elem);
360 libmesh_assert_equal_to (n_dofs, vector_phi.size());
371 Ke.
resize (n_dofs, n_dofs);
376 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
382 for (
unsigned int i = 0; i != n_dofs; i++)
383 for (
unsigned int j = 0; j != n_dofs; j++)
385 Ke(i, j) += JxW[qp]*(div_vector_phi[i][qp]*div_vector_phi[j][qp]+
386 vector_phi[i][qp]*vector_phi[j][qp]);
400 for (
unsigned int k = 0; k != n_dofs; k++)
402 Fe(k) += JxW[qp]*f*vector_phi[k][qp];
415 for (
auto side : elem->side_index_range())
416 if (elem->neighbor_ptr(side) ==
nullptr)
419 const std::vector<std::vector<RealGradient>> & vector_phi_face = vector_fe_face->get_phi();
423 const std::vector<Real> & JxW_face = vector_fe_face->get_JxW();
428 const std::vector<Point> & qface_point = vector_fe_face->get_xyz();
429 const std::vector<Point> & normals = vector_fe_face->get_normals();
432 vector_fe_face->reinit(elem, side);
436 libmesh_assert_equal_to (n_dofs, vector_phi_face.size());
439 for (
unsigned int qp=0; qp<qface.n_points(); qp++)
446 const Real penalty = 1.e10;
451 for (
unsigned int i = 0; i != n_dofs; i++)
452 for (
unsigned int j = 0; j != n_dofs; j++)
454 Ke(i, j) += JxW_face[qp]*penalty*vector_phi_face[i][qp]*
455 normals[qp]*vector_phi_face[j][qp]*normals[qp];
461 for (
unsigned int i = 0; i != n_dofs; i++)
463 Fe(i) += JxW_face[qp]*penalty*vector_phi_face[i][qp]*normals[qp]*
464 vector_value*normals[qp];
475 dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
This is the EquationSystems class.
Order
defines an enum for polynomial orders.
Real hdiv_error(std::string_view sys_name, std::string_view unknown_name)
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
void assemble_graddiv(EquationSystems &es, const std::string &system_name)
void attach_exact_values(const std::vector< FunctionBase< Number > *> &f)
Clone and attach arbitrary functors which compute the exact values of the EquationSystems' solutions ...
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
void resize(const unsigned int n)
Resize the vector.
virtual void add_vector(const T *v, const std::vector< numeric_index_type > &dof_indices)
Computes , where v is a pointer and each dof_indices[i] specifies where to add value v[i]...
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
void extra_quadrature_order(const int extraorder)
Increases or decreases the order of the quadrature rule used for numerical integration.
NumericVector< Number > * rhs
The system matrix.
Order default_quadrature_order() const
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
void attach_exact_derivs(const std::vector< FunctionBase< Gradient > *> &g)
Clone and attach arbitrary functors which compute the exact gradients of the EquationSystems' solutio...
virtual void solve() override
Assembles & solves the linear system A*x=b.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
unsigned int variable_number(std::string_view var) const
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
virtual void add_matrix(const DenseMatrix< T > &dm, const std::vector< numeric_index_type > &rows, const std::vector< numeric_index_type > &cols)=0
Add the full matrix dm to the SparseMatrix.
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
void compute_error(std::string_view sys_name, std::string_view unknown_name)
Computes and stores the error in the solution value e = u-u_h, the gradient grad(e) = grad(u) - grad(...
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
unsigned int add_variable(std::string_view var, const FEType &type, const std::set< subdomain_id_type > *const active_subdomains=nullptr)
Adds the variable var to the list of variables for this system.
static void RM(RealTensor T)
void attach_assemble_function(void fptr(EquationSystems &es, const std::string &name))
Register a user function to use in assembling the system matrix and RHS.
Real l2_error(std::string_view sys_name, std::string_view unknown_name)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const MeshBase & get_mesh() const
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
virtual void init()
Initialize all the systems.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
int main(int argc, char **argv)
RealGradient forcing(Point p)
const DofMap & get_dof_map() const
const SparseMatrix< Number > & get_system_matrix() const
This class defines a tensor in LIBMESH_DIM dimensional Real or Complex space.
Real error_norm(std::string_view sys_name, std::string_view unknown_name, const FEMNormType &norm)