Skip to content

Commit 159c9bb

Browse files
committed
add calculation of xyz_format
1 parent 2ae534b commit 159c9bb

File tree

3 files changed

+212
-0
lines changed

3 files changed

+212
-0
lines changed

.vscode/settings.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"files.associations": {
3+
"fstream": "cpp",
4+
"iosfwd": "cpp",
5+
"array": "cpp",
6+
"atomic": "cpp",
7+
"*.tcc": "cpp",
8+
"cctype": "cpp",
9+
"clocale": "cpp",
10+
"cmath": "cpp",
11+
"cstdarg": "cpp",
12+
"cstddef": "cpp",
13+
"cstdint": "cpp",
14+
"cstdio": "cpp",
15+
"cstdlib": "cpp",
16+
"cwchar": "cpp",
17+
"cwctype": "cpp",
18+
"deque": "cpp",
19+
"unordered_map": "cpp",
20+
"vector": "cpp",
21+
"exception": "cpp",
22+
"algorithm": "cpp",
23+
"map": "cpp",
24+
"memory": "cpp",
25+
"memory_resource": "cpp",
26+
"optional": "cpp",
27+
"string": "cpp",
28+
"string_view": "cpp",
29+
"system_error": "cpp",
30+
"tuple": "cpp",
31+
"type_traits": "cpp",
32+
"utility": "cpp",
33+
"initializer_list": "cpp",
34+
"iostream": "cpp",
35+
"istream": "cpp",
36+
"limits": "cpp",
37+
"new": "cpp",
38+
"ostream": "cpp",
39+
"sstream": "cpp",
40+
"stdexcept": "cpp",
41+
"streambuf": "cpp",
42+
"typeinfo": "cpp"
43+
}
44+
}

rho_of_lammps.cpp

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#include<iostream>
2+
#include<algorithm>
3+
#include<fstream>
4+
#include<string>
5+
#include<vector>
6+
#include<array>
7+
#include<cmath>
8+
#include <io.h>
9+
#include <direct.h>
10+
11+
int N;
12+
double Lx,Ly,Lz;
13+
std::vector<int> number_type;
14+
const int bins=1000;
15+
double rhos[bins],rhof[bins],rhosav[bins]{0},rhofav[bins]{0}; // short and long
16+
int stats=0;
17+
int save_step=100;
18+
19+
//==============================================================
20+
// Checks if directory exists
21+
//--------------------------------------------------------------
22+
void dexist(std::string dirname){
23+
if(_access(dirname.c_str(),0)==-1)
24+
_mkdir(dirname.c_str());
25+
return ;
26+
}
27+
28+
void conc(std::vector<std::array<double,3>> &x)
29+
{
30+
int zi,n_type=0;
31+
double V=Lx*Ly*Lz;
32+
double z, ADD=bins/V;
33+
for(int i=0;i<bins;i++)
34+
{
35+
rhos[i]=0;
36+
rhof[i]=0;
37+
}
38+
39+
stats ++;
40+
41+
if(stats%save_step==0)
42+
{
43+
dexist("dumps");
44+
std::string fname;
45+
fname="rho_ave"+std::to_string(stats);
46+
std::fstream write;
47+
write.open(fname,std::ios::out);
48+
for(int i=0;i<bins;i++){
49+
double z = (i+0.5)*Lx/bins;
50+
write<<z<<'\t'<<rhofav[i]<<'\t'<<rhosav[i]<<'\t'<<rhofav[i]+rhosav[i]<<std::endl;
51+
}
52+
write.close();
53+
54+
for(int i=0;i<bins;i++)
55+
{
56+
rhosav[i]=0;
57+
rhofav[i]=0;
58+
}
59+
}
60+
61+
for(int i=0;i<x.size();i++)
62+
{
63+
z=x[i][2]-std::floor(x[i][2]/Lz)*Lz;
64+
zi=bins*z/Lz;
65+
if(i>number_type[n_type])
66+
rhof[zi]+=ADD;
67+
else
68+
rhos[zi]+=ADD;
69+
}
70+
for(int i=0;i<bins;i++){
71+
rhofav[i] += (rhof[i]-rhofav[i])/(1.0*stats);
72+
rhosav[i] += (rhos[i]-rhosav[i])/(1.0*stats);
73+
}
74+
}
75+
76+
int get_para(std::fstream &read)
77+
{
78+
double low_x=0,low_y=0,low_z=0,high_x=0,high_y=0,high_z=0;
79+
std::string aline;
80+
if(!std::getline(read,aline))
81+
return 0;
82+
83+
read>>N;
84+
for(int i=0;i<8;i++)
85+
if(!std::getline(read,aline))
86+
return 0;
87+
88+
read>>low_x>>high_x;
89+
if(!std::getline(read,aline))
90+
return 0;
91+
read>>low_y>>high_y;
92+
if(!std::getline(read,aline))
93+
return 0;
94+
read>>low_z>>high_z;
95+
Lx=high_x-low_x;
96+
Ly=high_y-low_y;
97+
Lz=high_z-low_z;
98+
99+
return 1;
100+
}
101+
//设计成这样不需要new和delete
102+
int read_data(std::vector<std::array<double,3>> &x,std::fstream &read)
103+
{
104+
int NB,atom_type,old_atom_type=0;
105+
106+
std::string aline;
107+
108+
read>>NB;
109+
if(NB!=N)
110+
{
111+
std::cout<<"atom number isn't same!"<<std::endl;
112+
return 0;
113+
}
114+
115+
if(!std::getline(read,aline)) return 0;
116+
if(!std::getline(read,aline)) return 0;
117+
118+
for(int i=0;i<NB;i++)
119+
{
120+
x.push_back(std::array<double,3>{0});
121+
read>>atom_type>>x[i][0]>>x[i][1]>>x[i][2];
122+
if(atom_type!=old_atom_type)
123+
{
124+
number_type.push_back(i);
125+
old_atom_type=atom_type;
126+
}
127+
}
128+
129+
return 1;
130+
}
131+
132+
void cal_concertration(std::string readFileName,std::string dataName)
133+
{
134+
std::fstream read;
135+
read.open(readFileName,std::ios::in);
136+
if(!get_para(read))
137+
{
138+
std::cout<<"error of reading"<<std::endl;
139+
exit(-1);
140+
}
141+
142+
std::vector<std::array<double,3>> x;
143+
read.close();
144+
145+
read.open(dataName,std::ios::in);
146+
while (read_data(x,read))
147+
{
148+
149+
}
150+
151+
read.close();
152+
153+
}

xyz_to_lammps.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#include<iostream>
2+
#include<algorithm>
3+
#include<fstream>
4+
#include<string>
5+
#include<vector>
6+
7+
int read_data()
8+
{
9+
10+
}
11+
12+
int main()
13+
{
14+
15+
}

0 commit comments

Comments
 (0)