Go to the documentation of this file.
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"
69 #include "libmesh/enum_quadrature_type.h"
78 const std::string & system_name);
100 int main (
int argc,
char ** argv)
107 "--enable-petsc, --enable-trilinos, or --enable-eigen");
113 libmesh_error_msg(
"Usage: " << argv[0] <<
" -q <rule>\n" \
114 <<
" where <rule> is one of QGAUSS, QSIMPSON, or QTRAP.");
123 for (
int i=1; i<argc; i++)
131 quad_type = static_cast<QuadratureType>(std::atoi(argv[2]));
134 libmesh_example_requires(3 <= LIBMESH_DIM,
"3D support");
137 #ifndef LIBMESH_ENABLE_DIRICHLET
138 libmesh_example_requires(
false,
"--enable-dirichlet");
163 unsigned int u_var = equation_systems.
get_system(
"Poisson").add_variable(
"u",
FIRST);
172 std::set<boundary_id_type> boundary_ids;
174 boundary_ids.insert(0);
175 boundary_ids.insert(1);
176 boundary_ids.insert(2);
177 boundary_ids.insert(3);
178 boundary_ids.insert(4);
179 boundary_ids.insert(5);
182 std::vector<unsigned int> variables(1);
183 variables[0] = u_var;
189 #ifdef LIBMESH_ENABLE_DIRICHLET
196 (boundary_ids, variables, exact_solution_object);
200 equation_systems.
get_system(
"Poisson").get_dof_map().add_dirichlet_boundary(dirichlet_bc);
203 equation_systems.
init();
207 equation_systems.
get_system(
"Poisson").solve();
211 std::ostringstream f_name;
214 #ifdef LIBMESH_HAVE_EXODUS_API
217 #endif // #ifdef LIBMESH_HAVE_EXODUS_API
227 const std::string & libmesh_dbg_var(system_name))
229 libmesh_assert_equal_to (system_name,
"Poisson");
239 FEType fe_type = dof_map.variable_type(0);
263 fe->attach_quadrature_rule (qrule.get());
296 fe_face->attach_quadrature_rule (qface.get());
299 const std::vector<Real> & JxW = fe->get_JxW();
301 const std::vector<Point> & q_point = fe->get_xyz();
303 const std::vector<std::vector<Real>> & phi = fe->get_phi();
305 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
309 std::vector<dof_id_type> dof_indices;
315 dof_map.dof_indices (elem, dof_indices);
317 const unsigned int n_dofs =
318 cast_int<unsigned int>(dof_indices.size());
322 libmesh_assert_equal_to (n_dofs, phi.size());
324 Ke.
resize (n_dofs, n_dofs);
331 for (
unsigned int qp=0; qp<qrule->n_points(); qp++)
334 for (
unsigned int i=0; i != n_dofs; i++)
335 for (
unsigned int j=0; j != n_dofs; j++)
336 Ke(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
352 const Real x = q_point[qp](0);
353 const Real y = q_point[qp](1);
354 const Real z = q_point[qp](2);
355 const Real eps = 1.e-3;
369 const Real fxy = - (uxx + uyy + ((
dim==2) ? 0. : uzz));
373 for (
unsigned int i=0; i != n_dofs; i++)
374 Fe(i) += JxW[qp]*fxy*phi[i][qp];
381 dof_map.heterogenously_constrain_element_matrix_and_vector (Ke, Fe, dof_indices);
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
void exact_solution_wrapper(DenseVector< Number > &output, const Point &p, const Real)
virtual System & add_system(const std::string &system_type, const std::string &name)
Add the system of type system_type named name to the systems array.
const MeshBase & get_mesh() const
NumericVector< Number > * rhs
The system matrix.
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
void assemble_poisson(EquationSystems &es, const std::string &system_name)
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(const std::string &name) const
QuadratureType
Defines an enum for currently available quadrature rules.
SolverPackage default_solver_package()
unsigned int mesh_dimension() const
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
static std::unique_ptr< QBase > build(const std::string &name, const unsigned int dim, const Order order=INVALID_ORDER)
Builds a specific quadrature rule based on the name string.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
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].
This is the MeshBase class.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
Wraps a function pointer into a FunctionBase object.
virtual void init()
Initialize all the systems.
A Point defines a location in LIBMESH_DIM dimensional Real space.
SparseMatrix< Number > * matrix
The system matrix.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
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 ...
void resize(const unsigned int n)
Resize the vector.
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.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
This class handles the numbering of degrees of freedom on a mesh.
void print_info(std::ostream &os=libMesh::out) const
Prints relevant information about the mesh.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
int main(int argc, char **argv)
const DofMap & get_dof_map() const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
Real exact_solution(const Real x, const Real y, const Real z=0.)
This is the exact solution that we are trying to obtain.