https://mooseframework.inl.gov
MultiSystemSolveObject.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "MultiSystemSolveObject.h"
11 #include "FEProblemBase.h"
12 #include "LinearSystem.h"
13 #include "NonlinearSystem.h"
14 
17 {
19  params.addParam<std::vector<SolverSystemName>>(
20  "system_names",
21  "Names of the solver systems (both linear and nonlinear) that will be solved");
22  // Multi-system fixed point
23  // Defaults to false because of the difficulty of defining a good multi-system convergence
24  // criterion, unless we add a default one to the simulation?
25  params.addParam<bool>(
26  "multi_system_fixed_point",
27  false,
28  "Whether to perform fixed point (Picard) iterations between the nonlinear systems.");
29  params.addRangeCheckedParam<std::vector<Real>>(
30  "multi_system_fixed_point_relaxation_factor",
31  {1.0},
32  "multi_system_fixed_point_relaxation_factor>0 & multi_system_fixed_point_relaxation_factor<2",
33  "Relaxation factor(s) applied to system solution updates during multi-system fixed point "
34  "iterations; 1 disables relaxation. If one value is provided it is applied to every system; "
35  "otherwise the vector must match the number/order of systems being solved.");
36  params.addParam<ConvergenceName>(
37  "multi_system_fixed_point_convergence",
38  "Convergence object to determine the convergence of the multi-system fixed point iteration.");
39 
40  params.addParamNamesToGroup(
41  "system_names multi_system_fixed_point multi_system_fixed_point_convergence "
42  "multi_system_fixed_point_relaxation_factor",
43  "Multiple solver system");
44  return params;
45 }
46 
48  : SolveObject(ex),
49  _using_multi_sys_fp_iterations(getParam<bool>("multi_system_fixed_point")),
50  _multi_sys_fp_convergence(nullptr) // has not been created yet
51 
52 {
53  // Retrieve pointers to all the systems from the problem by default
54  const auto & nl_sys_names = _problem.getNonlinearSystemNames();
55  const auto & linear_sys_names = _problem.getLinearSystemNames();
56  if (!isParamValid("system_names"))
57  {
58  for (const auto & sys_name : nl_sys_names)
59  _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name)));
60  for (const auto & sys_name : linear_sys_names)
61  _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name)));
62  _num_nl_systems = nl_sys_names.size();
63  }
64  else
65  {
66  _num_nl_systems = 0;
67  // Retrieve pointers to all the user-specified systems in the order that the user specified them
68  for (const auto & sys_name : getParam<std::vector<SolverSystemName>>("system_names"))
69  {
70  if (std::find(nl_sys_names.begin(), nl_sys_names.end(), sys_name) != nl_sys_names.end())
71  {
72  _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name)));
74  }
75  else if (std::find(linear_sys_names.begin(), linear_sys_names.end(), sys_name) !=
76  linear_sys_names.end())
77  _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name)));
78  else
79  paramError("system_names",
80  "System '" + sys_name +
81  "' was not found in the Problem. Did you forget to declare it in the "
82  "[Problem] block?");
83  }
84  }
85 
86  if (_pars.isParamSetByUser("multi_system_fixed_point_relaxation_factor") &&
88  paramError("Can't use relaxation factors because multisystem fixed point iteration hasn't been "
89  "enabled!");
90 
92 }
93 
94 void
96 {
98  getParam<std::vector<Real>>("multi_system_fixed_point_relaxation_factor");
99  if (_multi_sys_fp_relax_factors.size() == 1)
101  else if (_multi_sys_fp_relax_factors.size() != _systems.size())
102  paramError("multi_system_fixed_point_relaxation_factor",
103  "Must provide either 1 value or " + Moose::stringify(_systems.size()) +
104  " values (one per system in the solve order).");
105 }
static InputParameters validParams()
const std::vector< NonlinearSystemName > & getNonlinearSystemNames() const
FEProblemBase & _problem
Reference to FEProblem.
Definition: SolveObject.h:47
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:40
const InputParameters & _pars
The object&#39;s parameters.
Definition: MooseBase.h:384
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:457
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseBase.h:406
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters emptyInputParameters()
const bool _using_multi_sys_fp_iterations
Whether we are using fixed point iterations for multi-system.
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:30
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:64
const std::vector< LinearSystemName > & getLinearSystemNames() const
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
unsigned int solverSysNum(const SolverSystemName &solver_sys_name) const override
unsigned int _num_nl_systems
Number of nonlinear systems.
SolverSystem & getSolverSystem(unsigned int sys_num)
Get non-constant reference to a solver system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
void addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition: MooseBase.h:199
MultiSystemSolveObject(Executioner &ex)
void setupMultiSystemFixedPointRelaxationFactors()
Initializes/expands the multi-system fixed point relaxation factors.
std::vector< SolverSystem * > _systems
Vector of pointers to the systems.
std::vector< Real > _multi_sys_fp_relax_factors
Per-system relaxation factors for multi-system fixed point iterations (expanded to match the number/o...
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...