Skip to content

Commit c86b71a

Browse files
committed
(a) The system shall throw an error if the user specifies either kernel_coverage_check or material_coverage_check together with default_block. (b) The system shall allow users to include ANY_BLOCK_ID in the default_block parameter. (c) Avoiding unnecessary copying of the block_param vector by using a reference.
1 parent 8ccf55a commit c86b71a

File tree

6 files changed

+33
-12
lines changed

6 files changed

+33
-12
lines changed

framework/include/problems/FEProblemBase.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2398,7 +2398,7 @@ class FEProblemBase : public SubProblem, public Restartable
23982398
/**
23992399
* @returns the default blocks (for block restriction)
24002400
*/
2401-
const std::vector<SubdomainName> getDefaultBlocks() const { return _default_blocks; };
2401+
const std::vector<SubdomainName> & getDefaultBlocks() const { return _default_blocks; };
24022402

24032403
protected:
24042404
/// Create extra tagged vectors and matrices

framework/src/interfaces/BlockRestrictable.C

+9-3
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ BlockRestrictable::initializeBlockRestrictable(const MooseObject * moose_object)
121121
else if (_blk_feproblem->isParamSetByUser("default_block"))
122122
{
123123
_blocks = _blk_feproblem->getDefaultBlocks();
124-
// Get the IDs from the supplied names
125-
_vec_ids = _blk_mesh->getSubdomainIDs(_blocks);
126124

127-
_blk_ids.insert(_vec_ids.begin(), _vec_ids.end());
125+
// Store the IDs in a set, handling ANY_BLOCK_ID if supplied
126+
if (std::find(_blocks.begin(), _blocks.end(), "ANY_BLOCK_ID") != _blocks.end())
127+
_blk_ids.insert(Moose::ANY_BLOCK_ID);
128+
else
129+
{
130+
// Get the IDs from the supplied names
131+
_vec_ids = _blk_mesh->getSubdomainIDs(_blocks);
132+
_blk_ids.insert(_vec_ids.begin(), _vec_ids.end());
133+
}
128134
}
129135

130136
// Produce error if the object is not allowed to be both block and boundary restricted

framework/src/problems/FEProblemBase.C

+11
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,17 @@ FEProblemBase::FEProblemBase(const InputParameters & parameters)
514514
_identify_variable_groups_in_nl(getParam<bool>("identify_variable_groups_in_nl")),
515515
_regard_general_exceptions_as_errors(getParam<bool>("regard_general_exceptions_as_errors"))
516516
{
517+
518+
auto checkConflict = [this](const std::string & coverage_check)
519+
{
520+
if (isParamSetByUser(coverage_check) && isParamSetByUser("default_block"))
521+
mooseError("Cannot set both '" + coverage_check +
522+
"' and 'default_block'. Please set only one.");
523+
};
524+
525+
checkConflict("kernel_coverage_check");
526+
checkConflict("material_coverage_check");
527+
517528
// Initialize static do_derivatives member. We initialize this to true so that all the default AD
518529
// things that we setup early in the simulation actually get their derivative vectors initalized.
519530
// We will toggle this to false when doing residual evaluations

framework/src/systems/SystemBase.C

+5-4
Original file line numberDiff line numberDiff line change
@@ -719,11 +719,12 @@ SystemBase::addVariable(const std::string & var_type,
719719
// Convert the std::vector parameter provided by the user into a std::set for use by libMesh's
720720
// System::add_variable method
721721
std::set<SubdomainID> blocks;
722-
auto block_param = parameters.get<std::vector<SubdomainName>>("block");
723-
if (block_param.empty() && _fe_problem.isParamValid("default_block"))
724-
block_param = _fe_problem.getDefaultBlocks();
722+
const std::vector<SubdomainName> * block_param =
723+
&parameters.get<std::vector<SubdomainName>>("block");
724+
if (block_param->empty() && _fe_problem.isParamValid("default_block"))
725+
block_param = &_fe_problem.getDefaultBlocks();
725726

726-
for (const auto & subdomain_name : block_param)
727+
for (const auto & subdomain_name : *block_param)
727728
{
728729
SubdomainID blk_id = _mesh.getSubdomainID(subdomain_name);
729730
blocks.insert(blk_id);

test/tests/default_block_check/tests

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
exodiff = 'diffusion_with_null_material_different_kernel_differnt_blocks_out.e'
1616
detail = 'Check whether different kernels can be assigned to different blocks, as long as the block IDs belong to the default_block list.'
1717
[]
18-
[kernel_coverage_override]
19-
type = 'Exodiff'
18+
[]
19+
[error_test]
20+
requirement = 'The system shall throw an error if the user sets either kernel_coverage_check or material_coverage_check together with default_block'
21+
[error]
22+
type = RunException
2023
input = 'diffusion_with_null_material_kernel_coverage_override.i'
21-
exodiff = 'diffusion_with_null_material_kernel_coverage_override_out.e'
22-
detail = 'Check whether kernel coverage override is allowed even when default_block is specified.'
24+
expect_err = "Cannot set both 'kernel_coverage_check' and 'default_block'. Please set only one."
25+
detail = 'Ensure that an error is thrown when user set both kernel_coverage_check and default_block in the [Problem].'
2326
[]
2427
[]
2528
[]

0 commit comments

Comments
 (0)