C++ mpi module for stochmagnet_main Package
SM_BeamTemperatureRange.h
1 #ifndef SM_BeamTemperatureRange_H
2 #define SM_BeamTemperatureRange_H
3 
4 //inherits header
5 #include "SM_BeamCycle.h"
6 
7 
14 class SM_BeamTemperatureRange: public SM_BeamCycle<SM_BeamTemperatureRange> {
15 
16  //attributes
17 private :
18 
19  //class type
22 
23  std::array<tReal,3> mTemperatureRange;
24  tString mKFileName;//temperature file
25  tIndex mBeamSize;
26 
27 public:
28  // CONSTRUCTORS
32 
33  }
34 
35  // DESTRUCTORS
38  virtual ~SM_BeamTemperatureRange(void) {
39  }
40 
41 
42 
43 public :
44  // CREATE class
45 
46 
47  //SET & GET methods
48 
49 
50 
51 
52  //MEMORY
53 
67  virtual tMemSize getMemorySize() const {
68  return sizeof(*this)+getContentsMemorySize();
69  }
78  virtual tMemSize getContentsMemorySize() const {
79  tMemSize mem=SuperClass::getContentsMemorySize();
80  mem+=3*SM_Constants::DIM*sizeof(tReal);//mTemperatureRange
81  mem+=mKFileName.length()*sizeof(tChar);
82  return mem;
83  }
84 
85  //New method
89  static CORE_UniquePointer<SelfClass> New() {
90  return CORE_UniquePointer<SelfClass>(new SelfClass(),
92 
93  }
94 
95 public:
96 
97 public:
98 
102  inline void setTemperatureRange(const std::array<tReal,3>& range) {
103  const tReal *iRange=range.data();
104  for(auto& Tk:mTemperatureRange) {
105  Tk=(*iRange);
106  iRange++;
107  }
108 
109  }
110 
111 
115  inline void setTemperaturesFileName(const tString& Kfile) {
116  mKFileName=Kfile;
117 
118  }
119 
120 public:
121 
122 
129  inline tBoolean open(SM_Beam& beam,SM_StochasticOutputComponent& stochasticOutput,
130  const tInteger& outputId,tIndex& iCycleStep) {
131  iCycleStep=0;
132 
133  //system
134  SM_System& system=beam.getSystem();
135 
136 
137  //set the temperature of the system
138  system.setNoiseTemperature(mTemperatureRange[0]);
139 
140  //open temperatures file
141  if (outputId==0) {
142  std::ofstream file(mKFileName.c_str(),std::ios::out);
143  if (!file) {
144  std::cout<<"impossible to open Temperature Range file "<<mKFileName<<"\n";
145  return false;
146  }
147 
148 
149  //print header in temperature file
150  printHeader(file,beam,stochasticOutput.getOutputDescription());
151 
152  //close the file
153  file.close();
154  }
155 
156  if (mTemperatureRange[0]==0) {
157  //store beam size
158  mBeamSize=beam.getBeamSize();
159  //only one simulation is needed
160  beam.setBeamSize(1);
161  }
162 
163  return true;
164  }
171  inline void nextCycleStep(const tIndex& iCycleStep,SM_Beam& beam,
172  const tInteger& outputId,const SM_StochasticOutputComponent& output) {
173 
174  //system
175  SM_System& system=beam.getSystem();
176 
177  //S
178  const SM_RealField& S=system.getMagneticMomentDirections();
179 
180 
181  //save the data
182  if (outputId==0) {
183  std::ofstream file(mKFileName.c_str(),std::ios::app);
184  const std::valarray<tReal>& outputs=output.getOutputValues();
185  for(const auto& r:outputs) {
186  file<<std::setprecision(12)<<r<<"\t";
187  }
188  file<<"\n";
189  file.close();
190 
191  }
192 
193  //set the next temperature
194  tReal T=beam.getSystem().getNoiseTemperature();
195  if (T==0) {
196  //restore beam size
197  beam.setBeamSize(mBeamSize);
198  }
199 
200  T+=mTemperatureRange[2];
201 
202  system.setNoiseTemperature(T);
203 
204 
205  //set the next initial direction to last magnetic moment direction computed
207 
208  }
209 
214  inline tBoolean isCycleFinished(const tIndex& iCycle,const SM_Beam& beam) {
215  return (beam.getSystem().getNoiseTemperature()>=mTemperatureRange[1]);
216  }
222  inline tBoolean close(const tIndex& iCycle,const SM_Beam& beam) {
223  return true;
224  }
225 
228  virtual tString toString() const override {
229  std::stringstream ret;
230  ret<<SuperClass::toString()<<"\n";
231  ret<<"\t Cycle temperature range:"<<functions_array::toString(mTemperatureRange)<<"\n";
232  return ret.str();
233  }
234 private:
237  inline void printHeader(std::ofstream& file,const SM_Beam& beam,const std::vector<tString>& outputDescription) const {
238 
239  file<<"# Temperature Range cycle Beam generated by soft:"<<CORE_Run::GetSoftName()<<" Version:"<<CORE_Run::GetVersion()<<"\n";
240  tString str="Temperature Range :"+this->toString();
241  functions_string::replaceAll("\n","\n#",str);
242  file<<"#"<<str<<"\n";
243 
244  str="beam:"+beam.toString();
245  functions_string::replaceAll("\n","\n#",str);
246  file<<"#"<<str<<"\n";
247 
248  file<<"#";
249  for(const auto& d:outputDescription) file<<"\t"<<d;
250  file<<"\n";
251  }
252 
253 
254 
255 };
256 
257 
258 #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_BeamTemperatureRange.h:14
tBoolean open(SM_Beam &beam, SM_StochasticOutputComponent &stochasticOutput, const tInteger &outputId, tIndex &iCycleStep)
init the cycle of beam run
Definition: SM_BeamTemperatureRange.h:129
static CORE_UniquePointer< SelfClass > New()
create an unique pointer to a new instance of this
Definition: SM_BeamTemperatureRange.h:89
void setTemperatureRange(const std::array< tReal, 3 > &range)
set the temperature range
Definition: SM_BeamTemperatureRange.h:102
void nextCycleStep(const tIndex &iCycleStep, SM_Beam &beam, const tInteger &outputId, const SM_StochasticOutputComponent &output)
next the cycle of beam run
Definition: SM_BeamTemperatureRange.h:171
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_BeamTemperatureRange.h:67
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_BeamTemperatureRange.h:78
virtual ~SM_BeamTemperatureRange(void)
destroy
Definition: SM_BeamTemperatureRange.h:38
virtual tString toString() const override
return the string representation of the class
Definition: SM_BeamTemperatureRange.h:228
SM_BeamTemperatureRange(void)
create
Definition: SM_BeamTemperatureRange.h:31
void setTemperaturesFileName(const tString &Kfile)
set the temperatures file
Definition: SM_BeamTemperatureRange.h:115
tBoolean isCycleFinished(const tIndex &iCycle, const SM_Beam &beam)
return true if the cycle is finished
Definition: SM_BeamTemperatureRange.h:214
tBoolean close(const tIndex &iCycle, const SM_Beam &beam)
return true if the cycle is close without error
Definition: SM_BeamTemperatureRange.h:222
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
const SM_RealField & getMagneticMomentDirections() const
get the unit direction of spins at time
Definition: SM_System.h:267
const tReal & getNoiseTemperature() const
get the noise temperature in Kelvin
Definition: SM_System.h:399
virtual void setNoiseTemperature(const tReal &T)
set the noise as a temperature in Kelvin
Definition: SM_System.h:392
virtual tBoolean updateInitialMagneticMomentDirections(const SM_RealField &S0)
update the initial unit direction of spins
Definition: SM_System.h:241