ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/SimInfo.cpp
Revision: 490
Committed: Fri Apr 11 15:16:59 2003 UTC (21 years, 3 months ago) by gezelter
File size: 3955 byte(s)
Log Message:
Bug fix in progress for NPT

File Contents

# Content
1 #include <cstdlib>
2 #include <cstring>
3
4
5 #include "SimInfo.hpp"
6 #define __C
7 #include "fSimulation.h"
8 #include "simError.h"
9
10 #include "fortranWrappers.hpp"
11
12 #ifdef IS_MPI
13 #include "mpiSimulation.hpp"
14 #endif
15
16 SimInfo* currentInfo;
17
18 SimInfo::SimInfo(){
19 excludes = NULL;
20 n_constraints = 0;
21 n_oriented = 0;
22 n_dipoles = 0;
23 ndf = 0;
24 ndfRaw = 0;
25 the_integrator = NULL;
26 setTemp = 0;
27 thermalTime = 0.0;
28 rCut = 0.0;
29
30 usePBC = 0;
31 useLJ = 0;
32 useSticky = 0;
33 useDipole = 0;
34 useReactionField = 0;
35 useGB = 0;
36 useEAM = 0;
37
38 wrapMeSimInfo( this );
39 }
40
41 void SimInfo::setBox(double newBox[3]) {
42 double smallestBox, maxCutoff;
43 int status;
44 box_x = newBox[0];
45 box_y = newBox[1];
46 box_z = newBox[2];
47 setFortranBoxSize(newBox);
48
49 smallestBox = box_x;
50 if (box_y < smallestBox) smallestBox = box_y;
51 if (box_z < smallestBox) smallestBox = box_z;
52
53 maxCutoff = smallestBox / 2.0;
54
55 if (rList > maxCutoff) {
56 sprintf( painCave.errMsg,
57 "New Box size is forcing neighborlist radius down to %lf\n",
58 maxCutoff );
59 painCave.isFatal = 0;
60 simError();
61
62 rList = maxCutoff;
63
64 sprintf( painCave.errMsg,
65 "New Box size is forcing cutoff radius down to %lf\n",
66 maxCutoff - 1.0 );
67 painCave.isFatal = 0;
68 simError();
69
70 rCut = rList - 1.0;
71
72 // list radius changed so we have to refresh the simulation structure.
73 refreshSim();
74 }
75
76 if (rCut > maxCutoff) {
77 sprintf( painCave.errMsg,
78 "New Box size is forcing cutoff radius down to %lf\n",
79 maxCutoff );
80 painCave.isFatal = 0;
81 simError();
82
83 status = 0;
84 LJ_new_rcut(&rCut, &status);
85 if (status != 0) {
86 sprintf( painCave.errMsg,
87 "Error in recomputing LJ shifts based on new rcut\n");
88 painCave.isFatal = 1;
89 simError();
90 }
91 }
92 }
93
94 void SimInfo::getBox(double theBox[3]) {
95 theBox[0] = box_x;
96 theBox[1] = box_y;
97 theBox[2] = box_z;
98 }
99
100 int SimInfo::getNDF(){
101 int ndf_local, ndf;
102
103 ndf_local = 3 * n_atoms + 3 * n_oriented - n_constraints;
104
105 #ifdef IS_MPI
106 MPI_Allreduce(&ndf_local,&ndf,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
107 #else
108 ndf = ndf_local;
109 #endif
110
111 ndf = ndf - 3;
112
113 return ndf;
114 }
115
116 int SimInfo::getNDFraw() {
117 int ndfRaw_local, ndfRaw;
118
119 // Raw degrees of freedom that we have to set
120 ndfRaw_local = 3 * n_atoms + 3 * n_oriented;
121
122 #ifdef IS_MPI
123 MPI_Allreduce(&ndfRaw_local,&ndfRaw,1,MPI_INT,MPI_SUM, MPI_COMM_WORLD);
124 #else
125 ndfRaw = ndfRaw_local;
126 #endif
127
128 return ndfRaw;
129 }
130
131 void SimInfo::refreshSim(){
132
133 simtype fInfo;
134 int isError;
135 int n_global;
136 int* excl;
137
138 fInfo.rrf = 0.0;
139 fInfo.rt = 0.0;
140 fInfo.dielect = 0.0;
141
142 fInfo.box[0] = box_x;
143 fInfo.box[1] = box_y;
144 fInfo.box[2] = box_z;
145
146 fInfo.rlist = rList;
147 fInfo.rcut = rCut;
148
149 if( useDipole ){
150 fInfo.rrf = ecr;
151 fInfo.rt = ecr - est;
152 if( useReactionField )fInfo.dielect = dielectric;
153 }
154
155 fInfo.SIM_uses_PBC = usePBC;
156 //fInfo.SIM_uses_LJ = 0;
157 fInfo.SIM_uses_LJ = useLJ;
158 fInfo.SIM_uses_sticky = useSticky;
159 //fInfo.SIM_uses_sticky = 0;
160 fInfo.SIM_uses_dipoles = useDipole;
161 //fInfo.SIM_uses_dipoles = 0;
162 //fInfo.SIM_uses_RF = useReactionField;
163 fInfo.SIM_uses_RF = 0;
164 fInfo.SIM_uses_GB = useGB;
165 fInfo.SIM_uses_EAM = useEAM;
166
167 excl = Exclude::getArray();
168
169 #ifdef IS_MPI
170 n_global = mpiSim->getTotAtoms();
171 #else
172 n_global = n_atoms;
173 #endif
174
175 isError = 0;
176
177 setFsimulation( &fInfo, &n_global, &n_atoms, identArray, &n_exclude, excl,
178 &nGlobalExcludes, globalExcludes, molMembershipArray,
179 &isError );
180
181 if( isError ){
182
183 sprintf( painCave.errMsg,
184 "There was an error setting the simulation information in fortran.\n" );
185 painCave.isFatal = 1;
186 simError();
187 }
188
189 #ifdef IS_MPI
190 sprintf( checkPointMsg,
191 "succesfully sent the simulation information to fortran.\n");
192 MPIcheckPoint();
193 #endif // is_mpi
194
195 this->ndf = this->getNDF();
196 this->ndfRaw = this->getNDFraw();
197
198 }
199