C++ mpi module for stochmagnet_main Package
SM_StochasticHysteresis.h
1 #ifndef SM_StochasticHysteresis_H
2 #define SM_StochasticHysteresis_H
3 
4 //inherited class header
5 #include "SM_StochasticOutput.h"
6 
7 //beam class header
8 #include "SM_LandauLifschitzBeam.h"
9 
10 //suystem class header
11 #include "SM_System.h"
12 
13 //runner header
14 #include "CORE_Run.h"
15 
16 //string utility header
17 #include "core_string.h"
18 #include "core_numeric.h"
19 
20 
21 
30 class SM_StochasticHysteresis : public SM_StochasticOutput<SM_StochasticHysteresis> {
31 
32  // ATTRIBUTES
33 
34 public:
35 
36 
37 
38 private:
39 
40  //class types definition
43 
44  std::array<tReal,SM_Constants::DIM> mD;//direction of computing
45  std::array<tReal,SM_Constants::DIM> mEpS;//mean over the particles of S
46 
47 public:
48  // METHODS
49 
50  // CONSTRUCTORS
51 
55 
57  "<E_{s}(E_p(<S(s,p),D>))",
58  "<samples number>",
59  "<number of simulations>",
60  });
61 
62  std::valarray<tReal>& outputs=getOutputValues();
63  outputs.resize(3);
64 
65  memset(&outputs[0],0,outputs.size()*sizeof(tReal));
66 
67  }
68 
69 
70 
71  // DESTRUCTORS
72 public:
73 
76  virtual ~SM_StochasticHysteresis(void) {
77  tString routineName="SM_StochasticHysteresis::~SM_StochasticHysteresis()";
79  CORE_Profiler::EndCallRoutine(routineName);
80  }
81 
82 
83 
84 public:
85  //MEMORY
86 
100  virtual tMemSize getMemorySize() const {
101  return sizeof(*this)+getContentsMemorySize();
102  }
103 
112  virtual tMemSize getContentsMemorySize() const {
113  tMemSize mem=SuperClass::getContentsMemorySize();
114  mem+=mEpS.size()*sizeof(tReal);
115  mem+=mD.size()*sizeof(tReal);
116  return mem;
117  }
118 
122  inline static CORE_UniquePointer<Self> New() {
123  return CORE_UniquePointer<Self>(new Self(),
125  }
129  inline static CORE_UniquePointer<Self> New(const Self& c) {
130  CORE_UniquePointer<Self> p=New();
131  p->copy(c);
132  return p;
133  }
134 
135  //SET & GET Methods
136  //=================
140  virtual void copy(const SM_StochasticOutputComponent& c) override {
141  SuperClass::copy(c);
142  }
143 
144 
148  virtual void adimensionize(const SM_Material& material) override {
149  }
150 
151 
155  inline void setHysteresisDirection(const std::array<tReal,SM_Constants::DIM>& D) {
156  mD=D;
157  }
158 
162  inline const std::array<tReal,SM_Constants::DIM>& getHysteresisDirection() const {
163  return mD;
164  }
165 
166 
167 
168 
169 
170 
171  //implemented templated methods
172  //=============================
173 
183  inline tBoolean open(const SM_Beam& beam) {
184 
185  if (getIndex()==0) {
186  //number of raws values number is null
187  tIndex &nRaws=getPackedRawValuesNumber();
188  nRaws=0;
189 
190  //set the size of the distribution
191  std::valarray<tReal>& rawValues=getPackedRawValues();
192  //rawValues[0]=sum_s <E_p(S),D>
193  //rawValues[1]=s
194  rawValues.resize(2);
195  //initialize to 0
196  memset(&rawValues[0],0,rawValues.size()*sizeof(tReal));
197  }
198 
199  return true;
200  }
201 
202 
203 
204 
210  inline tBoolean open(const tIndex& s,const SM_System& system) {
211  tBoolean ok=true;
212  return ok;
213  }
214 
220  inline tBoolean store(const SM_System& system) {
221 
222 
223  return true;
224  }
225 
226 
227 
237  inline tBoolean close(const tIndex& s,const SM_System& system,const tBoolean& hasSucceeded) {
238  tBoolean ok=true;
239 
240  //std::cout<<"begin SM_SHysteresis::close("<<s<<","<<getIndex()<<")\n";
241  if (hasSucceeded) {
242  if ((getIndex()==0) || (getRootIndex()==-1)) {
243 
244  //mEps=1/P \sum_R \sum_{p \in R} S(P) : sum over the networks P=\sum card{R}
246 
247  if (getIndex()==0) {
248  //compute <E_p(S,s,p),D> mean of S projected on D
249  tReal sED=0;
250  const tReal *iEpS=mEpS.data();
251  for (const auto& Dk:mD) {
252  sED+=Dk*(*iEpS);
253  iEpS++;
254  }
255  getPackedRawValues()[0]+=sED;
257  }
258  }
259  }
260 
261  //std::cout<<"SM_SHysteresis::close("<<s<<","<<getIndex()<<") hysValue="<<getPackedRawValues()[0]<<"\n";
262  return ok;
263  }
264 
272  inline tBoolean close(const SM_Beam& beam) {
273  //std::cout<<"begin SM_SHysteresis::close("<<getIndex()<<")\n";
274  if (getIndex()==0) {
275  //get the esperance to compute
276  std::valarray<tReal> &rawValues=getPackedRawValues();
277  tIndex& rawValuesNumber=getPackedRawValuesNumber();
278 
279  //number of simulation of the beam
280  rawValues[1]=beam.getBeamSize();
281 
282  //set the output of the stochatic data if mono core beam case
283  if (getPackedSimulationsNumber()==1) {
284  updateOutputs(rawValuesNumber,rawValues,getOutputValues());
285  }
286  }
287  //std::cout<<"end SM_SHysteresis::close("<<getIndex()<<")\n";
288  return true;
289 
290  }
291 
292 
302  virtual void closePackedSimulations(const SM_Beam& beam,
303  const tIndex& rawValuesNumber,
304  const std::valarray<tReal>& rawValues) override {
305  if (getIndex()==0) {
306  //std::cout<<"begin SM_SHysteresis::closePackedSimulations("<<getIndex()<<")\n";
307  updateOutputs(rawValuesNumber,rawValues,getOutputValues());
308  //std::cout<<"end SM_SHysteresis::closePackedSimulations("<<getIndex()<<")\n";
309  }
310  }
311 
314  virtual tString toString() const override {
315  std::stringstream ret;
316  ret<<SuperClass::toString();
317  return ret.str();
318  }
319 
320 
321 private:
322 
323  inline void updateOutputs(const tIndex& rawValuesNumber,
324  const std::valarray<tReal>& rawValues,
325  std::valarray<tReal>& outputs) {
326  if (outputs.size()<3) outputs.resize(3);
327  outputs[0]=rawValues[0]/rawValuesNumber;//E_s(<E_p(S),D>) mean on samples
328  outputs[1]=rawValuesNumber;//total number of samples
329  outputs[2]=rawValues[1];//total number of simlations
330 
331  }
332 
333 };
334 
335 #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
const tIndex & getBeamSize() const
get the beam size
Definition: SM_Beam.h:166
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
This class stores stochastic hysteresis values.
Definition: SM_StochasticHysteresis.h:30
tBoolean close(const tIndex &s, const SM_System &system, const tBoolean &hasSucceeded)
close the stochastic data for the simulation at index s
Definition: SM_StochasticHysteresis.h:237
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_StochasticHysteresis.h:100
virtual void adimensionize(const SM_Material &material) override
adimensionize the output compoent with material characteristic
Definition: SM_StochasticHysteresis.h:148
tBoolean open(const SM_Beam &beam)
open the stochastic data at the begininf of simulations
Definition: SM_StochasticHysteresis.h:183
tBoolean store(const SM_System &system)
store the stochastic data during the evolution method of the system
Definition: SM_StochasticHysteresis.h:220
virtual ~SM_StochasticHysteresis(void)
destroy
Definition: SM_StochasticHysteresis.h:76
const std::array< tReal, SM_Constants::DIM > & getHysteresisDirection() const
get the direction of hysteresis
Definition: SM_StochasticHysteresis.h:162
virtual void copy(const SM_StochasticOutputComponent &c) override
copy the stochastic data
Definition: SM_StochasticHysteresis.h:140
static CORE_UniquePointer< Self > New(const Self &c)
build a new instance of a stochastic data
Definition: SM_StochasticHysteresis.h:129
void setHysteresisDirection(const std::array< tReal, SM_Constants::DIM > &D)
set the direction of hysteresis
Definition: SM_StochasticHysteresis.h:155
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticHysteresis.h:112
SM_StochasticHysteresis(void)
create
Definition: SM_StochasticHysteresis.h:54
static CORE_UniquePointer< Self > New()
build a new instance of a stochastic data
Definition: SM_StochasticHysteresis.h:122
virtual void closePackedSimulations(const SM_Beam &beam, const tIndex &rawValuesNumber, const std::valarray< tReal > &rawValues) override
close stochastic data at the end of all packed simulations
Definition: SM_StochasticHysteresis.h:302
virtual tString toString() const override
return the string representation of the class
Definition: SM_StochasticHysteresis.h:314
tBoolean open(const tIndex &s, const SM_System &system)
open the stochastic data for simulation at index s
Definition: SM_StochasticHysteresis.h:210
tBoolean close(const SM_Beam &beam)
close stochastic data at the end of one packed simulations
Definition: SM_StochasticHysteresis.h:272
This class stores stochastic outpus computed for each trajectory of a simulation of trajectories of a...
Definition: SM_StochasticOutputComponent.h:36
const int & getRootIndex() const
get the root index of the output component
Definition: SM_StochasticOutputComponent.h:222
std::valarray< tReal > & getPackedRawValues()
get the packed raw values
Definition: SM_StochasticOutputComponent.h:301
void setOutputDescription(const std::vector< tString > &v)
et the output description
Definition: SM_StochasticOutputComponent.h:323
virtual tString toString() const override
return the string representation of the class
Definition: SM_StochasticOutputComponent.h:398
const tIndex & getPackedRawValuesNumber() const
get the packed raw values number
Definition: SM_StochasticOutputComponent.h:286
const tInteger & getPackedSimulationsNumber() const
get packed simulations number
Definition: SM_StochasticOutputComponent.h:269
const std::valarray< tReal > & getOutputValues() const
get the output values of the stochastic output for reading
Definition: SM_StochasticOutputComponent.h:330
const int & getIndex() const
get the index of the output component
Definition: SM_StochasticOutputComponent.h:217
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
virtual void copy(const SM_StochasticOutputComponent &c)
copy
Definition: SM_StochasticOutput.h:94
This class is a one simulation of a beam for Stoch Magnet package.
Definition: SM_System.h:53
void computeMagneticMomentDirectionsMeanOverNetworks(const int &rootNetwork, std::array< tReal, SM_Constants::DIM > &meanS) const
compute the mean over the domain of magneticmoment directions
Definition: SM_System.h:477