-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.cpp
More file actions
81 lines (65 loc) · 2.28 KB
/
setup.cpp
File metadata and controls
81 lines (65 loc) · 2.28 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
#include "idefix.hpp"
#include "setup.hpp"
#define FILENAME "analysis.dat"
real amplitude;
// Analyse data to get the amplitude of the k=1 temperature perturbation
void Analysis(DataBlock & data) {
DataBlockHost d(data);
d.SyncFromDevice();
real Tmode = 0;
for(int i = d.beg[IDIR]; i < d.end[IDIR] ; i++) {
real T = d.Vc(PRS,d.beg[KDIR],d.beg[JDIR],i) / d.Vc(RHO,d.beg[KDIR],d.beg[JDIR],i);
Tmode += T * sin(2.0*M_PI*d.x[IDIR](i));
}
Tmode = 2*Tmode/d.np_int[JDIR];
std::ofstream f;
f.open(FILENAME,std::ios::app);
f.precision(10);
f << std::scientific << data.t << "\t" << Tmode << std::endl;
f.close();
}
void InternalBoundary(Fluid<DefaultPhysics> * hydro, const real t) {
idefix_for("InternalBoundary",0,hydro->data->np_tot[KDIR],
0,hydro->data->np_tot[JDIR],
0,hydro->data->np_tot[IDIR],
KOKKOS_LAMBDA (int k, int j, int i) {
// Cancel any motion that could be happening
hydro->Vc(VX1,k,j,i) = 0.0;
hydro->Vc(VX2,k,j,i) = 0.0;
hydro->Vc(VX3,k,j,i) = 0.0;
});
}
// 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) {
output.EnrollAnalysis(&Analysis);
data.hydro->EnrollInternalBoundary(&InternalBoundary);
amplitude = input.Get<real>("Setup","amplitude",0);
// Initialise the output file
std::ofstream f;
f.open(FILENAME,std::ios::trunc);
f << "t\t\t T" << std::endl;
f.close();
}
// 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);
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++) {
d.Vc(RHO,k,j,i) = 1 - amplitude*sin(2.0*M_PI*d.x[IDIR](i));
d.Vc(VX1,k,j,i) = ZERO_F;
d.Vc(PRS,k,j,i) = 1.0;
}
}
}
// Send it all, if needed
d.SyncToDevice();
}
// Analyse data to produce an output
void MakeAnalysis(DataBlock & data) {
}