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 std::vector<AuxKernel *> aux_kernels;
336 .condition<AttribSubdomains>(subdomain_id)
337 .queryIntoUnsorted(aux_kernels);
338 std::set<std::string> names;
339 for (
auto & auxkernel : aux_kernels)
340 names.insert(auxkernel->name());
341 objectsFound = printCategoryAndNames(
"AuxKernels[nodal]", names) || objectsFound;
345 std::vector<VectorAuxKernel *> aux_kernels;
351 .condition<AttribSubdomains>(subdomain_id)
352 .queryIntoUnsorted(aux_kernels);
353 std::set<std::string> names;
354 for (
auto & auxkernel : aux_kernels)
355 names.insert(auxkernel->name());
356 objectsFound = printCategoryAndNames(
"AuxKernels[nodalVector]", names) || objectsFound;
360 std::vector<ArrayAuxKernel *> aux_kernels;
366 .condition<AttribSubdomains>(subdomain_id)
367 .queryIntoUnsorted(aux_kernels);
368 std::set<std::string> names;
369 for (
auto & auxkernel : aux_kernels)
370 names.insert(auxkernel->name());
371 objectsFound = printCategoryAndNames(
"AuxKernels[nodalArray]", names) || objectsFound;
375 std::vector<AuxKernel *> aux_kernels;
381 .condition<AttribSubdomains>(subdomain_id)
382 .queryIntoUnsorted(aux_kernels);
383 std::set<std::string> names;
384 for (
auto & auxkernel : aux_kernels)
385 names.insert(auxkernel->name());
386 objectsFound = printCategoryAndNames(
"AuxKernels[elemAux]", names) || objectsFound;
390 std::vector<VectorAuxKernel *> aux_kernels;
396 .condition<AttribSubdomains>(subdomain_id)
397 .queryIntoUnsorted(aux_kernels);
398 std::set<std::string> names;
399 for (
auto & auxkernel : aux_kernels)
400 names.insert(auxkernel->name());
401 objectsFound = printCategoryAndNames(
"AuxKernels[elemVector]", names) || objectsFound;
405 std::vector<ArrayAuxKernel *> aux_kernels;
411 .condition<AttribSubdomains>(subdomain_id)
412 .queryIntoUnsorted(aux_kernels);
413 std::set<std::string> names;
414 for (
auto & auxkernel : aux_kernels)
415 names.insert(auxkernel->name());
416 objectsFound = printCategoryAndNames(
"AuxKernels[elemArray]", names) || objectsFound;
423 std::set<std::string> names;
424 if (material_warehouse.hasActiveBlockObjects(subdomain_id))
426 auto const objs = material_warehouse.getBlockObjects(subdomain_id);
427 for (
const auto & mat : objs)
428 names.insert(mat->name());
430 objectsFound = printCategoryAndNames(
"Materials", names) || objectsFound;
436 std::set<std::string> names;
437 for (
const auto & obj : userObjects)
439 if (blockrestrictable_obj->hasBlocks(subdomain_id))
440 names.insert(obj->name());
441 objectsFound = printCategoryAndNames(
"UserObjects", names) || objectsFound;
445 out <<
" (no objects found)\n";
451 _console <<
"\n[DBG] Block-Restrictions (" << mesh_subdomains.size()
452 <<
" subdomains): showing active objects\n";
460 const auto & mesh_subdomains =
mesh.meshSubdomains();
462 RestrictionGroups<SubdomainID> groups;
463 std::vector<MooseObject *> objects;
467 .condition<AttribThread>(0)
468 .queryIntoUnsorted(objects);
470 for (
const auto object : objects)
473 const auto *
const block_restrictable =
dynamic_cast<const BlockRestrictable *
>(object);
474 mooseAssert(block_restrictable,
"Query returned an object without BlockRestrictable");
475 groups[block_restrictable->blockIDs()].insert(objectRestrictionName(*
object));
480 for (
const auto var_num : make_range(
_sys.
n_vars()))
487 groups[var.blockIDs()].
insert(
"Variable/" + var_name);
492 for (
const auto vg : make_range(aux_system.n_variable_groups()))
495 std::set<SubdomainID>
blocks;
496 for (
const auto subdomain_id : mesh_subdomains)
498 blocks.insert(subdomain_id);
500 for (
const auto vn : make_range(vg_description.
n_variables()))
501 groups[
blocks].insert(
"AuxVariable/" + vg_description.
name(vn));
507#ifdef MOOSE_KOKKOS_ENABLED
509 addWarehouseBlockRestrictionObjects(groups, aux_system_base.kokkosNodalAuxWarehouse());
510 addWarehouseBlockRestrictionObjects(groups, aux_system_base.kokkosElemAuxWarehouse());
521 std::stringstream out;
522 for (
const auto & group : groups)
526 << formatRestrictionIDs<SubdomainID>(group.first,
531 const auto & name = mesh.getSubdomainName(id);
532 return name.empty() ? std::to_string(id)
533 :
"'" + name +
"' (id " +
534 std::to_string(id) +
")";
536 <<
" (" << group.second.size() <<
" " << (group.second.size() == 1 ?
"item" :
"items")
538 printGroupNames(out, group.second);
542 out <<
"\n (no objects found)\n";
546 _console <<
"\n[DBG] Block-Restriction Groups (" << groups.size()
547 <<
" groups): showing objects with matching block restrictions\n";
555 const auto & mesh_boundaries =
mesh.getBoundaryIDs();
557 RestrictionGroups<BoundaryID> groups;
558 std::vector<MooseObject *> objects;
562 .condition<AttribThread>(0)
563 .queryIntoUnsorted(objects);
567 std::vector<MooseObject *> unrestricted_aux_kernel_vec;
574 .queryIntoUnsorted(unrestricted_aux_kernel_vec);
575 const std::set<const MooseObject *> unrestricted_aux_kernels(unrestricted_aux_kernel_vec.begin(),
576 unrestricted_aux_kernel_vec.end());
578 for (
const auto object : objects)
579 if (object->
enabled() && !unrestricted_aux_kernels.count(
object))
582 mooseAssert(boundary_restrictable,
"Query returned an object without BoundaryRestrictable");
584 const auto & ids = boundary_restrictable->boundaryRestricted()
585 ? boundary_restrictable->boundaryIDs()
586 : boundary_restrictable->meshBoundaryIDs();
587 groups[ids].insert(objectRestrictionName(*
object));
595#ifdef MOOSE_KOKKOS_ENABLED
597 addWarehouseBoundaryRestrictionObjects(groups, aux_system.kokkosNodalAuxWarehouse(),
false);
598 addWarehouseBoundaryRestrictionObjects(groups, aux_system.kokkosElemAuxWarehouse(),
false);
601 addWarehouseBoundaryRestrictionObjects(
606 std::stringstream out;
607 for (
const auto & group : groups)
610 out <<
" Boundaries "
611 << formatRestrictionIDs<BoundaryID>(group.first,
616 const auto name = mesh.getBoundaryString(id);
617 return
"'" + name +
"' (id " + std::to_string(id) +
620 <<
" (" << group.second.size() <<
" " << (group.second.size() == 1 ?
"item" :
"items")
622 printGroupNames(out, group.second);
626 out <<
"\n (no objects found)\n";
630 _console <<
"\n[DBG] Boundary-Restriction Groups (" << groups.size()
631 <<
" groups): showing objects with matching boundary restrictions\n";
@ Nodal
Execution categories.
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
registerMooseObject("MooseApp", BlockRestrictionDebugOutput)
const ExecFlagType EXEC_INITIAL
@ UnrestrictedOnly
Only objects that are not boundary restricted, whatever the query boundaries.
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
const BoundaryID ANY_BOUNDARY_ID
OStreamProxy out(std::cout)