libMesh
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | List of all members
HeterogeneousNonlinearConstraintTest Class Reference
Inheritance diagram for HeterogeneousNonlinearConstraintTest:
[legend]

Public Member Functions

 LIBMESH_CPPUNIT_TEST_SUITE (HeterogeneousNonlinearConstraintTest)
 
 CPPUNIT_TEST (testNonzeroDirichletValues)
 
 CPPUNIT_TEST_SUITE_END ()
 

Private Member Functions

void testNonzeroDirichletValues ()
 PetscNonlinearSolver enforces a constraint in each residual it hands PETSc.
 

Detailed Description

Definition at line 86 of file heterogeneous_nonlinear_constraint_test.C.

Member Function Documentation

◆ CPPUNIT_TEST()

HeterogeneousNonlinearConstraintTest::CPPUNIT_TEST ( testNonzeroDirichletValues  )

◆ CPPUNIT_TEST_SUITE_END()

HeterogeneousNonlinearConstraintTest::CPPUNIT_TEST_SUITE_END ( )

◆ LIBMESH_CPPUNIT_TEST_SUITE()

HeterogeneousNonlinearConstraintTest::LIBMESH_CPPUNIT_TEST_SUITE ( HeterogeneousNonlinearConstraintTest  )

◆ testNonzeroDirichletValues()

void HeterogeneousNonlinearConstraintTest::testNonzeroDirichletValues ( )
inlineprivate

PetscNonlinearSolver enforces a constraint in each residual it hands PETSc.

With nonzero DirichletBoundary values on both ends, the exact solution of -u'' = 0 is the line between them, which a converged solve has to reproduce

Definition at line 104 of file heterogeneous_nonlinear_constraint_test.C.

105 {
106 LOG_UNIT_TEST;
107
108 Mesh mesh(*TestCommWorld);
110
112 auto & sys = es.add_system<NonlinearImplicitSystem>("sys");
113 const auto u = sys.add_variable("u", FIRST, LAGRANGE);
114
115 // build_line's boundary ids
116 const boundary_id_type left_id = 0, right_id = 1;
117 const Real left_value = 2, right_value = 5;
118 sys.get_dof_map().add_dirichlet_boundary(
119 DirichletBoundary({left_id}, {u}, ConstFunction<Number>(left_value)));
120 sys.get_dof_map().add_dirichlet_boundary(
121 DirichletBoundary({right_id}, {u}, ConstFunction<Number>(right_value)));
122
123 LaplaceResidualAndJacobian assembly;
124 sys.nonlinear_solver->residual_and_jacobian_object = &assembly;
125
126 es.init();
127
128 // Start from an iterate that satisfies neither boundary value, so
129 // the constrained rows have to pull it to them
130 sys.solution->zero();
131 sys.solution->close();
132 sys.update();
133
134 sys.solve();
135
136 CPPUNIT_ASSERT(sys.nonlinear_solver->converged);
137
138 for (const Node * node : mesh.local_node_ptr_range())
139 {
140 const Real x = (*node)(0);
141 const Number exact = left_value + (right_value - left_value) * x;
142 LIBMESH_ASSERT_NUMBERS_EQUAL(
143 exact, (*sys.solution)(node->dof_number(sys.number(), u, 0)), TOLERANCE * TOLERANCE);
144 }
145 }
Function that returns a single value that never changes.
This class allows one to associate Dirichlet boundary values with a given set of mesh boundary ids an...
This is the EquationSystems class.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
Definition mesh.h:51
A Node is like a Point, but with more information.
Definition node.h:55
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
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.
Definition system.C:1344
static const boundary_id_type left_id
static const boundary_id_type right_id
MeshBase & mesh
void build_line(UnstructuredMesh &mesh, const unsigned int nx, const Real xmin=0., const Real xmax=1., const ElemType type=INVALID_ELEM, const bool gauss_lobatto_grid=false)
A specialized build_cube() for 1D meshes.
int8_t boundary_id_type
Definition id_types.h:51
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real

References libMesh::DofMap::add_dirichlet_boundary(), libMesh::EquationSystems::add_system(), libMesh::System::add_variable(), libMesh::MeshTools::Generation::build_line(), libMesh::EDGE2, libMesh::FIRST, libMesh::System::get_dof_map(), libMesh::EquationSystems::init(), libMesh::LAGRANGE, left_id, mesh, libMesh::NonlinearImplicitSystem::nonlinear_solver, libMesh::System::number(), libMesh::Real, right_id, libMesh::System::solution, libMesh::NonlinearImplicitSystem::solve(), TestCommWorld, libMesh::TOLERANCE, and libMesh::System::update().


The documentation for this class was generated from the following file: