11#include < AMReX.H>
22#include < AMReX_FFT.H>
33#include < AMReX_PlotFileUtil.H>
4+ #include < AMReX_ParmParse.H>
45
56using namespace amrex ;
67
78int main (int argc, char * argv[])
89{
910 amrex::Initialize (argc, argv);
1011 {
12+ std::string infile, outfile;
13+ Vector<std::string> vel_labels = {AMREX_D_DECL (" velx" ," vely" ," velz" )};
14+ ParmParse pp;
15+ pp.get (" infile" ,infile);
16+ pp.get (" outfile" ,outfile);
17+ pp.queryarr (" vel_labels" ,vel_labels,0 ,3 );
1118 Geometry geom;
1219 MultiFab vx, vy, vz;
20+ Vector<Real> scaleL (3 );
1321 {
14- PlotFileData plot (" plot" );
15- geom.define (plot.probDomain (0 ),
16- RealBox (plot.probLo (), plot.probHi ()),
17- plot.coordSys (), {1 ,1 ,1 });
18- vx = plot.get (0 , " velx" );
19- vy = plot.get (0 , " vely" );
20- vz = plot.get (0 , " velz" );
21- }
22-
22+ PlotFileData plot (infile);
23+ geom.define (plot.probDomain (0 ),
24+ RealBox (plot.probLo (), plot.probHi ()),
25+ plot.coordSys (), {1 ,1 ,1 });
26+ // Read data, remove mean field
27+ vx = plot.get (0 , vel_labels[0 ]); vx.mult (1 ./vx.sum (0 ,0 ));
28+ vy = plot.get (0 , vel_labels[1 ]); vy.mult (1 ./vy.sum (0 ,0 ));
29+ vz = plot.get (0 , vel_labels[2 ]); vz.mult (1 ./vz.sum (0 ,0 ));
30+ Real L = std::min ({geom.ProbLength (0 ),
31+ geom.ProbLength (1 ),
32+ geom.ProbLength (2 )});
33+ scaleL = {AMREX_D_DECL (1 ./std::round (geom.ProbLength (0 )/L),
34+ 1 ./std::round (geom.ProbLength (1 )/L),
35+ 1 ./std::round (geom.ProbLength (2 )/L))};
36+ }
2337 cMultiFab cx, cy, cz;
2438 {
2539 // Note that the complex Hermitian output array Y has (nx/2+1,ny,nz) elements.
@@ -34,8 +48,7 @@ int main (int argc, char* argv[])
3448 fft.forward (vz, cz);
3549 }
3650
37- // For simplicity, we assume the domain is a cube, and we are not
38- // going to worry about scaling.
51+ // For simplicity, we are not going to worry about scaling.
3952
4053 int nx = geom.Domain ().length (0 );
4154 int ny = geom.Domain ().length (1 );
@@ -51,7 +64,7 @@ int main (int argc, char* argv[])
5164 int ki = i;
5265 int kj = (j <= ny/2 ) ? j : ny-j;
5366 int kk = (k <= nz/2 ) ? k : nz-k;
54- Real d = std::sqrt (Real (ki*ki+kj*kj+kk*kk));
67+ Real d = std::sqrt (Real (ki*ki*scaleL[ 0 ] +kj*kj*scaleL[ 1 ] +kk*kk*scaleL[ 2 ] ));
5568 int di = int (std::round (d));
5669 if (di < nk) {
5770 Real value = amrex::norm (cxa[b](i,j,k))
@@ -79,8 +92,8 @@ int main (int argc, char* argv[])
7992 ParallelDescriptor::ReduceRealSum (pke_h, nk);
8093
8194 if (ParallelDescriptor::IOProcessor ()) {
82- std::ofstream ofs (" spectrum.txt " );
83- for (int i = 0 ; i < nk; ++i) {
95+ std::ofstream ofs (outfile. c_str () );
96+ for (int i = 0 ; i < nk; ++i) {
8497 ofs << i << " " << pke_h[i] << " \n " ;
8598 }
8699 }
0 commit comments