39 #include "libmesh/libmesh.h" 40 #include "libmesh/mesh.h" 41 #include "libmesh/mesh_generation.h" 42 #include "libmesh/linear_implicit_system.h" 43 #include "libmesh/equation_systems.h" 44 #include "libmesh/exact_solution.h" 45 #include "libmesh/exodusII_io.h" 46 #include "libmesh/fe.h" 47 #include "libmesh/quadrature_gauss.h" 48 #include "libmesh/dof_map.h" 49 #include "libmesh/sparse_matrix.h" 50 #include "libmesh/numeric_vector.h" 51 #include "libmesh/dense_matrix.h" 52 #include "libmesh/dense_vector.h" 53 #include "libmesh/elem.h" 54 #include "libmesh/dirichlet_boundaries.h" 55 #include "libmesh/zero_function.h" 56 #include "libmesh/libmesh_logging.h" 57 #include "libmesh/getpot.h" 58 #include "libmesh/error_vector.h" 59 #include "libmesh/kelly_error_estimator.h" 60 #include "libmesh/mesh_refinement.h" 61 #include "libmesh/enum_solver_package.h" 68 const std::string & system_name);
72 int main (
int argc,
char ** argv)
78 "--enable-petsc, --enable-trilinos, or --enable-eigen");
81 libmesh_error_msg_if(argc < 3,
"Usage:\n" <<
"\t " << argv[0] <<
" -n 15");
87 for (
int i=1; i<argc; i++)
93 const unsigned int dim = 3;
96 libmesh_example_requires(
dim <= LIBMESH_DIM,
"3D support");
99 #ifndef LIBMESH_ENABLE_DIRICHLET 100 libmesh_example_requires(
false,
"--enable-dirichlet");
117 LOG_SCOPE(
"Initialize and create cubes",
"main");
118 MeshTools::Generation::build_cube (
mesh, ps, ps, ps, -1, 0, 0, 1, 0, 1,
HEX8);
119 MeshTools::Generation::build_cube (mesh1, ps, ps, ps, 0, 1, 0, 1, 0, 1,
HEX8);
120 MeshTools::Generation::build_cube (mesh2, ps, ps, ps, -1, 0, -1, 0, 0, 1,
HEX8);
121 MeshTools::Generation::build_cube (mesh3, ps, ps, ps, 0, 1, -1, 0, 0, 1,
HEX8);
122 MeshTools::Generation::build_cube (mesh4, ps, ps, ps, -1, 0, 0, 1, -1, 0,
HEX8);
123 MeshTools::Generation::build_cube (mesh5, ps, ps, ps, 0, 1, 0, 1, -1, 0,
HEX8);
124 MeshTools::Generation::build_cube (mesh6, ps, ps, ps, -1, 0, -1, 0, -1, 0,
HEX8);
125 MeshTools::Generation::build_cube (mesh7, ps, ps, ps, 0, 1, -1, 0, -1, 0,
HEX8);
128 MeshTools::Generation::build_cube (nostitch_mesh, ps*2, ps*2, ps*2, -1, 1, -1, 1, -1, 1,
HEX8);
133 LOG_SCOPE(
"Stitching",
"main");
134 mesh.stitch_meshes(mesh1, 2, 4,
TOLERANCE,
true,
true,
false,
false);
135 mesh2.stitch_meshes(mesh3, 2, 4,
TOLERANCE,
true,
true,
false,
false);
136 mesh.stitch_meshes(mesh2, 1, 3,
TOLERANCE,
true,
true,
false,
false);
137 mesh4.stitch_meshes(mesh5, 2, 4,
TOLERANCE,
true,
true,
false,
false);
138 mesh6.stitch_meshes(mesh7, 2, 4,
TOLERANCE,
true,
true,
false,
false);
139 mesh4.stitch_meshes(mesh6, 1, 3,
TOLERANCE,
true,
true,
false,
false);
140 mesh.stitch_meshes(mesh4, 0, 5,
TOLERANCE,
true,
true,
false,
false);
146 LOG_SCOPE(
"Initialize and solve systems",
"main");
152 LOG_SCOPE(
"Result comparison",
"main");
158 libMesh::out <<
"L2 error between stitched and non-stitched cases: " << error << std::endl;
161 #ifdef LIBMESH_HAVE_EXODUS_API 163 LOG_SCOPE(
"Output",
"main");
165 equation_systems_stitch);
167 equation_systems_nostitch);
169 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 182 #ifdef LIBMESH_ENABLE_DIRICHLET 196 #endif // LIBMESH_ENABLE_DIRICHLET 198 equation_systems.
init();
201 #ifdef LIBMESH_ENABLE_AMR 208 const unsigned int max_r_steps = 2;
210 for (
unsigned int r_step=0; r_step<=max_r_steps; r_step++)
213 if (r_step != max_r_steps)
230 equation_systems.
reinit();
239 const std::string & libmesh_dbg_var(system_name))
241 libmesh_assert_equal_to (system_name,
"Poisson");
249 FEType fe_type = dof_map.variable_type(0);
252 fe->attach_quadrature_rule (&qrule);
255 fe_face->attach_quadrature_rule (&qface);
257 const std::vector<Real> & JxW = fe->get_JxW();
258 const std::vector<std::vector<Real>> & phi = fe->get_phi();
259 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
264 std::vector<dof_id_type> dof_indices;
267 for (
const auto & elem :
mesh.active_local_element_ptr_range())
269 dof_map.dof_indices (elem, dof_indices);
273 Ke.
resize (dof_indices.size(),
276 Fe.
resize (dof_indices.size());
278 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
280 for (std::size_t i=0; i<phi.size(); i++)
282 Fe(i) += JxW[qp]*phi[i][qp];
283 for (std::size_t j=0; j<phi.size(); j++)
284 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
288 dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
virtual T maximum() const
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...
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line...
This is the EquationSystems class.
ConstFunction that simply returns 0.
virtual Real l2_norm() const
static constexpr Real TOLERANCE
The ErrorVector is a specialization of the StatisticsVector for error data computed on a finite eleme...
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
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]...
Real & coarsen_fraction()
The coarsen_fraction sets either a desired target or a desired maximum number of elements to flag for...
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
NumericVector< Number > * rhs
The system matrix.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
Real & refine_fraction()
The refine_fraction sets either a desired target or a desired maximum number of elements to flag for ...
void assemble_and_solve(MeshBase &, EquationSystems &)
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
virtual void solve() override
Assembles & solves the linear system A*x=b.
const T_sys & get_system(std::string_view name) const
unsigned int & max_h_level()
The max_h_level is the greatest refinement level an element should reach.
This is the MeshBase class.
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.
Implements (adaptive) mesh refinement algorithms for a MeshBase.
void assemble_poisson(EquationSystems &es, const std::string &system_name)
The UnstructuredMesh class is derived from the MeshBase class.
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(...
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh.
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.
int main(int argc, char **argv)
unsigned int n_points() const
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)
This class implements the Kelly error indicator which is based on the flux jumps between elements...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool refine_and_coarsen_elements()
Refines and coarsens user-requested elements.
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
void flag_elements_by_error_fraction(const ErrorVector &error_per_cell, const Real refine_fraction=0.3, const Real coarsen_fraction=0.0, const unsigned int max_level=libMesh::invalid_uint)
Flags elements for coarsening and refinement based on the computed error passed in error_per_cell...
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
virtual void estimate_error(const System &system, ErrorVector &error_per_cell, const NumericVector< Number > *solution_vector=nullptr, bool estimate_parent_error=false) override
This function uses the derived class's jump error estimate formula to estimate the error on each cell...
virtual void init()
Initialize all the systems.
void attach_reference_solution(const EquationSystems *es_fine)
Attach function similar to system.h which allows the user to attach a second EquationSystems object w...
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.
const DofMap & get_dof_map() const
bool compare_elements(const UnstructuredMesh &mesh1, const UnstructuredMesh &mesh2)
const SparseMatrix< Number > & get_system_matrix() const