Skip to content

Commit 69f1be1

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 69f1be1

File tree

5 files changed

+22
-44
lines changed

5 files changed

+22
-44
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-12
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,6 @@ void LinearImplicitSystem::solve ()
118118
// Assemble the linear system
119119
this->assemble ();
120120

121-
// Get a reference to the EquationSystems
122-
const EquationSystems & es =
123-
this->get_equation_systems();
124-
125121
// If the linear solver hasn't been initialized, we do so here.
126122
if (libMesh::on_command_line("--solver-system-names"))
127123
linear_solver->init((this->name()+"_").c_str());
@@ -131,14 +127,7 @@ void LinearImplicitSystem::solve ()
131127
linear_solver->init_names(*this);
132128

133129
// 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");
130+
const auto [maxits, tol] = this->get_linear_solve_parameters();
142131

143132
if (_subset != nullptr)
144133
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

+11-9
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
@@ -1289,8 +1290,9 @@ public:
12891290
// Create an equation systems object.
12901291
EquationSystems equation_systems (mesh);
12911292

1292-
// Set some parameters to the equation system that would cause a failed solve
1293+
// Set some parameters to the equation system that would cause a failed test
12931294
equation_systems.parameters.set<unsigned int>("linear solver maximum iterations") = 0;
1295+
equation_systems.parameters.set<unsigned int>("nonlinear solver absolute residual tolerance") = 1e10;
12941296

12951297
// Setup Linear Implicit system
12961298
LinearImplicitSystem & li_system =
@@ -1313,21 +1315,21 @@ public:
13131315
nli_system.get_linear_solver()->set_preconditioner_type(IDENTITY_PRECOND);
13141316

13151317
// 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+
li_system.parameters.set<unsigned int>("linear solver maximum iterations") = 5;
1319+
nli_system.parameters.set<unsigned int>("nonlinear solver absolute residual tolerance") = 1e-10;
13181320

13191321
// See the solve pass, indicating system parameters are used over equation system parameters
13201322
equation_systems.init ();
13211323
li_system.solve();
13221324
nli_system.solve();
13231325

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

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-
}
1329+
// Check that the solution for the nonlinear system is converged
1330+
Real ref_l1_norm = static_cast<Real>(mesh.n_nodes() * li_system.n_vars());
1331+
LIBMESH_ASSERT_FP_EQUAL(nli_system.solution->l1_norm(), ref_l1_norm, TOLERANCE);
1332+
}
13311333

13321334
void testAssemblyWithDgFemContext()
13331335
{

0 commit comments

Comments
 (0)