C++ mpi module for stochmagnet_main Package
SM_BeamTimeStepRange.h
1 #ifndef SM_BeamTimeStepRange_H
2 #define SM_BeamTimeStepRange_H
3 
4 //inherits header
5 #include "SM_BeamCycle.h"
6 
7 //LL system header
8 #include "SM_LandauLifschitzSystem.h"
9 
16 class SM_BeamTimeStepRange: public SM_BeamCycle<SM_BeamTimeStepRange> {
17 
18  //attributes
19 private :
20 
21  //class type
24 
25  std::array<tReal,3> mTimeStepLogRange;//log of time
26  tString mDtFileName;//time steps file
27  tReal mRelaxedTime;//adimensionized relaxed time
28  tReal mTargetTime;//adimensionized target time
29 
30 public:
31  // CONSTRUCTORS
35 
36  }
37 
38  // DESTRUCTORS
41  virtual ~SM_BeamTimeStepRange(void) {
42  }
43 
44 
45 
46 public :
47  // CREATE class
48 
49 
50  //SET & GET methods
51 
52 
53 
54 
55  //MEMORY
56 
70  virtual tMemSize getMemorySize() const {
71  return sizeof(*this)+getContentsMemorySize();
72  }
81  virtual tMemSize getContentsMemorySize() const {
82  tMemSize mem=SuperClass::getContentsMemorySize();
83  mem+=mTimeStepLogRange.size()*sizeof(tReal);//mTimeStepRange
84  mem+=mDtFileName.length()*sizeof(tChar);
85  return mem;
86  }
87 
88  //New method
92  static CORE_UniquePointer<SelfClass> New() {
93  return CORE_UniquePointer<SelfClass>(new SelfClass(),
95 
96  }
97 
98 public:
99 
100 public:
101 
105  inline void setTimeStepRange(const std::array<tReal,3>& range) {
106  const tReal *iRange=range.data();
107  for(auto& Tk:mTimeStepLogRange) {
108  Tk=(*iRange);
109  iRange++;
110  }
111 
112  }
113 
114 
118  inline void setTimeStepsFileName(const tString& dtfile) {
119  mDtFileName=dtfile;
120 
121  }
122 
123 public:
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  //characteristic time step in s
139  const tReal& tc=system.getMaterial().getCharacteristicTime();
140 
141 
142  SM_LandauLifschitzSystem *llSystem=dynamic_cast<SM_LandauLifschitzSystem *>(&system);
143  if (llSystem==null) return false;
144 
145 
146 
147  //get the number of steps
148  const tIndex& nPS=beam.getPreconditioningStepsNumber();
149  const tIndex& nLS=beam.getStepsNumber();
150 
151  //set the adimensionized time step
152  const tReal& ldt=mTimeStepLogRange[0];//log(dt) in ps
153  tReal dt=pow(10,ldt-12)/tc;//dt=10^{log(dt)-12) is s
154  llSystem->getTimeStepper().setTimeStep(dt);
155 
156  //adimensionized relaxed time
157  mRelaxedTime=nPS*dt;
158 
159  //adimensionized target time
160  mTargetTime=nLS*dt;
161 
162 
163  //open time steps file
164  if (outputId==0) {
165  std::ofstream file(mDtFileName.c_str(),std::ios::out);
166  if (!file) {
167  std::cout<<"impossible to open TimeStep Range file "<<mDtFileName<<"\n";
168  return false;
169  }
170 
171  //print header in temperature file
172  printHeader(file,beam,stochasticOutput.getOutputDescription());
173 
174  //close the file
175  file.close();
176  }
177 
178 
179 
180  return true;
181  }
188  inline void nextCycleStep(const tIndex& iCycleStep,SM_Beam& beam,const tInteger& outputId,const SM_StochasticOutputComponent& output) {
189 
190 
191 
192  //system
193  SM_System& system=beam.getSystem();
194 
195  //LL -system
196  SM_LandauLifschitzSystem *llSystem=dynamic_cast<SM_LandauLifschitzSystem *>(&system);
197  if (llSystem==null) return;
198 
199  //get the current adimensionized time step
200  tReal dt=llSystem->getTimeStepper().getTimeStep();
201 
202  //caracteristic time in s
203  const tReal& tc=system.getMaterial().getCharacteristicTime();
204 
205  //save the data
206  if (outputId==0) {
207  std::ofstream file(mDtFileName.c_str(),std::ios::app);
208  //time step in s
209  file<<(dt*tc)<<"\t";
210  //precondition time steps
211  file<<beam.getPreconditioningStepsNumber()<<"\t";
212  //time steps
213  file<<beam.getStepsNumber()<<"\t";
214  const std::valarray<tReal> &outputs=output.getOutputValues();
215  //print the output values
216  for(const auto& r:outputs) {
217  file<<r<<"\t";
218  }
219  file<<"\n";
220  file.close();
221 
222  }
223  //log of dt is ps at next cycle
224  tReal ldt=mTimeStepLogRange[0]+mTimeStepLogRange[2]*(iCycleStep+1);//log(dt) in ps
225  //next timme step
226  dt=pow(10,ldt-12)/tc;//dt=10^{log(dt)-12) is s
227  llSystem->getTimeStepper().setTimeStep(dt);
228 
229 
230  //set the next steps in order to keep target & relaxed tilme unchanged
231  beam.setPreconditioningStepsNumber(mRelaxedTime/dt);
232  beam.setStepsNumber(mTargetTime/dt);
233 
234 
235  }
236 
241  inline tBoolean isCycleFinished(const tIndex& iCycleStep,const SM_Beam& beam) {
242  const SM_LandauLifschitzSystem *llSystem=dynamic_cast<const SM_LandauLifschitzSystem *>(&(beam.getSystem()));
243  if (llSystem==null) return true;
244  tReal ldt=mTimeStepLogRange[0]+mTimeStepLogRange[2]*iCycleStep;//log(dt) in ps
245  return (ldt>=mTimeStepLogRange[1]);
246  }
252  inline tBoolean close(const tIndex& iCycle,const SM_Beam& beam) {
253  return true;
254  }
255 
258  virtual tString toString() const override {
259  std::stringstream ret;
260  ret<<SuperClass::toString()<<"\n";
261  ret<<"\t Cycle time step range:"<<functions_array::toString(mTimeStepLogRange)<<"\n";
262  return ret.str();
263  }
264 private:
267  inline void printHeader(std::ofstream& file,const SM_Beam& beam,const std::vector<tString>& outputDescription) const {
268 
269  file<<"# TimeStep Range cycle Beam generated by soft:"<<CORE_Run::GetSoftName()<<" Version:"<<CORE_Run::GetVersion()<<"\n";
270  tString str="Log of Time Step in ps Range :"+this->toString();
271  functions_string::replaceAll("\n","\n#",str);
272  file<<"#"<<str<<"\n";
273 
274  str="beam:"+beam.toString();
275  functions_string::replaceAll("\n","\n#",str);
276  file<<"#"<<str<<"\n";
277 
278  file<<"#<dt in s> <number of preconditioning steps> <number of statistic steps>";
279  for(const auto& d:outputDescription) file<<"\t"<<d;
280  file<<"\n";
281  }
282 
283 
284 
285 };
286 
287 
288 #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 a time step cycle manager for running a cycle of beam class for Stoch Microm package.
Definition: SM_BeamTimeStepRange.h:16
SM_BeamTimeStepRange(void)
create
Definition: SM_BeamTimeStepRange.h:34
virtual ~SM_BeamTimeStepRange(void)
destroy
Definition: SM_BeamTimeStepRange.h:41
tBoolean close(const tIndex &iCycle, const SM_Beam &beam)
return true if the cycle is close without error
Definition: SM_BeamTimeStepRange.h:252
tBoolean isCycleFinished(const tIndex &iCycleStep, const SM_Beam &beam)
return true if the cycle is finished
Definition: SM_BeamTimeStepRange.h:241
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_BeamTimeStepRange.h:70
tBoolean open(SM_Beam &beam, SM_StochasticOutputComponent &stochasticOutput, const tInteger &outputId, tIndex &iCycleStep)
init the cycle of beam run
Definition: SM_BeamTimeStepRange.h:131
void setTimeStepRange(const std::array< tReal, 3 > &range)
set the time step range
Definition: SM_BeamTimeStepRange.h:105
void nextCycleStep(const tIndex &iCycleStep, SM_Beam &beam, const tInteger &outputId, const SM_StochasticOutputComponent &output)
next the cycle of beam run
Definition: SM_BeamTimeStepRange.h:188
virtual tString toString() const override
return the string representation of the class
Definition: SM_BeamTimeStepRange.h:258
void setTimeStepsFileName(const tString &dtfile)
set the temperatures file
Definition: SM_BeamTimeStepRange.h:118
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_BeamTimeStepRange.h:81
static CORE_UniquePointer< SelfClass > New()
create an unique pointer to a new instance of this
Definition: SM_BeamTimeStepRange.h:92
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
void setPreconditioningStepsNumber(const tIndex &n)
set the number of steps of preconditioning
Definition: SM_Beam.h:187
void setStepsNumber(const tIndex &n)
set the number of steps for loop
Definition: SM_Beam.h:201
const tIndex & getStepsNumber() const
get the number of steps for stochastic computation
Definition: SM_Beam.h:207
const tIndex & getPreconditioningStepsNumber() const
get the number of steps for precoditioning
Definition: SM_Beam.h:194
This class is a simulation of one trajectory class for Stoch Magnet package.
Definition: SM_LandauLifschitzSystem.h:59
const SM_TimeStepper & getTimeStepper() const
get the time stepper
Definition: SM_LandauLifschitzSystem.h:200
const tReal & getCharacteristicTime() const
get the characteristic time in s
Definition: SM_Material.h:355
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_Material & getMaterial() const
get the material of the network
Definition: SM_System.h:193
const tReal & getTimeStep() const
return the time step
Definition: SM_TimeStepper.h:108
void setTimeStep(const tReal &dt)
set the time step
Definition: SM_TimeStepper.h:99