1#include <libmesh/const_function.h>
2#include <libmesh/dense_matrix.h>
3#include <libmesh/dense_vector.h>
4#include <libmesh/dirichlet_boundaries.h>
5#include <libmesh/dof_map.h>
6#include <libmesh/elem.h>
7#include <libmesh/equation_systems.h>
9#include <libmesh/mesh.h>
10#include <libmesh/mesh_generation.h>
11#include <libmesh/nonlinear_implicit_system.h>
12#include <libmesh/nonlinear_solver.h>
13#include <libmesh/numeric_vector.h>
14#include <libmesh/quadrature_gauss.h>
15#include <libmesh/sparse_matrix.h>
44 fe->attach_quadrature_rule(&qrule);
45 const auto & JxW = fe->get_JxW();
46 const auto & dphi = fe->get_dphi();
53 std::vector<dof_id_type> dof_indices;
57 for (
const Elem * elem :
mesh.active_local_element_ptr_range())
62 const auto n = dof_indices.size();
70 const Number k = JxW[qp] * dphi[i][qp] * dphi[j][qp];
72 Re(i) += k * soln(dof_indices[j]);
91#if defined(LIBMESH_ENABLE_DIRICHLET) && defined(LIBMESH_HAVE_PETSC)
117 const Real left_value = 2, right_value = 5;
123 LaplaceResidualAndJacobian assembly;
138 for (
const Node * node :
mesh.local_node_ptr_range())
140 const Real x = (*node)(0);
141 const Number exact = left_value + (right_value - left_value) * x;
142 LIBMESH_ASSERT_NUMBERS_EQUAL(
CPPUNIT_TEST(testNonzeroDirichletValues)
LIBMESH_CPPUNIT_TEST_SUITE(HeterogeneousNonlinearConstraintTest)
void testNonzeroDirichletValues()
PetscNonlinearSolver enforces a constraint in each residual it hands PETSc.
Function that returns a single value that never changes.
Defines a dense matrix for use in Finite Element-type computations.
void resize(const unsigned int new_m, const unsigned int new_n)
Resizes the matrix to the specified size and calls zero().
Defines a dense vector for use in Finite Element-type computations.
void resize(const unsigned int n)
Resize the vector.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
This class handles the numbering of degrees of freedom on a mesh.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
void add_dirichlet_boundary(const DirichletBoundary &dirichlet_boundary)
Adds a copy of the specified Dirichlet boundary to the system.
const FEType & variable_type(const unsigned int i) const
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.
This is the base class from which all geometric element types are derived.
This is the EquationSystems class.
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.
static std::unique_ptr< FEGenericBase > build(const unsigned int dim, const FEType &type)
Builds a specific finite element type.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
Order default_quadrature_order() const
This is the MeshBase class.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Node is like a Point, but with more information.
Abstract base class to be used to calculate the residual and Jacobian simultaneously of a nonlinear s...
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
virtual void solve() override
Assembles & solves the nonlinear system R(x) = 0.
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
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].
virtual void zero()=0
Set all entries to zero.
This class implements specific orders of Gauss quadrature.
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 zero()=0
Set all entries to 0.
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.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
const DofMap & get_dof_map() const
unsigned int number() const
const MeshBase & get_mesh() const
static const boundary_id_type left_id
static const boundary_id_type right_id
Communicator * TestCommWorld
CPPUNIT_TEST_SUITE_REGISTRATION(HeterogeneousNonlinearConstraintTest)
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...