Skip to content

Commit 139973a

Browse files
author
Edward Palmer
committed
Adds SolverOptions structure and SetSolverOptions method.
1 parent 17d9098 commit 139973a

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/problem_operators/problem_operator_base.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,25 @@ ProblemOperatorBase::ConstructJacobianSolver()
1212
precond->SetPrintLevel(GetGlobalPrintLevel());
1313

1414
auto solver = std::make_unique<mfem::HypreGMRES>(_problem._comm);
15-
16-
solver->SetTol(1e-16);
17-
solver->SetAbsTol(1e-16);
18-
solver->SetMaxIter(1000);
19-
solver->SetKDim(10);
20-
solver->SetPrintLevel(GetGlobalPrintLevel());
2115
solver->SetPreconditioner(*precond);
2216

2317
_jacobian_preconditioner = std::move(precond);
2418
_jacobian_solver = std::move(solver);
19+
20+
SolverOptions default_options;
21+
SetSolverOptions(default_options);
22+
}
23+
24+
void
25+
ProblemOperatorBase::SetSolverOptions(SolverOptions & options)
26+
{
27+
auto & solver = static_cast<mfem::HypreGMRES &>(*_jacobian_solver);
28+
29+
solver.SetTol(options._tolerance);
30+
solver.SetAbsTol(options._abs_tolerance);
31+
solver.SetMaxIter(options._max_iteration);
32+
solver.SetKDim(options._k_dim);
33+
solver.SetPrintLevel(options._print_level);
2534
}
2635

2736
void

src/problem_operators/problem_operator_base.hpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ class ProblemOperatorBase
2626
return static_cast<TSolver *>(_jacobian_preconditioner.get());
2727
}
2828

29+
/// A structure for setting solver options. Defaults have been set.
30+
struct SolverOptions
31+
{
32+
double _tolerance{1e-16};
33+
double _abs_tolerance{1e-16};
34+
35+
unsigned int _max_iteration{1000};
36+
37+
int _print_level{GetGlobalPrintLevel()};
38+
int _k_dim{10};
39+
};
40+
41+
/// Sets the solver's options. Override in derived classes.
42+
virtual void SetSolverOptions(SolverOptions & options);
43+
2944
protected:
3045
/// Use of protected constructor to only allow construction by derived classes.
3146
/// All problem operator classes are built on-top of this class and it should not

0 commit comments

Comments
 (0)