www.mooseframework.org
VectorPostprocessorData.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 #include "FEProblem.h"
17 
19  : Restartable("values", "VectorPostprocessorData", fe_problem, 0)
20 {
21 }
22 
23 bool
25 {
26  return (_values.find(name) != _values.end());
27 }
28 
30 VectorPostprocessorData::getVectorPostprocessorValue(const VectorPostprocessorName & vpp_name,
31  const std::string & vector_name)
32 {
33  _requested_items.emplace(vpp_name + "::" + vector_name);
34 
35  return getVectorPostprocessorHelper(vpp_name, vector_name, true);
36 }
37 
39 VectorPostprocessorData::getVectorPostprocessorValueOld(const VectorPostprocessorName & vpp_name,
40  const std::string & vector_name)
41 {
42  _requested_items.emplace(vpp_name + "::" + vector_name);
43 
44  return getVectorPostprocessorHelper(vpp_name, vector_name, false);
45 }
46 
48 VectorPostprocessorData::declareVector(const std::string & vpp_name,
49  const std::string & vector_name)
50 {
51  _supplied_items.emplace(vpp_name + "::" + vector_name);
52 
53  return getVectorPostprocessorHelper(vpp_name, vector_name, true);
54 }
55 
57 VectorPostprocessorData::getVectorPostprocessorHelper(const VectorPostprocessorName & vpp_name,
58  const std::string & vector_name,
59  bool get_current)
60 {
61  // Intentional use of RHS brackets on a std::map to do a retrieve or insert
62  auto & vec_storage = _values[vpp_name];
63 
64  // lambda for doing compairison on name (i.e., first item in pair)
65  auto comp = [&vector_name](std::pair<std::string, VectorPostprocessorState> & pair) {
66  return pair.first == vector_name;
67  };
68 
69  // Search for the vector, if it is not located create the entry in the storage
70  auto iter = std::find_if(vec_storage.rbegin(), vec_storage.rend(), comp);
71  if (iter == vec_storage.rend())
72  {
73  vec_storage.emplace_back(
74  std::pair<std::string, VectorPostprocessorState>(vector_name, VectorPostprocessorState()));
75  iter = vec_storage.rbegin();
76  }
77 
78  auto & vec_struct = iter->second;
79  if (!vec_struct.current)
80  {
81  mooseAssert(!vec_struct.old, "Uninitialized pointers in VectorPostprocessor Data");
82  vec_struct.current = &declareRestartableDataWithObjectName<VectorPostprocessorValue>(
83  vpp_name + "_" + vector_name, "values");
84  vec_struct.old = &declareRestartableDataWithObjectName<VectorPostprocessorValue>(
85  vpp_name + "_" + vector_name, "values_old");
86  }
87 
88  return get_current ? *vec_struct.current : *vec_struct.old;
89 }
90 
91 bool
92 VectorPostprocessorData::hasVectors(const std::string & vpp_name) const
93 {
94  return _values.find(vpp_name) != _values.end();
95 }
96 
97 const std::vector<std::pair<std::string, VectorPostprocessorData::VectorPostprocessorState>> &
98 VectorPostprocessorData::vectors(const std::string & vpp_name) const
99 {
100  auto vec_pair = _values.find(vpp_name);
101  mooseAssert(vec_pair != _values.end(), "No vectors found for vpp_name: " << vpp_name);
102 
103  return vec_pair->second;
104 }
105 
106 void
108 {
109  for (const auto & it : _values)
110  for (const auto & vec_it : it.second)
111  vec_it.second.old->swap(*vec_it.second.current);
112 }
VectorPostprocessorValue & declareVector(const std::string &vpp_name, const std::string &vector_name)
Initialization method, sets the current and old value to 0.0 for this VectorPostprocessor.
const std::vector< std::pair< std::string, VectorPostprocessorState > > & vectors(const std::string &vpp_name) const
Get the map of vectors for a particular VectorPostprocessor.
A class for creating restricted objects.
Definition: Restartable.h:31
void copyValuesBack()
Copy the current post-processor values into old (i.e.
std::set< std::string > _requested_items
VectorPostprocessorValue & getVectorPostprocessorValueOld(const VectorPostprocessorName &vpp_name, const std::string &vector_name)
The the old value of an post-processor.
bool hasVectorPostprocessor(const std::string &name)
Returns a true value if the VectorPostprocessor exists.
VectorPostprocessorValue & getVectorPostprocessorHelper(const VectorPostprocessorName &vpp_name, const std::string &vector_name, bool get_current)
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
VectorPostprocessorValue & getVectorPostprocessorValue(const VectorPostprocessorName &vpp_name, const std::string &vector_name)
Return the value for the post processor.
VectorPostprocessorData(FEProblemBase &fe_problem)
Class constructor.
std::map< std::string, std::vector< std::pair< std::string, VectorPostprocessorState > > > _values
Values of the vector post-processor.
std::vector< Real > VectorPostprocessorValue
Definition: MooseTypes.h:74
bool hasVectors(const std::string &vpp_name) const
Check to see if a VPP has any vectors at all.
std::set< std::string > _supplied_items