37 #include "libmesh/libmesh.h" 38 #include "libmesh/mesh.h" 39 #include "libmesh/mesh_generation.h" 40 #include "libmesh/vtk_io.h" 41 #include "libmesh/linear_implicit_system.h" 42 #include "libmesh/equation_systems.h" 45 #include "libmesh/fe.h" 48 #include "libmesh/quadrature_gauss.h" 52 #include "libmesh/sparse_matrix.h" 53 #include "libmesh/numeric_vector.h" 54 #include "libmesh/dense_matrix.h" 55 #include "libmesh/dense_vector.h" 56 #include "libmesh/elem.h" 57 #include "libmesh/enum_solver_package.h" 61 #include "libmesh/dof_map.h" 73 const std::string & system_name);
80 int main (
int argc,
char ** argv)
87 "--enable-petsc, --enable-trilinos, or --enable-eigen");
93 for (
int i=1; i<argc; i++)
99 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
138 equation_systems.
init();
158 equation_systems.
get_system(
"Poisson").solve();
160 #if defined(LIBMESH_HAVE_VTK) && !defined(LIBMESH_ENABLE_PARMESH) 166 #endif // #ifdef LIBMESH_HAVE_VTK 180 const std::string & libmesh_dbg_var(system_name))
185 libmesh_assert_equal_to (system_name,
"Poisson");
204 FEType fe_type = dof_map.variable_type(0);
218 fe->attach_quadrature_rule (&qrule);
231 fe_face->attach_quadrature_rule (&qface);
237 const std::vector<Real> & JxW = fe->get_JxW();
242 const std::vector<Point> & q_point = fe->get_xyz();
245 const std::vector<std::vector<Real>> & phi = fe->get_phi();
249 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
263 std::vector<dof_id_type> dof_indices;
281 for (
const auto & elem :
mesh.active_local_element_ptr_range())
287 dof_map.dof_indices (elem, dof_indices);
294 const unsigned int n_dofs =
295 cast_int<unsigned int>(dof_indices.size());
305 libmesh_assert_equal_to (n_dofs, phi.size());
316 Ke.
resize (n_dofs, n_dofs);
322 for (
unsigned int qp=0; qp<qrule.
n_points(); qp++)
328 for (
unsigned int i=0; i != n_dofs; i++)
329 for (
unsigned int j=0; j != n_dofs; j++)
331 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
339 const Real x = q_point[qp](0);
340 const Real y = q_point[qp](1);
341 const Real eps = 1.e-3;
364 for (
unsigned int i=0; i != n_dofs; i++)
365 Fe(i) += JxW[qp]*fxy*phi[i][qp];
404 for (
auto side : elem->side_index_range())
405 if (elem->neighbor_ptr(side) ==
nullptr)
409 const std::vector<std::vector<Real>> & phi_face = fe_face->get_phi();
413 const std::vector<Real> & JxW_face = fe_face->get_JxW();
418 const std::vector<Point> & qface_point = fe_face->get_xyz();
422 fe_face->reinit(elem, side);
427 libmesh_assert_equal_to (n_dofs, phi_face.size());
430 for (
unsigned int qp=0; qp<qface.
n_points(); qp++)
434 const Real xf = qface_point[qp](0);
435 const Real yf = qface_point[qp](1);
439 const Real penalty = 1.e10;
445 for (
unsigned int i=0; i != n_dofs; i++)
446 for (
unsigned int j=0; j != n_dofs; j++)
447 Ke(i,j) += JxW_face[qp]*penalty*phi_face[i][qp]*phi_face[j][qp];
451 for (
unsigned int i=0; i != n_dofs; i++)
452 Fe(i) += JxW_face[qp]*penalty*
value*phi_face[i][qp];
462 dof_map.constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
This is the EquationSystems class.
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 ...
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.
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 reading and writing meshes in the VTK format.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
int main(int argc, char **argv)
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.
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 n_points() const
Real exact_solution(const Real x, const Real y, const Real z=0.)
This is the exact solution that we are trying to obtain.
void assemble_poisson(EquationSystems &es, const std::string &system_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.
const DofMap & get_dof_map() const
const SparseMatrix< Number > & get_system_matrix() const