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 "LazyCoupleable.h" 11 : #include "FEProblem.h" 12 : #include "MooseVariable.h" 13 : #include "InputParameters.h" 14 : #include "MooseObject.h" 15 : #include "MooseApp.h" 16 : #include "Executioner.h" 17 : 18 : #include "libmesh/simple_range.h" 19 : 20 0 : LazyCoupleable::LazyCoupleable(const MooseObject * moose_object) 21 0 : : _l_parameters(moose_object->parameters()), 22 0 : _l_name(_l_parameters.get<std::string>("_object_name")), 23 0 : _l_fe_problem(nullptr), 24 0 : _l_app(moose_object->getMooseApp()) 25 : { 26 0 : for (const auto & var_name : 27 0 : as_range(std::make_pair(_l_parameters.coupledVarsBegin(), _l_parameters.coupledVarsEnd()))) 28 0 : _coupled_var_numbers[var_name] = std::make_unique<unsigned int>(0); 29 0 : } 30 : 31 : void 32 0 : LazyCoupleable::setFEProblemPtr(FEProblemBase * fe_problem) 33 : { 34 0 : _l_fe_problem = fe_problem; 35 0 : init(); 36 0 : } 37 : 38 : void 39 0 : LazyCoupleable::init() 40 : { 41 0 : for (const auto & var_pair : _coupled_var_numbers) 42 : { 43 0 : if (!_l_fe_problem->hasVariable(var_pair.first)) 44 0 : mooseError("Unable to find variable ", var_pair.first); 45 : 46 0 : auto & moose_var = _l_fe_problem->getVariable( 47 0 : 0, var_pair.first, Moose::VarKindType::VAR_ANY, Moose::VarFieldType::VAR_FIELD_ANY); 48 0 : if (moose_var.kind() == Moose::VAR_SOLVER) 49 0 : *(var_pair.second) = moose_var.number(); 50 : else 51 0 : *(var_pair.second) = std::numeric_limits<unsigned int>::max() - moose_var.number(); 52 : } 53 0 : } 54 : 55 : unsigned int & 56 0 : LazyCoupleable::coupled(const std::string & var_name, unsigned int /*comp*/) 57 : { 58 0 : if (!_l_fe_problem) 59 : { 60 0 : auto executioner_ptr = _l_app.getExecutioner(); 61 0 : if (!executioner_ptr) 62 0 : mooseError("Executioner is nullptr in LazyCoupleable. You cannot call the \"coupled\" method " 63 : "until the add_algebraic_rm task"); 64 0 : setFEProblemPtr(&executioner_ptr->feProblem()); 65 : } 66 : 67 0 : const auto & var_pair = _coupled_var_numbers.find(var_name); 68 : mooseAssert(var_pair != _coupled_var_numbers.end(), "Internal error in LazyCoupleable"); 69 : 70 0 : return *(var_pair->second); 71 : }