REMORA
Regional Modeling of Oceans Refined Adaptively
Loading...
Searching...
No Matches
REMORA_ReadFromInitNetcdf.cpp
Go to the documentation of this file.
1#include "REMORA_NCFile.H"
2#include "AMReX_FArrayBox.H"
3#include "REMORA_DataStruct.H"
4
5using namespace amrex;
6
7#ifdef REMORA_USE_NETCDF
8/**
9 * @param lev level of data to read
10 * @param domain simulation domain
11 * @param fname file name to read from
12 * @param NC_temp_fab container for temperature data
13 * @param NC_salt_fab container for salinity data
14 * @param NC_u_fab container for u velocity data
15 * @param NC_v_fab container for v velocity data
16 */
17void
19 const Box& domain,
20 const std::string& fname,
21 FArrayBox& NC_temp_fab, FArrayBox& NC_salt_fab,
22 FArrayBox& NC_xvel_fab, FArrayBox& NC_yvel_fab)
23{
24 amrex::Print() << "Loading initial solution data from NetCDF file " << fname << std::endl;
25
27 Vector<std::string> NC_names;
29
30 NC_fabs.push_back(&NC_temp_fab); NC_names.push_back("temp"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 0
31 NC_fabs.push_back(&NC_salt_fab); NC_names.push_back("salt"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 1
32 NC_fabs.push_back(&NC_xvel_fab); NC_names.push_back("u"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 2
33 NC_fabs.push_back(&NC_yvel_fab); NC_names.push_back("v"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 3
34
35 // Read the netcdf file and fill these FABs
37}
38
39/**
40 * @param lev level of data to read
41 * @param domain simulation domain
42 * @param fname file name to read from
43 * @param NC_temp_fab container for temperature data
44 * @param NC_salt_fab container for salinity data
45 * @param NC_u_fab container for u velocity data
46 * @param NC_v_fab container for v velocity data
47 * @param ngrow number of grow cells to read
48 */
49void
51 const Box& domain,
52 const std::string& fname,
53 FArrayBox& NC_temp_fab, FArrayBox& NC_salt_fab,
54 FArrayBox& NC_xvel_fab, FArrayBox& NC_yvel_fab,
55 IntVect ngrow)
56{
57 amrex::Print() << "Loading initial solution data from NetCDF file " << fname << std::endl;
58
60 Vector<std::string> NC_names;
62
63 NC_fabs.push_back(&NC_temp_fab); NC_names.push_back("temp"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 0
64 NC_fabs.push_back(&NC_salt_fab); NC_names.push_back("salt"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 1
65 NC_fabs.push_back(&NC_xvel_fab); NC_names.push_back("u"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 2
66 NC_fabs.push_back(&NC_yvel_fab); NC_names.push_back("v"); NC_dim_types.push_back(NC_Data_Dims_Type::Time_BT_SN_WE); // 3
67
68 // Read the netcdf file and fill these FABs
70}
71
72/**
73 * @param lev level of data to read
74 * @param domain simulation domain
75 * @param fname file name to read from
76 * @param biology_names names of the biological tracer variables to read
77 * @param NC_biology_fab containers for the biological tracer data, one per name
78 */
79void
81 const Box& domain,
82 const std::string& fname,
83 const Vector<std::string>& biology_names,
85{
86 if (biology_names.empty()) {
87 return;
88 }
89
90 amrex::Print() << "Loading initial biology data from NetCDF file " << fname << std::endl;
91
92 NC_biology_fab.resize(biology_names.size());
95
96 for (int ibio = 0; ibio < static_cast<int>(biology_names.size()); ++ibio) {
97 NC_fabs.push_back(&NC_biology_fab[ibio]);
99 }
100
102}
103
104/**
105 * @param lev level of data to read
106 * @param domain simulation domain
107 * @param fname file name to read from
108 * @param biology_names names of the biological tracer variables to read
109 * @param NC_biology_fab containers for the biological tracer data, one per name
110 * @param ngrow number of grow cells to read
111 */
112void
114 const Box& domain,
115 const std::string& fname,
116 const Vector<std::string>& biology_names,
118 IntVect ngrow)
119{
120 if (biology_names.empty()) {
121 return;
122 }
123
124 amrex::Print() << "Loading high resolution biology data from NetCDF file " << fname << std::endl;
125
126 NC_biology_fab.resize(biology_names.size());
129
130 for (int ibio = 0; ibio < static_cast<int>(biology_names.size()); ++ibio) {
131 NC_fabs.push_back(&NC_biology_fab[ibio]);
133 }
134
136}
137
138/**
139 * @param fname file name the hires data will be read from
140 * @param var_name a rho-point variable in that file whose horizontal extent is checked
141 * @param domain the refined full-domain box the data has to cover
142 * @param ngrow grow cells the read asks for, i.e. cum_ref_ratios[hires_*_level]
143 *
144 * A high-resolution file has to carry the refined domain plus ngrow rings on every side
145 * (Docs/sphinx_doc/Inputs.rst). Checking that up front is not a nicety: BuildFABsFromNetCDFFile
146 * copies on intersection and fill_fab_from_arrays only asserts that the destination box is big
147 * enough for the source, so a file with too FEW grow cells reads cleanly and silently leaves
148 * the outer rings of the FAB at whatever they held -- which then gets averaged down into
149 * level 0. Only rho-point variables are checked; that is enough to catch an undersized file,
150 * and it avoids re-deriving the staggered offsets here.
151 */
152void
154 const std::string& var_name,
155 const Box& domain,
156 const IntVect& ngrow)
157{
158 int too_small = 0;
159 long found_x = 0, found_y = 0;
160 const long need_x = static_cast<long>(domain.length(0)) + 2L * ngrow[0];
161 const long need_y = static_cast<long>(domain.length(1)) + 2L * ngrow[1];
162
165 if (amrex::ParallelDescriptor::IOProcessor() && ncf.has_var(var_name))
166 {
167 // Whatever the leading time or vertical dimensions are, the last two are (eta, xi).
168 const std::vector<MPI_Offset> shape = ncf.var(var_name).shape();
169 if (shape.size() >= 2) {
170 found_y = static_cast<long>(shape[shape.size()-2]);
171 found_x = static_cast<long>(shape[shape.size()-1]);
172 too_small = (found_x < need_x || found_y < need_y) ? 1 : 0;
173 }
174 }
175 ncf.close();
176
177 const int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
178 amrex::ParallelDescriptor::Bcast(&too_small, 1, ioproc);
179 amrex::ParallelDescriptor::Bcast(&found_x, 1, ioproc);
180 amrex::ParallelDescriptor::Bcast(&found_y, 1, ioproc);
181
182 if (too_small) {
183 amrex::Abort("High-resolution file " + fname + " is too small: " + var_name + " is "
184 + std::to_string(found_x) + " x " + std::to_string(found_y)
185 + " (xi x eta) but covering the refined domain ("
186 + std::to_string(domain.length(0)) + " x " + std::to_string(domain.length(1))
187 + " cells) with " + std::to_string(ngrow[0]) + " x " + std::to_string(ngrow[1])
188 + " grow cells requires at least " + std::to_string(need_x) + " x "
189 + std::to_string(need_y) + ". Regenerate the file with the grow cells the "
190 "cumulative refinement ratio implies, or lower the refinement ratio.");
191 }
192}
193
194/**
195 * @param domain simulation domain
196 * @param fname file name to read from
197 * @param scalar_names per passive scalar, name of the variable in the file
198 * @param NC_scalar_fab per passive scalar, container for the dye data
199 * @param scalar_in_file filled on output: per passive scalar, whether the variable was
200 * found in the file and its FAB was built
201 * @param full_domain whether this is the high resolution full-domain read, which
202 * needs ngrow grow cells rather than the reader's default
203 * @param ngrow number of grow cells to read, for the full-domain read
204 *
205 * A passive scalar's initial field is optional. Initial files written for runs that
206 * carry no dye -- which is every ROMS initial file predating the dye variables, and
207 * most idealized ones -- have no "tracer" variable, so requiring the field would break
208 * every existing NetCDF-initialized run. Each name the file does carry is read; the rest
209 * keep the zero that init_data_from_netcdf set, which is the behavior those runs had
210 * before this read existed.
211 *
212 * Shared by the per-box and full-domain entry points below: the presence testing is
213 * the same for both, and only the grow cells and the wording of the log differ.
214 */
215namespace {
216void
217read_scalars_impl (const Box& domain,
218 const std::string& fname,
219 const Vector<std::string>& scalar_names,
221 Vector<int>& scalar_in_file,
222 bool full_domain,
223 IntVect ngrow)
224{
225 scalar_in_file.assign(scalar_names.size(), 0);
226 if (scalar_names.empty()) {
227 return;
228 }
229
230 NC_scalar_fab.resize(scalar_names.size());
232 Vector<std::string> NC_names;
234 Vector<std::string> missing;
235
236 for (int iscal = 0; iscal < static_cast<int>(scalar_names.size()); ++iscal) {
238 missing.push_back(scalar_names[iscal]);
239 continue;
240 }
242 NC_fabs.push_back(&NC_scalar_fab[iscal]);
243 NC_names.push_back(scalar_names[iscal]);
245 }
246
247 if (!missing.empty()) {
248 amrex::Print() << "Initial file " << fname << " does not contain";
249 for (const auto& name : missing) { amrex::Print() << " " << name; }
250 amrex::Print() << "; those passive scalars start at zero" << std::endl;
251 }
252 if (NC_names.empty()) {
253 return;
254 }
255
256 amrex::Print() << "Loading " << (full_domain ? "high resolution " : "initial ")
257 << "passive scalar data from NetCDF file " << fname << std::endl;
258
259 // Read the netcdf file and fill these FABs. The per-box read takes the reader's
260 // default grow cells, as the temperature and salinity read does.
261 if (full_domain) {
263 } else {
265 }
266}
267} // namespace
268
269/**
270 * @param lev level of data to read
271 * @param domain simulation domain
272 * @param fname file name to read from
273 * @param scalar_names names of the passive scalar variables to look for
274 * @param NC_scalar_fab containers for the passive scalar data, one per name
275 * @param scalar_in_file set per name to whether the file carried that variable
276 */
277void
279 const Box& domain,
280 const std::string& fname,
281 const Vector<std::string>& scalar_names,
283 Vector<int>& scalar_in_file)
284{
286 false, IntVect(0,0,0));
287}
288
289/**
290 * @param lev level of data to read
291 * @param domain simulation domain
292 * @param fname file name to read from
293 * @param scalar_names names of the passive scalar variables to look for
294 * @param NC_scalar_fab containers for the passive scalar data, one per name
295 * @param scalar_in_file set per name to whether the file carried that variable
296 * @param ngrow number of grow cells to read
297 */
298void
300 const Box& domain,
301 const std::string& fname,
302 const Vector<std::string>& scalar_names,
304 Vector<int>& scalar_in_file,
305 IntVect ngrow)
306{
308 true, ngrow);
309}
310
311/**
312 * @param lev level of data to read
313 * @param domain simulation domain
314 * @param fname file name to read from
315 * @param NC_zeta_fab container for sea surface height data
316 */
317void
319 const Box& domain,
320 const std::string& fname,
321 FArrayBox& NC_zeta_fab)
322{
323 amrex::Print() << "Loading initial sea surface height from NetCDF file " << fname << std::endl;
324
326 Vector<std::string> NC_names;
328
329 NC_fabs.push_back(&NC_zeta_fab ) ; NC_names.push_back("zeta") ; NC_dim_types.push_back(NC_Data_Dims_Type::Time_SN_WE); // 0
330
331 // Read the netcdf file and fill these FABs
333}
334
335/**
336 * @param lev level of data to read
337 * @param domain simulation domain
338 * @param fname file name to read from
339 * @param NC_zeta_fab container for sea surface height data
340 * @param ngrow number of grow cells to read in, if not default
341 */
342void
344 const Box& domain,
345 const std::string& fname,
346 FArrayBox& NC_zeta_fab,
347 IntVect ngrow)
348{
349 amrex::Print() << "Loading initial sea surface height from NetCDF file " << fname << std::endl;
350
352 Vector<std::string> NC_names;
354
355 NC_fabs.push_back(&NC_zeta_fab ) ; NC_names.push_back("zeta") ; NC_dim_types.push_back(NC_Data_Dims_Type::Time_SN_WE); // 0
356
357 // Read the netcdf file and fill these FABs
359}
360
361/**
362 * @param lev level of data to read
363 * @param domain simulation domain
364 * @param fname file name to read from
365 * @param NC_h_fab container for bathymetry data
366 */
367void
369 const Box& domain,
370 const std::string& fname,
371 FArrayBox& NC_h_fab)
372{
373 amrex::Print() << "Loading initial bathymetry from NetCDF file " << fname << std::endl;
374
376 Vector<std::string> NC_names;
378
379 NC_fabs.push_back(&NC_h_fab ) ; NC_names.push_back("h") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 0
380
381 // Read the netcdf file and fill these FABs
383}
384
385/**
386 * @param lev level of data to read
387 * @param domain simulation domain
388 * @param fname file name to read from
389 * @param NC_pm_fab container for pm data
390 * @param NC_pn_fab container for pn data
391 * @param NC_xr_fab container for x_rho data
392 * @param NC_yr_fab container for y_rho data
393 * @param NC_xu_fab container for x_u data
394 * @param NC_yu_fab container for y_u data
395 * @param NC_xv_fab container for x_v data
396 * @param NC_yv_fab container for y_v data
397 * @param NC_xp_fab container for x_p data
398 * @param NC_yp_fab container for y_p data
399 */
400void
402 const Box& domain,
403 const std::string& fname,
404 FArrayBox& NC_pm_fab, FArrayBox& NC_pn_fab,
405 FArrayBox& NC_xr_fab, FArrayBox& NC_yr_fab,
406 FArrayBox& NC_xu_fab, FArrayBox& NC_yu_fab,
407 FArrayBox& NC_xv_fab, FArrayBox& NC_yv_fab,
408 FArrayBox& NC_xp_fab, FArrayBox& NC_yp_fab)
409{
410 amrex::Print() << "Loading grid variables from NetCDF file " << fname << std::endl;
411
413 Vector<std::string> NC_names;
415
416 NC_fabs.push_back(&NC_pm_fab) ; NC_names.push_back("pm") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 1
417 NC_fabs.push_back(&NC_pn_fab) ; NC_names.push_back("pn") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 2
418 NC_fabs.push_back(&NC_xr_fab) ; NC_names.push_back("x_rho") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 3
419 NC_fabs.push_back(&NC_yr_fab) ; NC_names.push_back("y_rho") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 4
420 NC_fabs.push_back(&NC_xu_fab) ; NC_names.push_back("x_u") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 5
421 NC_fabs.push_back(&NC_yu_fab) ; NC_names.push_back("y_u") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 6
422 NC_fabs.push_back(&NC_xv_fab) ; NC_names.push_back("x_v") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 7
423 NC_fabs.push_back(&NC_yv_fab) ; NC_names.push_back("y_v") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 8
424 NC_fabs.push_back(&NC_xp_fab) ; NC_names.push_back("x_psi") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 9
425 NC_fabs.push_back(&NC_yp_fab) ; NC_names.push_back("y_psi") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 10
426
427 // Read the netcdf file and fill these FABs
429}
430
431/**
432 * @param domain simulation domain
433 * @param fname file name to read from
434 * @param NC_lonp_fab container for lon_psi data
435 * @param NC_latp_fab container for lat_psi data
436 * @returns whether the file carried spherical psi coordinates and they were read
437 *
438 * ROMS grid files for spherical grids carry lon_psi/lat_psi alongside
439 * x_psi/y_psi, and those degree-valued corner arrays are what a coupled driver
440 * needs when the two components do not share a projected Cartesian frame
441 * (SCRIP/COAWST selects the same way; see Lib/SCRIP_COAWST/read_roms.f).
442 * Idealized grid files carry no spherical coordinates, so this read is optional
443 * and reports whether it happened rather than aborting.
444 */
445bool
447 const Box& domain,
448 const std::string& fname,
449 FArrayBox& NC_lonp_fab, FArrayBox& NC_latp_fab)
450{
451 Vector<std::string> NC_names;
452 NC_names.push_back("lon_psi");
453 NC_names.push_back("lat_psi");
454
456 amrex::Print() << "Grid file " << fname << " has no lon_psi/lat_psi; "
457 << "spherical psi coordinates unavailable" << std::endl;
458 return false;
459 }
460
461 amrex::Print() << "Loading spherical psi coordinates from NetCDF file " << fname << std::endl;
462
465
468
470 return true;
471}
472
473/**
474 * @param domain simulation domain at nc_hires_grid_level
475 * @param fname file name to read from
476 * @param NC_h_fab container for bathymetry data
477 * @param ngrow number of grow cells to read in, if not default
478 */
479void
481 const std::string& fname,
482 FArrayBox& NC_h_fab, IntVect ngrow)
483{
484 amrex::Print() << "Loading high resolution bathymetry from NetCDF file " << fname << std::endl;
485
487 Vector<std::string> NC_names;
489
490 NC_fabs.push_back(&NC_h_fab ) ; NC_names.push_back("h") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 0
491
492 // Read the netcdf file and fill these FABs
494}
495
496/**
497 * @param lev level of data to read
498 * @param domain simulation domain
499 * @param fname file name to read from
500 * @param NC_pm_fab container for pm data
501 * @param NC_pn_fab container for pn data
502 * @param ngrow number of grow cells to read in, if not default
503 */
504void
506 const std::string& fname,
507 FArrayBox& NC_pm_fab, FArrayBox& NC_pn_fab,
508 IntVect ngrow)
509{
510 amrex::Print() << "Loading high resolution grid variables from NetCDF file " << fname << std::endl;
511
513 Vector<std::string> NC_names;
515
516 NC_fabs.push_back(&NC_pm_fab) ; NC_names.push_back("pm") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 0
517 NC_fabs.push_back(&NC_pn_fab) ; NC_names.push_back("pn") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 1
518 // Read the netcdf file and fill these FABs
520}
521
522/**
523 * @param lev level of data to read
524 * @param domain simulation domain
525 * @param fname file name to read from
526 * @param NC_fcor_fab container for Coriolis parameter data
527 */
528void
530 const Box& domain,
531 const std::string& fname,
532 FArrayBox& NC_fcor_fab)
533{
534 amrex::Print() << "Loading initial coriolis from NetCDF file " << fname << std::endl;
535
537 Vector<std::string> NC_names;
539
540 NC_fabs.push_back(&NC_fcor_fab ) ; NC_names.push_back("f") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 0
541
542 // Read the netcdf file and fill these FABs
544}
545
546/**
547 * @param lev level of data to read
548 * @param domain simulation domain
549 * @param fname file name to read from
550 * @param NC_mskr_fab container for rho-point land/sea mask data
551 * @param NC_msku_fab container for u-point land/sea mask data
552 * @param NC_mskv_fab container for v-point land/sea mask data
553 */
554void
556 const Box& domain,
557 const std::string& fname,
558 FArrayBox& NC_mskr_fab,
559 FArrayBox& NC_msku_fab,
560 FArrayBox& NC_mskv_fab)
561{
562 amrex::Print() << "Loading masks from NetCDF file " << fname << std::endl;
563
565 Vector<std::string> NC_names;
567
568 NC_fabs.push_back(&NC_mskr_fab ) ; NC_names.push_back("mask_rho") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 0
569 NC_fabs.push_back(&NC_msku_fab ) ; NC_names.push_back("mask_u") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 1
570 NC_fabs.push_back(&NC_mskv_fab ) ; NC_names.push_back("mask_v") ; NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE); // 2
571
572 // Read the netcdf file and fill these FABs
574}
575
576/**
577 * @param lev level of data to read
578 * @param domain simulation domain
579 * @param fname file name to read from
580 * @param do_m2_clim_nudg whether to do 2d momentum climatology nudging
581 * @param do_m3_clim_nudg whether to do 3d momentum climatology nudging
582 * @param do_cons_clim_nudg per cons component, whether to do climatology nudging
583 * @param cons_names per cons component, name of the tracer
584 * @param NC_M2NC_fab container for 2d momentum climatology data
585 * @param NC_M3NC_fab container for 3d momentum climatology data
586 * @param NC_ConsNC_fab per cons component, container for tracer climatology data
587 * @param cons_coeff_in_file filled on output: per cons component, whether a spatially
588 * varying coefficient was found in the file
589 */
590void
592 const Box& domain,
593 const std::string& fname,
594 bool do_m2_clim_nudg,
595 bool do_m3_clim_nudg,
596 const amrex::Vector<int>& do_cons_clim_nudg,
597 const amrex::Vector<std::string>& cons_names,
598 FArrayBox& NC_M2NC_fab,
599 FArrayBox& NC_M3NC_fab,
600 amrex::Vector<FArrayBox>& NC_ConsNC_fab,
601 amrex::Vector<int>& cons_coeff_in_file)
602{
603 amrex::Print() << "Loading nudging coefficients from NetCDF file " << fname << std::endl;
604
605 const int l_ncons = do_cons_clim_nudg.size();
606
608 Vector<std::string> NC_names;
610
611 if (do_m3_clim_nudg) {
612 NC_fabs.push_back(&NC_M3NC_fab ); NC_names.push_back("M3_NudgeCoef"); NC_dim_types.push_back(NC_Data_Dims_Type::BT_SN_WE);
613 }
614 if (do_m2_clim_nudg) {
615 NC_fabs.push_back(&NC_M2NC_fab ); NC_names.push_back("M2_NudgeCoef"); NC_dim_types.push_back(NC_Data_Dims_Type::SN_WE);
616 }
617 // Each tracer's spatially varying coefficient is stored under its own name, as in
618 // ROMS: temp_NudgeCoef, salt_NudgeCoef, NO3_NudgeCoef, ... A tracer whose field is
619 // absent from the file keeps the constant coefficient derived from remora.tnudg, so
620 // a file written for temp and salt alone still works when biology tracers are nudged.
621 cons_coeff_in_file.assign(l_ncons, 0);
622 Vector<std::string> missing;
623 for (int icomp = 0; icomp < l_ncons; ++icomp) {
624 if (!do_cons_clim_nudg[icomp]) { continue; }
625 const std::string coeff_name = cons_names[icomp] + "_NudgeCoef";
627 missing.push_back(coeff_name);
628 continue;
629 }
632 }
633 if (!missing.empty()) {
634 amrex::Print() << "Nudging coefficient file " << fname << " does not contain";
635 for (const auto& name : missing) { amrex::Print() << " " << name; }
636 amrex::Print() << "; those tracers will use the constant coefficient from remora.tnudg"
637 << std::endl;
638 }
639
640 // Read the netcdf file and fill these FABs
642}
643
644/**
645 * @param lev level of data to read
646 * @param fnames file name(s) to read from
647 * @param field_name field name to read
648 * @param vec_dat vector to fill data
649 */
650//template <typename DType>
651void read_vec_from_netcdf (int /*lev*/, const amrex::Vector<std::string>& fnames, const std::string& field_name, amrex::Vector<int>& vec_dat)
652{
653 AMREX_ALWAYS_ASSERT(!fnames.empty());
654 const std::string& fname = fnames[0];
655
656 amrex::Print() << "Reading " << field_name << " from NetCDF file" << std::endl;
657
658 // get x-positions and put in array
659 using ARRAY = NDArray<int>;
660 amrex::Vector<ARRAY> array_dat(1);
661 ReadNetCDFFile(fname, {field_name}, array_dat); // filled only on proc 0
662 if (amrex::ParallelDescriptor::IOProcessor())
663 {
664 int n = array_dat[0].get_vshape()[0];
665 for (int i(0); i < n; i++)
666 {
667 vec_dat.push_back((*(array_dat[0].get_data() + i)));
668 }
669 }
670 int nvals = vec_dat.size();
671 int ioproc = amrex::ParallelDescriptor::IOProcessorNumber();
672 amrex::ParallelDescriptor::Bcast(&nvals,1,ioproc);
673 if (!(amrex::ParallelDescriptor::IOProcessor())) {
674 vec_dat.resize(nvals);
675 }
676 amrex::ParallelDescriptor::Bcast(vec_dat.data(), vec_dat.size(), ioproc);
677}
678
679#endif // ROMSX_USE_NETCDF
mf_h setVal(geomdata.ProbHi(2))
AMREX_ALWAYS_ASSERT(!NSPeriodic||!EWPeriodic)
void ReadNetCDFFile(const std::string &fname, amrex::Vector< std::string > names, amrex::Vector< NDArray< DType > > &arrays, bool one_time=false, int fill_time=0)
Read in data from netcdf file and save to data arrays.
bool QueryNetCDFHasVars(const std::string &fname, const amrex::Vector< std::string > &var_names)
Helper function for testing whether a file carries every named variable.
void read_zeta_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_zeta_fab, IntVect ngrow)
helper function to read high-resolution full-domain sea surface height from netcdf
void read_bathymetry_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_h_fab)
helper function to read bathymetry from netcdf
void read_vec_from_netcdf(int, const amrex::Vector< std::string > &fnames, const std::string &field_name, amrex::Vector< int > &vec_dat)
helper function to read in vector of data from netcdf
void read_scalars_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &scalar_names, Vector< FArrayBox > &NC_scalar_fab, Vector< int > &scalar_in_file, IntVect ngrow)
helper function for reading in full domain high-resolution initial passive (dye) scalar data from net...
void read_data_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_temp_fab, FArrayBox &NC_salt_fab, FArrayBox &NC_xvel_fab, FArrayBox &NC_yvel_fab, IntVect ngrow)
helper function for reading in full domain high-resolution initial state data from netcdf
void check_hires_dims_from_netcdf(const std::string &fname, const std::string &var_name, const Box &domain, const IntVect &ngrow)
helper function checking that a high-resolution file covers the refined domain plus grow cells
void read_grid_vars_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_pm_fab, FArrayBox &NC_pn_fab, FArrayBox &NC_xr_fab, FArrayBox &NC_yr_fab, FArrayBox &NC_xu_fab, FArrayBox &NC_yu_fab, FArrayBox &NC_xv_fab, FArrayBox &NC_yv_fab, FArrayBox &NC_xp_fab, FArrayBox &NC_yp_fab)
helper function to read grid variables from netcdf
void read_biology_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &biology_names, Vector< FArrayBox > &NC_biology_fab)
helper function for reading in initial biology data from netcdf
void read_bathymetry_full_domain_from_netcdf(const Box &domain, const std::string &fname, FArrayBox &NC_h_fab, IntVect ngrow)
helper function to read full-domain high resolution bathymetry from netcdf
void read_clim_nudg_coeff_from_netcdf(int, const Box &domain, const std::string &fname, bool do_m2_clim_nudg, bool do_m3_clim_nudg, const amrex::Vector< int > &do_cons_clim_nudg, const amrex::Vector< std::string > &cons_names, FArrayBox &NC_M2NC_fab, FArrayBox &NC_M3NC_fab, amrex::Vector< FArrayBox > &NC_ConsNC_fab, amrex::Vector< int > &cons_coeff_in_file)
helper function to read climatology nudging from netcdf
void read_coriolis_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_fcor_fab)
helper function to read coriolis factor from netcdf
void read_masks_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_mskr_fab, FArrayBox &NC_msku_fab, FArrayBox &NC_mskv_fab)
helper function for reading in land-sea masks from netcdf
void read_biology_full_domain_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &biology_names, Vector< FArrayBox > &NC_biology_fab, IntVect ngrow)
helper function for reading in full domain high-resolution initial biology data from netcdf
void read_zeta_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_zeta_fab)
helper function to read sea surface height from netcdf
bool read_spherical_grid_vars_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_lonp_fab, FArrayBox &NC_latp_fab)
helper function to read optional spherical psi coordinates from netcdf
void read_data_from_netcdf(int, const Box &domain, const std::string &fname, FArrayBox &NC_temp_fab, FArrayBox &NC_salt_fab, FArrayBox &NC_xvel_fab, FArrayBox &NC_yvel_fab)
helper function for reading in initial state data from netcdf
void read_scalars_from_netcdf(int, const Box &domain, const std::string &fname, const Vector< std::string > &scalar_names, Vector< FArrayBox > &NC_scalar_fab, Vector< int > &scalar_in_file)
helper function for reading in initial passive (dye) scalar data from netcdf
void read_grid_vars_full_domain_from_netcdf(const Box &domain, const std::string &fname, FArrayBox &NC_pm_fab, FArrayBox &NC_pn_fab, IntVect ngrow)
helper function to read full-domain high resolution grid variables from netcdf
static NCFile open(const std::string &name, const int cmode=NC_NOWRITE, MPI_Comm comm=MPI_COMM_WORLD, MPI_Info info=MPI_INFO_NULL)
Open an existing file.
NDArray is the datatype designed to hold any data, including scalars, multidimensional arrays,...