https://mooseframework.inl.gov
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private 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...
 
 ScalarCoupleable (const ScalarCoupleable &object, const Moose::Kokkos::FunctorCopy &key)
 Special constructor used for Kokkos functor copy during parallel dispatch. More...
 
const std::vector< MooseVariableScalar * > & getCoupledMooseScalarVars ()
 Get the list of coupled scalar variables. More...
 
const std::set< TagID > & getScalarVariableCoupleableVectorTags () const
 
const std::set< TagID > & getScalarVariableCoupleableMatrixTags () const
 

Protected Member Functions

bool isCoupledScalar (const std::string &var_name, unsigned int i=0) const
 Returns true if a variables has been coupled_as name. More...
 
unsigned int coupledScalarComponents (const std::string &var_name) const
 Return the number of components to the coupled scalar variable. More...
 
unsigned int coupledScalar (const std::string &var_name, unsigned int comp=0) const
 Returns the index for a scalar coupled variable by name. More...
 
libMesh::Order coupledScalarOrder (const std::string &var_name, unsigned int comp=0) const
 Returns the order for a scalar coupled variable by name. More...
 
const VariableValuecoupledScalarValue (const std::string &var_name, unsigned int comp=0) const
 Returns value of a scalar coupled variable. More...
 
const ADVariableValueadCoupledScalarValue (const std::string &var_name, unsigned int comp=0) const
 Returns AD value of a scalar coupled variable. More...
 
template<bool is_ad>
const GenericVariableValue< is_ad > & coupledGenericScalarValue (const std::string &var_name, unsigned int comp=0) const
 Returns value of a coupled scalar variable for use in templated automatic differentiation classes. More...
 
const VariableValuecoupledVectorTagScalarValue (const std::string &var_name, TagID tag, unsigned int comp=0) const
 Returns value of a scalar coupled variable. More...
 
const VariableValuecoupledMatrixTagScalarValue (const std::string &var_name, TagID tag, unsigned int comp=0) const
 Returns value of a scalar coupled variable. More...
 
const VariableValuecoupledScalarValueOld (const std::string &var_name, unsigned int comp=0) const
 Returns the old (previous time step) value of a scalar coupled variable. More...
 
const VariableValuecoupledScalarValueOlder (const std::string &var_name, unsigned int comp=0) const
 Returns the older (two time steps previous) value of a scalar coupled variable. More...
 
const VariableValuecoupledScalarDot (const std::string &var_name, unsigned int comp=0) const
 Returns the time derivative of a scalar coupled variable. More...
 
const ADVariableValueadCoupledScalarDot (const std::string &var_name, unsigned int comp=0) const
 Returns the time derivative of a scalar coupled variable, including its dependence on the nonlinear degrees of freedom through automatic differentiation. More...
 
const VariableValuecoupledScalarDotDot (const std::string &var_name, unsigned int comp=0) const
 Returns the second time derivative of a scalar coupled variable. More...
 
const VariableValuecoupledScalarDotOld (const std::string &var_name, unsigned int comp=0) const
 Returns the old time derivative of a scalar coupled variable. More...
 
const VariableValuecoupledScalarDotDotOld (const std::string &var_name, unsigned int comp=0) const
 Returns the old second time derivative of a scalar coupled variable. More...
 
const VariableValuecoupledScalarDotDu (const std::string &var_name, unsigned int comp=0) const
 Time derivative of a scalar coupled variable with respect to the coefficients. More...
 
const VariableValuecoupledScalarDotDotDu (const std::string &var_name, unsigned int comp=0) const
 Second time derivative of a scalar coupled variable with respect to the coefficients. More...
 
const MooseVariableScalargetScalarVar (const std::string &var_name, unsigned int comp) const
 Extract pointer to a scalar coupled variable. More...
 
template<>
const GenericVariableValue< false > & coupledGenericScalarValue (const std::string &var_name, const unsigned int comp) const
 
template<>
const GenericVariableValue< true > & coupledGenericScalarValue (const std::string &var_name, const unsigned int comp) const
 

Protected Attributes

FEProblemBase_sc_fe_problem
 
const THREAD_ID _sc_tid
 Thread ID of the thread using this object. More...
 
const Real_real_zero
 Scalar zero. More...
 
const VariableValue_scalar_zero
 Zero value of a scalar variable. More...
 
const Point & _point_zero
 Zero point. More...
 

Private Member Functions

const VariableValuegetDefaultValue (const std::string &var_name) const
 Helper method to return (and insert if necessary) the default value for an uncoupled variable. More...
 
const ADVariableValuegetADDefaultValue (const std::string &var_name) const
 Helper method to return (and insert if necessary) the AD default value for an uncoupled variable. More...
 
void checkVar (const std::string &var_name) const
 Check that the right kind of variable is being coupled in. More...
 
void validateExecutionerType (const std::string &name, const std::string &fn_name) const
 Checks to make sure that the current Executioner has set "_is_transient" when old/older values are coupled in. More...
 

Private Attributes

const InputParameters_sc_parameters
 
const std::string & _sc_name
 The name of the object this interface is part of. More...
 
const bool _sc_is_implicit
 True if implicit value is required. More...
 
std::unordered_map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
 Coupled vars whose values we provide. More...
 
std::unordered_map< std::string, std::unique_ptr< VariableValue > > _default_value
 Will hold the default value for optional coupled scalar variables. More...
 
std::unordered_map< std::string, std::unique_ptr< ADVariableValue > > _dual_default_value
 Will hold the default AD value for optional coupled scalar variables. More...
 
std::vector< MooseVariableScalar * > _coupled_moose_scalar_vars
 Vector of coupled variables. More...
 
std::unordered_map< std::string, std::vector< MooseVariableFieldBase * > > _sc_coupled_vars
 Field variables coupled into this object (for error checking) More...
 
std::set< TagID_sc_coupleable_vector_tags
 The scalar coupleable vector tags. More...
 
std::set< TagID_sc_coupleable_matrix_tags
 The scalar coupleable matrix tags. More...
 

Detailed Description

Interface for objects that needs scalar coupling capabilities.

Definition at line 32 of file ScalarCoupleable.h.

Constructor & Destructor Documentation

◆ ScalarCoupleable() [1/2]

ScalarCoupleable::ScalarCoupleable ( const MooseObject moose_object)

Constructing the object.

Parameters
parametersParameters that come from constructing the object

Definition at line 19 of file ScalarCoupleable.C.

21  *moose_object->parameters().getCheckedPointerParam<FEProblemBase *>("_fe_problem_base")),
22  _sc_tid(moose_object->parameters().isParamValid("_tid")
23  ? moose_object->parameters().get<THREAD_ID>("_tid")
24  : 0),
28  _sc_parameters(moose_object->parameters()),
31  ? _sc_parameters.get<bool>("implicit")
32  : true)
33 {
34  SubProblem & problem = *_sc_parameters.getCheckedPointerParam<SubProblem *>("_subproblem");
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(_sc_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  {
55  MooseVariableFEBase * moose_var =
56  &problem.getVariable(_sc_tid,
57  coupled_var_name,
60  _sc_coupled_vars[name].push_back(moose_var);
61  }
62  else
63  mooseError(_sc_name, ": Coupled variable '", coupled_var_name, "' was not found");
64  }
65  }
66  }
67 }
std::string name(const ElemQuality q)
std::vector< Point > _point_zero
virtual MooseVariableScalar & getScalarVariable(const THREAD_ID tid, const std::string &var_name)=0
Returns the scalar variable reference from whichever system contains it.
std::unordered_map< std::string, std::vector< MooseVariableFieldBase * > > _sc_coupled_vars
Field variables coupled into this object (for error checking)
const Point & _point_zero
Zero point.
const THREAD_ID _sc_tid
Thread ID of the thread using this object.
const std::string & getObjectName() const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
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 InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseBase.h:131
char ** vars
const 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::set< std::string >::const_iterator coupledVarsBegin() const
Methods returning iterators to the coupled variables names stored in this InputParameters object...
const std::string & _sc_name
The name of the object this interface is part of.
FEProblemBase & _sc_fe_problem
This class provides an interface for common operations on field variables of both FE and FV types wit...
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
std::set< std::string >::const_iterator coupledVarsEnd() const
virtual bool hasScalarVariable(const std::string &var_name) const =0
Returns a Boolean indicating whether any system contains a variable with the name provided...
std::unordered_map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.
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 =0
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 =0
Whether or not this problem has the variable.
const InputParameters & _sc_parameters
bool have_parameter(std::string_view name) const
A wrapper around the Parameters base class method.
Generic class for solving transient nonlinear problems.
Definition: SubProblem.h:78
std::vector< MooseVariableScalar * > _coupled_moose_scalar_vars
Vector of coupled variables.
const Real & _real_zero
Scalar zero.
std::vector< VariableValue > _scalar_zero
Class for scalar variables (they are different).
const VariableValue & _scalar_zero
Zero value of a scalar variable.
std::vector< std::string > getVecMooseType(const std::string &name) const
unsigned int THREAD_ID
Definition: MooseTypes.h:209
std::vector< Real > _real_zero
Convenience zeros.
bool isParamValid(const std::string &name) const
This method returns parameters that have been initialized in one fashion or another, i.e.

◆ ScalarCoupleable() [2/2]

ScalarCoupleable::ScalarCoupleable ( const ScalarCoupleable object,
const Moose::Kokkos::FunctorCopy key 
)

Special constructor used for Kokkos functor copy during parallel dispatch.

Definition at line 70 of file ScalarCoupleable.C.

73  _sc_tid(object._sc_tid),
74  _real_zero(object._real_zero),
75  _scalar_zero(object._scalar_zero),
76  _point_zero(object._point_zero),
78  _sc_name(object._sc_name),
80 {
81 }
const Point & _point_zero
Zero point.
const THREAD_ID _sc_tid
Thread ID of the thread using this object.
const bool _sc_is_implicit
True if implicit value is required.
const std::string & _sc_name
The name of the object this interface is part of.
FEProblemBase & _sc_fe_problem
const InputParameters & _sc_parameters
const Real & _real_zero
Scalar zero.
const VariableValue & _scalar_zero
Zero value of a scalar variable.

Member Function Documentation

◆ adCoupledScalarDot()

const ADVariableValue & ScalarCoupleable::adCoupledScalarDot ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

Returns the time derivative of a scalar coupled variable, including its dependence on the nonlinear degrees of freedom through automatic differentiation.

Parameters
var_nameName of coupled variable
compComponent number for vector of coupled variables
Returns
Reference to the time derivative at quadrature points for the coupled variable, including automatic differentiation information

Definition at line 267 of file ScalarCoupleable.C.

268 {
269  checkVar(var_name);
270  validateExecutionerType(var_name, "adCoupledScalarDot");
271  return getScalarVar(var_name, comp)->adUDot();
272 }
const ADVariableValue & adUDot() const
Return the first derivative of the solution with derivative information.
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.

◆ adCoupledScalarValue()

const ADVariableValue & ScalarCoupleable::adCoupledScalarValue ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

Returns AD value of a scalar coupled variable.

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

Definition at line 150 of file ScalarCoupleable.C.

151 {
152  checkVar(var_name);
153  if (!isCoupledScalar(var_name, comp))
154  return *getADDefaultValue(var_name);
155 
156  auto var = getScalarVar(var_name, comp);
157 
158  if (_sc_is_implicit)
159  return var->adSln();
160  else
161  mooseError("adCoupledValue for non-implicit calculations is not currently supported. Use "
162  "coupledValue instead for non-implicit");
163 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const bool _sc_is_implicit
True if implicit value is required.
bool isCoupledScalar(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled_as name.
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
const ADVariableValue * getADDefaultValue(const std::string &var_name) const
Helper method to return (and insert if necessary) the AD default value for an uncoupled variable...

◆ checkVar()

void ScalarCoupleable::checkVar ( const std::string &  var_name) const
private

Check that the right kind of variable is being coupled in.

Parameters
var_nameThe name of the coupled variable

Definition at line 315 of file ScalarCoupleable.C.

Referenced by adCoupledScalarDot(), adCoupledScalarValue(), coupledMatrixTagScalarValue(), coupledScalar(), coupledScalarDot(), coupledScalarDotDot(), coupledScalarDotDotDu(), coupledScalarDotDotOld(), coupledScalarDotDu(), coupledScalarDotOld(), coupledScalarOrder(), coupledScalarValue(), coupledScalarValueOld(), coupledScalarValueOlder(), and coupledVectorTagScalarValue().

316 {
317  const auto var_name = _sc_parameters.checkForRename(var_name_in);
318 
319  auto it = _sc_coupled_vars.find(var_name);
320  if (it != _sc_coupled_vars.end())
321  {
322  std::string cvars;
323  for (auto jt : it->second)
324  cvars += " " + jt->name();
326  ": Trying to couple a field variable where scalar variable is expected, '",
327  var_name,
328  " =",
329  cvars,
330  "'");
331  }
332  // NOTE: non-existent variables are handled in the constructor
333 }
std::unordered_map< std::string, std::vector< MooseVariableFieldBase * > > _sc_coupled_vars
Field variables coupled into this object (for error checking)
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const std::string & _sc_name
The name of the object this interface is part of.
const InputParameters & _sc_parameters
std::string checkForRename(const std::string &name) const
Checks whether the provided name is a renamed parameter name.

◆ coupledGenericScalarValue() [1/3]

template<bool is_ad>
const GenericVariableValue<is_ad>& ScalarCoupleable::coupledGenericScalarValue ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

Returns value of a coupled scalar variable for use in templated automatic differentiation classes.

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

◆ coupledGenericScalarValue() [2/3]

template<>
const GenericVariableValue<false>& ScalarCoupleable::coupledGenericScalarValue ( const std::string &  var_name,
const unsigned int  comp 
) const
protected

Definition at line 167 of file ScalarCoupleable.C.

169 {
170  return coupledScalarValue(var_name, comp);
171 }
const VariableValue & coupledScalarValue(const std::string &var_name, unsigned int comp=0) const
Returns value of a scalar coupled variable.

◆ coupledGenericScalarValue() [3/3]

template<>
const GenericVariableValue<true>& ScalarCoupleable::coupledGenericScalarValue ( const std::string &  var_name,
const unsigned int  comp 
) const
protected

Definition at line 175 of file ScalarCoupleable.C.

177 {
178  return adCoupledScalarValue(var_name, comp);
179 }
const ADVariableValue & adCoupledScalarValue(const std::string &var_name, unsigned int comp=0) const
Returns AD value of a scalar coupled variable.

◆ coupledMatrixTagScalarValue()

const VariableValue & ScalarCoupleable::coupledMatrixTagScalarValue ( const std::string &  var_name,
TagID  tag,
unsigned int  comp = 0 
) const
protected

Returns value of a scalar coupled variable.

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

Definition at line 217 of file ScalarCoupleable.C.

220 {
221  checkVar(var_name);
222  if (!isCoupledScalar(var_name, comp))
223  return *getDefaultValue(var_name);
224 
225  _sc_coupleable_matrix_tags.insert(tag);
226 
227  return getScalarVar(var_name, comp)->matrixTagSln(tag);
228 }
std::set< TagID > _sc_coupleable_matrix_tags
The scalar coupleable matrix tags.
bool isCoupledScalar(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled_as name.
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
const VariableValue & matrixTagSln(TagID tag) const
const VariableValue * getDefaultValue(const std::string &var_name) const
Helper method to return (and insert if necessary) the default value for an uncoupled variable...

◆ coupledScalar()

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

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 108 of file ScalarCoupleable.C.

Referenced by ParsedODEKernel::ParsedODEKernel().

109 {
110  checkVar(var_name);
111  return getScalarVar(var_name, comp)->number();
112 }
unsigned int number() const
Get variable number coming from libMesh.
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.

◆ coupledScalarComponents()

unsigned int ScalarCoupleable::coupledScalarComponents ( const std::string &  var_name) const
protected

Return the number of components to the coupled scalar variable.

Parameters
var_nameThe of the coupled variable

Definition at line 368 of file ScalarCoupleable.C.

369 {
370  const auto var_name = _sc_parameters.checkForRename(var_name_in);
371 
372  const auto it = _coupled_scalar_vars.find(var_name);
373  if (it != _coupled_scalar_vars.end())
374  return it->second.size();
375 
376  mooseError(_sc_name, ": Trying to get a non-existent variable '", var_name, "'");
377 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const std::string & _sc_name
The name of the object this interface is part of.
std::unordered_map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.
const InputParameters & _sc_parameters
std::string checkForRename(const std::string &name) const
Checks whether the provided name is a renamed parameter name.

◆ coupledScalarDot()

const VariableValue & ScalarCoupleable::coupledScalarDot ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

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 259 of file ScalarCoupleable.C.

260 {
261  checkVar(var_name);
262  validateExecutionerType(var_name, "coupledScalarDot");
263  return getScalarVar(var_name, comp)->uDot();
264 }
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
const VariableValue & uDot() const
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.

◆ coupledScalarDotDot()

const VariableValue & ScalarCoupleable::coupledScalarDotDot ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

Returns the second 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 275 of file ScalarCoupleable.C.

276 {
277  checkVar(var_name);
278  validateExecutionerType(var_name, "coupledScalarDotDot");
279  return getScalarVar(var_name, comp)->uDotDot();
280 }
const VariableValue & uDotDot() const
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.

◆ coupledScalarDotDotDu()

const VariableValue & ScalarCoupleable::coupledScalarDotDotDu ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

Second 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 307 of file ScalarCoupleable.C.

308 {
309  checkVar(var_name);
310  validateExecutionerType(var_name, "coupledScalarDotDotDu");
311  return getScalarVar(var_name, comp)->duDotDotDu();
312 }
const VariableValue & duDotDotDu() const
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.

◆ coupledScalarDotDotOld()

const VariableValue & ScalarCoupleable::coupledScalarDotDotOld ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

Returns the old second 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 291 of file ScalarCoupleable.C.

293 {
294  checkVar(var_name);
295  validateExecutionerType(var_name, "coupledScalarDotDotOld");
296  return getScalarVar(var_name, comp)->uDotDotOld();
297 }
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
const VariableValue & uDotDotOld() const
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.

◆ coupledScalarDotDu()

const VariableValue & ScalarCoupleable::coupledScalarDotDu ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

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 299 of file ScalarCoupleable.C.

300 {
301  checkVar(var_name);
302  validateExecutionerType(var_name, "coupledScalarDotDu");
303  return getScalarVar(var_name, comp)->duDotDu();
304 }
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
const VariableValue & duDotDu() const

◆ coupledScalarDotOld()

const VariableValue & ScalarCoupleable::coupledScalarDotOld ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

Returns the old 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 283 of file ScalarCoupleable.C.

284 {
285  checkVar(var_name);
286  validateExecutionerType(var_name, "coupledScalarDotOld");
287  return getScalarVar(var_name, comp)->uDotOld();
288 }
const VariableValue & uDotOld() const
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.

◆ coupledScalarOrder()

Order ScalarCoupleable::coupledScalarOrder ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

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 115 of file ScalarCoupleable.C.

116 {
117  checkVar(var_name);
118  if (!isCoupledScalar(var_name, comp))
120 
121  return getScalarVar(var_name, comp)->order();
122 }
FEProblemBase & _sc_fe_problem
bool isCoupledScalar(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled_as name.
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
libMesh::Order order() const
Get the order of this variable Note: Order enum can be implicitly converted to unsigned int...
libMesh::Order getMaxScalarOrder() const

◆ coupledScalarValue()

const VariableValue & ScalarCoupleable::coupledScalarValue ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

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 139 of file ScalarCoupleable.C.

Referenced by ParsedODEKernel::ParsedODEKernel().

140 {
141  checkVar(var_name);
142  if (!isCoupledScalar(var_name, comp))
143  return *getDefaultValue(var_name);
144 
145  auto var = getScalarVar(var_name, comp);
146  return _sc_is_implicit ? var->sln() : var->slnOld();
147 }
const bool _sc_is_implicit
True if implicit value is required.
bool isCoupledScalar(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled_as name.
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
const VariableValue * getDefaultValue(const std::string &var_name) const
Helper method to return (and insert if necessary) the default value for an uncoupled variable...

◆ coupledScalarValueOld()

const VariableValue & ScalarCoupleable::coupledScalarValueOld ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

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 231 of file ScalarCoupleable.C.

232 {
233  checkVar(var_name);
234  if (!isCoupledScalar(var_name, comp))
235  return *getDefaultValue(var_name);
236 
237  validateExecutionerType(var_name, "coupledScalarValueOld");
238  auto var = getScalarVar(var_name, comp);
239  return _sc_is_implicit ? var->slnOld() : var->slnOlder();
240 }
const bool _sc_is_implicit
True if implicit value is required.
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
bool isCoupledScalar(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled_as name.
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
const VariableValue * getDefaultValue(const std::string &var_name) const
Helper method to return (and insert if necessary) the default value for an uncoupled variable...

◆ coupledScalarValueOlder()

const VariableValue & ScalarCoupleable::coupledScalarValueOlder ( const std::string &  var_name,
unsigned int  comp = 0 
) const
protected

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 243 of file ScalarCoupleable.C.

245 {
246  checkVar(var_name);
247  if (!isCoupledScalar(var_name, comp))
248  return *getDefaultValue(var_name);
249 
250  validateExecutionerType(var_name, "coupledScalarValueOlder");
251  auto var = getScalarVar(var_name, comp);
252  if (_sc_is_implicit)
253  return var->slnOlder();
254  else
255  mooseError("Older values not available for explicit schemes");
256 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const bool _sc_is_implicit
True if implicit value is required.
void validateExecutionerType(const std::string &name, const std::string &fn_name) const
Checks to make sure that the current Executioner has set "_is_transient" when old/older values are co...
bool isCoupledScalar(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled_as name.
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
const VariableValue * getDefaultValue(const std::string &var_name) const
Helper method to return (and insert if necessary) the default value for an uncoupled variable...

◆ coupledVectorTagScalarValue()

const VariableValue & ScalarCoupleable::coupledVectorTagScalarValue ( const std::string &  var_name,
TagID  tag,
unsigned int  comp = 0 
) const
protected

Returns value of a scalar coupled variable.

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

Definition at line 196 of file ScalarCoupleable.C.

199 {
200  checkVar(var_name);
201  if (!isCoupledScalar(var_name, comp))
202  return *getDefaultValue(var_name);
203 
205  mooseError("Attempting to couple to vector tag scalar with ID ",
206  tag,
207  "in ",
208  _sc_name,
209  ", but a vector tag with that ID does not exist");
210 
211  _sc_coupleable_vector_tags.insert(tag);
212 
213  return getScalarVar(var_name, comp)->vectorTagSln(tag);
214 }
std::set< TagID > _sc_coupleable_vector_tags
The scalar coupleable vector tags.
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const std::string & _sc_name
The name of the object this interface is part of.
FEProblemBase & _sc_fe_problem
bool isCoupledScalar(const std::string &var_name, unsigned int i=0) const
Returns true if a variables has been coupled_as name.
const VariableValue & vectorTagSln(TagID tag) const
void checkVar(const std::string &var_name) const
Check that the right kind of variable is being coupled in.
const MooseVariableScalar * getScalarVar(const std::string &var_name, unsigned int comp) const
Extract pointer to a scalar coupled variable.
virtual bool vectorTagExists(const TagID tag_id) const
Check to see if a particular Tag exists.
Definition: SubProblem.h:201
const VariableValue * getDefaultValue(const std::string &var_name) const
Helper method to return (and insert if necessary) the default value for an uncoupled variable...

◆ getADDefaultValue()

const ADVariableValue * ScalarCoupleable::getADDefaultValue ( const std::string &  var_name) const
private

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

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

Definition at line 182 of file ScalarCoupleable.C.

Referenced by adCoupledScalarValue().

183 {
184  auto default_value_it = _dual_default_value.find(var_name);
185  if (default_value_it == _dual_default_value.end())
186  {
187  auto value = std::make_unique<ADVariableValue>(_sc_fe_problem.getMaxScalarOrder(),
189  default_value_it = _dual_default_value.insert(std::make_pair(var_name, std::move(value))).first;
190  }
191 
192  return default_value_it->second.get();
193 }
FEProblemBase & _sc_fe_problem
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Real defaultCoupledValue(const std::string &coupling_name, unsigned int i=0) const
Get the default value for an optionally coupled variable.
const InputParameters & _sc_parameters
std::unordered_map< std::string, std::unique_ptr< ADVariableValue > > _dual_default_value
Will hold the default AD value for optional coupled scalar variables.
libMesh::Order getMaxScalarOrder() const

◆ getCoupledMooseScalarVars()

const std::vector<MooseVariableScalar *>& ScalarCoupleable::getCoupledMooseScalarVars ( )
inline

Get the list of coupled scalar variables.

Returns
The list of coupled variables

Definition at line 52 of file ScalarCoupleable.h.

Referenced by AuxScalarKernel::AuxScalarKernel(), MortarScalarBase::computeJacobian(), KernelScalarBase::computeResidualAndJacobian(), and ScalarInitialCondition::ScalarInitialCondition().

53  {
55  }
std::vector< MooseVariableScalar * > _coupled_moose_scalar_vars
Vector of coupled variables.

◆ getDefaultValue()

const VariableValue * ScalarCoupleable::getDefaultValue ( const std::string &  var_name) const
private

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 VariableValue.

Definition at line 125 of file ScalarCoupleable.C.

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

126 {
127  auto default_value_it = _default_value.find(var_name);
128  if (default_value_it == _default_value.end())
129  {
130  auto value = std::make_unique<VariableValue>(_sc_fe_problem.getMaxScalarOrder(),
132  default_value_it = _default_value.insert(std::make_pair(var_name, std::move(value))).first;
133  }
134 
135  return default_value_it->second.get();
136 }
FEProblemBase & _sc_fe_problem
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
Real defaultCoupledValue(const std::string &coupling_name, unsigned int i=0) const
Get the default value for an optionally coupled variable.
const InputParameters & _sc_parameters
std::unordered_map< std::string, std::unique_ptr< VariableValue > > _default_value
Will hold the default value for optional coupled scalar variables.
libMesh::Order getMaxScalarOrder() const

◆ getScalarVar()

const MooseVariableScalar * ScalarCoupleable::getScalarVar ( const std::string &  var_name,
unsigned int  comp 
) const
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 336 of file ScalarCoupleable.C.

Referenced by adCoupledScalarDot(), adCoupledScalarValue(), coupledMatrixTagScalarValue(), coupledScalar(), coupledScalarDot(), coupledScalarDotDot(), coupledScalarDotDotDu(), coupledScalarDotDotOld(), coupledScalarDotDu(), coupledScalarDotOld(), coupledScalarOrder(), coupledScalarValue(), coupledScalarValueOld(), coupledScalarValueOlder(), coupledVectorTagScalarValue(), and ParsedODEKernel::ParsedODEKernel().

337 {
338  const auto var_name = _sc_parameters.checkForRename(var_name_in);
339 
340  const auto it = _coupled_scalar_vars.find(var_name);
341  if (it != _coupled_scalar_vars.end())
342  {
343  const auto & entry = it->second;
344  if (comp < entry.size())
345  return entry[comp];
346  else
347  mooseError(_sc_name, ": Trying to get a non-existent component of variable '", var_name, "'");
348  }
349  else
350  mooseError(_sc_name, ": Trying to get a non-existent variable '", var_name, "'");
351 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const std::string & _sc_name
The name of the object this interface is part of.
std::unordered_map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.
const InputParameters & _sc_parameters
std::string checkForRename(const std::string &name) const
Checks whether the provided name is a renamed parameter name.

◆ getScalarVariableCoupleableMatrixTags()

const std::set<TagID>& ScalarCoupleable::getScalarVariableCoupleableMatrixTags ( ) const
inline

Definition at line 62 of file ScalarCoupleable.h.

63  {
65  }
std::set< TagID > _sc_coupleable_matrix_tags
The scalar coupleable matrix tags.

◆ getScalarVariableCoupleableVectorTags()

const std::set<TagID>& ScalarCoupleable::getScalarVariableCoupleableVectorTags ( ) const
inline

Definition at line 57 of file ScalarCoupleable.h.

58  {
60  }
std::set< TagID > _sc_coupleable_vector_tags
The scalar coupleable vector tags.

◆ isCoupledScalar()

bool ScalarCoupleable::isCoupledScalar ( const std::string &  var_name,
unsigned int  i = 0 
) const
protected

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 85 of file ScalarCoupleable.C.

Referenced by adCoupledScalarValue(), coupledMatrixTagScalarValue(), coupledScalarOrder(), coupledScalarValue(), coupledScalarValueOld(), coupledScalarValueOlder(), and coupledVectorTagScalarValue().

86 {
87  const auto var_name = _sc_parameters.checkForRename(var_name_in);
88 
89  auto it = _coupled_scalar_vars.find(var_name);
90  if (it != _coupled_scalar_vars.end())
91  return (i < it->second.size());
92  else
93  {
94  // Make sure the user originally requested this value in the InputParameter syntax
95  if (!_sc_parameters.hasCoupledValue(var_name))
97  ": The coupled scalar variable \"",
98  var_name,
99  "\" was never added to this object's "
100  "InputParameters, please double-check "
101  "your spelling");
102 
103  return false;
104  }
105 }
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:323
const std::string & _sc_name
The name of the object this interface is part of.
std::unordered_map< std::string, std::vector< MooseVariableScalar * > > _coupled_scalar_vars
Coupled vars whose values we provide.
const InputParameters & _sc_parameters
std::string checkForRename(const std::string &name) const
Checks whether the provided name is a renamed parameter name.

◆ validateExecutionerType()

void ScalarCoupleable::validateExecutionerType ( const std::string &  name,
const std::string &  fn_name 
) const
private

Checks to make sure that the current Executioner has set "_is_transient" when old/older values are coupled in.

Parameters
namethe name of the variable
fn_nameThe name of the function that called this method - used in the error message

Definition at line 354 of file ScalarCoupleable.C.

Referenced by adCoupledScalarDot(), coupledScalarDot(), coupledScalarDotDot(), coupledScalarDotDotDu(), coupledScalarDotDotOld(), coupledScalarDotDu(), coupledScalarDotOld(), coupledScalarValueOld(), and coupledScalarValueOlder().

356 {
359  ": Calling '",
360  fn_name,
361  "' on variable \"",
362  name,
363  "\" when using a \"Steady\" executioner is not allowed. This value is available "
364  "only in transient simulations.");
365 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:323
const std::string & _sc_name
The name of the object this interface is part of.
FEProblemBase & _sc_fe_problem
virtual bool isTransient() const override

Member Data Documentation

◆ _coupled_moose_scalar_vars

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

Vector of coupled variables.

Definition at line 304 of file ScalarCoupleable.h.

Referenced by getCoupledMooseScalarVars(), and ScalarCoupleable().

◆ _coupled_scalar_vars

std::unordered_map<std::string, std::vector<MooseVariableScalar *> > ScalarCoupleable::_coupled_scalar_vars
private

Coupled vars whose values we provide.

Definition at line 295 of file ScalarCoupleable.h.

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

◆ _default_value

std::unordered_map<std::string, std::unique_ptr<VariableValue> > ScalarCoupleable::_default_value
mutableprivate

Will hold the default value for optional coupled scalar variables.

Definition at line 298 of file ScalarCoupleable.h.

Referenced by getDefaultValue().

◆ _dual_default_value

std::unordered_map<std::string, std::unique_ptr<ADVariableValue> > ScalarCoupleable::_dual_default_value
mutableprivate

Will hold the default AD value for optional coupled scalar variables.

Definition at line 301 of file ScalarCoupleable.h.

Referenced by getADDefaultValue().

◆ _point_zero

const Point& ScalarCoupleable::_point_zero
protected

◆ _real_zero

const Real& ScalarCoupleable::_real_zero
protected

Scalar zero.

Definition at line 245 of file ScalarCoupleable.h.

◆ _sc_coupleable_matrix_tags

std::set<TagID> ScalarCoupleable::_sc_coupleable_matrix_tags
mutableprivate

The scalar coupleable matrix tags.

Definition at line 312 of file ScalarCoupleable.h.

Referenced by coupledMatrixTagScalarValue(), and getScalarVariableCoupleableMatrixTags().

◆ _sc_coupleable_vector_tags

std::set<TagID> ScalarCoupleable::_sc_coupleable_vector_tags
mutableprivate

The scalar coupleable vector tags.

Definition at line 310 of file ScalarCoupleable.h.

Referenced by coupledVectorTagScalarValue(), and getScalarVariableCoupleableVectorTags().

◆ _sc_coupled_vars

std::unordered_map<std::string, std::vector<MooseVariableFieldBase *> > ScalarCoupleable::_sc_coupled_vars
private

Field variables coupled into this object (for error checking)

Definition at line 307 of file ScalarCoupleable.h.

Referenced by checkVar(), and ScalarCoupleable().

◆ _sc_fe_problem

FEProblemBase& ScalarCoupleable::_sc_fe_problem
protected

◆ _sc_is_implicit

const bool ScalarCoupleable::_sc_is_implicit
private

True if implicit value is required.

Definition at line 292 of file ScalarCoupleable.h.

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

◆ _sc_name

const std::string& ScalarCoupleable::_sc_name
private

The name of the object this interface is part of.

Definition at line 289 of file ScalarCoupleable.h.

Referenced by checkVar(), coupledScalarComponents(), coupledVectorTagScalarValue(), getScalarVar(), isCoupledScalar(), ScalarCoupleable(), and validateExecutionerType().

◆ _sc_parameters

const InputParameters& ScalarCoupleable::_sc_parameters
private

◆ _sc_tid

const THREAD_ID ScalarCoupleable::_sc_tid
protected

Thread ID of the thread using this object.

Definition at line 242 of file ScalarCoupleable.h.

Referenced by ScalarCoupleable().

◆ _scalar_zero

const VariableValue& ScalarCoupleable::_scalar_zero
protected

Zero value of a scalar variable.

Definition at line 248 of file ScalarCoupleable.h.


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