ERF
Energy Research and Forecasting: An Atmospheric Modeling Code
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 dependency graph for ERF_PlotfileToNetCDF.cpp:

Functions

void writeNCPlotFile (int lev, int which, const std::string &dir, const amrex::Vector< const amrex::MultiFab * > &mf, const amrex::Vector< std::string > &plot_var_names, const amrex::Vector< int > &level_steps, amrex::Array< amrex::Real, AMREX_SPACEDIM > prob_lo, amrex::Array< amrex::Real, AMREX_SPACEDIM > prob_hi, amrex::Array< amrex::Real, AMREX_SPACEDIM > dx, const amrex::Box &bounding_region, amrex::Real time, amrex::Real start_bdy_time)
 
static void PrintUsage ()
 
void main_main ()
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)
139 {
140  amrex::SetVerbose(0);
141  amrex::Initialize(argc, argv, false);
142  main_main();
143  amrex::Finalize();
144  return 1;
145 }
void main_main()
Definition: ERF_PlotfileToNetCDF.cpp:56
Here is the call graph for this function:

◆ main_main()

void main_main ( )
57 {
58  const int narg = amrex::command_argument_count();
59 
60  if (narg == 0) {
61  PrintUsage();
62  }
63 
64  bool verbose = false;
65 
66  std::string iFile;
67  int farg = 1;
68  while (farg <= narg) {
69  const std::string fname = amrex::get_command_argument(farg);
70  if (fname == "-h" || fname == "--help") {
71  PrintUsage();
72  } else if (fname == "-v") {
73  verbose = true;
74  } else {
75  iFile = fname;
76  }
77  ++farg;
78  }
79 
80  if (iFile.empty()) {
81  amrex::Print() << "No plotfilename specified " << std::endl;
82  return;
83  } else {
84  // Remove trailing backslash if present
85  if (iFile.back() == '/') {
86  iFile.pop_back();
87  }
88  if (verbose) {
89  amrex::Print() << "Reading " << iFile << std::endl;
90  }
91  }
92 
93  PlotFileData pf_data(iFile);
94 
95  int finest_level = pf_data.finestLevel();
96 
97  int ncomp = pf_data.nComp();
98 
99  if (verbose) {
100  amrex::Print() << "Finished defining pf with finest level " << finest_level << " and ncomp " << ncomp << std::endl;
101  }
102 
103  const Vector<std::string>& varnames = pf_data.varNames();
104 
105  Vector<int> istep{3};
106  Real time = 0.;
107 
108  int max_grid_size = 64;
109 
110  Vector<MultiFab> mfvec(finest_level+1);
111  Vector<Geometry> geom(finest_level+1);
112 
113  Real start_bdy_time = time;
114 
115  for (int lev = 0; lev <= finest_level; lev++)
116  {
117  mfvec[lev].define(pf_data.boxArray(lev), pf_data.DistributionMap(lev), ncomp, 0);
118 
119  for (int icomp = 0; icomp < ncomp; icomp++) {
120  MultiFab tmp_data = pf_data.get(lev, varnames[icomp]);
121  MultiFab::Copy(mfvec[lev],tmp_data,0,icomp,1,0);
122  }
123 
124  // We assume only one "subdomain" at each level that holds all the grids
125  BoxArray ba(pf_data.boxArray(lev));
126  Box bounding_region = (lev == 0) ? pf_data.probDomain(lev) : ba.minimalBox();
127 
128  // We assume only one "subdomain" at each level
129  int which = lev;
130 
131  writeNCPlotFile(lev, which, iFile, GetVecOfConstPtrs(mfvec), varnames, istep,
132  pf_data.probLo(), pf_data.probHi(), pf_data.cellSize(lev), bounding_region, time, start_bdy_time);
133  }
134 }
static void PrintUsage()
Definition: ERF_PlotfileToNetCDF.cpp:41
void writeNCPlotFile(int lev, int which, const std::string &dir, const amrex::Vector< const amrex::MultiFab * > &mf, const amrex::Vector< std::string > &plot_var_names, const amrex::Vector< int > &level_steps, amrex::Array< amrex::Real, AMREX_SPACEDIM > prob_lo, amrex::Array< amrex::Real, AMREX_SPACEDIM > prob_hi, amrex::Array< amrex::Real, AMREX_SPACEDIM > dx, const amrex::Box &bounding_region, amrex::Real time, amrex::Real start_bdy_time)

Referenced by main().

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

◆ PrintUsage()

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

Referenced by main_main().

Here is the caller graph for this function:

◆ writeNCPlotFile()

void writeNCPlotFile ( int  lev,
int  which,
const std::string &  dir,
const amrex::Vector< const amrex::MultiFab * > &  mf,
const amrex::Vector< std::string > &  plot_var_names,
const amrex::Vector< int > &  level_steps,
amrex::Array< amrex::Real, AMREX_SPACEDIM >  prob_lo,
amrex::Array< amrex::Real, AMREX_SPACEDIM >  prob_hi,
amrex::Array< amrex::Real, AMREX_SPACEDIM >  dx,
const amrex::Box &  bounding_region,
amrex::Real  time,
amrex::Real  start_bdy_time 
)

Referenced by main_main().

Here is the caller graph for this function: