ls1-MarDyn
ls1-MarDyn molecular dynamics code
DistControl.h
1/*
2 * DistControl.h
3 *
4 * Created on: 16.03.2015
5 * Author: mheinen
6 */
7
8#ifndef DISTCONTROL_H_
9#define DISTCONTROL_H_
10
11#include <iostream>
12#include <string>
13#include <sstream>
14#include <vector>
15#include <cstdint>
16#include "plugins/PluginBase.h"
17#include "utils/ObserverBase.h"
18#include "utils/Region.h"
19#include "utils/CommVar.h"
20#include "molecules/MoleculeForwardDeclaration.h"
21
22using namespace std;
23
24class XMLfileUnits;
25class Domain;
28
29#define FORMAT_SCI_MAX_DIGITS std::setw(24) << std::scientific << std::setprecision(std::numeric_limits<double>::digits10)
30
31enum DistControlUpdateMethods
32{
33 DCUM_UNKNOWN = 0,
34 DCUM_DENSITY_PROFILE = 1,
35 DCUM_DENSITY_PROFILE_DERIVATION = 2,
36// DCUM_FORCE_PROFILE = 3,
37};
38
39enum DistControlInitMethods
40{
41 DCIM_UNKNOWN = 0,
42 DCIM_START_CONFIGURATION = 1,
43 DCIM_MIDPOINT_VALUES = 2,
44 DCIM_READ_FROM_FILE = 3,
45};
46
47class DistControl : public PluginBase, public ControlInstance, public SubjectBase
48{
49public:
51 virtual ~~DistControl();
52
53 std::string getShortName() override {return "DiC";}
54
85 void readXML(XMLfileUnits& xmlconfig) override;
86
87 void init(ParticleContainer *particleContainer,
88 DomainDecompBase *domainDecomp, Domain *domain) override;
89
90 void beforeEventNewTimestep(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp,
91 unsigned long simstep) override {};
92
93 void beforeForces(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp,
94 unsigned long simstep) override;
95
96 void siteWiseForces(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp,
97 unsigned long simstep) override {};
98 void afterForces(ParticleContainer* particleContainer, DomainDecompBase* domainDecomp,
99 unsigned long simstep) override {}
100
101 void endStep(ParticleContainer *particleContainer,
102 DomainDecompBase *domainDecomp, Domain *domain,
103 unsigned long simstep) override {};
104
105 void finish(ParticleContainer *particleContainer,
106 DomainDecompBase *domainDecomp, Domain *domain) override {}
107
108 std::string getPluginName() override {return std::string("DistControl");}
109 static PluginBase* createInstance() {return new DistControl();}
110
111 // set subdivision
112 void SetSubdivision(const uint32_t& numBins) {_binParams.count = numBins; _nSubdivisionOpt = SDOPT_BY_NUM_SLABS;}
113 void SetSubdivision(const double& dBinWidth) {_binParams.width = dBinWidth; _nSubdivisionOpt = SDOPT_BY_SLAB_WIDTH;}
114 void PrepareSubdivision(); // need to be called before PrepareDataStructures()
115
116 // data structures
117 void PrepareDataStructures();
118
119 // init
120 void InitPositions(const double& dInterfaceMidLeft, const double& dInterfaceMidRight);
121
122 double GetInterfaceMidLeft() {return _dInterfaceMidLeft;}
123 double GetInterfaceMidRight() {return _dInterfaceMidRight;}
124 unsigned int GetUpdateFreq() {return _controlFreqs.update;}
125 unsigned int GetWriteFreqProfiles() {return _controlFreqs.write.profiles;}
126
127 void Init(ParticleContainer* particleContainer);
128 void WriteHeader();
129 void WriteData(const uint64_t& simstep);
130 void WriteDataProfiles(const uint64_t& simstep);
131
132 // place method inside loop over molecule container
133 void SampleProfiles(Molecule* mol);
134
135 void UpdatePositionsInit(ParticleContainer* particleContainer); // call in Simulation::prepare_start()
136 void UpdatePositions(const uint64_t& simstep);
137
138 // SubjectBase methods
139 void registerObserver(ObserverBase* observer) override;
140 void unregisterObserver(ObserverBase* observer) override;
141 void informObserver() override;
142
143private:
144 // place methods after the loop
145 void CalcProfiles();
146 void EstimateInterfaceMidpoint(); // called by UpdatePositions
147 void EstimateInterfaceMidpointsByForce();
148 void ResetLocalValues();
149
150 // data structures
151 void InitDataStructures();
152
153 // processing profiles
154 void SmoothProfile(double* dData, double* dSmoothData, const uint64_t& nNumVals, const uint32_t& nNeighbourVals);
155 void SmoothProfiles(const uint32_t& nNeighbourVals);
156 void DerivateProfile(double* dDataX, double* dDataY, double* dDerivDataY, const uint64_t& nNumVals, const uint32_t& nNeighbourVals);
157 void DerivateProfiles(const uint32_t& nNeighbourVals);
158
159
160private:
161 double _dInterfaceMidLeft;
162 double _dInterfaceMidRight;
163
164 uint16_t _nNumComponents;
165 uint16_t _nTargetCompID;
166 uint64_t _nNumValuesScalar;
167 std::vector<uint64_t> _nOffsets;
168
169 CommVar<std::vector<uint64_t> > _nNumMolecules;
171 std::vector<double> _dMidpointPositions;
172 std::vector<double> _dDensityProfile;
173 std::vector<double> _dDensityProfileSmoothed;
174 std::vector<double> _dDensityProfileSmoothedDerivation;
175 std::vector<double> _dForceProfile;
176 std::vector<double> _dForceProfileSmoothed;
177
178 // update method
179 int _nMethod;
180 double _dVaporDensity;
181 uint16_t _nNeighbourValsSmooth;
182 uint16_t _nNeighbourValsDerivate;
183
184 int _nMethodInit;
185 std::string _strFilenameInit;
186 uint64_t _nRestartTimestep;
187
188 // write data
189 std::string _strFilename;
190 std::string _strFilenameProfilesPrefix;
191
192 // observer
193 std::vector<ObserverBase*> _observer;
194
195 int _nSubdivisionOpt;
196
197 struct BinParamsType
198 {
199 uint32_t count;
200 double width;
201 double invWidth;
202 double volume;
203 } _binParams;
204
205 struct ControlFreqType
206 {
207 uint32_t update;
209 {
210 uint32_t data;
211 uint32_t profiles;
212 } write;
213 } _controlFreqs;
214
215}; // class DistControl
216
217
218#endif /* DISTCONTROL_H_ */
Definition: CommVar.h:17
Definition: Region.h:29
Definition: DistControl.h:48
void afterForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep) override
Method afterForces will be called after forcefields have been applied no sitewise Forces can be appli...
Definition: DistControl.h:98
std::string getPluginName() override
return the name of the plugin
Definition: DistControl.h:108
void finish(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) override
Method finish will be called at the end of the simulation.
Definition: DistControl.h:105
void readXML(XMLfileUnits &xmlconfig) override
Read in XML configuration for DistControl and all its included objects.
Definition: DistControl.cpp:59
void beforeEventNewTimestep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep) override
Method will be called first thing in a new timestep.
Definition: DistControl.h:90
void beforeForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep) override
Method beforeForces will be called before forcefields have been applied no alterations w....
Definition: DistControl.cpp:236
void endStep(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain, unsigned long simstep) override
Method endStep will be called at the end of each time step.
Definition: DistControl.h:101
void init(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, Domain *domain) override
Method init will be called at the begin of the simulation.
Definition: DistControl.cpp:227
void siteWiseForces(ParticleContainer *particleContainer, DomainDecompBase *domainDecomp, unsigned long simstep) override
Method siteWiseForces will be called before forcefields have been applied alterations to sitewise for...
Definition: DistControl.h:96
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
Definition: ObserverBase.h:13
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: ObserverBase.h:20
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
Definition: DistControl.h:209