Skip to content

Commit

Permalink
Add error check that variable block restriction is correct for object…
Browse files Browse the repository at this point in the history
… block restriction

(closes idaholab#9889)
  • Loading branch information
aeslaughter committed Oct 23, 2017
1 parent b2799b2 commit cc6bd8f
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
24 changes: 24 additions & 0 deletions framework/src/base/MooseVariableInterface.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "MooseVariable.h"
#include "Problem.h"
#include "SubProblem.h"
#include "BlockRestrictable.h"
#include "MooseMesh.h"
#include "Conversion.h"

MooseVariableInterface::MooseVariableInterface(const MooseObject * moose_object,
bool nodal,
Expand All @@ -42,6 +45,27 @@ MooseVariableInterface::MooseVariableInterface(const MooseObject * moose_object,
_variable = &problem.getVariable(tid, variable_name);

_mvi_assembly = &problem.assembly(tid);

// Check for subdomain consistency
const BlockRestrictable * blk_ptr = dynamic_cast<const BlockRestrictable *>(moose_object);
if (blk_ptr && !blk_ptr->isBlockSubset(_variable->activeSubdomains()))
{
std::string var_ids = Moose::stringify(_variable->activeSubdomains());
std::string obj_ids = Moose::stringify(blk_ptr->blockRestricted() ? blk_ptr->blockIDs()
: blk_ptr->meshBlockIDs());
mooseError("The 'block' parameter of the object '",
moose_object->name(),
"' must be a subset of the 'block' parameter of the variable '",
variable_name,
"':\n ",
moose_object->name(),
": ",
obj_ids,
"\n ",
variable_name,
": ",
var_ids);
}
}

MooseVariableInterface::~MooseVariableInterface() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
[./norm]
type = ElementL2Norm
variable = u
block = 1
[../]
[]

Expand Down
54 changes: 54 additions & 0 deletions test/tests/misc/block_user_object_check/block_check.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[Mesh]
type = GeneratedMesh
dim = 2
nx = 10
ny = 5
[]

[MeshModifiers]
[./left_block]
type = SubdomainBoundingBox
block_id = 1
bottom_left = '0 0 0'
top_right = '0.5 1 0'
[../]
[./right_block]
type = SubdomainBoundingBox
block_id = 2
bottom_left = '0.5 0 0'
top_right = '1 1 0'
[../]
[]

[Variables]
[./var_1]
block = 1
initial_condition = 100
[../]
[./var_2]
block = 2
initial_condition = 200
[../]
[]

[Problem]
type = FEProblem
kernel_coverage_check = true
solve = false
[]

[Executioner]
type = Steady
[]

[Outputs]
[]

[Postprocessors]
[./obj]
type = NodalMaxValue
variable = var_1
#block = 1 # this is what being tested, see the test spec
execute_on = 'initial'
[../]
[]
18 changes: 18 additions & 0 deletions test/tests/misc/block_user_object_check/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Tests]
[./run]
type = RunApp
input = block_check.i
cli_args = 'Postprocessors/obj/block=1'
[../]
[./error_block_set]
type = RunException
input = block_check.i
cli_args = "Postprocessors/obj/block='1 2'"
expect_err = 'must be a subset'
[../]
[./error_block_any]
type = RunException
input = block_check.i
expect_err = 'must be a subset'
[../]
[]

0 comments on commit cc6bd8f

Please sign in to comment.