37 #include "libmesh/libmesh.h" 38 #include "libmesh/mesh.h" 39 #include "libmesh/mesh_generation.h" 40 #include "libmesh/exodusII_io.h" 41 #include "libmesh/linear_implicit_system.h" 42 #include "libmesh/equation_systems.h" 45 #include "libmesh/fe.h" 49 #include "libmesh/quadrature.h" 53 #include "libmesh/sparse_matrix.h" 54 #include "libmesh/numeric_vector.h" 55 #include "libmesh/dense_matrix.h" 56 #include "libmesh/dense_vector.h" 60 #include "libmesh/dof_map.h" 63 #include "libmesh/dirichlet_boundaries.h" 64 #include "libmesh/analytic_function.h" 67 #include "libmesh/elem.h" 68 #include "libmesh/enum_solver_package.h" 71 #include "libmesh/enum_quadrature_type.h" 72 #include "libmesh/string_to_enum.h" 81 const std::string & system_name);
103 int main (
int argc,
char ** argv)
110 "--enable-petsc, --enable-trilinos, or --enable-eigen");
114 libmesh_error_msg_if(argc < 3,
115 "Usage: " << argv[0] <<
" -q <rule>\n" 116 " where <rule> is one of QGAUSS, QSIMPSON, or QTRAP.");
121 for (
int i=1; i<argc; i++)
127 quad_type = Utility::string_to_enum<QuadratureType>
131 libmesh_example_requires(3 <= LIBMESH_DIM,
"3D support");
134 #ifndef LIBMESH_ENABLE_DIRICHLET 135 libmesh_example_requires(
false,
"--enable-dirichlet");
160 unsigned int u_var = equation_systems.
get_system(
"Poisson").add_variable(
"u",
FIRST);
169 std::set<boundary_id_type> boundary_ids {0,1,2,3,4,5};
175 #ifdef LIBMESH_ENABLE_DIRICHLET 182 (boundary_ids, {u_var}, exact_solution_object);
186 equation_systems.
get_system(
"Poisson").get_dof_map().add_dirichlet_boundary(dirichlet_bc);
189 equation_systems.
init();
193 equation_systems.
get_system(
"Poisson").solve();
197 std::ostringstream f_name;
200 #ifdef LIBMESH_HAVE_EXODUS_API 203 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 213 const std::string & libmesh_dbg_var(system_name))
215 libmesh_assert_equal_to (system_name,
"Poisson");
225 FEType fe_type = dof_map.variable_type(0);
249 fe->attach_quadrature_rule (qrule.get());
282 fe_face->attach_quadrature_rule (qface.get());
285 const std::vector<Real> & JxW = fe->get_JxW();
287 const std::vector<Point> & q_point = fe->get_xyz();
289 const std::vector<std::vector<Real>> & phi = fe->get_phi();
291 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
295 std::vector<dof_id_type> dof_indices;
302 for (
const auto & elem :
mesh.active_local_element_ptr_range())
304 dof_map.dof_indices (elem, dof_indices);
306 const unsigned int n_dofs =
307 cast_int<unsigned int>(dof_indices.size());
311 libmesh_assert_equal_to (n_dofs, phi.size());
313 Ke.
resize (n_dofs, n_dofs);
320 for (
unsigned int qp=0; qp<qrule->n_points(); qp++)
323 for (
unsigned int i=0; i != n_dofs; i++)
324 for (
unsigned int j=0; j != n_dofs; j++)
325 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
341 const Real x = q_point[qp](0);
342 const Real y = q_point[qp](1);
343 const Real z = q_point[qp](2);
344 const Real eps = 1.e-3;
358 const Real fxy = - (uxx + uyy + ((
dim==2) ? 0. : uzz));
362 for (
unsigned int i=0; i != n_dofs; i++)
363 Fe(i) += JxW[qp]*fxy*phi[i][qp];
370 dof_map.heterogenously_constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
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.
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]...
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...
QuadratureType
Defines an enum for currently available quadrature rules.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(std::string_view name) const
Wraps a function pointer into a FunctionBase object.
This is the MeshBase class.
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
void exact_solution_wrapper(DenseVector< Number > &output, const Point &p, const Real)
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.
int main(int argc, char **argv)
Real exact_solution(const Real x, const Real y, const Real z=0.)
This is the exact solution that we are trying to obtain.
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.
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().
unsigned int mesh_dimension() const
static std::unique_ptr< QBase > build(std::string_view name, const unsigned int dim, const Order order=INVALID_ORDER)
Builds a specific quadrature rule based on the name string.
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
A Point defines a location in LIBMESH_DIM dimensional Real space.
const SparseMatrix< Number > & get_system_matrix() const
void assemble_poisson(EquationSystems &es, const std::string &system_name)