30#include "libmesh/transient_system.h"
40using RestrictionGroups = std::map<std::set<ID>, std::set<std::string>>;
44formatRestrictionIDs(
const std::set<ID> & ids,
45 const std::set<ID> & all_ids,
46 const std::string & all_text,
47 const std::function<std::string(ID)> & id_to_string)
55 std::stringstream out;
57 for (
const auto id : ids)
58 out << id_to_string(id) << (++i < ids.size() ?
", " :
"");
64printGroupNames(std::stringstream & out,
const std::set<std::string> & names)
66 std::streampos begin_string_pos =
out.
tellp();
67 std::streampos curr_string_pos = begin_string_pos;
69 for (
const auto & name : names)
81 return object.type() +
"/" +
object.name();
85addBlockRestrictionObject(RestrictionGroups<SubdomainID> & groups,
const MooseObject &
object)
87 if (!
object.enabled())
90 const auto *
const block_restrictable =
dynamic_cast<const BlockRestrictable *
>(&object);
91 if (block_restrictable)
92 groups[block_restrictable->blockIDs()].insert(objectRestrictionName(
object));
96addBoundaryRestrictionObject(RestrictionGroups<BoundaryID> & groups,
98 const bool include_unrestricted)
100 if (!
object.enabled())
104 if (!boundary_restrictable)
107 if (!include_unrestricted && !boundary_restrictable->boundaryRestricted())
111 ? boundary_restrictable->boundaryIDs()
112 : boundary_restrictable->meshBoundaryIDs();
113 groups[ids].insert(objectRestrictionName(
object));
118addWarehouseBlockRestrictionObjects(RestrictionGroups<SubdomainID> & groups,
121 for (
const auto &
object : warehouse.getObjects( 0))
122 addBlockRestrictionObject(groups, *object);
127addWarehouseBoundaryRestrictionObjects(RestrictionGroups<BoundaryID> & groups,
129 const bool include_unrestricted)
131 for (
const auto &
object : warehouse.getObjects( 0))
132 addBoundaryRestrictionObject(groups, *object, include_unrestricted);
143 "The types of object to output block coverage for, if nothing is "
144 "provided everything will be output.");
146 params.
addParam<NonlinearSystemName>(
147 "nl_sys",
"nl0",
"The nonlinear system that we should output information for.");
149 "show_block_restriction_map",
151 "Print active objects for each block. This is the default block-restriction debug output.");
152 params.
addParam<
bool>(
"show_block_restriction_groups",
154 "Print groups of objects with identical block restrictions.");
155 params.
addParam<
bool>(
"show_boundary_restriction_groups",
157 "Print groups of objects with identical boundary restrictions.");
160 "Debug output object for displaying information regarding block and boundary restrictions of "
169 return MultiMooseEnum(
"none all variables kernels auxvariables auxkernels materials userobjects",
176 _nl(_problem_ptr->getNonlinearSystemBase(
177 _problem_ptr->nlSysNum(getParam<NonlinearSystemName>(
"nl_sys")))),
179 _show_block_restriction_map(getParam<bool>(
"show_block_restriction_map")),
180 _show_block_restriction_groups(getParam<bool>(
"show_block_restriction_groups")),
181 _show_boundary_restriction_groups(getParam<bool>(
"show_boundary_restriction_groups"))
206 std::stringstream out;
208 auto printCategoryAndNames = [&out](std::string category, std::set<std::string> & names)
210 const auto n = names.size();
214 out <<
" " << category <<
" (" << n <<
" " << ((n == 1) ?
"item" :
"items") <<
"): ";
218 std::streampos begin_string_pos = out.
tellp();
219 std::streampos curr_string_pos = begin_string_pos;
221 for (
const auto &
name : names)
224 curr_string_pos = out.
tellp();
240 const std::set<SubdomainID> & mesh_subdomains =
mesh.meshSubdomains();
244 const auto & kernels = kernel_warehouse.
getObjects( 0);
253 std::vector<UserObject *> userObjects;
257 .condition<AttribThread>(0)
258 .queryIntoUnsorted(userObjects);
264 for (
const auto & subdomain_id : mesh_subdomains)
267 const auto & subdomain_name =
mesh.getSubdomainName(subdomain_id);
270 out <<
" Subdomain '" << subdomain_name <<
"' (id " << subdomain_id <<
"):\n";
272 bool objectsFound =
false;
277 std::set<std::string> names;
278 for (
unsigned int var_num = 0; var_num <
_sys.
n_vars(); var_num++)
292 objectsFound = printCategoryAndNames(
"Variables", names) || objectsFound;
298 std::set<std::string> names;
299 for (
const auto & kernel : kernels)
301 if (kernel->hasBlocks(subdomain_id))
302 names.insert(kernel->name());
304 objectsFound = printCategoryAndNames(
"Kernels", names) || objectsFound;
310 std::set<std::string> names;
311 const auto & sys = auxSystem.system();
312 for (
unsigned int vg = 0; vg < sys.n_variable_groups(); vg++)
315 for (
unsigned int vn = 0; vn < vg_description.
n_variables(); vn++)
318 names.insert(vg_description.
name(vn));
321 objectsFound = printCategoryAndNames(
"AuxVariables", names) || objectsFound;
329 const auto & wh = auxSystem.nodalAuxWarehouse();
330 std::set<std::string> names;
331 if (wh.hasActiveBlockObjects(subdomain_id))
333 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
334 for (
auto & auxkernel : auxkernels)
335 names.insert(auxkernel->name());
337 objectsFound = printCategoryAndNames(
"AuxKernels[nodal]", names) || objectsFound;
341 const auto & wh = auxSystem.nodalVectorAuxWarehouse();
342 std::set<std::string> names;
343 if (wh.hasActiveBlockObjects(subdomain_id))
345 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
346 for (
auto & auxkernel : auxkernels)
347 names.insert(auxkernel->name());
349 objectsFound = printCategoryAndNames(
"AuxKernels[nodalVector]", names) || objectsFound;
353 const auto & wh = auxSystem.nodalArrayAuxWarehouse();
354 std::set<std::string> names;
355 if (wh.hasActiveBlockObjects(subdomain_id))
357 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
358 for (
auto & auxkernel : auxkernels)
359 names.insert(auxkernel->name());
361 objectsFound = printCategoryAndNames(
"AuxKernels[nodalArray]", names) || objectsFound;
365 const auto & wh = auxSystem.elemAuxWarehouse();
366 std::set<std::string> names;
367 if (wh.hasActiveBlockObjects(subdomain_id))
369 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
370 for (
auto & auxkernel : auxkernels)
371 names.insert(auxkernel->name());
373 objectsFound = printCategoryAndNames(
"AuxKernels[elemAux]", names) || objectsFound;
377 const auto & wh = auxSystem.elemVectorAuxWarehouse();
378 std::set<std::string> names;
379 if (wh.hasActiveBlockObjects(subdomain_id))
381 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
382 for (
auto & auxkernel : auxkernels)
383 names.insert(auxkernel->name());
385 objectsFound = printCategoryAndNames(
"AuxKernels[elemVector]", names) || objectsFound;
389 const auto & wh = auxSystem.elemArrayAuxWarehouse();
390 std::set<std::string> names;
391 if (wh.hasActiveBlockObjects(subdomain_id))
393 const auto & auxkernels = wh.getActiveBlockObjects(subdomain_id);
394 for (
auto & auxkernel : auxkernels)
395 names.insert(auxkernel->name());
397 objectsFound = printCategoryAndNames(
"AuxKernels[elemArray]", names) || objectsFound;
404 std::set<std::string> names;
405 if (material_warehouse.hasActiveBlockObjects(subdomain_id))
407 auto const objs = material_warehouse.getBlockObjects(subdomain_id);
408 for (
const auto & mat : objs)
409 names.insert(mat->name());
411 objectsFound = printCategoryAndNames(
"Materials", names) || objectsFound;
417 std::set<std::string> names;
418 for (
const auto & obj : userObjects)
420 if (blockrestrictable_obj->hasBlocks(subdomain_id))
421 names.insert(obj->name());
422 objectsFound = printCategoryAndNames(
"UserObjects", names) || objectsFound;
426 out <<
" (no objects found)\n";
432 _console <<
"\n[DBG] Block-Restrictions (" << mesh_subdomains.size()
433 <<
" subdomains): showing active objects\n";
441 const auto & mesh_subdomains =
mesh.meshSubdomains();
443 RestrictionGroups<SubdomainID> groups;
444 std::vector<MooseObject *> objects;
448 .condition<AttribThread>(0)
449 .queryIntoUnsorted(objects);
451 for (
const auto object : objects)
454 const auto *
const block_restrictable =
dynamic_cast<const BlockRestrictable *
>(object);
455 mooseAssert(block_restrictable,
"Query returned an object without BlockRestrictable");
456 groups[block_restrictable->blockIDs()].insert(objectRestrictionName(*
object));
461 for (
const auto var_num : make_range(
_sys.
n_vars()))
468 groups[var.blockIDs()].
insert(
"Variable/" + var_name);
473 for (
const auto vg : make_range(aux_system.n_variable_groups()))
476 std::set<SubdomainID>
blocks;
477 for (
const auto subdomain_id : mesh_subdomains)
479 blocks.insert(subdomain_id);
481 for (
const auto vn : make_range(vg_description.
n_variables()))
482 groups[
blocks].insert(
"AuxVariable/" + vg_description.
name(vn));
487 addWarehouseBlockRestrictionObjects(groups, aux_system_base.nodalAuxWarehouse());
488 addWarehouseBlockRestrictionObjects(groups, aux_system_base.mortarNodalAuxWarehouse());
489 addWarehouseBlockRestrictionObjects(groups, aux_system_base.nodalVectorAuxWarehouse());
490 addWarehouseBlockRestrictionObjects(groups, aux_system_base.nodalArrayAuxWarehouse());
491 addWarehouseBlockRestrictionObjects(groups, aux_system_base.elemAuxWarehouse());
492 addWarehouseBlockRestrictionObjects(groups, aux_system_base.elemVectorAuxWarehouse());
493 addWarehouseBlockRestrictionObjects(groups, aux_system_base.elemArrayAuxWarehouse());
494#ifdef MOOSE_KOKKOS_ENABLED
495 addWarehouseBlockRestrictionObjects(groups, aux_system_base.kokkosNodalAuxWarehouse());
496 addWarehouseBlockRestrictionObjects(groups, aux_system_base.kokkosElemAuxWarehouse());
507 std::stringstream out;
508 for (
const auto & group : groups)
512 << formatRestrictionIDs<SubdomainID>(group.first,
517 const auto & name = mesh.getSubdomainName(id);
518 return name.empty() ? std::to_string(id)
519 :
"'" + name +
"' (id " +
520 std::to_string(id) +
")";
522 <<
" (" << group.second.size() <<
" " << (group.second.size() == 1 ?
"item" :
"items")
524 printGroupNames(out, group.second);
528 out <<
"\n (no objects found)\n";
532 _console <<
"\n[DBG] Block-Restriction Groups (" << groups.size()
533 <<
" groups): showing objects with matching block restrictions\n";
541 const auto & mesh_boundaries =
mesh.getBoundaryIDs();
543 RestrictionGroups<BoundaryID> groups;
544 std::vector<MooseObject *> objects;
548 .condition<AttribThread>(0)
549 .queryIntoUnsorted(objects);
551 for (
const auto object : objects)
555 mooseAssert(boundary_restrictable,
"Query returned an object without BoundaryRestrictable");
556 const auto & ids = boundary_restrictable->boundaryRestricted()
557 ? boundary_restrictable->boundaryIDs()
558 : boundary_restrictable->meshBoundaryIDs();
559 groups[ids].insert(objectRestrictionName(*
object));
566 addWarehouseBoundaryRestrictionObjects(groups, aux_system.nodalAuxWarehouse(),
false);
567 addWarehouseBoundaryRestrictionObjects(groups, aux_system.mortarNodalAuxWarehouse(),
false);
568 addWarehouseBoundaryRestrictionObjects(groups, aux_system.nodalVectorAuxWarehouse(),
false);
569 addWarehouseBoundaryRestrictionObjects(groups, aux_system.nodalArrayAuxWarehouse(),
false);
570 addWarehouseBoundaryRestrictionObjects(groups, aux_system.elemAuxWarehouse(),
false);
571 addWarehouseBoundaryRestrictionObjects(groups, aux_system.elemVectorAuxWarehouse(),
false);
572 addWarehouseBoundaryRestrictionObjects(groups, aux_system.elemArrayAuxWarehouse(),
false);
573#ifdef MOOSE_KOKKOS_ENABLED
574 addWarehouseBoundaryRestrictionObjects(groups, aux_system.kokkosNodalAuxWarehouse(),
false);
575 addWarehouseBoundaryRestrictionObjects(groups, aux_system.kokkosElemAuxWarehouse(),
false);
578 addWarehouseBoundaryRestrictionObjects(
583 std::stringstream out;
584 for (
const auto & group : groups)
587 out <<
" Boundaries "
588 << formatRestrictionIDs<BoundaryID>(group.first,
593 const auto name = mesh.getBoundaryString(id);
594 return
"'" + name +
"' (id " + std::to_string(id) +
597 <<
" (" << group.second.size() <<
" " << (group.second.size() == 1 ?
"item" :
"items")
599 printGroupNames(out, group.second);
603 out <<
"\n (no objects found)\n";
607 _console <<
"\n[DBG] Boundary-Restriction Groups (" << groups.size()
608 <<
" groups): showing objects with matching boundary restrictions\n";
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
registerMooseObject("MooseApp", BlockRestrictionDebugOutput)
const ExecFlagType EXEC_INITIAL
virtual libMesh::System & system() override
Get the reference to the libMesh system.
An interface that restricts an object to subdomains via the 'blocks' input parameter.
bool hasBlocks(const SubdomainName &name) const
Test if the supplied block name is valid for this object.
A class for producing various debug related outputs.
const NonlinearSystemBase & _nl
Reference to MOOSE's nonlinear system.
const bool & _show_block_restriction_groups
Whether to print object groups by identical block restriction.
void printBoundaryRestrictionGroups() const
Prints object groups with identical boundary restrictions.
const bool & _show_boundary_restriction_groups
Whether to print object groups by identical boundary restriction.
virtual void output() override
Perform the debugging output.
void printBlockRestrictionGroups() const
Prints object groups with identical block restrictions.
const MultiMooseEnum & _scope
multi-enum of object types to show the block-restriction for
const libMesh::System & _sys
Reference to libMesh system.
static InputParameters validParams()
BlockRestrictionDebugOutput(const InputParameters ¶meters)
const bool & _show_block_restriction_map
Whether to print the existing per-block restriction map.
static MultiMooseEnum getScopes(std::string default_scopes="")
Get the supported scopes of output (e.g., variables, etc.)
void printBlockRestrictionMap() const
Prints block-restriction information.
/class BoundaryRestrictable /brief Provides functionality for limiting the object to certain boundary...
virtual bool boundaryRestricted() const
Returns true if this object has been restricted to a boundary.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
A MultiMooseEnum object to hold "execute_on" flags.
AuxiliarySystem & getAuxiliarySystem()
const InitialConditionWarehouse & getInitialConditionWarehouse() const
Return InitialCondition storage.
const MaterialWarehouse & getMaterialWarehouse() const
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...
virtual bool hasVariable(const std::string &var_name) const override
Whether or not this problem has the variable.
virtual MooseMesh & mesh() override
TheWarehouse & theWarehouse() const
const FVInitialConditionWarehouse & getFVInitialConditionWarehouse() const
Return FVInitialCondition storage.
const std::string & name() const
Get the name of the class.
MooseMesh wraps a libMesh::Mesh object and enhances its capabilities by caching additional data and s...
A base storage container for MooseObjects.
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.
Every object that can be built by the factory should be derived from this class.
virtual bool enabled() const
Return the enabled status of the object.
virtual void insert(libMesh::NumericVector< libMesh::Number > &vector)=0
Insert the currently cached degree of freedom values into the provided vector.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type.
bool contains(const std::string &value) const
Methods for seeing if a value is set in the MultiMooseEnum.
virtual bool isValid() const override
IsValid.
const ConstraintWarehouse & getConstraintWarehouse() const
MooseObjectTagWarehouse< KernelBase > & getKernelWarehouse()
Access functions to Warehouses from outside NonlinearSystemBase.
Based class for output objects.
FEProblemBase * _problem_ptr
Pointer the the FEProblemBase object for output object (use this)
static InputParameters validParams()
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
const std::string & variable_name(const unsigned int i) const
unsigned int n_vars() const
unsigned int n_variables() const
const std::string & name(unsigned int v) const
bool active_on_subdomain(subdomain_id_type sid) const
static const unsigned int console_field_width
Width used for printing simulation information.
void insertNewline(std::stringstream &oss, std::streampos &begin, std::streampos &curr)
Helper function function for stringstream formatting.
std::string stringify(const T &t)
conversion to string
OStreamProxy out(std::cout)