REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_Plotfile.cpp
Go to the documentation of this file.
1#include <REMORA.H>
2#include "AMReX_Interp_3D_C.H"
3#include "AMReX_PlotFileUtil.H"
4
5using namespace amrex;
6
7PhysBCFunctNoOp null_bc_for_fill;
8
9template<typename V, typename T>
10bool containerHasElement(const V& iterable, const T& query) {
11 return std::find(iterable.begin(), iterable.end(), query) != iterable.end();
12}
13
14/**
15 * @param pp_plot_var_names list of variable names to plot read in from parameter file
16 */
17void
18REMORA::setPlotVariables (const std::string& pp_plot_var_names)
19{
20 ParmParse pp(pp_prefix);
21
22 if (pp.contains(pp_plot_var_names.c_str()))
23 {
24 std::string nm;
25
26 int nPltVars = pp.countval(pp_plot_var_names.c_str());
27
28 for (int i = 0; i < nPltVars; i++)
29 {
30 pp.get(pp_plot_var_names.c_str(), nm, i);
31
32 // Add the named variable to our list of plot variables
33 // if it is not already in the list
35 plot_var_names.push_back(nm);
36 }
37 }
38 } else {
39 //
40 // The default is to add none of the variables to the list
41 //
42 plot_var_names.clear();
43 }
44
45 // Get state variables in the same order as we define them,
46 // since they may be in any order in the input list
47 Vector<std::string> tmp_plot_names;
48
49 for (int i = 0; i < NCONS; ++i) {
51 tmp_plot_names.push_back(cons_names[i]);
52 }
53 }
54 // Check for velocity since it's not in cons_names
55 // If we are asked for any velocity component, we will need them all
56 if (containerHasElement(plot_var_names, "x_velocity") ||
57 containerHasElement(plot_var_names, "y_velocity") ||
58 containerHasElement(plot_var_names, "z_velocity")) {
59 tmp_plot_names.push_back("x_velocity");
60 tmp_plot_names.push_back("y_velocity");
61 tmp_plot_names.push_back("z_velocity");
62 }
63
64 // If we are asked for any location component, we will provide them all
68 tmp_plot_names.push_back("x_cc");
69 tmp_plot_names.push_back("y_cc");
70 tmp_plot_names.push_back("z_cc");
71 }
72
73 for (int i = 0; i < derived_names.size(); ++i) {
75 tmp_plot_names.push_back(derived_names[i]);
76 } // if
77 } // i
78
79#ifdef REMORA_USE_PARTICLES
80 const auto& particles_namelist( particleData.getNamesUnalloc() );
81 for (auto it = particles_namelist.cbegin(); it != particles_namelist.cend(); ++it) {
82 std::string tmp( (*it)+"_count" );
84 tmp_plot_names.push_back(tmp);
85 }
86 }
87#endif
88
89 // Check to see if we found all the requested variables
90 for (auto plot_name : plot_var_names) {
91 if (!containerHasElement(tmp_plot_names, plot_name)) {
92 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' but it is not available");
93 }
94 }
95 plot_var_names = tmp_plot_names;
96}
97
98/**
99 * @param pp_plot_var_names variables to add to plot list
100 */
101void
102REMORA::appendPlotVariables (const std::string& pp_plot_var_names)
103{
104 ParmParse pp(pp_prefix);
105
106 if (pp.contains(pp_plot_var_names.c_str())) {
107 std::string nm;
108 int nPltVars = pp.countval(pp_plot_var_names.c_str());
109 for (int i = 0; i < nPltVars; i++) {
110 pp.get(pp_plot_var_names.c_str(), nm, i);
111 // Add the named variable to our list of plot variables
112 // if it is not already in the list
114 plot_var_names.push_back(nm);
115 }
116 }
117 }
118
119 Vector<std::string> tmp_plot_names(0);
120#ifdef REMORA_USE_PARTICLES
121 Vector<std::string> particle_mesh_plot_names;
122 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
123 for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
124 std::string tmp(particle_mesh_plot_names[i]);
126 tmp_plot_names.push_back(tmp);
127 }
128 }
129#endif
130
131 for (int i = 0; i < tmp_plot_names.size(); i++) {
132 plot_var_names.push_back( tmp_plot_names[i] );
133 }
134
135 // Finally, check to see if we found all the requested variables
136 for (const auto& plot_name : plot_var_names) {
137 if (!containerHasElement(plot_var_names, plot_name)) {
138 if (amrex::ParallelDescriptor::IOProcessor()) {
139 Warning("\nWARNING: Requested to plot variable '" + plot_name + "' but it is not available");
140 }
141 }
142 }
143}
144
145// Write plotfile to disk
146void
148{
149 Vector<std::string> varnames;
150 varnames.insert(varnames.end(), plot_var_names.begin(), plot_var_names.end());
151
152 const int ncomp_mf = varnames.size();
153 const auto ngrow_vars = IntVect(NGROW-1,NGROW-1,0);
154
155 if (ncomp_mf == 0) {
156 return;
157 }
158
159 // We fillpatch here because some of the derived quantities require derivatives
160 // which require ghost cells to be filled. Don't fill the boundary, though.
161 for (int lev = 0; lev <= finest_level; ++lev) {
162 FillPatchNoBC(lev, t_new[lev], *cons_new[lev], cons_new, BdyVars::t,0,true,false);
163 FillPatchNoBC(lev, t_new[lev], *xvel_new[lev], xvel_new, BdyVars::u,0,true,false);
164 FillPatchNoBC(lev, t_new[lev], *yvel_new[lev], yvel_new, BdyVars::v,0,true,false);
165 FillPatchNoBC(lev, t_new[lev], *zvel_new[lev], zvel_new, BdyVars::null,0,true,false);
166 }
167
168 Real fill_value = 0.0_rt;
169 for (int lev = 0; lev <= finest_level; ++lev) {
170 mask_arrays_for_write(lev, (Real) fill_value, 0.0_rt);
171 }
172
173 // Array of MultiFabs to hold the plotfile data
174 Vector<MultiFab> mf(finest_level+1);
175 for (int lev = 0; lev <= finest_level; ++lev) {
176 mf[lev].define(grids[lev], dmap[lev], ncomp_mf, ngrow_vars);
177 }
178
179 // Array of MultiFabs for nodal data
180 Vector<MultiFab> mf_nd(finest_level+1);
181 for (int lev = 0; lev <= finest_level; ++lev) {
182 BoxArray nodal_grids(grids[lev]); nodal_grids.surroundingNodes();
183 mf_nd[lev].define(nodal_grids, dmap[lev], AMREX_SPACEDIM, 0);
184 mf_nd[lev].setVal(0.);
185 }
186
187 // Array of MultiFabs for cell-centered velocity
188 Vector<MultiFab> mf_cc_vel(finest_level+1);
189
190 if (containerHasElement(plot_var_names, "x_velocity") ||
191 containerHasElement(plot_var_names, "y_velocity") ||
192 containerHasElement(plot_var_names, "z_velocity") ||
193 containerHasElement(plot_var_names, "vorticity") ) {
194
195 for (int lev = 0; lev <= finest_level; ++lev) {
196 mf_cc_vel[lev].define(grids[lev], dmap[lev], AMREX_SPACEDIM, IntVect(1,1,0));
197 mf_cc_vel[lev].setVal(0.0_rt); // zero out velocity in case we have any wall boundaries
198 average_face_to_cellcenter(mf_cc_vel[lev],0,
199 Array<const MultiFab*,3>{xvel_new[lev],yvel_new[lev],zvel_new[lev]});
200 mf_cc_vel[lev].FillBoundary(geom[lev].periodicity());
201 } // lev
202
203 // We need ghost cells if computing vorticity
204 amrex::Interpolater* mapper = &cell_cons_interp;
205 if ( containerHasElement(plot_var_names, "vorticity") ) {
206 for (int lev = 1; lev <= finest_level; ++lev) {
207 Vector<MultiFab*> fmf = {&(mf_cc_vel[lev]), &(mf_cc_vel[lev])};
208 Vector<Real> ftime = {t_new[lev], t_new[lev]};
209 Vector<MultiFab*> cmf = {&mf_cc_vel[lev-1], &mf_cc_vel[lev-1]};
210 Vector<Real> ctime = {t_new[lev], t_new[lev]};
211
212 MultiFab mf_to_fill;
213 amrex::FillPatchTwoLevels(mf_cc_vel[lev], t_new[lev], cmf, ctime, fmf, ftime,
214 0, 0, AMREX_SPACEDIM, geom[lev-1], geom[lev],
215 null_bc_for_fill, 0, null_bc_for_fill, 0, refRatio(lev-1),
216 mapper, domain_bcs_type, 0);
217 } // lev
218 } // if
219 } // if
220
221 for (int lev = 0; lev <= finest_level; ++lev)
222 {
223 int mf_comp = 0;
224
225 // First, copy any of the conserved state variables into the output plotfile
226 AMREX_ALWAYS_ASSERT(cons_names.size() == NCONS);
227 for (int i = 0; i < NCONS; ++i) {
229 if (cons_new[lev]->contains_nan() || cons_new[lev]->contains_inf()) {
230 amrex::Abort("Found while writing output: Cons (salt, temp, or scalar, etc) contains nan or inf");
231 }
232 MultiFab::Copy(mf[lev],*cons_new[lev],i,mf_comp,1,ngrow_vars);
233 mf_comp++;
234 }
235 } // NCONS
236
237 // Next, check for velocities
238 if (containerHasElement(plot_var_names, "x_velocity")) {
239 if (mf_cc_vel[lev].contains_nan(0,1) || mf_cc_vel[lev].contains_inf(0,1)) {
240 amrex::Abort("Found while writing output: u velocity contains nan or inf");
241 }
242 MultiFab::Copy(mf[lev], mf_cc_vel[lev], 0, mf_comp, 1, 0);
243 mf_comp += 1;
244 }
245 if (containerHasElement(plot_var_names, "y_velocity")) {
246 if (mf_cc_vel[lev].contains_nan(1,1) || mf_cc_vel[lev].contains_inf(1,1)) {
247 amrex::Abort("Found while writing output: v velocity contains nan or inf");
248 }
249 MultiFab::Copy(mf[lev], mf_cc_vel[lev], 1, mf_comp, 1, 0);
250 mf_comp += 1;
251 }
252 if (containerHasElement(plot_var_names, "z_velocity")) {
253 if (mf_cc_vel[lev].contains_nan(2,1) || mf_cc_vel[lev].contains_inf(2,1)) {
254 amrex::Abort("Found while writing output: z velocity contains nan or inf");
255 }
256 MultiFab::Copy(mf[lev], mf_cc_vel[lev], 2, mf_comp, 1, 0);
257 mf_comp += 1;
258 }
259
260 // Define standard process for calling the functions in Derive.cpp
261 auto calculate_derived = [&](const std::string& der_name,
262 decltype(derived::remora_dernull)& der_function)
263 {
264 if (containerHasElement(plot_var_names, der_name)) {
265 MultiFab dmf(mf[lev], make_alias, mf_comp, 1);
266#ifdef _OPENMP
267#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
268#endif
269 for (MFIter mfi(dmf, TilingIfNotGPU()); mfi.isValid(); ++mfi)
270 {
271 const Box& bx = mfi.tilebox();
272 auto& dfab = dmf[mfi];
273
274 if (der_name == "vorticity") {
275 auto const& sfab = mf_cc_vel[lev][mfi];
276 der_function(bx, dfab, 0, 1, sfab, vec_pm[lev]->const_array(mfi), vec_pn[lev]->const_array(mfi), Geom(lev), t_new[0], nullptr, lev);
277 } else {
278 auto const& sfab = (*cons_new[lev])[mfi];
279 der_function(bx, dfab, 0, 1, sfab, vec_pm[lev]->const_array(mfi), vec_pn[lev]->const_array(mfi), Geom(lev), t_new[0], nullptr, lev);
280 }
281 }
282
283 mf_comp++;
284 }
285 };
286
287 // Note: All derived variables must be computed in order of "derived_names" defined in REMORA.H
288 calculate_derived("vorticity", derived::remora_dervort);
289
290 // Fill cell-centered location
291 Real dx = Geom()[lev].CellSizeArray()[0];
292 Real dy = Geom()[lev].CellSizeArray()[1];
293
294 // Next, check for location names -- if we write one we write all
295 if (containerHasElement(plot_var_names, "x_cc") ||
298 {
299 MultiFab dmf(mf[lev], make_alias, mf_comp, AMREX_SPACEDIM);
300#ifdef _OPENMP
301#pragma omp parallel if (Gpu::notInLaunchRegion())
302#endif
303 for (MFIter mfi(dmf, TilingIfNotGPU()); mfi.isValid(); ++mfi) {
304 const Box& bx = mfi.tilebox();
305 const Array4<Real> loc_arr = dmf.array(mfi);
306 const Array4<Real const> zp_arr = vec_z_phys_nd[lev]->const_array(mfi);
307
308 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
309 loc_arr(i,j,k,0) = (i+0.5_rt) * dx;
310 loc_arr(i,j,k,1) = (j+0.5_rt) * dy;
311 loc_arr(i,j,k,2) = 0.125_rt * (zp_arr(i,j ,k ) + zp_arr(i+1,j ,k ) +
312 zp_arr(i,j+1,k ) + zp_arr(i+1,j+1,k ) +
313 zp_arr(i,j ,k+1) + zp_arr(i+1,j ,k+1) +
314 zp_arr(i,j+1,k+1) + zp_arr(i+1,j+1,k+1) );
315 });
316 } // mfi
317 mf_comp += AMREX_SPACEDIM;
318 } // if containerHasElement
319
320#ifdef REMORA_USE_PARTICLES
321 const auto& particles_namelist( particleData.getNames() );
322 for (ParticlesNamesVector::size_type i = 0; i < particles_namelist.size(); i++) {
323 if (containerHasElement(plot_var_names, std::string(particles_namelist[i]+"_count"))) {
324 MultiFab temp_dat(mf[lev].boxArray(), mf[lev].DistributionMap(), 1, 0);
325 temp_dat.setVal(0);
326 particleData[particles_namelist[i]]->Increment(temp_dat, lev);
327 MultiFab::Copy(mf[lev], temp_dat, 0, mf_comp, 1, 0);
328 mf_comp += 1;
329 }
330 }
331
332 Vector<std::string> particle_mesh_plot_names(0);
333 particleData.GetMeshPlotVarNames( particle_mesh_plot_names );
334 for (int i = 0; i < particle_mesh_plot_names.size(); i++) {
335 std::string plot_var_name(particle_mesh_plot_names[i]);
336 if (containerHasElement(plot_var_names, plot_var_name) ) {
337 MultiFab temp_dat(mf[lev].boxArray(), mf[lev].DistributionMap(), 1, 1);
338 temp_dat.setVal(0);
339 particleData.GetMeshPlotVar(plot_var_name, temp_dat, lev);
340 MultiFab::Copy(mf[lev], temp_dat, 0, mf_comp, 1, 0);
341 mf_comp += 1;
342 }
343 }
344#endif
345
346 MultiFab::Copy(mf_nd[lev],*vec_z_phys_nd[lev],0,2,1,0);
347 Real dz = Geom()[lev].CellSizeArray()[2];
348 int N = Geom()[lev].Domain().size()[2];
349
350#ifdef _OPENMP
351#pragma omp parallel if (Gpu::notInLaunchRegion())
352#endif
353 for (MFIter mfi(mf_nd[lev], TilingIfNotGPU()); mfi.isValid(); ++mfi)
354 {
355 const Box& bx = mfi.tilebox();
356 Array4<Real> mf_arr = mf_nd[lev].array(mfi);
357 ParallelFor(bx, [=] AMREX_GPU_DEVICE (int i, int j, int k) {
358 mf_arr(i,j,k,2) = mf_arr(i,j,k,2) + (N-k) * dz;
359 });
360 } // mfi
361
362 } // lev
363
364 std::string plotfilename = Concatenate(plot_file_name, istep[0], file_min_digits);
365
366 if (finest_level == 0)
367 {
369 amrex::Print() << "Writing plotfile " << plotfilename << "\n";
370 WriteMultiLevelPlotfileWithBathymetry(plotfilename, finest_level+1,
371 GetVecOfConstPtrs(mf),
372 GetVecOfConstPtrs(mf_nd),
373 varnames,
374 t_new[0], istep);
375 writeJobInfo(plotfilename);
376
377#ifdef REMORA_USE_PARTICLES
378 particleData.Checkpoint(plotfilename);
379#endif
380
381#ifdef REMORA_USE_HDF5
382 } else if (plotfile_type == PlotfileType::hdf5) {
383 amrex::Print() << "Writing plotfile " << plotfilename+"d01.h5" << "\n";
384 WriteMultiLevelPlotfileHDF5(plotfilename, finest_level+1,
385 GetVecOfConstPtrs(mf),
386 varnames,
387 Geom(), t_new[0], istep, refRatio());
388#endif
389 } else if (!(plotfile_type == PlotfileType::netcdf)) {
390 amrex::Abort("User specified unknown plot_filetype");
391 }
392
393 } else { // multilevel
394
395 Vector<IntVect> r2(finest_level);
396 Vector<Geometry> g2(finest_level+1);
397 Vector<MultiFab> mf2(finest_level+1);
398
399 mf2[0].define(grids[0], dmap[0], ncomp_mf, 0);
400
401 // Copy level 0 as is
402 MultiFab::Copy(mf2[0],mf[0],0,0,mf[0].nComp(),0);
403
404 // Define a new multi-level array of Geometry's so that we pass the new "domain" at lev > 0
405 Array<int,AMREX_SPACEDIM> periodicity =
406 {Geom()[0].isPeriodic(0),Geom()[0].isPeriodic(1),Geom()[0].isPeriodic(2)};
407 g2[0].define(Geom()[0].Domain(),&(Geom()[0].ProbDomain()),0,periodicity.data());
408
410 r2[0] = IntVect(1,1,ref_ratio[0][0]);
411 for (int lev = 1; lev <= finest_level; ++lev) {
412 if (lev > 1) {
413 r2[lev-1][0] = 1;
414 r2[lev-1][1] = 1;
415 r2[lev-1][2] = r2[lev-2][2] * ref_ratio[lev-1][0];
416 }
417
418 mf2[lev].define(refine(grids[lev],r2[lev-1]), dmap[lev], ncomp_mf, 0);
419
420 // Set the new problem domain
421 Box d2(Geom()[lev].Domain());
422 d2.refine(r2[lev-1]);
423
424 g2[lev].define(d2,&(Geom()[lev].ProbDomain()),0,periodicity.data());
425 }
426
427 // Make a vector of BCRec with default values so we can use it here -- note the values
428 // aren't actually used because we do PCInterp
429 amrex::Vector<amrex::BCRec> null_dom_bcs;
430 null_dom_bcs.resize(mf2[0].nComp());
431 for (int n = 0; n < mf2[0].nComp(); n++) {
432 for (int dir = 0; dir < AMREX_SPACEDIM; dir++) {
433 null_dom_bcs[n].setLo(dir, REMORABCType::int_dir);
434 null_dom_bcs[n].setHi(dir, REMORABCType::int_dir);
435 }
436 }
437
438 // Do piecewise interpolation of mf into mf2
439 for (int lev = 1; lev <= finest_level; ++lev) {
440 Interpolater* mapper_c = &pc_interp;
441 InterpFromCoarseLevel(mf2[lev], t_new[lev], mf[lev],
442 0, 0, mf2[lev].nComp(),
443 geom[lev], g2[lev],
445 r2[lev-1], mapper_c, null_dom_bcs, 0);
446 }
447
448 // Define an effective ref_ratio which is isotropic to be passed into WriteMultiLevelPlotfile
449 Vector<IntVect> rr(finest_level);
450 for (int lev = 0; lev < finest_level; ++lev) {
451 rr[lev] = IntVect(ref_ratio[lev][0],ref_ratio[lev][1],ref_ratio[lev][0]);
452 }
453
454 WriteMultiLevelPlotfile(plotfilename, finest_level+1, GetVecOfConstPtrs(mf2), varnames,
455 g2, t_new[0], istep, rr);
456 writeJobInfo(plotfilename);
457
458#ifdef REMORA_USE_PARTICLES
459 particleData.Checkpoint(plotfilename);
460#endif
461 }
462 } // end multi-level
463 for (int lev = 0; lev <= finest_level; ++lev) {
464 mask_arrays_for_write(lev, 0.0_rt, (Real) fill_value);
465 }
466}
467
468/**
469 * @param plotfilename name of plotfile to write to
470 * @param nlevels number of levels to write out
471 * @param mf MultiFab of data to write out
472 * @param mf_nd Multifab of nodal data to write out
473 * @param varnames variable names to write out
474 * @param time time at which to output
475 * @param level_steps vector over level of iterations
476 * @param versionName version string for VisIt
477 * @param levelPrefix string to prepend to level number
478 * @param mfPrefix subdirectory for multifab data
479 * @param extra_dirs additional subdirectories within plotfile
480 */
481 void
482 REMORA::WriteMultiLevelPlotfileWithBathymetry (const std::string& plotfilename, int nlevels,
483 const Vector<const MultiFab*>& mf,
484 const Vector<const MultiFab*>& mf_nd,
485 const Vector<std::string>& varnames,
486 Real time,
487 const Vector<int>& level_steps,
488 const std::string &versionName,
489 const std::string &levelPrefix,
490 const std::string &mfPrefix,
491 const Vector<std::string>& extra_dirs) const
492{
493 BL_PROFILE("WriteMultiLevelPlotfileWithBathymetry()");
494
495 BL_ASSERT(nlevels <= mf.size());
496 BL_ASSERT(nlevels <= ref_ratio.size()+1);
497 BL_ASSERT(nlevels <= level_steps.size());
498 BL_ASSERT(mf[0]->nComp() == varnames.size());
499
500 bool callBarrier(false);
501 PreBuildDirectorHierarchy(plotfilename, levelPrefix, nlevels, callBarrier);
502 if (!extra_dirs.empty()) {
503 for (const auto& d : extra_dirs) {
504 const std::string ed = plotfilename+"/"+d;
505 PreBuildDirectorHierarchy(ed, levelPrefix, nlevels, callBarrier);
506 }
507 }
508 ParallelDescriptor::Barrier();
509
510 if (ParallelDescriptor::MyProc() == ParallelDescriptor::NProcs()-1) {
511 Vector<BoxArray> boxArrays(nlevels);
512 for(int level(0); level < boxArrays.size(); ++level) {
513 boxArrays[level] = mf[level]->boxArray();
514 }
515
516 auto f = [=]() {
517 VisMF::IO_Buffer io_buffer(VisMF::IO_Buffer_Size);
518 std::string HeaderFileName(plotfilename + "/Header");
519 std::ofstream HeaderFile;
520 HeaderFile.rdbuf()->pubsetbuf(io_buffer.dataPtr(), io_buffer.size());
521 HeaderFile.open(HeaderFileName.c_str(), std::ofstream::out |
522 std::ofstream::trunc |
523 std::ofstream::binary);
524 if( ! HeaderFile.good()) FileOpenFailed(HeaderFileName);
525 WriteGenericPlotfileHeaderWithBathymetry(HeaderFile, nlevels, boxArrays, varnames,
526 time, level_steps, versionName,
527 levelPrefix, mfPrefix);
528 };
529
530 if (AsyncOut::UseAsyncOut()) {
531 AsyncOut::Submit(std::move(f));
532 } else {
533 f();
534 }
535 }
536
537 std::string mf_nodal_prefix = "Nu_nd";
538 for (int level = 0; level <= finest_level; ++level)
539 {
540 if (AsyncOut::UseAsyncOut()) {
541 VisMF::AsyncWrite(*mf[level],
542 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mfPrefix),
543 true);
544 VisMF::AsyncWrite(*mf_nd[level],
545 MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_nodal_prefix),
546 true);
547 } else {
548 const MultiFab* data;
549 std::unique_ptr<MultiFab> mf_tmp;
550 if (mf[level]->nGrowVect() != 0) {
551 mf_tmp = std::make_unique<MultiFab>(mf[level]->boxArray(),
552 mf[level]->DistributionMap(),
553 mf[level]->nComp(), 0, MFInfo(),
554 mf[level]->Factory());
555 MultiFab::Copy(*mf_tmp, *mf[level], 0, 0, mf[level]->nComp(), 0);
556 data = mf_tmp.get();
557 } else {
558 data = mf[level];
559 }
560 VisMF::Write(*data , MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mfPrefix));
561 VisMF::Write(*mf_nd[level], MultiFabFileFullPrefix(level, plotfilename, levelPrefix, mf_nodal_prefix));
562 }
563 }
564}
565
566/**
567 * @param HeaderFile output stream for header
568 * @param nlevels number of levels to write out
569 * @param bArray vector over levels of BoxArrays
570 * @param varnames variable names to write out
571 * @param time time at which to output
572 * @param level_steps vector over level of iterations
573 * @param versionName version string for VisIt
574 * @param levelPrefix string to prepend to level number
575 * @param mfPrefix subdirectory for multifab data
576 */
577void
579 int nlevels,
580 const Vector<BoxArray> &bArray,
581 const Vector<std::string> &varnames,
582 Real time,
583 const Vector<int> &level_steps,
584 const std::string &versionName,
585 const std::string &levelPrefix,
586 const std::string &mfPrefix) const
587{
588 BL_ASSERT(nlevels <= bArray.size());
589 BL_ASSERT(nlevels <= ref_ratio.size()+1);
590 BL_ASSERT(nlevels <= level_steps.size());
591
592 HeaderFile.precision(17);
593
594 // ---- this is the generic plot file type name
595 HeaderFile << versionName << '\n';
596
597 HeaderFile << varnames.size() << '\n';
598
599 for (int ivar = 0; ivar < varnames.size(); ++ivar) {
600 HeaderFile << varnames[ivar] << "\n";
601 }
602 HeaderFile << AMREX_SPACEDIM << '\n';
603 HeaderFile << time << '\n';
604 HeaderFile << finest_level << '\n';
605 for (int i = 0; i < AMREX_SPACEDIM; ++i) {
606 HeaderFile << geom[0].ProbLo(i) << ' ';
607 }
608 HeaderFile << '\n';
609 for (int i = 0; i < AMREX_SPACEDIM; ++i) {
610 HeaderFile << geom[0].ProbHi(i) << ' ';
611 }
612 HeaderFile << '\n';
613 for (int i = 0; i < finest_level; ++i) {
614 HeaderFile << ref_ratio[i][0] << ' ';
615 }
616 HeaderFile << '\n';
617 for (int i = 0; i <= finest_level; ++i) {
618 HeaderFile << geom[i].Domain() << ' ';
619 }
620 HeaderFile << '\n';
621 for (int i = 0; i <= finest_level; ++i) {
622 HeaderFile << level_steps[i] << ' ';
623 }
624 HeaderFile << '\n';
625 for (int i = 0; i <= finest_level; ++i) {
626 for (int k = 0; k < AMREX_SPACEDIM; ++k) {
627 HeaderFile << geom[i].CellSize()[k] << ' ';
628 }
629 HeaderFile << '\n';
630 }
631 HeaderFile << (int) geom[0].Coord() << '\n';
632 HeaderFile << "0\n";
633
634 for (int level = 0; level <= finest_level; ++level) {
635 HeaderFile << level << ' ' << bArray[level].size() << ' ' << time << '\n';
636 HeaderFile << level_steps[level] << '\n';
637
638 const IntVect& domain_lo = geom[level].Domain().smallEnd();
639 for (int i = 0; i < bArray[level].size(); ++i)
640 {
641 // Need to shift because the RealBox ctor we call takes the
642 // physical location of index (0,0,0). This does not affect
643 // the usual cases where the domain index starts with 0.
644 const Box& b = shift(bArray[level][i], -domain_lo);
645 RealBox loc = RealBox(b, geom[level].CellSize(), geom[level].ProbLo());
646 for (int n = 0; n < AMREX_SPACEDIM; ++n) {
647 HeaderFile << loc.lo(n) << ' ' << loc.hi(n) << '\n';
648 }
649 }
650
651 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mfPrefix) << '\n';
652 }
653 HeaderFile << "1" << "\n";
654 HeaderFile << "3" << "\n";
655 HeaderFile << "amrexvec_nu_x" << "\n";
656 HeaderFile << "amrexvec_nu_y" << "\n";
657 HeaderFile << "amrexvec_nu_z" << "\n";
658 std::string mf_nodal_prefix = "Nu_nd";
659 for (int level = 0; level <= finest_level; ++level) {
660 HeaderFile << MultiFabHeaderPath(level, levelPrefix, mf_nodal_prefix) << '\n';
661 }
662}
663
664/**
665 * @param lev level to mask
666 * @param fill_value fill value to mask with
667 * @param fill_where value at cells where we will apply the mask. This is necessary because rivers
668 */
669void
670REMORA::mask_arrays_for_write(int lev, Real fill_value, Real fill_where) {
671 for (MFIter mfi(*cons_new[lev],false); mfi.isValid(); ++mfi) {
672 Box gbx1 = mfi.growntilebox(IntVect(NGROW+1,NGROW+1,0));
673 Box ubx = mfi.grownnodaltilebox(0,IntVect(NGROW,NGROW,0));
674 Box vbx = mfi.grownnodaltilebox(1,IntVect(NGROW,NGROW,0));
675
676 Array4<Real> const& Zt_avg1 = vec_Zt_avg1[lev]->array(mfi);
677 Array4<Real> const& ubar = vec_ubar[lev]->array(mfi);
678 Array4<Real> const& vbar = vec_vbar[lev]->array(mfi);
679 Array4<Real> const& xvel = xvel_new[lev]->array(mfi);
680 Array4<Real> const& yvel = yvel_new[lev]->array(mfi);
681 Array4<Real> const& temp = cons_new[lev]->array(mfi,Temp_comp);
682 Array4<Real> const& salt = cons_new[lev]->array(mfi,Salt_comp);
683
684 Array4<Real const> const& mskr = vec_mskr[lev]->array(mfi);
685 Array4<Real const> const& msku = vec_msku[lev]->array(mfi);
686 Array4<Real const> const& mskv = vec_mskv[lev]->array(mfi);
687
688 ParallelFor(makeSlab(gbx1,2,0), [=] AMREX_GPU_DEVICE (int i, int j, int )
689 {
690 if (!mskr(i,j,0)) {
691 Zt_avg1(i,j,0) = fill_value;
692 }
693 });
694 ParallelFor(gbx1, [=] AMREX_GPU_DEVICE (int i, int j, int k)
695 {
696 if (!mskr(i,j,0)) {
697 temp(i,j,k) = fill_value;
698 salt(i,j,k) = fill_value;
699 }
700 });
701 ParallelFor(makeSlab(ubx,2,0), 3, [=] AMREX_GPU_DEVICE (int i, int j, int , int n)
702 {
703 if (!msku(i,j,0) && ubar(i,j,0)==fill_where) {
704 ubar(i,j,0,n) = fill_value;
705 }
706 });
707 ParallelFor(makeSlab(vbx,2,0), 3, [=] AMREX_GPU_DEVICE (int i, int j, int , int n)
708 {
709 if (!mskv(i,j,0) && vbar(i,j,0)==fill_where) {
710 vbar(i,j,0,n) = fill_value;
711 }
712 });
713 ParallelFor(ubx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
714 {
715 if (!msku(i,j,0) && xvel(i,j,k)==fill_where) {
716 xvel(i,j,k) = fill_value;
717 }
718 });
719 ParallelFor(vbx, [=] AMREX_GPU_DEVICE (int i, int j, int k)
720 {
721 if (!mskv(i,j,0) && yvel(i,j,k)==fill_where) {
722 yvel(i,j,k) = fill_value;
723 }
724 });
725 }
726 Gpu::streamSynchronize();
727}
Coord
Coordinates.
#define NGROW
#define Temp_comp
#define Salt_comp
#define NCONS
bool containerHasElement(const V &iterable, const T &query)
PhysBCFunctNoOp null_bc_for_fill
static PlotfileType plotfile_type
Native or NetCDF plotfile output.
Definition REMORA.H:1275
const amrex::Vector< std::string > cons_names
Names of scalars for plotfile output.
Definition REMORA.H:1231
amrex::Vector< amrex::BCRec > domain_bcs_type
vector (over BCVars) of BCRecs
Definition REMORA.H:1136
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pm
horizontal scaling factor: 1 / dx (2D)
Definition REMORA.H:358
amrex::Vector< std::string > plot_var_names
Names of variables to output to AMReX plotfile.
Definition REMORA.H:1229
amrex::Vector< amrex::MultiFab * > cons_new
multilevel data container for current step's scalar data: temperature, salinity, passive scalar
Definition REMORA.H:220
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskr
land/sea mask at cell centers (2D)
Definition REMORA.H:349
void writeJobInfo(const std::string &dir) const
Write job info to stdout.
amrex::Vector< amrex::MultiFab * > zvel_new
multilevel data container for current step's z velocities (largely unused; W stored separately)
Definition REMORA.H:226
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_msku
land/sea mask at x-faces (2D)
Definition REMORA.H:351
void FillPatchNoBC(int lev, amrex::Real time, amrex::MultiFab &mf_to_be_filled, amrex::Vector< amrex::MultiFab * > const &mfs, const int bdy_var_type=BdyVars::null, const int icomp=0, const bool fill_all=true, const bool fill_set=true)
Fill a new MultiFab by copying in phi from valid region and filling ghost cells without applying boun...
void setPlotVariables(const std::string &pp_plot_var_names)
amrex::Vector< amrex::MultiFab * > yvel_new
multilevel data container for current step's y velocities (v in ROMS)
Definition REMORA.H:224
amrex::Vector< amrex::MultiFab * > xvel_new
multilevel data container for current step's x velocities (u in ROMS)
Definition REMORA.H:222
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_mskv
land/sea mask at y-faces (2D)
Definition REMORA.H:353
void WriteGenericPlotfileHeaderWithBathymetry(std::ostream &HeaderFile, int nlevels, const amrex::Vector< amrex::BoxArray > &bArray, const amrex::Vector< std::string > &varnames, amrex::Real time, const amrex::Vector< int > &level_steps, const std::string &versionName, const std::string &levelPrefix, const std::string &mfPrefix) const
write out header data for an AMReX plotfile
amrex::Vector< int > istep
which step?
Definition REMORA.H:1110
void mask_arrays_for_write(int lev, amrex::Real fill_value, amrex::Real fill_where)
Mask data arrays before writing output.
static int file_min_digits
Minimum number of digits in plotfile name or chunked history file.
Definition REMORA.H:1272
void WriteMultiLevelPlotfileWithBathymetry(const std::string &plotfilename, int nlevels, const amrex::Vector< const amrex::MultiFab * > &mf, const amrex::Vector< const amrex::MultiFab * > &mf_nd, const amrex::Vector< std::string > &varnames, amrex::Real time, const amrex::Vector< int > &level_steps, const std::string &versionName="HyperCLaw-V1.1", const std::string &levelPrefix="Level_", const std::string &mfPrefix="Cell", const amrex::Vector< std::string > &extra_dirs=amrex::Vector< std::string >()) const
write out particular data to an AMReX plotfile
std::string pp_prefix
default prefix for input file parameters
Definition REMORA.H:208
amrex::Vector< amrex::Real > t_new
new time at each level
Definition REMORA.H:1114
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_vbar
barotropic y velocity (2D)
Definition REMORA.H:344
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_ubar
barotropic x velocity (2D)
Definition REMORA.H:342
void appendPlotVariables(const std::string &pp_plot_var_names)
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_z_phys_nd
z coordinates at psi points (cell nodes)
Definition REMORA.H:279
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_pn
horizontal scaling factor: 1 / dy (2D)
Definition REMORA.H:360
std::string plot_file_name
Plotfile prefix.
Definition REMORA.H:1206
amrex::Vector< std::unique_ptr< amrex::MultiFab > > vec_Zt_avg1
Average of the free surface, zeta (2D)
Definition REMORA.H:282
void WritePlotFile()
main driver for writing AMReX plotfiles
const amrex::Vector< std::string > derived_names
Names of derived fields for plotfiles.
Definition REMORA.H:1234
void remora_dernull(const amrex::Box &, amrex::FArrayBox &, int, int, const amrex::FArrayBox &, const amrex::Array4< const amrex::Real > &, const amrex::Array4< const amrex::Real > &, const amrex::Geometry &, amrex::Real, const int *, const int)
void remora_dervort(const amrex::Box &bx, amrex::FArrayBox &derfab, int dcomp, int ncomp, const amrex::FArrayBox &datfab, const amrex::Array4< const amrex::Real > &pm, const amrex::Array4< const amrex::Real > &pn, const amrex::Geometry &, amrex::Real, const int *, const int)