FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
tutorial/AdvancedSetup/problem1/setup.cpp at asnum2026 · idefix-code/tutorial · GitHub
idefix-code
tutorial
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
tutorial
/
AdvancedSetup
/
problem1
/
setup.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
146 lines (124 loc) · 4.52 KB
Breadcrumbs
tutorial
/
AdvancedSetup
/
problem1
/
setup.cpp
Copy path
File metadata and controls
146 lines (124 loc) · 4.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
algorithm
>
#
include
"
idefix.hpp
"
#
include
"
setup.hpp
"
namespace
SetupVariables
{
real h0;
//
The disc aspect ratio
}
void
MySoundSpeed
(DataBlock &data,
const
real t, IdefixArray3D<real> &cs) {
//
Always make local "copies" of the arrays you intent to use!
IdefixArray1D<real> x1 = data.
x
[
IDIR
];
//
NB: this is a shallow copy, it doesn't copy the data contained in the array, juste the "pointer"
real h0 = SetupVariables::h0;
//
Loop on the full domain
//
Here should come an idefix_for loop on the whole domain.
//
The idefix for should execute this kernel on each element of the array cs (=soundspeed)
KOKKOS_LAMBDA
(
int
k,
int
j,
int
i) {
real R =
x1
(i);
cs
(k,j,i) =
//
## TBF ##
}
}
//
User-defined boundaries
void
UserdefBoundary
(Fluid<DefaultPhysics> *hydro,
int
dir, BoundarySide side, real t) {
idfx::pushRegion
(
"
UserDefinedBoundary
"
);
if
(dir==
IDIR
) {
//
"always do shallow copies"
IdefixArray4D<real> Vc = hydro->
Vc
;
IdefixArray1D<real> x1 = hydro->
data
->
x
[
IDIR
];
//
the index in the active domain we use as reference
int
iref;
if
(side == left) {
iref = hydro->
data
->
beg
[
IDIR
];
}
else
if
(side==right) {
iref = hydro->
data
->
end
[
IDIR
]-
1
;
}
//
This makes an idefix_loop on the boundary elements (=ghost zones)
hydro->
boundary
->
BoundaryFor
(
"
UserDefBoundary_X1
"
, dir, side,
KOKKOS_LAMBDA
(
int
k,
int
j,
int
i) {
//
We want tho and Vr (VX1) to be equal to their value in the first active zone (index iref)
//
Vphi should be equal to the Keplerian velocity
//
Vc(RHO,k,j,i) = ## TBF ##
//
Vc(VX1,k,j,i) = ## TBF ##
//
Vc(VX2,k,j,i) = ## TBF ##
});
}
idfx::popRegion
();
}
/*
// -- Dust --
// User-defined boundaries
void UserdefBoundaryDust(Fluid<DustPhysics> *hydro, int dir, BoundarySide side, real t) {
idfx::pushRegion("UserDefinedBoundary");
if(dir==IDIR) {
// "always do shallow copies"
IdefixArray4D<real> Vc = hydro->Vc;
IdefixArray1D<real> x1 = hydro->data->x[IDIR];
// the index in the active domain we use as reference
int iref;
if(side == left) {
iref = hydro->data->beg[IDIR];
} else if (side==right) {
iref = hydro->data->end[IDIR]-1;
}
hydro->boundary->BoundaryFor("UserDefBoundary_X1Dust", dir, side,
KOKKOS_LAMBDA (int k, int j, int i) {
real R=x1(i);
real Vk = 1.0/sqrt(R);
Vc(RHO,k,j,i) = Vc(RHO,k,j,iref);
Vc(VX1,k,j,i) = Vc(VX1,k,j,iref);
Vc(VX2,k,j,i) = Vk;
});
}
idfx::popRegion();
}
*/
//
Default constructor
//
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)
{
//
Enroll the function used to define the boundary conditions
//
data.hydro->EnrollUserDefBoundary(&UserdefBoundary);
//
Enroll the function used to define the sound speed
//
data.hydro->EnrollIsoSoundSpeed(&MySoundSpeed);
//
Read the disc aspect ratio from the input file
SetupVariables::h0 = input.
Get
<real>(
"
Setup
"
,
"
h0
"
,
0
);
//
-- Dust --
//
User def boundaries for the 1st dust speciy
//
data.dust[0]->EnrollUserDefBoundary(&UserdefBoundaryDust);
}
//
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);
real h0 = SetupVariables::h0;
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 Vk=
1.0
/
sqrt
(R);
real cs2=(h0*Vk)*(h0*Vk);
d.
Vc
(
RHO
,k,j,i) =
100
/R;
//
Surface density profile
d.
Vc
(
VX1
,k,j,i) =
0.0
;
d.
Vc
(
VX2
,k,j,i) = Vk*
sqrt
(
1
-
3.0
*h0*h0);
/*
// ---Tracers ---
// We want to trace the material outside of the planet's orbital
d.Vc(TRG,k,j,i) = ## TBF ##
// --------------
*/
/*
// ---Dust grain ---
// We want the dust grains to have initially
// a density equal to 0.01 the gas density
d.dustVc[0](RHO,k,j,i) = ## TBF ##
d.dustVc[0](VX1,k,j,i) = ## TBF ##
d.dustVc[0](VX2,k,j,i) = ## TBF ##
*/
}
}
}
//
Send it all, if needed
d.
SyncToDevice
();
}
Back
|
FazBrowse Home
|
New Git URL