forked from rosamu/SPH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPH.cpp
178 lines (176 loc) · 4.7 KB
/
SPH.cpp
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
//============================================================================
// Name : SPH.cpp
// Author : Tongfei Guo
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include <fstream>
#include "SPH.h"
#include <string>
#include "STORAGE.h"
#include "SOLVE.h"
#include "EOS.h"
#include "KERNEL.h"
#include "mpi.h"
using namespace std;
int main(int argc, char **argv) {
STORAGE store;
SOLVE_BASE *solve;
EOS_BASE *equation_of_state;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD,&store.NumOfCpu);
MPI_Comm_rank(MPI_COMM_WORLD,&store.id);
// MPI::Init ( argc, argv );
//
// store.id = MPI::COMM_WORLD.Get_rank ( );
//
// store.NumOfCpu = MPI::COMM_WORLD.Get_size ( );
istringstream line;
if (argv[1][1] == 'i')
{
string input(argv[2]);
store.PN = 1;
store.PM = 1;
store.PL = 1;
store.Initialization(input);
}
else
{
if (argv[2][0] == '3')
{
//store.PN = argv[4][0] - 48;
//store.PM = argv[5][0] - 48;
//store.PL = argv[6][0] - 48;
string input = argv[4];
line.clear();
line.str(input);
line>>store.PN;
line.clear();
input = argv[5];
line.clear();
line.str(input);
line>>store.PM;
line.clear();
store.PL = argv[6][0] - 48;
input=argv[8];
store.Initialization(input);
}
else if (argv[2][0] == '2')
{
store.PN = argv[4][0] - 48;
store.PM = 1;
store.PL = argv[5][0] - 48;
string input(argv[7]);
store.Initialization(input);
}
else
{
store.PN = argv[4][0] - 48;
store.PM = 1;
store.PL = 1;
string input(argv[6]);
store.Initialization(input);
}
}
//PetscInitialize(&argc,&argv,PETSC_NULL,PETSC_NULL);
MPI_Barrier(MPI_COMM_WORLD);
if (store.i_EoS == 4)
equation_of_state = new EOS_SPOLY(&store);
else if (store.i_EoS == 1)
equation_of_state = new EOS_TAIT(&store);
else
{
assert(0);
}
if (store.i_algorithm == 1)
solve = new SOLVE_PREDICTOR_CORRECTOR(&store,equation_of_state);
if (store.i_kernel == 3)
solve->kernel_func=new KERNEL_CUBIC(&store);
else if (store.i_kernel == 5)
solve->kernel_func=new KERNEL_WENDLAND5(&store);
else
{solve->kernel_func = NULL;}
if (store.i_kernelcorrection == 0)
solve->kernel_correction_func = new KERNEL_CORRECTION_NC(&store);
else
{assert(0);}
solve->initialization();
string output;
if (argv[3][1] == 'o')
output = argv[4];
else
output = argv[10];
char filename[200];
sprintf(filename,"%s",output.c_str());
if (store.PN * store.PM * store.PL != 1)
sprintf(filename,"%s-nd%s",output.c_str(),store.right_flush(store.id,4));
ofstream myfile(filename);
double wtime = 0;
double wtime_init = 0;
if (store.id == 0)
{
wtime_init = MPI_Wtime();
}
MPI_Barrier(MPI_COMM_WORLD);
if (store.i_restartRun == 1)
{
store.interior_read(solve->itime,solve->dt,solve->time);
MPI_Barrier(MPI_COMM_WORLD);
}
store.divide(0,store.nbb1,1);
store.i_SR_step = 0;
store.SendRecvBuffer();
solve->parallelinitialization();
store.detail = 0;
if (store.i_restartRun != 1)
{
store.print_out(0,0,output.c_str());
store.StatesPrint(0,0,"Density",output.c_str());
store.StatesPrint(0,0,"Pressure",output.c_str());
store.StatesPrint(0,0,"Interface",output.c_str());
}
MPI_Barrier(MPI_COMM_WORLD);
assert(0);
while (solve->time < store.tmax && solve->itime < 40000)
{
solve->ModifyDtForPrint();
solve->time+=solve->dt;
solve->itime++;
store.t = solve->time;
solve->step();
wtime = MPI_Wtime ( ) - wtime_init;
myfile<<" Time is "<<solve->time<<" Step is "<<solve->itime<<" Next dt is "<< solve->dt<<" Actual Time is"<<wtime<<endl;
if (wtime > store.interior_print_out_time_interval)
{
store.interior_print_out_time_interval += 1800;
store.interior_print_out(solve->itime,solve->dt,solve->time);
}
if (store.i_output == 1)
{
store.i_output = 0;
store.print_out(store.nprint,solve->time,output.c_str());
store.StatesPrint(store.nprint,solve->time,"Density",output.c_str());
store.StatesPrint(store.nprint,solve->time,"Pressure",output.c_str());
store.StatesPrint(store.nprint,solve->time,"Interface",output.c_str());
}
}
if (solve->time < store.tmax)
{
store.print_out(++store.nprint,solve->time,output.c_str());
store.StatesPrint(store.nprint,solve->time,"Density",output.c_str());
store.StatesPrint(store.nprint,solve->time,"Pressure",output.c_str());
store.StatesPrint(store.nprint,solve->time,"Interface",output.c_str());
}
if (store.id == 0)
{
wtime = MPI_Wtime ( ) - wtime_init;
myfile<< " Wall clock elapsed seconds = " << wtime << endl;
cout << "\n";
cout << " Wall clock elapsed seconds = " << wtime << endl;
}
myfile.close();
MPI_Finalize();
return 0;
}