www.mooseframework.org
Public Member Functions | Private Member Functions | Private Attributes | List of all members
LazyCoupleable Class Reference

Interface for objects that need coupling capabilities. More...

#include <LazyCoupleable.h>

Public Member Functions

 LazyCoupleable (const MooseObject *moose_object)
 Constructing the object. More...
 
virtual ~LazyCoupleable ()=default
 
void setFEProblemPtr (FEProblemBase *fe_problem)
 Sets the FEProblem pointer which can (and is expected) to happen long after this interface is constructed. More...
 

Private Member Functions

void init ()
 
unsigned intcoupled (const std::string &var_name, unsigned int comp=0)
 Returns the index for a coupled variable by name. More...
 

Private Attributes

const InputParameters_l_parameters
 
const std::string & _l_name
 The name of the object this interface is part of. More...
 
FEProblemBase_l_fe_problem
 Reference to FEProblemBase. More...
 
MooseApp_l_app
 Reference to the MooseApp. More...
 
std::map< std::string, std::unique_ptr< unsigned int > > _coupled_var_numbers
 Coupled vars whose values we provide. More...
 

Detailed Description

Interface for objects that need coupling capabilities.

Definition at line 24 of file LazyCoupleable.h.

Constructor & Destructor Documentation

◆ LazyCoupleable()

LazyCoupleable::LazyCoupleable ( const MooseObject moose_object)

Constructing the object.

Parameters
parametersParameters that come from constructing the object
nodaltrue if we need to couple with nodal values, otherwise false

Definition at line 20 of file LazyCoupleable.C.

21  : _l_parameters(moose_object->parameters()),
22  _l_name(_l_parameters.get<std::string>("_object_name")),
23  _l_fe_problem(nullptr),
24  _l_app(moose_object->getMooseApp())
25 {
26  for (const auto & var_name :
28  _coupled_var_numbers[var_name] = std::make_unique<unsigned int>(0);
29 }
std::map< std::string, std::unique_ptr< unsigned int > > _coupled_var_numbers
Coupled vars whose values we provide.
std::vector< std::pair< R1, R2 > > get(const std::string &param1, const std::string &param2) const
Combine two vector parameters into a single vector of pairs.
const std::string & _l_name
The name of the object this interface is part of.
std::set< std::string >::const_iterator coupledVarsBegin() const
Methods returning iterators to the coupled variables names stored in this InputParameters object...
const InputParameters & _l_parameters
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:45
std::set< std::string >::const_iterator coupledVarsEnd() const
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
MooseApp & _l_app
Reference to the MooseApp.
FEProblemBase * _l_fe_problem
Reference to FEProblemBase.
const InputParameters & parameters() const
Get the parameters of the object.

◆ ~LazyCoupleable()

virtual LazyCoupleable::~LazyCoupleable ( )
virtualdefault

Member Function Documentation

◆ coupled()

unsigned int & LazyCoupleable::coupled ( const std::string &  var_name,
unsigned int  comp = 0 
)
private

Returns the index for a coupled variable by name.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Index of coupled variable, if this is an optionally coupled variable that wasn't provided this will return a unique "invalid" index.

Definition at line 56 of file LazyCoupleable.C.

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 }
std::map< std::string, std::unique_ptr< unsigned int > > _coupled_var_numbers
Coupled vars whose values we provide.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
MooseApp & _l_app
Reference to the MooseApp.
FEProblemBase * _l_fe_problem
Reference to FEProblemBase.
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition: MooseApp.C:1483
void setFEProblemPtr(FEProblemBase *fe_problem)
Sets the FEProblem pointer which can (and is expected) to happen long after this interface is constru...

◆ init()

void LazyCoupleable::init ( )
private

Definition at line 39 of file LazyCoupleable.C.

Referenced by setFEProblemPtr().

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 }
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
std::map< std::string, std::unique_ptr< unsigned int > > _coupled_var_numbers
Coupled vars whose values we provide.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
unsigned int number() const
Get variable number coming from libMesh.
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...
auto max(const L &left, const R &right)
FEProblemBase * _l_fe_problem
Reference to FEProblemBase.

◆ setFEProblemPtr()

void LazyCoupleable::setFEProblemPtr ( FEProblemBase fe_problem)

Sets the FEProblem pointer which can (and is expected) to happen long after this interface is constructed.

Once this pointer is set, this interface can retrieve the information it requires from the underlying class and the internal methods can be called. Errors are throw if internal methods are called when this pointer is nullptr.

Definition at line 32 of file LazyCoupleable.C.

Referenced by coupled().

33 {
34  _l_fe_problem = fe_problem;
35  init();
36 }
FEProblemBase * _l_fe_problem
Reference to FEProblemBase.

Member Data Documentation

◆ _coupled_var_numbers

std::map<std::string, std::unique_ptr<unsigned int> > LazyCoupleable::_coupled_var_numbers
private

Coupled vars whose values we provide.

Definition at line 69 of file LazyCoupleable.h.

Referenced by coupled(), init(), and LazyCoupleable().

◆ _l_app

MooseApp& LazyCoupleable::_l_app
private

Reference to the MooseApp.

Definition at line 66 of file LazyCoupleable.h.

Referenced by coupled().

◆ _l_fe_problem

FEProblemBase* LazyCoupleable::_l_fe_problem
private

Reference to FEProblemBase.

Definition at line 63 of file LazyCoupleable.h.

Referenced by coupled(), init(), and setFEProblemPtr().

◆ _l_name

const std::string& LazyCoupleable::_l_name
private

The name of the object this interface is part of.

Definition at line 60 of file LazyCoupleable.h.

◆ _l_parameters

const InputParameters& LazyCoupleable::_l_parameters
private

Definition at line 57 of file LazyCoupleable.h.

Referenced by LazyCoupleable().


The documentation for this class was generated from the following files: