1 #ifndef SM_StochasticDecreasingNoise_H
2 #define SM_StochasticDecreasingNoise_H
5 #include "SM_StochasticOutput.h"
11 #include "SM_LandauLifschitzSystem.h"
44 std::array<tReal,SM_Constants::DIM> mBarS;
47 std::array<tReal,SM_Constants::DIM> mSinf;
50 std::valarray<tReal> mTimes;
57 tString mPackedFileName;
62 tIndex mRegisteredTimesNumber;
76 "E(|Sinf-S|^2/eps^2)"});
118 mem+=
sizeof(tReal)*mTimes.size();
119 mem+=mSinf.size()*
sizeof(tReal);
120 mem+=mBarS.size()*
sizeof(tReal);
127 inline static CORE_UniquePointer<SM_StochasticDecreasingNoise>
New() {
144 const tReal *iHext=Hext.data();
146 for(
auto& Sk:mSinf) {
156 for(
auto& Sk:mSinf) {
167 auto iHext=Hext.begin();
170 tReal *iSk=mSinf.data();
173 const tReal* eS=mSinf.data();eS+=mSinf.size();
176 memset(iSk,0,
sizeof(tReal)*mSinf.size());
179 while ((iHext!=Hext.end()) && (iSk!=eS)) {
192 for(
auto& Sk:mSinf) {
214 if (llSystem==
null) {
234 mTimes.resize(nDrawns);
235 memset(&mTimes[0],0,mTimes.size()*
sizeof(tReal));
238 E.resize(mTimes.size());
239 memset(&E[0],0,E.size()*
sizeof(tReal));
243 outputs.resize(mTimes.size());
244 memset(&outputs[0],0,outputs.size()*
sizeof(tReal));
249 mFileName=mPackedFileName;
253 mPackedFileName+=
".dn";
256 std::ofstream file(mPackedFileName.c_str(),std::ios::out);
258 printHeader(file,beam);
261 std::cout<<
"Fatal Error : "<<mPackedFileName<<
" can not be opened \n";
280 mRegisteredTimesNumber=0;
310 if (mRegisteredTimesNumber>=mTimes.size()) {
312 "SM_StochasticDecreasingNoise::store()",
313 "error in times dimension");
317 const tReal *iSinf_k=mSinf.data();
319 for(
auto& Sk:mBarS) {
332 iepsilon2*=iepsilon2;
334 if (iepsilon2>functions_numeric::getEpsilon<tReal>()) iepsilon2=1./iepsilon2;
353 mRegisteredTimesNumber++;
366 inline tBoolean
close(
const tIndex& s,
const SM_System& system,
const tBoolean& hasSucceeded) {
380 inline const std::valarray<tReal>&
getTimes()
const {
387 return mRegisteredTimesNumber;
396 std::ofstream file(mPackedFileName.c_str(),std::ios::app);
412 const tIndex& rawValuesNumber,
413 const std::valarray<tReal>& rawValues)
override {
415 std::ofstream file(mFileName,std::ios::out);
422 printHeader(file,beam);
423 flushStochasticOutput(file,rawValuesNumber,rawValues);
434 std::stringstream ret;
436 ret<<
"\t Sinf="<<functions_array::toString(mSinf)<<
"\n";
446 inline void printHeader(std::ofstream& file,
const SM_Beam& beam) {
452 tString str=
"beam:"+beam.
toString();
453 functions_string::replaceAll(
"\n",
"\n#",str);
454 file<<
"#"<<str<<
"\n";
458 functions_string::replaceAll(
"\n",
"\n#",str);
459 file<<
"#"<<str<<
"\n";
460 file<<
"# bar S(s,t) = frac{1}{P} sum_p S(s,t,p) \n";
461 file<<
"# E(t)= frac{1}{S} . sum_{s=0}^{s=S-1} frac{1}{varepsilon_t^2}. frac{1}{S_{inf}-bar S(s,t)|^2} \n";
468 inline void flushStochasticOutput(std::ofstream& file,
469 const tIndex& rawValuesNumber,
470 const std::valarray<tReal>& rawValues) {
472 const tReal *iRawValues=&rawValues[0];
473 const tReal *iTimes=&mTimes[0];
474 tReal *iOutputs=&outputs[0];
475 for(tIndex i=0;i<mRegisteredTimesNumber;i++) {
476 (*iOutputs)=(*iRawValues);
477 if (rawValuesNumber>0) (*iOutputs)/=rawValuesNumber;
478 file<<(*iTimes)<<
"\t"<<(*iOutputs)<<
"\t"<<rawValuesNumber<<
"\n";
this class describes the exceptions raised for CORE package
Definition: CORE_Exception.h:17
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
const tIndex & getStepsNumber() const
get the number of steps for stochastic computation
Definition: SM_Beam.h:207
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
const tReal & getNoiseRate() const
get the noise rate
Definition: SM_LandauLifschitzSystem.h:251
This class describes a materials defined by state attributes:
Definition: SM_Material.h:61
This class stores stochastic L2 Convergence :
Definition: SM_StochasticDecreasingNoise.h:29
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_StochasticDecreasingNoise.h:116
void setSpinDirectionsAtRelaxationTime(const std::vector< tReal > &Hext)
set the deterministic dierctions of spins at relaxation time
Definition: SM_StochasticDecreasingNoise.h:164
virtual ~SM_StochasticDecreasingNoise(void)
destroy
Definition: SM_StochasticDecreasingNoise.h:83
tBoolean open(const SM_Beam &beam)
open the stochastic data
Definition: SM_StochasticDecreasingNoise.h:207
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_StochasticDecreasingNoise.h:411
virtual tString toString() const override
return the string representation of the class
Definition: SM_StochasticDecreasingNoise.h:433
static CORE_UniquePointer< SM_StochasticDecreasingNoise > New()
build a new instance of a stochastic data
Definition: SM_StochasticDecreasingNoise.h:127
const tIndex & getRegisteredTimesNumber() const
get the number of registered times
Definition: SM_StochasticDecreasingNoise.h:386
void setSpinDirectionsAtRelaxationTime(const std::array< tReal, SM_Constants::DIM > &Hext)
set the deterministic directions of spins at relaxation time
Definition: SM_StochasticDecreasingNoise.h:142
tBoolean close(const tIndex &s, const SM_System &system, const tBoolean &hasSucceeded)
close the stochastic data for the simulation s
Definition: SM_StochasticDecreasingNoise.h:366
tBoolean close(const SM_Beam &beam)
close stochastic data at the end of all simulations
Definition: SM_StochasticDecreasingNoise.h:392
tBoolean store(const SM_System &system)
store the stochastic data during the relation method of the system
Definition: SM_StochasticDecreasingNoise.h:291
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_StochasticDecreasingNoise.h:104
tBoolean open(const tIndex &s, const SM_System &system)
open the stochastic data for simulation s
Definition: SM_StochasticDecreasingNoise.h:274
SM_StochasticDecreasingNoise(void)
create
Definition: SM_StochasticDecreasingNoise.h:72
const std::valarray< tReal > & getTimes() const
get the time discretization
Definition: SM_StochasticDecreasingNoise.h:380
virtual void adimensionize(const SM_Material &material) override
adimensionize the output compoent with material characteristic
Definition: SM_StochasticDecreasingNoise.h:138
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 & getDrawnStepsNumber() const
get the drawn number to compute the stochastic output
Definition: SM_StochasticOutputComponent.h:243
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
This class is a one simulation of a beam for Stoch Magnet package.
Definition: SM_System.h:53
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