C++ mpi module for stochmagnet_main Package
SM_StochasticOutputList.h
1 #ifndef SM_StochasticOutputList_H
2 #define SM_StochasticOutputList_H
3 
4 //inherited class
5 #include "SM_StochasticOutput.h"
6 
7 //components of the list
8 #include "SM_StochasticOutputComponent.h"
9 
19 class SM_StochasticOutputList : public SM_StochasticOutput<SM_StochasticOutputList> {
20 
21  // ATTRIBUTES
22 
23 public:
24 
25 
26 
27 private:
30 
31 
32  std::vector<CORE_UniquePointer<SM_StochasticOutputComponent>> mStochasticOutputList;
33 
34 
35 
36 
37 
38 public:
39  // METHODS
40 
41  // CONSTRUCTORS
42 
46 
47  }
48 
49 
50  // DESTRUCTORS
51 
54  virtual ~SM_StochasticOutputList(void) {
55  }
56 
57 
58 
59 public:
60  //MEMORY
61 
75  virtual tMemSize getMemorySize() const {
76  return sizeof(*this)+getContentsMemorySize();
77  }
78 
87  virtual tMemSize getContentsMemorySize() const {
88  tMemSize mem=SuperClass::getContentsMemorySize();
89  for(const auto& sd : mStochasticOutputList) {
90  mem+=sd->getContentsMemorySize();
91  }
92  return mem;
93  }
94 
98  inline static CORE_UniquePointer<SelfClass> New() {
99  return CORE_UniquePointer<SelfClass>(new SelfClass(),
101  }
102 
103  //SET & GET Methods
104  //=================
107  inline void clear() {
108  mStochasticOutputList.resize(0);
109  }
110 
114  inline tIndex getSize() const {
115  return mStochasticOutputList.size();
116  }
117 
120  inline const std::vector<CORE_UniquePointer<SM_StochasticOutputComponent>>& getStochasticOutputList() const {
121  return mStochasticOutputList;
122  }
125  inline std::vector<CORE_UniquePointer<SM_StochasticOutputComponent>>& getStochasticOutputList() {
126  return mStochasticOutputList;
127  }
131  inline void add(CORE_UniquePointer<SM_StochasticOutputComponent> data) {
132  mStochasticOutputList.push_back(std::move(data));
133  }
138  inline const SM_StochasticOutputComponent* get(const tIndex& i) {
139  return mStochasticOutputList[i].get();
140  }
141 
142 
146  virtual void setOutputPath(const tString& path) override {
148  for(auto& SOutput:mStochasticOutputList) SOutput->setOutputPath(path);
149  }
150 
154  virtual void setPrefix(const tString& prefix) override {
155  SuperClass::setPrefix(prefix);
156  for(auto& SOutput:mStochasticOutputList) SOutput->setPrefix(prefix);
157  }
158 
162  virtual void adimensionize(const SM_Material& material) override {
163  for(auto& SOutput:mStochasticOutputList) SOutput->adimensionize(material);
164  }
170  virtual void setIndex(const int& index,
171  const int& rootIndex,
172  const int& n) final {
173  SuperClass::setIndex(index,rootIndex,n);
174  for(auto& SOutput:mStochasticOutputList) SOutput->setIndex(index,rootIndex,n);
175  }
176  //implemented templated methods
177  //===================
178 
182  inline tBoolean open(const SM_Beam& beam) {
183  tBoolean ok=true;
184  for(auto& p : mStochasticOutputList) {
185  ok=p->openComponent(beam) && ok;
186  }
187  return ok;
188  }
189 
194  inline tBoolean open(const tIndex& s,const SM_System& system) {
195  tBoolean ok=true;
196  for(auto& p : mStochasticOutputList) {
197  ok=ok && p->openComponent(s,system);
198  }
199  return ok;
200  }
201 
202 
203 
207  inline tBoolean store(const SM_System& system) {
208  tBoolean ok=true;
209  for(auto& p : mStochasticOutputList) {
210  ok=p->storeComponent(system) && ok;
211  }
212  return ok;
213 
214  }
220  inline tBoolean close(const tIndex& s,const SM_System& system,const tBoolean& hasSucceeded) {
221  tBoolean ok=true;
222  for(auto& p : mStochasticOutputList) {
223  ok=p->closeComponent(s,system,hasSucceeded) && ok;
224  }
225  return ok;
226  }
227 
231  inline tBoolean close(const SM_Beam& beam) {
232  tBoolean ok=true;
233  for(auto& p : mStochasticOutputList) {
234  ok=p->closeComponent(beam) && ok;
235  }
236  //set the packed raw values
237  auto iP=mStochasticOutputList.begin();
238  if (iP!=mStochasticOutputList.end()) {
239  getPackedRawValues()=(*iP)->getPackedRawValues();
240  getPackedRawValuesNumber()=(*iP)->getPackedRawValuesNumber();
241  }
242  return ok;
243  }
251  virtual void closePackedSimulations(const SM_Beam& beam,
252  const tIndex& rawValuesNumber,
253  const std::valarray<tReal>& rawValues) override {
254 
255  auto iP=mStochasticOutputList.begin();
256  if (iP!=mStochasticOutputList.end()) {
257  (*iP)->closePackedSimulations(beam,rawValuesNumber,rawValues);
258  }
259  }
260 
261 
262 
263 public:
264 
265 
266 public:
267  // OTHERS methods
268 
272  virtual tString toString() const override {
273  tString routineName="SM_StochasticOutputList::toString()";
274  CORE_Profiler::StartCallRoutine(routineName);
275  std::stringstream ret;
276  ret<<SM_StochasticOutput<SM_StochasticOutputList>::toString()<<"\n";
277  for(auto& p : mStochasticOutputList) {
278  ret<<"\t"<<p->toString()<<"\n";
279  }
280  CORE_Profiler::EndCallRoutine(routineName);
281  return ret.str();
282  }
283 
284 
285 
286 };
287 
288 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
static void EndCallRoutine(const tString &routineName)
end calling routine
Definition: CORE_Profiler.h:91
static void StartCallRoutine(const tString &routineName)
start calling routine
Definition: CORE_Profiler.h:61
This class defines a general stochastic beam of trajectories of system.
Definition: SM_Beam.h:61
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
This class stores stochastic outpus computed for each trajectory of a simulation of trajectories of a...
Definition: SM_StochasticOutputComponent.h:36
std::valarray< tReal > & getPackedRawValues()
get the packed raw values
Definition: SM_StochasticOutputComponent.h:301
const tIndex & getPackedRawValuesNumber() const
get the packed raw values number
Definition: SM_StochasticOutputComponent.h:286
virtual void setOutputPath(const tString &path)
set the output path
Definition: SM_StochasticOutputComponent.h:172
virtual void setIndex(const int &index, const int &rootIndex, const int &n)
set index of the output component
Definition: SM_StochasticOutputComponent.h:199
virtual void setPrefix(const tString &prefix)
set the prefix of generated files
Definition: SM_StochasticOutputComponent.h:184
This class stores stochastic data list* For parallel only the firs stocchastic values of first output...
Definition: SM_StochasticOutputList.h:19
const std::vector< CORE_UniquePointer< SM_StochasticOutputComponent > > & getStochasticOutputList() const
get the stochastic data list
Definition: SM_StochasticOutputList.h:120
void add(CORE_UniquePointer< SM_StochasticOutputComponent > data)
add a stochastic data
Definition: SM_StochasticOutputList.h:131
virtual void closePackedSimulations(const SM_Beam &beam, const tIndex &rawValuesNumber, const std::valarray< tReal > &rawValues) override
close the raws values for packed simulations
Definition: SM_StochasticOutputList.h:251
tBoolean close(const tIndex &s, const SM_System &system, const tBoolean &hasSucceeded)
close the stochastic data for the simulation s
Definition: SM_StochasticOutputList.h:220
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticOutputList.h:87
tBoolean open(const SM_Beam &beam)
open the stochastic data
Definition: SM_StochasticOutputList.h:182
tBoolean open(const tIndex &s, const SM_System &system)
open the stochastic data for simulation s
Definition: SM_StochasticOutputList.h:194
tBoolean store(const SM_System &system)
store the stochastic data during the relation method of the system
Definition: SM_StochasticOutputList.h:207
SM_StochasticOutputList(void)
create
Definition: SM_StochasticOutputList.h:45
virtual tString toString() const override
return the string representation of the class
Definition: SM_StochasticOutputList.h:272
std::vector< CORE_UniquePointer< SM_StochasticOutputComponent > > & getStochasticOutputList()
get the stochastic data list
Definition: SM_StochasticOutputList.h:125
virtual void setOutputPath(const tString &path) override
set the output path
Definition: SM_StochasticOutputList.h:146
virtual void setPrefix(const tString &prefix) override
set the prefix of generated files
Definition: SM_StochasticOutputList.h:154
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_StochasticOutputList.h:75
tBoolean close(const SM_Beam &beam)
close stochastic data at the end of all simulations
Definition: SM_StochasticOutputList.h:231
tIndex getSize() const
return the data list size
Definition: SM_StochasticOutputList.h:114
virtual ~SM_StochasticOutputList(void)
destroy
Definition: SM_StochasticOutputList.h:54
const SM_StochasticOutputComponent * get(const tIndex &i)
get a stochastic data
Definition: SM_StochasticOutputList.h:138
virtual void adimensionize(const SM_Material &material) override
adimensionize the output compoent with material characteristic
Definition: SM_StochasticOutputList.h:162
static CORE_UniquePointer< SelfClass > New()
build a new instance of a stochastic data
Definition: SM_StochasticOutputList.h:98
void clear()
clear the data list
Definition: SM_StochasticOutputList.h:107
virtual void setIndex(const int &index, const int &rootIndex, const int &n) final
set index of the output component
Definition: SM_StochasticOutputList.h:170
this class implements the virtual methods of its base class SM_StochasticOutputComponent with templat...
Definition: SM_StochasticOutput.h:24
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticOutput.h:84
This class is a one simulation of a beam for Stoch Magnet package.
Definition: SM_System.h:53