|
| 1 | +#include "idefix.hpp" |
| 2 | +#include "setup.hpp" |
| 3 | + |
| 4 | + |
| 5 | +#define FILENAME "analysis.dat" |
| 6 | +real amplitude; |
| 7 | +// Analyse data to get the amplitude of the k=1 temperature perturbation |
| 8 | +void Analysis(DataBlock & data) { |
| 9 | + DataBlockHost d(data); |
| 10 | + d.SyncFromDevice(); |
| 11 | + real Tmode = 0; |
| 12 | + for(int i = d.beg[IDIR]; i < d.end[IDIR] ; i++) { |
| 13 | + real T = d.Vc(PRS,d.beg[KDIR],d.beg[JDIR],i) / d.Vc(RHO,d.beg[KDIR],d.beg[JDIR],i); |
| 14 | + Tmode += T * sin(2.0*M_PI*d.x[IDIR](i)); |
| 15 | + } |
| 16 | + Tmode = 2*Tmode/d.np_int[JDIR]; |
| 17 | + |
| 18 | + std::ofstream f; |
| 19 | + f.open(FILENAME,std::ios::app); |
| 20 | + f.precision(10); |
| 21 | + f << std::scientific << data.t << "\t" << Tmode << std::endl; |
| 22 | + f.close(); |
| 23 | + |
| 24 | +} |
| 25 | + |
| 26 | +void InternalBoundary(DataBlock& data, const real t) { |
| 27 | + IdefixArray4D<real> Vc = data.hydro.Vc; |
| 28 | + idefix_for("InternalBoundary",0,data.np_tot[KDIR],0,data.np_tot[JDIR],0,data.np_tot[IDIR], |
| 29 | + KOKKOS_LAMBDA (int k, int j, int i) { |
| 30 | + // Cancel any motion that could be happening |
| 31 | + Vc(VX1,k,j,i) = 0.0; |
| 32 | + Vc(VX2,k,j,i) = 0.0; |
| 33 | + Vc(VX3,k,j,i) = 0.0; |
| 34 | + }); |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +// Initialisation routine. Can be used to allocate |
| 39 | +// Arrays or variables which are used later on |
| 40 | +Setup::Setup(Input &input, Grid &grid, DataBlock &data, Output &output) { |
| 41 | + output.EnrollAnalysis(&Analysis); |
| 42 | + data.hydro.EnrollInternalBoundary(&InternalBoundary); |
| 43 | + |
| 44 | + amplitude = input.GetReal("Setup","amplitude",0); |
| 45 | + // Initialise the output file |
| 46 | + std::ofstream f; |
| 47 | + f.open(FILENAME,std::ios::trunc); |
| 48 | + f << "t\t\t T" << std::endl; |
| 49 | + f.close(); |
| 50 | +} |
| 51 | + |
| 52 | +// This routine initialize the flow |
| 53 | +// Note that data is on the device. |
| 54 | +// One can therefore define locally |
| 55 | +// a datahost and sync it, if needed |
| 56 | +void Setup::InitFlow(DataBlock &data) { |
| 57 | + // Create a host copy |
| 58 | + DataBlockHost d(data); |
| 59 | + |
| 60 | + |
| 61 | + for(int k = 0; k < d.np_tot[KDIR] ; k++) { |
| 62 | + for(int j = 0; j < d.np_tot[JDIR] ; j++) { |
| 63 | + for(int i = 0; i < d.np_tot[IDIR] ; i++) { |
| 64 | + |
| 65 | + d.Vc(RHO,k,j,i) = 1 - amplitude*sin(2.0*M_PI*d.x[IDIR](i)); |
| 66 | + d.Vc(VX1,k,j,i) = ZERO_F; |
| 67 | + d.Vc(PRS,k,j,i) = 1.0; |
| 68 | + |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + // Send it all, if needed |
| 74 | + d.SyncToDevice(); |
| 75 | +} |
| 76 | + |
| 77 | +// Analyse data to produce an output |
| 78 | +void MakeAnalysis(DataBlock & data) { |
| 79 | + |
| 80 | +} |
0 commit comments