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 committed Jul 12, 2024
1 parent 366d996 commit cf901d5
Show file tree
Hide file tree
Showing 24 changed files with 463 additions and 36 deletions.
34 changes: 28 additions & 6 deletions framework/include/problems/FEProblemBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ class FEProblemBase : public SubProblem, public Restartable
FEProblemBase(const InputParameters & parameters);
virtual ~FEProblemBase();

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

enum class MaterialCoverageCheckMode
{
TRUE,
ON,
FALSE,
OFF,
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 +1755,15 @@ 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(KernelCoverageCheckMode mode) { _kernel_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; }
void setMaterialCoverageCheck(MaterialCoverageCheckMode mode) { _material_coverage_check = mode; }

/**
* Toggle parallel barrier messaging (defaults to on).
Expand Down Expand Up @@ -2640,8 +2660,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
KernelCoverageCheckMode _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 +2672,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
MaterialCoverageCheckMode _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
109 changes: 96 additions & 13 deletions framework/src/problems/FEProblemBase.C
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,18 @@ 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");
MooseEnum kernel_coverage_check_modes("TRUE ON FALSE OFF SKIP_LIST ONLY_LIST", "TRUE");
params.addParam<MooseEnum>(
"kernel_coverage_check",
kernel_coverage_check_modes,
"Controls, if and how a kernel 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 "
"'kernel_coverage_block_list'. To limit the check to a list of subdomains, 'ONLY_LIST' is to "
"be used (again, using the parameter 'kernel_coverage_block_list').");
params.addParam<std::vector<SubdomainName>>(
"kernel_coverage_block_list", {}, "List of subdomains for kernel coverage check");
params.addParam<bool>(
"boundary_restricted_node_integrity_check",
true,
Expand All @@ -217,9 +227,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("TRUE ON FALSE OFF SKIP_LIST ONLY_LIST", "TRUE");
params.addParam<MooseEnum>(
"material_coverage_check",
material_coverage_check_modes,
"Controls, if and how a material 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 "
"'kernel_coverage_block_list'. To limit the check to a list of subdomains, 'ONLY_LIST' is to "
"be used (again, using the parameter 'kernel_coverage_block_list').");
params.addParam<std::vector<SubdomainName>>(
"material_coverage_block_list", {}, "List of subdomains for material coverage check");
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 +328,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 +418,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<KernelCoverageCheckMode>()),
_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<MaterialCoverageCheckMode>()),
_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 +7785,39 @@ 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 != KernelCoverageCheckMode::FALSE &&
_kernel_coverage_check != KernelCoverageCheckMode::OFF)
{
std::set<SubdomainID> blocks;
if (_kernel_coverage_check == KernelCoverageCheckMode::TRUE ||
_kernel_coverage_check == KernelCoverageCheckMode::ON)
blocks = mesh_subdomains;
else if (_kernel_coverage_check == KernelCoverageCheckMode::SKIP_LIST)
{
blocks.insert(mesh_subdomains.begin(), mesh_subdomains.end());
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 == KernelCoverageCheckMode::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 +7833,8 @@ FEProblemBase::checkProblemIntegrity()

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

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

// did the user limit the subdomains to be checked?
if (_material_coverage_check == MaterialCoverageCheckMode::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 == MaterialCoverageCheckMode::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
4 changes: 4 additions & 0 deletions make_install_test/moose_test/tests/testroot
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
app_name = moose_test
allow_warnings = false
allow_unused = false
allow_override = false
18 changes: 18 additions & 0 deletions make_install_test/moose_test/tests/version/tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Tests]
issues = '#10163'
design = 'MooseApp.md'
[./print_version_long]
type = 'RunApp'
input = ''
expect_out = '^Application Version:\s*\S+'
cli_args = '--version'
requirement = "The application executable shall report the version with the --version command line argument."
[../]
[./print_version_short]
type = 'RunApp'
input = ''
expect_out = '^Application Version:\s*\S+'
cli_args = '-v'
requirement = "The application executable shall report the version with the -v command line argument."
[../]
[]
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::KernelCoverageCheckMode::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::KernelCoverageCheckMode::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::KernelCoverageCheckMode::TRUE
: FEProblemBase::KernelCoverageCheckMode::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::KernelCoverageCheckMode::TRUE
: FEProblemBase::KernelCoverageCheckMode::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::KernelCoverageCheckMode::TRUE
: FEProblemBase::KernelCoverageCheckMode::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::KernelCoverageCheckMode::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 cf901d5

Please sign in to comment.