-
Notifications
You must be signed in to change notification settings - Fork 9
/
sinking.cu
134 lines (107 loc) · 5.27 KB
/
sinking.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
/**
* @author Christoph Schaefer [email protected] and Thomas I. Maindl
*
* @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 "timeintegration.h"
#include "parameter.h"
#include "miluph.h"
#include "pressure.h"
#include "config_parameter.h"
#if PARTICLE_ACCRETION
#if UPDATE_SINK_VALUES
//function adds to sink: mass and velocity (angular momentum, linear momentum) of the accreted particle and calculate the new position of sink (COM)
__device__ void UpdateSinkValues(int sink_num, int particle_id)
{
//COM - position - velocity
pointmass.x[sink_num] = (pointmass.m[sink_num]*pointmass.x[sink_num] + p.m[particle_id]*p.x[particle_id]) / (pointmass.m[sink_num] + p.m[particle_id]);
pointmass.y[sink_num] = (pointmass.m[sink_num]*pointmass.y[sink_num] + p.m[particle_id]*p.y[particle_id]) / (pointmass.m[sink_num] + p.m[particle_id]);
pointmass.vx[sink_num] = (p.m[particle_id]*p.vx[particle_id] + pointmass.m[sink_num]*pointmass.vx[sink_num]) / (p.m[particle_id] + pointmass.m[sink_num]);
pointmass.vy[sink_num] = (p.m[particle_id]*p.vy[particle_id] + pointmass.m[sink_num]*pointmass.vy[sink_num]) / (p.m[particle_id] + pointmass.m[sink_num]);
#if DIM == 3
pointmass.z[sink_num] = (pointmass.m[sink_num]*pointmass.z[sink_num] + p.m[particle_id]*p.z[particle_id]) / (pointmass.m[sink_num] + p.m[particle_id]);
pointmass.vz[sink_num] = (p.m[particle_id]*p.vz[particle_id] + pointmass.m[sink_num]*pointmass.vz[sink_num]) / (p.m[particle_id] + pointmass.m[sink_num]);
#endif //DIM == 3
pointmass.m[sink_num] += p.m[particle_id];
}
#endif //UPDATE_SINK_VALUES
//function checks if particle is to be accreted on sink particle
__global__ void ParticleSinking()
{
register int i, inc, n;
double vel_esc, vel, dist_0, dist_1, distance, h, h_circ, r_x, r_y, r_z, v_x, v_y, v_z, h_x, h_y, h_z;
inc = blockDim.x * gridDim.x;
for (i = threadIdx.x + blockIdx.x * blockDim.x; i < numParticles; i += inc) {
//look for a particle with material type = -2 and reset it to material type = -1 if it is bound to sink particle
if (p_rhs.materialId[i] == EOS_TYPE_ACCRETED) {
//distance between particle and each sink and particle velocity
#if DIM == 2
dist_0 = sqrt( (pointmass.x[0] - p.x[i])*(pointmass.x[0] - p.x[i]) + (pointmass.y[0] - p.y[i])*(pointmass.y[0] - p.y[i]) );
dist_1 = sqrt( (pointmass.x[1] - p.x[i])*(pointmass.x[1] - p.x[i]) + (pointmass.y[1] - p.y[i])*(pointmass.y[1] - p.y[i]) );
vel = sqrt(p.vx[i]*p.vx[i] + p.vy[i]*p.vy[i]);
#endif //end DIM == 2
#if DIM == 3
dist_0 = sqrt( (pointmass.x[0] - p.x[i])*(pointmass.x[0] - p.x[i]) + (pointmass.y[0] - p.y[i])*(pointmass.y[0] - p.y[i]) + (pointmass.z[0] - p.z[i])*(pointmass.z[0] - p.z[i]) );
dist_1 = sqrt( (pointmass.x[1] - p.x[i])*(pointmass.x[1] - p.x[i]) + (pointmass.y[1] - p.y[i])*(pointmass.y[1] - p.y[i]) + (pointmass.z[1] - p.z[i])*(pointmass.z[1] - p.z[i]) );
vel = sqrt(p.vx[i]*p.vx[i] + p.vy[i]*p.vy[i] + p.vz[i]*p.vz[i]);
#endif //end DIM == 3
if (dist_0 < dist_1) {
n = 0;
distance = dist_0;
}
else {
n = 1;
distance = dist_1;
}
//escape velocity at r_acc(rmin)
vel_esc = sqrt(2. * gravConst * pointmass.m[n] / distance);
//specific angular momentum of each particle about the sink particle
r_x = pointmass.x[n] - p.x[i];
r_y = pointmass.y[n] - p.y[i];
v_x = pointmass.vx[n] - p.vx[i];
v_y = pointmass.vy[n] - p.vy[i];
h_z = r_x*v_y - r_y*v_x;
#if DIM == 2
h = sqrt(h_z*h_z);
#endif //DIM ==2
#if DIM == 3
r_z = pointmass.z[n] - p.z[i];
v_z = pointmass.vz[n] - p.vz[i];
h_x = r_y*v_z - r_z*v_y;
h_y = r_z*v_x - r_x*v_z;
h = sqrt(h_x*h_x + h_y*h_y + h_z*h_z);
#endif //DIM == 3
//specific angular momentum to form circular orbit at semi-major axis
h_circ = sqrt(gravConst * pointmass.m[n] * distance);
//check if particle is to be accreted (bound) to sink: particle velocity < escape velocity && specific angular momentum of particle < angular momentum to form circular orbit
if (vel < vel_esc && h < h_circ) {
#if UPDATE_SINK_VALUES
UpdateSinkValues(n, i);
#endif //UPDATE_SINK_VALUES
p_rhs.materialId[i] = EOS_TYPE_IGNORE;
}
else {
//particle is not accreted, particle material set to inital one
p_rhs.materialId[i] = p_rhs.materialId0[i];
}
}
}
}
#endif //PARTICLE_ACCRETION