forked from idaholab/moose
/
ReporterData.C
135 lines (117 loc) · 3.95 KB
/
ReporterData.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//* This file is part of the MOOSE framework
//* https://www.mooseframework.org
//*
//* All rights reserved, see COPYRIGHT for full restrictions
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
//*
//* Licensed under LGPL 2.1, please see LICENSE for details
//* https://www.gnu.org/licenses/lgpl-2.1.html
#include "ReporterData.h"
#include "MooseApp.h"
ReporterData::ReporterData(MooseApp & moose_app) : _app(moose_app) {}
void
ReporterData::copyValuesBack()
{
for (const auto & name_context_pair : _context_ptrs)
name_context_pair.second->copyValuesBack();
}
void
ReporterData::finalize(const std::string & object_name)
{
for (auto & name_context_pair : _context_ptrs)
if (name_context_pair.first.getObjectName() == object_name)
name_context_pair.second->finalize();
}
bool
ReporterData::hasReporterValue(const ReporterName & reporter_name) const
{
return _context_ptrs.count(reporter_name);
}
std::set<ReporterName>
ReporterData::getReporterNames() const
{
std::set<ReporterName> output;
for (const auto & name_context_pair : _context_ptrs)
output.insert(name_context_pair.second->name());
return output;
}
const ReporterContextBase &
ReporterData::getReporterContextBase(const ReporterName & reporter_name) const
{
if (!hasReporterValue(reporter_name))
mooseError("Unable to locate Reporter context with name: ", reporter_name);
return *_context_ptrs.at(reporter_name);
}
ReporterContextBase &
ReporterData::getReporterContextBase(const ReporterName & reporter_name)
{
if (!hasReporterValue(reporter_name))
mooseError("Unable to locate Reporter context with name: ", reporter_name);
return *_context_ptrs.at(reporter_name);
}
const ReporterStateBase &
ReporterData::getReporterStateBase(const ReporterName & reporter_name) const
{
if (!hasReporterState(reporter_name))
mooseError("Unable to locate Reporter state with name: ", reporter_name);
return *_states.at(reporter_name);
}
ReporterStateBase &
ReporterData::getReporterStateBase(const ReporterName & reporter_name)
{
if (!hasReporterState(reporter_name))
mooseError("Unable to locate Reporter state with name: ", reporter_name);
return *_states.at(reporter_name);
}
void
ReporterData::check() const
{
std::string missing;
for (const auto & name_state_pair : _states)
if (!name_state_pair.second->hasProducer())
missing += getReporterInfo(name_state_pair.first) + "\n";
if (missing.size())
mooseError("The following Reporter(s) were not declared:\n\n", missing);
}
RestartableDataValue &
ReporterData::getRestartableDataHelper(std::unique_ptr<RestartableDataValue> data_ptr,
bool declare) const
{
// get the name to avoid problems with arbitrary function argument evaluation
const auto name = data_ptr->name();
return _app.registerRestartableData(name, std::move(data_ptr), 0, !declare);
}
bool
ReporterData::hasReporterWithMode(const std::string & obj_name, const ReporterMode & mode) const
{
for (const auto & name_context_pair : _context_ptrs)
if (name_context_pair.first.getObjectName() == obj_name &&
name_context_pair.second->getProducerModeEnum() == mode)
return true;
return false;
}
const ReporterProducerEnum &
ReporterData::getReporterMode(const ReporterName & reporter_name) const
{
return getReporterContextBase(reporter_name).getProducerModeEnum();
}
bool
ReporterData::hasReporterState(const ReporterName & reporter_name) const
{
return _states.count(reporter_name);
}
std::string
ReporterData::getReporterInfo(const ReporterName & reporter_name) const
{
const ReporterContextBase * context =
hasReporterValue(reporter_name) ? &getReporterContextBase(reporter_name) : nullptr;
return getReporterStateBase(reporter_name).getInfo(context);
}
std::string
ReporterData::getReporterInfo() const
{
std::string out = _states.empty() ? "No reporters were requested or declared." : "";
for (const auto & name : getReporterNames())
out += getReporterInfo(name) + "\n";
return out;
}