Skip to content

Commit

Permalink
Remove BlockRestrictable assumptions about 'variable' parameter
Browse files Browse the repository at this point in the history
Assuming the blocks ids to match 'variable' command is not very robust, what if it is coupled?
(refs idaholab#9889)
  • Loading branch information
aeslaughter committed Oct 23, 2017
1 parent a269d62 commit 5e9ae2a
Show file tree
Hide file tree
Showing 42 changed files with 148 additions and 54 deletions.
9 changes: 9 additions & 0 deletions framework/include/base/BlockRestrictable.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,15 @@ class BlockRestrictable
*/
void checkVariable(const MooseVariable & variable) const;

///@{
/**
* Static methods to use by sibling classes to verify variable block restriction
* is consistent with the object block restriction.
*/
static void checkVariable(const MooseVariable & variable, const std::string & obj_name, const std::set<SubdomainID> & block_ids, MooseMesh * mesh);
static bool isBlockSubset(const std::set<SubdomainID> & block_ids, const std::set<SubdomainID> & ids, MooseMesh * mesh);
///@}

protected:
/// Pointer to the MaterialData class for this object
std::shared_ptr<MaterialData> _blk_material_data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,7 @@ class CoupleableMooseVariableDependencyIntermediateInterface
{
public:
CoupleableMooseVariableDependencyIntermediateInterface(const MooseObject * moose_object,
bool nodal)
: Coupleable(moose_object, nodal),
ScalarCoupleable(moose_object),
MooseVariableInterface(moose_object, nodal)
{
const std::vector<MooseVariable *> & coupled_vars = getCoupledMooseVars();
for (unsigned int i = 0; i < coupled_vars.size(); i++)
addMooseVariableDependency(coupled_vars[i]);

addMooseVariableDependency(mooseVariable());
}
bool nodal);
};

#endif // COUPLEABLEMOOSEVARIABLEDEPENDENCYINTERMEDIATEINTERFACE_H
13 changes: 13 additions & 0 deletions framework/include/base/MooseObjectWarehouseBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "BoundaryRestrictable.h"
#include "BlockRestrictable.h"
#include "TransientInterface.h"
#include "Coupleable.h"
#include "MooseVariableInterface.h"

// Forward declarations
class MooseVariable;
Expand Down Expand Up @@ -262,6 +264,17 @@ MooseObjectWarehouseBase<T>::addObject(std::shared_ptr<T> object, THREAD_ID tid
if (enabled)
_active_block_objects[tid][*it].push_back(object);
}

// Check variables
std::shared_ptr<Coupleable> c_ptr = std::dynamic_pointer_cast<Coupleable>(object);
if (c_ptr)
for (MooseVariable * var : c_ptr->getCoupledMooseVars())
blk->checkVariable(*var);

std::shared_ptr<MooseVariableInterface> mvi_ptr =
std::dynamic_pointer_cast<MooseVariableInterface>(object);
if (mvi_ptr)
blk->checkVariable(*(mvi_ptr->mooseVariable()));
}
}

Expand Down
1 change: 1 addition & 0 deletions framework/include/dgkernels/DGKernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "DGKernelBase.h"
#include "BlockRestrictable.h"
#include "TwoMaterialPropertyInterface.h"
#include "NeighborCoupleableMooseVariableDependencyIntermediateInterface.h"

class DGKernel;

Expand Down
3 changes: 3 additions & 0 deletions framework/src/actions/CheckIntegrityAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "CheckIntegrityAction.h"
#include "ActionWarehouse.h"
#include "FEProblem.h"
#include "BlockRestrictable.h"
#include "Coupleable.h"
#include "MooseVariableInterface.h"

template <>
InputParameters
Expand Down
10 changes: 9 additions & 1 deletion framework/src/actions/SetupResidualDebugAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "FEProblem.h"
#include "MooseVariable.h"
#include "NonlinearSystemBase.h"
#include "Conversion.h"

template <>
InputParameters
Expand Down Expand Up @@ -50,6 +51,7 @@ SetupResidualDebugAction::act()
{
// add aux-variable
MooseVariable & var = _problem->getVariable(0, var_name);
InputParameters params = _factory.getValidParams("DebugResidualAux");
const std::set<SubdomainID> & subdomains = var.activeSubdomains();

std::stringstream aux_var_ss;
Expand All @@ -59,14 +61,20 @@ SetupResidualDebugAction::act()
if (subdomains.empty())
_problem->addAuxVariable(aux_var_name, FEType(FIRST, LAGRANGE));
else
{
_problem->addAuxVariable(aux_var_name, FEType(FIRST, LAGRANGE), &subdomains);
std::vector<SubdomainName> block_names;
block_names.reserve(subdomains.size());
for (const SubdomainID & id : subdomains)
block_names.push_back(Moose::stringify(id));
params.set<std::vector<SubdomainName>>("block") = block_names;
}

// add aux-kernel
std::stringstream kern_ss;
kern_ss << "residual_" << var.name() << "_kernel";
std::string kern_name = kern_ss.str();

InputParameters params = _factory.getValidParams("DebugResidualAux");
params.set<AuxVariableName>("variable") = aux_var_name;
params.set<NonlinearVariableName>("debug_variable") = var.name();
params.set<MultiMooseEnum>("execute_on") = "linear timestep_end";
Expand Down
34 changes: 7 additions & 27 deletions framework/src/base/BlockRestrictable.C
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "MooseVariable.h"
#include "SystemBase.h"
#include "Conversion.h"
#include "MooseVariableInterface.h"

template <>
InputParameters
Expand Down Expand Up @@ -104,29 +105,8 @@ BlockRestrictable::initializeBlockRestrictable(const MooseObject * moose_object)
_blk_ids.insert(Moose::ANY_BLOCK_ID);
else
_blk_ids.insert(vec_ids.begin(), vec_ids.end());

// Check that supplied blocks are within the variable domain
if (parameters.isParamValid("variable") &&
(parameters.have_parameter<NonlinearVariableName>("variable") ||
parameters.have_parameter<AuxVariableName>("variable")))
{
// A pointer to the variable class
std::set<SubdomainID> var_ids = variableSubdomainIDs(parameters);

// Test if the variable blockIDs are valid for this object
if (!isBlockSubset(var_ids))
mooseError("In object ",
_blk_name,
" the defined blocks are outside of the domain of the variable");
}
}

// The 'block' input parameter is undefined, if the object contains a variable, set the subdomain
// ids to those of the variable
else if (parameters.isParamValid("variable") &&
(parameters.have_parameter<NonlinearVariableName>("variable") ||
parameters.have_parameter<AuxVariableName>("variable")))
_blk_ids = variableSubdomainIDs(parameters);

// Produce error if the object is not allowed to be both block and boundary restricted
if (!_blk_dual_restrictable && !_boundary_ids.empty() && !_boundary_ids.empty())
Expand Down Expand Up @@ -352,19 +332,19 @@ BlockRestrictable::checkVariable(const MooseVariable & variable) const
{
if (!isBlockSubset(variable.activeSubdomains()))
{
std::string var_ids = Moose::stringify(variable.activeSubdomains());
std::string obj_ids = Moose::stringify(blockRestricted() ? blockIDs() : meshBlockIDs());
std::string var_ids = Moose::stringify(variable.activeSubdomains(), ", ");
std::string obj_ids = Moose::stringify(blockRestricted() ? _blk_ids : meshBlockIDs(), ", ");
mooseError("The 'block' parameter of the object '",
_blk_name,
"' must be a subset of the 'block' parameter of the variable '",
variable.name(),
"':\n ",
"':\n Object '",
_blk_name,
": ",
"': ",
obj_ids,
"\n ",
"\n Variable '",
variable.name(),
": ",
"': ",
var_ids);
}
}
6 changes: 0 additions & 6 deletions framework/src/base/Coupleable.C
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ Coupleable::Coupleable(const MooseObject * moose_object, bool nodal)

THREAD_ID tid = _c_parameters.get<THREAD_ID>("_tid");

// Convert to BlockRestrictable to check variable block ids
const BlockRestrictable * blk_ptr = dynamic_cast<const BlockRestrictable *>(moose_object);

// Coupling
for (std::set<std::string>::const_iterator iter = _c_parameters.coupledVarsBegin();
iter != _c_parameters.coupledVarsEnd();
Expand All @@ -56,9 +53,6 @@ Coupleable::Coupleable(const MooseObject * moose_object, bool nodal)
MooseVariable * moose_var = &problem.getVariable(tid, coupled_var_name);
_coupled_vars[name].push_back(moose_var);
_coupled_moose_vars.push_back(moose_var);

if (blk_ptr)
blk_ptr->checkVariable(*moose_var);
}
else if (problem.hasScalarVariable(coupled_var_name))
; // ignore scalar variables
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "CoupleableMooseVariableDependencyIntermediateInterface.h"
#include "MooseVariable.h"
#include "FEProblemBase.h"
#include "MooseMesh.h"
#include "Conversion.h"

CoupleableMooseVariableDependencyIntermediateInterface::
CoupleableMooseVariableDependencyIntermediateInterface(const MooseObject * moose_object,
bool nodal)
: Coupleable(moose_object, nodal),
ScalarCoupleable(moose_object),
MooseVariableInterface(moose_object, nodal)
{
for (MooseVariable * coupled_var : getCoupledMooseVars())
addMooseVariableDependency(coupled_var);

addMooseVariableDependency(mooseVariable());
}
4 changes: 4 additions & 0 deletions modules/combined/examples/mortar/eigenstrain.i
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,29 @@
[Kernels]
# Set up stress divergence kernels
[./TensorMechanics]
block = 0
[../]

# Cahn-Hilliard kernels
[./c_dot]
type = CoupledTimeDerivative
variable = w
v = c
block = 0
[../]
[./c_res]
type = SplitCHParsed
variable = c
f_name = F
kappa_name = kappa_c
w = w
block = 0
[../]
[./w_res]
type = SplitCHWRes
variable = w
mob_name = M
block = 0
[../]
[]

Expand Down
9 changes: 9 additions & 0 deletions modules/combined/examples/mortar/mortar_gradient.i
Original file line number Diff line number Diff line change
Expand Up @@ -102,30 +102,36 @@
[./diff]
type = Diffusion
variable = c
block = 0
[../]
[./dt]
type = TimeDerivative
variable = c
block = 0
[../]

# the un-constrained concentration
[./diff2]
type = Diffusion
variable = v
block = 0
[../]
[./dt2]
type = TimeDerivative
variable = v
block = 0
[../]

# the value periodic concentration
[./diff3]
type = Diffusion
variable = p
block = 0
[../]
[./dt3]
type = TimeDerivative
variable = p
block = 0
[../]
[]

Expand Down Expand Up @@ -217,6 +223,7 @@
variable = diff_constraint
function = 'c-v'
args = 'c v'
block = 0
[../]

# difference between the periodic gradient constrained diffusion and the flat
Expand All @@ -229,6 +236,7 @@
variable = diff_periodic
function = 'c-p-slope'
args = 'c p slope'
block = 0
[../]

# subtract the constant slope from the gradient periodic simulation (should yield
Expand All @@ -238,6 +246,7 @@
variable = diff_slope
function = 'c-slope'
args = 'c slope'
block = 0
[../]
[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
type = HeatConduction
variable = temp
use_displaced_mesh = false
block = '1 2'
[../]
[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
type = ConstantAux
variable = disp_x
value = 0.1
block = '1'
[../]

[./disp_y_kernel]
type = ConstantAux
variable = disp_y
value = 0
block = '1'
[../]
[]

Expand Down Expand Up @@ -69,6 +71,7 @@
type = HeatConduction
variable = temp
use_displaced_mesh = true
block = '1 2'
[../]
[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
[Materials]
[./hcm]
type = HeatConductionMaterial
block = '1 2 3'
block = '1 3'
temp = temp
thermal_conductivity = 1
[../]
Expand All @@ -54,6 +54,7 @@
[Problem]
type = FEProblem
kernel_coverage_check = false
material_coverage_check = false
[]

[Executioner]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
[Materials]
[./hcm]
type = HeatConductionMaterial
block = '1 2 3'
block = '1 3'
temp = temp
thermal_conductivity = 1
[../]
Expand All @@ -55,6 +55,7 @@
[Problem]
type = FEProblem
kernel_coverage_check = false
material_coverage_check = false
[]

[Executioner]
Expand Down

0 comments on commit 5e9ae2a

Please sign in to comment.