4 #ifndef ERF_METGRIDUTIL_H_
5 #define ERF_METGRIDUTIL_H_
21 const amrex::Box& domain,
22 const std::string& fname,
23 std::string& NC_dateTime,
34 amrex::FArrayBox& NC_xvel_fab,
35 amrex::FArrayBox& NC_yvel_fab,
36 amrex::FArrayBox& NC_temp_fab,
37 amrex::FArrayBox& NC_rhum_fab,
38 amrex::FArrayBox& NC_pres_fab,
39 amrex::FArrayBox& NC_ght_fab,
40 amrex::FArrayBox& NC_hgt_fab,
41 amrex::FArrayBox& NC_psfc_fab,
42 amrex::FArrayBox& NC_msfu_fab,
43 amrex::FArrayBox& NC_msfv_fab,
44 amrex::FArrayBox& NC_msfm_fab,
45 amrex::FArrayBox& NC_sst_fab,
46 amrex::FArrayBox& NC_tsk_fab,
47 amrex::FArrayBox& NC_LAT_fab,
48 amrex::FArrayBox& NC_LON_fab,
49 amrex::IArrayBox& NC_lmask_iab,
50 amrex::Geometry& geom);
57 amrex::FArrayBox& NC_hgt_fab);
66 const bool interp_theta,
67 const bool metgrid_debug_quiescent,
68 const bool metgrid_debug_isothermal,
69 const bool metgrid_debug_dry,
70 const bool metgrid_basic_linear,
71 const bool metgrid_use_below_sfc,
72 const bool metgrid_use_sfc,
73 const bool metgrid_retain_sfc,
75 const int metgrid_order,
76 const int metgrid_metgrid_force_sfc_k,
82 amrex::FArrayBox& state_fab,
83 amrex::FArrayBox& x_vel_fab,
84 amrex::FArrayBox& y_vel_fab,
85 amrex::FArrayBox& z_vel_fab,
86 amrex::FArrayBox& z_phys_nd_fab,
87 const amrex::FArrayBox& NC_ght_fab,
88 const amrex::FArrayBox& NC_xvel_fab,
89 const amrex::FArrayBox& NC_yvel_fab,
90 const amrex::FArrayBox& NC_temp_fab,
91 const amrex::FArrayBox& NC_rhum_fab,
92 const amrex::FArrayBox& NC_pres_fab,
93 amrex::FArrayBox& tmp_src_fab,
94 amrex::FArrayBox& tmp_dst_fab,
95 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xlo,
96 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_xhi,
97 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_ylo,
98 amrex::Vector<amrex::Vector<amrex::FArrayBox>>& fabs_for_bcs_yhi,
99 const amrex::Array4<const int>& mask_c_arr,
100 const amrex::Array4<const int>& mask_u_arr,
101 const amrex::Array4<const int>& mask_v_arr);
108 amrex::FArrayBox& msfu_fab,
109 amrex::FArrayBox& msfv_fab,
110 amrex::FArrayBox& msfm_fab,
112 amrex::FArrayBox& NC_MSFU_fab,
113 amrex::FArrayBox& NC_MSFV_fab,
114 amrex::FArrayBox& NC_MSFM_fab);
121 const bool metgrid_debug_psfc,
123 const amrex::Box& valid_bx,
124 const int& flag_psfc,
125 amrex::FArrayBox& state_fab,
126 amrex::FArrayBox& r_hse_fab,
127 amrex::FArrayBox& p_hse_fab,
128 amrex::FArrayBox& pi_hse_fab,
129 amrex::FArrayBox& th_hse_fab,
130 amrex::FArrayBox& qv_hse_fab,
131 amrex::FArrayBox& z_phys_nd_fab,
132 amrex::FArrayBox& z_phys_cc_fab,
133 const amrex::FArrayBox& NC_psfc_fab);
153 for (
int i=0; i <= order; i++) {
156 for (
int k=0; k <= order; k++) {
157 if (k == i)
continue;
179 const bool& exp_interp,
180 const int& orig_npts,
197 amrex::ignore_unused(i,j);
198 #ifndef AMREX_USE_GPU
202 for (
int new_k=0; new_k < new_npts; new_k++) {
203 #ifndef AMREX_USE_GPU
204 if (debug) amrex::Print() <<
"new_k=" << new_k;
208 bool extrapolating =
true;
210 for (
int ko=0; ko < orig_npts-1; ko++) {
216 extrapolating =
false;
222 if (var_type ==
'T') {
225 amrex::Real depth_of_extrap_in_p = new_x_p[new_k]-orig_x_p[0];
231 new_y[new_k] = (temp_extrap_starting_point+dT)*std::pow(
amrex::Real(100000.0)/new_x_p[new_k],
RdoCp);
235 new_y[new_k] = orig_y[0];
241 if ((kl-((order+1)/2-1) >= 0) && (kr+((order+1)/2-1) <= orig_npts-1)) {
243 int ksta = kl-(((order+1)/2)-1);
244 int kend = ksta+order;
245 #ifndef AMREX_USE_GPU
246 int ksize = kend-ksta;
247 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;
250 amrex::GpuArray<amrex::Real,9> orig_x_sub;
253 new_x = new_x_p[new_k];
254 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
256 new_x = new_x_z[new_k];
257 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
259 amrex::GpuArray<amrex::Real,9> orig_y_sub;
261 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
262 #ifndef AMREX_USE_GPU
264 amrex::Print() <<
" orig_x_sub_p = [";
265 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
266 amrex::Print() <<
"]" << std::endl;
267 amrex::Print() <<
" orig_y_sub_p = [";
268 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
269 amrex::Print() <<
"]" << std::endl;
272 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
278 #ifndef AMREX_USE_GPU
279 int ksize = kend-ksta+1;
280 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;
283 amrex::GpuArray<amrex::Real,2> orig_x_sub;
284 amrex::GpuArray<amrex::Real,2> orig_y_sub;
288 new_x = new_x_p[new_k];
289 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
291 new_x = new_x_z[new_k];
292 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
294 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
295 #ifndef AMREX_USE_GPU
297 amrex::Print() <<
" orig_x_sub_p = [";
298 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
299 amrex::Print() <<
"]" << std::endl;
300 amrex::Print() <<
" orig_y_sub_p = [";
301 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
302 amrex::Print() <<
"]" << std::endl;
307 }
else if (order%2 == 0) {
308 if ((kl-(order/2) >= 0) && (kr+order/2 <= orig_npts-1)) {
313 int ksta = kl-(order/2-1);
314 int kend = ksta+order;
315 #ifndef AMREX_USE_GPU
316 int ksize = kend-ksta;
317 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;
320 amrex::GpuArray<amrex::Real,10> orig_x_sub;
321 amrex::GpuArray<amrex::Real,10> orig_y_sub;
325 new_x = new_x_p[new_k];
326 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
328 new_x = new_x_z[new_k];
329 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
331 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
332 #ifndef AMREX_USE_GPU
334 amrex::Print() <<
" orig_x_sub_p = [";
335 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
336 amrex::Print() <<
"]" << std::endl;
337 amrex::Print() <<
" orig_y_sub_p = [";
338 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
339 amrex::Print() <<
"]" << std::endl;
345 int ksta = kl-order/2;
346 int kend = ksta+order;
347 #ifndef AMREX_USE_GPU
348 int ksize = kend-ksta;
349 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;
352 amrex::GpuArray<amrex::Real,10> orig_x_sub;
353 amrex::GpuArray<amrex::Real,10> orig_y_sub;
357 new_x = new_x_p[new_k];
358 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
360 new_x = new_x_z[new_k];
361 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
363 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
364 #ifndef AMREX_USE_GPU
366 amrex::Print() <<
" orig_x_sub_p = [";
367 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
368 amrex::Print() <<
"]" << std::endl;
369 amrex::Print() <<
" orig_y_sub_p = [";
370 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
371 amrex::Print() <<
"]" << std::endl;
376 new_y[new_k] =
myhalf*(new_y_l+new_y_r);
377 }
else if ((kl-(order/2-1) >= 0) && (kr+order/2 <= orig_npts-1)) {
378 int ksta = kl-(order/2-1);
379 int kend = ksta+order;
380 #ifndef AMREX_USE_GPU
381 int ksize = kend-ksta;
382 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;
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]);
408 }
else if ((kl-order/2 >= 0) && (kr+order/2-1 <= orig_npts-1)) {
409 int ksta = kl-order/2;
410 int kend = ksta+order;
411 #ifndef AMREX_USE_GPU
412 int ksize = kend-ksta;
413 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;
416 amrex::GpuArray<amrex::Real,10> orig_x_sub;
417 amrex::GpuArray<amrex::Real,10> orig_y_sub;
421 new_x = new_x_p[new_k];
422 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
424 new_x = new_x_z[new_k];
425 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
427 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
428 #ifndef AMREX_USE_GPU
430 amrex::Print() <<
" orig_x_sub_p = [";
431 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
432 amrex::Print() <<
"]" << std::endl;
433 amrex::Print() <<
" orig_y_sub_p = [";
434 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
435 amrex::Print() <<
"]" << std::endl;
438 lagrange_interp(order, orig_x_sub_p, orig_y_sub_p, new_x, new_y[new_k]);
443 #ifndef AMREX_USE_GPU
444 int ksize = kend-ksta+1;
445 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;
448 amrex::GpuArray<amrex::Real,2> orig_x_sub;
449 amrex::GpuArray<amrex::Real,2> orig_y_sub;
453 new_x = new_x_p[new_k];
454 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_p[k]; }
456 new_x = new_x_z[new_k];
457 for (
int k=ksta; k <= kend; k++) { orig_x_sub_p[k-ksta] = orig_x_z[k]; }
459 for (
int k=ksta; k <= kend; k++) { orig_y_sub_p[k-ksta] = orig_y[k]; }
460 #ifndef AMREX_USE_GPU
462 amrex::Print() <<
" orig_x_sub_p = [";
463 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_x_sub_p[k];
464 amrex::Print() <<
"]" << std::endl;
465 amrex::Print() <<
" orig_y_sub_p = [";
466 for (
int k=0; k < ksize; k++) amrex::Print() <<
" " << orig_y_sub_p[k];
467 amrex::Print() <<
"]" << std::endl;
473 #ifndef AMREX_USE_GPU
474 if (debug) amrex::Print() <<
" new_y[" << new_k <<
"]=" << new_y[new_k] << std::endl;
498 const bool& metgrid_use_sfc,
499 const bool& exp_interp,
500 const bool& metgrid_retain_sfc,
502 const int& metgrid_order,
503 const int& metgrid_force_sfc_k,
511 const amrex::Array4<amrex::Real const>& orig_z_full,
512 const amrex::Array4<amrex::Real const>& orig_data,
513 const amrex::Array4<amrex::Real const>& new_z_full,
514 const amrex::Array4<amrex::Real>& new_data_full)
520 int imin_orig = amrex::lbound(amrex::Box(orig_data)).x;
521 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
522 int jmin_orig = amrex::lbound(amrex::Box(orig_data)).y;
523 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
524 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
525 int kmax_new = kmax + 1;
527 AMREX_ASSERT(kmax_orig < 256);
528 AMREX_ASSERT(kmax_new < 256);
530 amrex::GpuArray<amrex::Real,256> new_z;
531 amrex::GpuArray<amrex::Real,256> new_p;
532 amrex::GpuArray<amrex::Real,256> new_data;
536 for (
int k=0; k < kmax_new; k++) {
538 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));
539 }
else if (stag ==
'Y') {
540 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));
541 }
else if (stag ==
'M') {
542 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 )+
543 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));
548 amrex::GpuArray<amrex::Real,256> orig_z;
550 for (
int k=0; k < kmax_orig; k++) {
552 orig_z_p[k] = orig_z_full(i,j,k);
553 }
else if (stag ==
'X') {
554 if (i <= imin_orig) {
555 orig_z_p[k] = orig_z_full(i,j,k);
556 }
else if (i >= imax_orig) {
557 orig_z_p[k] = orig_z_full(imax_orig-1,j,k);
559 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i-1,j,k));
561 }
else if (stag ==
'Y') {
562 if (j <= jmin_orig) {
563 orig_z_p[k] = orig_z_full(i,j,k);
564 }
else if (j >= jmax_orig) {
565 orig_z_p[k] = orig_z_full(i,jmax_orig-1,k);
567 orig_z_p[k] =
myhalf*(orig_z_full(i,j,k)+orig_z_full(i,j-1,k));
573 bool flip_data_required =
false;
574 if (orig_z[1] > orig_z[kmax_orig-1]) flip_data_required =
true;
575 if (flip_data_required) amrex::Abort(
"metgrid initialization flip_data_required. Not yet implemented.");
581 for (
int k=1; k < kmax_orig; k++) {
582 if (orig_z_p[k] > orig_z_p[0]) {
589 amrex::GpuArray<amrex::Real,256> ordered_z;
590 amrex::GpuArray<amrex::Real,256> ordered_data;
593 if (k_above_sfc > 1) {
599 for (
int k=1; k < k_above_sfc; k++) {
600 ordered_z_p[count] = orig_z_p[k];
601 ordered_data_p[count] = orig_data(i,j,k,src_comp);
615 if (Pl-Pu < metgrid_proximity) {
620 ordered_z_p[count] = orig_z_p[0];
621 ordered_data_p[count] = orig_data(i,j,0,src_comp);
626 int knext = k_above_sfc;
632 if (metgrid_force_sfc_k > 0) {
633 for (
int k=k_above_sfc; k < kmax_orig; k++) {
634 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k-1]) {
645 if (Pl-Pu < metgrid_proximity) {
650 for (
int k=knext; k < kmax_orig; k++) {
651 ordered_z_p[count] = orig_z_p[k];
652 ordered_data_p[count] = orig_data(i,j,k,src_comp);
661 ordered_z_p[0] = orig_z[0];
662 ordered_data_p[0] = orig_data(i,j,0,src_comp);
668 if (metgrid_force_sfc_k > 0) {
669 for (
int k=knext; k < kmax_orig; k++) {
670 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k]) {
679 for (
int k=knext; k < kmax_orig; k++) {
683 if (Pl-Pu < metgrid_proximity) {
686 ordered_z_p[count] = orig_z_p[k];
687 ordered_data_p[count] = orig_data(i,j,k,src_comp);
693 int ksta(0), kend(0);
694 if (metgrid_use_below_sfc && metgrid_use_sfc) {
698 }
else if (metgrid_use_below_sfc && !metgrid_use_sfc) {
701 for (
int k=0; k < kmax_orig; k++) {
702 if (ordered_z_p[k] == orig_z_p[0]) {
707 for (
int k=ksfc; k < kmax_orig-1; k++) {
708 ordered_z_p[k] = ordered_z_p[k+1];
709 ordered_data_p[k] = ordered_data_p[k+1];
713 }
else if (!metgrid_use_below_sfc && metgrid_use_sfc) {
716 for (
int k=0; k < kend_order; k++) {
717 if (ordered_z_p[k] == orig_z_p[0]) {
726 amrex::Abort(
"metgrid initialization, !use_levels below_ground && !metgrid_use_sfc");
742 amrex::GpuArray<amrex::Real,256> ordered_p;
744 for (
int k=0; k < kend_order; k++) {
751 amrex::GpuArray<amrex::Real,256> final_z;
752 amrex::GpuArray<amrex::Real,256> final_p;
753 amrex::GpuArray<amrex::Real,256> final_data;
757 final_z_p[0] = ordered_z[ksta];
758 final_p_p[0] = ordered_p[ksta];
759 final_data_p[0] = ordered_data[ksta];
760 for (
int k=ksta+1; k <= kend; k++) {
762 if ((final_p_p[kfinal]-ordered_p_p[k]) < metgrid_proximity)
continue;
764 final_z_p[kfinal] = ordered_z_p[k];
765 final_p_p[kfinal] = ordered_p_p[k];
766 final_data_p[kfinal] = ordered_data_p[k];
786 if (metgrid_retain_sfc) new_data[0] = ordered_data[0];
789 for (
int k=0; k < kmax_new; k++) {
790 new_data_full(i,j,k,dst_comp) = new_data[k];
806 const amrex::Array4<amrex::Real const>& orig_z,
807 const amrex::Array4<amrex::Real const>& orig_data,
808 const amrex::Array4<amrex::Real const>& new_z)
811 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
812 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
813 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
817 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));
819 else if (stag ==
'Y') {
820 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));
822 else if (stag ==
'M') {
823 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 )+
824 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));
829 amrex::Real z0 = std::numeric_limits<amrex::Real>::quiet_NaN();
830 amrex::Real z1 = std::numeric_limits<amrex::Real>::quiet_NaN();
835 for (
int kk = 0; kk < kmax_orig; kk++) {
838 orig_z_stag = orig_z(i,j,kk);
842 orig_z_stag = orig_z(i,j,kk);
844 else if (i == imax_orig) {
845 orig_z_stag = orig_z(imax_orig-1,j,kk);
848 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
851 else if (stag ==
'Y') {
853 orig_z_stag = orig_z(i,j,kk);
855 else if (j == jmax_orig) {
856 orig_z_stag = orig_z(i,jmax_orig-1,kk);
859 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
884 for (
int kk = 0; kk < kmax_orig; kk++) {
887 orig_z_stag = orig_z(i,j,kk);
889 else if (stag ==
'X') {
891 orig_z_stag = orig_z(i,j,kk);
893 else if (i == imax_orig) {
894 orig_z_stag = orig_z(imax_orig-1,j,kk);
897 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i-1,j,kk));
900 else if (stag ==
'Y') {
902 orig_z_stag = orig_z(i,j,kk);
904 else if (j == jmax_orig) {
905 orig_z_stag = orig_z(i,jmax_orig-1,kk);
908 orig_z_stag =
myhalf*(orig_z(i,j,kk)+orig_z(i,j-1,kk));
912 if ((
dz <
zero) && (
dz > dzhi1) && (kk != khi0)) {
920 return ( y0-(y1-y0)/(z1-
z0)*(
z0-
z) );
923 }
else if (khi0 == -1) {
931 z0 = orig_z(i,j,khi0);
933 else if (stag ==
'X') {
935 z0 = orig_z(i,j,khi0);
937 else if (i == imax_orig) {
938 z0 = orig_z(imax_orig-1,j,khi0);
941 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i-1,j,khi0));
944 else if (stag ==
'Y') {
946 z0 = orig_z(i,j,khi0);
948 else if (j == jmax_orig) {
949 z0 = orig_z(i,jmax_orig-1,khi0);
952 z0 =
myhalf*(orig_z(i,j,khi0)+orig_z(i,j-1,khi0));
957 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
962 return ( y0+(y1-y0)/(z1-
z0)*(
z-
z0) );
976 const amrex::Array4<amrex::Real const>& rhum,
977 const amrex::Array4<amrex::Real const>& temp,
978 const amrex::Array4<amrex::Real const>&
pres,
980 const amrex::Array4<amrex::Real>& mxrat)
994 if (temp(i,j,k) !=
zero) {
998 mxrat(i,j,k,src_indx) = amrex::Math::powi<-6>(
amrex::Real(10.0));
1015 if (
pres(i,j,k) < qv_max_p_safe) {
1016 if (mxrat(i,j,k,src_indx) > qv_max_flag) {
1017 mxrat(i,j,k,src_indx) = qv_max_value;
1020 if (
pres(i,j,k) < qv_min_p_safe) {
1021 if (mxrat(i,j,k,src_indx) < qv_min_flag) {
1022 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_Bomex.H:14
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:141
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:801
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:497
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:485
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:178
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:973
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:27
@ p
Definition: ERF_WSM6.H:191
@ dz
Definition: ERF_AdvanceWSM6.cpp:104
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