Skip to content

Commit

Permalink
Improved user control over kernel and material coverage check
Browse files Browse the repository at this point in the history
  • Loading branch information
jmeier authored and grunerjmeier committed Jul 21, 2024
1 parent 366d996 commit 6301665
Show file tree
Hide file tree
Showing 22 changed files with 461 additions and 36 deletions.
44 changes: 38 additions & 6 deletions framework/include/problems/FEProblemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,16 @@ class FEProblemBase : public SubProblem, public Restartable
FEProblemBase(const InputParameters & parameters);
virtual ~FEProblemBase();

enum class CoverageCheckMode
{
FALSE,
TRUE,
OFF,
ON,
SKIP_LIST,
ONLY_LIST,
};

virtual EquationSystems & es() override { return _req.set().es(); }
virtual MooseMesh & mesh() override { return _mesh; }
virtual const MooseMesh & mesh() const override { return _mesh; }
Expand Down Expand Up @@ -1735,15 +1745,35 @@ class FEProblemBase : public SubProblem, public Restartable
* Set flag to indicate whether kernel coverage checks should be performed. This check makes
* sure that at least one kernel is active on all subdomains in the domain (default: true).
*/
void setKernelCoverageCheck(bool flag) { _kernel_coverage_check = flag; }
void setKernelCoverageCheck(CoverageCheckMode mode) { _kernel_coverage_check = mode; }

/**
* Set flag to indicate whether kernel coverage checks should be performed. This check makes
* sure that at least one kernel is active on all subdomains in the domain (default: true).
*/
void setKernelCoverageCheck(bool flag)
{
_kernel_coverage_check = flag ? CoverageCheckMode::TRUE : CoverageCheckMode::FALSE;
}

/**
* Set flag to indicate whether material coverage checks should be performed. This check makes
* sure that at least one material is active on all subdomains in the domain if any material is
* supplied. If no materials are supplied anywhere, a simulation is still considered OK as long as
* no properties are being requested anywhere.
*/
void setMaterialCoverageCheck(bool flag) { _material_coverage_check = flag; }
void setMaterialCoverageCheck(CoverageCheckMode mode) { _material_coverage_check = mode; }

/**
* Set flag to indicate whether material coverage checks should be performed. This check makes
* sure that at least one material is active on all subdomains in the domain if any material is
* supplied. If no materials are supplied anywhere, a simulation is still considered OK as long as
* no properties are being requested anywhere.
*/
void setMaterialCoverageCheck(bool flag)
{
_material_coverage_check = flag ? CoverageCheckMode::TRUE : CoverageCheckMode::FALSE;
}

/**
* Toggle parallel barrier messaging (defaults to on).
Expand Down Expand Up @@ -2640,8 +2670,9 @@ class FEProblemBase : public SubProblem, public Restartable

SolverParams _solver_params;

/// Determines whether a check to verify an active kernel on every subdomain
bool _kernel_coverage_check;
/// Determines whether and which subdomains are to be checked to ensure that they have an active kernel
CoverageCheckMode _kernel_coverage_check;
std::vector<SubdomainName> _kernel_coverage_blocks;

/// whether to perform checking of boundary restricted nodal object variable dependencies,
/// e.g. whether the variable dependencies are defined on the selected boundaries
Expand All @@ -2651,8 +2682,9 @@ class FEProblemBase : public SubProblem, public Restartable
/// e.g. whether the variable dependencies are defined on the selected boundaries
const bool _boundary_restricted_elem_integrity_check;

/// Determines whether a check to verify an active material on every subdomain
bool _material_coverage_check;
/// Determines whether and which subdomains are to be checked to ensure that they have an active material
CoverageCheckMode _material_coverage_check;
std::vector<SubdomainName> _material_coverage_blocks;

/// Whether to check overlapping Dirichlet and Flux BCs and/or multiple DirichletBCs per sideset
bool _fv_bcs_integrity_check;
Expand Down
2 changes: 1 addition & 1 deletion framework/src/problems/ExternalProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ExternalProblem::validParams()

// there is no nonlinear system (we set it as empty in the constructor)
params.suppressParameter<bool>("ignore_zeros_in_jacobian");
params.suppressParameter<bool>("kernel_coverage_check");
params.suppressParameter<MooseEnum>("kernel_coverage_check");
params.suppressParameter<std::vector<NonlinearSystemName>>("nl_sys_names");
params.suppressParameter<bool>("previous_nl_solution_required");
params.suppressParameter<bool>("skip_nl_system_check");
Expand Down
119 changes: 106 additions & 13 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,29 @@ FEProblemBase::validParams()
rz_coord_axis,
"The rotation axis (X | Y) for axisymetric coordinates",
"Please use 'Mesh/rz_coord_axis' instead");
params.addParam<bool>(
"kernel_coverage_check", true, "Set to false to disable kernel->subdomain coverage check");
auto coverage_check_description = [](std::string scope, std::string list_param_name)
{
return "Controls, if and how a " + scope +
" subdomain coverage check is performed. "
"With 'TRUE' or 'ON' all subdomains are checked (the default). Setting 'FALSE' or 'OFF' "
"will disable the check for all subdomains. "
"To exclude a predefined set of subdomains 'SKIP_LIST' is to "
"be used, while the subdomains to skip are to be defined in the parameter '" +
list_param_name +
"'. To limit the check to a list of subdomains, 'ONLY_LIST' is to "
"be used (again, using the parameter '" +
list_param_name + "').";
};
MooseEnum kernel_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
params.addParam<MooseEnum>("kernel_coverage_check",
kernel_coverage_check_modes,
coverage_check_description("kernel", "kernel_coverage_block_list"));
params.addParam<std::vector<SubdomainName>>(
"kernel_coverage_block_list",
{},
"List of subdomains for kernel coverage check. The meaning of this list is controlled by the "
"parameter 'kernel_coverage_check' (whether this is the list of subdomains to be checked, "
"not to be checked or not taken into account).");
params.addParam<bool>(
"boundary_restricted_node_integrity_check",
true,
Expand All @@ -217,9 +238,18 @@ FEProblemBase::validParams()
"Set to false to disable checking of boundary restricted elemental object "
"variable dependencies, e.g. are the variable dependencies defined on the "
"selected boundaries?");
params.addParam<bool>("material_coverage_check",
true,
"Set to false to disable material->subdomain coverage check");
MooseEnum material_coverage_check_modes("FALSE TRUE OFF ON SKIP_LIST ONLY_LIST", "TRUE");
params.addParam<MooseEnum>(
"material_coverage_check",
material_coverage_check_modes,
coverage_check_description("material", "material_coverage_block_list"));
params.addParam<std::vector<SubdomainName>>(
"material_coverage_block_list",
{},
"List of subdomains for material coverage check. The meaning of this list is controlled by "
"the "
"parameter 'kernel_coverage_check' (whether this is the list of subdomains to be checked, "
"not to be checked or not taken into account).");
params.addParam<bool>("fv_bcs_integrity_check",
true,
"Set to false to disable checking of overlapping Dirichlet and Flux BCs "
Expand Down Expand Up @@ -309,8 +339,10 @@ FEProblemBase::validParams()
"specific handling, immediately error instead of allowing the time step to be cut");

params.addParamNamesToGroup(
"skip_nl_system_check kernel_coverage_check boundary_restricted_node_integrity_check "
"boundary_restricted_elem_integrity_check material_coverage_check fv_bcs_integrity_check "
"skip_nl_system_check kernel_coverage_check kernel_coverage_block_list "
"boundary_restricted_node_integrity_check "
"boundary_restricted_elem_integrity_check material_coverage_check "
"material_coverage_block_list fv_bcs_integrity_check "
"material_dependency_check check_uo_aux_state error_on_jacobian_nonzero_reallocation",
"Simulation checks");
params.addParamNamesToGroup("use_nonlinear previous_nl_solution_required nl_sys_names "
Expand Down Expand Up @@ -397,12 +429,16 @@ FEProblemBase::FEProblemBase(const InputParameters & parameters)
_needs_old_newton_iter(false),
_has_nonlocal_coupling(false),
_calculate_jacobian_in_uo(false),
_kernel_coverage_check(getParam<bool>("kernel_coverage_check")),
_kernel_coverage_check(
getParam<MooseEnum>("kernel_coverage_check").getEnum<CoverageCheckMode>()),
_kernel_coverage_blocks(getParam<std::vector<SubdomainName>>("kernel_coverage_block_list")),
_boundary_restricted_node_integrity_check(
getParam<bool>("boundary_restricted_node_integrity_check")),
_boundary_restricted_elem_integrity_check(
getParam<bool>("boundary_restricted_elem_integrity_check")),
_material_coverage_check(getParam<bool>("material_coverage_check")),
_material_coverage_check(
getParam<MooseEnum>("material_coverage_check").getEnum<CoverageCheckMode>()),
_material_coverage_blocks(getParam<std::vector<SubdomainName>>("material_coverage_block_list")),
_fv_bcs_integrity_check(getParam<bool>("fv_bcs_integrity_check")),
_material_dependency_check(getParam<bool>("material_dependency_check")),
_uo_aux_state_check(getParam<bool>("check_uo_aux_state")),
Expand Down Expand Up @@ -7760,9 +7796,38 @@ FEProblemBase::checkProblemIntegrity()
const std::set<SubdomainID> & mesh_subdomains = _mesh.meshSubdomains();

// Check kernel coverage of subdomains (blocks) in the mesh
if (!_skip_nl_system_check && _solve && _kernel_coverage_check)
for (auto & nl : _nl)
nl->checkKernelCoverage(mesh_subdomains);
if (!_skip_nl_system_check && _solve && _kernel_coverage_check != CoverageCheckMode::FALSE &&
_kernel_coverage_check != CoverageCheckMode::OFF)
{
std::set<SubdomainID> blocks;
if (_kernel_coverage_check == CoverageCheckMode::TRUE ||
_kernel_coverage_check == CoverageCheckMode::ON)
blocks = mesh_subdomains;
else if (_kernel_coverage_check == CoverageCheckMode::SKIP_LIST)
{
blocks = mesh_subdomains;
for (const auto & subdomain_name : _kernel_coverage_blocks)
{
const auto id = _mesh.getSubdomainID(subdomain_name);
if (id == Moose::INVALID_BLOCK_ID)
paramError("kernel_coverage_block_list",
"Subdomain \"" + subdomain_name + "\" not found in mesh.");
blocks.erase(id);
}
}
else if (_kernel_coverage_check == CoverageCheckMode::ONLY_LIST)
for (const auto & subdomain_name : _kernel_coverage_blocks)
{
const auto id = _mesh.getSubdomainID(subdomain_name);
if (id == Moose::INVALID_BLOCK_ID)
paramError("kernel_coverage_block_list",
"Subdomain \"" + subdomain_name + "\" not found in mesh.");
blocks.insert(id);
}
if (!blocks.empty())
for (auto & nl : _nl)
nl->checkKernelCoverage(blocks);
}

// Check materials
{
Expand All @@ -7778,7 +7843,8 @@ FEProblemBase::checkProblemIntegrity()

std::set<SubdomainID> local_mesh_subs(mesh_subdomains);

if (_material_coverage_check)
if (_material_coverage_check != CoverageCheckMode::FALSE &&
_material_coverage_check != CoverageCheckMode::OFF)
{
/**
* If a material is specified for any block in the simulation, then all blocks must
Expand All @@ -7792,6 +7858,33 @@ FEProblemBase::checkProblemIntegrity()
check_material_coverage = true;
}

// did the user limit the subdomains to be checked?
if (_material_coverage_check == CoverageCheckMode::SKIP_LIST)
{
for (const auto & subdomain_name : _material_coverage_blocks)
{
const auto id = _mesh.getSubdomainID(subdomain_name);
if (id == Moose::INVALID_BLOCK_ID)
paramError("material_coverage_block_list",
"Subdomain \"" + subdomain_name + "\" not found in mesh.");
local_mesh_subs.erase(id);
}
}
else if (_material_coverage_check == CoverageCheckMode::ONLY_LIST)
{
std::set<SubdomainID> blocks(local_mesh_subs);
for (const auto & subdomain_name : _material_coverage_blocks)
{
const auto id = _mesh.getSubdomainID(subdomain_name);
if (id == Moose::INVALID_BLOCK_ID)
paramError("material_coverage_block_list",
"Subdomain \"" + subdomain_name + "\" not found in mesh.");
blocks.erase(id);
}
for (const auto id : blocks)
local_mesh_subs.erase(id);
}

// also exclude mortar spaces from the material check
auto && mortar_subdomain_ids = _mortar_data.getMortarSubdomainIDs();
for (auto subdomain_id : mortar_subdomain_ids)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ AddFluidPropertiesInterrogatorAction::act()
params.set<bool>("use_nonlinear") = true;
params.set<bool>("solve") = false;
_problem = _factory.create<FEProblemBase>(class_name, "Problem", params);
_problem->setKernelCoverageCheck(false);
_problem->setKernelCoverageCheck(FEProblemBase::CoverageCheckMode::FALSE);
}
// Add the fluid properties interrogator user object
else if (_current_task == "add_user_object")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ AddGeochemicalModelInterrogatorAction::act()
params.set<bool>("use_nonlinear") = true;
params.set<bool>("solve") = false;
_problem = _factory.create<FEProblemBase>(class_name, "Problem", params);
_problem->setKernelCoverageCheck(false);
_problem->setKernelCoverageCheck(FEProblemBase::CoverageCheckMode::FALSE);
}
// Set up an arbitrary steady executioner
else if (_current_task == "setup_executioner")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ AddSpatialReactionSolverAction::act()
params.set<bool>("use_nonlinear") = true;
params.set<bool>("solve") = getParam<bool>("include_moose_solve");
_problem = _factory.create<FEProblemBase>(class_name, "Problem", params);
_problem->setKernelCoverageCheck(getParam<bool>("include_moose_solve"));
_problem->setKernelCoverageCheck(getParam<bool>("include_moose_solve")
? FEProblemBase::CoverageCheckMode::TRUE
: FEProblemBase::CoverageCheckMode::FALSE);
}
else if (_current_task == "add_geochemistry_reactor")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ AddTimeDependentReactionSolverAction::act()
params.set<bool>("use_nonlinear") = true;
params.set<bool>("solve") = getParam<bool>("include_moose_solve");
_problem = _factory.create<FEProblemBase>(class_name, "Problem", params);
_problem->setKernelCoverageCheck(getParam<bool>("include_moose_solve"));
_problem->setKernelCoverageCheck(getParam<bool>("include_moose_solve")
? FEProblemBase::CoverageCheckMode::TRUE
: FEProblemBase::CoverageCheckMode::FALSE);
}
else if (_current_task == "add_geochemistry_reactor")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ AddTimeIndependentReactionSolverAction::act()
params.set<bool>("use_nonlinear") = true;
params.set<bool>("solve") = getParam<bool>("include_moose_solve");
_problem = _factory.create<FEProblemBase>(class_name, "Problem", params);
_problem->setKernelCoverageCheck(getParam<bool>("include_moose_solve"));
_problem->setKernelCoverageCheck(getParam<bool>("include_moose_solve")
? FEProblemBase::CoverageCheckMode::TRUE
: FEProblemBase::CoverageCheckMode::FALSE);
}
// Set up an arbitrary steady executioner
else if (_current_task == "setup_executioner")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ NavierStokesHDGKernel::NavierStokesHDGKernel(const InputParameters & parameters)
_pressure_mms_forcing_function(getFunctor<Real>("pressure_mms_forcing_function"))
{
// This class handles residuals and Jacobians for multiple variables
_fe_problem.setKernelCoverageCheck(false);
_fe_problem.setKernelCoverageCheck(FEProblemBase::CoverageCheckMode::FALSE);

_body_forces.push_back(&_body_force_x);
_body_forces.push_back(&_body_force_y);
Expand Down
2 changes: 1 addition & 1 deletion modules/optimization/src/actions/OptimizationAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ OptimizationAction::act()

// Set the object parameters
InputParameters & params = action->getObjectParams();
params.set<bool>("kernel_coverage_check") = false;
params.set<MooseEnum>("kernel_coverage_check") = "false";
params.set<bool>("skip_nl_system_check") = true;

// Add Action to the warehouse
Expand Down
4 changes: 2 additions & 2 deletions modules/stochastic_tools/src/actions/StochasticToolsAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ StochasticToolsAction::act()
params.set<bool>("solve") = false;

if (!params.isParamSetByUser("kernel_coverage_check"))
params.set<bool>("kernel_coverage_check") = false;
params.set<MooseEnum>("kernel_coverage_check") = "false";

if (!params.isParamSetByUser("skip_nl_system_check"))
params.set<bool>("skip_nl_system_check") = true;
Expand All @@ -106,7 +106,7 @@ StochasticToolsAction::act()
// Set the object parameters
InputParameters & params = action->getObjectParams();
params.set<bool>("solve") = false;
params.set<bool>("kernel_coverage_check") = false;
params.set<MooseEnum>("kernel_coverage_check") = "false";
params.set<bool>("skip_nl_system_check") = true;

// Add Action to the warehouse
Expand Down
2 changes: 1 addition & 1 deletion modules/thermal_hydraulics/test/src/actions/TestAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ TestAction::act()
std::shared_ptr<MooseObjectAction> action = std::static_pointer_cast<MooseObjectAction>(
_action_factory.create(class_name, "fe_problem", action_params));

action->getObjectParams().set<bool>("kernel_coverage_check") = false;
action->getObjectParams().set<MooseEnum>("kernel_coverage_check") = "false";
_awh.addActionBlock(action);
}
}
Expand Down
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 6301665

Please sign in to comment.