1 #ifndef SM_StochasticBoltzmann_H
2 #define SM_StochasticBoltzmann_H
5 #include "SM_StochasticOutput.h"
11 #include "SM_System.h"
17 #include "CORE_Chrono.h"
20 #include "SM_MonteCarloSystem.h"
21 #include "SM_LandauLifschitzSystem.h"
46 std::array<tReal,SM_Constants::DIM> mU;
61 tString mBoltzmannFileName;
62 tString mSBoltzmannFileName;
77 "<number of angles of S with easy axes in [theta_i,theta_i+1[>",
78 "<total number of computed angles>",
79 "<normalized propability>",
129 mem+=mU.size()*
sizeof(tIndex);
130 mem+=
sizeof(tChar)*mBoltzmannFileName.length();
131 mem+=
sizeof(tChar)*mSBoltzmannFileName.length();
138 inline static CORE_UniquePointer<Self>
New() {
139 return CORE_UniquePointer<Self>(
new Self(),
145 inline static CORE_UniquePointer<Self>
New(
const Self& c) {
146 CORE_UniquePointer<Self> p=
New();
165 const Self *cc=
dynamic_cast<const Self*
>(&c);
189 inline void setAxis(
const std::array<tReal,SM_Constants::DIM>& axis) {
194 inline void setAxis(
const std::vector<tReal>& axis) {
200 for(
const auto& Uk:axis) {
205 std::vector<tReal>::const_iterator iAxis=axis.begin();
215 inline const std::array<tReal,SM_Constants::DIM>&
getAxis()
const {
237 functions_string::replaceAll(
"\n",
"\n#",str);
238 file<<
"#"<<str<<
"\n";
242 functions_string::replaceAll(
"\n",
"\n#",str);
243 file<<
"#"<<str<<
"\n";
247 file<<
"#Teff:"<<mTeff<<
"\n";
274 rawValues.resize(mN);
277 memset(&rawValues[0],0,rawValues.size()*
sizeof(tReal));
288 mSBoltzmannFileName=mBoltzmannFileName;
290 mBoltzmannFileName+=
".bd";
291 mSBoltzmannFileName+=
".sbd";
294 std::ofstream file(mBoltzmannFileName.c_str(),
300 std::cout<<
"Fatal Error : "<<mBoltzmannFileName<<
" can not be opened \n";
304 std::ofstream sfile(mSBoltzmannFileName.c_str(),
310 std::cout<<
"Fatal Error : "<<mSBoltzmannFileName<<
" can not be opened \n";
317 mStepIndex=functions_numeric::getMax<tIndex>();
333 mStepIndex=functions_numeric::getMax<tIndex>();
352 const tReal* iS=&S[0];
354 const tReal* eS=iS;eS+=S.
getSize();
358 const tReal *iU=mU.data();
359 const tReal *eU=iU;eU+=mU.size();
372 tIndex i=sSU/mDTheta;
388 inline tBoolean
close(
const tIndex& s,
const SM_System& system,
const tBoolean& hasSucceeded) {
390 if (hasSucceeded)
store(system);
408 std::ofstream file(mBoltzmannFileName.c_str(),std::ios::app);
411 printDistribution(file,
417 std::ofstream sFile(mSBoltzmannFileName.c_str(),std::ios::app);
419 printSymmetricDistribution(sFile,
437 const tIndex& rawValuesNumber,
438 const std::valarray<tReal>& rawValues)
override {
444 file<<
"#Closed Packed Simulations\n";
446 printDistribution(file,
456 sFile<<
"#Closed Symmetric Packed Simulations\n";
458 printSymmetricDistribution(sFile,
478 std::vector<tReal>& intervals,
479 std::vector<tIndex>& intervalSamplesNumber,
480 tIndex& samplesNumber,
481 std::vector<tReal>& probability,
482 std::vector<tReal>& boltzmannProbability) {
483 std::ifstream f(fn.c_str(),std::ios::in);
488 intervalSamplesNumber.clear();
490 boltzmannProbability.clear();
494 tIndex n,samplesNumber;
497 while ((!f.eof()) && (std::getline(f,line))) {
500 if ((line.length()==0) || (line[0]==
'#'))
continue;
503 std::stringstream sstr;
518 intervals.push_back(x);
519 intervalSamplesNumber.push_back(n);
520 probability.push_back(Pk);
521 boltzmannProbability.push_back(thPk);
534 std::stringstream ret;
536 ret<<
"\t Number of subdivisions :"<<mN<<
"\n";
537 ret<<
"\t Easy axis :"<<functions_array::toString(mU)<<
"\n";
547 tReal computeBoltzmannDistribution(
const tReal& theta)
const {
563 tReal computeBoltzmannDistributionMaximum()
const {
564 tReal Pmax=exp(-mTeff);
566 tReal Pmax2=sqrt(1./(2.*mTeff*exp(1.)));
567 Pmax=(Pmax2>Pmax)?Pmax2:Pmax;
579 inline void printDistribution(std::ofstream& file,
580 const tInteger& rawDataSize,
581 const std::valarray<tReal>& rawData)
const {
584 tReal PBmax=computeBoltzmannDistributionMaximum();
586 tReal maxPk=rawData[0];
587 for(
const auto& Pk:rawData) {
588 maxPk=(maxPk<Pk)?Pk:maxPk;
593 for(
const auto& Pk:rawData) {
595 file<<theta<<
"\t"<<Pk<<
"\t"<<rawDataSize<<
"\t"<< (Pk/maxPk)<<
"\t"<<(computeBoltzmannDistribution(theta)/PBmax)<<
"\n";
600 for(
const auto& Pk:rawData) {
602 file<<theta<<
"\t"<<Pk<<
"\t"<<rawDataSize<<
"\t"<< Pk<<
"\t"<<(computeBoltzmannDistribution(theta)/PBmax)<<
"\n";
615 inline void printSymmetricDistribution(std::ofstream& file,
616 const tInteger& rawDataSize,
617 const std::valarray<tReal>& rawData)
const {
619 tInteger i,n=rawData.size();
623 const tReal *iRawData=&rawData[0];
624 const tReal *eRawData=iRawData;eRawData+=rawData.size();
626 const tReal *iEnd=eRawData;iEnd--;
630 tReal nMaxSamples=0,nSamples;
633 nSamples=(*iRawData)+(*iEnd);
634 nMaxSamples=(nMaxSamples<nSamples)?nSamples:nMaxSamples;
641 tReal PBmax=computeBoltzmannDistributionMaximum();
646 iRawData=&rawData[0];
647 iEnd=eRawData;iEnd--;
648 while (iRawData!=eRawData) {
650 if (iRawData!=iEnd) nSamples=(*iRawData)+(*iEnd);
651 else nSamples=(*iRawData);
653 file<<theta<<
"\t"<<nSamples<<
"\t"<<rawDataSize<<
"\t"<< (nSamples/nMaxSamples)<<
"\t"<<(computeBoltzmannDistribution(theta)/PBmax)<<
"\n";
661 for(
const auto& Pk:rawData) {
663 file<<theta<<
"\t"<<Pk<<
"\t"<<rawDataSize<<
"\t"<< Pk<<
"\t"<<(computeBoltzmannDistribution(theta)/PBmax)<<
"\n";
tIndex getSize() const
return the number values of the container
Definition: CORE_Field.h:161
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 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 tDimension DIM
space dimension
Definition: SM_Constants.h:80
static constexpr tReal K_B
Boltzmann constants : .
Definition: SM_Constants.h:44
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
const tReal & getAnisotropyEnergyFactor() const
get the anisotropy energy
Definition: SM_Material.h:274
This class stores stochastic Boltzmann distribution for 1 spin.
Definition: SM_StochasticBoltzmann.h:31
virtual ~SM_StochasticBoltzmann(void)
destroy
Definition: SM_StochasticBoltzmann.h:94
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_StochasticBoltzmann.h:115
virtual void closePackedSimulations(const SM_Beam &beam, const tIndex &rawValuesNumber, const std::valarray< tReal > &rawValues) override
reduction the raws values for packed simlations
Definition: SM_StochasticBoltzmann.h:436
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticBoltzmann.h:127
virtual void copy(const SM_StochasticOutputComponent &c) override
copy the stochastic data
Definition: SM_StochasticBoltzmann.h:163
virtual tString toString() const override
return the string representation of the class
Definition: SM_StochasticBoltzmann.h:533
void setAxis(const std::array< tReal, SM_Constants::DIM > &axis)
set the easy axis
Definition: SM_StochasticBoltzmann.h:189
static tBoolean LoadDistributionFile(const tString &fn, std::vector< tReal > &intervals, std::vector< tIndex > &intervalSamplesNumber, tIndex &samplesNumber, std::vector< tReal > &probability, std::vector< tReal > &boltzmannProbability)
load distribution from file
Definition: SM_StochasticBoltzmann.h:477
tBoolean open(const SM_Beam &beam)
open the stochastic data
Definition: SM_StochasticBoltzmann.h:265
tBoolean store(const SM_System &system)
store the stochastic data during the evolution method of the system
Definition: SM_StochasticBoltzmann.h:342
tBoolean close(const SM_Beam &beam)
close stochastic data at the end of all simulations at each epsilon
Definition: SM_StochasticBoltzmann.h:399
virtual void adimensionize(const SM_Material &material) override
adimensionize the output compoent with material characteristic
Definition: SM_StochasticBoltzmann.h:157
static CORE_UniquePointer< Self > New(const Self &c)
build a new instance of a stochastic data
Definition: SM_StochasticBoltzmann.h:145
SM_StochasticBoltzmann(void)
create
Definition: SM_StochasticBoltzmann.h:71
void setSegmentsNumber(const tInteger &n)
set the number of subdivisions of the support of the distribution
Definition: SM_StochasticBoltzmann.h:176
tBoolean close(const tIndex &s, const SM_System &system, const tBoolean &hasSucceeded)
close the stochastic data for the end of the simulation s
Definition: SM_StochasticBoltzmann.h:388
static CORE_UniquePointer< Self > New()
build a new instance of a stochastic data
Definition: SM_StochasticBoltzmann.h:138
const tInteger & getSegmentsNumber() const
get the number of subdivisions of the support of the distribution
Definition: SM_StochasticBoltzmann.h:182
void setAxis(const std::vector< tReal > &axis)
set the easy axis
Definition: SM_StochasticBoltzmann.h:194
tBoolean open(const tIndex &s, const SM_System &system)
open the stochastic data for simulation s
Definition: SM_StochasticBoltzmann.h:331
void printHeader(std::ofstream &file, const SM_Beam &beam)
print header on file
Definition: SM_StochasticBoltzmann.h:229
const std::array< tReal, SM_Constants::DIM > & getAxis() const
get the easy axis
Definition: SM_StochasticBoltzmann.h:215
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_RealField & getMagneticMomentDirections() const
get the unit direction of spins at time
Definition: SM_System.h:267
const SM_Material & getMaterial() const
get the material of the network
Definition: SM_System.h:193
const tReal & getNoiseTemperature() const
get the noise temperature in Kelvin
Definition: SM_System.h:399
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 tIndex & getStepIndex() const
get the step index
Definition: SM_System.h:415