Skip to content

Commit

Permalink
fix remaining issues with optional coupling refs idaholab#2358
Browse files Browse the repository at this point in the history
  • Loading branch information
friedmud authored and aeslaughter committed May 1, 2014
1 parent 495e5ba commit 5ebf310
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
3 changes: 3 additions & 0 deletions framework/include/base/Coupleable.h
Expand Up @@ -198,6 +198,9 @@ class Coupleable
/// Will hold the default value for optional coupled variables.
std::map<std::string, VariableValue *> _default_value;

/// This will always be zero because the default values for optionally coupled variables is always constant and this is used for time derivative info
VariableValue _default_value_zero;

/// This will always be zero because the default values for optionally coupled variables is always constant
VariableGradient _default_gradient;

Expand Down
27 changes: 26 additions & 1 deletion framework/src/base/Coupleable.C
Expand Up @@ -57,6 +57,7 @@ Coupleable::Coupleable(InputParameters & parameters, bool nodal) :
_optional_var_index[name] = std::numeric_limits<unsigned int>::max() - _optional_var_index.size();
}

_default_value_zero.resize(_coupleable_max_qps);
_default_gradient.resize(_coupleable_max_qps);
_default_second.resize(_coupleable_max_qps);
}
Expand Down Expand Up @@ -115,7 +116,7 @@ Coupleable::getVar(const std::string & var_name, unsigned int comp)
unsigned int
Coupleable::coupled(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // If it's optionally coupled just return 0
if (!isCoupled(var_name))
return _optional_var_index[var_name];

MooseVariable * var = getVar(var_name, comp);
Expand Down Expand Up @@ -208,6 +209,9 @@ Coupleable::coupledValueOlder(const std::string & var_name, unsigned int comp)
VariableValue &
Coupleable::coupledDot(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_value_zero;

MooseVariable * var = getVar(var_name, comp);

if (_nodal)
Expand All @@ -219,6 +223,9 @@ Coupleable::coupledDot(const std::string & var_name, unsigned int comp)
VariableValue &
Coupleable::coupledDotDu(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_value_zero;

MooseVariable * var = getVar(var_name, comp);

if (_nodal)
Expand All @@ -231,6 +238,9 @@ Coupleable::coupledDotDu(const std::string & var_name, unsigned int comp)
VariableGradient &
Coupleable::coupledGradient(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_gradient;

coupledCallback(var_name, false);
if (_nodal)
mooseError("Nodal variables do not have gradients");
Expand All @@ -242,6 +252,9 @@ Coupleable::coupledGradient(const std::string & var_name, unsigned int comp)
VariableGradient &
Coupleable::coupledGradientOld(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_gradient;

coupledCallback(var_name, true);
if (_nodal)
mooseError("Nodal variables do not have gradients");
Expand All @@ -254,6 +267,9 @@ Coupleable::coupledGradientOld(const std::string & var_name, unsigned int comp)
VariableGradient &
Coupleable::coupledGradientOlder(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_gradient;

coupledCallback(var_name, true);
if (_nodal)
mooseError("Nodal variables do not have gradients");
Expand All @@ -269,6 +285,9 @@ Coupleable::coupledGradientOlder(const std::string & var_name, unsigned int comp
VariableSecond &
Coupleable::coupledSecond(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_second;

coupledCallback(var_name, false);
if (_nodal)
mooseError("Nodal variables do not have second derivatives");
Expand All @@ -280,6 +299,9 @@ Coupleable::coupledSecond(const std::string & var_name, unsigned int comp)
VariableSecond &
Coupleable::coupledSecondOld(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_second;

coupledCallback(var_name, true);
if (_nodal)
mooseError("Nodal variables do not have second derivatives");
Expand All @@ -292,6 +314,9 @@ Coupleable::coupledSecondOld(const std::string & var_name, unsigned int comp)
VariableSecond &
Coupleable::coupledSecondOlder(const std::string & var_name, unsigned int comp)
{
if (!isCoupled(var_name)) // Return default 0
return _default_second;

coupledCallback(var_name, true);
if (_nodal)
mooseError("Nodal variables do not have second derivatives");
Expand Down
4 changes: 4 additions & 0 deletions test/include/kernels/OptionallyCoupledForce.h
Expand Up @@ -41,6 +41,10 @@ class OptionallyCoupledForce : public Kernel
private:
unsigned int _v_var;
VariableValue & _v;
VariableGradient & _grad_v;
VariableSecond & _second_v;
VariableValue & _v_dot;
VariableValue & _v_dot_du;
bool _v_coupled;
};

Expand Down
4 changes: 4 additions & 0 deletions test/src/kernels/OptionallyCoupledForce.C
Expand Up @@ -28,6 +28,10 @@ OptionallyCoupledForce::OptionallyCoupledForce(const std::string & name, InputPa
Kernel(name, parameters),
_v_var(coupled("v")),
_v(coupledValue("v")),
_grad_v(coupledGradient("v")),
_second_v(coupledSecond("v")),
_v_dot(coupledDot("v")),
_v_dot_du(coupledDotDu("v")),
_v_coupled(isCoupled("v"))
{
if (!_v_coupled && _v_var < 64)
Expand Down

0 comments on commit 5ebf310

Please sign in to comment.