Skip to content

Commit 7680964

Browse files
committed
Address Roy's review:
- centralize change in get_linear_solve_parameters - enable the test - use the number of iterations for the test
1 parent f3746dc commit 7680964

File tree

5 files changed

+17
-39
lines changed

5 files changed

+17
-39
lines changed

src/systems/frequency_system.C

+1-6
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,7 @@ void FrequencySystem::solve (const unsigned int n_start,
343343
// Get the user-specified linear solver tolerance,
344344
// the user-specified maximum # of linear solver iterations,
345345
// the user-specified wave speed
346-
const Real tol = parameters.have_parameter<Real>("linear solver tolerance") ?
347-
double(parameters.get<Real>("linear solver tolerance")) :
348-
es.parameters.get<Real>("linear solver tolerance");
349-
const unsigned int maxits = parameters.have_parameter<unsigned int>("linear solver maximum iterations") ?
350-
parameters.get<unsigned int>("linear solver maximum iterations") :
351-
es.parameters.get<unsigned int>("linear solver maximum iterations");
346+
const auto [maxits, tol] = this->get_linear_solve_parameters();
352347

353348
// start solver loop
354349
for (unsigned int n=n_start; n<= n_stop; n++)

src/systems/implicit_system.C

+8-10
Original file line numberDiff line numberDiff line change
@@ -1222,16 +1222,14 @@ LinearSolver<Number> * ImplicitSystem::get_linear_solver() const
12221222

12231223
std::pair<unsigned int, Real> ImplicitSystem::get_linear_solve_parameters() const
12241224
{
1225-
if (parameters.have_parameter<unsigned int>("linear solver maximum iterations") &&
1226-
parameters.have_parameter<Real>("linear solver tolerance"))
1227-
return std::make_pair(parameters.get<unsigned int>("linear solver maximum iterations"),
1228-
parameters.get<Real>("linear solver tolerance"));
1229-
else if (!parameters.have_parameter<unsigned int>("linear solver maximum iterations") &&
1230-
!parameters.have_parameter<Real>("linear solver tolerance"))
1231-
return std::make_pair(this->get_equation_systems().parameters.get<unsigned int>("linear solver maximum iterations"),
1232-
this->get_equation_systems().parameters.get<Real>("linear solver tolerance"));
1233-
else
1234-
libmesh_error_msg("ERROR: Insufficient linear solver parameters");
1225+
return std::make_pair(
1226+
parameters.have_parameter<unsigned int>("linear solver maximum iterations")
1227+
? parameters.get<unsigned int>("linear solver maximum iterations")
1228+
: this->get_equation_systems().parameters.get<unsigned int>(
1229+
"linear solver maximum iterations"),
1230+
parameters.have_parameter<Real>("linear solver tolerance")
1231+
? parameters.get<Real>("linear solver tolerance")
1232+
: this->get_equation_systems().parameters.get<Real>("linear solver tolerance"));
12351233
}
12361234

12371235

src/systems/linear_implicit_system.C

+1-8
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,7 @@ void LinearImplicitSystem::solve ()
131131
linear_solver->init_names(*this);
132132

133133
// Get the user-specified linear solver tolerance
134-
const double tol = parameters.have_parameter<Real>("linear solver tolerance") ?
135-
double(parameters.get<Real>("linear solver tolerance")) :
136-
double(es.parameters.get<Real>("linear solver tolerance"));
137-
138-
// Get the user-specified maximum # of linear solver iterations
139-
const unsigned int maxits = parameters.have_parameter<unsigned int>("linear solver maximum iterations") ?
140-
parameters.get<unsigned int>("linear solver maximum iterations") :
141-
es.parameters.get<unsigned int>("linear solver maximum iterations");
134+
const auto [maxits, tol] = this->get_linear_solve_parameters();
142135

143136
if (_subset != nullptr)
144137
linear_solver->restrict_solve_to(&_subset->dof_ids(),_subset_solve_mode);

src/systems/nonlinear_implicit_system.C

+1-7
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,7 @@ void NonlinearImplicitSystem::set_solver_parameters ()
147147
double(es.parameters.get<Real>("nonlinear solver relative step tolerance"));
148148

149149
// Get the user-specified linear solver tolerances
150-
const unsigned int maxlinearits = parameters.have_parameter<unsigned int>("linear solver maximum iterations") ?
151-
parameters.get<unsigned int>("linear solver maximum iterations") :
152-
es.parameters.get<unsigned int>("linear solver maximum iterations");
153-
154-
const double linear_tol = parameters.have_parameter<Real>("linear solver tolerance") ?
155-
double(parameters.get<Real>("linear solver tolerance")) :
156-
double(es.parameters.get<Real>("linear solver tolerance"));
150+
const auto [maxlinearits, linear_tol] = this->get_linear_solve_parameters();
157151

158152
const double linear_min_tol = parameters.have_parameter<Real>("linear solver minimum tolerance") ?
159153
double(parameters.get<Real>("linear solver minimum tolerance")) :

tests/systems/systems_test.C

+6-8
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ public:
472472
CPPUNIT_TEST( test3DProjectVectorFEHex20 );
473473
CPPUNIT_TEST( test3DProjectVectorFEHex27 );
474474
#ifdef LIBMESH_HAVE_SOLVER
475+
CPPUNIT_TEST( testSetSystemParameterOverEquationSystem);
475476
CPPUNIT_TEST( testAssemblyWithDgFemContext );
476477
#endif
477478
#endif // LIBMESH_DIM > 2
@@ -1313,20 +1314,17 @@ public:
13131314
nli_system.get_linear_solver()->set_preconditioner_type(IDENTITY_PRECOND);
13141315

13151316
// 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;
1317+
li_system.parameters.set<unsigned int>("linear solver maximum iterations") = 5;
1318+
nli_system.parameters.set<unsigned int>("linear solver maximum iterations") = 5;
13181319

13191320
// See the solve pass, indicating system parameters are used over equation system parameters
13201321
equation_systems.init ();
13211322
li_system.solve();
13221323
nli_system.solve();
13231324

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);
1325+
// Check that the number of iterations from the systems got obeyed
1326+
CPPUNIT_ASSERT_EQUAL(li_system.n_linear_iterations(), 5);
1327+
CPPUNIT_ASSERT_EQUAL(nli_system.n_linear_iterations(), 5);
13301328
}
13311329

13321330
void testAssemblyWithDgFemContext()

0 commit comments

Comments
 (0)