C++ mpi module for stochmagnet_main Package
SM_Beam.hpp
1 #ifndef SM_Beam_HPP
2 #define SM_Beam_HPP
3 
4 
5 template<class System,class StochOutputImplement>
7  tString routineName="SM_Beam::run<S,O>";
9 
10  tBoolean ok=true;
11 
12  //get the system
13  System& system=*dynamic_cast<System*>(&getSystem());
14 
15  //open the stochastic at the beginning of the simulations running of the beam
16  if (!outputSData.open(*this)) {
17  std::cout<<"stochastic output "<<outputSData.getIdentityString()<<" not compatible with the system \n";
18  return false;
19  }
20 
21  if (!this->hasStochasticFunctions()) {
22  //deterministic case with no stochastic function
23  //----------------------------------------------
24 
25 
26  //St=S0
27  //std::cout<<"initialize magnetic directions ..\n";
28  if (!system.initializeMagneticMomentDirections()) {
29  throw CORE_Exception("stochmagnet/core",
30  "SM_Beam::run(SM_StochasticOutput<StochOutputImplement>& outputSData)",
31  "initialization of S(t=0) failed");
32  }
33 
34  //std::cout<<"->begin run with no stoch function\n";
35  //std::cout<<" open SO \n";
36  //open the stochastic output the simulation 0 of the system
37  outputSData.open(0,system);
38 
39  //running the system from the equilibrium
40  ok= ok && system.deterministicRun(mPreconditioningStepsNumber+mStepsNumber,outputSData);
41 
42  //close the stochastic output the simulation 0 of the system
43  //std::cout<<"close SO ..\n";
44  outputSData.close(0,system,ok);
45  //std::cout<<"->end run with no stoch function \n";
46 
47 
48  } else {
49 
50  tIndex s0,s1;
51  getBeamSize(s0,s1);
52  //casting with stochastic function
54  //std::cout<<"beam size ["<<s0<<","<<s1<<"[\n";
55  for (tIndex s=s0;s<s1;s++) {
56 
57 
58  //St=S0
59  if (!system.initializeMagneticMomentDirections()) {
60  throw CORE_Exception("stochmagnet/core",
61  "SM_Beam::run(SM_StochasticOutput<StochOutputImplement>& outputSData)",
62  "initialization of S(t=0) failed");
63  }
64  //open the stochastic output the simulation 0 of the system
65  outputSData.open(s,system);
66 
67  //running the system until the equilibrium
68  //std::cout<<"preconditionning run \n";
69  ok=system.stochasticRun(mPreconditioningStepsNumber,sf);
70 
71  //running the system during loop steppers number
72  //
73  //std::cout<<"statistic run \n";
74  ok= ok && system.stochasticRun(mStepsNumber,sf,outputSData);
75 
76  //close the outputSData for simulation s at the end of simulations
77  outputSData.close(s,system,ok);
78  }
79 
80 
81  }
82  //close the stochastic output at the end of the runnings of the simulations
83  outputSData.close(*this);
84 
85  CORE_Profiler::EndCallRoutine(routineName);
86 
87  return true;
88 }
89 
90 
91 
92 #endif
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
tString getIdentityString() const
retrun the string identification of the class
Definition: CORE_Object.h:321
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
const SM_System & getSystem() const
get the system
Definition: SM_Beam.h:264
tBoolean run(SM_StochasticOutput< StochOutputImplement > &outputSData)
run the simulations
Definition: SM_Beam.hpp:6
const SM_MultiStochasticFunctionsInterface & getStochasticFunctions() const
get the stochastic functions
Definition: SM_Beam.h:236
tBoolean hasStochasticFunctions() const
return true if the beam has a stochastic function
Definition: SM_Beam.h:230
const tIndex & getBeamSize() const
get the beam size
Definition: SM_Beam.h:166
This class describes a multi stochastic functions based on same random number generator which impleme...
Definition: SM_MultiStochasticFunctionsInterface.h:18
this class implements the virtual methods of its base class SM_StochasticOutputComponent with templat...
Definition: SM_StochasticOutput.h:24
tBoolean close(const tIndex &s, const SM_System &system, const tBoolean &hasSucceeded)
close the stochastic data for the simulation s
Definition: SM_StochasticOutput.h:172
tBoolean open(const SM_Beam &beam)
open the stochastic data
Definition: SM_StochasticOutput.h:147