34 #include "libmesh/libmesh.h" 35 #include "libmesh/mesh.h" 36 #include "libmesh/mesh_generation.h" 37 #include "libmesh/exodusII_io.h" 38 #include "libmesh/gmv_io.h" 39 #include "libmesh/gnuplot_io.h" 40 #include "libmesh/linear_implicit_system.h" 41 #include "libmesh/equation_systems.h" 44 #include "libmesh/fe.h" 47 #include "libmesh/quadrature_gauss.h" 51 #include "libmesh/dof_map.h" 55 #include "libmesh/sparse_matrix.h" 56 #include "libmesh/numeric_vector.h" 57 #include "libmesh/dense_matrix.h" 58 #include "libmesh/dense_vector.h" 63 #include "libmesh/perf_log.h" 66 #include "libmesh/elem.h" 68 #include "libmesh/mesh_refinement.h" 71 #include "libmesh/system_subset_by_subdomain.h" 73 #include "libmesh/string_to_enum.h" 74 #include "libmesh/getpot.h" 75 #include "libmesh/enum_solver_package.h" 89 const std::string & system_name);
97 int main (
int argc,
char ** argv)
107 #ifndef LIBMESH_ENABLE_AMR 108 libmesh_example_requires(
false,
"--enable-amr");
115 GetPot command_line (argc, argv);
118 libmesh_error_msg_if(argc < 3,
"Usage:\n" <<
"\t " << argv[0] <<
" -d 2(3)" <<
" -n 15");
124 for (
int i=1; i<argc; i++)
135 libmesh_example_requires(
dim <= LIBMESH_DIM,
"2D/3D support");
142 std::string order =
"FIRST";
147 std::string family =
"LAGRANGE";
152 libmesh_error_msg_if((family ==
"MONOMIAL") || (family ==
"XYZ"),
153 "This example requires a C^0 (or higher) FE basis.");
165 Real halfwidth =
dim > 1 ? 1. : 0.;
166 Real halfheight =
dim > 2 ? 1. : 0.;
168 if ((family ==
"LAGRANGE") && (order ==
"FIRST"))
177 -halfwidth, halfwidth,
178 -halfheight, halfheight,
190 -halfwidth, halfwidth,
191 -halfheight, halfheight,
207 for (
auto & elem :
mesh.element_ptr_range())
212 bool node_in =
false;
213 bool node_out =
false;
214 for (
auto & n : elem->node_ref_range())
222 if (node_in && node_out)
239 for (
auto elem :
mesh.element_ptr_range())
241 Real d = elem->vertex_average().norm();
243 elem->subdomain_id() = 1;
261 Utility::string_to_enum<Order> (order),
262 Utility::string_to_enum<FEFamily>(family));
269 equation_systems.
init();
276 std::set<subdomain_id_type> id_list;
287 equation_systems.
get_system(
"Poisson").solve();
299 "out_3.gmv" :
"out_2.gmv", equation_systems);
300 #ifdef LIBMESH_HAVE_EXODUS_API 302 "out_3.e" :
"out_2.e", equation_systems);
303 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 306 #endif // #ifndef LIBMESH_ENABLE_AMR 321 const std::string & libmesh_dbg_var(system_name))
325 libmesh_assert_equal_to (system_name,
"Poisson");
331 PerfLog perf_log (
"Matrix Assembly");
350 FEType fe_type = dof_map.variable_type(0);
362 fe->attach_quadrature_rule (&qrule);
375 fe_face->attach_quadrature_rule (&qface);
381 const std::vector<Real> & JxW = fe->get_JxW();
386 const std::vector<Point> & q_point = fe->get_xyz();
389 const std::vector<std::vector<Real>> & phi = fe->get_phi();
393 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
405 std::vector<dof_id_type> dof_indices;
414 for (
const auto & elem :
mesh.active_local_element_ptr_range())
418 if (elem->subdomain_id()==1)
423 perf_log.
push(
"elem init");
429 dof_map.dof_indices (elem, dof_indices);
443 Ke.
resize (dof_indices.size(),
446 Fe.
resize (dof_indices.size());
451 perf_log.
pop(
"elem init");
462 perf_log.
push (
"Ke");
464 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
465 for (std::size_t i=0; i<phi.size(); i++)
466 for (std::size_t j=0; j<phi.size(); j++)
467 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
478 perf_log.
push (
"Fe");
480 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
496 const Real x = q_point[qp](0);
498 const Real y = q_point[qp](1);
503 const Real z = q_point[qp](2);
507 const Real eps = 1.e-3;
527 fxy = (0.25*
pi*
pi)*sin(.5*
pi*x);
531 fxy = - (uxx + uyy + ((
dim==2) ? 0. : uzz));
535 for (std::size_t i=0; i<phi.size(); i++)
536 Fe(i) += JxW[qp]*fxy*phi[i][qp];
551 LOG_SCOPE_WITH(
"BCs",
"", perf_log);
559 for (
auto side : elem->side_index_range())
560 if ((elem->neighbor_ptr(side) ==
nullptr) ||
561 (elem->neighbor_ptr(side)->subdomain_id()!=1))
566 const Real penalty = 1.e10;
570 const std::vector<std::vector<Real>> & phi_face = fe_face->get_phi();
574 const std::vector<Real> & JxW_face = fe_face->get_JxW();
579 const std::vector<Point> & qface_point = fe_face->get_xyz();
583 fe_face->reinit(elem, side);
586 for (
unsigned int qp=0; qp<qface.
n_points(); qp++)
590 const Real xf = qface_point[qp](0);
592 const Real yf = qface_point[qp](1);
597 const Real zf = qface_point[qp](2);
607 for (std::size_t i=0; i<phi_face.size(); i++)
608 for (std::size_t j=0; j<phi_face.size(); j++)
609 Ke(i,j) += JxW_face[qp]*penalty*phi_face[i][qp]*phi_face[j][qp];
613 for (std::size_t i=0; i<phi_face.size(); i++)
614 Fe(i) += JxW_face[qp]*penalty*
value*phi_face[i][qp];
621 dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
629 LOG_SCOPE_WITH(
"matrix insertion",
"", perf_log);
virtual void restrict_solve_to(const SystemSubset *subset, const SubsetSolveMode subset_solve_mode=SUBSET_ZERO) override
After calling this method, any solve will be limited to the given subset.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
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.
void pop(const char *label, const char *header="")
Pop the event label off the stack, resuming any lower event.
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
This method implements writing a mesh with data to a specified file where the data is taken from the ...
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
bool refine_elements()
Only refines the user-requested elements.
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.
Real exact_solution(const Real x, const Real y=0., const Real z=0.)
This is the exact solution that we are trying to obtain.
NumericVector< Number > * rhs
The system matrix.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
This class implements writing meshes in the GMV format.
const T_sys & get_system(std::string_view name) const
This class represents a subset of the dofs of a System, selected by the subdomain_id and possible the...
This is the MeshBase class.
int main(int argc, char **argv)
SolverPackage default_solver_package()
The PerfLog class allows monitoring of specific events.
This class handles the numbering of degrees of freedom on a mesh.
This class implements writing meshes using GNUplot, designed for use only with 1D meshes...
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.
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 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.
void push(const char *label, const char *header="")
Push the event label onto the stack, pausing any active event.
unsigned int n_points() const
Selection of subdomain ids by a list.
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.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void assemble_poisson(EquationSystems &es, const std::string &system_name)
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.
const DofMap & get_dof_map() const
const SparseMatrix< Number > & get_system_matrix() const