Go to the source code of this file.
◆ assemble_poisson() [1/2]
void assemble_poisson |
( |
EquationSystems & |
es, |
|
|
const std::string & |
libmesh_dbg_varsystem_name |
|
) |
| |
Definition at line 226 of file introduction_ex5.C.
229 libmesh_assert_equal_to (system_name,
"Poisson");
239 FEType fe_type = dof_map.variable_type(0);
246 std::unique_ptr<FEBase> fe (FEBase::build(
dim, fe_type));
263 fe->attach_quadrature_rule (qrule.get());
267 std::unique_ptr<FEBase> fe_face (FEBase::build(
dim, fe_type));
284 std::unique_ptr<QBase> qface (QBase::build(
quad_type,
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);
References libMesh::MeshBase::active_local_element_ptr_range(), libMesh::SparseMatrix< T >::add_matrix(), libMesh::NumericVector< T >::add_vector(), libMesh::QBase::build(), libMesh::FEGenericBase< OutputType >::build(), dim, exact_solution(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_mesh(), libMesh::EquationSystems::get_system(), libMesh::ImplicitSystem::matrix, mesh, libMesh::MeshBase::mesh_dimension(), quad_type, libMesh::Real, libMesh::DenseVector< T >::resize(), libMesh::DenseMatrix< T >::resize(), libMesh::ExplicitSystem::rhs, and libMesh::THIRD.
◆ assemble_poisson() [2/2]
void assemble_poisson |
( |
EquationSystems & |
es, |
|
|
const std::string & |
system_name |
|
) |
| |
◆ exact_solution()
Real exact_solution |
( |
const Real |
x, |
|
|
const Real |
y, |
|
|
const Real |
t |
|
) |
| |
This is the exact solution that we are trying to obtain.
We will solve
and take a finite difference approximation using this function to get f. This is the well-known "method of
manufactured solutions".
Definition at line 43 of file exact_solution.C.
47 static const Real pi = acos(-1.);
49 return cos(.5*
pi*x)*sin(.5*
pi*y)*cos(.5*
pi*z);
Referenced by assemble_poisson(), and exact_solution_wrapper().
◆ exact_solution_wrapper()
void exact_solution_wrapper |
( |
DenseVector< Number > & |
output, |
|
|
const Point & |
p, |
|
|
const |
Real |
|
) |
| |
◆ main()
int main |
( |
int |
argc, |
|
|
char ** |
argv |
|
) |
| |
Definition at line 100 of file introduction_ex5.C.
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);
165 equation_systems.get_system(
"Poisson").attach_assemble_function (
assemble_poisson);
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();
205 equation_systems.print_info();
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
References libMesh::EquationSystems::add_system(), assemble_poisson(), libMesh::MeshTools::Generation::build_cube(), libMesh::default_solver_package(), exact_solution_wrapper(), libMesh::FIRST, libMesh::EquationSystems::get_system(), libMesh::HEX8, libMesh::TriangleWrapper::init(), libMesh::EquationSystems::init(), libMesh::INVALID_SOLVER_PACKAGE, mesh, libMesh::out, libMesh::EquationSystems::print_info(), libMesh::MeshBase::print_info(), quad_type, and libMesh::MeshOutput< MT >::write_equation_systems().
◆ quad_type
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)
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)
const T_sys & get_system(const std::string &name) const
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.
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.
unsigned int add_variable(const std::string &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.
Wraps a function pointer into a FunctionBase object.
SparseMatrix< Number > * matrix
The system matrix.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
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...
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.