Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsetup.cpp
More file actions
294 lines (240 loc) · 9.02 KB
/
Copy pathsetup.cpp
File metadata and controls
294 lines (240 loc) · 9.02 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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
#include "idefix.hpp"
#include "setup.hpp"
real epsilonGlob;
real betaGlob;
real HidealGlob;
real AmMidGlob;
real gammaGlob;
real densityFloorGlob;
void MySourceTerm(Hydro *hydro, const real t, const real dtin) {
auto *data = hydro->data;
IdefixArray4D<real> Vc = hydro->Vc;
IdefixArray4D<real> Uc = hydro->Uc;
IdefixArray1D<real> x1=data->x[IDIR];
IdefixArray1D<real> x2=data->x[JDIR];
real epsilon = epsilonGlob;
real tauGlob=0.1;
real gamma_m1=gammaGlob-1.0;
real dt=dtin;
idefix_for("MySourceTerm",
0, data->np_tot[KDIR],
0, data->np_tot[JDIR],
0, data->np_tot[IDIR],
KOKKOS_LAMBDA (int k, int j, int i) {
real r=x1(i);
real th=x2(j);
real z=r*cos(th);
real R=r*sin(th);
real cs2, tau;
if(R>1.0) {
real csdisk = epsilon/sqrt(R);
cs2=(csdisk*csdisk);
tau= tauGlob*sqrt(R);
}
else {
real csdisk = epsilon;
cs2=(csdisk*csdisk);
tau=tauGlob;
}
// Cooling /heatig function
real Ptarget = cs2*Vc(RHO,k,j,i);
Uc(ENG,k,j,i) += -dt*(Vc(PRS,k,j,i)-Ptarget)/(tau*gamma_m1);
// Velocity relaxation
});
}
void FargoVelocity(DataBlock &data, IdefixArray2D<real> &Vphi) {
IdefixArray1D<real> x1 = data.x[IDIR];
IdefixArray1D<real> x2 = data.x[JDIR];
idefix_for("FargoVphi",0,data.np_tot[JDIR], 0, data.np_tot[IDIR],
KOKKOS_LAMBDA (int j, int i) {
Vphi(j,i) = 1.0/sqrt(x1(i)*sin(x2(j)));
});
}
void InternalBoundary(Hydro *hydro, const real t) {
auto *data = hydro->data;
IdefixArray4D<real> Vc = hydro->Vc;
IdefixArray4D<real> Vs = hydro->Vs;
IdefixArray1D<real> x1=data->x[IDIR];
IdefixArray1D<real> x2=data->x[JDIR];
real vAmax=10.0;
real densityFloor = densityFloorGlob;
idefix_for("InternalBoundary",
0, data->np_tot[KDIR],
0, data->np_tot[JDIR],
0, data->np_tot[IDIR],
KOKKOS_LAMBDA (int k, int j, int i) {
real b2=EXPAND(Vc(BX1,k,j,i)*Vc(BX1,k,j,i) , +Vc(BX2,k,j,i)*Vc(BX2,k,j,i), +Vc(BX3,k,j,i)*Vc(BX3,k,j,i) ) ;
real va2=b2/Vc(RHO,k,j,i);
real myMax=vAmax;
//if(x1(i)<1.1) myMax=myMax/50.0;
if(va2>myMax*myMax) {
real T = Vc(PRS,k,j,i)/Vc(RHO,k,j,i);
Vc(RHO,k,j,i) = b2/(myMax*myMax);
Vc(PRS,k,j,i) = T*Vc(RHO,k,j,i);
}
if(Vc(RHO,k,j,i) < densityFloor) {
real T= Vc(PRS,k,j,i)/Vc(RHO,k,j,i);
Vc(RHO,k,j,i)=densityFloor;
Vc(PRS,k,j,i)=T*Vc(RHO,k,j,i);
}
/*
real R = x1(i)*sin(x2(j));
if(R<1.0) {
Vc(VX1,k,j,i) = ZERO_F;
Vc(VX2,k,j,i) = ZERO_F;
Vc(VX3,k,j,i) = R;
}*/
});
}
// User-defined boundaries
void UserdefBoundary(Hydro *hydro, int dir, BoundarySide side, real t) {
auto *data = hydro->data;
if( (dir==IDIR) && (side == left)) {
IdefixArray4D<real> Vc = hydro->Vc;
IdefixArray4D<real> Vs = hydro->Vs;
IdefixArray1D<real> x1 = data->x[IDIR];
IdefixArray1D<real> x2 = data->x[JDIR];
int ighost = data->nghost[IDIR];
real Omega=1.0;
idefix_for("UserDefBoundary",
0, data->np_tot[KDIR],
0, data->np_tot[JDIR],
0, ighost,
KOKKOS_LAMBDA (int k, int j, int i) {
real R=x1(i)*sin(x2(j));
real z=x1(i)*cos(x2(j));
Vc(RHO,k,j,i) = Vc(RHO,k,j,ighost);
Vc(PRS,k,j,i) = Vc(PRS,k,j,ighost);
if(Vc(VX1,k,j,ighost)>=ZERO_F) Vc(VX1,k,j,i) = - Vc(VX1,k,j,2*ighost-i);
else Vc(VX1,k,j,i) = Vc(VX1,k,j,ighost);
Vc(VX2,k,j,i) = Vc(VX2,k,j,ighost);
Vc(VX3,k,j,i) = R*Omega;
});
idefix_for("UserDefBoundaryX1S",
0, data->np_tot[KDIR],
0, data->np_tot[JDIR]+1,
0, ighost,
KOKKOS_LAMBDA (int k, int j, int i) {
Vs(BX2s,k,j,i) = ZERO_F;
});
idefix_for("UserDefBoundaryX3S",
0, data->np_tot[KDIR]+1,
0, data->np_tot[JDIR],
0, ighost,
KOKKOS_LAMBDA (int k, int j, int i) {
Vs(BX3s,k,j,i) = ZERO_F;
});
}
if( dir==JDIR) {
IdefixArray4D<real> Vc = hydro->Vc;
IdefixArray4D<real> Vs = hydro->Vs;
int jghost;
int jbeg,jend;
if(side == left) {
jghost = data->beg[JDIR];
jbeg = 0;
jend = data->beg[JDIR];
//return;
}
else if(side==right) {
jghost = data->end[JDIR]-1;
jbeg=data->end[JDIR];
jend=data->np_tot[JDIR];
}
idefix_for("UserDefBoundary",
0, data->np_tot[KDIR],
jbeg, jend,
0, data->np_tot[IDIR],
KOKKOS_LAMBDA (int k, int j, int i) {
Vc(RHO,k,j,i) = Vc(RHO,k,jghost,i);
Vc(PRS,k,j,i) = Vc(PRS,k,jghost,i);
Vc(VX1,k,j,i) = ZERO_F;
Vc(VX2,k,j,i) = ZERO_F;
Vc(VX3,k,j,i) = ZERO_F;
});
idefix_for("UserDefBoundary_X1s",
0, data->np_tot[KDIR],
jbeg, jend,
0, data->np_tot[IDIR]+1,
KOKKOS_LAMBDA (int k, int j, int i) {
Vs(BX1s,k,j,i) = ZERO_F;
});
idefix_for("UserDefBoundary_X3s",
0, data->np_tot[KDIR]+1,
jbeg, jend,
0, data->np_tot[IDIR],
KOKKOS_LAMBDA (int k, int j, int i) {
Vs(BX3s,k,j,i) = ZERO_F;
});
}
}
// Default constructor
void ComputeUserVars(DataBlock & data, UserDefVariablesContainer &variables) {
// Make references to the user-defined arrays (variables is a container of IdefixHostArray3D)
// Note that the labels should match the variable names in the input file
IdefixHostArray3D<real> Er = variables["Er"];
IdefixHostArray3D<real> Eth = variables["Eth"];
Kokkos::deep_copy(Er,data.hydro->emf->Ex1);
Kokkos::deep_copy(Eth,data.hydro->emf->Ex2);
}
// Initialisation routine. Can be used to allocate
// Arrays or variables which are used later on
Setup::Setup(Input &input, Grid &grid, DataBlock &data, Output &output) {
// Set the function for userdefboundary
data.hydro->EnrollUserDefBoundary(&UserdefBoundary);
data.hydro->EnrollUserSourceTerm(&MySourceTerm);
data.hydro->EnrollInternalBoundary(&InternalBoundary);
if(data.haveFargo)
data.fargo->EnrollVelocity(&FargoVelocity);
output.EnrollUserDefVariables(&ComputeUserVars);
gammaGlob=data.hydro->eos->GetGamma();
epsilonGlob = input.Get<real>("Setup","epsilon",0);
densityFloorGlob = input.Get<real>("Setup","densityFloor",0);
}
// This routine initialize the flow
// Note that data is on the device.
// One can therefore define locally
// a datahost and sync it, if needed
void Setup::InitFlow(DataBlock &data) {
// Create a host copy
DataBlockHost d(data);
// Make vector potential
IdefixHostArray4D<real> A = IdefixHostArray4D<real>("Setup_VectorPotential", 3, data.np_tot[KDIR], data.np_tot[JDIR], data.np_tot[IDIR]);
real epsilon=0.1;
real beta=1000;
for(int k = 0; k < d.np_tot[KDIR] ; k++) {
for(int j = 0; j < d.np_tot[JDIR] ; j++) {
for(int i = 0; i < d.np_tot[IDIR] ; i++) {
real r=d.x[IDIR](i);
real th=d.x[JDIR](j);
real R=r*sin(th);
real z=r*cos(th);
real Vk=1.0/pow(R,0.5);
real cs2=(epsilon*Vk)*(epsilon*Vk);
d.Vc(RHO,k,j,i) = 1.0/(R*sqrt(R))*exp(1.0/(cs2)*(1/r-1/R));
d.Vc(PRS,k,j,i) = cs2*d.Vc(RHO,k,j,i);
d.Vc(VX1,k,j,i) = 0.0;
d.Vc(VX2,k,j,i) = 1e-1*(0.5-idfx::randm());
d.Vc(VX3,k,j,i) = Vk*sqrt(R/r-2.5*cs2);
d.Vs(BX1s,k,j,i) = 0.0;
d.Vs(BX2s,k,j,i) = 0.0;
d.Vs(BX3s,k,j,i) = 0.0;
real B0 = sqrt(2*cs2/(R*sqrt(R))/sqrt(beta));
r=d.xl[IDIR](i);
th=d.xl[JDIR](j);
R=r*sin(th);
z=r*cos(th);
A(IDIR,k,j,i) = 0.0;
A(JDIR,k,j,i) = 0.0;
A(KDIR,k,j,i) = B0*epsilon*cos(R/epsilon)*fmax(1-(z*z)/(4*R*R*epsilon*epsilon),ZERO_F);
}
}
}
// Make the field from the vector potential
d.MakeVsFromAmag(A);
// Send it all, if needed
d.SyncToDevice();
}
// Analyse data to produce an output
void MakeAnalysis(DataBlock & data) {
}
You can’t perform that action at this time.
