Skip to content

Commit

Permalink
Add variable and block boundary check to coupled variables
Browse files Browse the repository at this point in the history
  • Loading branch information
aeslaughter committed Oct 30, 2017
1 parent 54cb49e commit 78f7623
Show file tree
Hide file tree
Showing 11 changed files with 167 additions and 68 deletions.
14 changes: 13 additions & 1 deletion framework/include/base/BlockRestrictable.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
class BlockRestrictable;
class FEProblemBase;
class MooseMesh;
class MooseVariable;

template <>
InputParameters validParams<BlockRestrictable>();
Expand Down Expand Up @@ -189,6 +190,14 @@ class BlockRestrictable
*/
virtual bool blockRestricted() const;

/**
* Helper for checking that the ids for this object are in agreement with the variables
* on the supplied variable.
*
* @param variable The variable to check against.
*/
void checkVariable(const MooseVariable & variable) const;

protected:
/// Pointer to the MaterialData class for this object
std::shared_ptr<MaterialData> _blk_material_data;
Expand All @@ -212,7 +221,7 @@ class BlockRestrictable
Moose::CoordinateSystemType getBlockCoordSystem();

private:
/// Set of block ids supplied by the user via the input file
/// Set of block ids supplied by the user via the input file (for error reporting)
std::set<SubdomainID> _blk_ids;

/// Vector the block names supplied by the user via the input file
Expand All @@ -238,6 +247,9 @@ class BlockRestrictable
/// Thread id for this object
THREAD_ID _blk_tid;

/// Name of the object
const std::string & _blk_name;

/**
* A helper function for extracting the subdomain IDs for a variable
* @param parameters A reference to the input parameters supplied to the object
Expand Down
2 changes: 1 addition & 1 deletion framework/include/base/Coupleable.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ class Coupleable
std::vector<MooseVariable *> _coupled_moose_vars;

/// True if we provide coupling to nodal values
bool _nodal;
bool _c_nodal;

/// True if implicit value is required
bool _c_is_implicit;
Expand Down
2 changes: 1 addition & 1 deletion framework/include/base/MooseVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MooseVariable : public MooseVariableBase
void reinitNodes(const std::vector<dof_id_type> & nodes);
void reinitNodesNeighbor(const std::vector<dof_id_type> & nodes);

const std::set<SubdomainID> & activeSubdomains();
const std::set<SubdomainID> & activeSubdomains() const;

/**
* Is the variable active on the subdomain?
Expand Down
2 changes: 1 addition & 1 deletion framework/include/ics/InitialCondition.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ InputParameters validParams<InitialCondition>();
* InitialConditions are objects that set the initial value of variables.
*/
class InitialCondition : public MooseObject,
public BlockRestrictable,
public Coupleable,
public FunctionInterface,
public UserObjectInterface,
public BlockRestrictable,
public BoundaryRestrictable,
public DependencyResolverInterface,
public Restartable,
Expand Down
49 changes: 34 additions & 15 deletions framework/src/base/BlockRestrictable.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "MooseMesh.h"
#include "MooseVariable.h"
#include "SystemBase.h"
#include "Conversion.h"

template <>
InputParameters
Expand All @@ -32,8 +33,6 @@ validParams<BlockRestrictable>()
params.addParam<std::vector<SubdomainName>>(
"block", "The list of block ids (SubdomainID) that this object will be applied");

params.addPrivateParam<bool>("delay_initialization", false);

// A parameter for disabling error message for objects restrictable by boundary and block,
// if the parameter is valid it was already set so don't do anything
if (!params.isParamValid("_dual_restrictable"))
Expand All @@ -52,10 +51,10 @@ BlockRestrictable::BlockRestrictable(const InputParameters & parameters)
: NULL),
_blk_mesh(parameters.isParamValid("_mesh") ? parameters.get<MooseMesh *>("_mesh") : NULL),
_boundary_ids(_empty_boundary_ids),
_blk_tid(parameters.isParamValid("_tid") ? parameters.get<THREAD_ID>("_tid") : 0)
_blk_tid(parameters.isParamValid("_tid") ? parameters.get<THREAD_ID>("_tid") : 0),
_blk_name(parameters.get<std::string>("_object_name"))
{
if (!parameters.get<bool>("delay_initialization"))
initializeBlockRestrictable(parameters);
initializeBlockRestrictable(parameters);
}

// Dual restricted constructor
Expand All @@ -68,20 +67,17 @@ BlockRestrictable::BlockRestrictable(const InputParameters & parameters,
: NULL),
_blk_mesh(parameters.isParamValid("_mesh") ? parameters.get<MooseMesh *>("_mesh") : NULL),
_boundary_ids(boundary_ids),
_blk_tid(parameters.isParamValid("_tid") ? parameters.get<THREAD_ID>("_tid") : 0)
_blk_tid(parameters.isParamValid("_tid") ? parameters.get<THREAD_ID>("_tid") : 0),
_blk_name(parameters.get<std::string>("_object_name"))
{
if (!parameters.get<bool>("delay_initialization"))
initializeBlockRestrictable(parameters);
initializeBlockRestrictable(parameters);
}

void
BlockRestrictable::initializeBlockRestrictable(const InputParameters & parameters)
{
mooseAssert(!_initialized, "BlockRestrictable already initialized");

// The name and id of the object
const std::string name = parameters.get<std::string>("_object_name");

// If the mesh pointer is not defined, but FEProblemBase is, get it from there
if (_blk_feproblem != NULL && _blk_mesh == NULL)
_blk_mesh = &_blk_feproblem->mesh();
Expand Down Expand Up @@ -126,8 +122,9 @@ BlockRestrictable::initializeBlockRestrictable(const InputParameters & parameter

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

Expand All @@ -142,7 +139,7 @@ BlockRestrictable::initializeBlockRestrictable(const InputParameters & parameter
if (!_blk_dual_restrictable && !_boundary_ids.empty() && !_boundary_ids.empty())
if (!_boundary_ids.empty() && _boundary_ids.find(Moose::ANY_BOUNDARY_ID) == _boundary_ids.end())
mooseError("Attempted to restrict the object '",
name,
_blk_name,
"' to a block, but the object is already restricted by boundary");

// If no blocks were defined above, specify that it is valid on all blocks
Expand All @@ -167,7 +164,7 @@ BlockRestrictable::initializeBlockRestrictable(const InputParameters & parameter
if (!diff.empty())
{
std::ostringstream msg;
msg << "The object '" << name
msg << "The object '" << _blk_name
<< "' contains the following block ids that do not exist on the mesh:";
for (const auto & id : diff)
msg << " " << id;
Expand Down Expand Up @@ -372,3 +369,25 @@ BlockRestrictable::getBlockCoordSystem()

return coord_system;
}

void
BlockRestrictable::checkVariable(const MooseVariable & variable) const
{
if (_initialized && !isBlockSubset(variable.activeSubdomains()))
{
std::string var_ids = Moose::stringify(variable.activeSubdomains());
std::string obj_ids = Moose::stringify(blockRestricted() ? blockIDs() : meshBlockIDs());
mooseError("The 'block' parameter of the object '",
_blk_name,
"' must be a subset of the 'block' parameter of the variable '",
variable.name(),
"':\n ",
_blk_name,
": ",
obj_ids,
"\n ",
variable.name(),
": ",
var_ids);
}
}

0 comments on commit 78f7623

Please sign in to comment.