457 int imax_orig = amrex::ubound(amrex::Box(orig_data)).x;
458 int jmax_orig = amrex::ubound(amrex::Box(orig_data)).y;
459 int kmax_orig = amrex::ubound(amrex::Box(orig_data)).z;
460 int kmax_new = amrex::ubound(amrex::Box(new_z_full)).z;
462 AMREX_ASSERT(kmax_orig < 256);
463 AMREX_ASSERT(kmax_new < 256);
465 amrex::GpuArray<amrex::Real,256> new_z;
466 amrex::GpuArray<amrex::Real,256> new_p;
467 amrex::GpuArray<amrex::Real,256> new_data;
468 amrex::Real* new_z_p = new_z.data();
469 amrex::Real* new_p_p = new_p.data();
470 amrex::Real* new_data_p = new_data.data();
471 for (
int k=0; k < kmax_new; k++) {
473 new_z_p[k] = 0.25*(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));
474 }
else if (stag ==
'Y') {
475 new_z_p[k] = 0.25*(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));
476 }
else if (stag ==
'M') {
477 new_z_p[k] = 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 )+
478 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));
483 amrex::GpuArray<amrex::Real,256> orig_z;
484 amrex::Real* orig_z_p = orig_z.data();
485 for (
int k=0; k < kmax_orig; k++) {
487 orig_z_p[k] = orig_z_full(i,j,k);
488 }
else if (stag ==
'X') {
490 orig_z_p[k] = orig_z_full(i,j,k);
491 }
else if (i == imax_orig) {
492 orig_z_p[k] = orig_z_full(imax_orig-1,j,k);
494 orig_z_p[k] = 0.5*(orig_z_full(i,j,k)+orig_z_full(i-1,j,k));
496 }
else if (stag ==
'Y') {
498 orig_z_p[k] = orig_z_full(i,j,k);
499 }
else if (j == jmax_orig) {
500 orig_z_p[k] = orig_z_full(i,jmax_orig-1,k);
502 orig_z_p[k] = 0.5*(orig_z_full(i,j,k)+orig_z_full(i,j-1,k));
508 bool flip_data_required =
false;
509 if (orig_z[1] > orig_z[kmax_orig-1]) flip_data_required =
true;
510 if (flip_data_required) amrex::Abort(
"metgrid initialization flip_data_required. Not yet implemented.");
516 for (
int k=1; k < kmax_orig; k++) {
517 if (orig_z_p[k] > orig_z_p[0]) {
527 amrex::ignore_unused(zap,zap_above);
528 amrex::GpuArray<amrex::Real,256> ordered_z;
529 amrex::GpuArray<amrex::Real,256> ordered_data;
530 amrex::Real* ordered_z_p = ordered_z.data();
531 amrex::Real* ordered_data_p = ordered_data.data();
532 if (k_above_sfc > 1) {
538 for (
int k=1; k < k_above_sfc; k++) {
539 ordered_z_p[count] = orig_z_p[k];
540 ordered_data_p[count] = orig_data(i,j,k);
554 if (Pl-Pu < metgrid_proximity) {
561 ordered_z_p[count] = orig_z_p[0];
562 ordered_data_p[count] = orig_data(i,j,0);
567 int knext = k_above_sfc;
573 if (metgrid_force_sfc_k > 0) {
574 for (
int k=k_above_sfc; k < kmax_orig; k++) {
575 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k-1]) {
589 if (Pl-Pu < metgrid_proximity) {
596 for (
int k=knext; k < kmax_orig; k++) {
597 ordered_z_p[count] = orig_z_p[k];
598 ordered_data_p[count] = orig_data(i,j,k);
607 ordered_z_p[0] = orig_z[0];
608 ordered_data_p[0] = orig_data(i,j,0);
614 if (metgrid_force_sfc_k > 0) {
615 for (
int k=knext; k < kmax_orig; k++) {
616 if (orig_z_p[k] > new_z_p[metgrid_force_sfc_k]) {
628 for (
int k=knext; k < kmax_orig; k++) {
632 if (Pl-Pu < metgrid_proximity) {
637 ordered_z_p[count] = orig_z_p[k];
638 ordered_data_p[count] = orig_data(i,j,k);
644 int ksta(0), kend(0);
645 if (metgrid_use_below_sfc && metgrid_use_sfc) {
648 kend = ksta+kend_order-1;
649 }
else if (metgrid_use_below_sfc && !metgrid_use_sfc) {
652 for (
int k=0; k < kmax_orig; k++) {
653 if (ordered_z_p[k] == orig_z_p[0]) {
658 for (
int k=ksfc; k < kmax_orig-1; k++) {
659 ordered_z_p[k] = ordered_z_p[k+1];
660 ordered_data_p[k] = ordered_data_p[k+1];
663 kend = ksta+kend_order-2;
664 }
else if (!metgrid_use_below_sfc && metgrid_use_sfc) {
666 int kcount = k_above_sfc-1-zap_below;
668 for (
int k=0; k < kmax_orig; k++) {
669 if (ordered_z_p[kcount] == orig_z_p[k]) {
674 ksta = k_above_sfc-1-zap_below;
678 amrex::Abort(
"metgrid initialization, !use_levels below_ground && !metgrid_use_sfc");
694 amrex::GpuArray<amrex::Real,256> ordered_p;
695 amrex::Real* ordered_p_p = ordered_p.data();
696 for (
int k=0; k < kend_order; k++) {
702 amrex::GpuArray<amrex::Real,256> final_z;
703 amrex::GpuArray<amrex::Real,256> final_p;
704 amrex::GpuArray<amrex::Real,256> final_data;
705 amrex::Real* final_z_p = final_z.data();
706 amrex::Real* final_p_p = final_p.data();
707 amrex::Real* final_data_p = final_data.data();
708 final_z_p[0] = ordered_z[ksta];
709 final_p_p[0] = ordered_p[ksta];
710 final_data_p[0] = ordered_data[ksta];
711 for (
int k=ksta+1; k <= kend; k++) {
712 if ((final_p_p[new_n]-ordered_p_p[k]) < metgrid_proximity) {
716 final_z_p[new_n] = ordered_z_p[k];
717 final_p_p[new_n] = ordered_p_p[k];
718 final_data_p[new_n] = ordered_data_p[k];
738 if (metgrid_retain_sfc) new_data[0] = ordered_data[0];
741 for (
int k=0; k < kmax_new; k++) {
742 if (mask(i,j,k) && update_bc_data && bx_xlo.contains(i,j,k)) bc_data_xlo(i,j,k,0) = new_data[k];
743 if (mask(i,j,k) && update_bc_data && bx_xhi.contains(i,j,k)) bc_data_xhi(i,j,k,0) = new_data[k];
744 if (mask(i,j,k) && update_bc_data && bx_ylo.contains(i,j,k)) bc_data_ylo(i,j,k,0) = new_data[k];
745 if (mask(i,j,k) && update_bc_data && bx_yhi.contains(i,j,k)) bc_data_yhi(i,j,k,0) = new_data[k];
746 if (itime == 0) new_data_full(i,j,k,src_comp) = new_data[k];
AMREX_FORCE_INLINE AMREX_GPU_DEVICE void calc_p_isothermal(const amrex::Real &z, amrex::Real &p)
Definition: ERF_MetgridUtils.H:416
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, 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