ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
ERF_PlotfileToNetCDF.cpp File Reference
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <AMReX_PlotFileUtil.H>
#include <AMReX_Utility.H>
#include <AMReX_MultiFab.H>
#include "ERF_NCInterface.H"
#include "ERF_NCPlotFile.H"
Include dependency graph for ERF_PlotfileToNetCDF.cpp:

Functions

static void PrintUsage ()
 
int main_main ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Application entry point.

Parameters
[in]argcArgument count.
[in]argvArgument vector.
Returns
Execution status.
157 {
158  amrex::SetVerbose(0);
159  amrex::Initialize(argc, argv, false);
160  int status = main_main();
161  amrex::Finalize();
162  return status;
163 }
int main_main()
Definition: ERF_PlotfileToNetCDF.cpp:57
Here is the call graph for this function:

◆ main_main()

int main_main ( )

Convert a multilevel AMReX plotfile into NetCDF format.

Returns
0 on success, otherwise an error code.
58 {
59  const int narg = amrex::command_argument_count();
60 
61  if (narg == 0) {
62  PrintUsage();
63  }
64 
65  bool verbose = false;
66 
67  std::string iFile;
68  int farg = 1;
69  while (farg <= narg) {
70  const std::string fname = amrex::get_command_argument(farg);
71  if (fname == "-h" || fname == "--help") {
72  PrintUsage();
73  } else if (fname == "-v") {
74  verbose = true;
75  } else {
76  iFile = fname;
77  }
78  ++farg;
79  }
80 
81  if (iFile.empty()) {
82  amrex::Print() << "No plotfilename specified " << std::endl;
83  return 1;
84  } else {
85  // Remove trailing backslash if present
86  if (iFile.back() == '/') {
87  iFile.pop_back();
88  }
89  if (verbose) {
90  amrex::Print() << "Reading " << iFile << std::endl;
91  }
92  }
93 
94  PlotFileData pf_data(iFile);
95 
96  int finest_level = pf_data.finestLevel();
97 
98  int ncomp = pf_data.nComp();
99 
100  if (verbose) {
101  amrex::Print() << "Finished defining pf with finest level " << finest_level << " and ncomp " << ncomp << std::endl;
102  }
103 
104  const Vector<std::string>& varnames = pf_data.varNames();
105 
106  Vector<int> istep{3};
107  double time = pf_data.time();
108 
109  int max_grid_size = 64;
110 
111  Vector<MultiFab> mfvec(finest_level+1);
112  Vector<Geometry> geom(finest_level+1);
113 
114  double start_bdy_time = time;
115 
116  // A plotfile does not carry the solver configuration, and the only thing
117  // writeNCPlotFile takes from it is the mesh type. A plotfile also does not
118  // record the staggered z levels needed for a stretched mesh, so we can only
119  // write the (x,y,z) grid for a constant-dz mesh -- which is the default.
120  SolverChoice solverChoice;
121  Vector<Real> zlevels_stag;
122 
123  for (int lev = 0; lev <= finest_level; lev++)
124  {
125  mfvec[lev].define(pf_data.boxArray(lev), pf_data.DistributionMap(lev), ncomp, 0);
126 
127  for (int icomp = 0; icomp < ncomp; icomp++) {
128  MultiFab tmp_data = pf_data.get(lev, varnames[icomp]);
129  MultiFab::Copy(mfvec[lev],tmp_data,0,icomp,1,0);
130  }
131 
132  // We assume only one "subdomain" at each level that holds all the grids
133  BoxArray ba(pf_data.boxArray(lev));
134  Box bounding_region = (lev == 0) ? pf_data.probDomain(lev) : ba.minimalBox();
135 
136  // We assume only one "subdomain" at each level
137  int which = 0;
138 
139  writeNCPlotFile(lev, which, iFile, GetVecOfConstPtrs(mfvec), varnames, istep,
140  pf_data.probLo(), pf_data.probHi(), pf_data.cellSize(lev), bounding_region,
141  time, start_bdy_time, solverChoice, zlevels_stag);
142  }
143 
144  return 0;
145 }
void writeNCPlotFile(int lev, int which_subdomain, const std::string &dir, const Vector< const MultiFab * > &plotMF, const Vector< std::string > &plot_var_names, const Vector< int > &, Array< Real, AMREX_SPACEDIM > prob_lo, Array< Real, AMREX_SPACEDIM > prob_hi, Array< Real, AMREX_SPACEDIM > dx_in, const Box &subdomain, const double &time, const double &start_bdy_time, const SolverChoice &solverChoice, const Vector< Real > &zlevels_stag)
Definition: ERF_NCPlotFile.cpp:20
static void PrintUsage()
Definition: ERF_PlotfileToNetCDF.cpp:37
Definition: ERF_DataStruct.H:634

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintUsage()

static void PrintUsage ( )
static

Print the usage message and exit.

38 {
39  amrex::Print()
40  << "\n"
41  << " Convert a multilevel AMReX-formatted plotfile into one netcdf file per level \n"
42  << "\n"
43  << " usage:\n"
44  << " main*exe [-v] plotfilename\n"
45  << "\n"
46  << " optional arguments:\n"
47  << " -v verbosity : verbose if set, otherwise silent \n";
48  exit(1);
49 }

Referenced by main_main().

Here is the caller graph for this function: