Skip to content

Commit f3746dc

Browse files
committed
Add a test using system parameters over equation system parameters
1 parent 65da3a6 commit f3746dc

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

tests/systems/systems_test.C

+73
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <libmesh/cell_tet4.h>
1414
#include <libmesh/zero_function.h>
1515
#include <libmesh/linear_implicit_system.h>
16+
#include <libmesh/nonlinear_implicit_system.h>
1617
#include <libmesh/transient_system.h>
1718
#include <libmesh/quadrature_gauss.h>
1819
#include <libmesh/node_elem.h>
@@ -1256,6 +1257,78 @@ public:
12561257
LIBMESH_ASSERT_FP_EQUAL(system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
12571258
}
12581259

1260+
1261+
void testSetSystemParameterOverEquationSystem()
1262+
{
1263+
LOG_UNIT_TEST;
1264+
1265+
ReplicatedMesh mesh(*TestCommWorld);
1266+
1267+
MeshTools::Generation::build_cube (mesh,
1268+
1,
1269+
0,
1270+
0,
1271+
0., 1.,
1272+
0., 0.,
1273+
0., 0.,
1274+
EDGE2);
1275+
1276+
Point new_point_a(2.);
1277+
Point new_point_b(3.);
1278+
Node* new_node_a = mesh.add_point( new_point_a );
1279+
Node* new_node_b = mesh.add_point( new_point_b );
1280+
auto new_edge_elem = mesh.add_elem(Elem::build(EDGE2));
1281+
new_edge_elem->set_node(0) = new_node_a;
1282+
new_edge_elem->set_node(1) = new_node_b;
1283+
1284+
mesh.elem_ref(0).subdomain_id() = 10;
1285+
mesh.elem_ref(1).subdomain_id() = 10;
1286+
1287+
mesh.prepare_for_use();
1288+
1289+
// Create an equation systems object.
1290+
EquationSystems equation_systems (mesh);
1291+
1292+
// Set some parameters to the equation system that would cause a failed solve
1293+
equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 0;
1294+
1295+
// Setup Linear Implicit system
1296+
LinearImplicitSystem & li_system =
1297+
equation_systems.add_system<LinearImplicitSystem> ("test");
1298+
li_system.add_variable ("u", libMesh::FIRST);
1299+
li_system.add_variable ("v", libMesh::FIRST);
1300+
li_system.add_variable ("w", libMesh::FIRST);
1301+
li_system.attach_assemble_function (assemble_matrix_and_rhs);
1302+
li_system.get_linear_solver()->set_solver_type(JACOBI);
1303+
li_system.get_linear_solver()->set_preconditioner_type(IDENTITY_PRECOND);
1304+
1305+
// Setup nonlinear Implicit system
1306+
NonlinearImplicitSystem & nli_system =
1307+
equation_systems.add_system<NonlinearImplicitSystem> ("test");
1308+
nli_system.add_variable ("u", libMesh::FIRST);
1309+
nli_system.add_variable ("v", libMesh::FIRST);
1310+
nli_system.add_variable ("w", libMesh::FIRST);
1311+
nli_system.attach_assemble_function (assemble_matrix_and_rhs);
1312+
nli_system.get_linear_solver()->set_solver_type(JACOBI);
1313+
nli_system.get_linear_solver()->set_preconditioner_type(IDENTITY_PRECOND);
1314+
1315+
// Set some parameters to the system that work for the solve
1316+
li_system.parameters.set<unsigned int>("linear solver maximum iterations") = 100;
1317+
nli_system.parameters.set<unsigned int>("linear solver maximum iterations") = 100;
1318+
1319+
// See the solve pass, indicating system parameters are used over equation system parameters
1320+
equation_systems.init ();
1321+
li_system.solve();
1322+
nli_system.solve();
1323+
1324+
// We set the solution to be 1 everywhere, so the final l1 norm of the
1325+
// solution is the product of the number of variables and number of nodes.
1326+
Real ref_l1_norm = static_cast<Real>(mesh.n_nodes() * li_system.n_vars());
1327+
1328+
LIBMESH_ASSERT_FP_EQUAL(li_system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
1329+
LIBMESH_ASSERT_FP_EQUAL(nli_system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
1330+
}
1331+
12591332
void testAssemblyWithDgFemContext()
12601333
{
12611334
LOG_UNIT_TEST;

0 commit comments

Comments
 (0)