Skip to content

Commit

Permalink
Add functor output for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
GiudGiud authored and lynnmunday committed Sep 29, 2022
1 parent 4ed6759 commit 5389ac4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
16 changes: 14 additions & 2 deletions framework/include/problems/SubProblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,9 @@ class SubProblem : public Problem
virtual void residualSetup();
virtual void jacobianSetup();

/// Setter for debug functor output
void setFunctorOutput(bool set_output) { _output_functors = set_output; }

protected:
/**
* Helper function called by getVariable that handles the logic for
Expand Down Expand Up @@ -877,7 +880,7 @@ class SubProblem : public Problem
///@{
/**
* Data structures of the requested material properties. We store them in a map
* from boudnary/block id to multimap. Each of the multimaps is a list of
* from boundary/block id to multimap. Each of the multimaps is a list of
* requestor object names to material property names.
*/
std::map<SubdomainID, std::multimap<std::string, std::string>> _map_block_material_props_check;
Expand Down Expand Up @@ -937,15 +940,24 @@ class SubProblem : public Problem
std::vector<std::multimap<std::string, std::unique_ptr<Moose::FunctorEnvelopeBase>>> _functors;

private:
/// Lists all functors in the problem
void showFunctors(const THREAD_ID tid) const;

/// Lists all functors and all the objects that requested them
void showFunctorRequestors() const;

/// The requestors of functors where the key is the prop name and the value is a set of names of
/// requestors
std::map<std::string, std::set<std::string>> _functor_to_requestors;

/// Whether to output the functors (currently only at initialSetup)
bool _output_functors;

/// The declared vector tags
std::vector<VectorTag> _vector_tags;

/**
* The vector tags assoicated with each VectorTagType
* The vector tags associated with each VectorTagType
* This is kept separate from _vector_tags for quick access into typed vector tags in places where
* we don't want to build a new vector every call (like in residual evaluation)
*/
Expand Down
9 changes: 8 additions & 1 deletion framework/src/actions/SetupDebugAction.C
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ SetupDebugAction::validParams()
"pid_aux",
false,
"Add a AuxVariable named \"pid\" that shows the processors and partitioning");
params.addParam<bool>("show_functors", false, "Whether to output the problem functors");

params.addClassDescription(
"Adds various debugging type Output objects to the simulation system.");
Expand All @@ -69,7 +70,7 @@ SetupDebugAction::act()
_problem->addOutput(type, "_moose_material_property_debug_output", params);
}

// Variable residusl norms
// Variable residual norms
if (_pars.get<bool>("show_var_residual_norms"))
{
const std::string type = "VariableResidualNormsDebugOutput";
Expand Down Expand Up @@ -119,4 +120,10 @@ SetupDebugAction::act()
params.set<AuxVariableName>("variable") = "pid";
_problem->addAuxKernel("ProcessorIDAux", "pid_aux", params);
}

// Add functor output
if (getParam<bool>("show_functors"))
{
_problem->setFunctorOutput(getParam<bool>("show_functors"));
}
}
33 changes: 33 additions & 0 deletions framework/src/problems/SubProblem.C
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "libmesh/system.h"
#include "libmesh/dof_map.h"

#include <regex>

InputParameters
SubProblem::validParams()
{
Expand Down Expand Up @@ -1033,6 +1035,12 @@ SubProblem::jacobianSetup()
void
SubProblem::initialSetup()
{
if (_output_functors)
{
showFunctors(0);
showFunctorRequestors();
}

for (const auto & functors : _functors)
for (const auto & pr : functors)
if (pr.second->wrapsNull())
Expand All @@ -1043,6 +1051,31 @@ SubProblem::initialSetup()
"'.");
}

void
SubProblem::showFunctors(const THREAD_ID tid) const
{
mooseAssert(tid < _functors.size(), "Too large a thread ID");
_console << "[DBG] Wrapped functors found in Subproblem" << std::endl;
std::string functor_names = "[DBG] ";
for (const auto & functor_pair : _functors[tid])
functor_names += std::regex_replace(functor_pair.first, std::regex("wraps_"), "") + " ";
_console << functor_names << std::endl;
}

void
SubProblem::showFunctorRequestors() const
{
for (const auto & [functor, requestors] : _functor_to_requestors)
{
_console << "[DBG] Requestors for wrapped functor "
<< std::regex_replace(functor, std::regex("wraps_"), "") << std::endl;
std::string requestor_names = "[DBG] ";
for (const auto & requestor : requestors)
requestor_names += requestor + " ";
_console << requestor_names << std::endl;
}
}

bool
SubProblem::hasFunctor(const std::string & name, const THREAD_ID tid) const
{
Expand Down

0 comments on commit 5389ac4

Please sign in to comment.