forked from christophmschaefer/miluphcuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
euler.cu
176 lines (159 loc) · 6.02 KB
/
euler.cu
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
/**
* @author Christoph Schaefer [email protected]
*
* @section LICENSE
* Copyright (c) 2019 Christoph Schaefer
*
* This file is part of miluphcuda.
*
* miluphcuda is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* miluphcuda is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with miluphcuda. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "euler.h"
#include "timeintegration.h"
#include "parameter.h"
#include "rhs.h"
extern __device__ double dt;
extern __device__ double endTimeD, currentTimeD;
extern double L_ini;
__global__ void integrateEuler(void)
{
register int i, inc;
inc = blockDim.x * gridDim.x;
#if GRAVITATING_POINT_MASSES
for (i = threadIdx.x + blockIdx.x * blockDim.x; i < numPointmasses; i += inc) {
pointmass.x[i] += dt * pointmass.vx[i];
#if DIM > 1
pointmass.y[i] += dt * pointmass.vy[i];
pointmass.vy[i] += dt * pointmass.ay[i];
#if DIM == 3
pointmass.z[i] += dt * pointmass.vz[i];
#endif
#endif
pointmass.vx[i] += dt * pointmass.ax[i];
#if DIM == 3
pointmass.vz[i] += dt * pointmass.az[i];
#endif
}
#endif
for (i = threadIdx.x + blockIdx.x * blockDim.x; i < numParticles; i += inc) {
#if INTEGRATE_DENSITY
p.rho[i] += dt * p.drhodt[i];
#endif
#if INTEGRATE_ENERGY
p.e[i] += dt * p.dedt[i];
#endif
#if PALPHA_POROSITY
p.alpha_jutzi[i] += dt * p.dalphadt[i];
#endif
#if SIRONO_POROSITY
p.rho_0prime[i] = p.rho_0prime[i];
p.rho_c_plus[i] = p.rho_c_plus[i];
p.rho_c_minus[i] = p.rho_c_minus[i];
p.compressive_strength[i] = p.compressive_strength[i];
p.tensile_strength[i] = p.tensile_strength[i];
p.shear_strength[i] = p.shear_strength[i];
p.K[i] = p.K[i];
p.flag_rho_0prime[i] = p.flag_rho_0prime[i];
p.flag_plastic[i] = p.flag_plastic[i];
#endif
#if INTEGRATE_SML
p.h[i] += dt * p.dhdt[i];
#endif
#if JC_PLASTICITY
p.ep[i] += dt * p.edotp[i];
p.T[i] += dt * p.dTdt[i];
#endif
#if INVISCID_SPH
p.beta[i] += dt * p.dbetadt[i];
#endif
#if SOLID
#if FRAGMENTATION
p.d[i] += dt * p.dddt[i];
#if PALPHA_POROSITY
p.damage_porjutzi[i] += dt * p.ddamage_porjutzidt[i];
p.pold[i] = p.p[i];
#endif
#endif
int k;
for (k = 0; k < DIM*DIM; k++) {
p.S[i*DIM*DIM+k] += dt * p.dSdt[i*DIM*DIM+k];
}
#endif
p.x[i] += dt * p.dxdt[i];
#if DIM > 1
p.y[i] += dt * p.dydt[i];
p.vy[i] += dt * p.ay[i];
#if DIM == 3
p.z[i] += dt * p.dzdt[i];
#endif
#endif
p.vx[i] += dt * p.ax[i];
#if DIM == 3
p.vz[i] += dt * p.az[i];
#endif
}
}
void euler()
{
// integrate
int lastTimestep = startTimestep + numberOfTimesteps;
int timestep;
int eulerstep;
double tmptimestep = param.maxtimestep;
double endTime = startTime;
currentTime = startTime;
cudaVerify(cudaMemcpyToSymbol(currentTimeD, ¤tTime, sizeof(double)));
cudaVerify(cudaMemcpyToSymbol(dt, &tmptimestep, sizeof(double)));
for (timestep = startTimestep; timestep < lastTimestep; timestep++) {
eulerstep = 0;
endTime += timePerStep;
cudaVerify(cudaMemcpyToSymbol(endTimeD, &endTime, sizeof(double)));
// checking for changes in angular momentum
if (param.angular_momentum_check > 0) {
double L_current = calculate_angular_momentum();
double L_change_relative;
if (L_ini > 0) {
L_change_relative = fabs((L_ini - L_current)/L_ini);
}
if (param.verbose) {
fprintf(stdout, "Checking angular momentum conservation.\n");
fprintf(stdout, "Initial angular momentum: %.17e\n", L_ini);
fprintf(stdout, "Current angular momentum: %.17e\n", L_current);
fprintf(stdout, "Relative change: %.17e\n", L_change_relative);
}
if (L_change_relative > param.angular_momentum_check) {
fprintf(stderr, "Conservation of angular momentum violated. Exiting.\n");
exit(111);
}
}
while (currentTime < endTime) {
fprintf(stdout, "Euler Step # %d\n", ++eulerstep);
fprintf(stdout, " currenttime: %e \t endtime: %e, integrating with euler dt: %g\n", currentTime, endTime, param.maxtimestep);
rightHandSide();
if (currentTime + param.maxtimestep > endTime) {
tmptimestep = endTime - currentTime;
cudaVerify(cudaMemcpyToSymbol(dt, &tmptimestep, sizeof(double)));
currentTime += tmptimestep;
} else {
cudaVerify(cudaMemcpyToSymbol(dt, ¶m.maxtimestep, sizeof(double)));
currentTime += param.maxtimestep;
}
cudaVerifyKernel((integrateEuler<<<numberOfMultiprocessors, NUM_THREADS_EULER_INTEGRATOR>>>()));
//step was successful --> do something (e.g. look for min/max pressure...)
afterIntegrationStep();
}
copyToHostAndWriteToFile(timestep, lastTimestep);
}
}