Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 730214d

Browse files
committedNov 15, 2024·
Add a test using system parameters over equation system parameters
1 parent 65da3a6 commit 730214d

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
 

‎tests/systems/systems_test.C

+72
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,78 @@ public:
12561256
LIBMESH_ASSERT_FP_EQUAL(system.solution->l1_norm(), ref_l1_norm, TOLERANCE*TOLERANCE);
12571257
}
12581258

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

0 commit comments

Comments
 (0)
Please sign in to comment.