11 #include "SM_Object.h"
14 #include "SM_Constants.h"
77 tInteger mFileVersion;
79 tInteger mParticlesNumber;
82 tInteger mHaloParticlesNumber;
89 std::valarray<tIndex> mNeighboringParticlesList;
92 std::valarray<tIndex> mNeighboringParticlesNumberOffset;
96 std::valarray<tReal> mConnectionValues;
99 std::array<tBoolean,SM_Constants::DIM> mPeriodicity;
102 std::array<tReal,SM_Constants::DIM> mBoundingBoxMinPoint;
103 std::array<tReal,SM_Constants::DIM> mBoundingBoxSize;
123 mNeighboringParticlesNumberOffset={0,0};
127 for(
auto& Pk:mBoundingBoxMinPoint)Pk=0;
128 for(
auto& Pk:mBoundingBoxSize) Pk=0;
131 mHaloParticlesNumber=0;
134 mPeriodicity={
false,
false,
false};
135 for(
auto& Ik:mPeriodicity) Ik=0;
184 mem+=mNeighboringParticlesNumberOffset.size()*
sizeof(tIndex);
185 mem+=mNeighboringParticlesList.size()*
sizeof(tIndex);
186 mem+=mBoundingBoxMinPoint.size()*
sizeof(tReal);
187 mem+=mBoundingBoxSize.size()*
sizeof(tReal);
188 mem+=mConnectionValues.size()*
sizeof(tReal);
189 mem+=mPeriodicity.size()*
sizeof(tBoolean);
225 return mIndicesNumber;
239 inline void setIndex(
const int& index,
const int& rootIndex,
const int& indicesNumber) {
240 setIndex(index,rootIndex,indicesNumber,
"_c");
249 inline void setIndex(
const int& index,
const int& rootIndex,
const int& indicesNumber,
const tString& prefix) {
251 mRootIndex=rootIndex;
252 mIndicesNumber=indicesNumber;
253 int nDigits=(int) (log(indicesNumber)+1.);
254 mIndexPrefix=prefix+functions_numeric::toString(index,nDigits)+
"p"+functions_numeric::toString(indicesNumber,nDigits);
266 tBoolean *iPeriod=mPeriodicity.data();
268 auto iter=period.begin();
269 while ((iPeriod!=ePeriod) && (iter!=period.end())) {
274 while (iPeriod!=ePeriod) {
283 inline void setPeriodicity(
const std::array<tBoolean,SM_Constants::DIM>& period) {
291 tBoolean *iPeriod=mPeriodicity.data();
293 auto iter=period.begin();
294 while ((iPeriod!=ePeriod) && (iter!=period.end())) {
299 while (iPeriod!=ePeriod) {
325 inline void setSize(
const tInteger& nParticles,
326 const tInteger& nHaloParticles) {
327 mParticlesNumber=nParticles;
328 mHaloParticlesNumber=nHaloParticles;
334 mNeighboringParticlesNumberOffset.resize(nParticles+1);
337 memset(&mNeighboringParticlesNumberOffset[0],0,
sizeof(tIndex)*mNeighboringParticlesNumberOffset.size());
350 return mParticlesNumber;
356 return mHaloParticlesNumber;
400 return mNeighboringParticlesList;
407 return mNeighboringParticlesList;
414 return mNeighboringParticlesList.size();
422 return mNeighboringParticlesList.size();
429 return mNeighboringParticlesNumberOffset;
435 return mNeighboringParticlesNumberOffset;
442 ASSERT_IN(i<mNeighboringParticlesNumberOffset.size()-1);
443 return &mNeighboringParticlesList[mNeighboringParticlesNumberOffset[i]];
450 ASSERT_IN(i<mNeighboringParticlesNumberOffset.size()-1);
451 return mNeighboringParticlesNumberOffset[i+1]- mNeighboringParticlesNumberOffset[i];
458 std::valarray<tIndex>&& neighborsList) {
465 mNeighboringParticlesNumberOffset.resize(neighborsNumber.size()+1);
466 tIndex *iIndex=&mNeighboringParticlesNumberOffset[0];
467 tIndex *iNextIndex=iIndex;iNextIndex++;
468 const tIndex *eIndex=iIndex;eIndex+=mNeighboringParticlesNumberOffset.size();
470 for(
const auto& n:neighborsNumber) {
471 (*iNextIndex)=(*iIndex)+n;
476 mNeighboringParticlesList=neighborsList;
484 const std::vector<tIndex>& neighborsList) {
489 mNeighboringParticlesNumberOffset.resize(neighborsNumber.size()+1);
492 tIndex *iIndex=&mNeighboringParticlesNumberOffset[0];
494 tIndex *iNextIndex=iIndex;iNextIndex++;
496 const tIndex *eIndex=iIndex;eIndex+=mNeighboringParticlesNumberOffset.size();
498 for(
const auto& n:neighborsNumber) {
499 (*iNextIndex)=(*iIndex)+n;
507 auto Ni=neighborsList.cbegin();
508 mNeighboringParticlesList.resize(neighborsList.size());
509 std::for_each(std::begin(mNeighboringParticlesList),std::end(mNeighboringParticlesList),[&Ni](tIndex& e){e=(*Ni);Ni++;} );
517 tIndex nAloneParticles=0;
522 const tIndex *iIndex=&mNeighboringParticlesNumberOffset[0];
523 const tIndex *iNextIndex=iIndex;iNextIndex++;
525 const tIndex *eIndex=iIndex;eIndex+=mNeighboringParticlesNumberOffset.size();
526 while (iNextIndex!=eIndex) {
528 nAloneParticles+=((*iNextIndex)==(*iIndex));
534 return nAloneParticles;
545 return (mConnectionValues.size()>1);
552 return mConnectionValues.size();
559 return mConnectionValues;
566 return mConnectionValues;
577 ASSERT_IN(i<mNeighboringParticlesNumberOffset.size()-1);
578 ASSERT_IN(j<mNeighboringParticlesNumberOffset.size()-1);
579 tIndex index=mNeighboringParticlesNumberOffset[i];
580 index+=functions_numeric::quickSearch(j,mNeighboringParticlesNumberOffset[i+1]-index,
581 &mNeighboringParticlesList[index],
583 return mConnectionValues[index];
593 ASSERT_IN(i<mNeighboringParticlesNumberOffset.size()-1);
594 ASSERT_IN(j<mNeighboringParticlesNumberOffset.size()-1);
595 tIndex index=mNeighboringParticlesNumberOffset[i];
596 index+=functions_numeric::quickSearch(j,mNeighboringParticlesNumberOffset[i+1]-index,
597 &mNeighboringParticlesList[index],
599 return mConnectionValues[index];
608 ASSERT_IN(i<mNeighboringParticlesNumberOffset.size()-1);
609 return &mConnectionValues[mNeighboringParticlesNumberOffset[i]*(mConnectionValues.size()>1)];
617 ASSERT_IN(i<mNeighboringParticlesNumberOffset.size()-1);
618 return &mConnectionValues[mNeighboringParticlesNumberOffset[i]*(mConnectionValues.size()>1)];
630 return mBoundingBoxMinPoint;
636 return mBoundingBoxSize;
645 std::array<tReal,SM_Constants::DIM>& bbSize)
const =0;
666 const std::function<
void(
const tReal&,
const tReal& ,
const tReal&,tReal& )>& F)=0;
678 const tIndex& endIndex,
679 const tReal& noiseRate,
682 const std::function<
void(
const tReal&,
const tReal& ,
const tReal&,tReal& )>& F);
711 tBoolean
saveToFile(
const tString& fileName)
const;
738 void saveParticlesToFile(std::ofstream& file)
const;
739 tBoolean loadParticleDataFromFile(std::ifstream& file,
740 const tDimension& d);
741 tBoolean loadParticlesFromFile(std::ifstream& file,
743 const tIndex& nParticles,
744 const tIndex& nHaloParticles,
745 const tIndex& nNeighboringParticles);
752 virtual tString
toString()
const override;
virtual tMemSize getContentsMemorySize() const override
return the memory size of the included associations
Definition: CORE_Field.h:102
void copy(const tIndex &n, const Q *vs)
initialize the field to the values of pointer of size n
Definition: CORE_Field.h:447
void setElementsNumber(const tInteger &n)
set the number of element of the container
Definition: CORE_Field.h:121
virtual tMemSize getContentsMemorySize() const
return nthe memory size of the included associations
Definition: CORE_Object.h:278
static constexpr tDimension DIM
space dimension
Definition: SM_Constants.h:80
This class is describes a network composed by.
Definition: SM_Network.h:66
const std::array< tReal, SM_Constants::DIM > & getBoundingBoxMinPoint() const
get the min point of the boudning box
Definition: SM_Network.h:629
void setPeriodicity(const std::array< tBoolean, SM_Constants::DIM > &period)
set periodicity
Definition: SM_Network.h:283
virtual tMemSize getMemorySize() const
return the memory size of the class and the memory size of all its attributes/associations
Definition: SM_Network.h:169
tIndex getNeighboringParticlesNumber(const tIndex &i) const
get the number of neighboring particles for the particle i for writing
Definition: SM_Network.h:449
const std::array< tReal, SM_Constants::DIM > & getBoundingBoxSize() const
get the size of the boudning box
Definition: SM_Network.h:635
virtual void updateConnectionValues(const tReal &noiseRate, SM_StochasticFunctionsInterface &randomF, const tReal &J, const std::function< void(const tReal &, const tReal &, const tReal &, tReal &)> &F)=0
compute the connection values of the particles in [startInddex,endIndex[
tIndex getConnectionValuesNumber() const
get the number of connection values
Definition: SM_Network.h:551
tBoolean hasConnectionValues() const
has connection values
Definition: SM_Network.h:544
const std::valarray< tIndex > & getNeighboringParticlesList() const
get the neighbors indices
Definition: SM_Network.h:399
tIndex getConnectionsNumber() const
get the number of connections
Definition: SM_Network.h:421
tIndex computeAloneParticlesNumber() const
return the particles number without any connection
Definition: SM_Network.h:516
tReal * getConnectionValues(const tIndex &i)
get the connections values of the particle i for writing
Definition: SM_Network.h:616
virtual void saveStatesToFile(std::ofstream &file) const
save the state of the network
Definition: SM_Network.cpp:97
const tReal * getConnectionValues(const tIndex &i) const
get the connections values of the particle i for reading
Definition: SM_Network.h:607
const int & getIndicesNumber() const
get the number of network parts
Definition: SM_Network.h:224
void updateConnectionValuesSlice(const tIndex &startIndex, const tIndex &endIndex, const tReal &noiseRate, SM_StochasticFunctionsInterface &randomF, const tReal &J, const std::function< void(const tReal &, const tReal &, const tReal &, tReal &)> &F)
compute the connection values of the particles in [startInddex,endIndex[
Definition: SM_Network.cpp:10
tReal & getConnectionValue(const tIndex &i, const tIndex &j, tBoolean &isFound)
get the value of the connection between particle i and j fro writing
Definition: SM_Network.h:576
void setNeighboringParticlesList(std::valarray< tUCInt > &&neighborsNumber, std::valarray< tIndex > &&neighborsList)
set the neighbors list and offset for list
Definition: SM_Network.h:457
const std::valarray< tReal > & getConnectionValues() const
get the connection values for reading
Definition: SM_Network.h:558
void setPeriodicity(const std::vector< tBoolean > &period)
set periodicity
Definition: SM_Network.h:290
const tInteger & getHaloParticlesNumber() const
return the halo particles number
Definition: SM_Network.h:355
const int & getIndex() const
create new instance of the network
Definition: SM_Network.h:214
const std::array< tBoolean, SM_Constants::DIM > & getPeriodicity() const
get periodicity per direction
Definition: SM_Network.h:308
std::valarray< tIndex > & getNeighboringParticlesNumberOffset()
get the index of the array mNeighboringParticlesList of the first neighbor of the particle p
Definition: SM_Network.h:434
void setParticlesCoordinates(std::initializer_list< tReal > &&coords)
void set particles 3D-coordinates
Definition: SM_Network.h:363
void setParticlesCoordinates(const std::initializer_list< tReal > &coords)
void set particles 3D-coordinates
Definition: SM_Network.h:369
const tString & getIndexPrefix() const
index of the root network for network defined with many parts for mpi version
Definition: SM_Network.h:229
const tIndex * getNeighboringParticlesList(const tIndex &i) const
get the index of neighboring particles list for the particle i for reading
Definition: SM_Network.h:441
const tInteger & getParticlesNumber() const
return the particles number
Definition: SM_Network.h:349
const SM_RealField & getParticlesCoordinates() const
void get particles coordinates
Definition: SM_Network.h:382
const std::valarray< tIndex > & getNeighboringParticlesNumberOffset() const
get the index of the array mNeighboringParticlesList of the first neighbor of the particle p
Definition: SM_Network.h:428
std::valarray< tReal > & getConnectionValues()
get the connection values for writing
Definition: SM_Network.h:565
virtual void updateState()
update the state of the network It computes the bounding box
Definition: SM_Network.h:653
void setSize(const tInteger &nParticles, const tInteger &nHaloParticles)
set the size of the network
Definition: SM_Network.h:325
std::valarray< tIndex > & getNeighboringParticlesList()
get the neighbors indices
Definition: SM_Network.h:406
tBoolean saveToFile(const tString &fileName) const
save the network into file
Definition: SM_Network.cpp:76
const tReal & getConnectionValue(const tIndex &i, const tIndex &j, tBoolean &isFound) const
get the value of the connection between particle i and j for reading
Definition: SM_Network.h:592
void setNeighboringParticlesList(const std::valarray< tUCInt > &neighborsNumber, const std::vector< tIndex > &neighborsList)
set the neighboring particles list and its offset
Definition: SM_Network.h:483
void setIndex(const int &index, const int &rootIndex, const int &indicesNumber, const tString &prefix)
set the index of the network
Definition: SM_Network.h:249
void setParticlesCoordinates(const SM_RealField &coords)
void set particles coordinates
Definition: SM_Network.h:375
tIndex getNeighboringParticlesNumber() const
get the number of connections
Definition: SM_Network.h:413
SM_Network(void)
create a network class
Definition: SM_Network.h:113
virtual tMemSize getContentsMemorySize() const
return the memory size of the included associations
Definition: SM_Network.h:181
virtual void copy(const SM_Network &network)
copy the network
Definition: SM_Network.h:198
virtual tString toString() const override
turn the class into a string representation
Definition: SM_Network.cpp:496
virtual void computeBoundingBox(std::array< tReal, SM_Constants::DIM > &bbMinPoint, std::array< tReal, SM_Constants::DIM > &bbSize) const =0
get the min point and size of the bunding box
virtual ~SM_Network(void)
destroy
Definition: SM_Network.h:143
void setPeriodicity(const std::initializer_list< tBoolean > &&period)
set periodicity
Definition: SM_Network.h:265
void setIndex(const int &index, const int &rootIndex, const int &indicesNumber)
set the index of the network
Definition: SM_Network.h:239
SM_RealField & getParticlesCoordinates()
void get particles coordinates
Definition: SM_Network.h:389
tBoolean loadFromFile(const tString &fileName)
load the network from file
Definition: SM_Network.cpp:188
const int & getRootIndex() const
index of the root network for network defined with many parts for mpi version
Definition: SM_Network.h:219
virtual void loadStatesFromFile(std::ifstream &file, tInteger &version, tDimension &d)
load the state of the network
Definition: SM_Network.cpp:220
void setParticlesNumber(const tInteger &nParticles)
set the particles number
Definition: SM_Network.h:318
This class is a base class for Stoch Microm package.
Definition: SM_Object.h:36
This class describes a stochastic functions based on same random number generator which implement ran...
Definition: SM_StochasticFunctionsInterface.h:18