1 #ifndef SM_StochasticJs_H
2 #define SM_StochasticJs_H
5 #include "SM_StochasticOutput.h"
8 #include "SM_LandauLifschitzBeam.h"
11 #include "SM_System.h"
17 #include "core_string.h"
18 #include "core_numeric.h"
50 tString mCTPackedFileName;
59 std::array<tReal,SM_Constants::DIM> mBarS;
62 tUCInt mStochasticIndex;
65 tUCInt mNSamplesIndex;
73 tString mJFunctionName;
74 std::function<void(
const tReal&,
const tReal& ,
const tReal&,tReal& )> mJFunction;
76 std::ofstream *mJsFile;
92 "<number of simulations>",
107 memset(&outputs[0],0,outputs.size()*
sizeof(tReal));
156 mem+=mCTFileName.length()*
sizeof(tChar);
157 mem+=mCTPackedFileName.length()*
sizeof(tChar);
158 mem+=mBarS.size()*
sizeof(tReal);
160 mem+=mJFunctionName.length()*
sizeof(tChar);
161 mem+=mCTPackedFileName.length()*
sizeof(tChar);
162 mem+=mCTFileName.length()*
sizeof(tChar);
163 mem+=(mJsFile==
null)?0:
sizeof(*mJsFile);
170 inline static CORE_UniquePointer<Self>
New() {
171 return CORE_UniquePointer<Self>(
new Self(),
177 inline static CORE_UniquePointer<Self>
New(
const Self& c) {
178 CORE_UniquePointer<Self> p=
New();
200 mJFunctionName=FName;
204 mJFunction=([](
const tReal& J,
const tReal& eps,
const tReal& normal,tReal& v) {
215 mJFunction=([](
const tReal& J,
const tReal& eps,
const tReal& normal,tReal& v) {
228 mJFunction=([](
const tReal& J,
const tReal& eps,
const tReal& normal,tReal& v) {
234 v=std::max((tReal)0,v);
244 inline const std::function<void(
const tReal&,
const tReal& ,
const tReal&,tReal& )>&
getJFunction()
const {
281 tString str=
"beam:"+beam.
toString();
282 core_string::replaceAll(
"\n",
"\n#",str);
283 file<<
"#"<<str<<
"\n";
287 core_string::replaceAll(
"\n",
"\n#",str);
288 file<<
"#"<<str<<
"\n";
296 file<<
"# T: temperature N : simulations number\n";
297 file<<
"# for all simulation s in [0,N[:\n";
299 file<<
"# \t for all step t in [t_{eq},T[, bar S_k(s,t)=frac{1}{P} sum_{p=0}^{p=P-1} S^s_k(t,p) \n";
300 file<<
"# \t E_s=frac{1}{T} sum_{t=0}^{t=T-1} |bar S_k(eps,s,t)|\n";
301 file<<
"# E=frac{1}{N} sum_{s=0}^{s=N-1} E_s\n";
303 file<<
"# Curie Temperature: "<<Tc<<
"\n";
324 tString routineName=
"SM_StochasticJs::open()";
328 mStepIndex=core_numeric::getInfinity<tIndex>();
341 if ((prefix.length()>0)&&(
getIndex()==0)) {
344 mCTPackedFileName=mCTFileName;
348 mCTPackedFileName+=
".ct";
353 mCTPackedFileName=
"";
356 if (mCTPackedFileName.length()>0) {
359 std::ofstream file(mCTPackedFileName.c_str(),std::ios::out);
364 std::cout<<
"Fatal Error : "<<mCTPackedFileName<<
" can not be opened \n";
372 (*mJsFile)<<
"#simulation epsilon time <J for the particle 0>\n";
389 memset(&rawValues[0],0,rawValues.size()*
sizeof(tReal));
410 tString routineName=
"SM_StochasticJs::open(s,system)";
416 mStepIndex=core_numeric::getInfinity<tIndex>();
431 tString routineName=
"SM_StochasticJs::store()";
437 computeEsperanceContribution(system.
getStepIndex(),system);
468 inline tBoolean
close(
const tIndex& s,
const SM_System& system,
const tBoolean& hasSucceeded) {
470 tString routineName=
"SM_StochasticJs::close(s,system,hasSucceeded)";
475 computeEsperanceContribution(system.
getStepIndex(),system);
491 tString routineName=
"SM_StochasticJs::close(beam)";
500 if (mCTPackedFileName.length()>0) {
502 std::ofstream file(mCTPackedFileName.c_str(),std::ios::app);
507 flushStochasticOutput(file);
532 const tIndex& rawValuesNumber,
533 const std::valarray<tReal>& rawValues)
override {
534 tString routineName=
"SM_StochasticJs::closePackedSimulations(beam,nRaws,raws)";
539 if (mCTFileName.length()>0) {
540 std::ofstream file(mCTFileName,std::ios::out);
548 flushStochasticOutput(file);
560 std::stringstream ret;
562 ret<<
"\t JFunctionName:"<<mJFunctionName<<
"\n";
569 inline void computeEsperanceContribution(
const tIndex& stepIndex,
const SM_System& system) {
572 if (mStepIndex!=stepIndex) {
573 mStepIndex=stepIndex;
575 tIndex nConnections=0;
587 for(
const auto& Jij:Js) sumJij+=Jij;
588 nConnections=Js.size();
595 for(
const auto& Sk:mBarS) {
604 Es[mESRawIndex]+=mNormS;
608 sumJij/=nConnections;
609 Es[mEJRawIndex]+=sumJij;
618 inline void registerStochasticOutput(
const tIndex& rawValuesNumber,
619 const std::valarray<tReal>& rawValues) {
621 outputs[mMeanSIndex]=rawValues[mESRawIndex]/rawValuesNumber;
622 outputs[mMeanJIndex]=rawValues[mEJRawIndex]/rawValuesNumber;
623 outputs[mNSamplesIndex]=rawValuesNumber;
624 outputs[mNSimsIndex]=rawValues[mNRawIndex];
628 inline void flushStochasticOutput(std::ofstream& file) {
630 for(
const auto v:outputs) {
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:102
static tString GetAbsolutePath(const tString &path)
get the absolute path of the path
Definition: CORE_IO.h:365
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
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 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
static constexpr tReal K_B
Boltzmann constants : .
Definition: SM_Constants.h:44
const tUCInt & getCoordinationNumber() const
get the coodination number
Definition: SM_CrystalStructure.h:169
This class is a simulation of one trajectory class for Stoch Magnet package.
Definition: SM_LandauLifschitzSystem.h:59
const tReal & getTime() const
get the time
Definition: SM_LandauLifschitzSystem.h:214
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
const tReal & getExchangeEnergyFactor() const
get the exchange energy
Definition: SM_Material.h:316
const tReal & getSpinWaveMFCorrection() const
get the spin wave MF correction
Definition: SM_Material.h:340
const SM_CrystalStructure & getCrystalStructure() const
get the crystal structure
Definition: SM_Material.h:198
const std::valarray< tReal > & getConnectionValues() const
get the connection values for reading
Definition: SM_Network.h:558
tIndex getNeighboringParticlesNumber() const
get the number of connections
Definition: SM_Network.h:413
This class stores stochastic Curie temperature esperance for a dimension D.
Definition: SM_StochasticJs.h:34
tBoolean store(const SM_System &system)
store the stochastic data during the evolution method of the system
Definition: SM_StochasticJs.h:430
virtual void adimensionize(const SM_Material &material) override
adimensionize the output compoent with material characteristic
Definition: SM_StochasticJs.h:268
static CORE_UniquePointer< Self > New()
build a new instance of a stochastic data
Definition: SM_StochasticJs.h:170
SM_StochasticJs(void)
create
Definition: SM_StochasticJs.h:85
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticJs.h:154
SM_RealField & getEquilibriumState()
get the directions of spin at equilibrium
Definition: SM_StochasticJs.h:261
const SM_RealField & getEquilibriumState() const
get the directions of spin at equilibrium
Definition: SM_StochasticJs.h:256
tBoolean close(const SM_Beam &beam)
close stochastic data at the end of one packed simulations
Definition: SM_StochasticJs.h:490
void setJFunction(const tString &FName)
set J Function
Definition: SM_StochasticJs.h:199
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_StochasticJs.h:142
void setEquilibriumState(const SM_RealField &Seq)
set the directions of spin at equilibrium
Definition: SM_StochasticJs.h:251
void printHeader(std::ofstream &file, const SM_Beam &beam)
print he file header
Definition: SM_StochasticJs.h:275
static CORE_UniquePointer< Self > New(const Self &c)
build a new instance of a stochastic data
Definition: SM_StochasticJs.h:177
virtual tString toString() const override
return the string representation of the class
Definition: SM_StochasticJs.h:559
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_StochasticJs.h:531
const std::function< void(const tReal &, const tReal &,const tReal &, tReal &)> & getJFunction() const
get J function
Definition: SM_StochasticJs.h:244
tBoolean close(const tIndex &s, const SM_System &system, const tBoolean &hasSucceeded)
close the stochastic data for the simulation at index s
Definition: SM_StochasticJs.h:468
virtual ~SM_StochasticJs(void)
destroy
Definition: SM_StochasticJs.h:121
virtual void copy(const SM_StochasticOutputComponent &c) override
copy the stochastic data
Definition: SM_StochasticJs.h:188
tBoolean open(const tIndex &s, const SM_System &system)
open the stochastic data for simulation at index s
Definition: SM_StochasticJs.h:408
tBoolean open(const SM_Beam &beam)
open the stochastic data at the begininf of simulations
Definition: SM_StochasticJs.h:323
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
const tString & getPrefix() const
return the prefix
Definition: SM_StochasticOutputComponent.h:190
const tInteger & getPackedSimulationsIndex() const
get packed simulations index
Definition: SM_StochasticOutputComponent.h:257
const std::vector< tString > & getOutputDescription() const
get the string representation of the output values
Definition: SM_StochasticOutputComponent.h:316
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 tBoolean & hasLogPerPackedSimulations() const
return true if the stochastic output has log per pack of simulations
Definition: SM_StochasticOutputComponent.h:274
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
const tString & getOutputPath() const
return the output path
Definition: SM_StochasticOutputComponent.h:178
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
const SM_Network & getNetwork() const
get the network
Definition: SM_System.h:170
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
const SM_Material & getMaterial() const
get the material of the network
Definition: SM_System.h:193
virtual void sumOverNetworks(const int &rootNetwork, tIndex &n, const tIndex &nValues, tReal *values) const
sum the values of all network
Definition: SM_System.h:457
const tReal & getStochasticNoise() const
get the stochastic noise without dimension
Definition: SM_System.h:385
const tIndex & getStepIndex() const
get the step index
Definition: SM_System.h:415