1 #include <libmesh/dof_map.h> 2 #include <libmesh/elem.h> 3 #include <libmesh/enum_norm_type.h> 4 #include <libmesh/equation_systems.h> 5 #include <libmesh/exact_solution.h> 6 #include <libmesh/int_range.h> 7 #include <libmesh/linear_implicit_system.h> 8 #include <libmesh/mesh.h> 9 #include <libmesh/mesh_generation.h> 10 #include <libmesh/mesh_function.h> 11 #include <libmesh/mesh_tools.h> 12 #include <libmesh/numeric_vector.h> 13 #include <libmesh/parallel.h> 14 #include <libmesh/quadrature.h> 15 #include <libmesh/replicated_mesh.h> 16 #include <libmesh/sparse_matrix.h> 17 #include <libmesh/petsc_macro.h> 41 c.get_element_fe(0, fe,
dim);
43 const std::vector<Real> & JxW = fe->
get_JxW();
44 const std::vector<Point> & xyz = fe->
get_xyz();
45 const std::vector<std::vector<Real>> & phi = fe->
get_phi();
46 const std::vector<std::vector<RealGradient>> & dphi = fe->
get_dphi();
48 std::vector<dof_id_type> & dof_indices = c.get_dof_indices();
57 for ( ; el != end_el; ++el)
59 const Elem* elem = *el;
64 c.pre_fe_reinit(system, elem);
67 unsigned int n_dofs = dof_indices.size();
68 unsigned int n_qpoints = c.get_element_qrule().n_points();
70 for (
unsigned int qp=0; qp != n_qpoints; qp++)
72 const Gradient grad_u = c.interior_gradient(0, qp);
73 const Number u = c.interior_value(0, qp);
74 const Point p = xyz[qp];
76 const Number forcing = p(0);
78 for (
unsigned int i=0; i != n_dofs; i++)
80 F(i) += JxW[qp] * (grad_u * dphi[i][qp] + (forcing-u) * phi[i][qp]);
81 for (
unsigned int j=0; j != n_dofs; ++j)
82 K(i,j) += JxW[qp] * (dphi[i][qp] * dphi[j][qp] - phi[i][qp]*phi[j][qp]);
86 dof_map.constrain_element_matrix_and_vector (K, F, dof_indices);
103 #ifdef LIBMESH_HAVE_SOLVER 104 CPPUNIT_TEST( test1DCoarseningOperator );
105 CPPUNIT_TEST( test1DCoarseningNewNodes );
107 #ifdef LIBMESH_HAVE_EXODUS_API 117 #if PETSC_RELEASE_GREATER_THAN(3,8,0) 118 CPPUNIT_TEST( testCoreformGeom2 );
119 CPPUNIT_TEST( testCoreformGeom4 );
120 CPPUNIT_TEST( testCoreformGeom8 );
126 CPPUNIT_TEST_SUITE_END();
176 matrix->
set(i*2, i, 1);
177 matrix->
set(i*2+1, i, 0.5);
178 matrix->
set(i*2+1, i+1, 0.5);
180 matrix->
set(10, 5, 1);
225 auto serialized_solution2 =
228 sys2.
solution->localize(*serialized_solution2);
231 (es2, *serialized_solution2, sys2.
get_dof_map(), 0);
241 const std::string & matrixfile,
265 matrix->read_matlab(matrixfile);
266 matrix->get_transpose(*matrix);
281 std::set<unsigned int> skip_dimensions {0};
292 testCoreform(
"meshes/geom_2.exo",
293 "matrices/geom_2_extraction_op.m",
294 0.09598270393980124874069039295234223854_R);
301 testCoreform(
"meshes/geom_4.exo",
302 "matrices/geom_4_extraction_op.m",
303 0.1040405127939275102143852084416339522_R);
310 testCoreform(
"meshes/geom_8.exo",
311 "matrices/geom_8_extraction_op.m",
312 0.103252835327032837145271735988790535_R);
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
This is the EquationSystems class.
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false)=0
Interfaces for reading/writing a mesh to/from a file.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Order
defines an enum for polynomial orders.
virtual void solve() override
For explicit systems, just assemble the system which should directly compute A*x. ...
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use...
libMesh::Parallel::Communicator * TestCommWorld
The definition of the const_element_iterator struct.
static constexpr Real TOLERANCE
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
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 prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
This is the base class from which all geometric element types are derived.
processor_id_type rank() const
NumericVector< Number > * rhs
The system matrix.
void copy_constraint_rows(const MeshBase &other_mesh)
Copy the constraints from the other mesh to this mesh.
const Parallel::Communicator & comm() const
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(std::string_view name) const
static std::unique_ptr< SparseMatrix< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package(), const MatrixBuildType matrix_build_type=MatrixBuildType::AUTOMATIC)
Builds a SparseMatrix<T> using the linear solver package specified by solver_package.
This is the MeshBase class.
void assemble_matrix_and_rhs(EquationSystems &es, const std::string &)
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
virtual void read_matlab(const std::string &filename)
Read the contents of the matrix from the Matlab-script sparse matrix format used by PETSc...
This class handles the numbering of degrees of freedom on a mesh.
CPPUNIT_TEST_SUITE_REGISTRATION(ConstraintOperatorTest)
const std::vector< std::vector< OutputGradient > > & get_dphi() const
uint8_t processor_id_type
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 compute_error(std::string_view sys_name, std::string_view unknown_name)
Computes and stores the error in the solution value e = u-u_h, the gradient grad(e) = grad(u) - grad(...
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Real calculate_norm(const NumericVector< Number > &v, unsigned int var, FEMNormType norm_type, std::set< unsigned int > *skip_dimensions=nullptr) const
virtual_for_inffe const std::vector< Real > & get_JxW() const
This class provides all data required for a physics package (e.g.
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 testCoreform(const std::string &meshfile, const std::string &matrixfile, Real expected_norm, Order order=FIRST)
virtual_for_inffe const std::vector< Point > & get_xyz() const
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.
Real l2_error(std::string_view sys_name, std::string_view unknown_name)
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
void test1DCoarseningNewNodes()
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
dof_id_type n_constrained_dofs() const
const MeshBase & get_mesh() const
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
unsigned int mesh_dimension() const
void attach_exact_value(unsigned int sys_num, FunctionBase< Number > *f)
Clone and attach an arbitrary functor which computes the exact value of the system sys_num solution a...
virtual void init()
Initialize all the systems.
This class provides function-like objects for data distributed over a mesh.
virtual dof_id_type n_elem() const =0
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
virtual ElemType type() const =0
void test1DCoarseningOperator()
A Point defines a location in LIBMESH_DIM dimensional Real space.
const SparseMatrix< Number > & get_system_matrix() const
virtual dof_id_type n_nodes() const =0
This class forms the foundation from which generic finite elements may be derived.
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems...
const std::vector< std::vector< OutputShape > > & get_phi() const
virtual void init(const numeric_index_type m, const numeric_index_type n, const numeric_index_type m_l, const numeric_index_type n_l, const numeric_index_type nnz=30, const numeric_index_type noz=10, const numeric_index_type blocksize=1)=0
Initialize SparseMatrix with the specified sizes.