4 #ifndef ERF_METGRIDUTIL_H_
5 #define ERF_METGRIDUTIL_H_
23 const amrex::Box& domain,
24 const std::string& fname,
25 std::string& NC_dateTime,
36 amrex::FArrayBox& NC_xvel_fab,
37 amrex::FArrayBox& NC_yvel_fab,
38 amrex::FArrayBox& NC_temp_fab,
39 amrex::FArrayBox& NC_rhum_fab,
40 amrex::FArrayBox& NC_pres_fab,
41 amrex::FArrayBox& NC_ght_fab,
42 amrex::FArrayBox& NC_hgt_fab,
43 amrex::FArrayBox& NC_psfc_fab,
44 amrex::FArrayBox& NC_msfu_fab,
45 amrex::FArrayBox& NC_msfv_fab,
46 amrex::FArrayBox& NC_msfm_fab,
47 amrex::FArrayBox& NC_sst_fab,
48 amrex::FArrayBox& NC_tsk_fab,
49 amrex::FArrayBox& NC_LAT_fab,
50 amrex::FArrayBox& NC_LON_fab,
51 amrex::IArrayBox& NC_lmask_iab,
52 amrex::Geometry& geom);
59 amrex::Geometry& geom,
60 amrex::MultiFab* z_phys_nd,
61 amrex::FArrayBox& NC_hgt_fab);
70 const bool interp_theta,
71 const bool metgrid_debug_quiescent,
72 const bool metgrid_debug_isothermal,
73 const bool metgrid_debug_dry,
74 const bool metgrid_basic_linear,
75 const bool metgrid_use_below_sfc,
76 const bool metgrid_use_sfc,
77 const bool metgrid_retain_sfc,
79 const int metgrid_order,
80 const int metgrid_metgrid_force_sfc_k,
86 amrex::FArrayBox& state_fab,
87 amrex::FArrayBox& x_vel_fab,
88 amrex::FArrayBox& y_vel_fab,
89 amrex::FArrayBox& z_vel_fab,
90 amrex::FArrayBox& z_phys_nd_fab,
91 const amrex::FArrayBox& NC_ght_fab,
92 const amrex::FArrayBox& NC_xvel_fab,
93 const amrex::FArrayBox& NC_yvel_fab,
94 const amrex::FArrayBox& NC_temp_fab,
95 const amrex::FArrayBox& NC_rhum_fab,
96 const amrex::FArrayBox& NC_pres_fab,
97 amrex::FArrayBox& tmp_src_fab,
98 amrex::FArrayBox& tmp_dst_fab,
99 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xlo,
100 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xhi,
101 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_ylo,
102 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_yhi,
103 const amrex::Array4<const int>& mask_c_arr,
104 const amrex::Array4<const int>& mask_u_arr,
105 const amrex::Array4<const int>& mask_v_arr);
112 amrex::FArrayBox& msfu_fab,
113 amrex::FArrayBox& msfv_fab,
114 amrex::FArrayBox& msfm_fab,
116 amrex::FArrayBox& NC_MSFU_fab,
117 amrex::FArrayBox& NC_MSFV_fab,
118 amrex::FArrayBox& NC_MSFM_fab);
126 const bool metgrid_debug_psfc,
128 const amrex::Box& domain,
129 const amrex::Box& valid_bx,
130 const int& flag_psfc,
131 amrex::FArrayBox& state_fab,
132 amrex::FArrayBox& r_hse_fab,
133 amrex::FArrayBox& p_hse_fab,
134 amrex::FArrayBox& pi_hse_fab,
135 amrex::FArrayBox& th_hse_fab,
136 amrex::FArrayBox& qv_hse_fab,
137 amrex::FArrayBox& z_phys_nd_fab,
138 amrex::FArrayBox& z_phys_cc_fab,
139 const amrex::FArrayBox& NC_psfc_fab,
160 for (
int i=0; i <= order; i++) {
163 for (
int k=0; k <= order; k++) {
164 if (k == i)
continue;
186 const bool& exp_interp,
187 const int& orig_npts,
204 amrex::ignore_unused(i,j);
205 #ifndef AMREX_USE_GPU
209 for (
int new_k=0; new_k < new_npts; new_k++) {
210 #ifndef AMREX_USE_GPU
211 if (debug) amrex::Print() <<
"new_k=" << new_k;
215 bool extrapolating =
true;
217 for (
int ko=0; ko < orig_npts-1; ko++) {
223 extrapolating =
false;
229 if (var_type ==
'T') {
232 amrex::Real depth_of_extrap_in_p = new_x_p[new_k]-orig_x_p[0];
238 new_y[new_k] = (temp_extrap_starting_point+dT)*std::pow(
amrex::Real(100000.0)/new_x_p[new_k],
RdoCp);
242 new_y[new_k] = orig_y[0];
248 if ((kl-((order+1)/2-1) >= 0) && (kr+((order+1)/2-1) <= orig_npts-1)) {
250 int ksta = kl-(((order+1)/2)-1);
251 int kend = ksta+order;
252 #ifndef AMREX_USE_GPU
253 int ksize = kend-ksta;
254 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;
257 amrex::GpuArray<amrex::Real,9> orig_x_sub;
260 new_x = new_x_p[new_k];
261 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
263 new_x = new_x_z[new_k];
264 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
266 amrex::GpuArray<amrex::Real,9> orig_y_sub;
268 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
269 #ifndef AMREX_USE_GPU
271 amrex::Print() <<
" orig_x_sub_p = [";
272 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
273 amrex::Print() <<
"]" << std::endl;
274 amrex::Print() <<
" orig_y_sub_p = [";
275 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
276 amrex::Print() <<
"]" << std::endl;
279 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
285 #ifndef AMREX_USE_GPU
286 int ksize = kend-ksta+1;
287 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;
290 amrex::GpuArray<amrex::Real,2> orig_x_sub;
291 amrex::GpuArray<amrex::Real,2> orig_y_sub;
295 new_x = new_x_p[new_k];
296 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
298 new_x = new_x_z[new_k];
299 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
301 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
302 #ifndef AMREX_USE_GPU
304 amrex::Print() <<
" orig_x_sub_p = [";
305 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
306 amrex::Print() <<
"]" << std::endl;
307 amrex::Print() <<
" orig_y_sub_p = [";
308 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
309 amrex::Print() <<
"]" << std::endl;
314 }
else if (order%2 == 0) {
315 if ((kl-(order/2) >= 0) && (kr+order/2 <= orig_npts-1)) {
320 int ksta = kl-(order/2-1);
321 int kend = ksta+order;
322 #ifndef AMREX_USE_GPU
323 int ksize = kend-ksta;
324 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;
327 amrex::GpuArray<amrex::Real,10> orig_x_sub;
328 amrex::GpuArray<amrex::Real,10> orig_y_sub;
332 new_x = new_x_p[new_k];
333 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
335 new_x = new_x_z[new_k];
336 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
338 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
339 #ifndef AMREX_USE_GPU
341 amrex::Print() <<
" orig_x_sub_p = [";
342 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
343 amrex::Print() <<
"]" << std::endl;
344 amrex::Print() <<
" orig_y_sub_p = [";
345 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
346 amrex::Print() <<
"]" << std::endl;
352 int ksta = kl-order/2;
353 int kend = ksta+order;
354 #ifndef AMREX_USE_GPU
355 int ksize = kend-ksta;
356 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;
359 amrex::GpuArray<amrex::Real,10> orig_x_sub;
360 amrex::GpuArray<amrex::Real,10> orig_y_sub;
364 new_x = new_x_p[new_k];
365 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
367 new_x = new_x_z[new_k];
368 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
370 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
371 #ifndef AMREX_USE_GPU
373 amrex::Print() <<
" orig_x_sub_p = [";
374 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
375 amrex::Print() <<
"]" << std::endl;
376 amrex::Print() <<
" orig_y_sub_p = [";
377 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
378 amrex::Print() <<
"]" << std::endl;
383 new_y[new_k] =
myhalf*(new_y_l+new_y_r);
384 }
else if ((kl-(order/2-1) >= 0) && (kr+order/2 <= orig_npts-1)) {
385 int ksta = kl-(order/2-1);
386 int kend = ksta+order;
387 #ifndef AMREX_USE_GPU
388 int ksize = kend-ksta;
389 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;
392 amrex::GpuArray<amrex::Real,10> orig_x_sub;
393 amrex::GpuArray<amrex::Real,10> orig_y_sub;
397 new_x = new_x_p[new_k];
398 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
400 new_x = new_x_z[new_k];
401 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
403 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
404 #ifndef AMREX_USE_GPU
406 amrex::Print() <<
" orig_x_sub_p = [";
407 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
408 amrex::Print() <<
"]" << std::endl;
409 amrex::Print() <<
" orig_y_sub_p = [";
410 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
411 amrex::Print() <<
"]" << std::endl;
414 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
415 }
else if ((kl-order/2 >= 0) && (kr+order/2-1 <= orig_npts-1)) {
416 int ksta = kl-order/2;
417 int kend = ksta+order;
418 #ifndef AMREX_USE_GPU
419 int ksize = kend-ksta;
420 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;
423 amrex::GpuArray<amrex::Real,10> orig_x_sub;
424 amrex::GpuArray<amrex::Real,10> orig_y_sub;
428 new_x = new_x_p[new_k];
429 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
431 new_x = new_x_z[new_k];
432 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
434 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
435 #ifndef AMREX_USE_GPU
437 amrex::Print() <<
" orig_x_sub_p = [";
438 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
439 amrex::Print() <<
"]" << std::endl;
440 amrex::Print() <<
" orig_y_sub_p = [";
441 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
442 amrex::Print() <<
"]" << std::endl;
445 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
450 #ifndef AMREX_USE_GPU
451 int ksize = kend-ksta+1;
452 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;
455 amrex::GpuArray<amrex::Real,2> orig_x_sub;
456 amrex::GpuArray<amrex::Real,2> orig_y_sub;
460 new_x = new_x_p[new_k];
461 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
463 new_x = new_x_z[new_k];
464 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
466 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
467 #ifndef AMREX_USE_GPU
469 amrex::Print() <<
" orig_x_sub_p = [";
470 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
471 amrex::Print() <<
"]" << std::endl;
472 amrex::Print() <<
" orig_y_sub_p = [";
473 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
474 amrex::Print() <<
"]" << std::endl;
480 #ifndef AMREX_USE_GPU
481 if (debug) amrex::Print() <<
" new_y[" << new_k <<
"]=" << new_y[new_k] << std::endl;
505 const bool& metgrid_use_sfc,
506 const bool& exp_interp,
507 const bool& metgrid_retain_sfc,
509 const int& metgrid_order,
510 const int& metgrid_force_sfc_k,
518 const amrex::Array4<amrex::Real const>& orig_z_full,
519 const amrex::Array4<amrex::Real const>& orig_data,
520 const amrex::Array4<amrex::Real const>& new_z_full,
521 const amrex::Array4<amrex::Real>& new_data_full)
527 int imin_orig = amrex::lbound(amrex::Box(orig_data)).x;
528 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
529 int jmin_orig = amrex::lbound(amrex::Box(orig_data)).y;
530 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
531 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
532 int kmax_new = kmax + 1;
534 AMREX_ASSERT(kmax_orig < 256);
535 AMREX_ASSERT(kmax_new < 256);
537 amrex::GpuArray<amrex::Real,256> new_z;
538 amrex::GpuArray<amrex::Real,256> new_p;
539 amrex::GpuArray<amrex::Real,256> new_data;
543 for (
int k=0; k < kmax_new; k++) {
545 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));
546 }
else if (stag ==
'Y') {
547 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));
548 }
else if (stag ==
'M') {
549 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 )+
550 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));
555 amrex::GpuArray<amrex::Real,256> orig_z;
557 for (
int k=0; k < kmax_orig; k++) {
559 orig_z_p[k] = orig_z_full(i,j,k);
560 }
else if (stag ==
'X') {
561 if (i <= imin_orig) {
562 orig_z_p[k] = orig_z_full(i,j,k);
563 }
else if (i >= imax_orig) {
564 orig_z_p[k] = orig_z_full(imax_orig-1,j,k);
566 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i-1,j,k));
568 }
else if (stag ==
'Y') {
569 if (j <= jmin_orig) {
570 orig_z_p[k] = orig_z_full(i,j,k);
571 }
else if (j >= jmax_orig) {
572 orig_z_p[k] = orig_z_full(i,jmax_orig-1,k);
574 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i,j-1,k));
580 bool flip_data_required =
false;
581 if (orig_z[1] > orig_z[kmax_orig-1]) flip_data_required =
true;
582 if (flip_data_required) amrex::Abort(
"metgrid initialization flip_data_required. Not yet implemented.");
588 for (
int k=1; k < kmax_orig; k++) {
589 if (orig_z_p[k] > orig_z_p[0]) {
596 amrex::GpuArray<amrex::Real,256> ordered_z;
597 amrex::GpuArray<amrex::Real,256> ordered_data;
600 if (k_above_sfc > 1) {
606 for (
int k=1; k < k_above_sfc; k++) {
607 ordered_z_p[count] = orig_z_p[k];
608 ordered_data_p[count] = orig_data(i,j,k,src_comp);
622 if (Pl-Pu < metgrid_proximity) {
627 ordered_z_p[count] = orig_z_p[0];
628 ordered_data_p[count] = orig_data(i,j,0,src_comp);
633 int knext = k_above_sfc;
639 if (metgrid_force_sfc_k > 0) {
640 for (
int k=k_above_sfc; k < kmax_orig; k++) {
641 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k-1]) {
652 if (Pl-Pu < metgrid_proximity) {
657 for (
int k=knext; k < kmax_orig; k++) {
658 ordered_z_p[count] = orig_z_p[k];
659 ordered_data_p[count] = orig_data(i,j,k,src_comp);
668 ordered_z_p[0] = orig_z[0];
669 ordered_data_p[0] = orig_data(i,j,0,src_comp);
675 if (metgrid_force_sfc_k > 0) {
676 for (
int k=knext; k < kmax_orig; k++) {
677 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k]) {
686 for (
int k=knext; k < kmax_orig; k++) {
690 if (Pl-Pu < metgrid_proximity) {
693 ordered_z_p[count] = orig_z_p[k];
694 ordered_data_p[count] = orig_data(i,j,k,src_comp);
700 int ksta(0), kend(0);
701 if (metgrid_use_below_sfc && metgrid_use_sfc) {
705 }
else if (metgrid_use_below_sfc && !metgrid_use_sfc) {
708 for (
int k=0; k < kmax_orig; k++) {
709 if (ordered_z_p[k] == orig_z_p[0]) {
714 for (
int k=ksfc; k < kmax_orig-1; k++) {
715 ordered_z_p[k] = ordered_z_p[k+1];
716 ordered_data_p[k] = ordered_data_p[k+1];
720 }
else if (!metgrid_use_below_sfc && metgrid_use_sfc) {
723 for (
int k=0; k < kend_order; k++) {
724 if (ordered_z_p[k] == orig_z_p[0]) {
733 amrex::Abort(
"metgrid initialization, !use_levels below_ground && !metgrid_use_sfc");
749 amrex::GpuArray<amrex::Real,256> ordered_p;
751 for (
int k=0; k < kend_order; k++) {
758 amrex::GpuArray<amrex::Real,256> final_z;
759 amrex::GpuArray<amrex::Real,256> final_p;
760 amrex::GpuArray<amrex::Real,256> final_data;
764 final_z_p[0] = ordered_z[ksta];
765 final_p_p[0] = ordered_p[ksta];
766 final_data_p[0] = ordered_data[ksta];
767 for (
int k=ksta+1; k <= kend; k++) {
769 if ((final_p_p[kfinal]-ordered_p_p[k]) < metgrid_proximity)
continue;
771 final_z_p[kfinal] = ordered_z_p[k];
772 final_p_p[kfinal] = ordered_p_p[k];
773 final_data_p[kfinal] = ordered_data_p[k];
793 if (metgrid_retain_sfc) new_data[0] = ordered_data[0];
796 for (
int k=0; k < kmax_new; k++) {
797 new_data_full(i,j,k,dst_comp) = new_data[k];
813 const amrex::Array4<amrex::Real const>& orig_z,
814 const amrex::Array4<amrex::Real const>& orig_data,
815 const amrex::Array4<amrex::Real const>& new_z)
818 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
819 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
820 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
824 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));
826 else if (stag ==
'Y') {
827 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));
829 else if (stag ==
'M') {
830 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 )+
831 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));
836 amrex::Real z0 = std::numeric_limits<amrex::Real>::quiet_NaN();
837 amrex::Real z1 = std::numeric_limits<amrex::Real>::quiet_NaN();
842 for (
int kk = 0; kk < kmax_orig; kk++) {
845 orig_z_stag = orig_z(i,j,kk);
849 orig_z_stag = orig_z(i,j,kk);
851 else if (i == imax_orig) {
852 orig_z_stag = orig_z(imax_orig-1,j,kk);
855 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
858 else if (stag ==
'Y') {
860 orig_z_stag = orig_z(i,j,kk);
862 else if (j == jmax_orig) {
863 orig_z_stag = orig_z(i,jmax_orig-1,kk);
866 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
891 for (
int kk = 0; kk < kmax_orig; kk++) {
894 orig_z_stag = orig_z(i,j,kk);
896 else if (stag ==
'X') {
898 orig_z_stag = orig_z(i,j,kk);
900 else if (i == imax_orig) {
901 orig_z_stag = orig_z(imax_orig-1,j,kk);
904 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
907 else if (stag ==
'Y') {
909 orig_z_stag = orig_z(i,j,kk);
911 else if (j == jmax_orig) {
912 orig_z_stag = orig_z(i,jmax_orig-1,kk);
915 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
919 if ((
dz <
zero) && (
dz > dzhi1) && (kk != khi0)) {
927 return ( y0-(y1-y0)/(z1-
z0)*(
z0-
z) );
930 }
else if (khi0 == -1) {
938 z0 = orig_z(i,j,khi0);
940 else if (stag ==
'X') {
942 z0 = orig_z(i,j,khi0);
944 else if (i == imax_orig) {
945 z0 = orig_z(imax_orig-1,j,khi0);
948 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i-1,j,khi0));
951 else if (stag ==
'Y') {
953 z0 = orig_z(i,j,khi0);
955 else if (j == jmax_orig) {
956 z0 = orig_z(i,jmax_orig-1,khi0);
959 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i,j-1,khi0));
964 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
969 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
983 const amrex::Array4<amrex::Real const>& rhum,
984 const amrex::Array4<amrex::Real const>& temp,
985 const amrex::Array4<amrex::Real const>&
pres,
987 const amrex::Array4<amrex::Real>& mxrat)
1001 if (temp(i,j,k) !=
zero) {
1005 mxrat(i,j,k,src_indx) = amrex::Math::powi<-6>(
amrex::Real(10.0));
1022 if (
pres(i,j,k) < qv_max_p_safe) {
1023 if (mxrat(i,j,k,src_indx) > qv_max_flag) {
1024 mxrat(i,j,k,src_indx) = qv_max_value;
1027 if (
pres(i,j,k) < qv_min_p_safe) {
1028 if (mxrat(i,j,k,src_indx) < qv_min_flag) {
1029 mxrat(i,j,k,src_indx) = qv_min_value;
constexpr amrex::Real one
Definition: ERF_Constants.H:9
constexpr amrex::Real fourth
Definition: ERF_Constants.H:14
constexpr amrex::Real zero
Definition: ERF_Constants.H:8
constexpr amrex::Real myhalf
Definition: ERF_Constants.H:13
constexpr amrex::Real p_0
Definition: ERF_Constants.H:61
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:64
constexpr amrex::Real R_d
Definition: ERF_Constants.H:47
constexpr amrex::Real RdoCp
Definition: ERF_Constants.H:54
constexpr amrex::Real RdoRv
Definition: ERF_Constants.H:57
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:8
const bool use_moisture
Definition: ERF_InitCustomPert_ABL.H:71
void init_terrain_from_metgrid(const bool &avg_grid_faces_to_nodes, amrex::Geometry &geom, amrex::MultiFab *z_phys_nd, amrex::FArrayBox &NC_hgt_fab)
void init_base_state_from_metgrid(const bool use_moisture, const bool metgrid_debug_psfc, const amrex::Real l_rdOcp, const amrex::Box &domain, 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, const BaseStateParams &bsp)
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:148
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:808
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:504
void read_from_metgrid(int lev, int itime, const amrex::Box &domain, const std::string &fname, std::string &NC_dateTime, double &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:492
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)
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void lagrange_setup(char var_type, const bool &exp_interp, const int &orig_npts, const int &new_npts, 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:185
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::Box &tbxw, 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 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:980
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ pres
Definition: ERF_Kessler.H:27
@ dz
Definition: ERF_AdvanceWDM6.cpp:270
@ p
Definition: ERF_WSM6.H:191
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
Definition: ERF_BaseStateParams.H:35