4 #ifndef ERF_METGRIDUTIL_H_
5 #define ERF_METGRIDUTIL_H_
7 #include <AMReX_Math.H>
28 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
39 pressure = std::numeric_limits<amrex::Real>::quiet_NaN();
45 if (!amrex::Math::isfinite(file_psfc) || file_psfc <=
amrex::Real(0.0)) {
52 if (!amrex::Math::isfinite(z_sfc) || !amrex::Math::isfinite(P00) || P00 <=
amrex::Real(0.0) ||
53 !amrex::Math::isfinite(T00) || T00 <=
amrex::Real(0.0) ||
54 !amrex::Math::isfinite(TLP) || TLP <=
amrex::Real(0.0)) {
60 if (!amrex::Math::isfinite(radicand) || radicand <
amrex::Real(0.0)) {
63 const amrex::Real exponent = -ToA + std::sqrt(radicand);
64 const amrex::Real result = P00 * std::exp(exponent);
65 if (!amrex::Math::isfinite(result) || result <=
amrex::Real(0.0)) {
77 AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE
80 const bool debug_psfc,
92 P00, T00, TLP, surface_pressure)) {
105 const amrex::Box& domain,
106 const std::string& fname,
107 std::string& NC_dateTime,
108 double& NC_epochTime,
118 amrex::FArrayBox& NC_xvel_fab,
119 amrex::FArrayBox& NC_yvel_fab,
120 amrex::FArrayBox& NC_temp_fab,
121 amrex::FArrayBox& NC_rhum_fab,
122 amrex::FArrayBox& NC_pres_fab,
123 amrex::FArrayBox& NC_ght_fab,
124 amrex::FArrayBox& NC_hgt_fab,
125 amrex::FArrayBox& NC_psfc_fab,
126 amrex::FArrayBox& NC_msfu_fab,
127 amrex::FArrayBox& NC_msfv_fab,
128 amrex::FArrayBox& NC_msfm_fab,
129 amrex::FArrayBox& NC_sst_fab,
130 amrex::FArrayBox& NC_tsk_fab,
131 amrex::FArrayBox& NC_LAT_fab,
132 amrex::FArrayBox& NC_LON_fab,
133 amrex::IArrayBox& NC_lmask_iab,
134 amrex::Geometry& geom);
141 amrex::Geometry& geom,
142 amrex::MultiFab* z_phys_nd,
143 amrex::FArrayBox& NC_hgt_fab);
152 const bool interp_theta,
153 const bool metgrid_debug_quiescent,
154 const bool metgrid_debug_isothermal,
155 const bool metgrid_debug_dry,
156 const bool metgrid_basic_linear,
157 const bool metgrid_use_below_sfc,
158 const bool metgrid_use_sfc,
159 const bool metgrid_retain_sfc,
161 const int metgrid_order,
162 const int metgrid_metgrid_force_sfc_k,
168 amrex::FArrayBox& state_fab,
169 amrex::FArrayBox& x_vel_fab,
170 amrex::FArrayBox& y_vel_fab,
171 amrex::FArrayBox& z_vel_fab,
172 amrex::FArrayBox& z_phys_nd_fab,
173 const amrex::FArrayBox& NC_ght_fab,
174 const amrex::FArrayBox& NC_xvel_fab,
175 const amrex::FArrayBox& NC_yvel_fab,
176 const amrex::FArrayBox& NC_temp_fab,
177 const amrex::FArrayBox& NC_rhum_fab,
178 const amrex::FArrayBox& NC_pres_fab,
179 amrex::FArrayBox& tmp_src_fab,
180 amrex::FArrayBox& tmp_dst_fab,
181 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xlo,
182 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xhi,
183 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_ylo,
184 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_yhi,
185 const amrex::Array4<const int>& mask_c_arr,
186 const amrex::Array4<const int>& mask_u_arr,
187 const amrex::Array4<const int>& mask_v_arr);
194 amrex::FArrayBox& msfu_fab,
195 amrex::FArrayBox& msfv_fab,
196 amrex::FArrayBox& msfm_fab,
198 amrex::FArrayBox& NC_MSFU_fab,
199 amrex::FArrayBox& NC_MSFV_fab,
200 amrex::FArrayBox& NC_MSFM_fab);
208 const bool metgrid_debug_psfc,
210 const amrex::Box& domain,
211 const amrex::Box& valid_bx,
212 const int& flag_psfc,
213 amrex::FArrayBox& state_fab,
214 amrex::FArrayBox& r_hse_fab,
215 amrex::FArrayBox& p_hse_fab,
216 amrex::FArrayBox& pi_hse_fab,
217 amrex::FArrayBox& th_hse_fab,
218 amrex::FArrayBox& qv_hse_fab,
219 amrex::FArrayBox& z_phys_nd_fab,
220 amrex::FArrayBox& z_phys_cc_fab,
221 const amrex::FArrayBox& NC_psfc_fab,
222 int* base_state_column_failed,
243 for (
int i=0; i <= order; i++) {
246 for (
int k=0; k <= order; k++) {
247 if (k == i)
continue;
269 const bool& exp_interp,
270 const int& orig_npts,
287 amrex::ignore_unused(i,j);
288 #ifndef AMREX_USE_GPU
292 for (
int new_k=0; new_k < new_npts; new_k++) {
293 #ifndef AMREX_USE_GPU
294 if (debug) amrex::Print() <<
"new_k=" << new_k;
298 bool extrapolating =
true;
300 for (
int ko=0; ko < orig_npts-1; ko++) {
306 extrapolating =
false;
312 if (var_type ==
'T') {
315 amrex::Real depth_of_extrap_in_p = new_x_p[new_k]-orig_x_p[0];
321 new_y[new_k] = (temp_extrap_starting_point+dT)*std::pow(
amrex::Real(100000.0)/new_x_p[new_k],
RdoCp);
325 new_y[new_k] = orig_y[0];
331 if ((kl-((order+1)/2-1) >= 0) && (kr+((order+1)/2-1) <= orig_npts-1)) {
333 int ksta = kl-(((order+1)/2)-1);
334 int kend = ksta+order;
335 #ifndef AMREX_USE_GPU
336 int ksize = kend-ksta;
337 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;
340 amrex::GpuArray<amrex::Real,9> orig_x_sub;
343 new_x = new_x_p[new_k];
344 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
346 new_x = new_x_z[new_k];
347 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
349 amrex::GpuArray<amrex::Real,9> orig_y_sub;
351 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
352 #ifndef AMREX_USE_GPU
354 amrex::Print() <<
" orig_x_sub_p = [";
355 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
356 amrex::Print() <<
"]" << std::endl;
357 amrex::Print() <<
" orig_y_sub_p = [";
358 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
359 amrex::Print() <<
"]" << std::endl;
362 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
368 #ifndef AMREX_USE_GPU
369 int ksize = kend-ksta+1;
370 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;
373 amrex::GpuArray<amrex::Real,2> orig_x_sub;
374 amrex::GpuArray<amrex::Real,2> orig_y_sub;
378 new_x = new_x_p[new_k];
379 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
381 new_x = new_x_z[new_k];
382 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
384 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
385 #ifndef AMREX_USE_GPU
387 amrex::Print() <<
" orig_x_sub_p = [";
388 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
389 amrex::Print() <<
"]" << std::endl;
390 amrex::Print() <<
" orig_y_sub_p = [";
391 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
392 amrex::Print() <<
"]" << std::endl;
397 }
else if (order%2 == 0) {
398 if ((kl-(order/2) >= 0) && (kr+order/2 <= orig_npts-1)) {
403 int ksta = kl-(order/2-1);
404 int kend = ksta+order;
405 #ifndef AMREX_USE_GPU
406 int ksize = kend-ksta;
407 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;
410 amrex::GpuArray<amrex::Real,10> orig_x_sub;
411 amrex::GpuArray<amrex::Real,10> orig_y_sub;
415 new_x = new_x_p[new_k];
416 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
418 new_x = new_x_z[new_k];
419 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
421 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
422 #ifndef AMREX_USE_GPU
424 amrex::Print() <<
" orig_x_sub_p = [";
425 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
426 amrex::Print() <<
"]" << std::endl;
427 amrex::Print() <<
" orig_y_sub_p = [";
428 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
429 amrex::Print() <<
"]" << std::endl;
435 int ksta = kl-order/2;
436 int kend = ksta+order;
437 #ifndef AMREX_USE_GPU
438 int ksize = kend-ksta;
439 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;
442 amrex::GpuArray<amrex::Real,10> orig_x_sub;
443 amrex::GpuArray<amrex::Real,10> orig_y_sub;
447 new_x = new_x_p[new_k];
448 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
450 new_x = new_x_z[new_k];
451 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
453 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
454 #ifndef AMREX_USE_GPU
456 amrex::Print() <<
" orig_x_sub_p = [";
457 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
458 amrex::Print() <<
"]" << std::endl;
459 amrex::Print() <<
" orig_y_sub_p = [";
460 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
461 amrex::Print() <<
"]" << std::endl;
466 new_y[new_k] =
myhalf*(new_y_l+new_y_r);
467 }
else if ((kl-(order/2-1) >= 0) && (kr+order/2 <= orig_npts-1)) {
468 int ksta = kl-(order/2-1);
469 int kend = ksta+order;
470 #ifndef AMREX_USE_GPU
471 int ksize = kend-ksta;
472 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;
475 amrex::GpuArray<amrex::Real,10> orig_x_sub;
476 amrex::GpuArray<amrex::Real,10> orig_y_sub;
480 new_x = new_x_p[new_k];
481 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
483 new_x = new_x_z[new_k];
484 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
486 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
487 #ifndef AMREX_USE_GPU
489 amrex::Print() <<
" orig_x_sub_p = [";
490 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
491 amrex::Print() <<
"]" << std::endl;
492 amrex::Print() <<
" orig_y_sub_p = [";
493 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
494 amrex::Print() <<
"]" << std::endl;
497 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
498 }
else if ((kl-order/2 >= 0) && (kr+order/2-1 <= orig_npts-1)) {
499 int ksta = kl-order/2;
500 int kend = ksta+order;
501 #ifndef AMREX_USE_GPU
502 int ksize = kend-ksta;
503 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;
506 amrex::GpuArray<amrex::Real,10> orig_x_sub;
507 amrex::GpuArray<amrex::Real,10> orig_y_sub;
511 new_x = new_x_p[new_k];
512 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
514 new_x = new_x_z[new_k];
515 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
517 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
518 #ifndef AMREX_USE_GPU
520 amrex::Print() <<
" orig_x_sub_p = [";
521 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
522 amrex::Print() <<
"]" << std::endl;
523 amrex::Print() <<
" orig_y_sub_p = [";
524 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
525 amrex::Print() <<
"]" << std::endl;
528 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
533 #ifndef AMREX_USE_GPU
534 int ksize = kend-ksta+1;
535 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;
538 amrex::GpuArray<amrex::Real,2> orig_x_sub;
539 amrex::GpuArray<amrex::Real,2> orig_y_sub;
543 new_x = new_x_p[new_k];
544 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
546 new_x = new_x_z[new_k];
547 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
549 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
550 #ifndef AMREX_USE_GPU
552 amrex::Print() <<
" orig_x_sub_p = [";
553 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
554 amrex::Print() <<
"]" << std::endl;
555 amrex::Print() <<
" orig_y_sub_p = [";
556 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
557 amrex::Print() <<
"]" << std::endl;
563 #ifndef AMREX_USE_GPU
564 if (debug) amrex::Print() <<
" new_y[" << new_k <<
"]=" << new_y[new_k] << std::endl;
588 const bool& metgrid_use_sfc,
589 const bool& exp_interp,
590 const bool& metgrid_retain_sfc,
592 const int& metgrid_order,
593 const int& metgrid_force_sfc_k,
601 const amrex::Array4<amrex::Real const>& orig_z_full,
602 const amrex::Array4<amrex::Real const>& orig_data,
603 const amrex::Array4<amrex::Real const>& new_z_full,
604 const amrex::Array4<amrex::Real>& new_data_full)
610 int imin_orig = amrex::lbound(amrex::Box(orig_data)).x;
611 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
612 int jmin_orig = amrex::lbound(amrex::Box(orig_data)).y;
613 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
614 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
615 int kmax_new = kmax + 1;
617 AMREX_ASSERT(kmax_orig < 256);
618 AMREX_ASSERT(kmax_new < 256);
620 amrex::GpuArray<amrex::Real,256> new_z;
621 amrex::GpuArray<amrex::Real,256> new_p;
622 amrex::GpuArray<amrex::Real,256> new_data;
626 for (
int k=0; k < kmax_new; k++) {
628 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));
629 }
else if (stag ==
'Y') {
630 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));
631 }
else if (stag ==
'M') {
632 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 )+
633 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));
638 amrex::GpuArray<amrex::Real,256> orig_z;
640 for (
int k=0; k < kmax_orig; k++) {
642 orig_z_p[k] = orig_z_full(i,j,k);
643 }
else if (stag ==
'X') {
644 if (i <= imin_orig) {
645 orig_z_p[k] = orig_z_full(i,j,k);
646 }
else if (i >= imax_orig) {
647 orig_z_p[k] = orig_z_full(imax_orig-1,j,k);
649 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i-1,j,k));
651 }
else if (stag ==
'Y') {
652 if (j <= jmin_orig) {
653 orig_z_p[k] = orig_z_full(i,j,k);
654 }
else if (j >= jmax_orig) {
655 orig_z_p[k] = orig_z_full(i,jmax_orig-1,k);
657 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i,j-1,k));
663 bool flip_data_required =
false;
664 if (orig_z[1] > orig_z[kmax_orig-1]) flip_data_required =
true;
665 if (flip_data_required) amrex::Abort(
"metgrid initialization flip_data_required. Not yet implemented.");
671 for (
int k=1; k < kmax_orig; k++) {
672 if (orig_z_p[k] > orig_z_p[0]) {
679 amrex::GpuArray<amrex::Real,256> ordered_z;
680 amrex::GpuArray<amrex::Real,256> ordered_data;
683 if (k_above_sfc > 1) {
689 for (
int k=1; k < k_above_sfc; k++) {
690 ordered_z_p[count] = orig_z_p[k];
691 ordered_data_p[count] = orig_data(i,j,k,src_comp);
705 if (Pl-Pu < metgrid_proximity) {
710 ordered_z_p[count] = orig_z_p[0];
711 ordered_data_p[count] = orig_data(i,j,0,src_comp);
716 int knext = k_above_sfc;
722 if (metgrid_force_sfc_k > 0) {
723 for (
int k=k_above_sfc; k < kmax_orig; k++) {
724 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k-1]) {
735 if (Pl-Pu < metgrid_proximity) {
740 for (
int k=knext; k < kmax_orig; k++) {
741 ordered_z_p[count] = orig_z_p[k];
742 ordered_data_p[count] = orig_data(i,j,k,src_comp);
751 ordered_z_p[0] = orig_z[0];
752 ordered_data_p[0] = orig_data(i,j,0,src_comp);
758 if (metgrid_force_sfc_k > 0) {
759 for (
int k=knext; k < kmax_orig; k++) {
760 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k]) {
769 for (
int k=knext; k < kmax_orig; k++) {
773 if (Pl-Pu < metgrid_proximity) {
776 ordered_z_p[count] = orig_z_p[k];
777 ordered_data_p[count] = orig_data(i,j,k,src_comp);
783 int ksta(0), kend(0);
784 if (metgrid_use_below_sfc && metgrid_use_sfc) {
788 }
else if (metgrid_use_below_sfc && !metgrid_use_sfc) {
791 for (
int k=0; k < kmax_orig; k++) {
792 if (ordered_z_p[k] == orig_z_p[0]) {
797 for (
int k=ksfc; k < kmax_orig-1; k++) {
798 ordered_z_p[k] = ordered_z_p[k+1];
799 ordered_data_p[k] = ordered_data_p[k+1];
803 }
else if (!metgrid_use_below_sfc && metgrid_use_sfc) {
806 for (
int k=0; k < kend_order; k++) {
807 if (ordered_z_p[k] == orig_z_p[0]) {
816 amrex::Abort(
"metgrid initialization, !use_levels below_ground && !metgrid_use_sfc");
832 amrex::GpuArray<amrex::Real,256> ordered_p;
834 for (
int k=0; k < kend_order; k++) {
841 amrex::GpuArray<amrex::Real,256> final_z;
842 amrex::GpuArray<amrex::Real,256> final_p;
843 amrex::GpuArray<amrex::Real,256> final_data;
847 final_z_p[0] = ordered_z[ksta];
848 final_p_p[0] = ordered_p[ksta];
849 final_data_p[0] = ordered_data[ksta];
850 for (
int k=ksta+1; k <= kend; k++) {
852 if ((final_p_p[kfinal]-ordered_p_p[k]) < metgrid_proximity)
continue;
854 final_z_p[kfinal] = ordered_z_p[k];
855 final_p_p[kfinal] = ordered_p_p[k];
856 final_data_p[kfinal] = ordered_data_p[k];
876 if (metgrid_retain_sfc) new_data[0] = ordered_data[0];
879 for (
int k=0; k < kmax_new; k++) {
880 new_data_full(i,j,k,dst_comp) = new_data[k];
896 const amrex::Array4<amrex::Real const>& orig_z,
897 const amrex::Array4<amrex::Real const>& orig_data,
898 const amrex::Array4<amrex::Real const>& new_z)
901 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
902 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
903 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
907 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));
909 else if (stag ==
'Y') {
910 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));
912 else if (stag ==
'M') {
913 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 )+
914 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));
919 amrex::Real z0 = std::numeric_limits<amrex::Real>::quiet_NaN();
920 amrex::Real z1 = std::numeric_limits<amrex::Real>::quiet_NaN();
925 for (
int kk = 0; kk < kmax_orig; kk++) {
928 orig_z_stag = orig_z(i,j,kk);
932 orig_z_stag = orig_z(i,j,kk);
934 else if (i == imax_orig) {
935 orig_z_stag = orig_z(imax_orig-1,j,kk);
938 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
941 else if (stag ==
'Y') {
943 orig_z_stag = orig_z(i,j,kk);
945 else if (j == jmax_orig) {
946 orig_z_stag = orig_z(i,jmax_orig-1,kk);
949 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
974 for (
int kk = 0; kk < kmax_orig; kk++) {
977 orig_z_stag = orig_z(i,j,kk);
979 else if (stag ==
'X') {
981 orig_z_stag = orig_z(i,j,kk);
983 else if (i == imax_orig) {
984 orig_z_stag = orig_z(imax_orig-1,j,kk);
987 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
990 else if (stag ==
'Y') {
992 orig_z_stag = orig_z(i,j,kk);
994 else if (j == jmax_orig) {
995 orig_z_stag = orig_z(i,jmax_orig-1,kk);
998 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
1002 if ((
dz <
zero) && (
dz > dzhi1) && (kk != khi0)) {
1010 return ( y0-(y1-y0)/(z1-
z0)*(
z0-
z) );
1013 }
else if (khi0 == -1) {
1021 z0 = orig_z(i,j,khi0);
1023 else if (stag ==
'X') {
1025 z0 = orig_z(i,j,khi0);
1027 else if (i == imax_orig) {
1028 z0 = orig_z(imax_orig-1,j,khi0);
1031 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i-1,j,khi0));
1034 else if (stag ==
'Y') {
1036 z0 = orig_z(i,j,khi0);
1038 else if (j == jmax_orig) {
1039 z0 = orig_z(i,jmax_orig-1,khi0);
1042 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i,j-1,khi0));
1047 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
1052 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
1066 const amrex::Array4<amrex::Real const>& rhum,
1067 const amrex::Array4<amrex::Real const>& temp,
1068 const amrex::Array4<amrex::Real const>&
pres,
1070 const amrex::Array4<amrex::Real>& mxrat)
1084 if (temp(i,j,k) !=
zero) {
1088 mxrat(i,j,k,src_indx) = amrex::Math::powi<-6>(
amrex::Real(10.0));
1105 if (
pres(i,j,k) < qv_max_p_safe) {
1106 if (mxrat(i,j,k,src_indx) > qv_max_flag) {
1107 mxrat(i,j,k,src_indx) = qv_max_value;
1110 if (
pres(i,j,k) < qv_min_p_safe) {
1111 if (mxrat(i,j,k,src_indx) < qv_min_flag) {
1112 mxrat(i,j,k,src_indx) = qv_min_value;
constexpr amrex::Real p_0
Definition: ERF_Constants.H:53
constexpr amrex::Real CONST_GRAV
Definition: ERF_Constants.H:56
constexpr amrex::Real R_d
Definition: ERF_Constants.H:34
constexpr amrex::Real RdoCp
Definition: ERF_Constants.H:41
constexpr amrex::Real RdoRv
Definition: ERF_Constants.H:44
Real z0
Definition: ERF_InitCustomPertVels_ScalarAdvDiff.H:8
const bool use_moisture
Definition: ERF_InitCustomPert_ABL.H:71
const Real rdOcp
Definition: ERF_InitCustomPert_ABL.H:72
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)
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:231
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:891
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:587
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_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool metgrid_surface_pressure(const bool debug_psfc, const int flag_psfc, const amrex::Real file_psfc, const amrex::Real z_sfc, const amrex::Real P00, const amrex::Real T00, const amrex::Real TLP, amrex::Real &pressure)
Definition: ERF_MetgridUtils.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool metgrid_surface_theta(const amrex::Real temperature, const bool debug_psfc, const int flag_psfc, const amrex::Real file_psfc, const amrex::Real z_sfc, const amrex::Real P00, const amrex::Real T00, const amrex::Real TLP, const amrex::Real rdOcp, amrex::Real &theta)
Definition: ERF_MetgridUtils.H:79
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void calc_p_isothermal(const amrex::Real &z, amrex::Real &p)
Definition: ERF_MetgridUtils.H:575
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:268
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, int *base_state_column_failed, const BaseStateParams &bsp)
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:1063
constexpr amrex::Real one
Definition: ERF_NumericalConstants.H:30
constexpr amrex::Real fourth
Definition: ERF_NumericalConstants.H:35
constexpr amrex::Real zero
Definition: ERF_NumericalConstants.H:29
constexpr amrex::Real myhalf
Definition: ERF_NumericalConstants.H:34
amrex::Real Real
Definition: ERF_ShocInterface.H:19
@ theta
Definition: ERF_SLM.H:19
@ pres
Definition: ERF_Kessler.H:28
@ dz
Definition: ERF_AdvanceWDM6.cpp:272
@ p
Definition: ERF_WSM6.H:280
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE bool temperature_to_theta(const amrex::Real temperature, const amrex::Real pressure, const amrex::Real rdOcp, amrex::Real &theta)
Definition: ERF_SurfaceTemperature.H:73
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