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>

Inheritance diagram for LazyCoupleable:
[legend]

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 int & coupled (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 25 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 :
27  as_range(std::make_pair(_l_parameters.coupledVarsBegin(), _l_parameters.coupledVarsEnd())))
28  _coupled_var_numbers[var_name] = libmesh_make_unique<unsigned int>(0);
29 }
std::map< std::string, std::unique_ptr< unsigned int > > _coupled_var_numbers
Coupled vars whose values we provide.
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
std::set< std::string >::const_iterator coupledVarsEnd() const
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:57
MooseApp & _l_app
Reference to the MooseApp.
FEProblemBase * _l_fe_problem
Reference to FEProblemBase.
MooseApp & getMooseApp() const
Get the MooseApp this object is associated with.
Definition: MooseObject.h:86

◆ ~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.
Executioner * getExecutioner() const
Retrieve the Executioner for this App.
Definition: MooseApp.h:248
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
MooseApp & _l_app
Reference to the MooseApp.
FEProblemBase * _l_fe_problem
Reference to FEProblemBase.
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_NONLINEAR)
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
std::map< std::string, std::unique_ptr< unsigned int > > _coupled_var_numbers
Coupled vars whose values we provide.
virtual MooseVariableFEBase & getVariable(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) override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:208
unsigned int number() const
Get variable number coming from libMesh.
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 70 of file LazyCoupleable.h.

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

◆ _l_app

MooseApp& LazyCoupleable::_l_app
private

Reference to the MooseApp.

Definition at line 67 of file LazyCoupleable.h.

Referenced by coupled().

◆ _l_fe_problem

FEProblemBase* LazyCoupleable::_l_fe_problem
private

Reference to FEProblemBase.

Definition at line 64 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 61 of file LazyCoupleable.h.

◆ _l_parameters

const InputParameters& LazyCoupleable::_l_parameters
private

Definition at line 58 of file LazyCoupleable.h.

Referenced by LazyCoupleable().


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