Skip to content

Commit

Permalink
Add test for creating array variables in an action
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour committed Dec 7, 2021
1 parent 209de50 commit 49b4b02
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 22 deletions.
43 changes: 31 additions & 12 deletions test/src/actions/AddLotsOfDiffusion.C
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@
#include "libmesh/fe.h"

registerMooseAction("MooseTestApp", AddLotsOfDiffusion, "add_variable");

registerMooseAction("MooseTestApp", AddLotsOfDiffusion, "add_kernel");

registerMooseAction("MooseTestApp", AddLotsOfDiffusion, "add_bc");
registerMooseAction("MooseTestApp", AddLotsOfDiffusion, "add_material");

InputParameters
AddLotsOfDiffusion::validParams()
Expand All @@ -51,7 +50,7 @@ AddLotsOfDiffusion::validParams()
"LAGRANGE");
params.addParam<MooseEnum>(
"family", family, "Specifies the family of FE shape functions to use for this variable.");

params.addParam<bool>("array", false, "Whether or not to use array variables");
params.addRequiredParam<unsigned int>("number", "The number of variables to add");

return params;
Expand All @@ -64,15 +63,18 @@ AddLotsOfDiffusion::act()
{
unsigned int number = getParam<unsigned int>("number");

const auto array = getParam<bool>("array");

if (_current_task == "add_variable")
{
auto fe_type = AddVariableAction::feType(_pars);
auto type = AddVariableAction::variableType(fe_type);
auto type = AddVariableAction::variableType(fe_type, false, array);
auto var_params = _factory.getValidParams(type);

var_params.set<MooseEnum>("family") = getParam<MooseEnum>("family");
var_params.set<MooseEnum>("order") = getParam<MooseEnum>("order");

if (array)
var_params.set<unsigned int>("components") = 2;
for (unsigned int cur_num = 0; cur_num < number; cur_num++)
{
std::string var_name = name() + Moose::stringify(cur_num);
Expand All @@ -84,29 +86,46 @@ AddLotsOfDiffusion::act()
for (unsigned int cur_num = 0; cur_num < number; cur_num++)
{
std::string var_name = name() + Moose::stringify(cur_num);
const auto kernel_type = array ? "ArrayDiffusion" : "Diffusion";

InputParameters params = _factory.getValidParams("Diffusion");
InputParameters params = _factory.getValidParams(kernel_type);
params.set<NonlinearVariableName>("variable") = var_name;
_problem->addKernel("Diffusion", var_name, params);
if (array)
params.set<MaterialPropertyName>("diffusion_coefficient") = "dc";
_problem->addKernel(kernel_type, var_name, params);
}
}
else if (_current_task == "add_bc")
{
for (unsigned int cur_num = 0; cur_num < number; cur_num++)
{
std::string var_name = name() + Moose::stringify(cur_num);
const auto bc_type = array ? "ArrayDirichletBC" : "DirichletBC";

InputParameters params = _factory.getValidParams("DirichletBC");
InputParameters params = _factory.getValidParams(bc_type);
params.set<NonlinearVariableName>("variable") = var_name;
params.set<std::vector<BoundaryName>>("boundary").push_back("left");
params.set<Real>("value") = 0;
if (array)
params.set<RealEigenVector>("values") = RealEigenVector::Constant(2, 0);
else
params.set<Real>("value") = 0;

_problem->addBoundaryCondition("DirichletBC", var_name + "_left", params);
_problem->addBoundaryCondition(bc_type, var_name + "_left", params);

params.set<std::vector<BoundaryName>>("boundary")[0] = "right";
params.set<Real>("value") = 1;
if (array)
params.set<RealEigenVector>("values") = RealEigenVector::Constant(2, 1);
else
params.set<Real>("value") = 1;

_problem->addBoundaryCondition("DirichletBC", var_name + "_right", params);
_problem->addBoundaryCondition(bc_type, var_name + "_right", params);
}
}
else if (_current_task == "add_material" && array)
{
auto params = _factory.getValidParams("GenericConstantArray");
params.set<std::string>("prop_name") = "dc";
params.set<RealEigenVector>("prop_value") = RealEigenVector::Constant(2, 1);
_problem->addMaterial("GenericConstantArray", "dc", params);
}
}
21 changes: 21 additions & 0 deletions test/tests/variables/array_variable/array_variable_action.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[Mesh]
[gmg]
type = GeneratedMeshGenerator
dim = 2
nx = 3
ny = 3
[]
[]

[Testing/LotsOfDiffusion/lots]
number = 1
array = true
[]

[Executioner]
type = Steady
[]

[Outputs]
exodus = true
[]
Binary file not shown.
23 changes: 13 additions & 10 deletions test/tests/variables/array_variable/tests
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
[Tests]
[./block_aux_kernel_test]
issues = '#19564'
design = 'ArrayMooseVariable.md'

[block_aux_kernel_test]
type = 'Exodiff'
input = 'array_variable_test.i'
exodiff = 'array_variable_test_out.e'
requirement = 'MOOSE shall provide an ability to add array variables with constant initial conditions.'
issues = '#6881'
design = 'ArrayMooseVariable.md'
[../]
[array_variable_size_one]
[]
[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 variable with component size one.'
issues = '#19564'
design = 'ArrayMooseVariable.md'
[]
[array_variable_array_false]
[array_false_error]
type = 'RunException'
input = 'array_variable_size_one_test.i'
cli_args = 'Variables/u/components=2 Variables/u/array=false'
requirement = 'MOOSE shall report a reasonable error when defining a variable with multiple components not as an array variable.'
issues = '#19564'
expect_err = "'array' is set to false."
design = 'ArrayMooseVariable.md'
[]
[action]
type = 'Exodiff'
input = 'array_variable_action.i'
exodiff = 'array_variable_action_out.e'
requirement = 'MOOSE shall support the automated creation of array variables.'
[]
[]

0 comments on commit 49b4b02

Please sign in to comment.