diff --git a/Source/Initialization/ERF_Metgrid_utils.H b/Source/Initialization/ERF_Metgrid_utils.H index 452e4f567..ecb3808a8 100644 --- a/Source/Initialization/ERF_Metgrid_utils.H +++ b/Source/Initialization/ERF_Metgrid_utils.H @@ -101,90 +101,6 @@ init_base_state_from_metgrid (const bool use_moisture, amrex::Vector>& fabs_for_bcs, const amrex::Array4& mask_c_arr); -AMREX_FORCE_INLINE -AMREX_GPU_DEVICE -void -calc_rho_p (const int& kmax, - const int& flag_psfc, - const amrex::Real& psfc, - amrex::Real* Thetad_vec, - amrex::Real* Thetam_vec, - amrex::Real* Q_vec, - amrex::Real* z_vec, - amrex::Real* Rhod_vec, - amrex::Real* Rhom_vec, - amrex::Real* Pd_vec, - amrex::Real* Pm_vec) -{ - const int maxiter = 10; - const amrex::Real tol = 1.0e-12; - - // Calculate or use moist pressure at the surface. - amrex::Real Psurf; - if (flag_psfc == 1) { - Psurf = psfc; - } else { - amrex::Real t_0 = 290.0; // WRF's model_config_rec%base_temp - amrex::Real a = 50.0; // WRF's model_config_rec%base_lapse - Psurf = p_0*exp(-t_0/a+std::pow((std::pow(t_0/a, 2)-2.0*CONST_GRAV*z_vec[0]/(a*R_d)), 0.5)); - } - - // Iterations for the first CC point that is 1/2 dz off the surface - { - amrex::Real half_dz = z_vec[0]; - amrex::Real qvf = 1.0+(R_v/R_d)*Q_vec[0]; - Thetam_vec[0] = Thetad_vec[0]*qvf; - for (int it=0; ittol) HSEutils::Newton_Raphson_hse(tol, R_d/Cp_d, dz, - CONST_GRAV, C, Thetad_vec[k], - Q_vec[k], Q_vec[k], - Pm_vec[k], Rhom_vec[k], F); - } // k - - // integrate from the top back down to get dry pressure and density. - Pd_vec[kmax] = Pm_vec[kmax]; - Rhod_vec[kmax] = (p_0/(R_d*Thetam_vec[kmax]))*std::pow(Pd_vec[kmax]/p_0, iGamma); - for (int k=kmax-1; k>=0; k--) { - amrex::Real dz = z_vec[k+1]-z_vec[k]; - Rhod_vec[k] = Rhod_vec[k+1]; // an initial guess. - for (int it=0; ittol) HSEutils::Newton_Raphson_hse(tol, R_d/Cp_d, dz, + CONST_GRAV, C, Thetad_vec[k], + Q_vec[k], Q_vec[k], + Pm_vec[k], Rhom_vec[k], F); + } // k + + // integrate from the top back down to get dry pressure and density. + Pd_vec[kmax] = Pm_vec[kmax]; + Rhod_vec[kmax] = (p_0/(R_d*Thetam_vec[kmax]))*std::pow(Pd_vec[kmax]/p_0, iGamma); + for (int k=kmax-1; k>=0; k--) { + amrex::Real dz = z_vec[k+1]-z_vec[k]; + Rhod_vec[k] = Rhod_vec[k+1]; // an initial guess. + for (int iter=0; iter{}; auto p_hse_arr = p_hse_bcs_fab.array(); + const int maxiter = 10; + const amrex::Real tol = 1.0e-12; ParallelFor(valid_bx2d, [=] AMREX_GPU_DEVICE (int i, int j, int) noexcept { for (int k=0; k<=kmax; k++) { @@ -975,9 +1040,70 @@ init_base_state_from_metgrid (const bool use_moisture, } z_vec[kmax+1] = new_z(i,j,kmax+1); - calc_rho_p(kmax, flag_psfc_vec[it], orig_psfc(i,j,0), - Thetad_vec, Thetam_vec, Q_vec, z_vec, - Rhod_vec, Rhom_vec, Pd_vec, Pm_vec); + // Get Psurf + amrex::Real Psurf; + if (flag_psfc_vec[it] == 1) { + Psurf = orig_psfc(i,j,0); + } else { + amrex::Real t_0 = 290.0; // WRF's model_config_rec%base_temp + amrex::Real a = 50.0; // WRF's model_config_rec%base_lapse + Psurf = p_0*exp(-t_0/a+std::pow((std::pow(t_0/a, 2)-2.0*CONST_GRAV*z_vec[0]/(a*R_d)), 0.5)); + } + + // Iterations for the first CC point that is 1/2 dz off the surface + { + amrex::Real half_dz = z_vec[0]; + amrex::Real qvf = 1.0+(R_v/R_d)*Q_vec[0]; + Thetam_vec[0] = Thetad_vec[0]*qvf; + for (int iter=0; itertol) HSEutils::Newton_Raphson_hse(tol, R_d/Cp_d, dz, + CONST_GRAV, C, Thetad_vec[k], + Q_vec[k], Q_vec[k], + Pm_vec[k], Rhom_vec[k], F); + } // k + + // integrate from the top back down to get dry pressure and density. + Pd_vec[kmax] = Pm_vec[kmax]; + Rhod_vec[kmax] = (p_0/(R_d*Thetam_vec[kmax]))*std::pow(Pd_vec[kmax]/p_0, iGamma); + for (int k=kmax-1; k>=0; k--) { + amrex::Real dz = z_vec[k+1]-z_vec[k]; + Rhod_vec[k] = Rhod_vec[k+1]; // an initial guess. + for (int iter=0; iter