Skip to content

Commit 3f9135c

Browse files
committed
Add APIs for name prefixing
1 parent 89dfe77 commit 3f9135c

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

include/systems/system.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1927,6 +1927,22 @@ class System : public ReferenceCountedObject<System>,
19271927
*/
19281928
void prefer_hash_table_matrix_assembly(bool preference);
19291929

1930+
/**
1931+
* Instructs this system to prefix solve options with its name for solvers that leverage prefixes
1932+
*/
1933+
void prefix_with_name(bool value) { _prefix_with_name = value; }
1934+
1935+
/**
1936+
* @returns Whether we are name prefixing
1937+
*/
1938+
[[nodiscard]] bool prefix_with_name() const { return _prefix_with_name; }
1939+
1940+
/**
1941+
* @returns A prefix that may be applied to solver options. Note that this
1942+
* prefix is only used if \p prefix_with_name()
1943+
*/
1944+
std::string prefix() const { return this->name() + "_"; }
1945+
19301946
protected:
19311947

19321948
/**
@@ -2307,6 +2323,11 @@ class System : public ReferenceCountedObject<System>,
23072323
* Whether any of our matrices require an initial sparsity pattern computation in order to determine preallocation
23082324
*/
23092325
bool _require_sparsity_pattern;
2326+
2327+
/**
2328+
* Whether we are name prefixing solver options
2329+
*/
2330+
bool _prefix_with_name;
23102331
};
23112332

23122333

src/systems/continuation_system.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ ContinuationSystem::ContinuationSystem (EquationSystems & es,
6565
// moved.
6666
linear_solver = LinearSolver<Number>::build(es.comm());
6767

68-
if (libMesh::on_command_line("--solver-system-names"))
69-
linear_solver->init((this->name()+"_").c_str());
68+
if (this->prefix_with_name())
69+
linear_solver->init(this->prefix().c_str());
7070
else
7171
linear_solver->init();
7272

src/systems/implicit_system.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,8 @@ LinearSolver<Number> * ImplicitSystem::get_linear_solver() const
12081208

12091209
linear_solver = LinearSolver<Number>::build(this->comm());
12101210

1211-
if (libMesh::on_command_line("--solver-system-names"))
1212-
linear_solver->init((this->name() + "_").c_str());
1211+
if (this->prefix_with_name())
1212+
linear_solver->init(this->prefix().c_str());
12131213
else
12141214
linear_solver->init();
12151215

src/systems/linear_implicit_system.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ void LinearImplicitSystem::solve ()
123123
this->get_equation_systems();
124124

125125
// If the linear solver hasn't been initialized, we do so here.
126-
if (libMesh::on_command_line("--solver-system-names"))
127-
linear_solver->init((this->name()+"_").c_str());
126+
if (this->prefix_with_name())
127+
linear_solver->init(this->prefix().c_str());
128128
else
129129
linear_solver->init();
130130

src/systems/nonlinear_implicit_system.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ void NonlinearImplicitSystem::solve ()
201201
}
202202
else
203203
{
204-
if (libMesh::on_command_line("--solver-system-names"))
205-
nonlinear_solver->init((this->name()+"_").c_str());
204+
if (this->prefix_with_name())
205+
nonlinear_solver->init(this->prefix().c_str());
206206
else
207207
nonlinear_solver->init();
208208

src/systems/system.C

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,11 @@ System::System (EquationSystems & es,
9999
_hide_output (false),
100100
project_with_constraints (true),
101101
_prefer_hash_table_matrix_assembly(false),
102-
_require_sparsity_pattern (false)
102+
_require_sparsity_pattern (false),
103+
_prefix_with_name (false)
103104
{
105+
if (libMesh::on_command_line("--solver-system-names"))
106+
this->prefix_with_name(true);
104107
}
105108

106109

0 commit comments

Comments
 (0)