Line data Source code
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 : 15 : InputParameters 16 159132 : MultiSystemSolveObject::validParams() 17 : { 18 159132 : InputParameters params = emptyInputParameters(); 19 636528 : 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 477396 : params.addParam<bool>( 26 : "multi_system_fixed_point", 27 318264 : false, 28 : "Whether to perform fixed point (Picard) iterations between the nonlinear systems."); 29 1273056 : 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 636528 : 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 477396 : 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 159132 : return params; 45 0 : } 46 : 47 60680 : MultiSystemSolveObject::MultiSystemSolveObject(Executioner & ex) 48 : : SolveObject(ex), 49 121360 : _using_multi_sys_fp_iterations(getParam<bool>("multi_system_fixed_point")), 50 121360 : _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 60680 : const auto & nl_sys_names = _problem.getNonlinearSystemNames(); 55 60680 : const auto & linear_sys_names = _problem.getLinearSystemNames(); 56 182040 : if (!isParamValid("system_names")) 57 : { 58 119123 : for (const auto & sys_name : nl_sys_names) 59 59679 : _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name))); 60 59455 : for (const auto & sys_name : linear_sys_names) 61 11 : _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name))); 62 59444 : _num_nl_systems = nl_sys_names.size(); 63 : } 64 : else 65 : { 66 1236 : _num_nl_systems = 0; 67 : // Retrieve pointers to all the user-specified systems in the order that the user specified them 68 5041 : for (const auto & sys_name : getParam<std::vector<SolverSystemName>>("system_names")) 69 : { 70 1333 : if (std::find(nl_sys_names.begin(), nl_sys_names.end(), sys_name) != nl_sys_names.end()) 71 : { 72 116 : _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name))); 73 116 : _num_nl_systems++; 74 : } 75 1217 : else if (std::find(linear_sys_names.begin(), linear_sys_names.end(), sys_name) != 76 2434 : linear_sys_names.end()) 77 1217 : _systems.push_back(&_problem.getSolverSystem(_problem.solverSysNum(sys_name))); 78 : else 79 0 : paramError("system_names", 80 0 : "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 182325 : if (_pars.isParamSetByUser("multi_system_fixed_point_relaxation_factor") && 87 285 : !_using_multi_sys_fp_iterations) 88 0 : paramError("Can't use relaxation factors because multisystem fixed point iteration hasn't been " 89 : "enabled!"); 90 : 91 60680 : setupMultiSystemFixedPointRelaxationFactors(); 92 60680 : } 93 : 94 : void 95 60680 : MultiSystemSolveObject::setupMultiSystemFixedPointRelaxationFactors() 96 : { 97 : _multi_sys_fp_relax_factors = 98 121360 : getParam<std::vector<Real>>("multi_system_fixed_point_relaxation_factor"); 99 60680 : if (_multi_sys_fp_relax_factors.size() == 1) 100 60680 : _multi_sys_fp_relax_factors.resize(_systems.size(), _multi_sys_fp_relax_factors[0]); 101 0 : else if (_multi_sys_fp_relax_factors.size() != _systems.size()) 102 0 : paramError("multi_system_fixed_point_relaxation_factor", 103 0 : "Must provide either 1 value or " + Moose::stringify(_systems.size()) + 104 : " values (one per system in the solve order)."); 105 60680 : }