ls1-MarDyn
ls1-MarDyn molecular dynamics code
RDF.h
1#ifndef RDF_H
2#define RDF_H
3
4#include <cmath>
5#include <string>
6#include <utility>
7#include <vector>
8
9#include "plugins/PluginBase.h"
10#include "molecules/Molecule.h"
11#include "utils/CommVar.h"
12
13class Component;
15
37class RDF : public PluginBase {
38
39 friend class RDFTest;
40
41public:
42
43 RDF();
44 virtual ~~RDF();
45
58 void readXML(XMLfileUnits& xmlconfig);
59
60 void afterForces(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp, unsigned long simstep);
61
62 void init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain);
63
64 void finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain);
65
67 return std::string("RDF");
68 }
69 static PluginBase* createInstance() { return new RDF(); }
70
73 void setOutputTimestep(unsigned int timestep) { _writeFrequency = timestep; }
74
77 void setOutputPrefix(std::string prefix) { _outputPrefix = prefix; }
78
80 void endStep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomposition, Domain *domain,
81 unsigned long simStep);
82
85 void tickRDF() {
86 _numberOfRDFTimesteps++;
87 }
88
91 void accumulateNumberOfMolecules(std::vector<Component>& components);
92
93 void observeARDFMolecule(double dd, double cosPhi, double cosPhiReverse, unsigned cid1, unsigned cid2) {
94
95 if(dd > _maxDistanceSquare) { return; }
96 size_t distanceBinID = floor( sqrt(dd) / binwidth() );
97 size_t angularBinID = floor( (-cosPhi + 1.)/ angularbinwidth() );
98 size_t angularBinIDReverse = floor((-cosPhiReverse + 1.)/ angularbinwidth() );
99 size_t binID = distanceBinID * _angularBins + angularBinID;
100 size_t binIDReverse = distanceBinID * _angularBins + angularBinIDReverse;
101 #if defined _OPENMP
102 #pragma omp atomic
103 #endif
104 _ARDFdistribution.local[cid1][cid2][binID]++;
105 #if defined _OPENMP
106 #pragma omp atomic
107 #endif
108 _ARDFdistribution.local[cid2][cid1][binIDReverse]++;
109 }
110
111 void observeRDF(Molecule const& mi, Molecule const& mj, double dd) {
112 observeRDFMolecule(dd, mi.componentid(), mj.componentid());
113
114 if(isEnabledSiteRDF()) {
115 double drs[3];
116 double dr2;
117 unsigned si = mi.numSites();
118 unsigned sj = mj.numSites();
119 if(si+sj > 2) {
120 for(unsigned m = 0; m < si; m++) {
121 // when interacting two molecules with the same component id, the interaction of site m with site n is calculated twice if m!=n.
122 // this duplication is corrected by correctionFactor in the writeToFile(...) function.
123 // fixing this here, by starting n at m will break the unit tests and some symmetry.
124 for(unsigned n = 0; n < sj; n++) {
125 const std::array<double,3> dii = mi.site_d_abs(m);
126 const std::array<double,3> djj = mj.site_d_abs(n);
127 SiteSiteDistanceAbs(dii.data(), djj.data(), drs, dr2);
128 observeRDFSite(dr2, mi.componentid(), mj.componentid(), m, n);
129 }
130 }
131 }
132 }
133 }
134
138 void observeRDFMolecule(double dd, unsigned i, unsigned j) {
139 if(dd > _maxDistanceSquare) { return; }
140 if(i > j) { std::swap(j, i); }
141 size_t binId = floor( sqrt(dd) / binwidth() );
142 #if defined _OPENMP
143 #pragma omp atomic
144 #endif
145 _distribution.local[i][j-i][binId]++;
146 }
147
152 inline void observeRDFSite(double dd, unsigned i, unsigned j, unsigned m, unsigned n) {
153 if(dd > _maxDistanceSquare) { return; }
154 if (i > j) {
155 std::swap(j, i);
156 std::swap(m, n);
157 }
158
159 unsigned int binId = floor( sqrt(dd) / binwidth() );
160 #if defined _OPENMP
161 #pragma omp atomic
162 #endif
163 _siteDistribution.local[i][j-i][m][n][binId] ++;
164 if((i == j) && (m != n)){
165 #if defined _OPENMP
166 #pragma omp atomic
167 #endif
168 _siteDistribution.local[i][j-i][n][m][binId] ++;
169 }
170 }
171
172 bool isEnabledSiteRDF() const { return _doCollectSiteRDF; }
173 bool doARDF() const { return _doARDF; }
174
175 void reset();
176
177private:
178
179 template<typename T>
180 void resizeExactly(std::vector<T>& v, unsigned int numElements) const {
181 v.reserve(numElements);
182 v.resize(numElements);
183 }
184
185 void init();
186 unsigned int numBins() const { return _bins; }
187 unsigned int numARDFBins() const { return _ARDFBins; }
188 double binwidth() const { return _intervalLength; }
189 double angularbinwidth() const { return _angularIntervalLength; }
190 void collectRDF(DomainDecompBase* domainDecomp);
191
194 void accumulateRDF();
195
196 void writeToFile(const Domain* domain, const std::string& filename, unsigned int i, unsigned int j) const;
197 void writeToFileARDF(const Domain* domain, const std::string& filename, unsigned int i, unsigned int j) const;
200 double _intervalLength;
201
204 double _angularIntervalLength;
205
208 unsigned long _bins;
209
212 unsigned long _angularBins {1};
213
216 unsigned long _ARDFBins;
217
219 unsigned int _numberOfComponents;
220
222 std::vector<Component>* _components;
223
225 int _samplingFrequency;
226
229 int _numberOfRDFTimesteps;
230
233 int _accumulatedNumberOfRDFTimesteps;
234
236 double _maxDistanceSquare;
237
242 std::vector<unsigned long> _globalCtr;
243
247 std::vector<unsigned long> _globalAccumulatedCtr;
248
254 std::vector<std::vector<std::vector<unsigned long>>> _globalAccumulatedDistribution;
255 std::vector<std::vector<std::vector<unsigned long>>> _globalAccumulatedARDFDistribution;
256
257 bool _doCollectSiteRDF;
258 bool _doARDF;
259 // vector indices:
260 // first: component i
261 // second: component j, but shifted by -i, so that we only have to save it once for each component interaction (i<->j is the same as j<->i)
262 // third: site m of first component
263 // fourth: site n of second component
264 // fifth: bin to sort the particles into to get the actual RDF.
266
267 std::vector<std::vector<std::vector<std::vector<std::vector<unsigned long>>>>> _globalAccumulatedSiteDistribution;
268
269 unsigned int _writeFrequency;
270 std::string _outputPrefix;
271
272 bool _initialized;
273 bool _readConfig;
274
275 RDFCellProcessor * _cellProcessor;
276};
277
278#endif /* RDF_H */
Definition: CommVar.h:17
Class implementing molecules as rigid rotators consisting out of different interaction sites (LJcente...
Definition: Component.h:14
handle boundary region and multiple processes
Definition: DomainDecompBase.h:51
This class is used to read in the phasespace and to handle macroscopic values.
Definition: Domain.h:47
FullMolecule modeled as LJ sphere with point polarities.
Definition: FullMolecule.h:18
unsigned int numSites() const override
Definition: FullMolecule.h:136
This Interface is used to get access to particles and pairs of particles.
Definition: ParticleContainer.h:69
The PluginBase class provides the interface for any kind of output/plugin classes - called "(output) ...
Definition: PluginBase.h:47
Definition: RDFCellProcessor.h:16
This class calculates the Radial Distribution Function (RDF).
Definition: RDF.h:37
void endStep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomposition, Domain *domain, unsigned long simStep)
plot all the statistics calculated to one or several files
Definition: RDF.cpp:343
void setOutputTimestep(unsigned int timestep)
Definition: RDF.h:73
void observeRDFMolecule(double dd, unsigned i, unsigned j)
Definition: RDF.h:138
void readXML(XMLfileUnits &xmlconfig)
Read in XML configuration for RDFWriter.
Definition: RDF.cpp:154
void observeRDFSite(double dd, unsigned i, unsigned j, unsigned m, unsigned n)
Definition: RDF.h:152
void finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain)
Method finish will be called at the end of the simulation.
Definition: RDF.cpp:185
void afterForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep)
Method afterForces will be called after forcefields have been applied no sitewise Forces can be appli...
Definition: RDF.cpp:573
void accumulateNumberOfMolecules(std::vector< Component > &components)
Definition: RDF.cpp:195
void reset()
reset all values to 0, except the accumulated ones.
Definition: RDF.cpp:309
std::string getPluginName()
return the name of the plugin
Definition: RDF.h:66
void tickRDF()
Definition: RDF.h:85
void setOutputPrefix(std::string prefix)
Definition: RDF.h:77
void init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain)
Method init will be called at the begin of the simulation.
Definition: RDF.cpp:181
XML file with unit attributes abstraction.
Definition: xmlfileUnits.h:25
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
Definition: vtk-punstructured.h:270