-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDumpClass.cpp
More file actions
181 lines (141 loc) · 5.35 KB
/
DumpClass.cpp
File metadata and controls
181 lines (141 loc) · 5.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <iostream>
#include <fstream>
#include "LammpsUtilities.h"
DumpClass::DumpClass()
{
this->numberOfHeaderLines = 9;
this->headerInfo = new std::string[this->numberOfHeaderLines];
}
DumpClass::DumpClass(std::string *headInfo,int numAtoms, std::string *atomHeader)
{
this->numberOfHeaderLines = 9;
this->numberOfAtoms = numAtoms;
this->headerInfo = new std::string[this->numberOfHeaderLines];
//std::cout<< atomHeader << std::endl;
for(int i =0 ; i < this->numberOfHeaderLines-1; ++i){
if(i!=3){
this->headerInfo[i] = headInfo[i];
}else{
this->headerInfo[3] = std::to_string(this->numberOfAtoms);
}
} // Initializes the hearder information string
this->headerInfo[8] = *atomHeader; //Final header information
this->atoms = new AtomClass[numAtoms]; //Initializes the atom class
}
void DumpClass::readDumpFile(int numLammpsItems, std::string filePath)
{
std::ifstream inFile(filePath);
std::string line;
for (int i = 0; i < 9; i++) {
getline(inFile, line);
this->headerInfo[i] = line;
//std::cout << this->headerInfo[i] << std::endl;
}
try{
// For the time step given int he dump files
//std::cout<< this->headerInfo[1] << std::endl;
//std::cout<< this->headerInfo[3] << std::endl;
this->timeStep = std::stoi(this->headerInfo[1]);
// Total number of atoms given in the dump files
this->numberOfAtoms = std::stoi(this->headerInfo[3]);
}catch(std::exception e)
{
std::cout << "Bad string! Error in string to integer/double conversion" << std::endl;
std::cout << e.what() << std::endl;
}
this->lammpsItemsList = parseDump(this->headerInfo[8], numLammpsItems+2); // header info for all per atom quantities (e.g. represented by AtomInfo )
this->totalLinesInFile = this->numberOfAtoms + this->numberOfHeaderLines; //Total number of lines present in the dump file
// This one gets data from individual rows, containing per atom info like coordinates, energies etc., from the dump file.
this->AtomInfo = new std::string[this->numberOfAtoms];
for (int i = 9; i < this->totalLinesInFile ; i++) {
getline(inFile, line);
this->AtomInfo[i-9] = line;
}
this->atoms = new AtomClass[this->numberOfAtoms]; // Each row of atom data is stored in a class named AtomClass
std::string *tempAtomQuantList;
for(int i = 0; i < this->numberOfAtoms; ++i)
//for(int i = 0; i < 2; ++i) //For testing
{
tempAtomQuantList = parseDump(this->AtomInfo[i], numLammpsItems);
// each row of per-atom data is saved in the variables defined in the atom class
this->atoms[i].readAtomValues(numLammpsItems, this->lammpsItemsList, tempAtomQuantList);
//this->atoms[i].writeAtomData();
tempAtomQuantList = NULL;
}
}
void DumpClass::setAtomInfo(AtomClass *AtomArrayData)
{
for(int i = 0; i < this->numberOfAtoms; ++i){
//std::cout << "Inside" <<std::endl;
atoms[i].id = AtomArrayData[i].id;
atoms[i].type = AtomArrayData[i].type;
atoms[i].xpos = AtomArrayData[i].xpos;
atoms[i].ypos = AtomArrayData[i].ypos;
atoms[i].zpos = AtomArrayData[i].zpos;
atoms[i].vol = AtomArrayData[i].vol;
atoms[i].csym = AtomArrayData[i].csym;
atoms[i].pe = AtomArrayData[i].pe;
for(int j = 0; j < 8; ++j){
//std::cout << "More Inside" <<std::endl;
atoms[i].sij[j] = AtomArrayData[i].sij[j];
atoms[i].delSij[j] = AtomArrayData[i].delSij[j];
}
}
}
std::string *DumpClass::getAtomInfoAsString()
{
std::string* atomData = new std::string[this->numberOfAtoms];
for(int i = 0; i < this->numberOfAtoms; ++i){
try{
atomData[i] = std::to_string(atoms[i].id) + " " + std::to_string(atoms[i].type) + " " + std::to_string(atoms[i].xpos) + " " + \
std::to_string(atoms[i].ypos) + " " + std::to_string(atoms[i].zpos) + " " + std::to_string(atoms[i].pe)+ " " + std::to_string(atoms[i].vol) + " " + \
std::to_string(atoms[i].sij[0]) + " " + std::to_string(atoms[i].sij[1]) + " " + std::to_string(atoms[i].sij[2]) + " " + \
std::to_string(atoms[i].sij[3]) + " " + std::to_string(atoms[i].sij[4]) + " " + std::to_string(atoms[i].sij[5]) + " " + \
std::to_string(atoms[i].sij[6]) + " " + std::to_string(atoms[i].sij[7]);
//std::cout<<"pe "<< atoms[i].pe << " " << std::to_string(atoms[i].pe) << std::endl;
}catch(std::exception e)
{
std::cout << "Bad string! Error in integer/double to string conversion" << std::endl;
return 0;
}
}
return atomData;
}
//Print out the dheader information for debuggin purposes
void DumpClass::writeHeaderInfo()
{
for(int i = 0; i < this->numberOfHeaderLines; ++i){
std::cout<< this->headerInfo[i] << std::endl;
}
}
void DumpClass::writeAtomInfo()
{
std::string* atomData = this->getAtomInfoAsString();
for(int i = 0; i < this->numberOfAtoms; ++i){
std::cout<< atomData[i] << std::endl;
}
}
void DumpClass::printDumpFile()
{
this->writeHeaderInfo();
this->writeAtomInfo();
}
std::vector<long> DumpClass::getAtomIDVector()
{
std::vector<long> atomID = std::vector<long>();
for(int i = 0; i < this->numberOfAtoms; i++){
atomID.push_back(this->atoms[i].id);
}
return atomID;
}
AtomClass* DumpClass::getAtomInfoClass()
{
return atoms;
}
DumpClass::~DumpClass()
{
delete []this->headerInfo;
delete []this->AtomInfo;
delete []this->lammpsItemsList;
delete []this->atoms;
}