Skip to content

Commit

Permalink
add more interface functions in Coupleable idaholab#17586
Browse files Browse the repository at this point in the history
  • Loading branch information
YaqiWang committed Apr 16, 2021
1 parent d8704bd commit faef722
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 12 deletions.
2 changes: 0 additions & 2 deletions framework/include/auxkernels/TagMatrixAux.h
Expand Up @@ -31,7 +31,5 @@ class TagMatrixAux : public AuxKernel
protected:
virtual Real computeValue() override;

TagID _tag_id;
const VariableValue & _v;
};

2 changes: 0 additions & 2 deletions framework/include/auxkernels/TagVectorAux.h
Expand Up @@ -31,7 +31,5 @@ class TagVectorAux : public AuxKernel
protected:
virtual Real computeValue() override;

TagID _tag_id;
const VariableValue & _v;
};

30 changes: 30 additions & 0 deletions framework/include/interfaces/Coupleable.h
Expand Up @@ -236,6 +236,8 @@ class Coupleable
std::vector<const ADVectorVariableValue *>
adCoupledVectorValues(const std::string & var_name) const;

bool isTagNameValid(const std::string & tag_name) const;

/**
* Returns value of a coupled variable for a given tag
* @param var_name Name of coupled variable
Expand All @@ -247,6 +249,10 @@ class Coupleable
virtual const VariableValue &
coupledVectorTagValue(const std::string & var_name, TagID tag, unsigned int comp = 0) const;

virtual const VariableValue & coupledVectorTagValue(const std::string & var_name,
const std::string & tag_name,
unsigned int comp = 0) const;

/**
* Returns the values for all of a coupled variable's components for a given tag
* @param var_name Name of coupled variable
Expand All @@ -256,6 +262,9 @@ class Coupleable
std::vector<const VariableValue *> coupledVectorTagValues(const std::string & var_name,
TagID tag) const;

std::vector<const VariableValue *> coupledVectorTagValues(const std::string & var_name,
const std::string & tag_name) const;

/**
* Returns gradient of a coupled variable for a given tag
* @param var_name Name of coupled variable
Expand All @@ -267,6 +276,10 @@ class Coupleable
virtual const VariableGradient &
coupledVectorTagGradient(const std::string & var_name, TagID tag, unsigned int comp = 0) const;

virtual const VariableGradient & coupledVectorTagGradient(const std::string & var_name,
const std::string & tag_name,
unsigned int comp = 0) const;

/**
* Returns gradients for all of a coupled variable's components for a given tag
* @param var_name Name of coupled variable
Expand All @@ -276,6 +289,9 @@ class Coupleable
std::vector<const VariableGradient *> coupledVectorTagGradients(const std::string & var_name,
TagID tag) const;

std::vector<const VariableGradient *>
coupledVectorTagGradients(const std::string & var_name, const std::string & tag_name) const;

/**
* Returns dof value of a coupled variable for a given tag
* @param var_name Name of coupled variable
Expand All @@ -286,6 +302,10 @@ class Coupleable
virtual const VariableValue &
coupledVectorTagDofValue(const std::string & var_name, TagID tag, unsigned int comp = 0) const;

virtual const VariableValue & coupledVectorTagDofValue(const std::string & var_name,
const std::string & tag_name,
unsigned int comp = 0) const;

/**
* Returns the dof values for all of a coupled variable's components for a given tag
* @param var_name Name of coupled variable
Expand All @@ -295,6 +315,9 @@ class Coupleable
std::vector<const VariableValue *> coupledVectorTagDofValues(const std::string & var_name,
TagID tag) const;

std::vector<const VariableValue *> coupledVectorTagDofValues(const std::string & var_name,
const std::string & tag_name) const;

/**
* Returns value of a coupled variable for a given tag. This couples the diag vector of matrix
* @param var_name Name of coupled variable
Expand All @@ -306,6 +329,10 @@ class Coupleable
virtual const VariableValue &
coupledMatrixTagValue(const std::string & var_name, TagID tag, unsigned int comp = 0) const;

virtual const VariableValue & coupledMatrixTagValue(const std::string & var_name,
const std::string & tag_name,
unsigned int comp = 0) const;

/**
* Returns the diagonal matrix values for all of a coupled variable's components for a given tag
* @param var_name Name of coupled variable
Expand All @@ -315,6 +342,9 @@ class Coupleable
std::vector<const VariableValue *> coupledMatrixTagValues(const std::string & var_name,
TagID tag) const;

std::vector<const VariableValue *> coupledMatrixTagValues(const std::string & var_name,
const std::string & tag_name) const;

/**
* Returns value of a coupled vector variable
* @param var_name Name of coupled vector variable
Expand Down
6 changes: 2 additions & 4 deletions framework/src/auxkernels/TagMatrixAux.C
Expand Up @@ -17,7 +17,7 @@ InputParameters
TagMatrixAux::validParams()
{
InputParameters params = AuxKernel::validParams();
params.addParam<std::string>("matrix_tag", "TagName", "Tag Name this Aux works on");
params.addParam<TagName>("matrix_tag", "TagName", "Tag Name this Aux works on");
params.addRequiredCoupledVar("v",
"The coupled variable whose components are coupled to AuxVariable");
params.set<ExecFlagEnum>("execute_on", true) = {EXEC_TIMESTEP_END};
Expand All @@ -27,9 +27,7 @@ TagMatrixAux::validParams()
}

TagMatrixAux::TagMatrixAux(const InputParameters & parameters)
: AuxKernel(parameters),
_tag_id(_subproblem.getMatrixTagID(getParam<std::string>("matrix_tag"))),
_v(coupledMatrixTagValue("v", _tag_id))
: AuxKernel(parameters), _v(coupledMatrixTagValue("v", "matrix_tag"))
{
auto & execute_on = getParam<ExecFlagEnum>("execute_on");
if (execute_on.size() != 1 || !execute_on.contains(EXEC_TIMESTEP_END))
Expand Down
6 changes: 2 additions & 4 deletions framework/src/auxkernels/TagVectorAux.C
Expand Up @@ -18,7 +18,7 @@ TagVectorAux::validParams()
{
InputParameters params = AuxKernel::validParams();

params.addRequiredParam<std::string>("vector_tag", "Tag Name this Aux works on");
params.addRequiredParam<TagName>("vector_tag", "Tag Name this Aux works on");
params.addRequiredCoupledVar("v",
"The coupled variable whose components are coupled to AuxVariable");
params.set<ExecFlagEnum>("execute_on", true) = {EXEC_TIMESTEP_END};
Expand All @@ -28,9 +28,7 @@ TagVectorAux::validParams()
}

TagVectorAux::TagVectorAux(const InputParameters & parameters)
: AuxKernel(parameters),
_tag_id(_subproblem.getVectorTagID(getParam<std::string>("vector_tag"))),
_v(coupledVectorTagValue("v", _tag_id))
: AuxKernel(parameters), _v(coupledVectorTagValue("v", "vector_tag"))
{
auto & execute_on = getParam<ExecFlagEnum>("execute_on");
if (execute_on.size() != 1 || !execute_on.contains(EXEC_TIMESTEP_END))
Expand Down
128 changes: 128 additions & 0 deletions framework/src/interfaces/Coupleable.C
Expand Up @@ -469,6 +469,12 @@ Coupleable::coupledValueLower(const std::string & var_name, unsigned int comp) c
return (_c_is_implicit) ? var->slnLower() : var->slnLowerOld();
}

bool
Coupleable::isTagNameValid(const std::string & tag_name) const
{
return _c_parameters.isParamValid(tag_name) && _c_parameters.get<TagName>(tag_name).length() > 0;
}

const VariableValue &
Coupleable::coupledVectorTagValue(const std::string & var_name, TagID tag, unsigned int comp) const
{
Expand All @@ -492,6 +498,22 @@ Coupleable::coupledVectorTagValue(const std::string & var_name, TagID tag, unsig
return var->vectorTagValue(tag);
}

const VariableValue &
Coupleable::coupledVectorTagValue(const std::string & var_name,
const std::string & tag_name,
unsigned int comp) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledValue(var_name, comp);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledValue(var_name, comp);

TagID tag = _c_fe_problem.getVectorTagID(tagname);
return coupledVectorTagValue(var_name, tag, comp);
}

const VariableGradient &
Coupleable::coupledVectorTagGradient(const std::string & var_name,
TagID tag,
Expand All @@ -514,6 +536,22 @@ Coupleable::coupledVectorTagGradient(const std::string & var_name,
return var->vectorTagGradient(tag);
}

const VariableGradient &
Coupleable::coupledVectorTagGradient(const std::string & var_name,
const std::string & tag_name,
unsigned int comp) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledGradient(var_name, comp);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledGradient(var_name, comp);

TagID tag = _c_fe_problem.getVectorTagID(tagname);
return coupledVectorTagGradient(var_name, tag, comp);
}

const VariableValue &
Coupleable::coupledVectorTagDofValue(const std::string & var_name,
TagID tag,
Expand All @@ -529,6 +567,22 @@ Coupleable::coupledVectorTagDofValue(const std::string & var_name,
return var->vectorTagDofValue(tag);
}

const VariableValue &
Coupleable::coupledVectorTagDofValue(const std::string & var_name,
const std::string & tag_name,
unsigned int comp) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledDofValues(var_name, comp);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledDofValues(var_name, comp);

TagID tag = _c_fe_problem.getVectorTagID(tagname);
return coupledVectorTagDofValue(var_name, tag, comp);
}

const VariableValue &
Coupleable::coupledMatrixTagValue(const std::string & var_name, TagID tag, unsigned int comp) const
{
Expand All @@ -544,6 +598,22 @@ Coupleable::coupledMatrixTagValue(const std::string & var_name, TagID tag, unsig
return var->matrixTagValue(tag);
}

const VariableValue &
Coupleable::coupledMatrixTagValue(const std::string & var_name,
const std::string & tag_name,
unsigned int comp) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledValue(var_name, comp);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledValue(var_name, comp);

TagID tag = _c_fe_problem.getMatrixTagID(tagname);
return coupledMatrixTagValue(var_name, tag, comp);
}

const VectorVariableValue &
Coupleable::coupledVectorValue(const std::string & var_name, unsigned int comp) const
{
Expand Down Expand Up @@ -1951,6 +2021,20 @@ Coupleable::coupledVectorTagValues(const std::string & var_name, TagID tag) cons
return coupledVectorHelper<const VariableValue *>(var_name, func);
}

std::vector<const VariableValue *>
Coupleable::coupledVectorTagValues(const std::string & var_name, const std::string & tag_name) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledValues(var_name);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledValues(var_name);

TagID tag = _c_fe_problem.getVectorTagID(tagname);
return coupledVectorTagValues(var_name, tag);
}

std::vector<const VariableGradient *>
Coupleable::coupledVectorTagGradients(const std::string & var_name, TagID tag) const
{
Expand All @@ -1960,6 +2044,21 @@ Coupleable::coupledVectorTagGradients(const std::string & var_name, TagID tag) c
return coupledVectorHelper<const VariableGradient *>(var_name, func);
}

std::vector<const VariableGradient *>
Coupleable::coupledVectorTagGradients(const std::string & var_name,
const std::string & tag_name) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledGradients(var_name);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledGradients(var_name);

TagID tag = _c_fe_problem.getVectorTagID(tagname);
return coupledVectorTagGradients(var_name, tag);
}

std::vector<const VariableValue *>
Coupleable::coupledVectorTagDofValues(const std::string & var_name, TagID tag) const
{
Expand All @@ -1969,6 +2068,21 @@ Coupleable::coupledVectorTagDofValues(const std::string & var_name, TagID tag) c
return coupledVectorHelper<const VariableValue *>(var_name, func);
}

std::vector<const VariableValue *>
Coupleable::coupledVectorTagDofValues(const std::string & var_name,
const std::string & tag_name) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledAllDofValues(var_name);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledAllDofValues(var_name);

TagID tag = _c_fe_problem.getVectorTagID(tagname);
return coupledVectorTagDofValues(var_name, tag);
}

std::vector<const VariableValue *>
Coupleable::coupledMatrixTagValues(const std::string & var_name, TagID tag) const
{
Expand All @@ -1978,6 +2092,20 @@ Coupleable::coupledMatrixTagValues(const std::string & var_name, TagID tag) cons
return coupledVectorHelper<const VariableValue *>(var_name, func);
}

std::vector<const VariableValue *>
Coupleable::coupledMatrixTagValues(const std::string & var_name, const std::string & tag_name) const
{
if (!_c_parameters.isParamValid(tag_name))
return coupledValues(var_name);

TagName tagname = _c_parameters.get<TagName>(tag_name);
if (tagname.empty())
return coupledValues(var_name);

TagID tag = _c_fe_problem.getMatrixTagID(tagname);
return coupledMatrixTagValues(var_name, tag);
}

std::vector<const VariableValue *>
Coupleable::coupledValuesOld(const std::string & var_name) const
{
Expand Down

0 comments on commit faef722

Please sign in to comment.