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/equation_systems.h" 39 #include "libmesh/fe.h" 40 #include "libmesh/quadrature_gauss.h" 41 #include "libmesh/dof_map.h" 42 #include "libmesh/sparse_matrix.h" 43 #include "libmesh/numeric_vector.h" 44 #include "libmesh/dense_matrix.h" 45 #include "libmesh/dense_vector.h" 46 #include "libmesh/linear_implicit_system.h" 47 #include "libmesh/enum_solver_package.h" 48 #include "libmesh/getpot.h" 49 #include "libmesh/elem_side_builder.h" 55 #include "libmesh/dense_submatrix.h" 56 #include "libmesh/dense_subvector.h" 59 #include "libmesh/elem.h" 67 const std::string & system_name);
70 int main (
int argc,
char ** argv)
77 "--enable-petsc, --enable-trilinos, or --enable-eigen");
80 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
130 equation_systems.
init ();
132 equation_systems.
parameters.
set<
unsigned int>(
"linear solver maximum iterations") = 250;
140 equation_systems.
get_system(
"Stokes").solve();
142 #ifdef LIBMESH_HAVE_EXODUS_API 145 #endif // #ifdef LIBMESH_HAVE_EXODUS_API 152 const std::string & libmesh_dbg_var(system_name))
156 libmesh_assert_equal_to (system_name,
"Stokes");
193 fe_vel->attach_quadrature_rule (&qrule);
194 fe_pres->attach_quadrature_rule (&qrule);
200 const std::vector<Real> & JxW = fe_vel->get_JxW();
204 const std::vector<std::vector<RealGradient>> & dphi = fe_vel->get_dphi();
208 const std::vector<std::vector<Real>> & psi = fe_pres->get_phi();
224 Kuu(Ke), Kuv(Ke), Kup(Ke),
225 Kvu(Ke), Kvv(Ke), Kvp(Ke),
226 Kpu(Ke), Kpv(Ke), Kpp(Ke);
236 std::vector<dof_id_type> dof_indices;
237 std::vector<dof_id_type> dof_indices_u;
238 std::vector<dof_id_type> dof_indices_v;
239 std::vector<dof_id_type> dof_indices_p;
249 for (
const auto & elem :
mesh.active_local_element_ptr_range())
260 const unsigned int n_dofs = dof_indices.size();
261 const unsigned int n_u_dofs = dof_indices_u.size();
262 const unsigned int n_v_dofs = dof_indices_v.size();
263 const unsigned int n_p_dofs = dof_indices_p.size();
269 fe_vel->reinit (elem);
270 fe_pres->reinit (elem);
278 Ke.
resize (n_dofs, n_dofs);
294 Kuu.reposition (u_var*n_u_dofs, u_var*n_u_dofs, n_u_dofs, n_u_dofs);
295 Kuv.reposition (u_var*n_u_dofs, v_var*n_u_dofs, n_u_dofs, n_v_dofs);
296 Kup.reposition (u_var*n_u_dofs, p_var*n_u_dofs, n_u_dofs, n_p_dofs);
298 Kvu.reposition (v_var*n_v_dofs, u_var*n_v_dofs, n_v_dofs, n_u_dofs);
299 Kvv.reposition (v_var*n_v_dofs, v_var*n_v_dofs, n_v_dofs, n_v_dofs);
300 Kvp.reposition (v_var*n_v_dofs, p_var*n_v_dofs, n_v_dofs, n_p_dofs);
302 Kpu.reposition (p_var*n_u_dofs, u_var*n_u_dofs, n_p_dofs, n_u_dofs);
303 Kpv.reposition (p_var*n_u_dofs, v_var*n_u_dofs, n_p_dofs, n_v_dofs);
304 Kpp.
reposition (p_var*n_u_dofs, p_var*n_u_dofs, n_p_dofs, n_p_dofs);
306 Fu.reposition (u_var*n_u_dofs, n_u_dofs);
307 Fv.reposition (v_var*n_u_dofs, n_v_dofs);
311 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
315 for (
unsigned int i=0; i<n_u_dofs; i++)
316 for (
unsigned int j=0; j<n_u_dofs; j++)
317 Kuu(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
320 for (
unsigned int i=0; i<n_u_dofs; i++)
321 for (
unsigned int j=0; j<n_p_dofs; j++)
322 Kup(i,j) += -JxW[qp]*psi[j][qp]*dphi[i][qp](0);
327 for (
unsigned int i=0; i<n_v_dofs; i++)
328 for (
unsigned int j=0; j<n_v_dofs; j++)
329 Kvv(i,j) += JxW[qp]*(dphi[i][qp]*dphi[j][qp]);
332 for (
unsigned int i=0; i<n_v_dofs; i++)
333 for (
unsigned int j=0; j<n_p_dofs; j++)
334 Kvp(i,j) += -JxW[qp]*psi[j][qp]*dphi[i][qp](1);
339 for (
unsigned int i=0; i<n_p_dofs; i++)
340 for (
unsigned int j=0; j<n_u_dofs; j++)
341 Kpu(i,j) += -JxW[qp]*psi[i][qp]*dphi[j][qp](0);
344 for (
unsigned int i=0; i<n_p_dofs; i++)
345 for (
unsigned int j=0; j<n_v_dofs; j++)
346 Kpv(i,j) += -JxW[qp]*psi[i][qp]*dphi[j][qp](1);
365 for (
auto s : elem->side_index_range())
366 if (elem->neighbor_ptr(s) ==
nullptr)
368 const Elem & side = side_builder(*elem, s);
380 const Real penalty = 1.e10;
385 const Real u_value = (yf > .99) ? 1. : 0.;
388 const Real v_value = 0.;
393 for (
auto n : elem->node_index_range())
394 if (elem->node_id(n) == side.
node_id(ns))
401 Fu(n) += penalty*u_value;
402 Fv(n) += penalty*v_value;
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 assemble_stokes(EquationSystems &es, const std::string &system_name)
void constrain_element_matrix_and_vector(DenseMatrix< Number > &matrix, DenseVector< Number > &rhs, std::vector< dof_id_type > &elem_dofs, bool asymmetric_constraint_rows=true) const
Constrains the element matrix and vector.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
static constexpr Real TOLERANCE
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 ...
int main(int argc, char **argv)
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]...
This is the base class from which all geometric element types are derived.
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.
Order default_quadrature_order() const
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
This is the MeshBase class.
unsigned int variable_number(std::string_view var) const
Defines a dense subvector for use in finite element computations.
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
void reposition(const unsigned int ioff, const unsigned int n)
Changes the location of the subvector in the parent 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.
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.
Defines a dense submatrix for use in Finite Element-type computations.
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.
Helper for building element sides that minimizes the construction of new elements.
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.
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
T & set(const std::string &)
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
Parameters parameters
Data structure holding arbitrary parameters.
IntRange< unsigned short > node_index_range() const
void reposition(const unsigned int ioff, const unsigned int joff, const unsigned int new_m, const unsigned int new_n)
Changes the location of the submatrix in the parent matrix.
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
dof_id_type node_id(const unsigned int i) const
const Point & point(const unsigned int i) const
const SparseMatrix< Number > & get_system_matrix() const