ls1-MarDyn
ls1-MarDyn molecular dynamics code
ParticlePairs2PotForceAdapter.h
1
2#ifndef PARTICLEPAIRS2POTFORCEADAPTER_H_
3#define PARTICLEPAIRS2POTFORCEADAPTER_H_
4
5#include "molecules/potforce.h"
6#include "particleContainer/handlerInterfaces/ParticlePairsHandler.h"
7#include "io/RDF.h"
8#include "Domain.h"
9#include "WrapOpenMP.h"
10
21public:
24 _domain(domain), _virial(0.0), _upot6LJ(0.0), _upotXpoles(0.0), _myRF(0.0) {
25 //this->_doRecordRDF = false;
26
27 const int numThreads = mardyn_get_max_threads();
28 Log::global_log->info() << "ParticlePairs2PotForceAdapter: allocate data for " << numThreads << " threads." << std::endl;
29 _threadData.resize(numThreads);
30 #if defined(_OPENMP)
31 #pragma omp parallel
32 #endif
33 {
34 PP2PFAThreadData * myown = new PP2PFAThreadData();
35 const int myid = mardyn_get_thread_num();
36 _threadData[myid] = myown;
37 } // end pragma omp parallel
38 }
39
42 #if defined(_OPENMP)
43 #pragma omp parallel
44 #endif
45 {
46 const int myid = mardyn_get_thread_num();
47 delete _threadData[myid];
48 } // end pragma omp parallel
49 }
50
56 void init() {
57 _virial = 0;
58 _upot6LJ = 0;
59 _upotXpoles = 0;
60 _myRF = 0;
61
62 #if defined(_OPENMP)
63 #pragma omp parallel
64 #endif
65 {
66 const int myid = mardyn_get_thread_num();
67 _threadData[myid]->initComp2Param(_domain.getComp2Params());
68 _threadData[myid]->clear();
69 }
70 }
71
76 void finish() {
77 double glob_virial = 0.0;
78 double glob_upot6LJ = 0.0;
79 double glob_upotXpoles = 0.0;
80 double glob_myRF = 0.0;
81
82 #if defined(_OPENMP)
83 #pragma omp parallel reduction(+:glob_virial, glob_upot6LJ, glob_upotXpoles, glob_myRF)
84 #endif
85 {
86 const int myid = mardyn_get_thread_num();
87 glob_virial += _threadData[myid]->_virial;
88 glob_upot6LJ += _threadData[myid]->_upot6LJ;
89 glob_upotXpoles += _threadData[myid]->_upotXpoles;
90 glob_myRF += _threadData[myid]->_myRF;
91 } // end pragma omp parallel reduction
92
93 _virial = glob_virial;
94 _upot6LJ = glob_upot6LJ;
95 _upotXpoles = glob_upotXpoles;
96 _myRF = glob_myRF;
97
98 _domain.setLocalUpot(_upot6LJ / 6. + _upotXpoles + _myRF);
99 _domain.setLocalVirial(_virial + 3.0 * _myRF);
100 }
101
103 PP2PFAThreadData() : _virial(0.0), _upot6LJ(0.0), _upotXpoles(0.0), _myRF(0.0), _comp2Param(0) {}
104
106 if(_comp2Param != 0) {
107 delete _comp2Param;
108 _comp2Param = 0;
109 }
110 }
111
112 void initComp2Param(Comp2Param& c2p) {
113 if (_comp2Param != 0) {
114 delete _comp2Param;
115 }
116 _comp2Param = new Comp2Param(c2p);
117 }
118
119 void clear() {
120 _virial = 0.0;
121 _upot6LJ = 0.0;
122 _upotXpoles = 0.0;
123 _myRF = 0.0;
124 }
125
126 double _virial;
127 double _upot6LJ;
128 double _upotXpoles;
129 double _myRF;
130 Comp2Param * _comp2Param;
131 };
132
133 std::vector<PP2PFAThreadData *> _threadData;
134
150 double processPair(Molecule& molecule1, Molecule& molecule2, double distanceVector[3], PairType pairType, double dd, bool calculateLJ = true) {
151 const int tid = mardyn_get_thread_num();
152 PP2PFAThreadData &my_threadData = *_threadData[tid];
153
154 ParaStrm& params = (* my_threadData._comp2Param)(molecule1.componentid(), molecule2.componentid());
155 params.reset_read();
156
157 switch (pairType) {
158
159 double dummy1, dummy2, dummy3, dummy4[3], Virial3[3];
160
161 case MOLECULE_MOLECULE :
162// if ( _rdf != NULL ) _rdf->observeRDF(molecule1, molecule2, dd); // moved to RDFCellProcessor
163 PotForce(molecule1, molecule2, params, distanceVector, my_threadData._upot6LJ, my_threadData._upotXpoles, my_threadData._myRF, Virial3, calculateLJ );
164 my_threadData._virial += 2*(Virial3[0]+Virial3[1]+Virial3[2]);
165 return my_threadData._upot6LJ + my_threadData._upotXpoles;
166 case MOLECULE_HALOMOLECULE :
167
168 PotForce(molecule1, molecule2, params, distanceVector, dummy1, dummy2, dummy3, dummy4, calculateLJ);
169 return 0.0;
170 case MOLECULE_MOLECULE_FLUID :
171 dummy1 = 0.0; // 6*U_LJ
172 dummy2 = 0.0; // U_polarity
173 dummy3 = 0.0; // U_dipole_reaction_field
174
175 FluidPot(molecule1, molecule2, params, distanceVector, dummy1, dummy2, dummy3, calculateLJ);
176 return dummy1 / 6.0 + dummy2 + dummy3;
177 default:
178 Simulation::exit(666);
179 }
180 return 0.0;
181 }
182
183
184// void recordRDF() {
185// this->_doRecordRDF = true;
186// }
187
188private:
190 Domain& _domain;
191
193 double _virial;
195 double _upot6LJ;
197 double _upotXpoles;
199 double _myRF;
200
201// bool _doRecordRDF;
202};
203
204#endif /*PARTICLEPAIRS2POTFORCEADAPTER_H_*/
Definition: Comp2Param.h:15
This class is used to read in the phasespace and to handle macroscopic values.
Definition: Domain.h:47
void setLocalVirial(double Virial)
set the virial of the local process
Definition: Domain.cpp:113
void setLocalUpot(double Upot)
set the potential of the local process
Definition: Domain.cpp:109
Comp2Param & getComp2Params()
get the parameter streams
Definition: Domain.cpp:147
FullMolecule modeled as LJ sphere with point polarities.
Definition: FullMolecule.h:18
Definition: ParaStrm.h:21
void reset_read()
reset reading "pointer" to the beginning of the stream
Definition: ParaStrm.h:51
calculate pair forces and collect macroscopic values
Definition: ParticlePairs2PotForceAdapter.h:20
double processPair(Molecule &molecule1, Molecule &molecule2, double distanceVector[3], PairType pairType, double dd, bool calculateLJ=true)
Definition: ParticlePairs2PotForceAdapter.h:150
void init()
initialize macroscopic values
Definition: ParticlePairs2PotForceAdapter.h:56
void finish()
calculate macroscopic values
Definition: ParticlePairs2PotForceAdapter.h:76
~ParticlePairs2PotForceAdapter()
Destructor.
Definition: ParticlePairs2PotForceAdapter.h:41
ParticlePairs2PotForceAdapter(Domain &domain)
Constructor.
Definition: ParticlePairs2PotForceAdapter.h:23
interface for defining the action performed when processing a pair
Definition: ParticlePairsHandler.h:38
static void exit(int exitcode)
Terminate simulation with given exit code.
Definition: Simulation.cpp:155
Definition: ParticlePairs2PotForceAdapter.h:102