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
107#ifdef LIBMESH_HAVE_EXODUS_API
117#if PETSC_RELEASE_GREATER_THAN(3,8,0)
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,
281 std::set<unsigned int> skip_dimensions {0};
293 "matrices/geom_2_extraction_op.m",
294 0.09598270393980124874069039295234223854_R);
302 "matrices/geom_4_extraction_op.m",
303 0.1040405127939275102143852084416339522_R);
311 "matrices/geom_8_extraction_op.m",
312 0.103252835327032837145271735988790535_R);
CPPUNIT_TEST(test1DCoarseningNewNodes)
LIBMESH_CPPUNIT_TEST_SUITE(ConstraintOperatorTest)
void test1DCoarseningNewNodes()
void testCoreform(const std::string &meshfile, const std::string &matrixfile, Real expected_norm, Order order=FIRST)
CPPUNIT_TEST(testCoreformGeom2)
CPPUNIT_TEST(testCoreformGeom4)
CPPUNIT_TEST(test1DCoarseningOperator)
void test1DCoarseningOperator()
CPPUNIT_TEST(testCoreformGeom8)
processor_id_type rank() const
Defines a dense matrix for use in Finite Element-type computations.
Defines a dense vector for use in Finite Element-type computations.
This class handles the numbering of degrees of freedom on a mesh.
dof_id_type n_constrained_dofs() const
This is the base class from which all geometric element types are derived.
virtual ElemType type() const =0
This is the EquationSystems class.
const MeshBase & get_mesh() const
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.
const T_sys & get_system(std::string_view name) const
This class handles the computation of the L2 and/or H1 error for the Systems in the EquationSystems o...
Real l2_error(std::string_view sys_name, std::string_view unknown_name)
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...
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(...
Manages consistently variables, degrees of freedom, and coefficient vectors for explicit systems.
NumericVector< Number > * rhs
The system matrix.
virtual void solve() override
For explicit systems, just assemble the system which should directly compute A*x.
virtual_for_inffe const std::vector< Real > & get_JxW() const
virtual_for_inffe const std::vector< Point > & get_xyz() const
This class forms the foundation from which generic finite elements may be derived.
const std::vector< std::vector< OutputShape > > & get_phi() const
const std::vector< std::vector< OutputGradient > > & get_dphi() const
This class provides all data required for a physics package (e.g.
const SparseMatrix< Number > & get_system_matrix() const
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
This is the MeshBase class.
unsigned int mesh_dimension() const
virtual dof_id_type n_elem() const =0
void allow_renumbering(bool allow)
If false is passed in then this mesh will no longer be renumbered when being prepared for use.
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
virtual dof_id_type n_nodes() const =0
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
void copy_constraint_rows(const MeshBase &other_mesh)
Copy the constraints from the other mesh to this mesh.
This class provides function-like objects for data distributed over a mesh.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
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].
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...
const Parallel::Communicator & comm() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
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.
virtual void close()=0
Calls the SparseMatrix's internal assembly routines, ensuring that the values are consistent across p...
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.
virtual void read_matlab(const std::string &filename)
Read the contents of the matrix from the Matlab-script sparse matrix format used by PETSc.
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 get_transpose(SparseMatrix< T > &dest) const =0
Copies the transpose of the matrix into dest, which may be *this.
virtual void set(const numeric_index_type i, const numeric_index_type j, const T value)=0
Set the element (i,j) to value.
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.
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.
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
const DofMap & get_dof_map() const
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
CPPUNIT_TEST_SUITE_REGISTRATION(ConstraintOperatorTest)
Communicator * TestCommWorld
The libMesh namespace provides an interface to certain functionality in the library.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
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...
The definition of the const_element_iterator struct.
void assemble_matrix_and_rhs(EquationSystems &es, const std::string &)