Skip to content

Commit 1f18635

Browse files
committed
Add a parameter object on the system, use it for the nonlinear implicit system
refs #4006
1 parent cd33969 commit 1f18635

6 files changed

+60
-36
lines changed

include/systems/system.h

+4-13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "libmesh/fem_function_base.h"
2828
#include "libmesh/libmesh_common.h"
2929
#include "libmesh/parallel_object.h"
30+
#include "libmesh/parameters.h"
3031
#include "libmesh/qoi_set.h"
3132
#include "libmesh/reference_counted_object.h"
3233
#include "libmesh/tensor_value.h" // For point_hessian
@@ -60,7 +61,6 @@ class MeshBase;
6061
class Xdr;
6162
class DofMap;
6263
template <typename Output> class FunctionBase;
63-
class Parameters;
6464
class ParameterVector;
6565
class Point;
6666
class SensitivityData;
@@ -510,8 +510,6 @@ class System : public ReferenceCountedObject<System>,
510510
* user-provided cloneable functors.
511511
* A gradient \p g is only required/used for projecting onto finite
512512
* element spaces with continuous derivatives.
513-
* If non-default \p Parameters are to be used, they can be provided
514-
* in the \p parameters argument.
515513
*/
516514
void project_solution (FunctionBase<Number> * f,
517515
FunctionBase<Gradient> * g = nullptr) const;
@@ -522,8 +520,6 @@ class System : public ReferenceCountedObject<System>,
522520
* user-provided cloneable functors.
523521
* A gradient \p g is only required/used for projecting onto finite
524522
* element spaces with continuous derivatives.
525-
* If non-default \p Parameters are to be used, they can be provided
526-
* in the \p parameters argument.
527523
*/
528524
void project_solution (FEMFunctionBase<Number> * f,
529525
FEMFunctionBase<Gradient> * g = nullptr) const;
@@ -554,8 +550,6 @@ class System : public ReferenceCountedObject<System>,
554550
* user-provided cloneable functors.
555551
* A gradient \p g is only required/used for projecting onto finite
556552
* element spaces with continuous derivatives.
557-
* If non-default \p Parameters are to be used, they can be provided
558-
* in the \p parameters argument.
559553
*
560554
* Constrain the new vector using the requested adjoint rather than
561555
* primal constraints if is_adjoint is non-negative.
@@ -572,8 +566,6 @@ class System : public ReferenceCountedObject<System>,
572566
* user-provided cloneable functors.
573567
* A gradient \p g is only required/used for projecting onto finite
574568
* element spaces with continuous derivatives.
575-
* If non-default \p Parameters are to be used, they can be provided
576-
* in the \p parameters argument.
577569
*
578570
* Constrain the new vector using the requested adjoint rather than
579571
* primal constraints if is_adjoint is non-negative.
@@ -611,8 +603,6 @@ class System : public ReferenceCountedObject<System>,
611603
* user-provided cloneable functors.
612604
* A gradient \p g is only required/used for projecting onto finite
613605
* element spaces with continuous derivatives.
614-
* If non-default \p Parameters are to be used, they can be provided
615-
* in the \p parameters argument.
616606
*/
617607
void boundary_project_solution (const std::set<boundary_id_type> & b,
618608
const std::vector<unsigned int> & variables,
@@ -648,8 +638,6 @@ class System : public ReferenceCountedObject<System>,
648638
* user-provided cloneable functors.
649639
* A gradient \p g is only required/used for projecting onto finite
650640
* element spaces with continuous derivatives.
651-
* If non-default \p Parameters are to be used, they can be provided
652-
* in the \p parameters argument.
653641
*
654642
* Constrain the new vector using the requested adjoint rather than
655643
* primal constraints if is_adjoint is non-negative.
@@ -1531,6 +1519,9 @@ class System : public ReferenceCountedObject<System>,
15311519
*/
15321520
virtual void prolong_vectors ();
15331521

1522+
/// Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSystems
1523+
Parameters parameters;
1524+
15341525
/**
15351526
* Flag which tells the system to whether or not to
15361527
* call the user assembly function during each call to solve().

src/systems/eigen_system.C

+8-4
Original file line numberDiff line numberDiff line change
@@ -222,16 +222,20 @@ EigenSystem::solve_helper(SparseMatrix<Number> * const A,
222222
// Get the tolerance for the solver and the maximum
223223
// number of iterations. Here, we simply adopt the linear solver
224224
// specific parameters.
225-
const double tol =
225+
const double tol = parameters.have_parameter<Real>("linear solver tolerance") ?
226+
double(parameters.get<Real>("linear solver tolerance")) :
226227
double(es.parameters.get<Real>("linear solver tolerance"));
227228

228-
const unsigned int maxits =
229+
const unsigned int maxits = parameters.have_parameter<unsigned int>("linear solver maximum iterations") ?
230+
parameters.get<unsigned int>("linear solver maximum iterations") :
229231
es.parameters.get<unsigned int>("linear solver maximum iterations");
230232

231-
const unsigned int nev =
233+
const unsigned int nev = parameters.have_parameter<unsigned int>("eigenpairs") ?
234+
parameters.get<unsigned int>("eigenpairs") :
232235
es.parameters.get<unsigned int>("eigenpairs");
233236

234-
const unsigned int ncv =
237+
const unsigned int ncv = parameters.have_parameter<unsigned int>("basis vectors") ?
238+
parameters.get<unsigned int>("basis vectors") :
235239
es.parameters.get<unsigned int>("basis vectors");
236240

237241
std::pair<unsigned int, unsigned int> solve_data;

src/systems/frequency_system.C

+10-4
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,18 @@ void FrequencySystem::init_data ()
112112
// make sure we have frequencies to solve for
113113
if (!_finished_set_frequencies)
114114
{
115+
// not supported for now
116+
if (parameters.have_parameter<unsigned int> ("n_frequencies"))
117+
libmesh_error_msg("ERROR: Not supported");
118+
115119
// when this system was read from file, check
116120
// if this has a "n_frequencies" parameter,
117121
// and initialize us with these.
118122
if (es.parameters.have_parameter<unsigned int> ("n_frequencies"))
119123
{
120124
#ifndef NDEBUG
121125
const unsigned int n_freq =
122-
es.parameters.get<unsigned int>("n_frequencies");
126+
es.para) :<unsigned int>("n_frequencies");
123127

124128
libmesh_assert_greater (n_freq, 0);
125129
#endif
@@ -304,7 +308,7 @@ void FrequencySystem::set_frequencies (const std::vector<Number> & frequencies,
304308
unsigned int FrequencySystem::n_frequencies () const
305309
{
306310
libmesh_assert(_finished_set_frequencies);
307-
return this->get_equation_systems().parameters.get<unsigned int>("n_frequencies");
311+
return this->get_equation_systems().para) :<unsigned int>("n_frequencies");
308312
}
309313

310314

@@ -339,9 +343,11 @@ void FrequencySystem::solve (const unsigned int n_start,
339343
// Get the user-specified linear solver tolerance,
340344
// the user-specified maximum # of linear solver iterations,
341345
// the user-specified wave speed
342-
const Real tol =
346+
const Real tol = parameters.have_parameter<Real>("linear solver tolerance") ?
347+
double(parameters.get<Real>("linear solver tolerance")) :
343348
es.parameters.get<Real>("linear solver tolerance");
344-
const unsigned int maxits =
349+
const unsigned int maxits = parameters.have_parameter<unsigned int>("linear solver maximum iterations") ?
350+
parameters.get<unsigned int>("linear solver maximum iterations") :
345351
es.parameters.get<unsigned int>("linear solver maximum iterations");
346352

347353
// start solver loop

src/systems/implicit_system.C

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

12231223
std::pair<unsigned int, Real> ImplicitSystem::get_linear_solve_parameters() const
12241224
{
1225-
return std::make_pair(this->get_equation_systems().parameters.get<unsigned int>("linear solver maximum iterations"),
1226-
this->get_equation_systems().parameters.get<Real>("linear solver tolerance"));
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");
12271235
}
12281236

12291237

src/systems/linear_implicit_system.C

+4-2
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,13 @@ void LinearImplicitSystem::solve ()
131131
linear_solver->init_names(*this);
132132

133133
// Get the user-specified linear solver tolerance
134-
const double tol =
134+
const double tol = parameters.have_parameter<Real>("linear solver tolerance") ?
135+
double(parameters.get<Real>("linear solver tolerance")) :
135136
double(es.parameters.get<Real>("linear solver tolerance"));
136137

137138
// Get the user-specified maximum # of linear solver iterations
138-
const unsigned int maxits =
139+
const unsigned int maxits = parameters.have_parameter<unsigned int>("linear solver maximum iterations") ?
140+
parameters.get<unsigned int>("linear solver maximum iterations") :
139141
es.parameters.get<unsigned int>("linear solver maximum iterations");
140142

141143
if (_subset != nullptr)

src/systems/nonlinear_implicit_system.C

+24-11
Original file line numberDiff line numberDiff line change
@@ -118,40 +118,53 @@ void NonlinearImplicitSystem::set_solver_parameters ()
118118
this->get_equation_systems();
119119

120120
// Get the user-specified nonlinear solver tolerances
121-
const unsigned int maxits =
121+
const unsigned int maxits = parameters.have_parameter<unsigned int>("nonlinear solver maximum iterations") ?
122+
parameters.get<unsigned int>("nonlinear solver maximum iterations") :
122123
es.parameters.get<unsigned int>("nonlinear solver maximum iterations");
123124

124-
const unsigned int maxfuncs =
125+
const unsigned int maxfuncs = parameters.have_parameter<unsigned int>("nonlinear solver maximum function evaluations") ?
126+
parameters.get<unsigned int>("nonlinear solver maximum function evaluations") :
125127
es.parameters.get<unsigned int>("nonlinear solver maximum function evaluations");
126128

127-
const double abs_resid_tol =
129+
const double abs_resid_tol = parameters.have_parameter<Real>("nonlinear solver absolute residual tolerance") ?
130+
double(parameters.get<Real>("nonlinear solver absolute residual tolerance")) :
128131
double(es.parameters.get<Real>("nonlinear solver absolute residual tolerance"));
129132

130-
const double rel_resid_tol =
133+
const double rel_resid_tol = parameters.have_parameter<Real>("nonlinear solver relative residual tolerance") ?
134+
double(parameters.get<Real>("nonlinear solver relative residual tolerance")) :
131135
double(es.parameters.get<Real>("nonlinear solver relative residual tolerance"));
132136

133-
const double div_tol =
137+
const double div_tol = parameters.have_parameter<Real>("nonlinear solver divergence tolerance") ?
138+
double(parameters.get<Real>("nonlinear solver divergence tolerance")) :
134139
double(es.parameters.get<Real>("nonlinear solver divergence tolerance"));
135140

136-
const double abs_step_tol =
141+
const double abs_step_tol = parameters.have_parameter<Real>("nonlinear solver absolute step tolerance") ?
142+
double(parameters.get<Real>("nonlinear solver absolute step tolerance")) :
137143
double(es.parameters.get<Real>("nonlinear solver absolute step tolerance"));
138144

139-
const double rel_step_tol =
145+
const double rel_step_tol = parameters.have_parameter<Real>("nonlinear solver relative step tolerance")?
146+
double(parameters.get<Real>("nonlinear solver relative step tolerance")) :
140147
double(es.parameters.get<Real>("nonlinear solver relative step tolerance"));
141148

142149
// Get the user-specified linear solver tolerances
143-
const unsigned int maxlinearits =
150+
const unsigned int maxlinearits = parameters.have_parameter<unsigned int>("linear solver maximum iterations") ?
151+
parameters.get<unsigned int>("linear solver maximum iterations") :
144152
es.parameters.get<unsigned int>("linear solver maximum iterations");
145153

146-
const double linear_tol =
154+
const double linear_tol = parameters.have_parameter<Real>("linear solver tolerance") ?
155+
double(parameters.get<Real>("linear solver tolerance")) :
147156
double(es.parameters.get<Real>("linear solver tolerance"));
148157

149-
const double linear_min_tol =
158+
const double linear_min_tol = parameters.have_parameter<Real>("linear solver minimum tolerance") ?
159+
double(parameters.get<Real>("linear solver minimum tolerance")) :
150160
double(es.parameters.get<Real>("linear solver minimum tolerance"));
151161

152-
const bool reuse_preconditioner =
162+
const bool reuse_preconditioner = parameters.have_parameter<unsigned int>("reuse preconditioner") ?
163+
parameters.get<unsigned int>("reuse preconditioner") :
153164
es.parameters.get<bool>("reuse preconditioner");
154165
const unsigned int reuse_preconditioner_max_linear_its =
166+
parameters.have_parameter<unsigned int>("reuse preconditioner maximum linear iterations") ?
167+
parameters.get<unsigned int>("reuse preconditioner maximum linear iterations") :
155168
es.parameters.get<unsigned int>("reuse preconditioner maximum linear iterations");
156169

157170
// Set all the parameters on the NonlinearSolver

0 commit comments

Comments
 (0)