Skip to content

Commit

Permalink
Allowing to define an array varible with component size one, refs ida…
Browse files Browse the repository at this point in the history
  • Loading branch information
yjung-anl committed Dec 7, 2021
1 parent d3a9b36 commit 1182e21
Show file tree
Hide file tree
Showing 7 changed files with 101 additions and 7 deletions.
6 changes: 4 additions & 2 deletions framework/include/actions/AddVariableAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ class AddVariableAction : public MooseObjectAction
/**
* determine the variable type given an FEType and number of components
*/
static std::string
determineType(const FEType & fe_type, unsigned int components, bool is_fv = false);
static std::string determineType(const FEType & fe_type,
unsigned int components,
bool is_fv = false,
bool is_array_variable = false);

protected:
/**
Expand Down
11 changes: 8 additions & 3 deletions framework/src/actions/AddVariableAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ AddVariableAction::init()

// Determine the MooseVariable type
bool is_fv = _moose_object_pars.get<bool>("fv");
bool is_array_variable =
(_components > 1 || _moose_object_pars.get<bool>("array_variable")) ? true : false;
if (_type == "MooseVariableBase")
_type = determineType(_fe_type, _components, is_fv);
_type = determineType(_fe_type, _components, is_fv, is_array_variable);
if (is_fv)
_problem->needFV();

Expand Down Expand Up @@ -223,12 +225,15 @@ AddVariableAction::createInitialConditionAction()
}

std::string
AddVariableAction::determineType(const FEType & fe_type, unsigned int components, bool is_fv)
AddVariableAction::determineType(const FEType & fe_type,
unsigned int components,
bool is_fv,
bool is_array_variable)
{
if (is_fv)
return "MooseVariableFVReal";

if (components > 1)
if (components > 1 || is_array_variable)
{
if (fe_type.family == LAGRANGE_VEC || fe_type.family == NEDELEC_ONE ||
fe_type.family == MONOMIAL_VEC)
Expand Down
3 changes: 3 additions & 0 deletions framework/src/systems/SystemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,9 @@ SystemBase::addVariable(const std::string & var_type,
// The number returned by libMesh is the _last_ variable number... we want to hold onto the
// _first_
var_num = system().add_variables(var_names, fe_type, &blocks) - (components - 1);

// Set as array variable
parameters.set<bool>("array_variable") = true;
}
else
var_num = system().add_variable(name, fe_type, &blocks);
Expand Down
13 changes: 11 additions & 2 deletions framework/src/variables/MooseVariableBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ MooseVariableBase::validParams()
"Specifies a scaling factor to apply to this variable");
params.addParam<bool>("eigen", false, "True to make this variable an eigen variable");
params.addParam<bool>("fv", false, "True to make this variable a finite volume variable");
params.addParam<bool>(
"array_variable",
false,
"True to make this variable a array variable regardless of number of components");
params.addParamNamesToGroup("scaling eigen", "Advanced");

params.addParam<bool>("use_dual", false, "True to use dual basis for Lagrange multipliers");
Expand Down Expand Up @@ -107,8 +111,10 @@ MooseVariableBase::MooseVariableBase(const InputParameters & parameters)
paramError("family", "finite volume (fv=true) variables must be have MONOMIAL family");
if (getParam<bool>("fv") && _fe_type.order != 0)
paramError("order", "finite volume (fv=true) variables currently support CONST order only");

if (_count > 1)
bool is_array_variable = getParam<bool>("array_variable");
if (!is_array_variable && _count > 1)
paramError("array_variable", "array_variable must be true if 'component' is greater than one");
if (is_array_variable)
{
auto name0 = _sys.system().variable(_var_num).name();
std::size_t found = name0.find_last_of("_");
Expand All @@ -117,7 +123,10 @@ MooseVariableBase::MooseVariableBase(const InputParameters & parameters)
_var_name = name0.substr(0, found);
}
else
{
mooseAssert(_count == 1, "component size of normal variable (_count) must be one");
_var_name = _sys.system().variable(_var_num).name();
}
}

const std::vector<dof_id_type> &
Expand Down
67 changes: 67 additions & 0 deletions test/tests/variables/array_variable/array_variable_size_one_test.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[Mesh]
[square]
type = GeneratedMeshGenerator
nx = 3
ny = 3
dim = 2
[]
[]

[Variables]
[u]
order = THIRD
family = MONOMIAL
components = 1
array_variable = true
[]
[]

[Kernels]
[diff]
type = ArrayDiffusion
variable = u
diffusion_coefficient = dc
[]
[reaction]
type = ArrayReaction
variable = u
reaction_coefficient = rc
[]
[source]
type = ArrayBodyForce
variable = u
function = '1'
[]
[]

[BCs]
[all]
type = ArrayVacuumBC
boundary = 'left right top bottom'
variable = u
[]
[]

[Materials]
[dc]
type = GenericConstantArray
prop_name = dc
prop_value = '1'
[]
[rc]
type = GenericConstantArray
prop_name = rc
prop_value = '2'
[]
[]

[Executioner]
type = Steady
solve_type = 'NEWTON'
[]

[Outputs]
[out]
type = Exodus
[]
[]
Binary file not shown.
8 changes: 8 additions & 0 deletions test/tests/variables/array_variable/tests
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@
issues = '#6881'
design = 'ArrayMooseVariable.md'
[../]
[./array_variable_size_one]
type = 'Exodiff'
input = 'array_variable_size_one_test.i'
exodiff = 'array_variable_size_one_test_out.e'
requirement = 'MOOSE shall be able to define an array varibale with component size one.'
issues = '#19564'
design = 'ArrayMooseVariable.md'
[../]
[]

0 comments on commit 1182e21

Please sign in to comment.