Skip to content

Commit

Permalink
Move Reporter producer ownership to the context
Browse files Browse the repository at this point in the history
  • Loading branch information
loganharbour committed Apr 21, 2021
1 parent d584ba2 commit 4cec036
Show file tree
Hide file tree
Showing 10 changed files with 120 additions and 118 deletions.
71 changes: 53 additions & 18 deletions framework/include/reporters/ReporterContext.h
Expand Up @@ -54,7 +54,7 @@ class ReporterData;
class ReporterContextBase : public libMesh::ParallelObject
{
public:
ReporterContextBase(const libMesh::ParallelObject & other);
ReporterContextBase(const libMesh::ParallelObject & other, const MooseObject & producer);
virtual ~ReporterContextBase() = default;

/// Return the ReporterName that the context is associated
Expand Down Expand Up @@ -100,6 +100,11 @@ class ReporterContextBase : public libMesh::ParallelObject
*/
void init(const ReporterMode & mode);

/**
* Return the MooseObject that produces this Reporter.
*/
const MooseObject & getProducer() const { return _producer; }

/**
* Return the Reporter value produced mode
*/
Expand Down Expand Up @@ -170,6 +175,9 @@ class ReporterContextBase : public libMesh::ParallelObject
void requiresConsumerModes(const ReporterStateBase & state,
const std::set<ReporterMode> & modes) const;

/// The MooseObject that is producing this Reporter
const MooseObject & _producer;

/// Defines how the Reporter value can be produced and how it is being produced
ReporterProducerEnum _producer_enum;
};
Expand All @@ -194,8 +202,11 @@ class ReporterContext : public ReporterContextBase
BROADCAST
};

ReporterContext(const libMesh::ParallelObject & other, ReporterState<T> & state);
ReporterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state);
ReporterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value);

Expand Down Expand Up @@ -269,17 +280,20 @@ class ReporterContext : public ReporterContextBase
};

template <typename T>
ReporterContext<T>::ReporterContext(const libMesh::ParallelObject & other, ReporterState<T> & state)
: ReporterContextBase(other), _state(state)
ReporterContext<T>::ReporterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state)
: ReporterContextBase(other, producer), _state(state)
{
_producer_enum.insert(REPORTER_MODE_ROOT, REPORTER_MODE_REPLICATED, REPORTER_MODE_DISTRIBUTED);
}

template <typename T>
ReporterContext<T>::ReporterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value)
: ReporterContext(other, state)
: ReporterContext(other, producer, state)
{
_state.value() = default_value;
}
Expand Down Expand Up @@ -362,14 +376,17 @@ template <typename T>
class ReporterGeneralContext : public ReporterContext<T>
{
public:
ReporterGeneralContext(const libMesh::ParallelObject & other, ReporterState<T> & state)
: ReporterContext<T>(other, state)
ReporterGeneralContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state)
: ReporterContext<T>(other, producer, state)
{
}
ReporterGeneralContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value)
: ReporterContext<T>(other, state, default_value)
: ReporterContext<T>(other, producer, state, default_value)
{
}

Expand Down Expand Up @@ -412,8 +429,11 @@ template <typename T>
class ReporterBroadcastContext : public ReporterGeneralContext<T>
{
public:
ReporterBroadcastContext(const libMesh::ParallelObject & other, ReporterState<T> & state);
ReporterBroadcastContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state);
ReporterBroadcastContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value);
virtual void finalize() override;
Expand All @@ -422,18 +442,20 @@ class ReporterBroadcastContext : public ReporterGeneralContext<T>

template <typename T>
ReporterBroadcastContext<T>::ReporterBroadcastContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state)
: ReporterGeneralContext<T>(other, state)
: ReporterGeneralContext<T>(other, producer, state)
{
this->_producer_enum.clear();
this->_producer_enum.insert(REPORTER_MODE_ROOT);
}

template <typename T>
ReporterBroadcastContext<T>::ReporterBroadcastContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value)
: ReporterGeneralContext<T>(other, state, default_value)
: ReporterGeneralContext<T>(other, producer, state, default_value)
{
this->_producer_enum.clear();
this->_producer_enum.insert(REPORTER_MODE_ROOT);
Expand All @@ -455,9 +477,11 @@ class ReporterScatterContext : public ReporterGeneralContext<T>
{
public:
ReporterScatterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const std::vector<T> & values);
ReporterScatterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value,
const std::vector<T> & values);
Expand All @@ -472,20 +496,22 @@ class ReporterScatterContext : public ReporterGeneralContext<T>

template <typename T>
ReporterScatterContext<T>::ReporterScatterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const std::vector<T> & values)
: ReporterGeneralContext<T>(other, state), _values(values)
: ReporterGeneralContext<T>(other, producer, state), _values(values)
{
this->_producer_enum.clear();
this->_producer_enum.insert(REPORTER_MODE_ROOT);
}

template <typename T>
ReporterScatterContext<T>::ReporterScatterContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value,
const std::vector<T> & values)
: ReporterGeneralContext<T>(other, state, default_value), _values(values)
: ReporterGeneralContext<T>(other, producer, state, default_value), _values(values)
{
this->_producer_enum.clear();
this->_producer_enum.insert(REPORTER_MODE_ROOT);
Expand All @@ -512,8 +538,11 @@ template <typename T>
class ReporterGatherContext : public ReporterGeneralContext<T>
{
public:
ReporterGatherContext(const libMesh::ParallelObject & other, ReporterState<T> & state);
ReporterGatherContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state);
ReporterGatherContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value);

Expand All @@ -523,18 +552,20 @@ class ReporterGatherContext : public ReporterGeneralContext<T>

template <typename T>
ReporterGatherContext<T>::ReporterGatherContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state)
: ReporterGeneralContext<T>(other, state)
: ReporterGeneralContext<T>(other, producer, state)
{
this->_producer_enum.clear();
this->_producer_enum.insert(REPORTER_MODE_DISTRIBUTED);
}

template <typename T>
ReporterGatherContext<T>::ReporterGatherContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state,
const T & default_value)
: ReporterGeneralContext<T>(other, state, default_value)
: ReporterGeneralContext<T>(other, producer, state, default_value)
{
this->_producer_enum.clear();
this->_producer_enum.insert(REPORTER_MODE_DISTRIBUTED);
Expand All @@ -559,8 +590,10 @@ class ReporterVectorContext : public ReporterContext<std::vector<T>>
{
public:
ReporterVectorContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<std::vector<T>> & state);
ReporterVectorContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<std::vector<T>> & state,
const std::vector<T> & default_value);

Expand Down Expand Up @@ -593,15 +626,17 @@ class ReporterVectorContext : public ReporterContext<std::vector<T>>

template <typename T>
ReporterVectorContext<T>::ReporterVectorContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<std::vector<T>> & state)
: ReporterContext<std::vector<T>>(other, state)
: ReporterContext<std::vector<T>>(other, producer, state)
{
}

template <typename T>
ReporterVectorContext<T>::ReporterVectorContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<std::vector<T>> & state,
const std::vector<T> & default_value)
: ReporterContext<std::vector<T>>(other, state, default_value)
: ReporterContext<std::vector<T>>(other, producer, state, default_value)
{
}
22 changes: 10 additions & 12 deletions framework/include/reporters/ReporterData.h
Expand Up @@ -242,11 +242,15 @@ class ReporterData
*/
const ReporterProducerEnum & getReporterMode(const ReporterName & reporter_name) const;

/**
* Gets information pertaining to the Reporter with state \p state and possibly
* context \p context.
*/
static std::string getReporterInfo(const ReporterStateBase & state,
const ReporterContextBase * context);

/**
* Gets information pertaining to the Reporter with name \p reporter_name.
*
* See ReporterState::getInfo. This is redeclared in ReporterData because it adds
* additional context about the context type if available.
*/
std::string getReporterInfo(const ReporterName & reporter_name) const;

Expand Down Expand Up @@ -346,12 +350,6 @@ ReporterData::getReporterStateHelper(const ReporterName & reporter_name,
// different special types are not unique so they'll be the same entry
_states.emplace(reporter_name, state);

if (declare)
{
mooseAssert(moose_object, "Declaring a Reporter requires a MooseObject as a producer");
state->setProducer(*moose_object);
}

return *state;
}

Expand All @@ -377,8 +375,8 @@ ReporterData::declareReporterValue(const ReporterName & reporter_name,
// Get/create the ReporterState
auto & state = getReporterStateHelper<T>(reporter_name, /* declare = */ true, &producer);

// They key in _states (ReporterName) is not unique. This is done on purpose
// because we want to store reporter names a single name regardless of type.
// They key in _states (ReporterName) is not unique by special type. This is done on purpose
// because we want to store reporter names a single name regardless of special type.
// Beacuse of this, we have the case where someone could request a reporter value
// that is later declared as a pp or a vpp value. In this case, when it is first
// requested, the _state entry will have a key and name with a special type of ANY.
Expand All @@ -405,7 +403,7 @@ ReporterData::declareReporterValue(const ReporterName & reporter_name,
mooseAssert(!_context_ptrs.count(reporter_name), "Context already exists");

// Create the ReporterContext
auto context_ptr = libmesh_make_unique<S>(_app, state, args...);
auto context_ptr = libmesh_make_unique<S>(_app, producer, state, args...);
context_ptr->init(mode); // initialize the mode, see ContextReporter
_context_ptrs.emplace(reporter_name, std::move(context_ptr));

Expand Down
26 changes: 0 additions & 26 deletions framework/include/reporters/ReporterState.h
Expand Up @@ -47,13 +47,6 @@ class ReporterStateBase
*/
void addConsumer(ReporterMode mode, const MooseObject & moose_object);

/**
* Sets the producer for this state, which is the object that is responsible for
* setting the value
* @param moose_object The producing object
*/
void setProducer(const MooseObject & moose_object);

/**
* Returns the consumers for this state; a pair that consists of the mode
* that the state is being consumed by, and the object consuming it
Expand All @@ -64,23 +57,6 @@ class ReporterStateBase
return _consumers;
}

/**
* @returns True if this state has an object that produces it
*/
bool hasProducer() const { return _producer; }
/**
* @returns The producer for this state; nullptr if none
*/
const MooseObject & getProducer() const { return *_producer; }

/**
* @returns A string containing information about this state, including
* its type, its producers, and its consumers.
*
* If the context is provided in \p context, the context type will also be provided.
*/
std::string getInfo(const ReporterContextBase * context = nullptr) const;

/**
* @returns The type associated with this state
*/
Expand All @@ -102,8 +78,6 @@ class ReporterStateBase
private:
/// Name of data that state is associated
ReporterName _reporter_name;
/// The MooseObject that is producing this ReporterState
const MooseObject * _producer;

/// The consumers for this state; we store the MooseObject for detailed error reporting
std::set<std::pair<ReporterMode, const MooseObject *>> _consumers;
Expand Down
4 changes: 3 additions & 1 deletion framework/include/vectorpostprocessors/VectorPostprocessor.h
Expand Up @@ -114,7 +114,9 @@ template <typename T>
class VectorPostprocessorContext : public ReporterGeneralContext<T>
{
public:
VectorPostprocessorContext(const libMesh::ParallelObject & other, ReporterState<T> & state);
VectorPostprocessorContext(const libMesh::ParallelObject & other,
const MooseObject & producer,
ReporterState<T> & state);
virtual void finalize() override;
virtual void copyValuesBack() override;

Expand Down

0 comments on commit 4cec036

Please sign in to comment.