https://mooseframework.inl.gov
ReporterContext.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "ReporterContext.h"
11 
12 #include "ReporterData.h"
13 
15  const MooseObject & producer)
16  : libMesh::ParallelObject(other), _producer(producer)
17 {
18 }
19 
20 void
22 {
23  if (mode != REPORTER_MODE_UNSET)
24  _producer_enum.assign(mode);
25 }
26 
29 {
30  return _producer_enum;
31 }
32 
33 void
35  const std::set<ReporterMode> & modes) const
36 {
37  for (const auto & mode_object_pair : state.getConsumers())
38  if (!modes.count(mode_object_pair.first))
39  {
40  std::stringstream oss;
41  std::copy(modes.begin(), modes.end(), std::ostream_iterator<ReporterMode>(oss, " "));
42 
43  mooseError("The Reporter value '",
44  name(),
45  "' is being produced in ",
47  " mode, but ",
48  mode_object_pair.second->typeAndName(),
49  " is requesting to consume it in ",
50  mode_object_pair.first,
51  " mode, which is not supported.\n\nThe mode must be { ",
52  oss.str(),
53  " }.\n\n",
54  ReporterData::getReporterInfo(state, this));
55  }
56 }
void init(const ReporterMode &mode)
Initialize the producer mode.
const std::set< std::pair< ReporterMode, const MooseObject * > > & getConsumers() const
Returns the consumers for this state; a pair that consists of the mode that the state is being consum...
Definition: ReporterState.h:56
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:302
const ReporterMode REPORTER_MODE_UNSET
MooseEnum designed for the ReporterContext objects to define how a ReporterValue can and is being pro...
Definition: ReporterMode.h:61
virtual const ReporterName & name() const =0
Return the ReporterName that the context is associated.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
ReporterContextBase(const libMesh::ParallelObject &other, const MooseObject &producer)
const ReporterProducerEnum & getProducerModeEnum() const
Return the Reporter value produced mode.
Every object that can be built by the factory should be derived from this class.
Definition: MooseObject.h:28
void requiresConsumerModes(const ReporterStateBase &state, const std::set< ReporterMode > &modes) const
Helper for checking whether or not the state state has only the modes modes.
The base class for storing a Reporter&#39;s state.
Definition: ReporterState.h:32
void assign(const std::string &name, const std::optional< std::string > &context={})
Definition: MooseEnum.C:60
std::string getReporterInfo() const
Gets information about all declared/requested Reporters.
Definition: ReporterData.C:247
ReporterProducerEnum _producer_enum
Defines how the Reporter value can be produced and how it is being produced.
MooseEnumItem that automatically creates the ID and doesn&#39;t allow the ID to be assigned.
Definition: ReporterMode.h:44