Skip to content

Commit

Permalink
Implement variable check for some boundary restricted objects
Browse files Browse the repository at this point in the history
Makes sure that variable dependencies have degrees of freedom on
all nodes along the boundaries of a boundary restricted object

Closes idaholab#9734
  • Loading branch information
lindsayad committed May 18, 2022
1 parent dc704a7 commit 2345d39
Show file tree
Hide file tree
Showing 33 changed files with 436 additions and 35 deletions.
2 changes: 1 addition & 1 deletion framework/include/auxkernels/AuxKernel.h
Expand Up @@ -62,7 +62,7 @@ class AuxKernelTempl : public MooseObject,
public PostprocessorInterface,
public DependencyResolverInterface,
public RandomInterface,
protected GeometricSearchInterface,
public GeometricSearchInterface,
public Restartable,
public MeshChangedInterface,
protected VectorPostprocessorInterface,
Expand Down
10 changes: 10 additions & 0 deletions framework/include/geomsearch/GeometricSearchInterface.h
Expand Up @@ -58,6 +58,16 @@ class GeometricSearchInterface
NearestNodeLocator & getQuadratureNearestNodeLocator(const BoundaryName & primary,
const BoundaryName & secondary);

/**
* Whether any of this interface's methods have been called, e.g. whether the object that this
* interface is for requires geometric search data
*/
bool requiresGeometricSearch() const { return _requires_geometric_search; }

protected:
GeometricSearchData & _geometric_search_data;

/// Whether any of this interface's methods have been called, e.g. whether the object that this
/// interface is for requires geometric search data
bool _requires_geometric_search;
};
5 changes: 4 additions & 1 deletion framework/include/interfaces/BoundaryRestrictable.h
Expand Up @@ -204,10 +204,13 @@ class BoundaryRestrictable
/// Whether or not this object is restricted to nodesets
bool _bnd_nodal;

/// The moose object that this is an interface for
const MooseObject & _moose_object;

/**
* An initialization routine needed for dual constructors
*/
void initializeBoundaryRestrictable(const MooseObject * moose_object);
void initializeBoundaryRestrictable();

protected:
/**
Expand Down
39 changes: 39 additions & 0 deletions framework/include/loops/BoundaryNodeIntegrityCheckThread.h
@@ -0,0 +1,39 @@
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html

#pragma once

// MOOSE includes
#include "MooseMesh.h"
#include "ThreadedNodeLoop.h"
#include "TheWarehouse.h"

class AuxiliarySystem;

class BoundaryNodeIntegrityCheckThread
: public ThreadedNodeLoop<ConstBndNodeRange, ConstBndNodeRange::const_iterator>
{
public:
BoundaryNodeIntegrityCheckThread(FEProblemBase & fe_problem, const TheWarehouse::Query & query);

// Splitting Constructor
BoundaryNodeIntegrityCheckThread(BoundaryNodeIntegrityCheckThread & x, Threads::split split);

virtual void onNode(ConstBndNodeRange::const_iterator & node_it) override;

void join(const BoundaryNodeIntegrityCheckThread & /*y*/);

protected:
/// The auxiliary system to whom we'll delegate the boundary variable dependency integrity check
const AuxiliarySystem & _aux_sys;

/// A warehouse query that we will use to obtain user objects for boundary variable dependency
/// integrity checks
const TheWarehouse::Query & _query;
};
2 changes: 2 additions & 0 deletions framework/include/systems/AuxiliarySystem.h
Expand Up @@ -153,6 +153,8 @@ class AuxiliarySystem : public SystemBase, public PerfGraphInterface

void clearScalarVariableCoupleableTags();

void boundaryAuxKernelIntegrityCheck(const Node & nd, BoundaryID bnd_id, THREAD_ID tid) const;

protected:
void computeScalarVars(ExecFlagType type);
void computeNodalVars(ExecFlagType type);
Expand Down
20 changes: 18 additions & 2 deletions framework/include/variables/MooseVariableDependencyInterface.h
Expand Up @@ -11,13 +11,17 @@

#include <set>

// Forward declarations
class MooseVariableFieldBase;
namespace libMesh
{
class DofObject;
}

class MooseVariableDependencyInterface
{
public:
MooseVariableDependencyInterface() {}
// Must be a pointer in order to disambiguate with default copy constructor
MooseVariableDependencyInterface(const MooseObject * moose_object);

/**
* Retrieve the set of MooseVariableFieldBase that _this_ object depends on.
Expand All @@ -28,6 +32,12 @@ class MooseVariableDependencyInterface
return _moose_variable_dependencies;
}

/**
* Check whether all of the variable dependencies are evaluable on the supplied degree of freedom
* object
*/
void checkEvaluable(const libMesh::DofObject & dof_object) const;

protected:
/**
* Call this function to add the passed in MooseVariableFieldBase as a variable that _this_ object
Expand All @@ -44,4 +54,10 @@ class MooseVariableDependencyInterface

private:
std::set<MooseVariableFieldBase *> _moose_variable_dependencies;

/// The name of the moose object that this interface aggregates into
const std::string & _mvdi_name;

/// The type of the moose object that this interface aggregates into
const std::string & _mvdi_type;
};
Expand Up @@ -31,7 +31,9 @@ class NeighborCoupleableMooseVariableDependencyIntermediateInterface
bool nodal,
bool neighbor_nodal,
bool is_fv = false)
: NeighborCoupleable(moose_object, nodal, neighbor_nodal, is_fv), ScalarCoupleable(moose_object)
: NeighborCoupleable(moose_object, nodal, neighbor_nodal, is_fv),
ScalarCoupleable(moose_object),
MooseVariableDependencyInterface(moose_object)
{
for (MooseVariableFEBase * coupled_var : getCoupledMooseVars())
addMooseVariableDependency(coupled_var);
Expand Down
8 changes: 4 additions & 4 deletions framework/include/warehouses/ExecuteMooseObjectWarehouse.h
Expand Up @@ -42,7 +42,7 @@ class ExecuteMooseObjectWarehouse : public MooseObjectWarehouse<T>
* Adds an object to the storage structure.
* @param object A shared pointer to the object being added
*/
virtual void addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true);
void addObject(std::shared_ptr<T> object, THREAD_ID tid = 0, bool recurse = true) override;
void addObjectMask(std::shared_ptr<T> object,
THREAD_ID tid = 0,
std::uint16_t flag_mask = std::numeric_limits<std::uint16_t>::max());
Expand Down Expand Up @@ -73,16 +73,16 @@ class ExecuteMooseObjectWarehouse : public MooseObjectWarehouse<T>
/**
* Updates the active objects storage.
*/
virtual void updateActive(THREAD_ID tid = 0);
void updateActive(THREAD_ID tid = 0) override;

///@{
/**
* Convenience methods for calling object setup methods.
*
* Limits call to these methods only to objects being executed on linear/nonlinear iterations.
*/
void jacobianSetup(THREAD_ID tid = 0) const;
void residualSetup(THREAD_ID tid = 0) const;
void jacobianSetup(THREAD_ID tid = 0) const override;
void residualSetup(THREAD_ID tid = 0) const override;
void setup(const ExecFlagType & exec_flag, THREAD_ID tid = 0) const;
///@}

Expand Down
9 changes: 9 additions & 0 deletions framework/include/warehouses/MooseObjectWarehouseBase.h
Expand Up @@ -94,6 +94,7 @@ class MooseObjectWarehouseBase
bool hasActiveBlockObjects(SubdomainID id, THREAD_ID tid = 0) const;
bool hasActiveBoundaryObjects(THREAD_ID tid = 0) const;
bool hasActiveBoundaryObjects(BoundaryID id, THREAD_ID tid = 0) const;
bool hasBoundaryObjects(BoundaryID id, THREAD_ID tid = 0) const;
///@}

/**
Expand Down Expand Up @@ -345,6 +346,14 @@ MooseObjectWarehouseBase<T>::getBoundaryObjects(THREAD_ID tid /* = 0*/) const
return _all_boundary_objects[tid];
}

template <typename T>
bool
MooseObjectWarehouseBase<T>::hasBoundaryObjects(BoundaryID id, THREAD_ID tid /* = 0*/) const
{
checkThreadID(tid);
return _all_boundary_objects[tid].find(id) != _all_boundary_objects[tid].end();
}

template <typename T>
const std::vector<std::shared_ptr<T>> &
MooseObjectWarehouseBase<T>::getBoundaryObjects(BoundaryID id, THREAD_ID tid /* = 0*/) const
Expand Down
2 changes: 1 addition & 1 deletion framework/src/auxkernels/AuxNodalScalarKernel.C
Expand Up @@ -21,7 +21,7 @@ AuxNodalScalarKernel::validParams()
AuxNodalScalarKernel::AuxNodalScalarKernel(const InputParameters & parameters)
: AuxScalarKernel(parameters),
Coupleable(this, true),
MooseVariableDependencyInterface(),
MooseVariableDependencyInterface(this),
_node_ids(getParam<std::vector<dof_id_type>>("nodes"))
{
// Fill in the MooseVariable dependencies
Expand Down
1 change: 1 addition & 0 deletions framework/src/fvbcs/FVBoundaryCondition.C
Expand Up @@ -68,6 +68,7 @@ FVBoundaryCondition::FVBoundaryCondition(const InputParameters & parameters)
"variable",
Moose::VarKindType::VAR_ANY,
Moose::VarFieldType::VAR_FIELD_STANDARD),
MooseVariableDependencyInterface(this),
FunctorInterface(this),
_var(*mooseVariableFV()),
_subproblem(*getCheckedPointerParam<SubProblem *>("_subproblem")),
Expand Down
7 changes: 6 additions & 1 deletion framework/src/geomsearch/GeometricSearchInterface.C
Expand Up @@ -26,7 +26,8 @@ GeometricSearchInterface::validParams()
GeometricSearchInterface::GeometricSearchInterface(const MooseObject * moose_object)
: _geometric_search_data(moose_object->parameters()
.getCheckedPointerParam<SubProblem *>("_subproblem")
->geomSearchData())
->geomSearchData()),
_requires_geometric_search(false)
{
}

Expand All @@ -35,6 +36,7 @@ GeometricSearchInterface::getPenetrationLocator(const BoundaryName & primary,
const BoundaryName & secondary,
Order order)
{
_requires_geometric_search = true;
return _geometric_search_data.getPenetrationLocator(primary, secondary, order);
}

Expand All @@ -43,19 +45,22 @@ GeometricSearchInterface::getQuadraturePenetrationLocator(const BoundaryName & p
const BoundaryName & secondary,
Order order)
{
_requires_geometric_search = true;
return _geometric_search_data.getQuadraturePenetrationLocator(primary, secondary, order);
}

NearestNodeLocator &
GeometricSearchInterface::getNearestNodeLocator(const BoundaryName & primary,
const BoundaryName & secondary)
{
_requires_geometric_search = true;
return _geometric_search_data.getNearestNodeLocator(primary, secondary);
}

NearestNodeLocator &
GeometricSearchInterface::getQuadratureNearestNodeLocator(const BoundaryName & primary,
const BoundaryName & secondary)
{
_requires_geometric_search = true;
return _geometric_search_data.getQuadratureNearestNodeLocator(primary, secondary);
}
1 change: 1 addition & 0 deletions framework/src/indicators/Indicator.C
Expand Up @@ -45,6 +45,7 @@ Indicator::Indicator(const InputParameters & parameters)
SetupInterface(this),
FunctionInterface(this),
UserObjectInterface(this),
MooseVariableDependencyInterface(this),
Restartable(this, "Indicators"),
OutputInterface(parameters),
MaterialPropertyInterface(this, blockIDs(), Moose::EMPTY_BOUNDARY_IDS),
Expand Down
22 changes: 12 additions & 10 deletions framework/src/interfaces/BoundaryRestrictable.C
Expand Up @@ -44,9 +44,10 @@ BoundaryRestrictable::BoundaryRestrictable(const MooseObject * moose_object, boo
_block_ids(_empty_block_ids),
_bnd_tid(moose_object->isParamValid("_tid") ? moose_object->getParam<THREAD_ID>("_tid") : 0),
_bnd_material_data(_bnd_feproblem->getMaterialData(Moose::BOUNDARY_MATERIAL_DATA, _bnd_tid)),
_bnd_nodal(nodal)
_bnd_nodal(nodal),
_moose_object(*moose_object)
{
initializeBoundaryRestrictable(moose_object);
initializeBoundaryRestrictable();
}

// Dual restricted constructor
Expand All @@ -62,16 +63,17 @@ BoundaryRestrictable::BoundaryRestrictable(const MooseObject * moose_object,
_block_ids(block_ids),
_bnd_tid(moose_object->isParamValid("_tid") ? moose_object->getParam<THREAD_ID>("_tid") : 0),
_bnd_material_data(_bnd_feproblem->getMaterialData(Moose::BOUNDARY_MATERIAL_DATA, _bnd_tid)),
_bnd_nodal(nodal)
_bnd_nodal(nodal),
_moose_object(*moose_object)
{
initializeBoundaryRestrictable(moose_object);
initializeBoundaryRestrictable();
}

void
BoundaryRestrictable::initializeBoundaryRestrictable(const MooseObject * moose_object)
BoundaryRestrictable::initializeBoundaryRestrictable()
{
// The name and id of the object
const std::string & name = moose_object->getParam<std::string>("_object_name");
const std::string & name = _moose_object.getParam<std::string>("_object_name");

// If the mesh pointer is not defined, but FEProblemBase is, get it from there
if (_bnd_feproblem != NULL && _bnd_mesh == NULL)
Expand All @@ -83,10 +85,10 @@ BoundaryRestrictable::initializeBoundaryRestrictable(const MooseObject * moose_o
"a pointer to the MooseMesh via '_mesh'");

// If the user supplies boundary IDs
if (moose_object->isParamValid("boundary"))
if (_moose_object.isParamValid("boundary"))
{
// Extract the blocks from the input
_boundary_names = moose_object->getParam<std::vector<BoundaryName>>("boundary");
_boundary_names = _moose_object.getParam<std::vector<BoundaryName>>("boundary");

// Get the IDs from the supplied names
_vec_ids = _bnd_mesh->getBoundaryIDs(_boundary_names, true);
Expand All @@ -102,7 +104,7 @@ BoundaryRestrictable::initializeBoundaryRestrictable(const MooseObject * moose_o
// Produce error if the object is not allowed to be both block and boundary restricted
if (!_bnd_dual_restrictable && !_bnd_ids.empty() && !_block_ids.empty())
if (!_block_ids.empty() && _block_ids.find(Moose::ANY_BLOCK_ID) == _block_ids.end())
moose_object->paramError("boundary",
_moose_object.paramError("boundary",
"Attempted to restrict the object '",
name,
"' to a boundary, but the object is already restricted by block(s)");
Expand Down Expand Up @@ -168,7 +170,7 @@ BoundaryRestrictable::initializeBoundaryRestrictable(const MooseObject * moose_o
"error.\n"
"Note: If you are running with adaptivity you should prefer using side sets.";

moose_object->paramError("boundary", msg.str());
_moose_object.paramError("boundary", msg.str());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion framework/src/kernels/NodalScalarKernel.C
Expand Up @@ -29,7 +29,7 @@ NodalScalarKernel::validParams()
NodalScalarKernel::NodalScalarKernel(const InputParameters & parameters)
: ScalarKernel(parameters),
Coupleable(this, true),
MooseVariableDependencyInterface(),
MooseVariableDependencyInterface(this),
_node_ids(getParam<std::vector<dof_id_type>>("nodes")),
_boundary_names(getParam<std::vector<BoundaryName>>("boundary"))
{
Expand Down

0 comments on commit 2345d39

Please sign in to comment.