www.mooseframework.org
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ScalarCoupleable Class Reference

Interface for objects that needs scalar coupling capabilities. More...

#include <ScalarCoupleable.h>

Inheritance diagram for ScalarCoupleable:
[legend]

Public Member Functions

 ScalarCoupleable (const MooseObject *moose_object)
 Constructing the object. More...
 
virtual ~ScalarCoupleable ()
 Destructor for object. More...
 
const std::vector< MooseVariableScalar * > & getCoupledMooseScalarVars ()
 Get the list of coupled scalar variables. More...
 

Protected Member Functions

virtual bool isCoupledScalar (const std::string &var_name, unsigned int i=0)
 Returns true if a variables has been coupled_as name. More...
 
virtual unsigned int coupledScalarComponents (const std::string &var_name)
 Return the number of components to the coupled scalar variable. More...
 
virtual unsigned int coupledScalar (const std::string &var_name, unsigned int comp=0)
 Returns the index for a scalar coupled variable by name. More...
 
virtual Order coupledScalarOrder (const std::string &var_name, unsigned int comp=0)
 Returns the order for a scalar coupled variable by name. More...
 
virtual VariableValuecoupledScalarValue (const std::string &var_name, unsigned int comp=0)
 Returns value of a scalar coupled variable. More...
 
virtual VariableValuecoupledScalarValueOld (const std::string &var_name, unsigned int comp=0)
 Returns the old (previous time step) value of a scalar coupled variable. More...
 
virtual VariableValuecoupledScalarValueOlder (const std::string &var_name, unsigned int comp=0)
 Returns the older (two time steps previous) value of a scalar coupled variable. More...
 
virtual VariableValuecoupledScalarDot (const std::string &var_name, unsigned int comp=0)
 Returns the time derivative of a scalar coupled variable. More...
 
virtual VariableValuecoupledScalarDotDu (const std::string &var_name, unsigned int comp=0)
 Time derivative of a scalar coupled variable with respect to the coefficients. More...
 
VariableValuegetDefaultValue (const std::string &var_name)
 Helper method to return (and insert if necessary) the default value for an uncoupled variable. More...
 
MooseVariableScalargetScalarVar (const std::string &var_name, unsigned int comp)
 Extract pointer to a scalar coupled variable. More...
 

Protected Attributes

const InputParameters_sc_parameters
 
FEProblemBase_sc_fe_problem
 
std::map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
 Coupled vars whose values we provide. More...
 
std::map< std::string, VariableValue * > _default_value
 Will hold the default value for optional coupled scalar variables. More...
 
std::vector< MooseVariableScalar * > _coupled_moose_scalar_vars
 Vector of coupled variables. More...
 
bool _sc_is_implicit
 True if implicit value is required. More...
 
const InputParameters_coupleable_params
 Local InputParameters. More...
 

Detailed Description

Interface for objects that needs scalar coupling capabilities.

Definition at line 38 of file ScalarCoupleable.h.

Constructor & Destructor Documentation

ScalarCoupleable::ScalarCoupleable ( const MooseObject moose_object)

Constructing the object.

Parameters
parametersParameters that come from constructing the object

Definition at line 23 of file ScalarCoupleable.C.

24  : _sc_parameters(moose_object->parameters()),
26  _sc_is_implicit(_sc_parameters.have_parameter<bool>("implicit")
27  ? _sc_parameters.get<bool>("implicit")
28  : true),
30 {
31  SubProblem & problem = *_sc_parameters.get<SubProblem *>("_subproblem");
32 
33  THREAD_ID tid =
34  _sc_parameters.have_parameter<THREAD_ID>("_tid") ? _sc_parameters.get<THREAD_ID>("_tid") : 0;
35 
36  // Coupling
37  for (std::set<std::string>::const_iterator iter = _sc_parameters.coupledVarsBegin();
39  ++iter)
40  {
41  std::string name = *iter;
42  if (_sc_parameters.getVecMooseType(*iter) != std::vector<std::string>())
43  {
44  std::vector<std::string> vars = _sc_parameters.getVecMooseType(*iter);
45  for (const auto & coupled_var_name : vars)
46  {
47  if (problem.hasScalarVariable(coupled_var_name))
48  {
49  MooseVariableScalar * scalar_var = &problem.getScalarVariable(tid, coupled_var_name);
50  _coupled_scalar_vars[name].push_back(scalar_var);
51  _coupled_moose_scalar_vars.push_back(scalar_var);
52  }
53  else if (problem.hasVariable(coupled_var_name))
54  ; // ignore normal variables
55  else
56  mooseError("Coupled variable '" + coupled_var_name + "' was not found\n");
57  }
58  }
59  }
60 }
virtual bool hasVariable(const std::string &var_name)=0
std::set< std::string >::const_iterator coupledVarsEnd() const
std::vector< std::string > getVecMooseType(const std::string &name) const
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name)=0
Returns the scalar variable reference from whichever system contains it.
FEProblemBase & _sc_fe_problem
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
const InputParameters & _coupleable_params
Local InputParameters.
bool _sc_is_implicit
True if implicit value is required.
T getCheckedPointerParam(const std::string &name, const std::string &error_string="") const
Verifies that the requested parameter exists and is not NULL and returns it to the caller...
std::map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.
const InputParameters & _sc_parameters
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:53
std::vector< MooseVariableScalar * > _coupled_moose_scalar_vars
Vector of coupled variables.
Class for scalar variables (they are different).
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
std::set< std::string >::const_iterator coupledVarsBegin() const
Methods returning iterators to the coupled variables names stored in this InputParameters object...
virtual bool hasScalarVariable(const std::string &var_name)=0
Returns a Boolean indicating whether any system contains a variable with the name provided...
unsigned int THREAD_ID
Definition: MooseTypes.h:79
ScalarCoupleable::~ScalarCoupleable ( )
virtual

Destructor for object.

Definition at line 62 of file ScalarCoupleable.C.

63 {
64  for (auto & it : _default_value)
65  {
66  it.second->release();
67  delete it.second;
68  }
69 }
std::map< std::string, VariableValue * > _default_value
Will hold the default value for optional coupled scalar variables.

Member Function Documentation

unsigned int ScalarCoupleable::coupledScalar ( const std::string &  var_name,
unsigned int  comp = 0 
)
protectedvirtual

Returns the index for a scalar coupled variable by name.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Index of coupled variable

Definition at line 99 of file ScalarCoupleable.C.

Referenced by ParsedODEKernel::ParsedODEKernel().

100 {
101  return getScalarVar(var_name, comp)->number();
102 }
MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp)
Extract pointer to a scalar coupled variable.
unsigned int number() const
Get variable number coming from libMesh.
unsigned int ScalarCoupleable::coupledScalarComponents ( const std::string &  var_name)
protectedvirtual

Return the number of components to the coupled scalar variable.

Parameters
var_nameThe of the coupled variable

Definition at line 189 of file ScalarCoupleable.C.

190 {
191  return _coupled_scalar_vars[var_name].size();
192 }
std::map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.
VariableValue & ScalarCoupleable::coupledScalarDot ( const std::string &  var_name,
unsigned int  comp = 0 
)
protectedvirtual

Returns the time derivative of a scalar coupled variable.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Reference to a time derivative VariableValue for the coupled variable

Definition at line 161 of file ScalarCoupleable.C.

162 {
163  MooseVariableScalar * var = getScalarVar(var_name, comp);
164  return var->uDot();
165 }
VariableValue & uDot()
MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp)
Extract pointer to a scalar coupled variable.
Class for scalar variables (they are different).
VariableValue & ScalarCoupleable::coupledScalarDotDu ( const std::string &  var_name,
unsigned int  comp = 0 
)
protectedvirtual

Time derivative of a scalar coupled variable with respect to the coefficients.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Reference to a VariableValue containing the time derivative of the coupled variable with respect to the coefficients

Definition at line 168 of file ScalarCoupleable.C.

169 {
170  MooseVariableScalar * var = getScalarVar(var_name, comp);
171  return var->duDotDu();
172 }
VariableValue & duDotDu()
MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp)
Extract pointer to a scalar coupled variable.
Class for scalar variables (they are different).
Order ScalarCoupleable::coupledScalarOrder ( const std::string &  var_name,
unsigned int  comp = 0 
)
protectedvirtual

Returns the order for a scalar coupled variable by name.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Order of coupled variable

Definition at line 105 of file ScalarCoupleable.C.

106 {
107  if (!isCoupledScalar(var_name, comp))
109 
110  return getScalarVar(var_name, comp)->order();
111 }
virtual bool isCoupledScalar(const std::string &var_name, unsigned int i=0)
Returns true if a variables has been coupled_as name.
FEProblemBase & _sc_fe_problem
Order getMaxScalarOrder() const
MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp)
Extract pointer to a scalar coupled variable.
Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int...
VariableValue & ScalarCoupleable::coupledScalarValue ( const std::string &  var_name,
unsigned int  comp = 0 
)
protectedvirtual

Returns value of a scalar coupled variable.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Reference to a VariableValue for the coupled variable

Definition at line 128 of file ScalarCoupleable.C.

Referenced by ParsedODEKernel::ParsedODEKernel().

129 {
130  if (!isCoupledScalar(var_name, comp))
131  return *getDefaultValue(var_name);
132 
133  MooseVariableScalar * var = getScalarVar(var_name, comp);
134  return (_sc_is_implicit) ? var->sln() : var->slnOld();
135 }
VariableValue & sln()
virtual bool isCoupledScalar(const std::string &var_name, unsigned int i=0)
Returns true if a variables has been coupled_as name.
VariableValue * getDefaultValue(const std::string &var_name)
Helper method to return (and insert if necessary) the default value for an uncoupled variable...
MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp)
Extract pointer to a scalar coupled variable.
bool _sc_is_implicit
True if implicit value is required.
Class for scalar variables (they are different).
VariableValue & slnOld()
VariableValue & ScalarCoupleable::coupledScalarValueOld ( const std::string &  var_name,
unsigned int  comp = 0 
)
protectedvirtual

Returns the old (previous time step) value of a scalar coupled variable.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Reference to a old VariableValue for the coupled variable

Definition at line 138 of file ScalarCoupleable.C.

139 {
140  if (!isCoupledScalar(var_name, comp))
141  return *getDefaultValue(var_name);
142 
143  MooseVariableScalar * var = getScalarVar(var_name, comp);
144  return (_sc_is_implicit) ? var->slnOld() : var->slnOlder();
145 }
virtual bool isCoupledScalar(const std::string &var_name, unsigned int i=0)
Returns true if a variables has been coupled_as name.
VariableValue * getDefaultValue(const std::string &var_name)
Helper method to return (and insert if necessary) the default value for an uncoupled variable...
MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp)
Extract pointer to a scalar coupled variable.
bool _sc_is_implicit
True if implicit value is required.
Class for scalar variables (they are different).
VariableValue & slnOlder()
VariableValue & slnOld()
VariableValue & ScalarCoupleable::coupledScalarValueOlder ( const std::string &  var_name,
unsigned int  comp = 0 
)
protectedvirtual

Returns the older (two time steps previous) value of a scalar coupled variable.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Reference to a older VariableValue for the coupled variable

Definition at line 148 of file ScalarCoupleable.C.

149 {
150  if (!isCoupledScalar(var_name, comp))
151  return *getDefaultValue(var_name);
152 
153  MooseVariableScalar * var = getScalarVar(var_name, comp);
154  if (_sc_is_implicit)
155  return var->slnOlder();
156  else
157  mooseError("Older values not available for explicit schemes");
158 }
virtual bool isCoupledScalar(const std::string &var_name, unsigned int i=0)
Returns true if a variables has been coupled_as name.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
VariableValue * getDefaultValue(const std::string &var_name)
Helper method to return (and insert if necessary) the default value for an uncoupled variable...
MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp)
Extract pointer to a scalar coupled variable.
bool _sc_is_implicit
True if implicit value is required.
Class for scalar variables (they are different).
VariableValue & slnOlder()
const std::vector< MooseVariableScalar * > & ScalarCoupleable::getCoupledMooseScalarVars ( )

Get the list of coupled scalar variables.

Returns
The list of coupled variables

Definition at line 72 of file ScalarCoupleable.C.

Referenced by AuxScalarKernel::AuxScalarKernel(), and ScalarInitialCondition::ScalarInitialCondition().

73 {
75 }
std::vector< MooseVariableScalar * > _coupled_moose_scalar_vars
Vector of coupled variables.
VariableValue * ScalarCoupleable::getDefaultValue ( const std::string &  var_name)
protected

Helper method to return (and insert if necessary) the default value for an uncoupled variable.

Parameters
var_namethe name of the variable for which to retrieve a default value
Returns
VariableValue * a pointer to the associated VarirableValue.

Definition at line 114 of file ScalarCoupleable.C.

Referenced by coupledScalarValue(), coupledScalarValueOld(), and coupledScalarValueOlder().

115 {
116  std::map<std::string, VariableValue *>::iterator default_value_it = _default_value.find(var_name);
117  if (default_value_it == _default_value.end())
118  {
121  default_value_it = _default_value.insert(std::make_pair(var_name, value)).first;
122  }
123 
124  return default_value_it->second;
125 }
MooseArray< Real > VariableValue
FEProblemBase & _sc_fe_problem
Order getMaxScalarOrder() const
const InputParameters & _coupleable_params
Local InputParameters.
std::map< std::string, VariableValue * > _default_value
Will hold the default value for optional coupled scalar variables.
Real defaultCoupledValue(const std::string &coupling_name) const
Get the default value for an optionally coupled variable.
MooseVariableScalar * ScalarCoupleable::getScalarVar ( const std::string &  var_name,
unsigned int  comp 
)
protected

Extract pointer to a scalar coupled variable.

Parameters
var_nameName of parameter desired
compComponent number of multiple coupled variables
Returns
Pointer to the desired variable

Definition at line 175 of file ScalarCoupleable.C.

Referenced by coupledScalar(), coupledScalarDot(), coupledScalarDotDu(), coupledScalarOrder(), coupledScalarValue(), coupledScalarValueOld(), coupledScalarValueOlder(), and ParsedODEKernel::ParsedODEKernel().

176 {
177  if (_coupled_scalar_vars.find(var_name) != _coupled_scalar_vars.end())
178  {
179  if (comp < _coupled_scalar_vars[var_name].size())
180  return _coupled_scalar_vars[var_name][comp];
181  else
182  mooseError("Trying to get a non-existent component of variable '" + var_name + "'");
183  }
184  else
185  mooseError("Trying to get a non-existent variable '" + var_name + "'");
186 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.
bool ScalarCoupleable::isCoupledScalar ( const std::string &  var_name,
unsigned int  i = 0 
)
protectedvirtual

Returns true if a variables has been coupled_as name.

Parameters
var_nameThe of the coupled variable
iBy default 0, in general the index to test in a vector of MooseVariable pointers.

Definition at line 78 of file ScalarCoupleable.C.

Referenced by coupledScalarOrder(), coupledScalarValue(), coupledScalarValueOld(), and coupledScalarValueOlder().

79 {
80  std::map<std::string, std::vector<MooseVariableScalar *>>::iterator it =
81  _coupled_scalar_vars.find(var_name);
82  if (it != _coupled_scalar_vars.end())
83  return (i < it->second.size());
84  else
85  {
86  // Make sure the user originally requested this value in the InputParameter syntax
87  if (!_coupleable_params.hasCoupledValue(var_name))
88  mooseError("The coupled scalar variable \"",
89  var_name,
90  "\" was never added to this objects's "
91  "InputParameters, please double-check "
92  "your spelling");
93 
94  return false;
95  }
96 }
bool hasCoupledValue(const std::string &coupling_name) const
Return whether or not the coupled variable exists.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
const InputParameters & _coupleable_params
Local InputParameters.
std::map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.

Member Data Documentation

const InputParameters& ScalarCoupleable::_coupleable_params
protected

Local InputParameters.

Definition at line 150 of file ScalarCoupleable.h.

Referenced by getDefaultValue(), and isCoupledScalar().

std::vector<MooseVariableScalar *> ScalarCoupleable::_coupled_moose_scalar_vars
protected

Vector of coupled variables.

Definition at line 144 of file ScalarCoupleable.h.

Referenced by getCoupledMooseScalarVars(), and ScalarCoupleable().

std::map<std::string, std::vector<MooseVariableScalar *> > ScalarCoupleable::_coupled_scalar_vars
protected

Coupled vars whose values we provide.

Definition at line 138 of file ScalarCoupleable.h.

Referenced by coupledScalarComponents(), getScalarVar(), isCoupledScalar(), and ScalarCoupleable().

std::map<std::string, VariableValue *> ScalarCoupleable::_default_value
protected

Will hold the default value for optional coupled scalar variables.

Definition at line 141 of file ScalarCoupleable.h.

Referenced by getDefaultValue(), and ~ScalarCoupleable().

FEProblemBase& ScalarCoupleable::_sc_fe_problem
protected

Definition at line 135 of file ScalarCoupleable.h.

Referenced by coupledScalarOrder(), and getDefaultValue().

bool ScalarCoupleable::_sc_is_implicit
protected

True if implicit value is required.

Definition at line 147 of file ScalarCoupleable.h.

Referenced by coupledScalarValue(), coupledScalarValueOld(), and coupledScalarValueOlder().

const InputParameters& ScalarCoupleable::_sc_parameters
protected

Definition at line 60 of file ScalarCoupleable.h.

Referenced by ScalarCoupleable().


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