https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LazyCoupleable.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 "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
21 : _l_parameters(moose_object->parameters()),
22 _l_name(moose_object->name()),
23 _l_fe_problem(nullptr),
24 _l_app(moose_object->getMooseApp())
25{
26 for (const auto & var_name :
27 as_range(std::make_pair(_l_parameters.coupledVarsBegin(), _l_parameters.coupledVarsEnd())))
28 _coupled_var_numbers[var_name] = std::make_unique<unsigned int>(0);
29}
30
31void
33{
34 _l_fe_problem = fe_problem;
35 init();
36}
37
38void
40{
41 for (const auto & var_pair : _coupled_var_numbers)
42 {
43 if (!_l_fe_problem->hasVariable(var_pair.first))
44 mooseError("Unable to find variable ", var_pair.first);
45
46 auto & moose_var = _l_fe_problem->getVariable(
48 if (moose_var.kind() == Moose::VAR_SOLVER)
49 *(var_pair.second) = moose_var.number();
50 else
51 *(var_pair.second) = std::numeric_limits<unsigned int>::max() - moose_var.number();
52 }
53}
54
55unsigned int &
56LazyCoupleable::coupled(const std::string & var_name, unsigned int /*comp*/)
57{
58 if (!_l_fe_problem)
59 {
60 auto executioner_ptr = _l_app.getExecutioner();
61 if (!executioner_ptr)
62 mooseError("Executioner is nullptr in LazyCoupleable. You cannot call the \"coupled\" method "
63 "until the add_algebraic_rm task");
64 setFEProblemPtr(&executioner_ptr->feProblem());
65 }
66
67 const auto & var_pair = _coupled_var_numbers.find(var_name);
68 mooseAssert(var_pair != _coupled_var_numbers.end(), "Internal error in LazyCoupleable");
69
70 return *(var_pair->second);
71}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
std::set< std::string >::const_iterator coupledVarsEnd() const
std::set< std::string >::const_iterator coupledVarsBegin() const
Methods returning iterators to the coupled variables names stored in this InputParameters object.
FEProblemBase * _l_fe_problem
Reference to FEProblemBase.
unsigned int & coupled(const std::string &var_name, unsigned int comp=0)
Returns the index for a coupled variable by name.
const InputParameters & _l_parameters
LazyCoupleable(const MooseObject *moose_object)
Constructing the object.
MooseApp & _l_app
Reference to the MooseApp.
std::map< std::string, std::unique_ptr< unsigned int > > _coupled_var_numbers
Coupled vars whose values we provide.
void setFEProblemPtr(FEProblemBase *fe_problem)
Sets the FEProblem pointer which can (and is expected) to happen long after this interface is constru...
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition MooseApp.C:2015
Every object that can be built by the factory should be derived from this class.
Definition MooseObject.h:31
unsigned int number() const
Get variable number coming from libMesh.
@ VAR_FIELD_ANY
Definition MooseTypes.h:781
@ VAR_ANY
Definition MooseTypes.h:772
@ VAR_SOLVER
Definition MooseTypes.h:770