C++ mpi module for stochmagnet_main Package
SM_BeamRandomJRange.h
1 #ifndef SM_BeamRandomJRange_H
2 #define SM_BeamRandomJRange_H
3 
4 //inherits header
5 #include "SM_BeamCycle.h"
6 
7 
14 class SM_BeamRandomJRange: public SM_BeamCycle<SM_BeamRandomJRange> {
15 
16  //attributes
17 private :
18 
19  //class type
22 
23  //range [eps0,eps1,deps]
24  std::array<tReal,3> mRandomJRange;
25 
26  tString mJFileName;//J file
27  tIndex mBeamSize;
28 
29 public:
30  // CONSTRUCTORS
34 
35  }
36 
37  // DESTRUCTORS
40  virtual ~SM_BeamRandomJRange(void) {
41  }
42 
43 
44 
45 public :
46  // CREATE class
47 
48 
49  //SET & GET methods
50 
51 
52 
53 
54  //MEMORY
55 
69  virtual tMemSize getMemorySize() const {
70  return sizeof(*this)+getContentsMemorySize();
71  }
80  virtual tMemSize getContentsMemorySize() const {
81  tMemSize mem=SuperClass::getContentsMemorySize();
82  mem+=3*SM_Constants::DIM*sizeof(tReal);//mRandomJRange
83  mem+=mJFileName.length()*sizeof(tChar);
84  return mem;
85  }
86 
87  //New method
91  static CORE_UniquePointer<SelfClass> New() {
92  return CORE_UniquePointer<SelfClass>(new SelfClass(),
94 
95  }
96 
97 public:
98 
99 public:
100 
104  inline void setStochasticRange(const std::array<tReal,3>& range) {
105  const tReal *iRange=range.data();
106  for(auto& Tk:mRandomJRange) {
107  Tk=(*iRange);
108  iRange++;
109  }
110 
111  }
112 
113 
117  inline void setJFileName(const tString& Jfile) {
118  mJFileName=Jfile;
119 
120  }
121 
122 public:
123 
124 
131  inline tBoolean open(SM_Beam& beam,SM_StochasticOutputComponent& stochasticOutput,
132  const tInteger& outputId,tIndex& iCycleStep) {
133  iCycleStep=0;
134 
135  //system
136  SM_System& system=beam.getSystem();
137 
138 
139  //set the temperature of the system
140  system.setStochasticNoise(mRandomJRange[0]);
141 
142  //open file
143  if (outputId==0) {
144  std::ofstream file(mJFileName.c_str(),std::ios::out);
145  if (!file) {
146  std::cout<<"impossible to open J Range file "<<mJFileName<<"\n";
147  return false;
148  }
149 
150 
151  //print header in temperature file
152  printHeader(file,beam,stochasticOutput.getOutputDescription());
153 
154  //close the file
155  file.close();
156  }
157 
158  if (mRandomJRange[0]==0) {
159  //store beam size
160  mBeamSize=beam.getBeamSize();
161  //only one simulation is needed
162  beam.setBeamSize(1);
163  }
164 
165  return true;
166  }
173  inline void nextCycleStep(const tIndex& iCycleStep,SM_Beam& beam,const tInteger& outputId,const SM_StochasticOutputComponent& output) {
174 
175  //system
176  SM_System& system=beam.getSystem();
177 
178  //S
179  //const SM_RealField& S=system.getMagneticMomentDirections();
180 
181 
182  //save the data
183  if (outputId==0) {
184  std::ofstream file(mJFileName.c_str(),std::ios::app);
185  const std::valarray<tReal>& outputs=output.getOutputValues();
186  for(const auto& r:outputs) {
187  file<<r<<"\t";
188  }
189  file<<"\n";
190  file.close();
191 
192  }
193 
194  //set the next epsilon
195  tReal eps=beam.getSystem().getStochasticNoise();
196  if (eps==0) {
197  //restore beam size
198  beam.setBeamSize(mBeamSize);
199  }
200 
201  eps+=mRandomJRange[2];
202 
203  system.setStochasticNoise(eps);
204 
205 
206  }
207 
212  inline tBoolean isCycleFinished(const tIndex& iCycle,const SM_Beam& beam) {
213  return (beam.getSystem().getStochasticNoise()>=mRandomJRange[1]);
214  }
220  inline tBoolean close(const tIndex& iCycle,const SM_Beam& beam) {
221  return true;
222  }
223 
226  virtual tString toString() const override {
227  std::stringstream ret;
228  ret<<SuperClass::toString()<<"\n";
229  ret<<"\t Cycle temperature range:"<<functions_array::toString(mRandomJRange)<<"\n";
230  return ret.str();
231  }
232 private:
238  inline void printHeader(std::ofstream& file,const SM_Beam& beam,const std::vector<tString>& outputDescription) const {
239 
240  file<<"# J stochastic Range cycle Beam generated by soft:"<<CORE_Run::GetSoftName()<<" Version:"<<CORE_Run::GetVersion()<<"\n";
241  tString str="J stochastic Range :"+this->toString();
242  functions_string::replaceAll("\n","\n#",str);
243  file<<"#"<<str<<"\n";
244 
245  str="beam:"+beam.toString();
246  functions_string::replaceAll("\n","\n#",str);
247  file<<"#"<<str<<"\n";
248 
249  file<<"#";
250  for(const auto& d:outputDescription) file<<"\t"<<d;
251  file<<"\n";
252  }
253 
254 
255 
256 };
257 
258 
259 #endif
class Free introduced for deleting a smart pointer
Definition: CORE_Object.h:113
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
static const tString & GetSoftName()
get soft name
Definition: CORE_Run.h:115
static const tString & GetVersion()
get the version
Definition: CORE_Run.h:129
This class is an interface of Beam Cycle class for Stoch Microm package.
Definition: SM_BeamCycle.h:20
virtual tString toString() const override
return the string representation of the class
Definition: SM_BeamCycle.h:193
This class is an temperature cycle manager for running a cycle of beam class for Stoch Microm package...
Definition: SM_BeamRandomJRange.h:14
void setStochasticRange(const std::array< tReal, 3 > &range)
set the temperature range
Definition: SM_BeamRandomJRange.h:104
void nextCycleStep(const tIndex &iCycleStep, SM_Beam &beam, const tInteger &outputId, const SM_StochasticOutputComponent &output)
next the cycle of beam run
Definition: SM_BeamRandomJRange.h:173
virtual ~SM_BeamRandomJRange(void)
destroy
Definition: SM_BeamRandomJRange.h:40
tBoolean close(const tIndex &iCycle, const SM_Beam &beam)
return true if the cycle is close without error
Definition: SM_BeamRandomJRange.h:220
SM_BeamRandomJRange(void)
create
Definition: SM_BeamRandomJRange.h:33
void setJFileName(const tString &Jfile)
set the J file
Definition: SM_BeamRandomJRange.h:117
virtual tString toString() const override
return the string representation of the class
Definition: SM_BeamRandomJRange.h:226
tBoolean isCycleFinished(const tIndex &iCycle, const SM_Beam &beam)
return true if the cycle is finished
Definition: SM_BeamRandomJRange.h:212
static CORE_UniquePointer< SelfClass > New()
create an unique pointer to a new instance of this
Definition: SM_BeamRandomJRange.h:91
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_BeamRandomJRange.h:69
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_BeamRandomJRange.h:80
tBoolean open(SM_Beam &beam, SM_StochasticOutputComponent &stochasticOutput, const tInteger &outputId, tIndex &iCycleStep)
init the cycle of beam run
Definition: SM_BeamRandomJRange.h:131
This class defines a general stochastic beam of trajectories of system.
Definition: SM_Beam.h:61
const SM_System & getSystem() const
get the system
Definition: SM_Beam.h:264
virtual tString toString() const override
turn the class into a string representation
Definition: SM_Beam.h:315
const tIndex & getBeamSize() const
get the beam size
Definition: SM_Beam.h:166
void setBeamSize(const tIndex &n)
set the beam size
Definition: SM_Beam.h:149
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
This class stores stochastic outpus computed for each trajectory of a simulation of trajectories of a...
Definition: SM_StochasticOutputComponent.h:36
const std::vector< tString > & getOutputDescription() const
get the string representation of the output values
Definition: SM_StochasticOutputComponent.h:316
const std::valarray< tReal > & getOutputValues() const
get the output values of the stochastic output for reading
Definition: SM_StochasticOutputComponent.h:330
This class is a one simulation of a beam for Stoch Magnet package.
Definition: SM_System.h:53
virtual void setStochasticNoise(const tReal &eps)
set the stochastic noise without dimension
Definition: SM_System.h:379
const tReal & getStochasticNoise() const
get the stochastic noise without dimension
Definition: SM_System.h:385