1 |
#include <cstring> |
2 |
#include <iostream> |
3 |
#include <fstream> |
4 |
|
5 |
#include "ReadWrite.hpp" |
6 |
#include "simError.h" |
7 |
|
8 |
|
9 |
DumpWriter::DumpWriter( SimInfo* the_entry_plug ){ |
10 |
|
11 |
#ifdef IS_MPI |
12 |
if(worldRank == TESTWRITE ){ |
13 |
#endif // is_mpi |
14 |
|
15 |
entry_plug = the_entry_plug; |
16 |
|
17 |
strcpy( outName, entry_plug->sampleName ); |
18 |
|
19 |
std::cerr << "Opening " << outName << " for dumping.\n"; |
20 |
|
21 |
outFile.open(outName, ios::out | ios::trunc ); |
22 |
|
23 |
if( !outFile ){ |
24 |
|
25 |
sprintf( painCave.errMsg, |
26 |
"Could not open \"%s\" for dump output.\n", |
27 |
outName); |
28 |
painCave.isFatal = 1; |
29 |
simError(); |
30 |
} |
31 |
|
32 |
//outFile.setf( ios::scientific ); |
33 |
|
34 |
#ifdef IS_MPI |
35 |
} |
36 |
#endif // is_mpi |
37 |
} |
38 |
|
39 |
DumpWriter::~DumpWriter( ){ |
40 |
|
41 |
#ifdef IS_MPI |
42 |
if(worldRank == TESTWRITE ){ |
43 |
#endif // is_mpi |
44 |
|
45 |
outFile.close(); |
46 |
|
47 |
#ifdef IS_MPI |
48 |
} |
49 |
#endif // is_mpi |
50 |
} |
51 |
|
52 |
void DumpWriter::writeDump( double currentTime ){ |
53 |
|
54 |
#ifdef IS_MPI |
55 |
if(worldRank == TESTWRITE ){ |
56 |
#endif // is_mpi |
57 |
|
58 |
|
59 |
int i; |
60 |
double q[4]; |
61 |
DirectionalAtom* dAtom; |
62 |
int nAtoms = entry_plug->n_atoms; |
63 |
Atom** atoms = entry_plug->atoms; |
64 |
|
65 |
|
66 |
outFile << nAtoms << "\n"; |
67 |
|
68 |
outFile << currentTime << "\t" |
69 |
<< entry_plug->box_x << "\t" |
70 |
<< entry_plug->box_y << "\t" |
71 |
<< entry_plug->box_z << "\n"; |
72 |
|
73 |
for( i=0; i<nAtoms; i++ ){ |
74 |
|
75 |
outFile |
76 |
<< atoms[i]->getType() << "\t" |
77 |
<< atoms[i]->getX() << "\t" |
78 |
<< atoms[i]->getY() << "\t" |
79 |
<< atoms[i]->getZ() << "\t" |
80 |
<< atoms[i]->get_vx() << "\t" |
81 |
<< atoms[i]->get_vy() << "\t" |
82 |
<< atoms[i]->get_vz() << "\t"; |
83 |
|
84 |
if( atoms[i]->isDirectional() ){ |
85 |
|
86 |
dAtom = (DirectionalAtom *)atoms[i]; |
87 |
dAtom->getQ( q ); |
88 |
|
89 |
outFile |
90 |
<< q[0] << "\t" |
91 |
<< q[1] << "\t" |
92 |
<< q[2] << "\t" |
93 |
<< q[3] << "\t" |
94 |
<< dAtom->getJx() << "\t" |
95 |
<< dAtom->getJy() << "\t" |
96 |
<< dAtom->getJz() << "\n"; |
97 |
} |
98 |
else{ |
99 |
outFile |
100 |
<< 0.0 << "\t" |
101 |
<< 0.0 << "\t" |
102 |
<< 0.0 << "\t" |
103 |
<< 0.0 << "\t" |
104 |
<< 0.0 << "\t" |
105 |
<< 0.0 << "\t" |
106 |
<< 0.0 << "\n"; |
107 |
} |
108 |
} |
109 |
outFile.flush(); |
110 |
|
111 |
#ifdef IS_MPI |
112 |
} |
113 |
#endif // is_mpi |
114 |
} |
115 |
|
116 |
|
117 |
|
118 |
void DumpWriter::writeFinal(){ |
119 |
|
120 |
#ifdef IS_MPI |
121 |
if(worldRank == TESTWRITE ){ |
122 |
#endif // is_mpi |
123 |
|
124 |
char finalName[500]; |
125 |
strcpy( finalName, entry_plug->finalName ); |
126 |
|
127 |
ofstream finalOut( finalName ); |
128 |
if( !finalOut ){ |
129 |
sprintf( painCave.errMsg, |
130 |
"Could not open \"%s\" for final dump output.\n", |
131 |
finalName ); |
132 |
painCave.isFatal = 1; |
133 |
simError(); |
134 |
} |
135 |
|
136 |
// finalOut.setf( ios::scientific ); |
137 |
|
138 |
|
139 |
int i; |
140 |
double q[4]; |
141 |
DirectionalAtom* dAtom; |
142 |
int nAtoms = entry_plug->n_atoms; |
143 |
Atom** atoms = entry_plug->atoms; |
144 |
|
145 |
|
146 |
finalOut << nAtoms << "\n"; |
147 |
|
148 |
finalOut << 0.0 << "\t" |
149 |
<< entry_plug->box_x << "\t" |
150 |
<< entry_plug->box_y << "\t" |
151 |
<< entry_plug->box_z << "\n"; |
152 |
|
153 |
for( i=0; i<nAtoms; i++ ){ |
154 |
|
155 |
finalOut |
156 |
<< atoms[i]->getType() << "\t" |
157 |
<< atoms[i]->getX() << "\t" |
158 |
<< atoms[i]->getY() << "\t" |
159 |
<< atoms[i]->getZ() << "\t" |
160 |
<< atoms[i]->get_vx() << "\t" |
161 |
<< atoms[i]->get_vy() << "\t" |
162 |
<< atoms[i]->get_vz() << "\t"; |
163 |
|
164 |
if( atoms[i]->isDirectional() ){ |
165 |
|
166 |
dAtom = (DirectionalAtom *)atoms[i]; |
167 |
dAtom->getQ( q ); |
168 |
|
169 |
finalOut |
170 |
<< q[0] << "\t" |
171 |
<< q[1] << "\t" |
172 |
<< q[2] << "\t" |
173 |
<< q[3] << "\t" |
174 |
<< dAtom->getJx() << "\t" |
175 |
<< dAtom->getJy() << "\t" |
176 |
<< dAtom->getJz() << "\n"; |
177 |
} |
178 |
else{ |
179 |
finalOut |
180 |
<< 0.0 << "\t" |
181 |
<< 0.0 << "\t" |
182 |
<< 0.0 << "\t" |
183 |
<< 0.0 << "\t" |
184 |
<< 0.0 << "\t" |
185 |
<< 0.0 << "\t" |
186 |
<< 0.0 << "\n"; |
187 |
} |
188 |
} |
189 |
finalOut.close(); |
190 |
|
191 |
#ifdef IS_MPI |
192 |
} |
193 |
#endif // is_mpi |
194 |
} |