1 #ifndef ERF_METGRIDUTIL_H_
2 #define ERF_METGRIDUTIL_H_
13 const amrex::Box& domain,
14 const std::string& fname,
15 std::string& NC_dateTime,
26 amrex::FArrayBox& NC_xvel_fab,
27 amrex::FArrayBox& NC_yvel_fab,
28 amrex::FArrayBox& NC_temp_fab,
29 amrex::FArrayBox& NC_rhum_fab,
30 amrex::FArrayBox& NC_pres_fab,
31 amrex::FArrayBox& NC_ght_fab,
32 amrex::FArrayBox& NC_hgt_fab,
33 amrex::FArrayBox& NC_psfc_fab,
34 amrex::FArrayBox& NC_msfu_fab,
35 amrex::FArrayBox& NC_msfv_fab,
36 amrex::FArrayBox& NC_msfm_fab,
37 amrex::FArrayBox& NC_sst_fab,
38 amrex::FArrayBox& NC_tsk_fab,
39 amrex::FArrayBox& NC_LAT_fab,
40 amrex::FArrayBox& NC_LON_fab,
41 amrex::IArrayBox& NC_lmask_iab,
42 amrex::Geometry& geom);
46 amrex::FArrayBox& NC_hgt_fab);
52 const bool interp_theta,
53 const bool metgrid_debug_quiescent,
54 const bool metgrid_debug_isothermal,
55 const bool metgrid_debug_dry,
56 const bool metgrid_basic_linear,
57 const bool metgrid_use_below_sfc,
58 const bool metgrid_use_sfc,
59 const bool metgrid_retain_sfc,
61 const int metgrid_order,
62 const int metgrid_metgrid_force_sfc_k,
67 amrex::FArrayBox& state_fab,
68 amrex::FArrayBox& x_vel_fab,
69 amrex::FArrayBox& y_vel_fab,
70 amrex::FArrayBox& z_vel_fab,
71 amrex::FArrayBox& z_phys_nd_fab,
72 const amrex::FArrayBox& NC_ght_fab,
73 const amrex::FArrayBox& NC_xvel_fab,
74 const amrex::FArrayBox& NC_yvel_fab,
75 const amrex::FArrayBox& NC_temp_fab,
76 const amrex::FArrayBox& NC_rhum_fab,
77 const amrex::FArrayBox& NC_pres_fab,
78 amrex::FArrayBox& tmp_src_fab,
79 amrex::FArrayBox& tmp_dst_fab,
80 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xlo,
81 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xhi,
82 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_ylo,
83 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_yhi,
84 const amrex::Array4<const int>& mask_c_arr,
85 const amrex::Array4<const int>& mask_u_arr,
86 const amrex::Array4<const int>& mask_v_arr);
90 amrex::FArrayBox& msfu_fab,
91 amrex::FArrayBox& msfv_fab,
92 amrex::FArrayBox& msfm_fab,
94 amrex::FArrayBox& NC_MSFU_fab,
95 amrex::FArrayBox& NC_MSFV_fab,
96 amrex::FArrayBox& NC_MSFM_fab);
100 const bool metgrid_debug_psfc,
102 const amrex::Box& valid_bx,
103 const int& flag_psfc,
104 amrex::FArrayBox& state_fab,
105 amrex::FArrayBox& r_hse_fab,
106 amrex::FArrayBox& p_hse_fab,
107 amrex::FArrayBox& pi_hse_fab,
108 amrex::FArrayBox& th_hse_fab,
109 amrex::FArrayBox& qv_hse_fab,
110 amrex::FArrayBox& z_phys_nd_fab,
111 amrex::FArrayBox& z_phys_cc_fab,
112 const amrex::FArrayBox& NC_psfc_fab);
129 for (
int i=0; i <= order; i++) {
132 for (
int k=0; k <= order; k++) {
133 if (k == i)
continue;
148 const bool& exp_interp,
166 amrex::ignore_unused(i,j);
167 #ifndef AMREX_USE_GPU
171 for (
int new_k=0; new_k < new_n; new_k++) {
172 #ifndef AMREX_USE_GPU
173 if (debug) amrex::Print() <<
"new_k=" << new_k;
177 bool extrapolating =
true;
179 for (
int ko=0; ko < orig_n-1; ko++) {
185 extrapolating =
false;
191 if (var_type ==
'T') {
194 amrex::Real depth_of_extrap_in_p = new_x_p[new_k]-orig_x_p[0];
200 new_y[new_k] = (temp_extrap_starting_point+dT)*std::pow(
amrex::Real(100000.0)/new_x_p[new_k],
R_d/
Cp_d);
204 new_y[new_k] = orig_y[0];
210 if ((kl-((order+1)/2-1) >= 0) && (kr+((order+1)/2-1) <= orig_n-1)) {
212 int ksta = kl-(((order+1)/2)-1);
213 int kend = ksta+order;
214 #ifndef AMREX_USE_GPU
215 int ksize = kend-ksta;
216 if (debug) amrex::Print() <<
" (1a) order=" << order <<
" new_x_z=" << new_x_z[new_k] <<
" new_x_p=" << new_x_p[new_k] <<
" kl=" << kl <<
" kr=" << kr <<
" ksta=" << ksta <<
" kend=" << kend << std::endl;
219 amrex::GpuArray<amrex::Real,9> orig_x_sub;
222 new_x = new_x_p[new_k];
223 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
225 new_x = new_x_z[new_k];
226 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
228 amrex::GpuArray<amrex::Real,9> orig_y_sub;
230 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
231 #ifndef AMREX_USE_GPU
233 amrex::Print() <<
" orig_x_sub_p = [";
234 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
235 amrex::Print() <<
"]" << std::endl;
236 amrex::Print() <<
" orig_y_sub_p = [";
237 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
238 amrex::Print() <<
"]" << std::endl;
241 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
247 #ifndef AMREX_USE_GPU
248 int ksize = kend-ksta+1;
249 if (debug) amrex::Print() <<
" (1b) order=" << order <<
" new_x=" << new_x_z[new_k] <<
" new_x_p=" << new_x_p[new_k] <<
" kl=" << kl <<
" kr=" << kr <<
" ksta=" << ksta <<
" kend=" << kend << std::endl;
252 amrex::GpuArray<amrex::Real,2> orig_x_sub;
253 amrex::GpuArray<amrex::Real,2> orig_y_sub;
257 new_x = new_x_p[new_k];
258 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
260 new_x = new_x_z[new_k];
261 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
263 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
264 #ifndef AMREX_USE_GPU
266 amrex::Print() <<
" orig_x_sub_p = [";
267 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
268 amrex::Print() <<
"]" << std::endl;
269 amrex::Print() <<
" orig_y_sub_p = [";
270 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
271 amrex::Print() <<
"]" << std::endl;
276 }
else if (order%2 == 0) {
277 if ((kl-(order/2) >= 0) && (kr+order/2 <= orig_n-1)) {
282 int ksta = kl-(order/2-1);
283 int kend = ksta+order;
284 #ifndef AMREX_USE_GPU
285 int ksize = kend-ksta;
286 if (debug) amrex::Print() <<
" (2a) order=" << order <<
" new_x_z=" << new_x_z[new_k] <<
" new_x_p=" << new_x_p[new_k] <<
" kl=" << kl <<
" kr=" << kr <<
" ksta=" << ksta <<
" kend=" << kend << std::endl;
289 amrex::GpuArray<amrex::Real,10> orig_x_sub;
290 amrex::GpuArray<amrex::Real,10> orig_y_sub;
294 new_x = new_x_p[new_k];
295 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
297 new_x = new_x_z[new_k];
298 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
300 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
301 #ifndef AMREX_USE_GPU
303 amrex::Print() <<
" orig_x_sub_p = [";
304 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
305 amrex::Print() <<
"]" << std::endl;
306 amrex::Print() <<
" orig_y_sub_p = [";
307 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
308 amrex::Print() <<
"]" << std::endl;
314 int ksta = kl-order/2;
315 int kend = ksta+order;
316 #ifndef AMREX_USE_GPU
317 int ksize = kend-ksta;
318 if (debug) amrex::Print() <<
"new_k=" << new_k <<
" (2b) order=" << order <<
" new_x_z=" << new_x_z[new_k] <<
" new_x_p=" << new_x_p[new_k] <<
" kl=" << kl <<
" kr=" << kr <<
" ksta=" << ksta <<
" kend=" << kend << std::endl;
321 amrex::GpuArray<amrex::Real,10> orig_x_sub;
322 amrex::GpuArray<amrex::Real,10> orig_y_sub;
326 new_x = new_x_p[new_k];
327 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
329 new_x = new_x_z[new_k];
330 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
332 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
333 #ifndef AMREX_USE_GPU
335 amrex::Print() <<
" orig_x_sub_p = [";
336 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
337 amrex::Print() <<
"]" << std::endl;
338 amrex::Print() <<
" orig_y_sub_p = [";
339 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
340 amrex::Print() <<
"]" << std::endl;
345 new_y[new_k] =
myhalf*(new_y_l+new_y_r);
346 }
else if ((kl-(order/2-1) >= 0) && (kr+order/2 <= orig_n-1)) {
347 int ksta = kl-(order/2-1);
348 int kend = ksta+order;
349 #ifndef AMREX_USE_GPU
350 int ksize = kend-ksta;
351 if (debug) amrex::Print() <<
" (3) order=" << order <<
" new_x_z=" << new_x_z[new_k] <<
" new_x_p=" << new_x_p[new_k] <<
" kl=" << kl <<
" kr=" << kr <<
" ksta=" << ksta <<
" kend=" << kend << std::endl;
354 amrex::GpuArray<amrex::Real,10> orig_x_sub;
355 amrex::GpuArray<amrex::Real,10> orig_y_sub;
359 new_x = new_x_p[new_k];
360 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
362 new_x = new_x_z[new_k];
363 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
365 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
366 #ifndef AMREX_USE_GPU
368 amrex::Print() <<
" orig_x_sub_p = [";
369 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
370 amrex::Print() <<
"]" << std::endl;
371 amrex::Print() <<
" orig_y_sub_p = [";
372 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
373 amrex::Print() <<
"]" << std::endl;
376 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
377 }
else if ((kl-order/2 >= 0) && (kr+order/2-1 <= orig_n-1)) {
378 int ksta = kl-order/2;
379 int kend = ksta+order;
380 #ifndef AMREX_USE_GPU
381 int ksize = kend-ksta;
382 if (debug) amrex::Print() <<
" (4) order=" << order <<
" new_x_z=" << new_x_z[new_k] <<
" new_x_p=" << new_x_p[new_k] <<
" kl=" << kl <<
" kr=" << kr <<
" ksta=" << ksta <<
" kend=" << kend << std::endl;
385 amrex::GpuArray<amrex::Real,10> orig_x_sub;
386 amrex::GpuArray<amrex::Real,10> orig_y_sub;
390 new_x = new_x_p[new_k];
391 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
393 new_x = new_x_z[new_k];
394 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
396 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
397 #ifndef AMREX_USE_GPU
399 amrex::Print() <<
" orig_x_sub_p = [";
400 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
401 amrex::Print() <<
"]" << std::endl;
402 amrex::Print() <<
" orig_y_sub_p = [";
403 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
404 amrex::Print() <<
"]" << std::endl;
407 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
412 #ifndef AMREX_USE_GPU
413 int ksize = kend-ksta+1;
414 if (debug) amrex::Print() <<
" (5) order=" << order <<
" new_x=" << new_x_z[new_k] <<
" new_x_p=" << new_x_p[new_k] <<
" kl=" << kl <<
" kr=" << kr <<
" ksta=" << ksta <<
" kend=" << kend << std::endl;
417 amrex::GpuArray<amrex::Real,2> orig_x_sub;
418 amrex::GpuArray<amrex::Real,2> orig_y_sub;
422 new_x = new_x_p[new_k];
423 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
425 new_x = new_x_z[new_k];
426 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
428 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
429 #ifndef AMREX_USE_GPU
431 amrex::Print() <<
" orig_x_sub_p = [";
432 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
433 amrex::Print() <<
"]" << std::endl;
434 amrex::Print() <<
" orig_y_sub_p = [";
435 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
436 amrex::Print() <<
"]" << std::endl;
442 #ifndef AMREX_USE_GPU
443 if (debug) amrex::Print() <<
" new_y[" << new_k <<
"]=" << new_y[new_k] << std::endl;
461 const bool& metgrid_use_sfc,
462 const bool& exp_interp,
463 const bool& metgrid_retain_sfc,
465 const int& metgrid_order,
466 const int& metgrid_force_sfc_k,
474 const amrex::Array4<amrex::Real const>& orig_z_full,
475 const amrex::Array4<amrex::Real const>& orig_data,
476 const amrex::Array4<amrex::Real const>& new_z_full,
477 const amrex::Array4<amrex::Real>& new_data_full)
483 int imin_orig = amrex::lbound(amrex::Box(orig_data)).x;
484 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
485 int jmin_orig = amrex::lbound(amrex::Box(orig_data)).y;
486 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
487 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
488 int kmax_new = kmax + 1;
490 AMREX_ASSERT(kmax_orig < 256);
491 AMREX_ASSERT(kmax_new < 256);
493 amrex::GpuArray<amrex::Real,256> new_z;
494 amrex::GpuArray<amrex::Real,256> new_p;
495 amrex::GpuArray<amrex::Real,256> new_data;
499 for (
int k=0; k < kmax_new; k++) {
501 new_z_p[k] =
fourth*(new_z_full(i,j,k)+new_z_full(i,j+1,k)+new_z_full(i,j,k+1)+new_z_full(i,j+1,k+1));
502 }
else if (stag ==
'Y') {
503 new_z_p[k] =
fourth*(new_z_full(i,j,k)+new_z_full(i+1,j,k)+new_z_full(i,j,k+1)+new_z_full(i+1,j,k+1));
504 }
else if (stag ==
'M') {
505 new_z_p[k] =
amrex::Real(0.125)*(new_z_full(i,j,k )+new_z_full(i,j+1,k )+new_z_full(i+1,j,k )+new_z_full(i+1,j+1,k )+
506 new_z_full(i,j,k+1)+new_z_full(i,j+1,k+1)+new_z_full(i+1,j,k+1)+new_z_full(i+1,j+1,k+1));
511 amrex::GpuArray<amrex::Real,256> orig_z;
513 for (
int k=0; k < kmax_orig; k++) {
515 orig_z_p[k] = orig_z_full(i,j,k);
516 }
else if (stag ==
'X') {
517 if (i <= imin_orig) {
518 orig_z_p[k] = orig_z_full(i,j,k);
519 }
else if (i >= imax_orig) {
520 orig_z_p[k] = orig_z_full(imax_orig-1,j,k);
522 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i-1,j,k));
524 }
else if (stag ==
'Y') {
525 if (j <= jmin_orig) {
526 orig_z_p[k] = orig_z_full(i,j,k);
527 }
else if (j >= jmax_orig) {
528 orig_z_p[k] = orig_z_full(i,jmax_orig-1,k);
530 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i,j-1,k));
536 bool flip_data_required =
false;
537 if (orig_z[1] > orig_z[kmax_orig-1]) flip_data_required =
true;
538 if (flip_data_required) amrex::Abort(
"metgrid initialization flip_data_required. Not yet implemented.");
544 for (
int k=1; k < kmax_orig; k++) {
545 if (orig_z_p[k] > orig_z_p[0]) {
552 amrex::GpuArray<amrex::Real,256> ordered_z;
553 amrex::GpuArray<amrex::Real,256> ordered_data;
556 if (k_above_sfc > 1) {
562 for (
int k=1; k < k_above_sfc; k++) {
563 ordered_z_p[count] = orig_z_p[k];
564 ordered_data_p[count] = orig_data(i,j,k,src_comp);
578 if (Pl-Pu < metgrid_proximity) {
583 ordered_z_p[count] = orig_z_p[0];
584 ordered_data_p[count] = orig_data(i,j,0,src_comp);
589 int knext = k_above_sfc;
595 if (metgrid_force_sfc_k > 0) {
596 for (
int k=k_above_sfc; k < kmax_orig; k++) {
597 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k-1]) {
608 if (Pl-Pu < metgrid_proximity) {
613 for (
int k=knext; k < kmax_orig; k++) {
614 ordered_z_p[count] = orig_z_p[k];
615 ordered_data_p[count] = orig_data(i,j,k,src_comp);
624 ordered_z_p[0] = orig_z[0];
625 ordered_data_p[0] = orig_data(i,j,0,src_comp);
631 if (metgrid_force_sfc_k > 0) {
632 for (
int k=knext; k < kmax_orig; k++) {
633 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k]) {
642 for (
int k=knext; k < kmax_orig; k++) {
646 if (Pl-Pu < metgrid_proximity) {
649 ordered_z_p[count] = orig_z_p[k];
650 ordered_data_p[count] = orig_data(i,j,k,src_comp);
656 int ksta(0), kend(0);
657 if (metgrid_use_below_sfc && metgrid_use_sfc) {
661 }
else if (metgrid_use_below_sfc && !metgrid_use_sfc) {
664 for (
int k=0; k < kmax_orig; k++) {
665 if (ordered_z_p[k] == orig_z_p[0]) {
670 for (
int k=ksfc; k < kmax_orig-1; k++) {
671 ordered_z_p[k] = ordered_z_p[k+1];
672 ordered_data_p[k] = ordered_data_p[k+1];
676 }
else if (!metgrid_use_below_sfc && metgrid_use_sfc) {
679 for (
int k=0; k < kend_order; k++) {
680 if (ordered_z_p[k] == orig_z_p[0]) {
689 amrex::Abort(
"metgrid initialization, !use_levels below_ground && !metgrid_use_sfc");
705 amrex::GpuArray<amrex::Real,256> ordered_p;
707 for (
int k=0; k < kend_order; k++) {
713 amrex::GpuArray<amrex::Real,256> final_z;
714 amrex::GpuArray<amrex::Real,256> final_p;
715 amrex::GpuArray<amrex::Real,256> final_data;
719 final_z_p[0] = ordered_z[ksta];
720 final_p_p[0] = ordered_p[ksta];
721 final_data_p[0] = ordered_data[ksta];
722 for (
int k=ksta+1; k <= kend; k++) {
723 if ((final_p_p[new_n]-ordered_p_p[k]) < metgrid_proximity) {
727 final_z_p[new_n] = ordered_z_p[k];
728 final_p_p[new_n] = ordered_p_p[k];
729 final_data_p[new_n] = ordered_data_p[k];
751 if (metgrid_retain_sfc) new_data[0] = ordered_data[0];
754 for (
int k=0; k < kmax_new; k++) {
755 new_data_full(i,j,k,dst_comp) = new_data[k];
768 const amrex::Array4<amrex::Real const>& orig_z,
769 const amrex::Array4<amrex::Real const>& orig_data,
770 const amrex::Array4<amrex::Real const>& new_z)
773 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
774 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
775 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
779 z =
fourth*(new_z(i,j,k)+new_z(i,j+1,k)+new_z(i,j,k+1)+new_z(i,j+1,k+1));
781 else if (stag ==
'Y') {
782 z =
fourth*(new_z(i,j,k)+new_z(i+1,j,k)+new_z(i,j,k+1)+new_z(i+1,j,k+1));
784 else if (stag ==
'M') {
785 z =
amrex::Real(0.125)*(new_z(i,j,k )+new_z(i,j+1,k )+new_z(i+1,j,k )+new_z(i+1,j+1,k )+
786 new_z(i,j,k+1)+new_z(i,j+1,k+1)+new_z(i+1,j,k+1)+new_z(i+1,j+1,k+1));
794 for (
int kk = 0; kk < kmax_orig; kk++) {
797 orig_z_stag = orig_z(i,j,kk);
801 orig_z_stag = orig_z(i,j,kk);
803 else if (i == imax_orig) {
804 orig_z_stag = orig_z(imax_orig-1,j,kk);
807 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
810 else if (stag ==
'Y') {
812 orig_z_stag = orig_z(i,j,kk);
814 else if (j == jmax_orig) {
815 orig_z_stag = orig_z(i,jmax_orig-1,kk);
818 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
839 for (
int kk = 0; kk < kmax_orig; kk++) {
842 orig_z_stag = orig_z(i,j,kk);
844 else if (stag ==
'X') {
846 orig_z_stag = orig_z(i,j,kk);
848 else if (i == imax_orig) {
849 orig_z_stag = orig_z(imax_orig-1,j,kk);
852 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
855 else if (stag ==
'Y') {
857 orig_z_stag = orig_z(i,j,kk);
859 else if (j == jmax_orig) {
860 orig_z_stag = orig_z(i,jmax_orig-1,kk);
863 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
867 if ((
dz <
zero) && (
dz > dzhi1) && (kk != khi0)) {
875 return ( y0-(y1-y0)/(z1-
z0)*(
z0-
z) );
878 }
else if (khi0 == -1) {
882 z0 = orig_z(i,j,khi0);
884 else if (stag ==
'X') {
886 z0 = orig_z(i,j,khi0);
888 else if (i == imax_orig) {
889 z0 = orig_z(imax_orig-1,j,khi0);
892 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i-1,j,khi0));
895 else if (stag ==
'Y') {
897 z0 = orig_z(i,j,khi0);
899 else if (j == jmax_orig) {
900 z0 = orig_z(i,jmax_orig-1,khi0);
903 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i,j-1,khi0));
908 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
913 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
924 const amrex::Array4<amrex::Real const>& rhum,
925 const amrex::Array4<amrex::Real const>& temp,
926 const amrex::Array4<amrex::Real const>&
pres,
928 const amrex::Array4<amrex::Real>& mxrat)
942 if (temp(i,j,k) !=
zero) {
946 mxrat(i,j,k,src_indx) = amrex::Math::powi<-6>(
amrex::Real(10.0));
963 if (
pres(i,j,k) < qv_max_p_safe) {
964 if (mxrat(i,j,k,src_indx) > qv_max_flag) {
965 mxrat(i,j,k,src_indx) = qv_max_value;
968 if (
pres(i,j,k) < qv_min_p_safe) {
969 if (mxrat(i,j,k,src_indx) < qv_min_flag) {
970 mxrat(i,j,k,src_indx) = qv_min_value;
constexpr amrex::Real Cp_d
Definition: ERF_Constants.H:23
constexpr amrex::Real one
Definition: ERF_Constants.H:7
constexpr amrex::Real fourth
Definition: ERF_Constants.H:12
constexpr amrex::Real zero
Definition: ERF_Constants.H:6
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:11
constexpr amrex::Real p_0
Definition: ERF_Constants.H:29
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:32
constexpr amrex::Real R_d
Definition: ERF_Constants.H:21
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:8
const bool use_moisture
Definition: ERF_InitCustomPert_Bomex.H:14
const Real dz
Definition: ERF_InitCustomPert_Bubble.H:25
Real * p
Definition: ERF_InitCustomPert_SquallLine.H:61
void init_terrain_from_metgrid(amrex::FArrayBox &z_phys_nd_fab, amrex::FArrayBox &NC_hgt_fab)
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void lagrange_interp(const int &order, amrex::Real *x, amrex::Real *y, amrex::Real &new_x, amrex::Real &new_y)
Definition: ERF_MetgridUtils.H:117
AMREX_FORCE_INLINE AMREX_GPU_DEVICE amrex::Real interpolate_column_metgrid_linear(const int &i, const int &j, const int &k, char stag, int src_comp, const amrex::Array4< amrex::Real const > &orig_z, const amrex::Array4< amrex::Real const > &orig_data, const amrex::Array4< amrex::Real const > &new_z)
Definition: ERF_MetgridUtils.H:763
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void interpolate_column_metgrid(const bool &metgrid_use_below_sfc, const bool &metgrid_use_sfc, const bool &exp_interp, const bool &metgrid_retain_sfc, const amrex::Real &metgrid_proximity, const int &metgrid_order, const int &metgrid_force_sfc_k, const int &i, const int &j, const int &kmax, const int &src_comp, const int &dst_comp, char var_type, char stag, const amrex::Array4< amrex::Real const > &orig_z_full, const amrex::Array4< amrex::Real const > &orig_data, const amrex::Array4< amrex::Real const > &new_z_full, const amrex::Array4< amrex::Real > &new_data_full)
Definition: ERF_MetgridUtils.H:460
void read_from_metgrid(int lev, int itime, const amrex::Box &domain, const std::string &fname, std::string &NC_dateTime, amrex::Real &NC_epochTime, int &flag_psfc, int &flag_msf, int &flag_sst, int &flag_tsk, int &flag_lmask, int &NC_nx, int &NC_ny, amrex::Real &NC_dx, amrex::Real &NC_dy, amrex::FArrayBox &NC_xvel_fab, amrex::FArrayBox &NC_yvel_fab, amrex::FArrayBox &NC_temp_fab, amrex::FArrayBox &NC_rhum_fab, amrex::FArrayBox &NC_pres_fab, amrex::FArrayBox &NC_ght_fab, amrex::FArrayBox &NC_hgt_fab, amrex::FArrayBox &NC_psfc_fab, amrex::FArrayBox &NC_msfu_fab, amrex::FArrayBox &NC_msfv_fab, amrex::FArrayBox &NC_msfm_fab, amrex::FArrayBox &NC_sst_fab, amrex::FArrayBox &NC_tsk_fab, amrex::FArrayBox &NC_LAT_fab, amrex::FArrayBox &NC_LON_fab, amrex::IArrayBox &NC_lmask_iab, amrex::Geometry &geom)
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void calc_p_isothermal(const amrex::Real &z, amrex::Real &p)
Definition: ERF_MetgridUtils.H:451
void init_msfs_from_metgrid(const bool metgrid_debug_msf, amrex::FArrayBox &msfu_fab, amrex::FArrayBox &msfv_fab, amrex::FArrayBox &msfm_fab, const int &flag_msf, amrex::FArrayBox &NC_MSFU_fab, amrex::FArrayBox &NC_MSFV_fab, amrex::FArrayBox &NC_MSFM_fab)
void init_state_from_metgrid(const int lev, const int itime, const bool use_moisture, const bool interp_theta, const bool metgrid_debug_quiescent, const bool metgrid_debug_isothermal, const bool metgrid_debug_dry, const bool metgrid_basic_linear, const bool metgrid_use_below_sfc, const bool metgrid_use_sfc, const bool metgrid_retain_sfc, const amrex::Real metgrid_proximity, const int metgrid_order, const int metgrid_metgrid_force_sfc_k, const amrex::Real l_rdOcp, amrex::Box &tbxc, amrex::Box &tbxu, amrex::Box &tbxv, amrex::FArrayBox &state_fab, amrex::FArrayBox &x_vel_fab, amrex::FArrayBox &y_vel_fab, amrex::FArrayBox &z_vel_fab, amrex::FArrayBox &z_phys_nd_fab, const amrex::FArrayBox &NC_ght_fab, const amrex::FArrayBox &NC_xvel_fab, const amrex::FArrayBox &NC_yvel_fab, const amrex::FArrayBox &NC_temp_fab, const amrex::FArrayBox &NC_rhum_fab, const amrex::FArrayBox &NC_pres_fab, amrex::FArrayBox &tmp_src_fab, amrex::FArrayBox &tmp_dst_fab, amrex::Vector< amrex::Vector< amrex::FArrayBox >> &fabs_for_bcs_xlo, amrex::Vector< amrex::Vector< amrex::FArrayBox >> &fabs_for_bcs_xhi, amrex::Vector< amrex::Vector< amrex::FArrayBox >> &fabs_for_bcs_ylo, amrex::Vector< amrex::Vector< amrex::FArrayBox >> &fabs_for_bcs_yhi, const amrex::Array4< const int > &mask_c_arr, const amrex::Array4< const int > &mask_u_arr, const amrex::Array4< const int > &mask_v_arr)
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void lagrange_setup(char var_type, const bool &exp_interp, const int &orig_n, const int &new_n, const int &order, const int &i, const int &j, amrex::Real *orig_x_z, amrex::Real *orig_x_p, amrex::Real *orig_y, amrex::Real *new_x_z, amrex::Real *new_x_p, amrex::Real *new_y)
Definition: ERF_MetgridUtils.H:147
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void rh_to_mxrat(int i, int j, int k, const amrex::Array4< amrex::Real const > &rhum, const amrex::Array4< amrex::Real const > &temp, const amrex::Array4< amrex::Real const > &pres, int src_indx, const amrex::Array4< amrex::Real > &mxrat)
Definition: ERF_MetgridUtils.H:921
void init_base_state_from_metgrid(const bool use_moisture, const bool metgrid_debug_psfc, const amrex::Real l_rdOcp, const amrex::Box &valid_bx, const int &flag_psfc, amrex::FArrayBox &state_fab, amrex::FArrayBox &r_hse_fab, amrex::FArrayBox &p_hse_fab, amrex::FArrayBox &pi_hse_fab, amrex::FArrayBox &th_hse_fab, amrex::FArrayBox &qv_hse_fab, amrex::FArrayBox &z_phys_nd_fab, amrex::FArrayBox &z_phys_cc_fab, const amrex::FArrayBox &NC_psfc_fab)
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ pres
Definition: ERF_Kessler.H:25
real(c_double), parameter svp1
Definition: ERF_module_model_constants.F90:78
real(c_double), parameter svp3
Definition: ERF_module_model_constants.F90:80
real(c_double), parameter svp2
Definition: ERF_module_model_constants.F90:79
real(c_double), parameter svpt0
Definition: ERF_module_model_constants.F90:81