30 #include "libmesh/transient_system.h" 41 template <
typename ID>
42 using RestrictionGroups = std::map<std::set<ID>, std::set<std::string>>;
44 template <
typename ID>
46 formatRestrictionIDs(
const std::set<ID> & ids,
47 const std::set<ID> & all_ids,
48 const std::string & all_text,
49 const std::function<std::string(ID)> & id_to_string)
57 std::stringstream
out;
59 for (
const auto id : ids)
60 out << id_to_string(
id) << (++i < ids.size() ?
", " :
"");
66 printGroupNames(std::stringstream &
out,
const std::set<std::string> & names)
68 std::streampos begin_string_pos =
out.
tellp();
69 std::streampos curr_string_pos = begin_string_pos;
71 for (
const auto & name : names)
83 return object.type() +
"/" +
object.name();
87 addBlockRestrictionObject(RestrictionGroups<SubdomainID> & groups,
const MooseObject &
object)
89 if (!
object.enabled())
92 const auto *
const block_restrictable =
dynamic_cast<const BlockRestrictable *
>(&object);
93 if (block_restrictable)
94 groups[block_restrictable->blockIDs()].insert(objectRestrictionName(
object));
98 addBoundaryRestrictionObject(RestrictionGroups<BoundaryID> & groups,
100 const bool include_unrestricted)
102 if (!
object.enabled())
106 if (!boundary_restrictable)
109 if (!include_unrestricted && !boundary_restrictable->boundaryRestricted())
113 ? boundary_restrictable->boundaryIDs()
114 : boundary_restrictable->meshBoundaryIDs();
115 groups[ids].insert(objectRestrictionName(
object));
118 template <
typename T>
120 addWarehouseBlockRestrictionObjects(RestrictionGroups<SubdomainID> & groups,
123 for (
const auto &
object : warehouse.
getObjects( 0))
124 addBlockRestrictionObject(groups, *
object);
127 template <
typename T>
129 addWarehouseBoundaryRestrictionObjects(RestrictionGroups<BoundaryID> & groups,
131 const bool include_unrestricted)
133 for (
const auto &
object : warehouse.
getObjects( 0))
134 addBoundaryRestrictionObject(groups, *
object, include_unrestricted);
145 "The types of object to output block coverage for, if nothing is " 146 "provided everything will be output.");
148 params.
addParam<NonlinearSystemName>(
149 "nl_sys",
"nl0",
"The nonlinear system that we should output information for.");
151 "show_block_restriction_map",
153 "Print active objects for each block. This is the default block-restriction debug output.");
154 params.
addParam<
bool>(
"show_block_restriction_groups",
156 "Print groups of objects with identical block restrictions.");
157 params.
addParam<
bool>(
"show_boundary_restriction_groups",
159 "Print groups of objects with identical boundary restrictions.");
162 "Debug output object for displaying information regarding block and boundary restrictions of " 171 return MultiMooseEnum(
"none all variables kernels auxvariables auxkernels materials userobjects",
178 _nl(_problem_ptr->getNonlinearSystemBase(
179 _problem_ptr->nlSysNum(getParam<NonlinearSystemName>(
"nl_sys")))),
181 _show_block_restriction_map(getParam<bool>(
"show_block_restriction_map")),
182 _show_block_restriction_groups(getParam<bool>(
"show_block_restriction_groups")),
183 _show_boundary_restriction_groups(getParam<bool>(
"show_boundary_restriction_groups"))
208 std::stringstream
out;
210 auto printCategoryAndNames = [&
out](std::string category, std::set<std::string> & names)
212 const auto n = names.size();
216 out <<
" " << category <<
" (" << n <<
" " << ((n == 1) ?
"item" :
"items") <<
"): ";
220 std::streampos begin_string_pos =
out.
tellp();
221 std::streampos curr_string_pos = begin_string_pos;
223 for (
const auto &
name : names)
242 const std::set<SubdomainID> & mesh_subdomains =
mesh.meshSubdomains();
246 const auto & kernels = kernel_warehouse.
getObjects( 0);
255 std::vector<UserObject *> userObjects;
259 .condition<AttribThread>(0)
260 .queryIntoUnsorted(userObjects);
266 for (
const auto & subdomain_id : mesh_subdomains)
269 const auto & subdomain_name =
mesh.getSubdomainName(subdomain_id);
272 out <<
" Subdomain '" << subdomain_name <<
"' (id " << subdomain_id <<
"):\n";
274 bool objectsFound =
false;
279 std::set<std::string> names;
280 for (
unsigned int var_num = 0; var_num <
_sys.
n_vars(); var_num++)
294 objectsFound = printCategoryAndNames(
"Variables", names) || objectsFound;
300 std::set<std::string> names;
301 for (
const auto & kernel : kernels)
303 if (kernel->hasBlocks(subdomain_id))
304 names.insert(kernel->name());
306 objectsFound = printCategoryAndNames(
"Kernels", names) || objectsFound;
312 std::set<std::string> names;
313 const auto & sys = auxSystem.system();
314 for (
unsigned int vg = 0; vg < sys.n_variable_groups(); vg++)
316 const VariableGroup & vg_description(sys.variable_group(vg));
317 for (
unsigned int vn = 0; vn < vg_description.n_variables(); vn++)
319 if (vg_description.active_on_subdomain(subdomain_id))
320 names.insert(vg_description.name(vn));
323 objectsFound = printCategoryAndNames(
"AuxVariables", names) || objectsFound;
331 const auto & wh = auxSystem.nodalAuxWarehouse();
332 std::set<std::string> names;
333 if (wh.hasActiveBlockObjects(subdomain_id))
335 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
336 for (
auto & auxkernel : auxkernels)
337 names.insert(auxkernel->name());
339 objectsFound = printCategoryAndNames(
"AuxKernels[nodal]", names) || objectsFound;
343 const auto & wh = auxSystem.nodalVectorAuxWarehouse();
344 std::set<std::string> names;
345 if (wh.hasActiveBlockObjects(subdomain_id))
347 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
348 for (
auto & auxkernel : auxkernels)
349 names.insert(auxkernel->name());
351 objectsFound = printCategoryAndNames(
"AuxKernels[nodalVector]", names) || objectsFound;
355 const auto & wh = auxSystem.nodalArrayAuxWarehouse();
356 std::set<std::string> names;
357 if (wh.hasActiveBlockObjects(subdomain_id))
359 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
360 for (
auto & auxkernel : auxkernels)
361 names.insert(auxkernel->name());
363 objectsFound = printCategoryAndNames(
"AuxKernels[nodalArray]", names) || objectsFound;
367 const auto & wh = auxSystem.elemAuxWarehouse();
368 std::set<std::string> names;
369 if (wh.hasActiveBlockObjects(subdomain_id))
371 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
372 for (
auto & auxkernel : auxkernels)
373 names.insert(auxkernel->name());
375 objectsFound = printCategoryAndNames(
"AuxKernels[elemAux]", names) || objectsFound;
379 const auto & wh = auxSystem.elemVectorAuxWarehouse();
380 std::set<std::string> names;
381 if (wh.hasActiveBlockObjects(subdomain_id))
383 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
384 for (
auto & auxkernel : auxkernels)
385 names.insert(auxkernel->name());
387 objectsFound = printCategoryAndNames(
"AuxKernels[elemVector]", names) || objectsFound;
391 const auto & wh = auxSystem.elemArrayAuxWarehouse();
392 std::set<std::string> names;
393 if (wh.hasActiveBlockObjects(subdomain_id))
395 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
396 for (
auto & auxkernel : auxkernels)
397 names.insert(auxkernel->name());
399 objectsFound = printCategoryAndNames(
"AuxKernels[elemArray]", names) || objectsFound;
406 std::set<std::string> names;
407 if (material_warehouse.hasActiveBlockObjects(subdomain_id))
409 auto const objs = material_warehouse.getBlockObjects(subdomain_id);
410 for (
const auto & mat : objs)
411 names.insert(mat->name());
413 objectsFound = printCategoryAndNames(
"Materials", names) || objectsFound;
419 std::set<std::string> names;
420 for (
const auto & obj : userObjects)
421 if (
BlockRestrictable * blockrestrictable_obj = dynamic_cast<BlockRestrictable *>(obj))
422 if (blockrestrictable_obj->hasBlocks(subdomain_id))
423 names.insert(obj->name());
424 objectsFound = printCategoryAndNames(
"UserObjects", names) || objectsFound;
428 out <<
" (no objects found)\n";
434 _console <<
"\n[DBG] Block-Restrictions (" << mesh_subdomains.size()
435 <<
" subdomains): showing active objects\n";
443 const auto & mesh_subdomains =
mesh.meshSubdomains();
445 RestrictionGroups<SubdomainID> groups;
446 std::vector<MooseObject *> objects;
450 .condition<AttribThread>(0)
451 .queryIntoUnsorted(objects);
453 for (
const auto object : objects)
456 const auto *
const block_restrictable =
dynamic_cast<const BlockRestrictable *
>(object);
457 mooseAssert(block_restrictable,
"Query returned an object without BlockRestrictable");
458 groups[block_restrictable->blockIDs()].insert(objectRestrictionName(*
object));
470 groups[var.blockIDs()].
insert(
"Variable/" + var_name);
475 for (
const auto vg :
make_range(aux_system.n_variable_groups()))
477 const VariableGroup & vg_description(aux_system.variable_group(vg));
478 std::set<SubdomainID>
blocks;
479 for (
const auto subdomain_id : mesh_subdomains)
480 if (vg_description.active_on_subdomain(subdomain_id))
481 blocks.insert(subdomain_id);
483 for (
const auto vn :
make_range(vg_description.n_variables()))
484 groups[
blocks].insert(
"AuxVariable/" + vg_description.name(vn));
489 addWarehouseBlockRestrictionObjects(groups, aux_system_base.nodalAuxWarehouse());
490 addWarehouseBlockRestrictionObjects(groups, aux_system_base.mortarNodalAuxWarehouse());
491 addWarehouseBlockRestrictionObjects(groups, aux_system_base.nodalVectorAuxWarehouse());
492 addWarehouseBlockRestrictionObjects(groups, aux_system_base.nodalArrayAuxWarehouse());
493 addWarehouseBlockRestrictionObjects(groups, aux_system_base.elemAuxWarehouse());
494 addWarehouseBlockRestrictionObjects(groups, aux_system_base.elemVectorAuxWarehouse());
495 addWarehouseBlockRestrictionObjects(groups, aux_system_base.elemArrayAuxWarehouse());
496 #ifdef MOOSE_KOKKOS_ENABLED 497 addWarehouseBlockRestrictionObjects(groups, aux_system_base.kokkosNodalAuxWarehouse());
498 addWarehouseBlockRestrictionObjects(groups, aux_system_base.kokkosElemAuxWarehouse());
509 std::stringstream
out;
510 for (
const auto & group : groups)
514 << formatRestrictionIDs<SubdomainID>(group.first,
519 const auto &
name =
mesh.getSubdomainName(
id);
520 return name.empty() ? std::to_string(
id)
521 :
"'" +
name +
"' (id " +
522 std::to_string(
id) +
")";
524 <<
" (" << group.second.size() <<
" " << (group.second.size() == 1 ?
"item" :
"items")
526 printGroupNames(
out, group.second);
530 out <<
"\n (no objects found)\n";
534 _console <<
"\n[DBG] Block-Restriction Groups (" << groups.size()
535 <<
" groups): showing objects with matching block restrictions\n";
543 const auto & mesh_boundaries =
mesh.getBoundaryIDs();
545 RestrictionGroups<BoundaryID> groups;
546 std::vector<MooseObject *> objects;
550 .condition<AttribThread>(0)
551 .queryIntoUnsorted(objects);
553 for (
const auto object : objects)
557 mooseAssert(boundary_restrictable,
"Query returned an object without BoundaryRestrictable");
558 const auto & ids = boundary_restrictable->boundaryRestricted()
559 ? boundary_restrictable->boundaryIDs()
560 : boundary_restrictable->meshBoundaryIDs();
561 groups[ids].insert(objectRestrictionName(*
object));
568 addWarehouseBoundaryRestrictionObjects(groups, aux_system.nodalAuxWarehouse(),
false);
569 addWarehouseBoundaryRestrictionObjects(groups, aux_system.mortarNodalAuxWarehouse(),
false);
570 addWarehouseBoundaryRestrictionObjects(groups, aux_system.nodalVectorAuxWarehouse(),
false);
571 addWarehouseBoundaryRestrictionObjects(groups, aux_system.nodalArrayAuxWarehouse(),
false);
572 addWarehouseBoundaryRestrictionObjects(groups, aux_system.elemAuxWarehouse(),
false);
573 addWarehouseBoundaryRestrictionObjects(groups, aux_system.elemVectorAuxWarehouse(),
false);
574 addWarehouseBoundaryRestrictionObjects(groups, aux_system.elemArrayAuxWarehouse(),
false);
575 #ifdef MOOSE_KOKKOS_ENABLED 576 addWarehouseBoundaryRestrictionObjects(groups, aux_system.kokkosNodalAuxWarehouse(),
false);
577 addWarehouseBoundaryRestrictionObjects(groups, aux_system.kokkosElemAuxWarehouse(),
false);
580 addWarehouseBoundaryRestrictionObjects(
585 std::stringstream
out;
586 for (
const auto & group : groups)
589 out <<
" Boundaries " 590 << formatRestrictionIDs<BoundaryID>(group.first,
595 const auto name =
mesh.getBoundaryString(
id);
596 return "'" +
name +
"' (id " + std::to_string(
id) +
599 <<
" (" << group.second.size() <<
" " << (group.second.size() == 1 ?
"item" :
"items")
601 printGroupNames(
out, group.second);
605 out <<
"\n (no objects found)\n";
609 _console <<
"\n[DBG] Boundary-Restriction Groups (" << groups.size()
610 <<
" groups): showing objects with matching boundary restrictions\n";
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
const ConstraintWarehouse & getConstraintWarehouse() const
BlockRestrictionDebugOutput(const InputParameters ¶meters)
A MultiMooseEnum object to hold "execute_on" flags.
const bool & _show_block_restriction_groups
Whether to print object groups by identical block restriction.
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
void printBlockRestrictionMap() const
Prints block-restriction information.
virtual bool isValid() const override
IsValid.
virtual void output() override
Perform the debugging output.
MooseObjectTagWarehouse< KernelBase > & getKernelWarehouse()
Access functions to Warehouses from outside NonlinearSystemBase.
A class for producing various debug related outputs.
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
const MaterialWarehouse & getMaterialWarehouse() const
const InitialConditionWarehouse & getInitialConditionWarehouse() const
Return InitialCondition storage.
const bool & _show_block_restriction_map
Whether to print the existing per-block restriction map.
const NonlinearSystemBase & _nl
Reference to MOOSE's nonlinear system.
const bool & _show_boundary_restriction_groups
Whether to print object groups by identical boundary restriction.
void printBoundaryRestrictionGroups() const
Prints object groups with identical boundary restrictions.
virtual const MooseVariableFieldBase & getVariable(const THREAD_ID tid, const std::string &var_name, Moose::VarKindType expected_var_type=Moose::VarKindType::VAR_ANY, Moose::VarFieldType expected_var_field_type=Moose::VarFieldType::VAR_FIELD_ANY) const override
Returns the variable reference for requested variable which must be of the expected_var_type (Nonline...
static const unsigned int console_field_width
Width used for printing simulation information.
Based class for output objects.
bool contains(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
const std::string & name() const
Get the name of the class.
const std::vector< std::shared_ptr< T > > & getObjects(THREAD_ID tid=0) const
Retrieve complete vector to the all/block/boundary restricted objects for a given thread...
TheWarehouse & theWarehouse() const
const MultiMooseEnum & _scope
multi-enum of object types to show the block-restriction for
Every object that can be built by the factory should be derived from this class.
void insertNewline(std::stringstream &oss, std::streampos &begin, std::streampos &curr)
Helper function function for stringstream formatting.
boundary_id_type BoundaryID
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
const std::string & variable_name(const unsigned int i) const
static InputParameters validParams()
std::string stringify(const T &t)
conversion to string
AuxiliarySystem & getAuxiliarySystem()
registerMooseObject("MooseApp", BlockRestrictionDebugOutput)
virtual void insert(libMesh::NumericVector< libMesh::Number > &vector)=0
Insert the currently cached degree of freedom values into the provided vector.
const FVInitialConditionWarehouse & getFVInitialConditionWarehouse() const
Return FVInitialCondition storage.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse...
static MultiMooseEnum getScopes(std::string default_scopes="")
Get the supported scopes of output (e.g., variables, etc.)
An interface that restricts an object to subdomains via the 'blocks' input parameter.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type...
virtual libMesh::System & system() override
Get the reference to the libMesh system.
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
unsigned int n_vars() const
OStreamProxy out(std::cout)
A base storage container for MooseObjects.
static InputParameters validParams()
void printBlockRestrictionGroups() const
Prints object groups with identical block restrictions.
virtual bool enabled() const
Return the enabled status of the object.
const libMesh::System & _sys
Reference to libMesh system.
const ExecFlagType EXEC_INITIAL