47 #include "libmesh/libmesh.h" 48 #include "libmesh/mesh.h" 49 #include "libmesh/mesh_refinement.h" 50 #include "libmesh/vtk_io.h" 51 #include "libmesh/equation_systems.h" 52 #include "libmesh/fe.h" 53 #include "libmesh/quadrature_gauss.h" 54 #include "libmesh/dof_map.h" 55 #include "libmesh/sparse_matrix.h" 56 #include "libmesh/numeric_vector.h" 57 #include "libmesh/dense_matrix.h" 58 #include "libmesh/dense_vector.h" 59 #include "libmesh/mesh_generation.h" 60 #include "libmesh/sum_shell_matrix.h" 61 #include "libmesh/tensor_shell_matrix.h" 62 #include "libmesh/sparse_shell_matrix.h" 63 #include "libmesh/mesh_refinement.h" 65 #include "libmesh/getpot.h" 69 #include "libmesh/transient_system.h" 70 #include "libmesh/linear_implicit_system.h" 71 #include "libmesh/vector_value.h" 74 #include "libmesh/elem.h" 75 #include "libmesh/enum_solver_package.h" 83 const std::string & system_name);
90 int main (
int argc,
char ** argv)
95 #if !defined(LIBMESH_ENABLE_AMR) 96 libmesh_example_requires(
false,
"--enable-amr");
105 for (
int i=1; i<argc; i++)
111 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
121 GetPot input(argc, argv);
123 const unsigned int nx = input(
"nx", 16);
124 const unsigned int ny = input(
"ny", 16);
154 equation_systems.init ();
157 equation_systems.print_info();
159 equation_systems.parameters.set<
unsigned int>
160 (
"linear solver maximum iterations") = 250;
161 equation_systems.parameters.set<
Real>
165 for (
unsigned int i=0; i<2; i++)
168 for (
auto & elem :
mesh.element_ptr_range())
172 if ((elem->id()%20)>8)
181 equation_systems.reinit();
185 equation_systems.print_info();
198 shellMatrix.matrices.push_back(&shellMatrix0);
200 shellMatrix.matrices.push_back(&shellMatrix1);
219 <<
" iterations, residual norm is " 224 #if defined(LIBMESH_HAVE_VTK) && !defined(LIBMESH_ENABLE_PARMESH) 227 #endif // #ifdef LIBMESH_HAVE_VTK 229 #endif // #ifndef LIBMESH_ENABLE_AMR 240 const std::string & system_name)
245 #ifdef LIBMESH_ENABLE_AMR 248 libmesh_assert_equal_to (system_name,
"System");
273 QGauss qrule (
dim, fe_type.default_quadrature_order());
274 QGauss qface (
dim-1, fe_type.default_quadrature_order());
277 fe->attach_quadrature_rule (&qrule);
278 fe_face->attach_quadrature_rule (&qface);
283 const std::vector<Real> & JxW = fe->get_JxW();
284 const std::vector<Real> & JxW_face = fe_face->get_JxW();
287 const std::vector<std::vector<Real>> & phi = fe->get_phi();
288 const std::vector<std::vector<Real>> & psi = fe_face->get_phi();
292 const std::vector<std::vector<RealGradient>> & dphi = fe->get_dphi();
318 std::vector<dof_id_type> dof_indices;
328 for (
const auto & elem :
mesh.active_local_element_ptr_range())
348 const unsigned int n_dofs =
349 cast_int<unsigned int>(dof_indices.size());
351 Ke.
resize (n_dofs, n_dofs);
363 for (
unsigned int qp=0; qp<qrule.n_points(); qp++)
366 for (
unsigned int i=0; i<n_dofs; i++)
369 Fe(i) += JxW[qp]*phi[i][qp];
371 for (
unsigned int j=0; j<n_dofs; j++)
376 (dphi[i][qp]*dphi[j][qp])
381 Ve(i) += JxW[qp]*phi[i][qp];
382 We(i) += JxW[qp]*phi[i][qp];
397 const Real penalty = 1.e10;
402 for (
auto s : elem->side_index_range())
403 if (elem->neighbor_ptr(s) ==
nullptr)
405 fe_face->reinit(elem, s);
407 for (
unsigned int qp=0; qp<qface.n_points(); qp++)
410 for (
unsigned int i=0; i<n_dofs; i++)
411 for (
unsigned int j=0; j<n_dofs; j++)
412 Ke(i,j) += penalty*JxW_face[qp]*psi[i][qp]*psi[j][qp];
432 std::vector<dof_id_type> dof_indices_backup(dof_indices);
434 dof_indices = dof_indices_backup;
458 #endif // #ifdef LIBMESH_ENABLE_AMR class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
void constrain_element_dyad_matrix(DenseVector< Number > &v, DenseVector< Number > &w, std::vector< dof_id_type > &row_dofs, bool asymmetric_constraint_rows=true) const
Constrains a dyadic element matrix B = v w'.
void attach_shell_matrix(ShellMatrix< Number > *shell_matrix)
This function enables the user to provide a shell matrix, i.e.
This is the EquationSystems class.
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.
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 dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
static constexpr Real TOLERANCE
bool refine_elements()
Only refines the user-requested elements.
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]...
NumericVector< Number > * rhs
The system matrix.
const Parallel::Communicator & comm() const
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
This class combines any number of shell matrices to a single shell matrix by summing them together...
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
dof_id_type n_local_dofs() const
This class implements reading and writing meshes in the VTK format.
virtual void solve() override
Assembles & solves the linear system A*x=b.
const T_sys & get_system(std::string_view name) const
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
void assemble(EquationSystems &es, const std::string &system_name)
dof_id_type n_dofs() const
This is the MeshBase class.
SolverPackage default_solver_package()
This class handles the numbering of degrees of freedom on a mesh.
Shell matrix that is given by a tensor product of two vectors, i.e.
void libmesh_ignore(const Args &...)
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.
Real final_linear_residual() const
Implements (adaptive) mesh refinement algorithms for a MeshBase.
virtual void zero()=0
Set all entries to 0.
unsigned int n_linear_iterations() const
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.
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.
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
SparseMatrix< Number > * matrix
The system matrix.
This class allows to use any SparseMatrix object as a shell matrix.
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().
int main(int argc, char **argv)
This class implements specific orders of Gauss quadrature.
unsigned int mesh_dimension() const
void detach_shell_matrix()
Detaches a shell matrix.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
SparseMatrix< Number > & add_matrix(std::string_view mat_name, ParallelType type=PARALLEL, MatrixBuildType mat_build_type=MatrixBuildType::AUTOMATIC)
Adds the additional matrix mat_name to this system.
const DofMap & get_dof_map() const
const SparseMatrix< Number > & get_matrix(std::string_view mat_name) const
const SparseMatrix< Number > & get_system_matrix() const
const NumericVector< Number > & get_vector(std::string_view vec_name) const