From ce87db3ee442ee30c976386625cc5c20f04f4472 Mon Sep 17 00:00:00 2001 From: MichaelSt98 Date: Wed, 17 Jul 2024 16:28:01 +0300 Subject: [PATCH] single precision HIP (via preprocessor macro(s)) --- src/cloudsc_hip/CMakeLists.txt | 3 + src/cloudsc_hip/cloudsc/cloudsc_c.cpp | 1038 ++++++++-------- src/cloudsc_hip/cloudsc/cloudsc_c.h | 57 +- src/cloudsc_hip/cloudsc/cloudsc_c_hoist.cpp | 1100 ++++++++--------- src/cloudsc_hip/cloudsc/cloudsc_c_hoist.h | 69 +- .../cloudsc/cloudsc_c_k_caching.cpp | 1078 ++++++++-------- src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.h | 57 +- src/cloudsc_hip/cloudsc/cloudsc_driver.cpp | 652 +++++----- src/cloudsc_hip/cloudsc/cloudsc_driver.h | 1 + .../cloudsc/cloudsc_driver_hoist.cpp | 720 +++++------ .../cloudsc/cloudsc_driver_hoist.h | 1 + src/cloudsc_hip/cloudsc/cloudsc_validate.cpp | 137 +- src/cloudsc_hip/cloudsc/cloudsc_validate.h | 9 +- src/cloudsc_hip/cloudsc/dtype.h | 41 + src/cloudsc_hip/cloudsc/load_state.cpp | 457 +++---- src/cloudsc_hip/cloudsc/load_state.h | 37 +- src/cloudsc_hip/cloudsc/yoecldp_c.h | 214 ++-- 17 files changed, 2888 insertions(+), 2783 deletions(-) create mode 100644 src/cloudsc_hip/cloudsc/dtype.h diff --git a/src/cloudsc_hip/CMakeLists.txt b/src/cloudsc_hip/CMakeLists.txt index 20fb57a0..b05d5f94 100644 --- a/src/cloudsc_hip/CMakeLists.txt +++ b/src/cloudsc_hip/CMakeLists.txt @@ -22,6 +22,7 @@ if( HAVE_CLOUDSC_HIP ) TARGET dwarf-cloudsc-hip-lib INSTALL_HEADERS LISTED SOURCES + cloudsc/dtype.h cloudsc/yoecldp_c.h cloudsc/load_state.h cloudsc/load_state.cpp @@ -74,6 +75,7 @@ if( HAVE_CLOUDSC_HIP ) TARGET dwarf-cloudsc-hip-hoist-lib INSTALL_HEADERS LISTED SOURCES + cloudsc/dtype.h cloudsc/yoecldp_c.h cloudsc/load_state.h cloudsc/load_state.cpp @@ -126,6 +128,7 @@ if( HAVE_CLOUDSC_HIP ) TARGET dwarf-cloudsc-hip-k-caching-lib INSTALL_HEADERS LISTED SOURCES + cloudsc/dtype.h cloudsc/yoecldp_c.h cloudsc/load_state.h cloudsc/load_state.cpp diff --git a/src/cloudsc_hip/cloudsc/cloudsc_c.cpp b/src/cloudsc_hip/cloudsc/cloudsc_c.cpp index 1bca62cc..4caf31b0 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_c.cpp +++ b/src/cloudsc_hip/cloudsc/cloudsc_c.cpp @@ -11,34 +11,34 @@ #include "cloudsc_c.h" #include -__global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, - const double * __restrict__ pt, - const double * __restrict__ pq, const double * __restrict__ tendency_tmp_t, - const double * __restrict__ tendency_tmp_q, const double * __restrict__ tendency_tmp_a, - const double * __restrict__ tendency_tmp_cld, double * __restrict__ tendency_loc_t, - double * __restrict__ tendency_loc_q, double * __restrict__ tendency_loc_a, - double * __restrict__ tendency_loc_cld, const double * __restrict__ pvfa, - const double * __restrict__ pvfl, const double * __restrict__ pvfi, const double * __restrict__ pdyna, - const double * __restrict__ pdynl, const double * __restrict__ pdyni, const double * __restrict__ phrsw, - double * __restrict__ phrlw, const double * __restrict__ pvervel, const double * __restrict__ pap, - const double * __restrict__ paph, const double * __restrict__ plsm, - const int * ktype, const double * __restrict__ plu, double * __restrict__ plude, - const double * __restrict__ psnde, const double * __restrict__ pmfu, const double * __restrict__ pmfd, - const double * __restrict__ pa, const double * __restrict__ pclv, const double * __restrict__ psupsat, - const double * __restrict__ plcrit_aer, const double * __restrict__ picrit_aer, - const double * __restrict__ pre_ice, const double * __restrict__ pccn, const double * __restrict__ pnice, - double * __restrict__ pcovptot, double * __restrict__ prainfrac_toprfz, - double * __restrict__ pfsqlf, double * __restrict__ pfsqif, double * __restrict__ pfcqnng, - double * __restrict__ pfcqlng, double * __restrict__ pfsqrf, double * __restrict__ pfsqsf, - double * __restrict__ pfcqrng, double * __restrict__ pfcqsng, - double * __restrict__ pfsqltur, double * __restrict__ pfsqitur, - double * __restrict__ pfplsl, double * __restrict__ pfplsn, double * __restrict__ pfhpsl, - double * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, - double rg, double rd, double rcpd, double retv, double rlvtt, double rlstt, double rlmlt, double rtt, - double rv, double r2es, double r3les, double r3ies, double r4les, double r4ies, double r5les, - double r5ies, double r5alvcp, double r5alscp, double ralvdcp, double ralsdcp, double ralfdcp, - double rtwat, double rtice, double rticecu, double rtwat_rtice_r, double rtwat_rticecu_r, - double rkoop1, double rkoop2) { +__global__ void cloudsc_c(int kidia, int kfdia, int klon, dtype ptsphy, + const dtype * __restrict__ pt, + const dtype * __restrict__ pq, const dtype * __restrict__ tendency_tmp_t, + const dtype * __restrict__ tendency_tmp_q, const dtype * __restrict__ tendency_tmp_a, + const dtype * __restrict__ tendency_tmp_cld, dtype * __restrict__ tendency_loc_t, + dtype * __restrict__ tendency_loc_q, dtype * __restrict__ tendency_loc_a, + dtype * __restrict__ tendency_loc_cld, const dtype * __restrict__ pvfa, + const dtype * __restrict__ pvfl, const dtype * __restrict__ pvfi, const dtype * __restrict__ pdyna, + const dtype * __restrict__ pdynl, const dtype * __restrict__ pdyni, const dtype * __restrict__ phrsw, + dtype * __restrict__ phrlw, const dtype * __restrict__ pvervel, const dtype * __restrict__ pap, + const dtype * __restrict__ paph, const dtype * __restrict__ plsm, + const int * ktype, const dtype * __restrict__ plu, dtype * __restrict__ plude, + const dtype * __restrict__ psnde, const dtype * __restrict__ pmfu, const dtype * __restrict__ pmfd, + const dtype * __restrict__ pa, const dtype * __restrict__ pclv, const dtype * __restrict__ psupsat, + const dtype * __restrict__ plcrit_aer, const dtype * __restrict__ picrit_aer, + const dtype * __restrict__ pre_ice, const dtype * __restrict__ pccn, const dtype * __restrict__ pnice, + dtype * __restrict__ pcovptot, dtype * __restrict__ prainfrac_toprfz, + dtype * __restrict__ pfsqlf, dtype * __restrict__ pfsqif, dtype * __restrict__ pfcqnng, + dtype * __restrict__ pfcqlng, dtype * __restrict__ pfsqrf, dtype * __restrict__ pfsqsf, + dtype * __restrict__ pfcqrng, dtype * __restrict__ pfcqsng, + dtype * __restrict__ pfsqltur, dtype * __restrict__ pfsqitur, + dtype * __restrict__ pfplsl, dtype * __restrict__ pfplsn, dtype * __restrict__ pfhpsl, + dtype * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, + dtype rg, dtype rd, dtype rcpd, dtype retv, dtype rlvtt, dtype rlstt, dtype rlmlt, dtype rtt, + dtype rv, dtype r2es, dtype r3les, dtype r3ies, dtype r4les, dtype r4ies, dtype r5les, + dtype r5ies, dtype r5alvcp, dtype r5alscp, dtype ralvdcp, dtype ralsdcp, dtype ralfdcp, + dtype rtwat, dtype rtice, dtype rticecu, dtype rtwat_rtice_r, dtype rtwat_rticecu_r, + dtype rkoop1, dtype rkoop2) { //------------------------------------------------------------------------------- // Declare input/output arguments @@ -53,105 +53,105 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, const int klev = 137; // Number of levels - double zlcond1, zlcond2, zlevapl, zlevapi, zrainaut, zsnowaut, zliqcld, zicecld; - double zlevap, zleros; + dtype zlcond1, zlcond2, zlevapl, zlevapi, zrainaut, zsnowaut, zliqcld, zicecld; + dtype zlevap, zleros; // condensation and evaporation terms // autoconversion terms - double zfokoop; - double zfoealfa[klev + 1]; - double zicenuclei; // number concentration of ice nuclei - - double zlicld; - double zacond; - double zaeros; - double zlfinalsum; - double zdqs; - double ztold; - double zqold; - double zdtgdp; - double zrdtgdp; - double ztrpaus; - double zcovpclr; - double zpreclr; - double zcovptot; - double zcovpmax; - double zqpretot; - double zdpevap; - double zdtforc; - double zdtdiab; - double ztp1[klev]; - double zldefr; - double zldifdt; - double zdtgdpf; - double zlcust[5]; - double zacust; - double zmf; - - double zrho; - double ztmp1, ztmp2, ztmp3; - double ztmp4, ztmp5, ztmp6, ztmp7; - double zalfawm; + dtype zfokoop; + dtype zfoealfa[klev + 1]; + dtype zicenuclei; // number concentration of ice nuclei + + dtype zlicld; + dtype zacond; + dtype zaeros; + dtype zlfinalsum; + dtype zdqs; + dtype ztold; + dtype zqold; + dtype zdtgdp; + dtype zrdtgdp; + dtype ztrpaus; + dtype zcovpclr; + dtype zpreclr; + dtype zcovptot; + dtype zcovpmax; + dtype zqpretot; + dtype zdpevap; + dtype zdtforc; + dtype zdtdiab; + dtype ztp1[klev]; + dtype zldefr; + dtype zldifdt; + dtype zdtgdpf; + dtype zlcust[5]; + dtype zacust; + dtype zmf; + + dtype zrho; + dtype ztmp1, ztmp2, ztmp3; + dtype ztmp4, ztmp5, ztmp6, ztmp7; + dtype zalfawm; // Accumulators of A,B,and C factors for cloud equations - double zsolab; // -ve implicit CC - double zsolac; // linear CC - double zanew; - double zanewm1; + dtype zsolab; // -ve implicit CC + dtype zsolac; // linear CC + dtype zanew; + dtype zanewm1; - double zgdp; + dtype zgdp; //---for flux calculation - double zda; - double zli[klev], za[klev]; - double zaorig[klev]; // start of scheme value for CC + dtype zda; + dtype zli[klev], za[klev]; + dtype zaorig[klev]; // start of scheme value for CC int llflag; int llo1; int icall, ik, jk, jl, jm, jn, jo, jlen, is; - double zdp, zpaphd; + dtype zdp, zpaphd; - double zalfa; + dtype zalfa; // & ZALFACU, ZALFALS - double zalfaw; - double zbeta, zbeta1; + dtype zalfaw; + dtype zbeta, zbeta1; //REAL(KIND=JPRB) :: ZBOTT - double zcfpr; - double zcor; - double zcdmax; - double zmin; - double zlcondlim; - double zdenom; - double zdpmxdt; - double zdpr; - double zdtdp; - double ze; - double zepsec; - double zfac, zfaci, zfacw; - double zgdcp; - double zinew; - double zlcrit; - double zmfdn; - double zprecip; - double zqe; - double zqsat, zqtmst, zrdcp; - double zrhc, zsig, zsigk; - double zwtot; - double zzco, zzdl, zzrh, zzzdt, zqadj; - double zqnew, ztnew; - double zrg_r, zgdph_r, zcons1, zcond, zcons1a; - double zlfinal; - double zmelt; - double zevap; - double zfrz; - double zvpliq, zvpice; - double zadd, zbdd, zcvds, zice0, zdepos; - double zsupsat; - double zfall; - double zre_ice; - double zrldcp; - double zqp1env; + dtype zcfpr; + dtype zcor; + dtype zcdmax; + dtype zmin; + dtype zlcondlim; + dtype zdenom; + dtype zdpmxdt; + dtype zdpr; + dtype zdtdp; + dtype ze; + dtype zepsec; + dtype zfac, zfaci, zfacw; + dtype zgdcp; + dtype zinew; + dtype zlcrit; + dtype zmfdn; + dtype zprecip; + dtype zqe; + dtype zqsat, zqtmst, zrdcp; + dtype zrhc, zsig, zsigk; + dtype zwtot; + dtype zzco, zzdl, zzrh, zzzdt, zqadj; + dtype zqnew, ztnew; + dtype zrg_r, zgdph_r, zcons1, zcond, zcons1a; + dtype zlfinal; + dtype zmelt; + dtype zevap; + dtype zfrz; + dtype zvpliq, zvpice; + dtype zadd, zbdd, zcvds, zice0, zdepos; + dtype zsupsat; + dtype zfall; + dtype zre_ice; + dtype zrldcp; + dtype zqp1env; //---------------------------- // Arrays for new microphysics @@ -168,16 +168,16 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, int llindex1[5]; // index variable int llindex3[5 * 5]; // index variable - double zmax; - double zrat; + dtype zmax; + dtype zrat; int iorder[5]; // array for sorting explicit terms - double zliqfrac[klev]; // cloud liquid water fraction: ql/(ql+qi) - double zicefrac[klev]; // cloud ice water fraction: qi/(ql+qi) - double zqxn[5]; // new values for zqx at time+1 - double zqxfg[5]; // first guess values including precip - double zqxnm1[5]; // new values for zqx at time+1 at level above - double zfluxq[5]; // fluxes convergence of species (needed?) + dtype zliqfrac[klev]; // cloud liquid water fraction: ql/(ql+qi) + dtype zicefrac[klev]; // cloud ice water fraction: qi/(ql+qi) + dtype zqxn[5]; // new values for zqx at time+1 + dtype zqxfg[5]; // first guess values including precip + dtype zqxnm1[5]; // new values for zqx at time+1 at level above + dtype zfluxq[5]; // fluxes convergence of species (needed?) // Keep the following for possible future total water variance scheme? //REAL(KIND=JPRB) :: ZTL(KLON,KLEV) ! liquid water temperature //REAL(KIND=JPRB) :: ZABETA(KLON,KLEV) ! cloud fraction @@ -185,31 +185,31 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //REAL(KIND=JPRB) :: ZQTMIN(KLON,KLEV) //REAL(KIND=JPRB) :: ZQTMAX(KLON,KLEV) - double zmeltmax; - double zfrzmax; - double zicetot; + dtype zmeltmax; + dtype zfrzmax; + dtype zicetot; - double zqsmix[klev]; // diagnostic mixed phase saturation + dtype zqsmix[klev]; // diagnostic mixed phase saturation //REAL(KIND=JPRB) :: ZQSBIN(KLON,KLEV) ! binary switched ice/liq saturation - double zqsliq[klev]; // liquid water saturation - double zqsice[klev]; // ice water saturation + dtype zqsliq[klev]; // liquid water saturation + dtype zqsice[klev]; // ice water saturation //REAL(KIND=JPRB) :: ZRHM(KLON,KLEV) ! diagnostic mixed phase RH //REAL(KIND=JPRB) :: ZRHL(KLON,KLEV) ! RH wrt liq //REAL(KIND=JPRB) :: ZRHI(KLON,KLEV) ! RH wrt ice - double zfoeewmt[klev]; - double zfoeew[klev]; - double zfoeeliqt[klev]; + dtype zfoeewmt[klev]; + dtype zfoeew[klev]; + dtype zfoeeliqt[klev]; //REAL(KIND=JPRB) :: ZFOEEICET(KLON,KLEV) - double zdqsliqdt, zdqsicedt, zdqsmixdt; - double zcorqsliq; - double zcorqsice; + dtype zdqsliqdt, zdqsicedt, zdqsmixdt; + dtype zcorqsliq; + dtype zcorqsice; //REAL(KIND=JPRB) :: ZCORQSBIN(KLON) - double zcorqsmix; - double zevaplimliq, zevaplimice, zevaplimmix; + dtype zcorqsmix; + dtype zevaplimliq, zevaplimice, zevaplimmix; //------------------------------------------------------- // SOURCE/SINK array for implicit and explicit terms @@ -230,60 +230,60 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // i.e. A positive value is a sink!????? weird... //------------------------------------------------------- - double zsolqa[5 * 5]; // explicit sources and sinks - double zsolqb[5 * 5]; // implicit sources and sinks + dtype zsolqa[5 * 5]; // explicit sources and sinks + dtype zsolqb[5 * 5]; // implicit sources and sinks // e.g. microphysical pathways between ice variables. - double zqlhs[5 * 5]; // n x n matrix storing the LHS of implicit solver - double zvqx[5]; // fall speeds of three categories - double zexplicit; - double zratio[5], zsinksum[5]; + dtype zqlhs[5 * 5]; // n x n matrix storing the LHS of implicit solver + dtype zvqx[5]; // fall speeds of three categories + dtype zexplicit; + dtype zratio[5], zsinksum[5]; // for sedimentation source/sink terms - double zfallsink[5]; - double zfallsrce[5]; + dtype zfallsink[5]; + dtype zfallsrce[5]; // for convection detrainment source and subsidence source/sink terms - double zconvsrce[5]; - double zconvsink[5]; + dtype zconvsrce[5]; + dtype zconvsink[5]; // for supersaturation source term from previous timestep - double zpsupsatsrce[5]; + dtype zpsupsatsrce[5]; // Numerical fit to wet bulb temperature - double ztw1 = (double) 1329.31; - double ztw2 = (double) 0.0074615; - double ztw3 = (double) 0.85E5; - double ztw4 = (double) 40.637; - double ztw5 = (double) 275.0; - - double zsubsat; // Subsaturation for snow melting term - double ztdmtw0; // Diff between dry-bulb temperature and + dtype ztw1 = (dtype) 1329.31; + dtype ztw2 = (dtype) 0.0074615; + dtype ztw3 = (dtype) 0.85E5; + dtype ztw4 = (dtype) 40.637; + dtype ztw5 = (dtype) 275.0; + + dtype zsubsat; // Subsaturation for snow melting term + dtype ztdmtw0; // Diff between dry-bulb temperature and // temperature when wet-bulb = 0degC // Variables for deposition term - double ztcg; // Temperature dependent function for ice PSD - double zfacx1i, zfacx1s; // PSD correction factor - double zaplusb, zcorrfac, zcorrfac2, zpr02, zterm1, zterm2; // for ice dep - double zcldtopdist; // Distance from cloud top - double zinfactor; // No. of ice nuclei factor for deposition + dtype ztcg; // Temperature dependent function for ice PSD + dtype zfacx1i, zfacx1s; // PSD correction factor + dtype zaplusb, zcorrfac, zcorrfac2, zpr02, zterm1, zterm2; // for ice dep + dtype zcldtopdist; // Distance from cloud top + dtype zinfactor; // No. of ice nuclei factor for deposition // Autoconversion/accretion/riming/evaporation int iwarmrain; int ievaprain; int ievapsnow; int idepice; - double zrainacc; - double zraincld; - double zsnowrime; - double zsnowcld; - double zesatliq; - double zfallcorr; - double zlambda; - double zevap_denom; - double zcorr2; - double zka; - double zconst; - double ztemp; + dtype zrainacc; + dtype zraincld; + dtype zsnowrime; + dtype zsnowcld; + dtype zesatliq; + dtype zfallcorr; + dtype zlambda; + dtype zevap_denom; + dtype zcorr2; + dtype zka; + dtype zconst; + dtype ztemp; // Rain freezing int llrainliq; // True if majority of raindrops are liquid (no ice core) @@ -295,27 +295,27 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------- // SCM budget statistics //---------------------- - double zrain; + dtype zrain; - double zhook_handle; - double ztmpl, ztmpi, ztmpa; + dtype zhook_handle; + dtype ztmpl, ztmpi, ztmpa; - double zmm, zrr; - double zrg; + dtype zmm, zrr; + dtype zrg; - double zzsum, zzratio; - double zepsilon; + dtype zzsum, zzratio; + dtype zepsilon; - double zcond1, zqp; + dtype zcond1, zqp; - double psum_solqa; + dtype psum_solqa; int ibl; int i_llfall_0; - double zqx[5 * klev]; - double zqx0[5 * klev]; - double zpfplsx[5 * (klev + 1)]; - double zlneg[5 * klev]; - double zqxn2d[5 * klev]; + dtype zqx[5 * klev]; + dtype zqx0[5 * klev]; + dtype zpfplsx[5 * (klev + 1)]; + dtype zlneg[5 * klev]; + dtype zqxn2d[5 * klev]; jl = threadIdx.x; ibl = blockIdx.x; @@ -333,7 +333,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 0. *** SET UP CONSTANTS *** //###################################################################### - zepsilon = (double) 100.*DBL_EPSILON; + zepsilon = (dtype) 100.*DBL_EPSILON; // --------------------------------------------------------------------- // Set version of warm-rain autoconversion/accretion @@ -363,13 +363,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // --------------------- // Some simple constants // --------------------- - zqtmst = (double) 1.0 / ptsphy; + zqtmst = (dtype) 1.0 / ptsphy; zgdcp = rg / rcpd; zrdcp = rd / rcpd; zcons1a = rcpd / (rlmlt*rg*(*yrecldp).rtaumel); - zepsec = (double) 1.E-14; - zrg_r = (double) 1.0 / rg; - zrldcp = (double) 1.0 / (ralsdcp - ralvdcp); + zepsec = (dtype) 1.E-14; + zrg_r = (dtype) 1.0 / rg; + zrldcp = (dtype) 1.0 / (ralsdcp - ralvdcp); // Note: Defined in module/yoecldp.F90 // NCLDQL=1 ! liquid cloud water @@ -401,28 +401,28 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // INITIALIZATION OF OUTPUT TENDENCIES // ----------------------------------------------- for (jk = 0; jk <= klev + -1; jk += 1) { - tendency_loc_t[jl + klon*(jk + klev*(ibl))] = (double) 0.0; - tendency_loc_q[jl + klon*(jk + klev*(ibl))] = (double) 0.0; - tendency_loc_a[jl + klon*(jk + klev*(ibl))] = (double) 0.0; + tendency_loc_t[jl + klon*(jk + klev*(ibl))] = (dtype) 0.0; + tendency_loc_q[jl + klon*(jk + klev*(ibl))] = (dtype) 0.0; + tendency_loc_a[jl + klon*(jk + klev*(ibl))] = (dtype) 0.0; } for (jm = 0; jm <= 5 - 1 + -1; jm += 1) { for (jk = 0; jk <= klev + -1; jk += 1) { - tendency_loc_cld[jl + klon*(jk + klev*(jm + 5*(ibl)))] = (double) 0.0; + tendency_loc_cld[jl + klon*(jk + klev*(jm + 5*(ibl)))] = (dtype) 0.0; } } //-- These were uninitialized : meaningful only when we compare error differences for (jk = 0; jk <= klev + -1; jk += 1) { - pcovptot[jl + klon*(jk + klev*(ibl))] = (double) 0.0; - tendency_loc_cld[jl + klon*(jk + klev*(4 + 5*(ibl)))] = (double) 0.0 + pcovptot[jl + klon*(jk + klev*(ibl))] = (dtype) 0.0; + tendency_loc_cld[jl + klon*(jk + klev*(4 + 5*(ibl)))] = (dtype) 0.0 ; } // ------------------------- // set up fall speeds in m/s // ------------------------- - zvqx[4] = (double) 0.0; - zvqx[0] = (double) 0.0; + zvqx[4] = (dtype) 0.0; + zvqx[0] = (dtype) 0.0; zvqx[1] = (*yrecldp).rvice; zvqx[2] = (*yrecldp).rvrain; zvqx[3] = (*yrecldp).rvsnow; @@ -430,7 +430,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, llfall[i_llfall_0] = false; } for (jm = 0; jm <= 5 + -1; jm += 1) { - if (zvqx[jm] > (double) 0.0) { + if (zvqx[jm] > (dtype) 0.0) { llfall[jm] = true; } // falling species @@ -478,18 +478,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //------------- for (jm = 0; jm <= 5 + -1; jm += 1) { for (jk = 0; jk <= klev + 1 + -1; jk += 1) { - zpfplsx[jk + (klev + 1)*jm] = (double) 0.0; // precip fluxes + zpfplsx[jk + (klev + 1)*jm] = (dtype) 0.0; // precip fluxes } } for (jm = 0; jm <= 5 + -1; jm += 1) { for (jk = 0; jk <= klev + -1; jk += 1) { - zqxn2d[jk + klev*jm] = (double) 0.0; // end of timestep values in 2D - zlneg[jk + klev*jm] = (double) 0.0; // negative input check + zqxn2d[jk + klev*jm] = (dtype) 0.0; // end of timestep values in 2D + zlneg[jk + klev*jm] = (dtype) 0.0; // negative input check } } - prainfrac_toprfz[jl + klon*(ibl)] = (double) 0.0; // rain fraction at top of refreezing layer + prainfrac_toprfz[jl + klon*(ibl)] = (dtype) 0.0; // rain fraction at top of refreezing layer llrainliq = true; // Assume all raindrops are liquid initially // ---------------------------------------------------- @@ -507,7 +507,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*(ibl))] = tendency_loc_t[jl + klon*(jk + klev*(ibl))] - ralvdcp*zqadj; zqx[jk + klev*(4)] = zqx[jk + klev*(4)] + zqx[jk + klev*(0)]; - zqx[jk + klev*(0)] = (double) 0.0; + zqx[jk + klev*(0)] = (dtype) 0.0; // Evaporate small cloud ice water amounts zlneg[jk + klev*(1)] = zlneg[jk + klev*(1)] + zqx[jk + klev*(1)]; @@ -517,10 +517,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*(ibl))] = tendency_loc_t[jl + klon*(jk + klev*(ibl))] - ralsdcp*zqadj; zqx[jk + klev*(4)] = zqx[jk + klev*(4)] + zqx[jk + klev*(1)]; - zqx[jk + klev*(1)] = (double) 0.0; + zqx[jk + klev*(1)] = (dtype) 0.0; // Set cloud cover to zero - za[jk] = (double) 0.0; + za[jk] = (dtype) 0.0; } } @@ -547,7 +547,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*(ibl))] - ralsdcp*zqadj; } zqx[jk + klev*(4)] = zqx[jk + klev*(4)] + zqx[jk + klev*jm]; - zqx[jk + klev*jm] = (double) 0.0; + zqx[jk + klev*jm] = (dtype) 0.0; } } } @@ -560,34 +560,34 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------------- // old *diagnostic* mixed phase saturation //---------------------------------------- - zfoealfa[jk] = ((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))); + zfoealfa[jk] = ((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))); zfoeewmt[jk] = - fmin(((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*exp((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)) + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))) / pap[jl + klon*(jk + klev*(ibl))], (double) 0.5); + MYMIN(((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*MYEXP((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)) + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))) / pap[jl + klon*(jk + klev*(ibl))], (dtype) 0.5); zqsmix[jk] = zfoeewmt[jk]; - zqsmix[jk] = zqsmix[jk] / ((double) 1.0 - retv*zqsmix[jk]); + zqsmix[jk] = zqsmix[jk] / ((dtype) 1.0 - retv*zqsmix[jk]); //--------------------------------------------- // ice saturation T<273K // liquid water saturation for T>273K //--------------------------------------------- - zalfa = ((double)(fmax(0.0, copysign(1.0, ztp1[jk] - rtt)))); - zfoeew[jk] = fmin((zalfa*((double)(r2es*exp((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))) + ((double) 1.0 - zalfa)*((double)(r2es*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))) / pap[jl + - klon*(jk + klev*(ibl))], (double) 0.5); - zfoeew[jk] = fmin((double) 0.5, zfoeew[jk]); - zqsice[jk] = zfoeew[jk] / ((double) 1.0 - retv*zfoeew[jk]); + zalfa = ((dtype)(MYMAX(0.0, copysign(1.0, ztp1[jk] - rtt)))); + zfoeew[jk] = MYMIN((zalfa*((dtype)(r2es*MYEXP((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))) + ((dtype) 1.0 - zalfa)*((dtype)(r2es*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))) / pap[jl + + klon*(jk + klev*(ibl))], (dtype) 0.5); + zfoeew[jk] = MYMIN((dtype) 0.5, zfoeew[jk]); + zqsice[jk] = zfoeew[jk] / ((dtype) 1.0 - retv*zfoeew[jk]); //---------------------------------- // liquid water saturation //---------------------------------- zfoeeliqt[jk] = - fmin(((double)(r2es*exp((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))) / pap[jl + klon*(jk + klev*(ibl))], (double) 0.5); + MYMIN(((dtype)(r2es*MYEXP((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))) / pap[jl + klon*(jk + klev*(ibl))], (dtype) 0.5); zqsliq[jk] = zfoeeliqt[jk]; - zqsliq[jk] = zqsliq[jk] / ((double) 1.0 - retv*zqsliq[jk]); + zqsliq[jk] = zqsliq[jk] / ((dtype) 1.0 - retv*zqsliq[jk]); // !---------------------------------- // ! ice water saturation // !---------------------------------- - // ZFOEEICET(JL,JK)=MIN(((double)(r2es*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))(ZTP1(JL,JK))/PAP(JL,JK),0.5_JPRB) + // ZFOEEICET(JL,JK)=MIN(((dtype)(r2es*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))(ZTP1(JL,JK))/PAP(JL,JK),0.5_JPRB) // ZQSICE(JL,JK)=ZFOEEICET(JL,JK) // ZQSICE(JL,JK)=ZQSICE(JL,JK)/(1.0_JPRB-RETV*ZQSICE(JL,JK)) @@ -599,7 +599,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //------------------------------------------ // Ensure cloud fraction is between 0 and 1 //------------------------------------------ - za[jk] = fmax((double) 0.0, fmin((double) 1.0, za[jk])); + za[jk] = MYMAX((dtype) 0.0, MYMIN((dtype) 1.0, za[jk])); //------------------------------------------------------------------- // Calculate liq/ice fractions (no longer a diagnostic relationship) @@ -607,10 +607,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zli[jk] = zqx[jk + klev*(0)] + zqx[jk + klev*(1)]; if (zli[jk] > (*yrecldp).rlmin) { zliqfrac[jk] = zqx[jk + klev*(0)] / zli[jk]; - zicefrac[jk] = (double) 1.0 - zliqfrac[jk]; + zicefrac[jk] = (dtype) 1.0 - zliqfrac[jk]; } else { - zliqfrac[jk] = (double) 0.0; - zicefrac[jk] = (double) 0.0; + zliqfrac[jk] = (dtype) 0.0; + zicefrac[jk] = (dtype) 0.0; } } @@ -626,11 +626,11 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------- // Find tropopause level (ZTRPAUS) //--------------------------------- - ztrpaus = (double) 0.1; - zpaphd = (double) 1.0 / paph[jl + klon*(klev + (klev + 1)*(ibl))]; + ztrpaus = (dtype) 0.1; + zpaphd = (dtype) 1.0 / paph[jl + klon*(klev + (klev + 1)*(ibl))]; for (jk = 0; jk <= klev - 1 + -1; jk += 1) { zsig = pap[jl + klon*(jk + klev*(ibl))]*zpaphd; - if (zsig > (double) 0.1 && zsig < (double) 0.4 && ztp1[jk] > ztp1[1 + jk]) { + if (zsig > (dtype) 0.1 && zsig < (dtype) 0.4 && ztp1[jk] > ztp1[1 + jk]) { ztrpaus = zsig; } } @@ -639,12 +639,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reset single level variables //----------------------------- - zanewm1 = (double) 0.0; - zda = (double) 0.0; - zcovpclr = (double) 0.0; - zcovpmax = (double) 0.0; - zcovptot = (double) 0.0; - zcldtopdist = (double) 0.0; + zanewm1 = (dtype) 0.0; + zda = (dtype) 0.0; + zcovpclr = (dtype) 0.0; + zcovpmax = (dtype) 0.0; + zcovptot = (dtype) 0.0; + zcldtopdist = (dtype) 0.0; //###################################################################### // 3. *** PHYSICS *** @@ -672,37 +672,37 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Set KLON arrays to zero //--------------------------------- - zlicld = (double) 0.0; - zrainaut = (double) 0.0; // currently needed for diags - zrainacc = (double) 0.0; // currently needed for diags - zsnowaut = (double) 0.0; // needed - zldefr = (double) 0.0; - zacust = (double) 0.0; // set later when needed - zqpretot = (double) 0.0; - zlfinalsum = (double) 0.0; + zlicld = (dtype) 0.0; + zrainaut = (dtype) 0.0; // currently needed for diags + zrainacc = (dtype) 0.0; // currently needed for diags + zsnowaut = (dtype) 0.0; // needed + zldefr = (dtype) 0.0; + zacust = (dtype) 0.0; // set later when needed + zqpretot = (dtype) 0.0; + zlfinalsum = (dtype) 0.0; // Required for first guess call - zlcond1 = (double) 0.0; - zlcond2 = (double) 0.0; - zsupsat = (double) 0.0; - zlevapl = (double) 0.0; - zlevapi = (double) 0.0; + zlcond1 = (dtype) 0.0; + zlcond2 = (dtype) 0.0; + zsupsat = (dtype) 0.0; + zlevapl = (dtype) 0.0; + zlevapi = (dtype) 0.0; //------------------------------------- // solvers for cloud fraction //------------------------------------- - zsolab = (double) 0.0; - zsolac = (double) 0.0; + zsolab = (dtype) 0.0; + zsolac = (dtype) 0.0; - zicetot = (double) 0.0; + zicetot = (dtype) 0.0; //------------------------------------------ // reset matrix so missing pathways are set //------------------------------------------ for (jm = 0; jm <= 5 + -1; jm += 1) { for (jn = 0; jn <= 5 + -1; jn += 1) { - zsolqb[jn + 5*jm] = (double) 0.0; - zsolqa[jn + 5*jm] = (double) 0.0; + zsolqb[jn + 5*jm] = (dtype) 0.0; + zsolqa[jn + 5*jm] = (dtype) 0.0; } } @@ -710,12 +710,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // reset new microphysics variables //---------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zfallsrce[jm] = (double) 0.0; - zfallsink[jm] = (double) 0.0; - zconvsrce[jm] = (double) 0.0; - zconvsink[jm] = (double) 0.0; - zpsupsatsrce[jm] = (double) 0.0; - zratio[jm] = (double) 0.0; + zfallsrce[jm] = (dtype) 0.0; + zfallsink[jm] = (dtype) 0.0; + zconvsrce[jm] = (dtype) 0.0; + zconvsink[jm] = (dtype) 0.0; + zpsupsatsrce[jm] = (dtype) 0.0; + zratio[jm] = (dtype) 0.0; } @@ -729,7 +729,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zrho = pap[jl + klon*(jk + klev*(ibl))] / (rd*ztp1[jk]); // p/RT air density zdtgdp = ptsphy*zgdp; // dt g/dp - zrdtgdp = zdp*((double) 1.0 / (ptsphy*rg)); // 1/(dt g/dp) + zrdtgdp = zdp*((dtype) 1.0 / (ptsphy*rg)); // 1/(dt g/dp) if (jk + 1 > 1) { zdtgdpf = ptsphy*rg / (pap[jl + klon*(jk + klev*(ibl))] - pap[jl + @@ -742,37 +742,37 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reminder: RETV=RV/RD-1 // liquid - zfacw = r5les / (pow((ztp1[jk] - r4les), 2)); - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeeliqt[jk]); + zfacw = r5les / (MYPOW((ztp1[jk] - r4les), 2)); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeeliqt[jk]); zdqsliqdt = zfacw*zcor*zqsliq[jk]; - zcorqsliq = (double) 1.0 + ralvdcp*zdqsliqdt; + zcorqsliq = (dtype) 1.0 + ralvdcp*zdqsliqdt; // ice - zfaci = r5ies / (pow((ztp1[jk] - r4ies), 2)); - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeew[jk]); + zfaci = r5ies / (MYPOW((ztp1[jk] - r4ies), 2)); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeew[jk]); zdqsicedt = zfaci*zcor*zqsice[jk]; - zcorqsice = (double) 1.0 + ralsdcp*zdqsicedt; + zcorqsice = (dtype) 1.0 + ralsdcp*zdqsicedt; // diagnostic mixed zalfaw = zfoealfa[jk]; zalfawm = zalfaw; - zfac = zalfaw*zfacw + ((double) 1.0 - zalfaw)*zfaci; - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeewmt[jk]); + zfac = zalfaw*zfacw + ((dtype) 1.0 - zalfaw)*zfaci; + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeewmt[jk]); zdqsmixdt = zfac*zcor*zqsmix[jk]; - zcorqsmix = (double) 1.0 + ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zdqsmixdt; + zcorqsmix = (dtype) 1.0 + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zdqsmixdt; // evaporation/sublimation limits zevaplimmix = - fmax((zqsmix[jk] - zqx[jk + klev*(4)]) / zcorqsmix, (double) 0.0); + MYMAX((zqsmix[jk] - zqx[jk + klev*(4)]) / zcorqsmix, (dtype) 0.0); zevaplimliq = - fmax((zqsliq[jk] - zqx[jk + klev*(4)]) / zcorqsliq, (double) 0.0); + MYMAX((zqsliq[jk] - zqx[jk + klev*(4)]) / zcorqsliq, (dtype) 0.0); zevaplimice = - fmax((zqsice[jk] - zqx[jk + klev*(4)]) / zcorqsice, (double) 0.0); + MYMAX((zqsice[jk] - zqx[jk + klev*(4)]) / zcorqsice, (dtype) 0.0); //-------------------------------- // in-cloud consensate amount //-------------------------------- - ztmpa = (double) 1.0 / fmax(za[jk], zepsec); + ztmpa = (dtype) 1.0 / MYMAX(za[jk], zepsec); zliqcld = zqx[jk + klev*(0)]*ztmpa; zicecld = zqx[jk + klev*(1)]*ztmpa; zlicld = zliqcld + zicecld; @@ -812,13 +812,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 3.1.1 Supersaturation limit (from Koop) //----------------------------------- // Needs to be set for all temperatures - zfokoop = ((double)(fmin(rkoop1 - rkoop2*ztp1[jk], (double)(r2es*exp((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))*1.0/(double)(r2es*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies)))))); + zfokoop = ((dtype)(MYMIN(rkoop1 - rkoop2*ztp1[jk], (dtype)(r2es*MYEXP((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))*1.0/(dtype)(r2es*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies)))))); if (ztp1[jk] >= rtt || (*yrecldp).nssopt == 0) { - zfac = (double) 1.0; - zfaci = (double) 1.0; + zfac = (dtype) 1.0; + zfaci = (dtype) 1.0; } else { - zfac = za[jk] + zfokoop*((double) 1.0 - za[jk]); + zfac = za[jk] + zfokoop*((dtype) 1.0 - za[jk]); zfaci = ptsphy / (*yrecldp).rkooptau; } @@ -829,16 +829,16 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //------------------------------------------------------------------- // Calculate supersaturation to add to cloud - if (za[jk] > (double) 1.0 - (*yrecldp).ramin) { + if (za[jk] > (dtype) 1.0 - (*yrecldp).ramin) { zsupsat = - fmax((zqx[jk + klev*(4)] - zfac*zqsice[jk]) / zcorqsice, (double) 0.0); + MYMAX((zqx[jk + klev*(4)] - zfac*zqsice[jk]) / zcorqsice, (dtype) 0.0); } else { // Calculate environmental humidity supersaturation - zqp1env = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / fmax((double) 1.0 - + zqp1env = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / MYMAX((dtype) 1.0 - za[jk], zepsilon); //& SIGN(MAX(ABS(1.0_JPRB-ZA(JL,JK)),ZEPSILON),1.0_JPRB-ZA(JL,JK)) - zsupsat = fmax(((double) 1.0 - za[jk])*(zqp1env - zfac*zqsice[jk]) / zcorqsice, - (double) 0.0); + zsupsat = MYMAX(((dtype) 1.0 - za[jk])*(zqp1env - zfac*zqsice[jk]) / zcorqsice, + (dtype) 0.0); } //------------------------------------------------------------------- @@ -864,7 +864,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } // Increase cloud amount using RKOOPTAU timescale - zsolac = ((double) 1.0 - za[jk])*zfaci; + zsolac = ((dtype) 1.0 - za[jk])*zfaci; } @@ -892,7 +892,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } // Increase cloud amount using RKOOPTAU timescale - zsolac = ((double) 1.0 - za[jk])*zfaci; + zsolac = ((dtype) 1.0 - za[jk])*zfaci; // Store cloud budget diagnostics if required } @@ -925,13 +925,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zalfaw = zfoealfa[jk]; zconvsrce[0] = zalfaw*plude[jl + klon*(jk + klev*(ibl))]; zconvsrce[1] = - ((double) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*(ibl))]; + ((dtype) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*(ibl))]; zsolqa[0 + 5*(0)] = zsolqa[0 + 5*(0)] + zconvsrce[0]; zsolqa[1 + 5*(1)] = zsolqa[1 + 5*(1)] + zconvsrce[1]; } else { - plude[jl + klon*(jk + klev*(ibl))] = (double) 0.0; + plude[jl + klon*(jk + klev*(ibl))] = (dtype) 0.0; } // *convective snow detrainment source @@ -960,7 +960,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------- if (jk + 1 > (*yrecldp).ncldtop) { - zmf = fmax((double) 0.0, (pmfu[jl + klon*(jk + klev*(ibl))] + pmfd[-1 + + zmf = MYMAX((dtype) 0.0, (pmfu[jl + klon*(jk + klev*(ibl))] + pmfd[-1 + jl + klon*(jk + klev*(ibl))])*zdtgdp); zacust = zmf*zanewm1; @@ -976,7 +976,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // since there is no prognostic memory for in-cloud humidity, i.e. // we always assume cloud is saturated. - zdtdp = zrdcp*(double) 0.5*(ztp1[-1 + jk] + ztp1[jk]) / paph[jl + klon*(jk + + zdtdp = zrdcp*(dtype) 0.5*(ztp1[-1 + jk] + ztp1[jk]) / paph[jl + klon*(jk + (klev + 1)*(ibl))]; zdtforc = zdtdp*(pap[jl + klon*(jk + klev*(ibl))] - pap[jl + klon*(-1 + jk + klev*(ibl))]); @@ -985,9 +985,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jm = 0; jm <= 5 + -1; jm += 1) { if (!llfall[jm] && iphase[jm] > 0) { - zlfinal = fmax((double) 0.0, zlcust[jm] - zdqs); //lim to zero + zlfinal = MYMAX((dtype) 0.0, zlcust[jm] - zdqs); //lim to zero // no supersaturation allowed incloud ---V - zevap = fmin((zlcust[jm] - zlfinal), zevaplimmix); + zevap = MYMIN((zlcust[jm] - zlfinal), zevaplimmix); // ZEVAP=0.0_JPRB zlfinal = zlcust[jm] - zevap; zlfinalsum = zlfinalsum + zlfinal; // sum @@ -1000,7 +1000,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reset the cloud contribution if no cloud water survives to this level: if (zlfinalsum < zepsec) { - zacust = (double) 0.0; + zacust = (dtype) 0.0; } zsolac = zsolac + zacust; @@ -1015,7 +1015,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (jk + 1 < klev) { - zmfdn = fmax((double) 0.0, (pmfu[jl + klon*(1 + jk + klev*(ibl))] + + zmfdn = MYMAX((dtype) 0.0, (pmfu[jl + klon*(1 + jk + klev*(ibl))] + pmfd[jl + klon*(1 + jk + klev*(ibl))])*zdtgdp); zsolab = zsolab + zmfdn; @@ -1055,10 +1055,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // ZQE=(ZQX(JL,JK,NCLDQV)-ZA(JL,JK)*ZQSMIX(JL,JK))/& // & MAX(ZEPSEC,1.0_JPRB-ZA(JL,JK)) // ZE=ZLDIFDT(JL)*MAX(ZQSMIX(JL,JK)-ZQE,0.0_JPRB) - ze = zldifdt*fmax(zqsmix[jk] - zqx[jk + klev*(4)], (double) 0.0); + ze = zldifdt*MYMAX(zqsmix[jk] - zqx[jk + klev*(4)], (dtype) 0.0); zleros = za[jk]*ze; - zleros = fmin(zleros, zevaplimmix); - zleros = fmin(zleros, zli[jk]); + zleros = MYMIN(zleros, zevaplimmix); + zleros = MYMIN(zleros, zli[jk]); zaeros = zleros / zlicld; //if linear term // Erosion is -ve LINEAR in L,A @@ -1091,18 +1091,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zdtdp = zrdcp*ztp1[jk] / pap[jl + klon*(jk + klev*(ibl))]; zdpmxdt = zdp*zqtmst; - zmfdn = (double) 0.0; + zmfdn = (dtype) 0.0; if (jk + 1 < klev) { zmfdn = pmfu[jl + klon*(1 + jk + klev*(ibl))] + pmfd[jl + klon*(1 + jk + klev*(ibl))]; } - zwtot = pvervel[jl + klon*(jk + klev*(ibl))] + (double) 0.5*rg*(pmfu[ + zwtot = pvervel[jl + klon*(jk + klev*(ibl))] + (dtype) 0.5*rg*(pmfu[ jl + klon*(jk + klev*(ibl))] + pmfd[jl + klon*(jk + klev*(ibl))] + zmfdn); - zwtot = fmin(zdpmxdt, fmax(-zdpmxdt, zwtot)); + zwtot = MYMIN(zdpmxdt, MYMAX(-zdpmxdt, zwtot)); zzzdt = phrsw[jl + klon*(jk + klev*(ibl))] + phrlw[jl + klon*(jk + klev*(ibl))]; - zdtdiab = fmin(zdpmxdt*zdtdp, fmax(-zdpmxdt*zdtdp, zzzdt))*ptsphy + ralfdcp*zldefr; + zdtdiab = MYMIN(zdpmxdt*zdtdp, MYMAX(-zdpmxdt*zdtdp, zzzdt))*ptsphy + ralfdcp*zldefr; // Note: ZLDEFR should be set to the difference between the mixed phase functions // in the convection and cloud scheme, but this is not calculated, so is zero and // the functions must be the same @@ -1110,24 +1110,24 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zqold = zqsmix[jk]; ztold = ztp1[jk]; ztp1[jk] = ztp1[jk] + zdtforc; - ztp1[jk] = fmax(ztp1[jk], (double) 160.0); + ztp1[jk] = MYMAX(ztp1[jk], (dtype) 160.0); llflag = true; // Formerly a call to CUADJTQ(..., ICALL=5) - zqp = (double) 1.0 / pap[jl + klon*(jk + klev*(ibl))]; - zqsat = ((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*exp((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)) + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies)))))*zqp; - zqsat = fmin((double) 0.5, zqsat); - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsat); + zqp = (dtype) 1.0 / pap[jl + klon*(jk + klev*(ibl))]; + zqsat = ((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*MYEXP((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)) + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies)))))*zqp; + zqsat = MYMIN((dtype) 0.5, zqsat); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsat); zqsat = zqsat*zcor; - zcond = (zqsmix[jk] - zqsat) / ((double) 1.0 + zqsat*zcor*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/pow(ztp1[jk] - r4les, 2)) + ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)*(1.0/pow(ztp1[jk] - r4ies, 2))))); - ztp1[jk] = ztp1[jk] + ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond; + zcond = (zqsmix[jk] - zqsat) / ((dtype) 1.0 + zqsat*zcor*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/MYPOW(ztp1[jk] - r4les, 2)) + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)*(1.0/MYPOW(ztp1[jk] - r4ies, 2))))); + ztp1[jk] = ztp1[jk] + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond; zqsmix[jk] = zqsmix[jk] - zcond; - zqsat = ((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*exp((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)) + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies)))))*zqp; - zqsat = fmin((double) 0.5, zqsat); - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsat); + zqsat = ((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*MYEXP((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)) + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies)))))*zqp; + zqsat = MYMIN((dtype) 0.5, zqsat); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsat); zqsat = zqsat*zcor; - zcond1 = (zqsmix[jk] - zqsat) / ((double) 1.0 + zqsat*zcor*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/pow(ztp1[jk] - r4les, 2)) + ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)*(1.0/pow(ztp1[jk] - r4ies, 2))))); - ztp1[jk] = ztp1[jk] + ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond1; + zcond1 = (zqsmix[jk] - zqsat) / ((dtype) 1.0 + zqsat*zcor*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/MYPOW(ztp1[jk] - r4les, 2)) + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)*(1.0/MYPOW(ztp1[jk] - r4ies, 2))))); + ztp1[jk] = ztp1[jk] + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond1; zqsmix[jk] = zqsmix[jk] - zcond1; zdqs = zqsmix[jk] - zqold; @@ -1142,13 +1142,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Previous function based on DELTA DISTRIBUTION in cloud: - if (zdqs > (double) 0.0) { + if (zdqs > (dtype) 0.0) { // If subsidence evaporation term is turned off, then need to use updated // liquid and cloud here? // ZLEVAP = MAX(ZA(JL,JK)+ZACUST(JL),1.0_JPRB)*MIN(ZDQS(JL),ZLICLD(JL)+ZLFINALSUM(JL)) - zlevap = za[jk]*fmin(zdqs, zlicld); - zlevap = fmin(zlevap, zevaplimmix); - zlevap = fmin(zlevap, fmax(zqsmix[jk] - zqx[jk + klev*(4)], (double) 0.0)); + zlevap = za[jk]*MYMIN(zdqs, zlicld); + zlevap = MYMIN(zlevap, zevaplimmix); + zlevap = MYMIN(zlevap, MYMAX(zqsmix[jk] - zqx[jk + klev*(4)], (dtype) 0.0)); // For first guess call zlevapl = zliqfrac[jk]*zlevap; @@ -1169,22 +1169,22 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // (1) Increase of cloud water in existing clouds if (za[jk] > zepsec && zdqs <= -(*yrecldp).rlmin) { - zlcond1 = fmax(-zdqs, (double) 0.0); //new limiter + zlcond1 = MYMAX(-zdqs, (dtype) 0.0); //new limiter //old limiter (significantly improves upper tropospheric humidity rms) - if (za[jk] > (double) 0.99) { - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsmix[jk]); - zcdmax = (zqx[jk + klev*(4)] - zqsmix[jk]) / ((double) 1.0 + - zcor*zqsmix[jk]*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/pow(ztp1[jk] - r4les, 2)) + ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)*(1.0/pow(ztp1[jk] - r4ies, 2))))); + if (za[jk] > (dtype) 0.99) { + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsmix[jk]); + zcdmax = (zqx[jk + klev*(4)] - zqsmix[jk]) / ((dtype) 1.0 + + zcor*zqsmix[jk]*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/MYPOW(ztp1[jk] - r4les, 2)) + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)*(1.0/MYPOW(ztp1[jk] - r4ies, 2))))); } else { zcdmax = (zqx[jk + klev*(4)] - za[jk]*zqsmix[jk]) / za[jk]; } - zlcond1 = fmax(fmin(zlcond1, zcdmax), (double) 0.0); + zlcond1 = MYMAX(MYMIN(zlcond1, zcdmax), (dtype) 0.0); // end old limiter zlcond1 = za[jk]*zlcond1; if (zlcond1 < (*yrecldp).rlmin) { - zlcond1 = (double) 0.0; + zlcond1 = (dtype) 0.0; } //------------------------------------------------------------------------- @@ -1206,7 +1206,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // (2) Generation of new clouds (da/dt>0) - if (zdqs <= -(*yrecldp).rlmin && za[jk] < (double) 1.0 - zepsec) { + if (zdqs <= -(*yrecldp).rlmin && za[jk] < (dtype) 1.0 - zepsec) { //--------------------------- // Critical relative humidity @@ -1215,9 +1215,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zsigk = pap[jl + klon*(jk + klev*(ibl))] / paph[jl + klon*(klev + (klev + 1)*(ibl))]; // Increase RHcrit to 1.0 towards the surface (eta>0.8) - if (zsigk > (double) 0.8) { - zrhc = (*yrecldp).ramid + ((double) 1.0 - (*yrecldp).ramid)*(pow(((zsigk - - (double) 0.8) / (double) 0.2), 2)); + if (zsigk > (dtype) 0.8) { + zrhc = (*yrecldp).ramid + ((dtype) 1.0 - (*yrecldp).ramid)*(MYPOW(((zsigk - + (dtype) 0.8) / (dtype) 0.2), 2)); } // Commented out for CY37R1 to reduce humidity in high trop and strat @@ -1232,14 +1232,14 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- if ((*yrecldp).nssopt == 0) { // No scheme - zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / fmax(zepsec, (double) 1.0 + zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / MYMAX(zepsec, (dtype) 1.0 - za[jk]); - zqe = fmax((double) 0.0, zqe); + zqe = MYMAX((dtype) 0.0, zqe); } else if ((*yrecldp).nssopt == 1) { // Tompkins - zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / fmax(zepsec, (double) 1.0 + zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / MYMAX(zepsec, (dtype) 1.0 - za[jk]); - zqe = fmax((double) 0.0, zqe); + zqe = MYMAX((dtype) 0.0, zqe); } else if ((*yrecldp).nssopt == 2) { // Lohmann and Karcher zqe = zqx[jk + klev*(4)]; @@ -1250,7 +1250,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk] >= rtt || (*yrecldp).nssopt == 0) { // No ice supersaturation allowed - zfac = (double) 1.0; + zfac = (dtype) 1.0; } else { // Ice supersaturation zfac = zfokoop; @@ -1259,33 +1259,33 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zqe >= zrhc*zqsice[jk]*zfac && zqe < zqsice[jk]*zfac) { // note: not **2 on 1-a term if ZQE is used. // Added correction term ZFAC to numerator 15/03/2010 - zacond = -((double) 1.0 - za[jk])*zfac*zdqs / fmax((double) + zacond = -((dtype) 1.0 - za[jk])*zfac*zdqs / MYMAX((dtype) 2.0*(zfac*zqsice[jk] - zqe), zepsec); - zacond = fmin(zacond, (double) 1.0 - za[jk]); //PUT THE LIMITER BACK + zacond = MYMIN(zacond, (dtype) 1.0 - za[jk]); //PUT THE LIMITER BACK // Linear term: // Added correction term ZFAC 15/03/2010 - zlcond2 = -zfac*zdqs*(double) 0.5*zacond; //mine linear + zlcond2 = -zfac*zdqs*(dtype) 0.5*zacond; //mine linear // new limiter formulation zzdl = - (double) 2.0*(zfac*zqsice[jk] - zqe) / fmax(zepsec, (double) 1.0 - za[jk]); + (dtype) 2.0*(zfac*zqsice[jk] - zqe) / MYMAX(zepsec, (dtype) 1.0 - za[jk]); // Added correction term ZFAC 15/03/2010 if (zfac*zdqs < -zzdl) { // ZLCONDLIM=(ZA(JL,JK)-1.0_JPRB)*ZDQS(JL)-ZQSICE(JL,JK)+ZQX(JL,JK,NCLDQV) - zlcondlim = (za[jk] - (double) 1.0)*zfac*zdqs - zfac*zqsice[jk] + zqx[jk + + zlcondlim = (za[jk] - (dtype) 1.0)*zfac*zdqs - zfac*zqsice[jk] + zqx[jk + klev*(4)]; - zlcond2 = fmin(zlcond2, zlcondlim); + zlcond2 = MYMIN(zlcond2, zlcondlim); } - zlcond2 = fmax(zlcond2, (double) 0.0); + zlcond2 = MYMAX(zlcond2, (dtype) 0.0); - if (zlcond2 < (*yrecldp).rlmin || ((double) 1.0 - za[jk]) < zepsec) { - zlcond2 = (double) 0.0; - zacond = (double) 0.0; + if (zlcond2 < (*yrecldp).rlmin || ((dtype) 1.0 - za[jk]) < zepsec) { + zlcond2 = (dtype) 0.0; + zacond = (dtype) 0.0; } - if (zlcond2 == (double) 0.0) { - zacond = (double) 0.0; + if (zlcond2 == (dtype) 0.0) { + zacond = (dtype) 0.0; } // Large-scale generation is LINEAR in A and LINEAR in L @@ -1338,7 +1338,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------------- if (za[-1 + jk] < (*yrecldp).rcldtopcf && za[jk] >= (*yrecldp).rcldtopcf) { - zcldtopdist = (double) 0.0; + zcldtopdist = (dtype) 0.0; } else { zcldtopdist = zcldtopdist + zdp / (zrho*rg); } @@ -1351,37 +1351,37 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk] < rtt && zqxfg[0] > (*yrecldp).rlmin) { // T<273K - zvpice = ((double)(r2es*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))*rv / rd; + zvpice = ((dtype)(r2es*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))*rv / rd; zvpliq = zvpice*zfokoop; - zicenuclei = (double) 1000.0*exp((double) 12.96*(zvpliq - zvpice) / zvpliq - - (double) 0.639); + zicenuclei = (dtype) 1000.0*MYEXP((dtype) 12.96*(zvpliq - zvpice) / zvpliq - + (dtype) 0.639); //------------------------------------------------ // 2.4e-2 is conductivity of air // 8.8 = 700**1/3 = density of ice to the third //------------------------------------------------ zadd = - rlstt*(rlstt / (rv*ztp1[jk]) - (double) 1.0) / ((double) 2.4E-2*ztp1[jk]); - zbdd = rv*ztp1[jk]*pap[jl + klon*(jk + klev*(ibl))] / ((double) + rlstt*(rlstt / (rv*ztp1[jk]) - (dtype) 1.0) / ((dtype) 2.4E-2*ztp1[jk]); + zbdd = rv*ztp1[jk]*pap[jl + klon*(jk + klev*(ibl))] / ((dtype) 2.21*zvpice); - zcvds = (double) 7.8*(pow((zicenuclei / zrho), (double) 0.666))*(zvpliq - - zvpice) / ((double) 8.87*(zadd + zbdd)*zvpice); + zcvds = (dtype) 7.8*(MYPOW((zicenuclei / zrho), (dtype) 0.666))*(zvpliq - + zvpice) / ((dtype) 8.87*(zadd + zbdd)*zvpice); //----------------------------------------------------- // RICEINIT=1.E-12_JPRB is initial mass of ice particle //----------------------------------------------------- - zice0 = fmax(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); + zice0 = MYMAX(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); //------------------ // new value of ice: //------------------ - zinew = pow(((double) 0.666*zcvds*ptsphy + (pow(zice0, (double) 0.666))), - (double) 1.5); + zinew = MYPOW(((dtype) 0.666*zcvds*ptsphy + (MYPOW(zice0, (dtype) 0.666))), + (dtype) 1.5); //--------------------------- // grid-mean deposition rate: //--------------------------- - zdepos = fmax(za[jk]*(zinew - zice0), (double) 0.0); + zdepos = MYMAX(za[jk]*(zinew - zice0), (dtype) 0.0); //-------------------------------------------------------------------- // Limit deposition to liquid water amount @@ -1392,7 +1392,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // flux from the clear sky to the cloudy area. We thus rely on the // supersaturation check to clean up any remaining supersaturation //-------------------------------------------------------------------- - zdepos = fmin(zdepos, zqxfg[0]); // limit to liquid water amount + zdepos = MYMIN(zdepos, zqxfg[0]); // limit to liquid water amount //-------------------------------------------------------------------- // At top of cloud, reduce deposition rate near cloud top to account for @@ -1401,9 +1401,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // ZDEPOS = ZDEPOS*MIN(RDEPLIQREFRATE+ZCLDTOPDIST(JL)/RDEPLIQREFDEPTH,1.0_JPRB) // Change to include dependence on ice nuclei concentration // to increase deposition rate with decreasing temperatures - zinfactor = fmin(zicenuclei / (double) 15000., (double) 1.0); - zdepos = zdepos*fmin(zinfactor + ((double) 1.0 - zinfactor)*((*yrecldp) - .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (double) 1.0); + zinfactor = MYMIN(zicenuclei / (dtype) 15000., (dtype) 1.0); + zdepos = zdepos*MYMIN(zinfactor + ((dtype) 1.0 - zinfactor)*((*yrecldp) + .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (dtype) 1.0); //-------------- // add to matrix @@ -1430,7 +1430,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------------- if (za[-1 + jk] < (*yrecldp).rcldtopcf && za[jk] >= (*yrecldp).rcldtopcf) { - zcldtopdist = (double) 0.0; + zcldtopdist = (dtype) 0.0; } else { zcldtopdist = zcldtopdist + zdp / (zrho*rg); } @@ -1443,38 +1443,38 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk] < rtt && zqxfg[0] > (*yrecldp).rlmin) { // T<273K - zvpice = ((double)(r2es*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))*rv / rd; + zvpice = ((dtype)(r2es*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))*rv / rd; zvpliq = zvpice*zfokoop; - zicenuclei = (double) 1000.0*exp((double) 12.96*(zvpliq - zvpice) / zvpliq - - (double) 0.639); + zicenuclei = (dtype) 1000.0*MYEXP((dtype) 12.96*(zvpliq - zvpice) / zvpliq - + (dtype) 0.639); //----------------------------------------------------- // RICEINIT=1.E-12_JPRB is initial mass of ice particle //----------------------------------------------------- - zice0 = fmax(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); + zice0 = MYMAX(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); // Particle size distribution - ztcg = (double) 1.0; - zfacx1i = (double) 1.0; + ztcg = (dtype) 1.0; + zfacx1i = (dtype) 1.0; zaplusb = (*yrecldp).rcl_apb1*zvpice - (*yrecldp).rcl_apb2*zvpice*ztp1[jk] + - pap[jl + klon*(jk + klev*(ibl))]*(*yrecldp).rcl_apb3*(pow(ztp1[jk], - (double) 3.)); - zcorrfac = pow(((double) 1.0 / zrho), (double) 0.5); - zcorrfac2 = (pow((ztp1[jk] / (double) 273.0), (double) 1.5))*((double) 393.0 / - (ztp1[jk] + (double) 120.0)); + pap[jl + klon*(jk + klev*(ibl))]*(*yrecldp).rcl_apb3*(MYPOW(ztp1[jk], + (dtype) 3.)); + zcorrfac = MYPOW(((dtype) 1.0 / zrho), (dtype) 0.5); + zcorrfac2 = (MYPOW((ztp1[jk] / (dtype) 273.0), (dtype) 1.5))*((dtype) 393.0 / + (ztp1[jk] + (dtype) 120.0)); zpr02 = zrho*zice0*(*yrecldp).rcl_const1i / (ztcg*zfacx1i); - zterm1 = (zvpliq - zvpice)*(pow(ztp1[jk], (double) 2.0)) + zterm1 = (zvpliq - zvpice)*(MYPOW(ztp1[jk], (dtype) 2.0)) *zvpice*zcorrfac2*ztcg*(*yrecldp).rcl_const2i*zfacx1i / (zrho*zaplusb*zvpice) ; - zterm2 = (double) 0.65*(*yrecldp).rcl_const6i*(pow(zpr02, (*yrecldp) - .rcl_const4i)) + (*yrecldp).rcl_const3i*(pow(zcorrfac, (double) 0.5)) - *(pow(zrho, (double) 0.5))*(pow(zpr02, (*yrecldp).rcl_const5i)) / - (pow(zcorrfac2, (double) 0.5)); + zterm2 = (dtype) 0.65*(*yrecldp).rcl_const6i*(MYPOW(zpr02, (*yrecldp) + .rcl_const4i)) + (*yrecldp).rcl_const3i*(MYPOW(zcorrfac, (dtype) 0.5)) + *(MYPOW(zrho, (dtype) 0.5))*(MYPOW(zpr02, (*yrecldp).rcl_const5i)) / + (MYPOW(zcorrfac2, (dtype) 0.5)); - zdepos = fmax(za[jk]*zterm1*zterm2*ptsphy, (double) 0.0); + zdepos = MYMAX(za[jk]*zterm1*zterm2*ptsphy, (dtype) 0.0); //-------------------------------------------------------------------- // Limit deposition to liquid water amount @@ -1485,7 +1485,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // flux from the clear sky to the cloudy area. We thus rely on the // supersaturation check to clean up any remaining supersaturation //-------------------------------------------------------------------- - zdepos = fmin(zdepos, zqxfg[0]); // limit to liquid water amount + zdepos = MYMIN(zdepos, zqxfg[0]); // limit to liquid water amount //-------------------------------------------------------------------- // At top of cloud, reduce deposition rate near cloud top to account for @@ -1493,9 +1493,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------------------- // Change to include dependence on ice nuclei concentration // to increase deposition rate with decreasing temperatures - zinfactor = fmin(zicenuclei / (double) 15000., (double) 1.0); - zdepos = zdepos*fmin(zinfactor + ((double) 1.0 - zinfactor)*((*yrecldp) - .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (double) 1.0); + zinfactor = MYMIN(zicenuclei / (dtype) 15000., (dtype) 1.0); + zdepos = zdepos*MYMIN(zinfactor + ((dtype) 1.0 - zinfactor)*((*yrecldp) + .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (dtype) 1.0); //-------------- // add to matrix @@ -1516,7 +1516,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------- // revise in-cloud consensate amount //---------------------------------- - ztmpa = (double) 1.0 / fmax(za[jk], zepsec); + ztmpa = (dtype) 1.0 / MYMAX(za[jk], zepsec); zliqcld = zqxfg[0]*ztmpa; zicecld = zqxfg[1]*ztmpa; zlicld = zliqcld + zicecld; @@ -1549,7 +1549,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zre_ice = pre_ice[jl + klon*(jk + klev*(ibl))]; // The exponent value is from // Morrison et al. JAS 2005 Appendix - zvqx[1] = (double) 0.002*(pow(zre_ice, (double) 1.0)); + zvqx[1] = (dtype) 0.002*(MYPOW(zre_ice, (dtype) 1.0)); } zfall = zvqx[jm]*zrho; //------------------------------------------------- @@ -1583,20 +1583,20 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // zero. //--------------------------------------------------------------- if (zqpretot > zepsec) { - zcovptot = (double) 1.0 - (((double) 1.0 - zcovptot)*((double) 1.0 - fmax(za[jk], - za[-1 + jk])) / ((double) 1.0 - fmin(za[-1 + jk], (double) 1.0 - (double) + zcovptot = (dtype) 1.0 - (((dtype) 1.0 - zcovptot)*((dtype) 1.0 - MYMAX(za[jk], + za[-1 + jk])) / ((dtype) 1.0 - MYMIN(za[-1 + jk], (dtype) 1.0 - (dtype) 1.E-06))); - zcovptot = fmax(zcovptot, (*yrecldp).rcovpmin); - zcovpclr = fmax((double) 0.0, zcovptot - za[jk]); // clear sky proportion + zcovptot = MYMAX(zcovptot, (*yrecldp).rcovpmin); + zcovpclr = MYMAX((dtype) 0.0, zcovptot - za[jk]); // clear sky proportion zraincld = zqxfg[2] / zcovptot; zsnowcld = zqxfg[3] / zcovptot; - zcovpmax = fmax(zcovptot, zcovpmax); + zcovpmax = MYMAX(zcovptot, zcovpmax); } else { - zraincld = (double) 0.0; - zsnowcld = (double) 0.0; - zcovptot = (double) 0.0; // no flux - reset cover - zcovpclr = (double) 0.0; // reset clear sky proportion - zcovpmax = (double) 0.0; // reset max cover for ZZRH calc + zraincld = (dtype) 0.0; + zsnowcld = (dtype) 0.0; + zcovptot = (dtype) 0.0; // no flux - reset cover + zcovpclr = (dtype) 0.0; // reset clear sky proportion + zcovpmax = (dtype) 0.0; // reset max cover for ZZRH calc } //---------------------------------------------------------------------- @@ -1609,18 +1609,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------------- if (zicecld > zepsec) { - zzco = ptsphy*(*yrecldp).rsnowlin1*exp((*yrecldp).rsnowlin2*(ztp1[jk] - rtt)); + zzco = ptsphy*(*yrecldp).rsnowlin1*MYEXP((*yrecldp).rsnowlin2*(ztp1[jk] - rtt)); if ((*yrecldp).laericeauto) { zlcrit = picrit_aer[jl + klon*(jk + klev*(ibl))]; // 0.3 = N**0.333 with N=0.027 - zzco = zzco*(pow(((*yrecldp).rnice / pnice[jl + klon*(jk + klev*( - ibl))]), (double) 0.333)); + zzco = zzco*(MYPOW(((*yrecldp).rnice / pnice[jl + klon*(jk + klev*( + ibl))]), (dtype) 0.333)); } else { zlcrit = (*yrecldp).rlcritsnow; } - zsnowaut = zzco*((double) 1.0 - exp(-(pow((zicecld / zlcrit), 2)))); + zsnowaut = zzco*((dtype) 1.0 - MYEXP(-(MYPOW((zicecld / zlcrit), 2)))); zsolqb[3 + 5*(1)] = zsolqb[3 + 5*(1)] + zsnowaut; } @@ -1646,13 +1646,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if ((*yrecldp).laerliqautolsp) { zlcrit = plcrit_aer[jl + klon*(jk + klev*(ibl))]; // 0.3 = N**0.333 with N=125 cm-3 - zzco = zzco*(pow(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*(ibl) - )]), (double) 0.333)); + zzco = zzco*(MYPOW(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*(ibl) + )]), (dtype) 0.333)); } else { // Modify autoconversion threshold dependent on: // land (polluted, high CCN, smaller droplets, higher threshold) // sea (clean, low CCN, larger droplets, lower threshold) - if (plsm[jl + klon*(ibl)] > (double) 0.5) { + if (plsm[jl + klon*(ibl)] > (dtype) 0.5) { zlcrit = (*yrecldp).rclcrit_land; // land } else { zlcrit = (*yrecldp).rclcrit_sea; // ocean @@ -1665,23 +1665,23 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to REPLACE this with an explicit collection parametrization //------------------------------------------------------------------ zprecip = (zpfplsx[jk + (klev + 1)*(3)] + zpfplsx[jk + (klev + 1)*(2) - ]) / fmax(zepsec, zcovptot); - zcfpr = (double) 1.0 + (*yrecldp).rprc1*sqrt(fmax(zprecip, (double) 0.0)); + ]) / MYMAX(zepsec, zcovptot); + zcfpr = (dtype) 1.0 + (*yrecldp).rprc1*sqrt(MYMAX(zprecip, (dtype) 0.0)); // ZCFPR=1.0_JPRB + RPRC1*SQRT(MAX(ZPRECIP,0.0_JPRB))*& // &ZCOVPTOT(JL)/(MAX(ZA(JL,JK),ZEPSEC)) if ((*yrecldp).laerliqcoll) { // 5.0 = N**0.333 with N=125 cm-3 - zcfpr = zcfpr*(pow(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*( - ibl))]), (double) 0.333)); + zcfpr = zcfpr*(MYPOW(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*( + ibl))]), (dtype) 0.333)); } zzco = zzco*zcfpr; - zlcrit = zlcrit / fmax(zcfpr, zepsec); + zlcrit = zlcrit / MYMAX(zcfpr, zepsec); - if (zliqcld / zlcrit < (double) 20.0) { + if (zliqcld / zlcrit < (dtype) 20.0) { // Security for exp for some compilers - zrainaut = zzco*((double) 1.0 - exp(-(pow((zliqcld / zlcrit), 2)))); + zrainaut = zzco*((dtype) 1.0 - MYEXP(-(MYPOW((zliqcld / zlcrit), 2)))); } else { zrainaut = zzco; } @@ -1700,7 +1700,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------- } else if (iwarmrain == 2) { - if (plsm[jl + klon*(ibl)] > (double) 0.5) { + if (plsm[jl + klon*(ibl)] > (dtype) 0.5) { // land zconst = (*yrecldp).rcl_kk_cloud_num_land; zlcrit = (*yrecldp).rclcrit_land; @@ -1712,25 +1712,25 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zliqcld > zlcrit) { - zrainaut = (double) 1.5*za[jk]*ptsphy*(*yrecldp).rcl_kkaau*(pow(zliqcld, - (*yrecldp).rcl_kkbauq))*(pow(zconst, (*yrecldp).rcl_kkbaun)); + zrainaut = (dtype) 1.5*za[jk]*ptsphy*(*yrecldp).rcl_kkaau*(MYPOW(zliqcld, + (*yrecldp).rcl_kkbauq))*(MYPOW(zconst, (*yrecldp).rcl_kkbaun)); - zrainaut = fmin(zrainaut, zqxfg[0]); + zrainaut = MYMIN(zrainaut, zqxfg[0]); if (zrainaut < zepsec) { - zrainaut = (double) 0.0; + zrainaut = (dtype) 0.0; } - zrainacc = (double) 2.0*za[jk]*ptsphy*(*yrecldp) - .rcl_kkaac*(pow((zliqcld*zraincld), (*yrecldp).rcl_kkbac)); + zrainacc = (dtype) 2.0*za[jk]*ptsphy*(*yrecldp) + .rcl_kkaac*(MYPOW((zliqcld*zraincld), (*yrecldp).rcl_kkbac)); - zrainacc = fmin(zrainacc, zqxfg[0]); + zrainacc = MYMIN(zrainacc, zqxfg[0]); if (zrainacc < zepsec) { - zrainacc = (double) 0.0; + zrainacc = (dtype) 0.0; } } else { - zrainaut = (double) 0.0; - zrainacc = (double) 0.0; + zrainaut = (dtype) 0.0; + zrainacc = (dtype) 0.0; } // If temperature < 0, then autoconversion produces snow rather than rain @@ -1764,21 +1764,21 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk] <= rtt && zliqcld > zepsec) { // Fallspeed air density correction - zfallcorr = pow(((*yrecldp).rdensref / zrho), (double) 0.4); + zfallcorr = MYPOW(((*yrecldp).rdensref / zrho), (dtype) 0.4); //------------------------------------------------------------------ // Riming of snow by cloud water - implicit in lwc //------------------------------------------------------------------ - if (zsnowcld > zepsec && zcovptot > (double) 0.01) { + if (zsnowcld > zepsec && zcovptot > (dtype) 0.01) { // Calculate riming term // Factor of liq water taken out because implicit - zsnowrime = (double) 0.3*zcovptot*ptsphy*(*yrecldp) - .rcl_const7s*zfallcorr*(pow((zrho*zsnowcld*(*yrecldp).rcl_const1s), + zsnowrime = (dtype) 0.3*zcovptot*ptsphy*(*yrecldp) + .rcl_const7s*zfallcorr*(MYPOW((zrho*zsnowcld*(*yrecldp).rcl_const1s), (*yrecldp).rcl_const8s)); // Limit snow riming term - zsnowrime = fmin(zsnowrime, (double) 1.0); + zsnowrime = MYMIN(zsnowrime, (dtype) 1.0); zsolqb[3 + 5*(0)] = zsolqb[3 + 5*(0)] + zsnowrime; @@ -1816,13 +1816,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------------------------------------------- zicetot = zqxfg[1] + zqxfg[3]; - zmeltmax = (double) 0.0; + zmeltmax = (dtype) 0.0; // If there are frozen hydrometeors present and dry-bulb temperature > 0degC if (zicetot > zepsec && ztp1[jk] > rtt) { // Calculate subsaturation - zsubsat = fmax(zqsice[jk] - zqx[jk + klev*(4)], (double) 0.0); + zsubsat = MYMAX(zqsice[jk] - zqx[jk + klev*(4)], (dtype) 0.0); // Calculate difference between dry-bulb (ZTP1) and the temperature // at which the wet-bulb=0degC (RTT-ZSUBSAT*....) using an approx. @@ -1833,8 +1833,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, klev*(ibl))] - ztw3) - ztw4*(ztp1[jk] - ztw5)); // Not implicit yet... // Ensure ZCONS1 is positive so that ZMELTMAX=0 if ZTDMTW0<0 - zcons1 = fabs(ptsphy*((double) 1.0 + (double) 0.5*ztdmtw0) / (*yrecldp).rtaumel); - zmeltmax = fmax(ztdmtw0*zcons1*zrldcp, (double) 0.0); + zcons1 = MYABS(ptsphy*((dtype) 1.0 + (dtype) 0.5*ztdmtw0) / (*yrecldp).rtaumel); + zmeltmax = MYMAX(ztdmtw0*zcons1*zrldcp, (dtype) 0.0); } // Loop over frozen hydrometeors (ice, snow) @@ -1844,7 +1844,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zmeltmax > zepsec && zicetot > zepsec) { // Apply melting in same proportion as frozen hydrometeor fractions zalfa = zqxfg[jm] / zicetot; - zmelt = fmin(zqxfg[jm], zalfa*zmeltmax); + zmelt = MYMIN(zqxfg[jm], zalfa*zmeltmax); // needed in first guess // This implies that zqpretot has to be recalculated below // since is not conserved here if ice falls and liquid doesn't @@ -1868,7 +1868,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // store rain/snow fraction for precip type diagnosis // If mostly rain, then supercooled rain slow to freeze // otherwise faster to freeze (snow or ice pellets) - zqpretot = fmax(zqx[jk + klev*(3)] + zqx[jk + klev*(2)], zepsec); + zqpretot = MYMAX(zqx[jk + klev*(3)] + zqx[jk + klev*(2)], zepsec); prainfrac_toprfz[jl + klon*(ibl)] = zqx[jk + klev*(2)] / zqpretot; if (prainfrac_toprfz[jl + klon*(ibl)] > 0.8) { @@ -1887,28 +1887,28 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Refreezing is by slow heterogeneous freezing // Slope of rain particle size distribution - zlambda = pow(((*yrecldp).rcl_fac1 / (zrho*zqx[jk + klev*(2)])), + zlambda = MYPOW(((*yrecldp).rcl_fac1 / (zrho*zqx[jk + klev*(2)])), (*yrecldp).rcl_fac2); // Calculate freezing rate based on Bigg(1953) and Wisner(1972) ztemp = (*yrecldp).rcl_fzrab*(ztp1[jk] - rtt); - zfrz = ptsphy*((*yrecldp).rcl_const5r / zrho)*(exp(ztemp) - (double) 1.) - *(pow(zlambda, (*yrecldp).rcl_const6r)); - zfrzmax = fmax(zfrz, (double) 0.0); + zfrz = ptsphy*((*yrecldp).rcl_const5r / zrho)*(MYEXP(ztemp) - (dtype) 1.) + *(MYPOW(zlambda, (*yrecldp).rcl_const6r)); + zfrzmax = MYMAX(zfrz, (dtype) 0.0); } else { // Majority of raindrops only partially melted // Refreeze with a shorter timescale (reverse of melting...for now) - zcons1 = fabs(ptsphy*((double) 1.0 + (double) 0.5*(rtt - ztp1[jk])) / + zcons1 = MYABS(ptsphy*((dtype) 1.0 + (dtype) 0.5*(rtt - ztp1[jk])) / (*yrecldp).rtaumel); - zfrzmax = fmax((rtt - ztp1[jk])*zcons1*zrldcp, (double) 0.0); + zfrzmax = MYMAX((rtt - ztp1[jk])*zcons1*zrldcp, (dtype) 0.0); } if (zfrzmax > zepsec) { - zfrz = fmin(zqx[jk + klev*(2)], zfrzmax); + zfrz = MYMIN(zqx[jk + klev*(2)], zfrzmax); zsolqa[3 + 5*(2)] = zsolqa[3 + 5*(2)] + zfrz; zsolqa[2 + 5*(3)] = zsolqa[2 + 5*(3)] - zfrz; } @@ -1921,12 +1921,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 4.4c FREEZING of LIQUID //---------------------------------------------------------------------- // not implicit yet... - zfrzmax = fmax(((*yrecldp).rthomo - ztp1[jk])*zrldcp, (double) 0.0); + zfrzmax = MYMAX(((*yrecldp).rthomo - ztp1[jk])*zrldcp, (dtype) 0.0); jm = 1; jn = imelt[-1 + jm]; if (zfrzmax > zepsec && zqxfg[-1 + jm] > zepsec) { - zfrz = fmin(zqxfg[-1 + jm], zfrzmax); + zfrz = MYMIN(zqxfg[-1 + jm], zfrzmax); zsolqa[-1 + jn + 5*(-1 + jm)] = zsolqa[-1 + jn + 5*(-1 + jm)] + zfrz; zsolqa[-1 + jm + 5*(-1 + jn)] = zsolqa[-1 + jm + 5*(-1 + jn)] - zfrz; } @@ -1943,21 +1943,21 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Rain - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jk]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jk]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); - zqe = (zqx[jk + klev*(4)] - za[jk]*zqsliq[jk]) / fmax(zepsec, (double) 1.0 - + zqe = (zqx[jk + klev*(4)] - za[jk]*zqsliq[jk]) / MYMAX(zepsec, (dtype) 1.0 - za[jk]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsliq[jk])); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsliq[jk])); llo1 = zcovpclr > zepsec && zqxfg[2] > zepsec && zqe < zzrh*zqsliq[jk]; if (llo1) { // note: zpreclr is a rain flux - zpreclr = zqxfg[2]*zcovpclr / copysign(fmax(fabs(zcovptot*zdtgdp), + zpreclr = zqxfg[2]*zcovpclr / copysign(MYMAX(MYABS(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); //-------------------------------------- @@ -1966,11 +1966,11 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zbeta1 = sqrt(pap[jl + klon*(jk + klev*(ibl))] / paph[jl + klon*(klev + (klev + 1)*(ibl))]) / (*yrecldp).rvrfactor*zpreclr / - fmax(zcovpclr, zepsec); + MYMAX(zcovpclr, zepsec); - zbeta = rg*(*yrecldp).rpecons*(double) 0.5*(pow(zbeta1, (double) 0.5777)); + zbeta = rg*(*yrecldp).rpecons*(dtype) 0.5*(MYPOW(zbeta1, (dtype) 0.5777)); - zdenom = (double) 1.0 + zbeta*ptsphy*zcorqsliq; + zdenom = (dtype) 1.0 + zbeta*ptsphy*zcorqsliq; zdpr = zcovpclr*zbeta*(zqsliq[jk] - zqe) / zdenom*zdp*zrg_r; zdpevap = zdpr*zdtgdp; @@ -1982,7 +1982,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Evaporate rain - zevap = fmin(zdpevap, zqxfg[2]); + zevap = MYMIN(zdpevap, zqxfg[2]); zsolqa[4 + 5*(2)] = zsolqa[4 + 5*(2)] + zevap; zsolqa[2 + 5*(4)] = zsolqa[2 + 5*(4)] - zevap; @@ -1992,7 +1992,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, (zcovptot - + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk])*zevap / zqxfg[2])); // Update fg field @@ -2012,9 +2012,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to avoid cloud formation and saturation of the grid box //----------------------------------------------------------------------- // Limit RH for rain evaporation dependent on precipitation fraction - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jk]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jk]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); // Critical relative humidity //ZRHC=RAMID @@ -2026,9 +2026,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //ZZRH = MIN(ZRHC,ZZRH) // Further limit RH for rain evaporation to 80% (RHcrit in free troposphere) - zzrh = fmin((double) 0.8, zzrh); + zzrh = MYMIN((dtype) 0.8, zzrh); - zqe = fmax((double) 0.0, fmin(zqx[jk + klev*(4)], zqsliq[jk])); + zqe = MYMAX((dtype) 0.0, MYMIN(zqx[jk + klev*(4)], zqsliq[jk])); llo1 = zcovpclr > zepsec && zqxfg[2] > zepsec && zqe < zzrh*zqsliq[jk]; @@ -2041,32 +2041,32 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zpreclr = zqxfg[2] / zcovptot; // Fallspeed air density correction - zfallcorr = pow(((*yrecldp).rdensref / zrho), 0.4); + zfallcorr = MYPOW(((*yrecldp).rdensref / zrho), 0.4); // Saturation vapour pressure with respect to liquid phase - zesatliq = rv / rd*((double)(r2es*exp((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))); + zesatliq = rv / rd*((dtype)(r2es*MYEXP((r3les*(ztp1[jk] - rtt))/(ztp1[jk] - r4les)))); // Slope of particle size distribution - zlambda = pow(((*yrecldp).rcl_fac1 / (zrho*zpreclr)), (*yrecldp).rcl_fac2); // ZPRECLR=kg/kg + zlambda = MYPOW(((*yrecldp).rcl_fac1 / (zrho*zpreclr)), (*yrecldp).rcl_fac2); // ZPRECLR=kg/kg zevap_denom = (*yrecldp).rcl_cdenom1*zesatliq - (*yrecldp) - .rcl_cdenom2*ztp1[jk]*zesatliq + (*yrecldp).rcl_cdenom3*(pow(ztp1[jk], - (double) 3.))*pap[jl + klon*(jk + klev*(ibl))]; + .rcl_cdenom2*ztp1[jk]*zesatliq + (*yrecldp).rcl_cdenom3*(MYPOW(ztp1[jk], + (dtype) 3.))*pap[jl + klon*(jk + klev*(ibl))]; // Temperature dependent conductivity - zcorr2 = (pow((ztp1[jk] / (double) 273.), (double) 1.5))*(double) 393. / - (ztp1[jk] + (double) 120.); + zcorr2 = (MYPOW((ztp1[jk] / (dtype) 273.), (dtype) 1.5))*(dtype) 393. / + (ztp1[jk] + (dtype) 120.); zka = (*yrecldp).rcl_ka273*zcorr2; - zsubsat = fmax(zzrh*zqsliq[jk] - zqe, (double) 0.0); + zsubsat = MYMAX(zzrh*zqsliq[jk] - zqe, (dtype) 0.0); - zbeta = ((double) 0.5 / zqsliq[jk])*(pow(ztp1[jk], (double) 2.)) - *zesatliq*(*yrecldp).rcl_const1r*(zcorr2 / zevap_denom)*((double) 0.78 / - (pow(zlambda, (*yrecldp).rcl_const4r)) + (*yrecldp) - .rcl_const2r*(pow((zrho*zfallcorr), (double) 0.5)) / ((pow(zcorr2, (double) - 0.5))*(pow(zlambda, (*yrecldp).rcl_const3r)))); + zbeta = ((dtype) 0.5 / zqsliq[jk])*(MYPOW(ztp1[jk], (dtype) 2.)) + *zesatliq*(*yrecldp).rcl_const1r*(zcorr2 / zevap_denom)*((dtype) 0.78 / + (MYPOW(zlambda, (*yrecldp).rcl_const4r)) + (*yrecldp) + .rcl_const2r*(MYPOW((zrho*zfallcorr), (dtype) 0.5)) / ((MYPOW(zcorr2, (dtype) + 0.5))*(MYPOW(zlambda, (*yrecldp).rcl_const3r)))); - zdenom = (double) 1.0 + zbeta*ptsphy; //*ZCORQSLIQ(JL) + zdenom = (dtype) 1.0 + zbeta*ptsphy; //*ZCORQSLIQ(JL) zdpevap = zcovpclr*zbeta*ptsphy*zsubsat / zdenom; //--------------------------------------------------------- @@ -2077,7 +2077,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Limit rain evaporation - zevap = fmin(zdpevap, zqxfg[2]); + zevap = MYMIN(zdpevap, zqxfg[2]); zsolqa[4 + 5*(2)] = zsolqa[4 + 5*(2)] + zevap; zsolqa[2 + 5*(4)] = zsolqa[2 + 5*(4)] - zevap; @@ -2087,7 +2087,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, (zcovptot - + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk])*zevap / zqxfg[2])); // Update fg field @@ -2104,21 +2104,21 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Snow if (ievapsnow == 1) { - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jk]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); - zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / fmax(zepsec, (double) 1.0 - + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jk]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); + zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / MYMAX(zepsec, (dtype) 1.0 - za[jk]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsice[jk])); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsice[jk])); llo1 = zcovpclr > zepsec && zqxfg[3] > zepsec && zqe < zzrh*zqsice[jk]; if (llo1) { // note: zpreclr is a rain flux a - zpreclr = zqxfg[3]*zcovpclr / copysign(fmax(fabs(zcovptot*zdtgdp), + zpreclr = zqxfg[3]*zcovpclr / copysign(MYMAX(MYABS(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); //-------------------------------------- @@ -2127,11 +2127,11 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zbeta1 = sqrt(pap[jl + klon*(jk + klev*(ibl))] / paph[jl + klon*(klev + (klev + 1)*(ibl))]) / (*yrecldp).rvrfactor*zpreclr / - fmax(zcovpclr, zepsec); + MYMAX(zcovpclr, zepsec); - zbeta = rg*(*yrecldp).rpecons*(pow(zbeta1, (double) 0.5777)); + zbeta = rg*(*yrecldp).rpecons*(MYPOW(zbeta1, (dtype) 0.5777)); - zdenom = (double) 1.0 + zbeta*ptsphy*zcorqsice; + zdenom = (dtype) 1.0 + zbeta*ptsphy*zcorqsice; zdpr = zcovpclr*zbeta*(zqsice[jk] - zqe) / zdenom*zdp*zrg_r; zdpevap = zdpr*zdtgdp; @@ -2143,7 +2143,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Evaporate snow - zevap = fmin(zdpevap, zqxfg[3]); + zevap = MYMIN(zdpevap, zqxfg[3]); zsolqa[4 + 5*(3)] = zsolqa[4 + 5*(3)] + zevap; zsolqa[3 + 5*(4)] = zsolqa[3 + 5*(4)] - zevap; @@ -2153,7 +2153,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, (zcovptot - + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk])*zevap / zqxfg[3])); //Update first guess field @@ -2168,16 +2168,16 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------------------------------- // Calculate relative humidity limit for snow evaporation //----------------------------------------------------------------------- - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jk]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); - zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / fmax(zepsec, (double) 1.0 - + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jk]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); + zqe = (zqx[jk + klev*(4)] - za[jk]*zqsice[jk]) / MYMAX(zepsec, (dtype) 1.0 - za[jk]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsice[jk])); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsice[jk])); llo1 = zcovpclr > zepsec && zqx[jk + klev*(3)] > zepsec && zqe < zzrh*zqsice[jk]; @@ -2185,36 +2185,36 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Calculate local precipitation (kg/kg) zpreclr = zqx[jk + klev*(3)] / zcovptot; - zvpice = ((double)(r2es*exp((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))*rv / rd; + zvpice = ((dtype)(r2es*MYEXP((r3ies*(ztp1[jk] - rtt))/(ztp1[jk] - r4ies))))*rv / rd; // Particle size distribution // ZTCG increases Ni with colder temperatures - essentially a // Fletcher or Meyers scheme? - ztcg = (double) 1.0; //v1 EXP(RCL_X3I*(273.15_JPRB-ZTP1(JL,JK))/8.18_JPRB) + ztcg = (dtype) 1.0; //v1 EXP(RCL_X3I*(273.15_JPRB-ZTP1(JL,JK))/8.18_JPRB) // ZFACX1I modification is based on Andrew Barrett's results - zfacx1s = (double) 1.0; //v1 (ZICE0/1.E-5_JPRB)**0.627_JPRB + zfacx1s = (dtype) 1.0; //v1 (ZICE0/1.E-5_JPRB)**0.627_JPRB zaplusb = (*yrecldp).rcl_apb1*zvpice - (*yrecldp).rcl_apb2*zvpice*ztp1[jk] + - pap[jl + klon*(jk + klev*(ibl))]*(*yrecldp).rcl_apb3*(pow(ztp1[jk], + pap[jl + klon*(jk + klev*(ibl))]*(*yrecldp).rcl_apb3*(MYPOW(ztp1[jk], 3)); - zcorrfac = pow((1.0 / zrho), 0.5); - zcorrfac2 = (pow((ztp1[jk] / 273.0), 1.5))*(393.0 / (ztp1[jk] + 120.0)); + zcorrfac = MYPOW((1.0 / zrho), 0.5); + zcorrfac2 = (MYPOW((ztp1[jk] / 273.0), 1.5))*(393.0 / (ztp1[jk] + 120.0)); zpr02 = zrho*zpreclr*(*yrecldp).rcl_const1s / (ztcg*zfacx1s); - zterm1 = (zqsice[jk] - zqe)*(pow(ztp1[jk], 2))*zvpice*zcorrfac2*ztcg*(*yrecldp) + zterm1 = (zqsice[jk] - zqe)*(MYPOW(ztp1[jk], 2))*zvpice*zcorrfac2*ztcg*(*yrecldp) .rcl_const2s*zfacx1s / (zrho*zaplusb*zqsice[jk]); - zterm2 = 0.65*(*yrecldp).rcl_const6s*(pow(zpr02, (*yrecldp).rcl_const4s)) + - (*yrecldp).rcl_const3s*(pow(zcorrfac, 0.5))*(pow(zrho, 0.5))*(pow(zpr02, - (*yrecldp).rcl_const5s)) / (pow(zcorrfac2, 0.5)); + zterm2 = 0.65*(*yrecldp).rcl_const6s*(MYPOW(zpr02, (*yrecldp).rcl_const4s)) + + (*yrecldp).rcl_const3s*(MYPOW(zcorrfac, 0.5))*(MYPOW(zrho, 0.5))*(MYPOW(zpr02, + (*yrecldp).rcl_const5s)) / (MYPOW(zcorrfac2, 0.5)); - zdpevap = fmax(zcovpclr*zterm1*zterm2*ptsphy, (double) 0.0); + zdpevap = MYMAX(zcovpclr*zterm1*zterm2*ptsphy, (dtype) 0.0); //-------------------------------------------------------------------- // Limit evaporation to snow amount //-------------------------------------------------------------------- - zevap = fmin(zdpevap, zevaplimice); - zevap = fmin(zevap, zqx[jk + klev*(3)]); + zevap = MYMIN(zdpevap, zevaplimice); + zevap = MYMIN(zevap, zqx[jk + klev*(3)]); zsolqa[4 + 5*(3)] = zsolqa[4 + 5*(3)] + zevap; @@ -2225,7 +2225,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, (zcovptot - + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk])*zevap / zqx[jk + klev*(3)])); //Update first guess field @@ -2257,10 +2257,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- // 5.1 solver for cloud cover //--------------------------- - zanew = (za[jk] + zsolac) / ((double) 1.0 + zsolab); - zanew = fmin(zanew, (double) 1.0); + zanew = (za[jk] + zsolac) / ((dtype) 1.0 + zsolab); + zanew = MYMIN(zanew, (dtype) 1.0); if (zanew < (*yrecldp).ramin) { - zanew = (double) 0.0; + zanew = (dtype) 0.0; } zda = zanew - zaorig[jk]; //--------------------------------- @@ -2282,7 +2282,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jn = 0; jn <= 5 + -1; jn += 1) { llindex3[jn + 5*jm] = false; } - zsinksum[jm] = (double) 0.0; + zsinksum[jm] = (dtype) 0.0; } //---------------------------- @@ -2298,8 +2298,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // calculate overshoot and scaling factor //--------------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zmax = fmax(zqx[jk + klev*jm], zepsec); - zrat = fmax(zsinksum[jm], zmax); + zmax = MYMAX(zqx[jk + klev*jm], zepsec); + zrat = MYMAX(zsinksum[jm], zmax); zratio[jm] = zmax / zrat; } @@ -2308,7 +2308,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // recalculating the scale factor each time //-------------------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zsinksum[jm] = (double) 0.0; + zsinksum[jm] = (dtype) 0.0; } //---------------- @@ -2324,8 +2324,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- // recalculate scaling factor //--------------------------- - zmm = fmax(zqx[jk + klev*jm], zepsec); - zrr = fmax(zsinksum[jm], zmm); + zmm = MYMAX(zqx[jk + klev*jm], zepsec); + zrr = MYMAX(zsinksum[jm], zmm); zratio[jm] = zmm / zrr; //------ // scale @@ -2334,7 +2334,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //DIR$ IVDEP //DIR$ PREFERVECTOR for (jn = 0; jn <= 5 + -1; jn += 1) { - if (zsolqa[jm + 5*jn] < (double) 0.0) { + if (zsolqa[jm + 5*jn] < (dtype) 0.0) { zsolqa[jm + 5*jn] = zsolqa[jm + 5*jn]*zzratio; zsolqa[jn + 5*jm] = zsolqa[jn + 5*jm]*zzratio; } @@ -2354,7 +2354,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // diagonals: microphysical sink terms+transport //---------------------------------------------- if (jn + 1 == jm + 1) { - zqlhs[jn + 5*jm] = (double) 1.0 + zfallsink[jm]; + zqlhs[jn + 5*jm] = (dtype) 1.0 + zfallsink[jm]; for (jo = 0; jo <= 5 + -1; jo += 1) { zqlhs[jn + 5*jm] = zqlhs[jn + 5*jm] + zsolqb[jo + 5*jn]; } @@ -2374,7 +2374,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------- // sum the explicit source and sink //--------------------------------- - zexplicit = (double) 0.0; + zexplicit = (dtype) 0.0; for (jn = 0; jn <= 5 + -1; jn += 1) { zexplicit = zexplicit + zsolqa[jm + 5*jn]; // sum over middle index } @@ -2427,7 +2427,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jn = 0; jn <= 5 - 1 + -1; jn += 1) { if (zqxn[jn] < zepsec) { zqxn[4] = zqxn[4] + zqxn[jn]; - zqxn[jn] = (double) 0.0; + zqxn[jn] = (dtype) 0.0; } } @@ -2453,7 +2453,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zqpretot = zpfplsx[1 + jk + (klev + 1)*(3)] + zpfplsx[1 + jk + (klev + 1)*(2)]; if (zqpretot < zepsec) { - zcovptot = (double) 0.0; + zcovptot = (dtype) 0.0; } //###################################################################### @@ -2535,17 +2535,17 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------- // Fluxes: //-------- - pfsqlf[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; - pfsqif[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; - pfsqrf[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; - pfsqsf[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; - pfcqlng[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; - pfcqnng[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; - pfcqrng[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; //rain - pfcqsng[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; //snow + pfsqlf[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; + pfsqif[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; + pfsqrf[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; + pfsqsf[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; + pfcqlng[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; + pfcqnng[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; + pfcqrng[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; //rain + pfcqsng[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; //snow // fluxes due to turbulence - pfsqltur[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; - pfsqitur[jl + klon*(0 + (klev + 1)*(ibl))] = (double) 0.0; + pfsqltur[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; + pfsqitur[jl + klon*(0 + (klev + 1)*(ibl))] = (dtype) 0.0; for (jk = 0; jk <= klev + -1; jk += 1) { @@ -2599,7 +2599,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Ice , LS scheme minus detrainment pfsqif[jl + klon*(1 + jk + (klev + 1)*(ibl))] = pfsqif[jl + klon*(1 + jk + (klev + 1)*(ibl))] + (zqxn2d[jk + klev*(1)] - zqx0[jk + klev*(-1 - + 2)] + pvfi[jl + klon*(jk + klev*(ibl))]*ptsphy - ((double) 1.0 - + + 2)] + pvfi[jl + klon*(jk + klev*(ibl))]*ptsphy - ((dtype) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*(ibl))])*zgdph_r; // ice, negative numbers pfcqnng[jl + klon*(1 + jk + (klev + 1)*(ibl))] = pfcqnng[jl + diff --git a/src/cloudsc_hip/cloudsc/cloudsc_c.h b/src/cloudsc_hip/cloudsc/cloudsc_c.h index e4d0364b..2db230ca 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_c.h +++ b/src/cloudsc_hip/cloudsc/cloudsc_c.h @@ -12,33 +12,34 @@ #include "hip/hip_runtime.h" #include "yoecldp_c.h" #include +#include "dtype.h" -__global__ void __launch_bounds__(128, 1) cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, - const double * __restrict__ pt, - const double * __restrict__ pq, const double * __restrict__ tendency_tmp_t, - const double * __restrict__ tendency_tmp_q, const double * __restrict__ tendency_tmp_a, - const double * __restrict__ tendency_tmp_cld, double * __restrict__ tendency_loc_t, - double * __restrict__ tendency_loc_q, double * __restrict__ tendency_loc_a, - double * __restrict__ tendency_loc_cld, const double * __restrict__ pvfa, - const double * __restrict__ pvfl, const double * __restrict__ pvfi, const double * __restrict__ pdyna, - const double * __restrict__ pdynl, const double * __restrict__ pdyni, const double * __restrict__ phrsw, - double * __restrict__ phrlw, const double * __restrict__ pvervel, const double * __restrict__ pap, - const double * __restrict__ paph, const double * __restrict__ plsm, - const int * ktype, const double * __restrict__ plu, double * __restrict__ plude, - const double * __restrict__ psnde, const double * __restrict__ pmfu, const double * __restrict__ pmfd, - const double * __restrict__ pa, const double * __restrict__ pclv, const double * __restrict__ psupsat, - const double * __restrict__ plcrit_aer, const double * __restrict__ picrit_aer, - const double * __restrict__ pre_ice, const double * __restrict__ pccn, const double * __restrict__ pnice, - double * __restrict__ pcovptot, double * __restrict__ prainfrac_toprfz, - double * __restrict__ pfsqlf, double * __restrict__ pfsqif, double * __restrict__ pfcqnng, - double * __restrict__ pfcqlng, double * __restrict__ pfsqrf, double * __restrict__ pfsqsf, - double * __restrict__ pfcqrng, double * __restrict__ pfcqsng, - double * __restrict__ pfsqltur, double * __restrict__ pfsqitur, - double * __restrict__ pfplsl, double * __restrict__ pfplsn, double * __restrict__ pfhpsl, - double * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, - double rg, double rd, double rcpd, double retv, double rlvtt, double rlstt, double rlmlt, double rtt, - double rv, double r2es, double r3les, double r3ies, double r4les, double r4ies, double r5les, - double r5ies, double r5alvcp, double r5alscp, double ralvdcp, double ralsdcp, double ralfdcp, - double rtwat, double rtice, double rticecu, double rtwat_rtice_r, double rtwat_rticecu_r, - double rkoop1, double rkoop2); +__global__ void __launch_bounds__(128, 1) cloudsc_c(int kidia, int kfdia, int klon, dtype ptsphy, + const dtype * __restrict__ pt, + const dtype * __restrict__ pq, const dtype * __restrict__ tendency_tmp_t, + const dtype * __restrict__ tendency_tmp_q, const dtype * __restrict__ tendency_tmp_a, + const dtype * __restrict__ tendency_tmp_cld, dtype * __restrict__ tendency_loc_t, + dtype * __restrict__ tendency_loc_q, dtype * __restrict__ tendency_loc_a, + dtype * __restrict__ tendency_loc_cld, const dtype * __restrict__ pvfa, + const dtype * __restrict__ pvfl, const dtype * __restrict__ pvfi, const dtype * __restrict__ pdyna, + const dtype * __restrict__ pdynl, const dtype * __restrict__ pdyni, const dtype * __restrict__ phrsw, + dtype * __restrict__ phrlw, const dtype * __restrict__ pvervel, const dtype * __restrict__ pap, + const dtype * __restrict__ paph, const dtype * __restrict__ plsm, + const int * ktype, const dtype * __restrict__ plu, dtype * __restrict__ plude, + const dtype * __restrict__ psnde, const dtype * __restrict__ pmfu, const dtype * __restrict__ pmfd, + const dtype * __restrict__ pa, const dtype * __restrict__ pclv, const dtype * __restrict__ psupsat, + const dtype * __restrict__ plcrit_aer, const dtype * __restrict__ picrit_aer, + const dtype * __restrict__ pre_ice, const dtype * __restrict__ pccn, const dtype * __restrict__ pnice, + dtype * __restrict__ pcovptot, dtype * __restrict__ prainfrac_toprfz, + dtype * __restrict__ pfsqlf, dtype * __restrict__ pfsqif, dtype * __restrict__ pfcqnng, + dtype * __restrict__ pfcqlng, dtype * __restrict__ pfsqrf, dtype * __restrict__ pfsqsf, + dtype * __restrict__ pfcqrng, dtype * __restrict__ pfcqsng, + dtype * __restrict__ pfsqltur, dtype * __restrict__ pfsqitur, + dtype * __restrict__ pfplsl, dtype * __restrict__ pfplsn, dtype * __restrict__ pfhpsl, + dtype * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, + dtype rg, dtype rd, dtype rcpd, dtype retv, dtype rlvtt, dtype rlstt, dtype rlmlt, dtype rtt, + dtype rv, dtype r2es, dtype r3les, dtype r3ies, dtype r4les, dtype r4ies, dtype r5les, + dtype r5ies, dtype r5alvcp, dtype r5alscp, dtype ralvdcp, dtype ralsdcp, dtype ralfdcp, + dtype rtwat, dtype rtice, dtype rticecu, dtype rtwat_rtice_r, dtype rtwat_rticecu_r, + dtype rkoop1, dtype rkoop2); diff --git a/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.cpp b/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.cpp index 9506d2c6..d55574c9 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.cpp +++ b/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.cpp @@ -11,40 +11,40 @@ #include "cloudsc_c_hoist.h" #include -__global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, - const double * __restrict__ pt, - const double * __restrict__ pq, const double * __restrict__ tendency_tmp_t, - const double * __restrict__ tendency_tmp_q, const double * __restrict__ tendency_tmp_a, - const double * __restrict__ tendency_tmp_cld, double * __restrict__ tendency_loc_t, - double * __restrict__ tendency_loc_q, double * __restrict__ tendency_loc_a, - double * __restrict__ tendency_loc_cld, const double * __restrict__ pvfa, - const double * __restrict__ pvfl, const double * __restrict__ pvfi, const double * __restrict__ pdyna, - const double * __restrict__ pdynl, const double * __restrict__ pdyni, const double * __restrict__ phrsw, - double * __restrict__ phrlw, const double * __restrict__ pvervel, const double * __restrict__ pap, - const double * __restrict__ paph, const double * __restrict__ plsm, - const int * ktype, const double * __restrict__ plu, double * __restrict__ plude, - const double * __restrict__ psnde, const double * __restrict__ pmfu, const double * __restrict__ pmfd, - const double * __restrict__ pa, const double * __restrict__ pclv, const double * __restrict__ psupsat, - const double * __restrict__ plcrit_aer, const double * __restrict__ picrit_aer, - const double * __restrict__ pre_ice, const double * __restrict__ pccn, const double * __restrict__ pnice, - double * __restrict__ pcovptot, double * __restrict__ prainfrac_toprfz, - double * __restrict__ pfsqlf, double * __restrict__ pfsqif, double * __restrict__ pfcqnng, - double * __restrict__ pfcqlng, double * __restrict__ pfsqrf, double * __restrict__ pfsqsf, - double * __restrict__ pfcqrng, double * __restrict__ pfcqsng, - double * __restrict__ pfsqltur, double * __restrict__ pfsqitur, - double * __restrict__ pfplsl, double * __restrict__ pfplsn, double * __restrict__ pfhpsl, - double * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, - double rg, double rd, double rcpd, double retv, double rlvtt, double rlstt, double rlmlt, double rtt, - double rv, double r2es, double r3les, double r3ies, double r4les, double r4ies, double r5les, - double r5ies, double r5alvcp, double r5alscp, double ralvdcp, double ralsdcp, double ralfdcp, - double rtwat, double rtice, double rticecu, double rtwat_rtice_r, double rtwat_rticecu_r, - double rkoop1, double rkoop2, - double * __restrict__ zfoealfa, double * __restrict__ ztp1, double * __restrict__ zli, - double * __restrict__ za, double * __restrict__ zaorig, double * __restrict__ zliqfrac, - double * __restrict__ zicefrac, double * __restrict__ zqx, double * __restrict__ zqx0, - double * __restrict__ zpfplsx, double * __restrict__ zlneg, double * __restrict__ zqxn2d, - double * __restrict__ zqsmix, double * __restrict__ zqsliq, double * __restrict__ zqsice, - double * __restrict__ zfoeewmt, double * __restrict__ zfoeew, double * __restrict__ zfoeeliqt) { +__global__ void cloudsc_c(int kidia, int kfdia, int klon, dtype ptsphy, + const dtype * __restrict__ pt, + const dtype * __restrict__ pq, const dtype * __restrict__ tendency_tmp_t, + const dtype * __restrict__ tendency_tmp_q, const dtype * __restrict__ tendency_tmp_a, + const dtype * __restrict__ tendency_tmp_cld, dtype * __restrict__ tendency_loc_t, + dtype * __restrict__ tendency_loc_q, dtype * __restrict__ tendency_loc_a, + dtype * __restrict__ tendency_loc_cld, const dtype * __restrict__ pvfa, + const dtype * __restrict__ pvfl, const dtype * __restrict__ pvfi, const dtype * __restrict__ pdyna, + const dtype * __restrict__ pdynl, const dtype * __restrict__ pdyni, const dtype * __restrict__ phrsw, + dtype * __restrict__ phrlw, const dtype * __restrict__ pvervel, const dtype * __restrict__ pap, + const dtype * __restrict__ paph, const dtype * __restrict__ plsm, + const int * ktype, const dtype * __restrict__ plu, dtype * __restrict__ plude, + const dtype * __restrict__ psnde, const dtype * __restrict__ pmfu, const dtype * __restrict__ pmfd, + const dtype * __restrict__ pa, const dtype * __restrict__ pclv, const dtype * __restrict__ psupsat, + const dtype * __restrict__ plcrit_aer, const dtype * __restrict__ picrit_aer, + const dtype * __restrict__ pre_ice, const dtype * __restrict__ pccn, const dtype * __restrict__ pnice, + dtype * __restrict__ pcovptot, dtype * __restrict__ prainfrac_toprfz, + dtype * __restrict__ pfsqlf, dtype * __restrict__ pfsqif, dtype * __restrict__ pfcqnng, + dtype * __restrict__ pfcqlng, dtype * __restrict__ pfsqrf, dtype * __restrict__ pfsqsf, + dtype * __restrict__ pfcqrng, dtype * __restrict__ pfcqsng, + dtype * __restrict__ pfsqltur, dtype * __restrict__ pfsqitur, + dtype * __restrict__ pfplsl, dtype * __restrict__ pfplsn, dtype * __restrict__ pfhpsl, + dtype * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, + dtype rg, dtype rd, dtype rcpd, dtype retv, dtype rlvtt, dtype rlstt, dtype rlmlt, dtype rtt, + dtype rv, dtype r2es, dtype r3les, dtype r3ies, dtype r4les, dtype r4ies, dtype r5les, + dtype r5ies, dtype r5alvcp, dtype r5alscp, dtype ralvdcp, dtype ralsdcp, dtype ralfdcp, + dtype rtwat, dtype rtice, dtype rticecu, dtype rtwat_rtice_r, dtype rtwat_rticecu_r, + dtype rkoop1, dtype rkoop2, + dtype * __restrict__ zfoealfa, dtype * __restrict__ ztp1, dtype * __restrict__ zli, + dtype * __restrict__ za, dtype * __restrict__ zaorig, dtype * __restrict__ zliqfrac, + dtype * __restrict__ zicefrac, dtype * __restrict__ zqx, dtype * __restrict__ zqx0, + dtype * __restrict__ zpfplsx, dtype * __restrict__ zlneg, dtype * __restrict__ zqxn2d, + dtype * __restrict__ zqsmix, dtype * __restrict__ zqsliq, dtype * __restrict__ zqsice, + dtype * __restrict__ zfoeewmt, dtype * __restrict__ zfoeew, dtype * __restrict__ zfoeeliqt) { //------------------------------------------------------------------------------- // Declare input/output arguments @@ -59,105 +59,105 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, const int klev = 137; // Number of levels - double zlcond1, zlcond2, zlevapl, zlevapi, zrainaut, zsnowaut, zliqcld, zicecld; - double zlevap, zleros; + dtype zlcond1, zlcond2, zlevapl, zlevapi, zrainaut, zsnowaut, zliqcld, zicecld; + dtype zlevap, zleros; // condensation and evaporation terms // autoconversion terms - double zfokoop; - //double zfoealfa[klev + 1]; - double zicenuclei; // number concentration of ice nuclei + dtype zfokoop; + //dtype zfoealfa[klev + 1]; + dtype zicenuclei; // number concentration of ice nuclei - double zlicld; - double zacond; - double zaeros; - double zlfinalsum; - double zdqs; - double ztold; - double zqold; - double zdtgdp; - double zrdtgdp; - double ztrpaus; - double zcovpclr; - double zpreclr; - double zcovptot; - double zcovpmax; - double zqpretot; - double zdpevap; - double zdtforc; - double zdtdiab; - //double ztp1[klev]; - double zldefr; - double zldifdt; - double zdtgdpf; - double zlcust[5]; - double zacust; - double zmf; + dtype zlicld; + dtype zacond; + dtype zaeros; + dtype zlfinalsum; + dtype zdqs; + dtype ztold; + dtype zqold; + dtype zdtgdp; + dtype zrdtgdp; + dtype ztrpaus; + dtype zcovpclr; + dtype zpreclr; + dtype zcovptot; + dtype zcovpmax; + dtype zqpretot; + dtype zdpevap; + dtype zdtforc; + dtype zdtdiab; + //dtype ztp1[klev]; + dtype zldefr; + dtype zldifdt; + dtype zdtgdpf; + dtype zlcust[5]; + dtype zacust; + dtype zmf; - double zrho; - double ztmp1, ztmp2, ztmp3; - double ztmp4, ztmp5, ztmp6, ztmp7; - double zalfawm; + dtype zrho; + dtype ztmp1, ztmp2, ztmp3; + dtype ztmp4, ztmp5, ztmp6, ztmp7; + dtype zalfawm; // Accumulators of A,B,and C factors for cloud equations - double zsolab; // -ve implicit CC - double zsolac; // linear CC - double zanew; - double zanewm1; + dtype zsolab; // -ve implicit CC + dtype zsolac; // linear CC + dtype zanew; + dtype zanewm1; - double zgdp; + dtype zgdp; //---for flux calculation - double zda; - //double zli[klev], za[klev]; - //double zaorig[klev]; // start of scheme value for CC + dtype zda; + //dtype zli[klev], za[klev]; + //dtype zaorig[klev]; // start of scheme value for CC int llflag; int llo1; int icall, ik, jk, jl, jm, jn, jo, jlen, is; - double zdp, zpaphd; + dtype zdp, zpaphd; - double zalfa; + dtype zalfa; // & ZALFACU, ZALFALS - double zalfaw; - double zbeta, zbeta1; + dtype zalfaw; + dtype zbeta, zbeta1; //REAL(KIND=JPRB) :: ZBOTT - double zcfpr; - double zcor; - double zcdmax; - double zmin; - double zlcondlim; - double zdenom; - double zdpmxdt; - double zdpr; - double zdtdp; - double ze; - double zepsec; - double zfac, zfaci, zfacw; - double zgdcp; - double zinew; - double zlcrit; - double zmfdn; - double zprecip; - double zqe; - double zqsat, zqtmst, zrdcp; - double zrhc, zsig, zsigk; - double zwtot; - double zzco, zzdl, zzrh, zzzdt, zqadj; - double zqnew, ztnew; - double zrg_r, zgdph_r, zcons1, zcond, zcons1a; - double zlfinal; - double zmelt; - double zevap; - double zfrz; - double zvpliq, zvpice; - double zadd, zbdd, zcvds, zice0, zdepos; - double zsupsat; - double zfall; - double zre_ice; - double zrldcp; - double zqp1env; + dtype zcfpr; + dtype zcor; + dtype zcdmax; + dtype zmin; + dtype zlcondlim; + dtype zdenom; + dtype zdpmxdt; + dtype zdpr; + dtype zdtdp; + dtype ze; + dtype zepsec; + dtype zfac, zfaci, zfacw; + dtype zgdcp; + dtype zinew; + dtype zlcrit; + dtype zmfdn; + dtype zprecip; + dtype zqe; + dtype zqsat, zqtmst, zrdcp; + dtype zrhc, zsig, zsigk; + dtype zwtot; + dtype zzco, zzdl, zzrh, zzzdt, zqadj; + dtype zqnew, ztnew; + dtype zrg_r, zgdph_r, zcons1, zcond, zcons1a; + dtype zlfinal; + dtype zmelt; + dtype zevap; + dtype zfrz; + dtype zvpliq, zvpice; + dtype zadd, zbdd, zcvds, zice0, zdepos; + dtype zsupsat; + dtype zfall; + dtype zre_ice; + dtype zrldcp; + dtype zqp1env; //---------------------------- // Arrays for new microphysics @@ -174,16 +174,16 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, int llindex1[5]; // index variable int llindex3[5 * 5]; // index variable - double zmax; - double zrat; + dtype zmax; + dtype zrat; int iorder[5]; // array for sorting explicit terms - //double zliqfrac[klev]; // cloud liquid water fraction: ql/(ql+qi) - //double zicefrac[klev]; // cloud ice water fraction: qi/(ql+qi) - double zqxn[5]; // new values for zqx at time+1 - double zqxfg[5]; // first guess values including precip - double zqxnm1[5]; // new values for zqx at time+1 at level above - double zfluxq[5]; // fluxes convergence of species (needed?) + //dtype zliqfrac[klev]; // cloud liquid water fraction: ql/(ql+qi) + //dtype zicefrac[klev]; // cloud ice water fraction: qi/(ql+qi) + dtype zqxn[5]; // new values for zqx at time+1 + dtype zqxfg[5]; // first guess values including precip + dtype zqxnm1[5]; // new values for zqx at time+1 at level above + dtype zfluxq[5]; // fluxes convergence of species (needed?) // Keep the following for possible future total water variance scheme? //REAL(KIND=JPRB) :: ZTL(KLON,KLEV) ! liquid water temperature //REAL(KIND=JPRB) :: ZABETA(KLON,KLEV) ! cloud fraction @@ -191,31 +191,31 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //REAL(KIND=JPRB) :: ZQTMIN(KLON,KLEV) //REAL(KIND=JPRB) :: ZQTMAX(KLON,KLEV) - double zmeltmax; - double zfrzmax; - double zicetot; + dtype zmeltmax; + dtype zfrzmax; + dtype zicetot; - //double zqsmix[klev]; // diagnostic mixed phase saturation + //dtype zqsmix[klev]; // diagnostic mixed phase saturation //REAL(KIND=JPRB) :: ZQSBIN(KLON,KLEV) ! binary switched ice/liq saturation - //double zqsliq[klev]; // liquid water saturation - //double zqsice[klev]; // ice water saturation + //dtype zqsliq[klev]; // liquid water saturation + //dtype zqsice[klev]; // ice water saturation //REAL(KIND=JPRB) :: ZRHM(KLON,KLEV) ! diagnostic mixed phase RH //REAL(KIND=JPRB) :: ZRHL(KLON,KLEV) ! RH wrt liq //REAL(KIND=JPRB) :: ZRHI(KLON,KLEV) ! RH wrt ice - //double zfoeewmt[klev]; - //double zfoeew[klev]; - //double zfoeeliqt[klev]; + //dtype zfoeewmt[klev]; + //dtype zfoeew[klev]; + //dtype zfoeeliqt[klev]; //REAL(KIND=JPRB) :: ZFOEEICET(KLON,KLEV) - double zdqsliqdt, zdqsicedt, zdqsmixdt; - double zcorqsliq; - double zcorqsice; + dtype zdqsliqdt, zdqsicedt, zdqsmixdt; + dtype zcorqsliq; + dtype zcorqsice; //REAL(KIND=JPRB) :: ZCORQSBIN(KLON) - double zcorqsmix; - double zevaplimliq, zevaplimice, zevaplimmix; + dtype zcorqsmix; + dtype zevaplimliq, zevaplimice, zevaplimmix; //------------------------------------------------------- // SOURCE/SINK array for implicit and explicit terms @@ -236,60 +236,60 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // i.e. A positive value is a sink!????? weird... //------------------------------------------------------- - double zsolqa[5 * 5]; // explicit sources and sinks - double zsolqb[5 * 5]; // implicit sources and sinks + dtype zsolqa[5 * 5]; // explicit sources and sinks + dtype zsolqb[5 * 5]; // implicit sources and sinks // e.g. microphysical pathways between ice variables. - double zqlhs[5 * 5]; // n x n matrix storing the LHS of implicit solver - double zvqx[5]; // fall speeds of three categories - double zexplicit; - double zratio[5], zsinksum[5]; + dtype zqlhs[5 * 5]; // n x n matrix storing the LHS of implicit solver + dtype zvqx[5]; // fall speeds of three categories + dtype zexplicit; + dtype zratio[5], zsinksum[5]; // for sedimentation source/sink terms - double zfallsink[5]; - double zfallsrce[5]; + dtype zfallsink[5]; + dtype zfallsrce[5]; // for convection detrainment source and subsidence source/sink terms - double zconvsrce[5]; - double zconvsink[5]; + dtype zconvsrce[5]; + dtype zconvsink[5]; // for supersaturation source term from previous timestep - double zpsupsatsrce[5]; + dtype zpsupsatsrce[5]; // Numerical fit to wet bulb temperature - double ztw1 = (double) 1329.31; - double ztw2 = (double) 0.0074615; - double ztw3 = (double) 0.85E5; - double ztw4 = (double) 40.637; - double ztw5 = (double) 275.0; + dtype ztw1 = (dtype) 1329.31; + dtype ztw2 = (dtype) 0.0074615; + dtype ztw3 = (dtype) 0.85E5; + dtype ztw4 = (dtype) 40.637; + dtype ztw5 = (dtype) 275.0; - double zsubsat; // Subsaturation for snow melting term - double ztdmtw0; // Diff between dry-bulb temperature and + dtype zsubsat; // Subsaturation for snow melting term + dtype ztdmtw0; // Diff between dry-bulb temperature and // temperature when wet-bulb = 0degC // Variables for deposition term - double ztcg; // Temperature dependent function for ice PSD - double zfacx1i, zfacx1s; // PSD correction factor - double zaplusb, zcorrfac, zcorrfac2, zpr02, zterm1, zterm2; // for ice dep - double zcldtopdist; // Distance from cloud top - double zinfactor; // No. of ice nuclei factor for deposition + dtype ztcg; // Temperature dependent function for ice PSD + dtype zfacx1i, zfacx1s; // PSD correction factor + dtype zaplusb, zcorrfac, zcorrfac2, zpr02, zterm1, zterm2; // for ice dep + dtype zcldtopdist; // Distance from cloud top + dtype zinfactor; // No. of ice nuclei factor for deposition // Autoconversion/accretion/riming/evaporation int iwarmrain; int ievaprain; int ievapsnow; int idepice; - double zrainacc; - double zraincld; - double zsnowrime; - double zsnowcld; - double zesatliq; - double zfallcorr; - double zlambda; - double zevap_denom; - double zcorr2; - double zka; - double zconst; - double ztemp; + dtype zrainacc; + dtype zraincld; + dtype zsnowrime; + dtype zsnowcld; + dtype zesatliq; + dtype zfallcorr; + dtype zlambda; + dtype zevap_denom; + dtype zcorr2; + dtype zka; + dtype zconst; + dtype ztemp; // Rain freezing int llrainliq; // True if majority of raindrops are liquid (no ice core) @@ -301,27 +301,27 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------- // SCM budget statistics //---------------------- - double zrain; + dtype zrain; - double zhook_handle; - double ztmpl, ztmpi, ztmpa; + dtype zhook_handle; + dtype ztmpl, ztmpi, ztmpa; - double zmm, zrr; - double zrg; + dtype zmm, zrr; + dtype zrg; - double zzsum, zzratio; - double zepsilon; + dtype zzsum, zzratio; + dtype zepsilon; - double zcond1, zqp; + dtype zcond1, zqp; - double psum_solqa; + dtype psum_solqa; int ibl; int i_llfall_0; - //double zqx[5 * klev]; - //double zqx0[5 * klev]; - //double zpfplsx[5 * (klev + 1)]; - //double zlneg[5 * klev]; - //double zqxn2d[5 * klev]; + //dtype zqx[5 * klev]; + //dtype zqx0[5 * klev]; + //dtype zpfplsx[5 * (klev + 1)]; + //dtype zlneg[5 * klev]; + //dtype zqxn2d[5 * klev]; jl = threadIdx.x; ibl = blockIdx.x; //blockIdx.z; @@ -339,7 +339,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 0. *** SET UP CONSTANTS *** //###################################################################### - zepsilon = (double) 100.*DBL_EPSILON; + zepsilon = (dtype) 100.*DBL_EPSILON; // --------------------------------------------------------------------- // Set version of warm-rain autoconversion/accretion @@ -369,13 +369,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // --------------------- // Some simple constants // --------------------- - zqtmst = (double) 1.0 / ptsphy; + zqtmst = (dtype) 1.0 / ptsphy; zgdcp = rg / rcpd; zrdcp = rd / rcpd; zcons1a = rcpd / (rlmlt*rg*(*yrecldp).rtaumel); - zepsec = (double) 1.E-14; - zrg_r = (double) 1.0 / rg; - zrldcp = (double) 1.0 / (ralsdcp - ralvdcp); + zepsec = (dtype) 1.E-14; + zrg_r = (dtype) 1.0 / rg; + zrldcp = (dtype) 1.0 / (ralsdcp - ralvdcp); // Note: Defined in module/yoecldp.F90 // NCLDQL=1 ! liquid cloud water @@ -407,27 +407,27 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // INITIALIZATION OF OUTPUT TENDENCIES // ----------------------------------------------- for (jk = 0; jk <= klev + -1; jk += 1) { - tendency_loc_t[jl + klon*(jk + klev*ibl)] = (double) 0.0; - tendency_loc_q[jl + klon*(jk + klev*ibl)] = (double) 0.0; - tendency_loc_a[jl + klon*(jk + klev*ibl)] = (double) 0.0; + tendency_loc_t[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; + tendency_loc_q[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; + tendency_loc_a[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; } for (jm = 0; jm <= 5 - 1 + -1; jm += 1) { for (jk = 0; jk <= klev + -1; jk += 1) { - tendency_loc_cld[jl + klon*(jk + klev*(jm + 5*ibl))] = (double) 0.0; + tendency_loc_cld[jl + klon*(jk + klev*(jm + 5*ibl))] = (dtype) 0.0; } } //-- These were uninitialized : meaningful only when we compare error differences for (jk = 0; jk <= klev + -1; jk += 1) { - pcovptot[jl + klon*(jk + klev*ibl)] = (double) 0.0; - tendency_loc_cld[jl + klon*(jk + klev*(4 + 5*ibl))] = (double) 0.0; + pcovptot[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; + tendency_loc_cld[jl + klon*(jk + klev*(4 + 5*ibl))] = (dtype) 0.0; } // ------------------------- // set up fall speeds in m/s // ------------------------- - zvqx[4] = (double) 0.0; - zvqx[0] = (double) 0.0; + zvqx[4] = (dtype) 0.0; + zvqx[0] = (dtype) 0.0; zvqx[1] = (*yrecldp).rvice; zvqx[2] = (*yrecldp).rvrain; zvqx[3] = (*yrecldp).rvsnow; @@ -435,7 +435,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, llfall[i_llfall_0] = false; } for (jm = 0; jm <= 5 + -1; jm += 1) { - if (zvqx[jm] > (double) 0.0) { + if (zvqx[jm] > (dtype) 0.0) { llfall[jm] = true; } // falling species @@ -483,18 +483,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //------------- for (jm = 0; jm <= 5 + -1; jm += 1) { for (jk = 0; jk <= klev + 1 + -1; jk += 1) { - zpfplsx[jl + klon*(jk + (klev + 1)*(jm + 5*ibl))] = (double) 0.0; // precip fluxes + zpfplsx[jl + klon*(jk + (klev + 1)*(jm + 5*ibl))] = (dtype) 0.0; // precip fluxes } } for (jm = 0; jm <= 5 + -1; jm += 1) { for (jk = 0; jk <= klev + -1; jk += 1) { - zqxn2d[jl + klon*(jk + klev*(jm + 5*ibl))] = (double) 0.0; // end of timestep values in 2D - zlneg[jl + klon*(jk + klev*(jm + 5*ibl))] = (double) 0.0; // negative input check + zqxn2d[jl + klon*(jk + klev*(jm + 5*ibl))] = (dtype) 0.0; // end of timestep values in 2D + zlneg[jl + klon*(jk + klev*(jm + 5*ibl))] = (dtype) 0.0; // negative input check } } - prainfrac_toprfz[jl + klon*ibl] = (double) 0.0; // rain fraction at top of refreezing layer + prainfrac_toprfz[jl + klon*ibl] = (dtype) 0.0; // rain fraction at top of refreezing layer llrainliq = true; // Assume all raindrops are liquid initially // ---------------------------------------------------- @@ -515,7 +515,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*ibl)] - ralvdcp*zqadj; zqx[jl + klon*(jk + klev*(4 + 5*ibl))] = zqx[jl + klon*(jk + klev*(4 + 5*ibl))] + zqx[jl + klon*(jk + klev*(0 + 5*ibl))]; - zqx[jl + klon*(jk + klev*(0 + 5*ibl))] = (double) 0.0; + zqx[jl + klon*(jk + klev*(0 + 5*ibl))] = (dtype) 0.0; // Evaporate small cloud ice water amounts zlneg[jl + klon*(jk + klev*(1 + 5*ibl))] = zlneg[jl + klon*(jk + klev*(1 + 5*ibl))] + @@ -527,10 +527,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*ibl)] - ralsdcp*zqadj; zqx[jl + klon*(jk + klev*(4 + 5*ibl))] = zqx[jl + klon*(jk + klev*(4 + 5*ibl))] + zqx[jl + klon*(jk + klev*(1 + 5*ibl))]; - zqx[jl + klon*(jk + klev*(1 + 5*ibl))] = (double) 0.0; + zqx[jl + klon*(jk + klev*(1 + 5*ibl))] = (dtype) 0.0; // Set cloud cover to zero - za[jl + klon*(jk + klev*ibl)] = (double) 0.0; + za[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; } } @@ -556,7 +556,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } zqx[jl + klon*(jk + klev*(4 + 5*ibl))] = zqx[jl + klon*(jk + klev*(4 + 5*ibl))] + zqx[jl + klon*(jk + klev*(jm + 5*ibl))]; - zqx[jl + klon*(jk + klev*(jm + 5*ibl))] = (double) 0.0; + zqx[jl + klon*(jk + klev*(jm + 5*ibl))] = (dtype) 0.0; } } } @@ -570,38 +570,38 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // old *diagnostic* mixed phase saturation //---------------------------------------- zfoealfa[jl + klon*(jk + (klev + 1)*ibl)] = - ((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))); + ((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))); zfoeewmt[jl + klon*(jk + klev*ibl)] = - fmin(((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))* - exp((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4les)) + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))* - exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies))))) / - pap[jl + klon*(jk + klev*ibl)], (double) 0.5); + MYMIN(((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))* + MYEXP((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4les)) + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))* + MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies))))) / + pap[jl + klon*(jk + klev*ibl)], (dtype) 0.5); zqsmix[jl + klon*(jk + klev*ibl)] = zfoeewmt[jl + klon*(jk + klev*ibl)]; zqsmix[jl + klon*(jk + klev*ibl)] = zqsmix[jl + klon*(jk + klev*ibl)] / - ((double) 1.0 - retv*zqsmix[jl + klon*(jk + klev*ibl)]); + ((dtype) 1.0 - retv*zqsmix[jl + klon*(jk + klev*ibl)]); //--------------------------------------------- // ice saturation T<273K // liquid water saturation for T>273K //--------------------------------------------- - zalfa = ((double)(fmax(0.0, copysign(1.0, ztp1[jl + klon*(jk + klev*ibl)] - rtt)))); - zfoeew[jl + klon*(jk + klev*ibl)] = fmin((zalfa*((double)(r2es*exp((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ - (ztp1[jl + klon*(jk + klev*ibl)] - r4les)))) + ((double) 1.0 - zalfa)* - ((double)(r2es*exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies)))))/ - pap[jl + klon*(jk + klev*ibl)], (double) 0.5); - zfoeew[jl + klon*(jk + klev*ibl)] = fmin((double) 0.5, zfoeew[jl + klon*(jk + klev*ibl)]); + zalfa = ((dtype)(MYMAX(0.0, copysign(1.0, ztp1[jl + klon*(jk + klev*ibl)] - rtt)))); + zfoeew[jl + klon*(jk + klev*ibl)] = MYMIN((zalfa*((dtype)(r2es*MYEXP((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ + (ztp1[jl + klon*(jk + klev*ibl)] - r4les)))) + ((dtype) 1.0 - zalfa)* + ((dtype)(r2es*MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies)))))/ + pap[jl + klon*(jk + klev*ibl)], (dtype) 0.5); + zfoeew[jl + klon*(jk + klev*ibl)] = MYMIN((dtype) 0.5, zfoeew[jl + klon*(jk + klev*ibl)]); zqsice[jl + klon*(jk + klev*ibl)] = zfoeew[jl + klon*(jk + klev*ibl)] / - ((double) 1.0 - retv*zfoeew[jl + klon*(jk + klev*ibl)]); + ((dtype) 1.0 - retv*zfoeew[jl + klon*(jk + klev*ibl)]); //---------------------------------- // liquid water saturation //---------------------------------- - zfoeeliqt[jl + klon*(jk + klev*ibl)] = fmin(((double)(r2es*exp((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ - (ztp1[jl + klon*(jk + klev*ibl)] - r4les)))) / pap[jl + klon*(jk + klev*ibl)], (double) 0.5); + zfoeeliqt[jl + klon*(jk + klev*ibl)] = MYMIN(((dtype)(r2es*MYEXP((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ + (ztp1[jl + klon*(jk + klev*ibl)] - r4les)))) / pap[jl + klon*(jk + klev*ibl)], (dtype) 0.5); zqsliq[jl + klon*(jk + klev*ibl)] = zfoeeliqt[jl + klon*(jk + klev*ibl)]; zqsliq[jl + klon*(jk + klev*ibl)] = zqsliq[jl + klon*(jk + klev*ibl)] / - ((double) 1.0 - retv*zqsliq[jl + klon*(jk + klev*ibl)]); + ((dtype) 1.0 - retv*zqsliq[jl + klon*(jk + klev*ibl)]); // !---------------------------------- // ! ice water saturation @@ -619,7 +619,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Ensure cloud fraction is between 0 and 1 //------------------------------------------ za[jl + klon*(jk + klev*ibl)] = - fmax((double) 0.0, fmin((double) 1.0, za[jl + klon*(jk + klev*ibl)])); + MYMAX((dtype) 0.0, MYMIN((dtype) 1.0, za[jl + klon*(jk + klev*ibl)])); //------------------------------------------------------------------- // Calculate liq/ice fractions (no longer a diagnostic relationship) @@ -630,10 +630,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zliqfrac[jl + klon*(jk + klev*ibl)] = zqx[jl + klon*(jk + klev*(0 + 5*ibl))] / zli[jl + klon*(jk + klev*ibl)]; zicefrac[jl + klon*(jk + klev*ibl)] = - (double) 1.0 - zliqfrac[jl + klon*(jk + klev*ibl)]; + (dtype) 1.0 - zliqfrac[jl + klon*(jk + klev*ibl)]; } else { - zliqfrac[jl + klon*(jk + klev*ibl)] = (double) 0.0; - zicefrac[jl + klon*(jk + klev*ibl)] = (double) 0.0; + zliqfrac[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; + zicefrac[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; } } @@ -648,11 +648,11 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------- // Find tropopause level (ZTRPAUS) //--------------------------------- - ztrpaus = (double) 0.1; - zpaphd = (double) 1.0 / paph[jl + klon*(klev + (klev + 1)*ibl)]; + ztrpaus = (dtype) 0.1; + zpaphd = (dtype) 1.0 / paph[jl + klon*(klev + (klev + 1)*ibl)]; for (jk = 0; jk <= klev - 1 + -1; jk += 1) { zsig = pap[jl + klon*(jk + klev*ibl)]*zpaphd; - if (zsig > (double) 0.1 && zsig < (double) 0.4 && ztp1[jl + klon*(jk + klev*ibl)] > + if (zsig > (dtype) 0.1 && zsig < (dtype) 0.4 && ztp1[jl + klon*(jk + klev*ibl)] > ztp1[jl + klon*(1 + jk + klev*ibl)]) { ztrpaus = zsig; } @@ -662,12 +662,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reset single level variables //----------------------------- - zanewm1 = (double) 0.0; - zda = (double) 0.0; - zcovpclr = (double) 0.0; - zcovpmax = (double) 0.0; - zcovptot = (double) 0.0; - zcldtopdist = (double) 0.0; + zanewm1 = (dtype) 0.0; + zda = (dtype) 0.0; + zcovpclr = (dtype) 0.0; + zcovpmax = (dtype) 0.0; + zcovptot = (dtype) 0.0; + zcldtopdist = (dtype) 0.0; //###################################################################### // 3. *** PHYSICS *** @@ -695,37 +695,37 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Set KLON arrays to zero //--------------------------------- - zlicld = (double) 0.0; - zrainaut = (double) 0.0; // currently needed for diags - zrainacc = (double) 0.0; // currently needed for diags - zsnowaut = (double) 0.0; // needed - zldefr = (double) 0.0; - zacust = (double) 0.0; // set later when needed - zqpretot = (double) 0.0; - zlfinalsum = (double) 0.0; + zlicld = (dtype) 0.0; + zrainaut = (dtype) 0.0; // currently needed for diags + zrainacc = (dtype) 0.0; // currently needed for diags + zsnowaut = (dtype) 0.0; // needed + zldefr = (dtype) 0.0; + zacust = (dtype) 0.0; // set later when needed + zqpretot = (dtype) 0.0; + zlfinalsum = (dtype) 0.0; // Required for first guess call - zlcond1 = (double) 0.0; - zlcond2 = (double) 0.0; - zsupsat = (double) 0.0; - zlevapl = (double) 0.0; - zlevapi = (double) 0.0; + zlcond1 = (dtype) 0.0; + zlcond2 = (dtype) 0.0; + zsupsat = (dtype) 0.0; + zlevapl = (dtype) 0.0; + zlevapi = (dtype) 0.0; //------------------------------------- // solvers for cloud fraction //------------------------------------- - zsolab = (double) 0.0; - zsolac = (double) 0.0; + zsolab = (dtype) 0.0; + zsolac = (dtype) 0.0; - zicetot = (double) 0.0; + zicetot = (dtype) 0.0; //------------------------------------------ // reset matrix so missing pathways are set //------------------------------------------ for (jm = 0; jm <= 5 + -1; jm += 1) { for (jn = 0; jn <= 5 + -1; jn += 1) { - zsolqb[jn + 5*jm] = (double) 0.0; - zsolqa[jn + 5*jm] = (double) 0.0; + zsolqb[jn + 5*jm] = (dtype) 0.0; + zsolqa[jn + 5*jm] = (dtype) 0.0; } } @@ -733,12 +733,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // reset new microphysics variables //---------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zfallsrce[jm] = (double) 0.0; - zfallsink[jm] = (double) 0.0; - zconvsrce[jm] = (double) 0.0; - zconvsink[jm] = (double) 0.0; - zpsupsatsrce[jm] = (double) 0.0; - zratio[jm] = (double) 0.0; + zfallsrce[jm] = (dtype) 0.0; + zfallsink[jm] = (dtype) 0.0; + zconvsrce[jm] = (dtype) 0.0; + zconvsink[jm] = (dtype) 0.0; + zpsupsatsrce[jm] = (dtype) 0.0; + zratio[jm] = (dtype) 0.0; } @@ -752,7 +752,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zrho = pap[jl + klon*(jk + klev*ibl)] / (rd*ztp1[jl + klon*(jk + klev*ibl)]); // p/RT air density zdtgdp = ptsphy*zgdp; // dt g/dp - zrdtgdp = zdp*((double) 1.0 / (ptsphy*rg)); // 1/(dt g/dp) + zrdtgdp = zdp*((dtype) 1.0 / (ptsphy*rg)); // 1/(dt g/dp) if (jk + 1 > 1) { zdtgdpf = ptsphy*rg / (pap[jl + klon*(jk + klev*ibl)] - @@ -765,39 +765,39 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reminder: RETV=RV/RD-1 // liquid - zfacw = r5les / (pow((ztp1[jl + klon*(jk + klev*ibl)] - r4les), 2)); - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeeliqt[jl + klon*(jk + klev*ibl)]); + zfacw = r5les / (MYPOW((ztp1[jl + klon*(jk + klev*ibl)] - r4les), 2)); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeeliqt[jl + klon*(jk + klev*ibl)]); zdqsliqdt = zfacw*zcor*zqsliq[jl + klon*(jk + klev*ibl)]; - zcorqsliq = (double) 1.0 + ralvdcp*zdqsliqdt; + zcorqsliq = (dtype) 1.0 + ralvdcp*zdqsliqdt; // ice - zfaci = r5ies / (pow((ztp1[jl + klon*(jk + klev*ibl)] - r4ies), 2)); - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeew[jl + klon*(jk + klev*ibl)]); + zfaci = r5ies / (MYPOW((ztp1[jl + klon*(jk + klev*ibl)] - r4ies), 2)); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeew[jl + klon*(jk + klev*ibl)]); zdqsicedt = zfaci*zcor*zqsice[jl + klon*(jk + klev*ibl)]; - zcorqsice = (double) 1.0 + ralsdcp*zdqsicedt; + zcorqsice = (dtype) 1.0 + ralsdcp*zdqsicedt; // diagnostic mixed zalfaw = zfoealfa[jl + klon*(jk + (klev + 1)*ibl)]; zalfawm = zalfaw; - zfac = zalfaw*zfacw + ((double) 1.0 - zalfaw)*zfaci; - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeewmt[jl + klon*(jk + klev*ibl)]); + zfac = zalfaw*zfacw + ((dtype) 1.0 - zalfaw)*zfaci; + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeewmt[jl + klon*(jk + klev*ibl)]); zdqsmixdt = zfac*zcor*zqsmix[jl + klon*(jk + klev*ibl)]; - zcorqsmix = (double) 1.0 + ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)* - rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)* + zcorqsmix = (dtype) 1.0 + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)* + rtwat_rtice_r, 2)))*ralvdcp + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)* rtwat_rtice_r, 2))))*ralsdcp))*zdqsmixdt; // evaporation/sublimation limits - zevaplimmix = fmax((zqsmix[jl + klon*(jk + klev*ibl)] - - zqx[jl + klon*(jk + klev*(4 + 5*ibl))]) / zcorqsmix, (double) 0.0); - zevaplimliq = fmax((zqsliq[jl + klon*(jk + klev*ibl)] - - zqx[jl + klon*(jk + klev*(4 + 5*ibl))]) / zcorqsliq, (double) 0.0); - zevaplimice = fmax((zqsice[jl + klon*(jk + klev*ibl)] - - zqx[jl + klon*(jk + klev*(4 + 5*ibl))]) / zcorqsice, (double) 0.0); + zevaplimmix = MYMAX((zqsmix[jl + klon*(jk + klev*ibl)] - + zqx[jl + klon*(jk + klev*(4 + 5*ibl))]) / zcorqsmix, (dtype) 0.0); + zevaplimliq = MYMAX((zqsliq[jl + klon*(jk + klev*ibl)] - + zqx[jl + klon*(jk + klev*(4 + 5*ibl))]) / zcorqsliq, (dtype) 0.0); + zevaplimice = MYMAX((zqsice[jl + klon*(jk + klev*ibl)] - + zqx[jl + klon*(jk + klev*(4 + 5*ibl))]) / zcorqsice, (dtype) 0.0); //-------------------------------- // in-cloud consensate amount //-------------------------------- - ztmpa = (double) 1.0 / fmax(za[jl + klon*(jk + klev*ibl)], zepsec); + ztmpa = (dtype) 1.0 / MYMAX(za[jl + klon*(jk + klev*ibl)], zepsec); zliqcld = zqx[jl + klon*(jk + klev*(0 + 5*ibl))]*ztmpa; zicecld = zqx[jl + klon*(jk + klev*(1 + 5*ibl))]*ztmpa; zlicld = zliqcld + zicecld; @@ -835,15 +835,15 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 3.1.1 Supersaturation limit (from Koop) //----------------------------------- // Needs to be set for all temperatures - zfokoop = ((double)(fmin(rkoop1 - rkoop2*ztp1[jl + klon*(jk + klev*ibl)], (double)(r2es*exp((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ - (ztp1[jl + klon*(jk + klev*ibl)] - r4les)))*1.0/(double)(r2es*exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ + zfokoop = ((dtype)(MYMIN(rkoop1 - rkoop2*ztp1[jl + klon*(jk + klev*ibl)], (dtype)(r2es*MYEXP((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ + (ztp1[jl + klon*(jk + klev*ibl)] - r4les)))*1.0/(dtype)(r2es*MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ (ztp1[jl + klon*(jk + klev*ibl)] - r4ies)))))); if (ztp1[jl + klon*(jk + klev*ibl)] >= rtt || (*yrecldp).nssopt == 0) { - zfac = (double) 1.0; - zfaci = (double) 1.0; + zfac = (dtype) 1.0; + zfaci = (dtype) 1.0; } else { - zfac = za[jl + klon*(jk + klev*ibl)] + zfokoop*((double) 1.0 - za[jl + klon*(jk +klev*ibl)]); + zfac = za[jl + klon*(jk + klev*ibl)] + zfokoop*((dtype) 1.0 - za[jl + klon*(jk +klev*ibl)]); zfaci = ptsphy / (*yrecldp).rkooptau; } @@ -854,17 +854,17 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //------------------------------------------------------------------- // Calculate supersaturation to add to cloud - if (za[jl + klon*(jk + klev*ibl)] > (double) 1.0 - (*yrecldp).ramin) { - zsupsat = fmax((zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - zfac*zqsice[jl + klon*(jk + klev*ibl)]) / - zcorqsice, (double) 0.0); + if (za[jl + klon*(jk + klev*ibl)] > (dtype) 1.0 - (*yrecldp).ramin) { + zsupsat = MYMAX((zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - zfac*zqsice[jl + klon*(jk + klev*ibl)]) / + zcorqsice, (dtype) 0.0); } else { // Calculate environmental humidity supersaturation zqp1env = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - za[jl + klon*(jk + klev*ibl)]*zqsice[jl + klon*(jk + klev*ibl)]) / - fmax((double) 1.0 - za[jl + klon*(jk + klev*ibl)], zepsilon); + MYMAX((dtype) 1.0 - za[jl + klon*(jk + klev*ibl)], zepsilon); //& SIGN(MAX(ABS(1.0_JPRB-ZA(JL,JK)),ZEPSILON),1.0_JPRB-ZA(JL,JK)) - zsupsat = fmax(((double) 1.0 - za[jl + klon*(jk + klev*ibl)])*(zqp1env - zfac*zqsice[jl + klon*(jk + klev*ibl)]) / - zcorqsice, (double) 0.0); + zsupsat = MYMAX(((dtype) 1.0 - za[jl + klon*(jk + klev*ibl)])*(zqp1env - zfac*zqsice[jl + klon*(jk + klev*ibl)]) / + zcorqsice, (dtype) 0.0); } //------------------------------------------------------------------- @@ -890,7 +890,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } // Increase cloud amount using RKOOPTAU timescale - zsolac = ((double) 1.0 - za[jl + klon*(jk + klev*ibl)])*zfaci; + zsolac = ((dtype) 1.0 - za[jl + klon*(jk + klev*ibl)])*zfaci; } @@ -916,7 +916,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } // Increase cloud amount using RKOOPTAU timescale - zsolac = ((double) 1.0 - za[jl + klon*(jk + klev*ibl)])*zfaci; + zsolac = ((dtype) 1.0 - za[jl + klon*(jk + klev*ibl)])*zfaci; // Store cloud budget diagnostics if required } @@ -946,13 +946,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // *diagnostic temperature split* zalfaw = zfoealfa[jl + klon*(jk + (klev + 1)*ibl)]; zconvsrce[0] = zalfaw*plude[jl + klon*(jk + klev*ibl)]; - zconvsrce[1] = ((double) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)]; + zconvsrce[1] = ((dtype) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)]; zsolqa[0 + 5*(0)] = zsolqa[0 + 5*(0)] + zconvsrce[0]; zsolqa[1 + 5*(1)] = zsolqa[1 + 5*(1)] + zconvsrce[1]; } else { - plude[jl + klon*(jk + klev*ibl)] = (double) 0.0; + plude[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; } // *convective snow detrainment source @@ -980,7 +980,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------- if (jk + 1 > (*yrecldp).ncldtop) { - zmf = fmax((double) 0.0, (pmfu[jl + klon*(jk + klev*ibl)] + pmfd[jl + klon*(jk + klev*ibl)])*zdtgdp); + zmf = MYMAX((dtype) 0.0, (pmfu[jl + klon*(jk + klev*ibl)] + pmfd[jl + klon*(jk + klev*ibl)])*zdtgdp); zacust = zmf*zanewm1; for (jm = 0; jm <= 5 + -1; jm += 1) { @@ -995,7 +995,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // since there is no prognostic memory for in-cloud humidity, i.e. // we always assume cloud is saturated. - zdtdp = zrdcp*(double) 0.5*(ztp1[jl + klon*(-1 + jk + klev*ibl)] + + zdtdp = zrdcp*(dtype) 0.5*(ztp1[jl + klon*(-1 + jk + klev*ibl)] + ztp1[jl + klon*(jk + klev*ibl)]) / paph[jl + klon*(jk + (klev + 1)*ibl)]; zdtforc = zdtdp*(pap[jl + klon*(jk + klev*ibl)] - pap[jl + klon*(-1 + jk + klev*ibl)]); //[#Note: Diagnostic mixed phase should be replaced below] @@ -1003,9 +1003,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jm = 0; jm <= 5 + -1; jm += 1) { if (!llfall[jm] && iphase[jm] > 0) { - zlfinal = fmax((double) 0.0, zlcust[jm] - zdqs); //lim to zero + zlfinal = MYMAX((dtype) 0.0, zlcust[jm] - zdqs); //lim to zero // no supersaturation allowed incloud ---V - zevap = fmin((zlcust[jm] - zlfinal), zevaplimmix); + zevap = MYMIN((zlcust[jm] - zlfinal), zevaplimmix); // ZEVAP=0.0_JPRB zlfinal = zlcust[jm] - zevap; zlfinalsum = zlfinalsum + zlfinal; // sum @@ -1018,7 +1018,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reset the cloud contribution if no cloud water survives to this level: if (zlfinalsum < zepsec) { - zacust = (double) 0.0; + zacust = (dtype) 0.0; } zsolac = zsolac + zacust; @@ -1033,7 +1033,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (jk + 1 < klev) { - zmfdn = fmax((double) 0.0, (pmfu[jl + klon*(1 + jk + klev*ibl)] + + zmfdn = MYMAX((dtype) 0.0, (pmfu[jl + klon*(1 + jk + klev*ibl)] + pmfd[jl + klon*(1 + jk + klev*ibl)])*zdtgdp); zsolab = zsolab + zmfdn; @@ -1072,11 +1072,11 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // ZQE=(ZQX(JL,JK,NCLDQV)-ZA(JL,JK)*ZQSMIX(JL,JK))/& // & MAX(ZEPSEC,1.0_JPRB-ZA(JL,JK)) // ZE=ZLDIFDT(JL)*MAX(ZQSMIX(JL,JK)-ZQE,0.0_JPRB) - ze = zldifdt*fmax(zqsmix[jl + klon*(jk + klev*ibl)] - - zqx[jl + klon*(jk + klev*(4 + 5*ibl))], (double) 0.0); + ze = zldifdt*MYMAX(zqsmix[jl + klon*(jk + klev*ibl)] - + zqx[jl + klon*(jk + klev*(4 + 5*ibl))], (dtype) 0.0); zleros = za[jl + klon*(jk + klev*ibl)]*ze; - zleros = fmin(zleros, zevaplimmix); - zleros = fmin(zleros, zli[jl + klon*(jk + klev*ibl)]); + zleros = MYMIN(zleros, zevaplimmix); + zleros = MYMIN(zleros, zli[jl + klon*(jk + klev*ibl)]); zaeros = zleros / zlicld; //if linear term // Erosion is -ve LINEAR in L,A @@ -1109,15 +1109,15 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zdtdp = zrdcp*ztp1[jl + klon*(jk + klev*ibl)] / pap[jl + klon*(jk + klev*ibl)]; zdpmxdt = zdp*zqtmst; - zmfdn = (double) 0.0; + zmfdn = (dtype) 0.0; if (jk + 1 < klev) { zmfdn = pmfu[jl + klon*(1 + jk + klev*ibl)] + pmfd[jl + klon*(1 + jk + klev*ibl)]; } zwtot = pvervel[jl + klon*(jk + klev*ibl)] + - (double) 0.5*rg*(pmfu[jl + klon*(jk + klev*ibl)] + pmfd[jl + klon*(jk + klev*ibl)] + zmfdn); - zwtot = fmin(zdpmxdt, fmax(-zdpmxdt, zwtot)); + (dtype) 0.5*rg*(pmfu[jl + klon*(jk + klev*ibl)] + pmfd[jl + klon*(jk + klev*ibl)] + zmfdn); + zwtot = MYMIN(zdpmxdt, MYMAX(-zdpmxdt, zwtot)); zzzdt = phrsw[jl + klon*(jk + klev*ibl)] + phrlw[jl + klon*(jk + klev*ibl)]; - zdtdiab = fmin(zdpmxdt*zdtdp, fmax(-zdpmxdt*zdtdp, zzzdt))*ptsphy + ralfdcp*zldefr; + zdtdiab = MYMIN(zdpmxdt*zdtdp, MYMAX(-zdpmxdt*zdtdp, zzzdt))*ptsphy + ralfdcp*zldefr; // Note: ZLDEFR should be set to the difference between the mixed phase functions // in the convection and cloud scheme, but this is not calculated, so is zero and // the functions must be the same @@ -1125,42 +1125,42 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zqold = zqsmix[jl + klon*(jk + klev*ibl)]; ztold = ztp1[jl + klon*(jk + klev*ibl)]; ztp1[jl + klon*(jk + klev*ibl)] = ztp1[jl + klon*(jk + klev*ibl)] + zdtforc; - ztp1[jl + klon*(jk + klev*ibl)] = fmax(ztp1[jl + klon*(jk + klev*ibl)], (double) 160.0); + ztp1[jl + klon*(jk + klev*ibl)] = MYMAX(ztp1[jl + klon*(jk + klev*ibl)], (dtype) 160.0); llflag = true; // Formerly a call to CUADJTQ(..., ICALL=5) - zqp = (double) 1.0 / pap[jl + klon*(jk + klev*ibl)]; - zqsat = ((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))* - exp((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4les)) + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))* - exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies)))))*zqp; - zqsat = fmin((double) 0.5, zqsat); - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsat); + zqp = (dtype) 1.0 / pap[jl + klon*(jk + klev*ibl)]; + zqsat = ((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))* + MYEXP((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4les)) + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))* + MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies)))))*zqp; + zqsat = MYMIN((dtype) 0.5, zqsat); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsat); zqsat = zqsat*zcor; zcond = (zqsmix[jl + klon*(jk + klev*ibl)] - zqsat) / - ((double) 1.0 + zqsat*zcor*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/pow(ztp1[jl + klon*(jk + klev*ibl)] - r4les, 2)) + - ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* - (1.0/pow(ztp1[jl + klon*(jk + klev*ibl)] - r4ies, 2))))); + ((dtype) 1.0 + zqsat*zcor*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - + rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/MYPOW(ztp1[jl + klon*(jk + klev*ibl)] - r4les, 2)) + + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* + (1.0/MYPOW(ztp1[jl + klon*(jk + klev*ibl)] - r4ies, 2))))); ztp1[jl + klon*(jk + klev*ibl)] = ztp1[jl + klon*(jk + klev*ibl)] + - ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond; + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond; zqsmix[jl + klon*(jk + klev*ibl)] = zqsmix[jl + klon*(jk + klev*ibl)] - zcond; - zqsat = ((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))* - exp((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4les)) + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))* - exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies)))))*zqp; - zqsat = fmin((double) 0.5, zqsat); - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsat); + zqsat = ((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))* + MYEXP((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4les)) + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))* + MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies)))))*zqp; + zqsat = MYMIN((dtype) 0.5, zqsat); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsat); zqsat = zqsat*zcor; zcond1 = (zqsmix[jl + klon*(jk + klev*ibl)] - zqsat) / - ((double) 1.0 + zqsat*zcor*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - - rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/pow(ztp1[jl + klon*(jk + klev*ibl)] - r4les, 2)) + - ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* - (1.0/pow(ztp1[jl + klon*(jk + klev*ibl)] - r4ies, 2))))); + ((dtype) 1.0 + zqsat*zcor*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - + rtice)*rtwat_rtice_r, 2)))*r5alvcp)*(1.0/MYPOW(ztp1[jl + klon*(jk + klev*ibl)] - r4les, 2)) + + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* + (1.0/MYPOW(ztp1[jl + klon*(jk + klev*ibl)] - r4ies, 2))))); ztp1[jl + klon*(jk + klev*ibl)] = ztp1[jl + klon*(jk + klev*ibl)] + - ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond1; + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond1; zqsmix[jl + klon*(jk + klev*ibl)] = zqsmix[jl + klon*(jk + klev*ibl)] - zcond1; zdqs = zqsmix[jl + klon*(jk + klev*ibl)] - zqold; @@ -1175,14 +1175,14 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Previous function based on DELTA DISTRIBUTION in cloud: - if (zdqs > (double) 0.0) { + if (zdqs > (dtype) 0.0) { // If subsidence evaporation term is turned off, then need to use updated // liquid and cloud here? // ZLEVAP = MAX(ZA(JL,JK)+ZACUST(JL),1.0_JPRB)*MIN(ZDQS(JL),ZLICLD(JL)+ZLFINALSUM(JL)) - zlevap = za[jl + klon*(jk + klev*ibl)]*fmin(zdqs, zlicld); - zlevap = fmin(zlevap, zevaplimmix); - zlevap = fmin(zlevap, fmax(zqsmix[jl + klon*(jk + klev*ibl)] - - zqx[jl + klon*(jk + klev*(4 + 5*ibl))], (double) 0.0)); + zlevap = za[jl + klon*(jk + klev*ibl)]*MYMIN(zdqs, zlicld); + zlevap = MYMIN(zlevap, zevaplimmix); + zlevap = MYMIN(zlevap, MYMAX(zqsmix[jl + klon*(jk + klev*ibl)] - + zqx[jl + klon*(jk + klev*(4 + 5*ibl))], (dtype) 0.0)); // For first guess call zlevapl = zliqfrac[jl + klon*(jk + klev*ibl)]*zlevap; @@ -1203,27 +1203,27 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // (1) Increase of cloud water in existing clouds if (za[jl + klon*(jk + klev*ibl)] > zepsec && zdqs <= -(*yrecldp).rlmin) { - zlcond1 = fmax(-zdqs, (double) 0.0); //new limiter + zlcond1 = MYMAX(-zdqs, (dtype) 0.0); //new limiter //old limiter (significantly improves upper tropospheric humidity rms) - if (za[jl + klon*(jk + klev*ibl)] > (double) 0.99) { - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsmix[jl + klon*(jk + klev*ibl)]); + if (za[jl + klon*(jk + klev*ibl)] > (dtype) 0.99) { + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsmix[jl + klon*(jk + klev*ibl)]); zcdmax = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - zqsmix[jl + klon*(jk + klev*ibl)]) / - ((double) 1.0 + zcor*zqsmix[jl + klon*(jk + klev*ibl)]*((double)(((double) - (fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* - (1.0/pow(ztp1[jl + klon*(jk + klev*ibl)] - r4les, 2)) + - ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))) - *r5alscp)*(1.0/pow(ztp1[jl + klon*(jk + klev*ibl)] - r4ies, 2))))); + ((dtype) 1.0 + zcor*zqsmix[jl + klon*(jk + klev*ibl)]*((dtype)(((dtype) + (MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* + (1.0/MYPOW(ztp1[jl + klon*(jk + klev*ibl)] - r4les, 2)) + + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jl + klon*(jk + klev*ibl)])) - rtice)*rtwat_rtice_r, 2)))) + *r5alscp)*(1.0/MYPOW(ztp1[jl + klon*(jk + klev*ibl)] - r4ies, 2))))); } else { zcdmax = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - za[jl + klon*(jk + klev*ibl)]*zqsmix[jl + klon*(jk + klev*ibl)]) / za[jl + klon*(jk + klev*ibl)]; } - zlcond1 = fmax(fmin(zlcond1, zcdmax), (double) 0.0); + zlcond1 = MYMAX(MYMIN(zlcond1, zcdmax), (dtype) 0.0); // end old limiter zlcond1 = za[jl + klon*(jk + klev*ibl)]*zlcond1; if (zlcond1 < (*yrecldp).rlmin) { - zlcond1 = (double) 0.0; + zlcond1 = (dtype) 0.0; } //------------------------------------------------------------------------- @@ -1245,7 +1245,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // (2) Generation of new clouds (da/dt>0) - if (zdqs <= -(*yrecldp).rlmin && za[jl + klon*(jk + klev*ibl)] < (double) 1.0 - zepsec) { + if (zdqs <= -(*yrecldp).rlmin && za[jl + klon*(jk + klev*ibl)] < (dtype) 1.0 - zepsec) { //--------------------------- // Critical relative humidity @@ -1253,9 +1253,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zrhc = (*yrecldp).ramid; zsigk = pap[jl + klon*(jk + klev*ibl)] / paph[jl + klon*(klev + (klev + 1)*ibl)]; // Increase RHcrit to 1.0 towards the surface (eta>0.8) - if (zsigk > (double) 0.8) { - zrhc = (*yrecldp).ramid + ((double) 1.0 - (*yrecldp).ramid)*(pow(((zsigk - (double) 0.8) / - (double) 0.2), 2)); + if (zsigk > (dtype) 0.8) { + zrhc = (*yrecldp).ramid + ((dtype) 1.0 - (*yrecldp).ramid)*(MYPOW(((zsigk - (dtype) 0.8) / + (dtype) 0.2), 2)); } // Commented out for CY37R1 to reduce humidity in high trop and strat @@ -1271,14 +1271,14 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if ((*yrecldp).nssopt == 0) { // No scheme zqe = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - za[jl + klon*(jk + klev*ibl)]* - zqsice[jl + klon*(jk + klev*ibl)]) / fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); - zqe = fmax((double) 0.0, zqe); + zqsice[jl + klon*(jk + klev*ibl)]) / MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zqe = MYMAX((dtype) 0.0, zqe); } else if ((*yrecldp).nssopt == 1) { // Tompkins zqe = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - za[jl + klon*(jk + klev*ibl)]* - zqsice[jl + klon*(jk + klev*ibl)]) / fmax(zepsec, (double) 1.0 - + zqsice[jl + klon*(jk + klev*ibl)]) / MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); - zqe = fmax((double) 0.0, zqe); + zqe = MYMAX((dtype) 0.0, zqe); } else if ((*yrecldp).nssopt == 2) { // Lohmann and Karcher zqe = zqx[jl + klon*(jk + klev*(4 + 5*ibl))]; @@ -1290,7 +1290,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jl + klon*(jk + klev*ibl)] >= rtt || (*yrecldp).nssopt == 0) { // No ice supersaturation allowed - zfac = (double) 1.0; + zfac = (dtype) 1.0; } else { // Ice supersaturation zfac = zfokoop; @@ -1300,34 +1300,34 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zqe < zqsice[jl + klon*(jk + klev*ibl)]*zfac) { // note: not **2 on 1-a term if ZQE is used. // Added correction term ZFAC to numerator 15/03/2010 - zacond = -((double) 1.0 - za[jl + klon*(jk + klev*ibl)])*zfac*zdqs / - fmax((double) 2.0*(zfac*zqsice[jl + klon*(jk + klev*ibl)] - zqe), zepsec); + zacond = -((dtype) 1.0 - za[jl + klon*(jk + klev*ibl)])*zfac*zdqs / + MYMAX((dtype) 2.0*(zfac*zqsice[jl + klon*(jk + klev*ibl)] - zqe), zepsec); - zacond = fmin(zacond, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); //PUT THE LIMITER BACK + zacond = MYMIN(zacond, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); //PUT THE LIMITER BACK // Linear term: // Added correction term ZFAC 15/03/2010 - zlcond2 = -zfac*zdqs*(double) 0.5*zacond; //mine linear + zlcond2 = -zfac*zdqs*(dtype) 0.5*zacond; //mine linear // new limiter formulation - zzdl = (double) 2.0*(zfac*zqsice[jl + klon*(jk + klev*ibl)] - zqe) / - fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zzdl = (dtype) 2.0*(zfac*zqsice[jl + klon*(jk + klev*ibl)] - zqe) / + MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); // Added correction term ZFAC 15/03/2010 if (zfac*zdqs < -zzdl) { // ZLCONDLIM=(ZA(JL,JK)-1.0_JPRB)*ZDQS(JL)-ZQSICE(JL,JK)+ZQX(JL,JK,NCLDQV) - zlcondlim = (za[jl + klon*(jk + klev*ibl)] - (double) 1.0)*zfac*zdqs - zfac* + zlcondlim = (za[jl + klon*(jk + klev*ibl)] - (dtype) 1.0)*zfac*zdqs - zfac* zqsice[jl + klon*(jk + klev*ibl)] + zqx[jl + klon*(jk + klev*(4 + 5*ibl))]; - zlcond2 = fmin(zlcond2, zlcondlim); + zlcond2 = MYMIN(zlcond2, zlcondlim); } - zlcond2 = fmax(zlcond2, (double) 0.0); + zlcond2 = MYMAX(zlcond2, (dtype) 0.0); - if (zlcond2 < (*yrecldp).rlmin || ((double) 1.0 - + if (zlcond2 < (*yrecldp).rlmin || ((dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]) < zepsec) { - zlcond2 = (double) 0.0; - zacond = (double) 0.0; + zlcond2 = (dtype) 0.0; + zacond = (dtype) 0.0; } - if (zlcond2 == (double) 0.0) { - zacond = (double) 0.0; + if (zlcond2 == (dtype) 0.0) { + zacond = (dtype) 0.0; } // Large-scale generation is LINEAR in A and LINEAR in L @@ -1381,7 +1381,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (za[jl + klon*(-1 + jk + klev*ibl)] < (*yrecldp).rcldtopcf && za[jl + klon*(jk + klev*ibl)] >= (*yrecldp).rcldtopcf) { - zcldtopdist = (double) 0.0; + zcldtopdist = (dtype) 0.0; } else { zcldtopdist = zcldtopdist + zdp / (zrho*rg); } @@ -1394,36 +1394,36 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jl + klon*(jk + klev*ibl)] < rtt && zqxfg[0] > (*yrecldp).rlmin) { // T<273K - zvpice = ((double)(r2es*exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ + zvpice = ((dtype)(r2es*MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ (ztp1[jl + klon*(jk + klev*ibl)] - r4ies))))*rv / rd; zvpliq = zvpice*zfokoop; - zicenuclei = (double) 1000.0*exp((double) 12.96*(zvpliq - zvpice) / zvpliq - (double) 0.639); + zicenuclei = (dtype) 1000.0*MYEXP((dtype) 12.96*(zvpliq - zvpice) / zvpliq - (dtype) 0.639); //------------------------------------------------ // 2.4e-2 is conductivity of air // 8.8 = 700**1/3 = density of ice to the third //------------------------------------------------ - zadd = rlstt*(rlstt / (rv*ztp1[jl + klon*(jk + klev*ibl)]) - (double) 1.0) / - ((double) 2.4E-2*ztp1[jl + klon*(jk + klev*ibl)]); + zadd = rlstt*(rlstt / (rv*ztp1[jl + klon*(jk + klev*ibl)]) - (dtype) 1.0) / + ((dtype) 2.4E-2*ztp1[jl + klon*(jk + klev*ibl)]); zbdd = rv*ztp1[jl + klon*(jk + klev*ibl)]*pap[jl + klon*(jk + klev*ibl)] / - ((double) 2.21*zvpice); - zcvds = (double) 7.8*(pow((zicenuclei / zrho), (double) 0.666))*(zvpliq - - zvpice) / ((double) 8.87*(zadd + zbdd)*zvpice); + ((dtype) 2.21*zvpice); + zcvds = (dtype) 7.8*(MYPOW((zicenuclei / zrho), (dtype) 0.666))*(zvpliq - + zvpice) / ((dtype) 8.87*(zadd + zbdd)*zvpice); //----------------------------------------------------- // RICEINIT=1.E-12_JPRB is initial mass of ice particle //----------------------------------------------------- - zice0 = fmax(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); + zice0 = MYMAX(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); //------------------ // new value of ice: //------------------ - zinew = pow(((double) 0.666*zcvds*ptsphy + (pow(zice0, (double) 0.666))), (double) 1.5); + zinew = MYPOW(((dtype) 0.666*zcvds*ptsphy + (MYPOW(zice0, (dtype) 0.666))), (dtype) 1.5); //--------------------------- // grid-mean deposition rate: //--------------------------- - zdepos = fmax(za[jl + klon*(jk + klev*ibl)]*(zinew - zice0), (double) 0.0); + zdepos = MYMAX(za[jl + klon*(jk + klev*ibl)]*(zinew - zice0), (dtype) 0.0); //-------------------------------------------------------------------- // Limit deposition to liquid water amount @@ -1434,7 +1434,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // flux from the clear sky to the cloudy area. We thus rely on the // supersaturation check to clean up any remaining supersaturation //-------------------------------------------------------------------- - zdepos = fmin(zdepos, zqxfg[0]); // limit to liquid water amount + zdepos = MYMIN(zdepos, zqxfg[0]); // limit to liquid water amount //-------------------------------------------------------------------- // At top of cloud, reduce deposition rate near cloud top to account for @@ -1443,9 +1443,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // ZDEPOS = ZDEPOS*MIN(RDEPLIQREFRATE+ZCLDTOPDIST(JL)/RDEPLIQREFDEPTH,1.0_JPRB) // Change to include dependence on ice nuclei concentration // to increase deposition rate with decreasing temperatures - zinfactor = fmin(zicenuclei / (double) 15000., (double) 1.0); - zdepos = zdepos*fmin(zinfactor + ((double) 1.0 - zinfactor)*((*yrecldp).rdepliqrefrate + - zcldtopdist / (*yrecldp).rdepliqrefdepth), (double) 1.0); + zinfactor = MYMIN(zicenuclei / (dtype) 15000., (dtype) 1.0); + zdepos = zdepos*MYMIN(zinfactor + ((dtype) 1.0 - zinfactor)*((*yrecldp).rdepliqrefrate + + zcldtopdist / (*yrecldp).rdepliqrefdepth), (dtype) 1.0); //-------------- // add to matrix @@ -1473,7 +1473,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (za[jl + klon*(-1 + jk + klev*ibl)] < (*yrecldp).rcldtopcf && za[jl + klon*(jk + klev*ibl)] >= (*yrecldp).rcldtopcf) { - zcldtopdist = (double) 0.0; + zcldtopdist = (dtype) 0.0; } else { zcldtopdist = zcldtopdist + zdp / (zrho*rg); } @@ -1486,36 +1486,36 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jl + klon*(jk + klev*ibl)] < rtt && zqxfg[0] > (*yrecldp).rlmin) { // T<273K - zvpice = ((double)(r2es*exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ + zvpice = ((dtype)(r2es*MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ (ztp1[jl + klon*(jk + klev*ibl)] - r4ies))))*rv / rd; zvpliq = zvpice*zfokoop; - zicenuclei = (double) 1000.0*exp((double) 12.96*(zvpliq - zvpice) / zvpliq - (double) 0.639); + zicenuclei = (dtype) 1000.0*MYEXP((dtype) 12.96*(zvpliq - zvpice) / zvpliq - (dtype) 0.639); //----------------------------------------------------- // RICEINIT=1.E-12_JPRB is initial mass of ice particle //----------------------------------------------------- - zice0 = fmax(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); + zice0 = MYMAX(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); // Particle size distribution - ztcg = (double) 1.0; - zfacx1i = (double) 1.0; + ztcg = (dtype) 1.0; + zfacx1i = (dtype) 1.0; zaplusb = (*yrecldp).rcl_apb1*zvpice - (*yrecldp).rcl_apb2*zvpice* ztp1[jl + klon*(jk + klev*ibl)] + pap[jl + klon*(jk + klev*ibl)]* - (*yrecldp).rcl_apb3*(pow(ztp1[jl + klon*(jk + klev*ibl)], (double) 3.)); - zcorrfac = pow(((double) 1.0 / zrho), (double) 0.5); - zcorrfac2 = (pow((ztp1[jl + klon*(jk + klev*ibl)] / (double) 273.0), (double)1.5))* - ((double) 393.0 / (ztp1[jl + klon*(jk + klev*ibl)] + (double) 120.0)); + (*yrecldp).rcl_apb3*(MYPOW(ztp1[jl + klon*(jk + klev*ibl)], (dtype) 3.)); + zcorrfac = MYPOW(((dtype) 1.0 / zrho), (dtype) 0.5); + zcorrfac2 = (MYPOW((ztp1[jl + klon*(jk + klev*ibl)] / (dtype) 273.0), (dtype)1.5))* + ((dtype) 393.0 / (ztp1[jl + klon*(jk + klev*ibl)] + (dtype) 120.0)); zpr02 = zrho*zice0*(*yrecldp).rcl_const1i / (ztcg*zfacx1i); - zterm1 = (zvpliq - zvpice)*(pow(ztp1[jl + klon*(jk + klev*ibl)], (double) 2.0))* + zterm1 = (zvpliq - zvpice)*(MYPOW(ztp1[jl + klon*(jk + klev*ibl)], (dtype) 2.0))* zvpice*zcorrfac2*ztcg*(*yrecldp).rcl_const2i*zfacx1i / (zrho*zaplusb*zvpice); - zterm2 = (double) 0.65*(*yrecldp).rcl_const6i*(pow(zpr02, (*yrecldp).rcl_const4i)) + - (*yrecldp).rcl_const3i*(pow(zcorrfac, (double) 0.5))*(pow(zrho, (double) 0.5))* - (pow(zpr02, (*yrecldp).rcl_const5i)) / (pow(zcorrfac2, (double) 0.5)); + zterm2 = (dtype) 0.65*(*yrecldp).rcl_const6i*(MYPOW(zpr02, (*yrecldp).rcl_const4i)) + + (*yrecldp).rcl_const3i*(MYPOW(zcorrfac, (dtype) 0.5))*(MYPOW(zrho, (dtype) 0.5))* + (MYPOW(zpr02, (*yrecldp).rcl_const5i)) / (MYPOW(zcorrfac2, (dtype) 0.5)); - zdepos = fmax(za[jl + klon*(jk + klev*ibl)]*zterm1*zterm2*ptsphy, (double) 0.0); + zdepos = MYMAX(za[jl + klon*(jk + klev*ibl)]*zterm1*zterm2*ptsphy, (dtype) 0.0); //-------------------------------------------------------------------- // Limit deposition to liquid water amount @@ -1526,7 +1526,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // flux from the clear sky to the cloudy area. We thus rely on the // supersaturation check to clean up any remaining supersaturation //-------------------------------------------------------------------- - zdepos = fmin(zdepos, zqxfg[0]); // limit to liquid water amount + zdepos = MYMIN(zdepos, zqxfg[0]); // limit to liquid water amount //-------------------------------------------------------------------- // At top of cloud, reduce deposition rate near cloud top to account for @@ -1534,9 +1534,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------------------- // Change to include dependence on ice nuclei concentration // to increase deposition rate with decreasing temperatures - zinfactor = fmin(zicenuclei / (double) 15000., (double) 1.0); - zdepos = zdepos*fmin(zinfactor + ((double) 1.0 - zinfactor)* - ((*yrecldp).rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (double) 1.0); + zinfactor = MYMIN(zicenuclei / (dtype) 15000., (dtype) 1.0); + zdepos = zdepos*MYMIN(zinfactor + ((dtype) 1.0 - zinfactor)* + ((*yrecldp).rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (dtype) 1.0); //-------------- // add to matrix @@ -1557,7 +1557,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------- // revise in-cloud consensate amount //---------------------------------- - ztmpa = (double) 1.0 / fmax(za[jl + klon*(jk + klev*ibl)], zepsec); + ztmpa = (dtype) 1.0 / MYMAX(za[jl + klon*(jk + klev*ibl)], zepsec); zliqcld = zqxfg[0]*ztmpa; zicecld = zqxfg[1]*ztmpa; zlicld = zliqcld + zicecld; @@ -1590,7 +1590,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zre_ice = pre_ice[jl + klon*(jk + klev*ibl)]; // The exponent value is from // Morrison et al. JAS 2005 Appendix - zvqx[1] = (double) 0.002*(pow(zre_ice, (double) 1.0)); + zvqx[1] = (dtype) 0.002*(MYPOW(zre_ice, (dtype) 1.0)); } zfall = zvqx[jm]*zrho; //------------------------------------------------- @@ -1624,20 +1624,20 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // zero. //--------------------------------------------------------------- if (zqpretot > zepsec) { - zcovptot = (double) 1.0 - (((double) 1.0 - zcovptot)*((double) 1.0 - - fmax(za[jl + klon*(jk + klev*ibl)], za[jl + klon*(-1 + jk + klev*ibl)])) / - ((double) 1.0 - fmin(za[jl + klon*(-1 + jk + klev*ibl)], (double) 1.0 - (double) 1.E-06))); - zcovptot = fmax(zcovptot, (*yrecldp).rcovpmin); - zcovpclr = fmax((double) 0.0, zcovptot - za[jl + klon*(jk + klev*ibl)]); // clear sky proportion + zcovptot = (dtype) 1.0 - (((dtype) 1.0 - zcovptot)*((dtype) 1.0 - + MYMAX(za[jl + klon*(jk + klev*ibl)], za[jl + klon*(-1 + jk + klev*ibl)])) / + ((dtype) 1.0 - MYMIN(za[jl + klon*(-1 + jk + klev*ibl)], (dtype) 1.0 - (dtype) 1.E-06))); + zcovptot = MYMAX(zcovptot, (*yrecldp).rcovpmin); + zcovpclr = MYMAX((dtype) 0.0, zcovptot - za[jl + klon*(jk + klev*ibl)]); // clear sky proportion zraincld = zqxfg[2] / zcovptot; zsnowcld = zqxfg[3] / zcovptot; - zcovpmax = fmax(zcovptot, zcovpmax); + zcovpmax = MYMAX(zcovptot, zcovpmax); } else { - zraincld = (double) 0.0; - zsnowcld = (double) 0.0; - zcovptot = (double) 0.0; // no flux - reset cover - zcovpclr = (double) 0.0; // reset clear sky proportion - zcovpmax = (double) 0.0; // reset max cover for ZZRH calc + zraincld = (dtype) 0.0; + zsnowcld = (dtype) 0.0; + zcovptot = (dtype) 0.0; // no flux - reset cover + zcovpclr = (dtype) 0.0; // reset clear sky proportion + zcovpmax = (dtype) 0.0; // reset max cover for ZZRH calc } //---------------------------------------------------------------------- @@ -1650,18 +1650,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------------- if (zicecld > zepsec) { - zzco = ptsphy*(*yrecldp).rsnowlin1*exp((*yrecldp).rsnowlin2* + zzco = ptsphy*(*yrecldp).rsnowlin1*MYEXP((*yrecldp).rsnowlin2* (ztp1[jl + klon*(jk + klev*ibl)] - rtt)); if ((*yrecldp).laericeauto) { zlcrit = picrit_aer[jl + klon*(jk + klev*ibl)]; // 0.3 = N**0.333 with N=0.027 - zzco = zzco*(pow(((*yrecldp).rnice / pnice[jl + klon*(jk + klev*ibl)]), (double) 0.333)); + zzco = zzco*(MYPOW(((*yrecldp).rnice / pnice[jl + klon*(jk + klev*ibl)]), (dtype) 0.333)); } else { zlcrit = (*yrecldp).rlcritsnow; } - zsnowaut = zzco*((double) 1.0 - exp(-(pow((zicecld / zlcrit), 2)))); + zsnowaut = zzco*((dtype) 1.0 - MYEXP(-(MYPOW((zicecld / zlcrit), 2)))); zsolqb[3 + 5*(1)] = zsolqb[3 + 5*(1)] + zsnowaut; } @@ -1687,12 +1687,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if ((*yrecldp).laerliqautolsp) { zlcrit = plcrit_aer[jl + klon*(jk + klev*ibl)]; // 0.3 = N**0.333 with N=125 cm-3 - zzco = zzco*(pow(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), (double) 0.333)); + zzco = zzco*(MYPOW(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), (dtype) 0.333)); } else { // Modify autoconversion threshold dependent on: // land (polluted, high CCN, smaller droplets, higher threshold) // sea (clean, low CCN, larger droplets, lower threshold) - if (plsm[jl + klon*ibl] > (double) 0.5) { + if (plsm[jl + klon*ibl] > (dtype) 0.5) { zlcrit = (*yrecldp).rclcrit_land; // land } else { zlcrit = (*yrecldp).rclcrit_sea; // ocean @@ -1705,22 +1705,22 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to REPLACE this with an explicit collection parametrization //------------------------------------------------------------------ zprecip = (zpfplsx[jl + klon*(jk + (klev + 1)*(3 + 5*ibl))] + - zpfplsx[jl + klon*(jk + (klev + 1)*(2 + 5*ibl))]) / fmax(zepsec, zcovptot); - zcfpr = (double) 1.0 + (*yrecldp).rprc1*sqrt(fmax(zprecip, (double) 0.0)); + zpfplsx[jl + klon*(jk + (klev + 1)*(2 + 5*ibl))]) / MYMAX(zepsec, zcovptot); + zcfpr = (dtype) 1.0 + (*yrecldp).rprc1*sqrt(MYMAX(zprecip, (dtype) 0.0)); // ZCFPR=1.0_JPRB + RPRC1*SQRT(MAX(ZPRECIP,0.0_JPRB))*& // &ZCOVPTOT(JL)/(MAX(ZA(JL,JK),ZEPSEC)) if ((*yrecldp).laerliqcoll) { // 5.0 = N**0.333 with N=125 cm-3 - zcfpr = zcfpr*(pow(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), (double) 0.333)); + zcfpr = zcfpr*(MYPOW(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), (dtype) 0.333)); } zzco = zzco*zcfpr; - zlcrit = zlcrit / fmax(zcfpr, zepsec); + zlcrit = zlcrit / MYMAX(zcfpr, zepsec); - if (zliqcld / zlcrit < (double) 20.0) { + if (zliqcld / zlcrit < (dtype) 20.0) { // Security for exp for some compilers - zrainaut = zzco*((double) 1.0 - exp(-(pow((zliqcld / zlcrit), 2)))); + zrainaut = zzco*((dtype) 1.0 - MYEXP(-(MYPOW((zliqcld / zlcrit), 2)))); } else { zrainaut = zzco; } @@ -1739,7 +1739,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------- } else if (iwarmrain == 2) { - if (plsm[jl + klon*ibl] > (double) 0.5) { + if (plsm[jl + klon*ibl] > (dtype) 0.5) { // land zconst = (*yrecldp).rcl_kk_cloud_num_land; zlcrit = (*yrecldp).rclcrit_land; @@ -1751,26 +1751,26 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zliqcld > zlcrit) { - zrainaut = (double) 1.5*za[jl + klon*(jk + klev*ibl)]*ptsphy* - (*yrecldp).rcl_kkaau*(pow(zliqcld, (*yrecldp).rcl_kkbauq))* - (pow(zconst, (*yrecldp).rcl_kkbaun)); + zrainaut = (dtype) 1.5*za[jl + klon*(jk + klev*ibl)]*ptsphy* + (*yrecldp).rcl_kkaau*(MYPOW(zliqcld, (*yrecldp).rcl_kkbauq))* + (MYPOW(zconst, (*yrecldp).rcl_kkbaun)); - zrainaut = fmin(zrainaut, zqxfg[0]); + zrainaut = MYMIN(zrainaut, zqxfg[0]); if (zrainaut < zepsec) { - zrainaut = (double) 0.0; + zrainaut = (dtype) 0.0; } - zrainacc = (double) 2.0*za[jl + klon*(jk + klev*ibl)]*ptsphy*(*yrecldp).rcl_kkaac* - (pow((zliqcld*zraincld), (*yrecldp).rcl_kkbac)); + zrainacc = (dtype) 2.0*za[jl + klon*(jk + klev*ibl)]*ptsphy*(*yrecldp).rcl_kkaac* + (MYPOW((zliqcld*zraincld), (*yrecldp).rcl_kkbac)); - zrainacc = fmin(zrainacc, zqxfg[0]); + zrainacc = MYMIN(zrainacc, zqxfg[0]); if (zrainacc < zepsec) { - zrainacc = (double) 0.0; + zrainacc = (dtype) 0.0; } } else { - zrainaut = (double) 0.0; - zrainacc = (double) 0.0; + zrainaut = (dtype) 0.0; + zrainacc = (dtype) 0.0; } // If temperature < 0, then autoconversion produces snow rather than rain @@ -1804,20 +1804,20 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jl + klon*(jk + klev*ibl)] <= rtt && zliqcld > zepsec) { // Fallspeed air density correction - zfallcorr = pow(((*yrecldp).rdensref / zrho), (double) 0.4); + zfallcorr = MYPOW(((*yrecldp).rdensref / zrho), (dtype) 0.4); //------------------------------------------------------------------ // Riming of snow by cloud water - implicit in lwc //------------------------------------------------------------------ - if (zsnowcld > zepsec && zcovptot > (double) 0.01) { + if (zsnowcld > zepsec && zcovptot > (dtype) 0.01) { // Calculate riming term // Factor of liq water taken out because implicit - zsnowrime = (double) 0.3*zcovptot*ptsphy*(*yrecldp).rcl_const7s* - zfallcorr*(pow((zrho*zsnowcld*(*yrecldp).rcl_const1s), (*yrecldp).rcl_const8s)); + zsnowrime = (dtype) 0.3*zcovptot*ptsphy*(*yrecldp).rcl_const7s* + zfallcorr*(MYPOW((zrho*zsnowcld*(*yrecldp).rcl_const1s), (*yrecldp).rcl_const8s)); // Limit snow riming term - zsnowrime = fmin(zsnowrime, (double) 1.0); + zsnowrime = MYMIN(zsnowrime, (dtype) 1.0); zsolqb[3 + 5*(0)] = zsolqb[3 + 5*(0)] + zsnowrime; @@ -1855,14 +1855,14 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------------------------------------------- zicetot = zqxfg[1] + zqxfg[3]; - zmeltmax = (double) 0.0; + zmeltmax = (dtype) 0.0; // If there are frozen hydrometeors present and dry-bulb temperature > 0degC if (zicetot > zepsec && ztp1[jl + klon*(jk + klev*ibl)] > rtt) { // Calculate subsaturation - zsubsat = fmax(zqsice[jl + klon*(jk + klev*ibl)] - - zqx[jl + klon*(jk + klev*(4 + 5*ibl))], (double) 0.0); + zsubsat = MYMAX(zqsice[jl + klon*(jk + klev*ibl)] - + zqx[jl + klon*(jk + klev*(4 + 5*ibl))], (dtype) 0.0); // Calculate difference between dry-bulb (ZTP1) and the temperature // at which the wet-bulb=0degC (RTT-ZSUBSAT*....) using an approx. @@ -1873,8 +1873,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, ztw4*(ztp1[jl + klon*(jk + klev*ibl)] - ztw5)); // Not implicit yet... // Ensure ZCONS1 is positive so that ZMELTMAX=0 if ZTDMTW0<0 - zcons1 = fabs(ptsphy*((double) 1.0 + (double) 0.5*ztdmtw0) / (*yrecldp).rtaumel); - zmeltmax = fmax(ztdmtw0*zcons1*zrldcp, (double) 0.0); + zcons1 = MYABS(ptsphy*((dtype) 1.0 + (dtype) 0.5*ztdmtw0) / (*yrecldp).rtaumel); + zmeltmax = MYMAX(ztdmtw0*zcons1*zrldcp, (dtype) 0.0); } // Loop over frozen hydrometeors (ice, snow) @@ -1884,7 +1884,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zmeltmax > zepsec && zicetot > zepsec) { // Apply melting in same proportion as frozen hydrometeor fractions zalfa = zqxfg[jm] / zicetot; - zmelt = fmin(zqxfg[jm], zalfa*zmeltmax); + zmelt = MYMIN(zqxfg[jm], zalfa*zmeltmax); // needed in first guess // This implies that zqpretot has to be recalculated below // since is not conserved here if ice falls and liquid doesn't @@ -1908,7 +1908,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // store rain/snow fraction for precip type diagnosis // If mostly rain, then supercooled rain slow to freeze // otherwise faster to freeze (snow or ice pellets) - zqpretot = fmax(zqx[jl + klon*(jk + klev*(3 + 5*ibl))] + + zqpretot = MYMAX(zqx[jl + klon*(jk + klev*(3 + 5*ibl))] + zqx[jl + klon*(jk + klev*(2 + 5*ibl))], zepsec); prainfrac_toprfz[jl + klon*ibl] = zqx[jl + klon*(jk + klev*(2 + 5*ibl))] / zqpretot; if (prainfrac_toprfz[jl + klon*ibl] > 0.8) { @@ -1927,28 +1927,28 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Refreezing is by slow heterogeneous freezing // Slope of rain particle size distribution - zlambda = pow(((*yrecldp).rcl_fac1 / (zrho*zqx[jl + klon*(jk + klev*(2 +5*ibl))])), + zlambda = MYPOW(((*yrecldp).rcl_fac1 / (zrho*zqx[jl + klon*(jk + klev*(2 +5*ibl))])), (*yrecldp).rcl_fac2); // Calculate freezing rate based on Bigg(1953) and Wisner(1972) ztemp = (*yrecldp).rcl_fzrab*(ztp1[jl + klon*(jk + klev*ibl)] - rtt); - zfrz = ptsphy*((*yrecldp).rcl_const5r / zrho)*(exp(ztemp) - - (double) 1.)*(pow(zlambda, (*yrecldp).rcl_const6r)); - zfrzmax = fmax(zfrz, (double) 0.0); + zfrz = ptsphy*((*yrecldp).rcl_const5r / zrho)*(MYEXP(ztemp) - + (dtype) 1.)*(MYPOW(zlambda, (*yrecldp).rcl_const6r)); + zfrzmax = MYMAX(zfrz, (dtype) 0.0); } else { // Majority of raindrops only partially melted // Refreeze with a shorter timescale (reverse of melting...for now) - zcons1 = fabs(ptsphy*((double) 1.0 + (double) 0.5*(rtt - + zcons1 = MYABS(ptsphy*((dtype) 1.0 + (dtype) 0.5*(rtt - ztp1[jl + klon*(jk + klev*ibl)])) / (*yrecldp).rtaumel); - zfrzmax = fmax((rtt - ztp1[jl + klon*(jk + klev*ibl)])*zcons1*zrldcp, (double) 0.0); + zfrzmax = MYMAX((rtt - ztp1[jl + klon*(jk + klev*ibl)])*zcons1*zrldcp, (dtype) 0.0); } if (zfrzmax > zepsec) { - zfrz = fmin(zqx[jl + klon*(jk + klev*(2 + 5*ibl))], zfrzmax); + zfrz = MYMIN(zqx[jl + klon*(jk + klev*(2 + 5*ibl))], zfrzmax); zsolqa[3 + 5*(2)] = zsolqa[3 + 5*(2)] + zfrz; zsolqa[2 + 5*(3)] = zsolqa[2 + 5*(3)] - zfrz; } @@ -1961,12 +1961,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 4.4c FREEZING of LIQUID //---------------------------------------------------------------------- // not implicit yet... - zfrzmax = fmax(((*yrecldp).rthomo - ztp1[jl + klon*(jk + klev*ibl)])*zrldcp, (double) 0.0); + zfrzmax = MYMAX(((*yrecldp).rthomo - ztp1[jl + klon*(jk + klev*ibl)])*zrldcp, (dtype) 0.0); jm = 1; jn = imelt[-1 + jm]; if (zfrzmax > zepsec && zqxfg[-1 + jm] > zepsec) { - zfrz = fmin(zqxfg[-1 + jm], zfrzmax); + zfrz = MYMIN(zqxfg[-1 + jm], zfrzmax); zsolqa[-1 + jn + 5*(-1 + jm)] = zsolqa[-1 + jn + 5*(-1 + jm)] + zfrz; zsolqa[-1 + jm + 5*(-1 + jn)] = zsolqa[-1 + jm + 5*(-1 + jn)] - zfrz; } @@ -1983,32 +1983,32 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Rain - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); zqe = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - za[jl + klon*(jk + klev*ibl)]* - zqsliq[jl + klon*(jk + klev*ibl)]) / fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zqsliq[jl + klon*(jk + klev*ibl)]) / MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsliq[jl + klon*(jk + klev*ibl)])); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsliq[jl + klon*(jk + klev*ibl)])); llo1 = zcovpclr > zepsec && zqxfg[2] > zepsec && zqe < zzrh*zqsliq[jl + klon*(jk + klev*ibl)]; if (llo1) { // note: zpreclr is a rain flux - zpreclr = zqxfg[2]*zcovpclr / copysign(fmax(fabs(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); + zpreclr = zqxfg[2]*zcovpclr / copysign(MYMAX(MYABS(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); //-------------------------------------- // actual microphysics formula in zbeta //-------------------------------------- zbeta1 = sqrt(pap[jl + klon*(jk + klev*ibl)] / paph[jl + klon*(klev + (klev + 1)*ibl)]) / - (*yrecldp).rvrfactor*zpreclr / fmax(zcovpclr, zepsec); + (*yrecldp).rvrfactor*zpreclr / MYMAX(zcovpclr, zepsec); - zbeta = rg*(*yrecldp).rpecons*(double) 0.5*(pow(zbeta1, (double) 0.5777)); + zbeta = rg*(*yrecldp).rpecons*(dtype) 0.5*(MYPOW(zbeta1, (dtype) 0.5777)); - zdenom = (double) 1.0 + zbeta*ptsphy*zcorqsliq; + zdenom = (dtype) 1.0 + zbeta*ptsphy*zcorqsliq; zdpr = zcovpclr*zbeta*(zqsliq[jl + klon*(jk + klev*ibl)] - zqe) / zdenom*zdp*zrg_r; zdpevap = zdpr*zdtgdp; @@ -2020,7 +2020,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Evaporate rain - zevap = fmin(zdpevap, zqxfg[2]); + zevap = MYMIN(zdpevap, zqxfg[2]); zsolqa[4 + 5*(2)] = zsolqa[4 + 5*(2)] + zevap; zsolqa[2 + 5*(4)] = zsolqa[2 + 5*(4)] - zevap; @@ -2030,7 +2030,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jl + klon*(jk + klev*ibl)])*zevap / zqxfg[2])); // Update fg field @@ -2050,9 +2050,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to avoid cloud formation and saturation of the grid box //----------------------------------------------------------------------- // Limit RH for rain evaporation dependent on precipitation fraction - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); // Critical relative humidity //ZRHC=RAMID @@ -2064,9 +2064,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //ZZRH = MIN(ZRHC,ZZRH) // Further limit RH for rain evaporation to 80% (RHcrit in free troposphere) - zzrh = fmin((double) 0.8, zzrh); + zzrh = MYMIN((dtype) 0.8, zzrh); - zqe = fmax((double) 0.0, fmin(zqx[jl + klon*(jk + klev*(4 + 5*ibl))], + zqe = MYMAX((dtype) 0.0, MYMIN(zqx[jl + klon*(jk + klev*(4 + 5*ibl))], zqsliq[jl + klon*(jk + klev*ibl)])); llo1 = zcovpclr > zepsec && zqxfg[2] > zepsec && @@ -2081,33 +2081,33 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zpreclr = zqxfg[2] / zcovptot; // Fallspeed air density correction - zfallcorr = pow(((*yrecldp).rdensref / zrho), 0.4); + zfallcorr = MYPOW(((*yrecldp).rdensref / zrho), 0.4); // Saturation vapour pressure with respect to liquid phase - zesatliq = rv / rd*((double)(r2es*exp((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ + zesatliq = rv / rd*((dtype)(r2es*MYEXP((r3les*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/ (ztp1[jl + klon*(jk + klev*ibl)] - r4les)))); // Slope of particle size distribution - zlambda = pow(((*yrecldp).rcl_fac1 / (zrho*zpreclr)), (*yrecldp).rcl_fac2); // ZPRECLR=kg/kg + zlambda = MYPOW(((*yrecldp).rcl_fac1 / (zrho*zpreclr)), (*yrecldp).rcl_fac2); // ZPRECLR=kg/kg zevap_denom = (*yrecldp).rcl_cdenom1*zesatliq - (*yrecldp).rcl_cdenom2* ztp1[jl + klon*(jk + klev*ibl)]*zesatliq + (*yrecldp).rcl_cdenom3* - (pow(ztp1[jl + klon*(jk + klev*ibl)], (double) 3.))*pap[jl + klon*(jk + klev*ibl)]; + (MYPOW(ztp1[jl + klon*(jk + klev*ibl)], (dtype) 3.))*pap[jl + klon*(jk + klev*ibl)]; // Temperature dependent conductivity - zcorr2 = (pow((ztp1[jl + klon*(jk + klev*ibl)] / (double) 273.), (double) 1.5))*(double) 393. / - (ztp1[jl + klon*(jk + klev*ibl)] + (double) 120.); + zcorr2 = (MYPOW((ztp1[jl + klon*(jk + klev*ibl)] / (dtype) 273.), (dtype) 1.5))*(dtype) 393. / + (ztp1[jl + klon*(jk + klev*ibl)] + (dtype) 120.); zka = (*yrecldp).rcl_ka273*zcorr2; - zsubsat = fmax(zzrh*zqsliq[jl + klon*(jk + klev*ibl)] - zqe, (double) 0.0); + zsubsat = MYMAX(zzrh*zqsliq[jl + klon*(jk + klev*ibl)] - zqe, (dtype) 0.0); - zbeta = ((double) 0.5 / zqsliq[jl + klon*(jk + klev*ibl)])* - (pow(ztp1[jl + klon*(jk + klev*ibl)], (double) 2.))*zesatliq*(*yrecldp).rcl_const1r*(zcorr2 / - zevap_denom)*((double) 0.78 / (pow(zlambda, (*yrecldp).rcl_const4r)) + - (*yrecldp).rcl_const2r*(pow((zrho*zfallcorr), (double) 0.5)) / ((pow(zcorr2, - (double) 0.5))*(pow(zlambda, (*yrecldp).rcl_const3r)))); + zbeta = ((dtype) 0.5 / zqsliq[jl + klon*(jk + klev*ibl)])* + (MYPOW(ztp1[jl + klon*(jk + klev*ibl)], (dtype) 2.))*zesatliq*(*yrecldp).rcl_const1r*(zcorr2 / + zevap_denom)*((dtype) 0.78 / (MYPOW(zlambda, (*yrecldp).rcl_const4r)) + + (*yrecldp).rcl_const2r*(MYPOW((zrho*zfallcorr), (dtype) 0.5)) / ((MYPOW(zcorr2, + (dtype) 0.5))*(MYPOW(zlambda, (*yrecldp).rcl_const3r)))); - zdenom = (double) 1.0 + zbeta*ptsphy; //*ZCORQSLIQ(JL) + zdenom = (dtype) 1.0 + zbeta*ptsphy; //*ZCORQSLIQ(JL) zdpevap = zcovpclr*zbeta*ptsphy*zsubsat / zdenom; //--------------------------------------------------------- @@ -2118,7 +2118,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Limit rain evaporation - zevap = fmin(zdpevap, zqxfg[2]); + zevap = MYMIN(zdpevap, zqxfg[2]); zsolqa[4 + 5*(2)] = zsolqa[4 + 5*(2)] + zevap; zsolqa[2 + 5*(4)] = zsolqa[2 + 5*(4)] - zevap; @@ -2128,7 +2128,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, (zcovptot - + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jl + klon*(jk + klev*ibl)])*zevap / zqxfg[2])); // Update fg field @@ -2145,33 +2145,33 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Snow if (ievapsnow == 1) { - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); zqe = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - za[jl + klon*(jk + klev*ibl)]* - zqsice[jl + klon*(jk + klev*ibl)]) / fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zqsice[jl + klon*(jk + klev*ibl)]) / MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsice[jl + klon*(jk + klev*ibl)])); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsice[jl + klon*(jk + klev*ibl)])); llo1 = zcovpclr > zepsec && zqxfg[3] > zepsec && zqe < zzrh*zqsice[jl + klon*(jk + klev*ibl)]; if (llo1) { // note: zpreclr is a rain flux a - zpreclr = zqxfg[3]*zcovpclr / copysign(fmax(fabs(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); + zpreclr = zqxfg[3]*zcovpclr / copysign(MYMAX(MYABS(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); //-------------------------------------- // actual microphysics formula in zbeta //-------------------------------------- zbeta1 = sqrt(pap[jl + klon*(jk + klev*ibl)] / paph[jl + klon*(klev + (klev + 1)*ibl)]) / - (*yrecldp).rvrfactor*zpreclr / fmax(zcovpclr, zepsec); + (*yrecldp).rvrfactor*zpreclr / MYMAX(zcovpclr, zepsec); - zbeta = rg*(*yrecldp).rpecons*(pow(zbeta1, (double) 0.5777)); + zbeta = rg*(*yrecldp).rpecons*(MYPOW(zbeta1, (dtype) 0.5777)); - zdenom = (double) 1.0 + zbeta*ptsphy*zcorqsice; + zdenom = (dtype) 1.0 + zbeta*ptsphy*zcorqsice; zdpr = zcovpclr*zbeta*(zqsice[jl + klon*(jk + klev*ibl)] - zqe) / zdenom*zdp*zrg_r; zdpevap = zdpr*zdtgdp; @@ -2183,7 +2183,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Evaporate snow - zevap = fmin(zdpevap, zqxfg[3]); + zevap = MYMIN(zdpevap, zqxfg[3]); zsolqa[4 + 5*(3)] = zsolqa[4 + 5*(3)] + zevap; zsolqa[3 + 5*(4)] = zsolqa[3 + 5*(4)] - zevap; @@ -2193,7 +2193,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, (zcovptot - + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jl + klon*(jk + klev*ibl)])*zevap / zqxfg[3])); //Update first guess field @@ -2208,16 +2208,16 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------------------------------- // Calculate relative humidity limit for snow evaporation //----------------------------------------------------------------------- - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / - fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax)*zcovpmax / + MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); zqe = (zqx[jl + klon*(jk + klev*(4 + 5*ibl))] - za[jl + klon*(jk + klev*ibl)]* - zqsice[jl + klon*(jk + klev*ibl)]) / fmax(zepsec, (double) 1.0 - za[jl + klon*(jk + klev*ibl)]); + zqsice[jl + klon*(jk + klev*ibl)]) / MYMAX(zepsec, (dtype) 1.0 - za[jl + klon*(jk + klev*ibl)]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsice[jl + klon*(jk + klev*ibl)])); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsice[jl + klon*(jk + klev*ibl)])); llo1 = zcovpclr > zepsec && zqx[jl + klon*(jk + klev*(3 + 5*ibl))] > zepsec && zqe < zzrh*zqsice[jl + klon*(jk + klev*ibl)]; @@ -2225,36 +2225,36 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Calculate local precipitation (kg/kg) zpreclr = zqx[jl + klon*(jk + klev*(3 + 5*ibl))] / zcovptot; - zvpice = ((double)(r2es*exp((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies))))*rv / rd; + zvpice = ((dtype)(r2es*MYEXP((r3ies*(ztp1[jl + klon*(jk + klev*ibl)] - rtt))/(ztp1[jl + klon*(jk + klev*ibl)] - r4ies))))*rv / rd; // Particle size distribution // ZTCG increases Ni with colder temperatures - essentially a // Fletcher or Meyers scheme? - ztcg = (double) 1.0; //v1 EXP(RCL_X3I*(273.15_JPRB-ZTP1(JL,JK))/8.18_JPRB) + ztcg = (dtype) 1.0; //v1 EXP(RCL_X3I*(273.15_JPRB-ZTP1(JL,JK))/8.18_JPRB) // ZFACX1I modification is based on Andrew Barrett's results - zfacx1s = (double) 1.0; //v1 (ZICE0/1.E-5_JPRB)**0.627_JPRB + zfacx1s = (dtype) 1.0; //v1 (ZICE0/1.E-5_JPRB)**0.627_JPRB zaplusb = (*yrecldp).rcl_apb1*zvpice - (*yrecldp).rcl_apb2*zvpice* ztp1[jl + klon*(jk + klev*ibl)] + pap[jl + klon*(jk + klev*ibl)]*(*yrecldp).rcl_apb3* - (pow(ztp1[jl + klon*(jk + klev*ibl)], 3)); - zcorrfac = pow((1.0 / zrho), 0.5); - zcorrfac2 = (pow((ztp1[jl + klon*(jk + klev*ibl)] / 273.0), 1.5))*(393.0 / (ztp1[jl + klon*(jk + klev*ibl)] + 120.0)); + (MYPOW(ztp1[jl + klon*(jk + klev*ibl)], 3)); + zcorrfac = MYPOW((1.0 / zrho), 0.5); + zcorrfac2 = (MYPOW((ztp1[jl + klon*(jk + klev*ibl)] / 273.0), 1.5))*(393.0 / (ztp1[jl + klon*(jk + klev*ibl)] + 120.0)); zpr02 = zrho*zpreclr*(*yrecldp).rcl_const1s / (ztcg*zfacx1s); - zterm1 = (zqsice[jl + klon*(jk + klev*ibl)] - zqe)*(pow(ztp1[jl + klon*(jk + klev*ibl)], 2))* + zterm1 = (zqsice[jl + klon*(jk + klev*ibl)] - zqe)*(MYPOW(ztp1[jl + klon*(jk + klev*ibl)], 2))* zvpice*zcorrfac2*ztcg*(*yrecldp).rcl_const2s*zfacx1s / (zrho*zaplusb*zqsice[jl + klon*(jk + klev*ibl)]); - zterm2 = 0.65*(*yrecldp).rcl_const6s*(pow(zpr02, (*yrecldp).rcl_const4s)) + - (*yrecldp).rcl_const3s*(pow(zcorrfac, 0.5))*(pow(zrho, 0.5))*(pow(zpr02, - (*yrecldp).rcl_const5s)) / (pow(zcorrfac2, 0.5)); + zterm2 = 0.65*(*yrecldp).rcl_const6s*(MYPOW(zpr02, (*yrecldp).rcl_const4s)) + + (*yrecldp).rcl_const3s*(MYPOW(zcorrfac, 0.5))*(MYPOW(zrho, 0.5))*(MYPOW(zpr02, + (*yrecldp).rcl_const5s)) / (MYPOW(zcorrfac2, 0.5)); - zdpevap = fmax(zcovpclr*zterm1*zterm2*ptsphy, (double) 0.0); + zdpevap = MYMAX(zcovpclr*zterm1*zterm2*ptsphy, (dtype) 0.0); //-------------------------------------------------------------------- // Limit evaporation to snow amount //-------------------------------------------------------------------- - zevap = fmin(zdpevap, zevaplimice); - zevap = fmin(zevap, zqx[jl + klon*(jk + klev*(3 + 5*ibl))]); + zevap = MYMIN(zdpevap, zevaplimice); + zevap = MYMIN(zevap, zqx[jl + klon*(jk + klev*(3 + 5*ibl))]); zsolqa[4 + 5*(3)] = zsolqa[4 + 5*(3)] + zevap; @@ -2265,7 +2265,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, (zcovptot - + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jl + klon*(jk + klev*ibl)])*zevap / zqx[jl + klon*(jk + klev*(3 + 5*ibl))])); //Update first guess field @@ -2297,10 +2297,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- // 5.1 solver for cloud cover //--------------------------- - zanew = (za[jl + klon*(jk + klev*ibl)] + zsolac) / ((double) 1.0 + zsolab); - zanew = fmin(zanew, (double) 1.0); + zanew = (za[jl + klon*(jk + klev*ibl)] + zsolac) / ((dtype) 1.0 + zsolab); + zanew = MYMIN(zanew, (dtype) 1.0); if (zanew < (*yrecldp).ramin) { - zanew = (double) 0.0; + zanew = (dtype) 0.0; } zda = zanew - zaorig[jl + klon*(jk + klev*ibl)]; //--------------------------------- @@ -2322,7 +2322,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jn = 0; jn <= 5 + -1; jn += 1) { llindex3[jn + 5*jm] = false; } - zsinksum[jm] = (double) 0.0; + zsinksum[jm] = (dtype) 0.0; } //---------------------------- @@ -2338,8 +2338,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // calculate overshoot and scaling factor //--------------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zmax = fmax(zqx[jl + klon*(jk + klev*(jm + 5*ibl))], zepsec); - zrat = fmax(zsinksum[jm], zmax); + zmax = MYMAX(zqx[jl + klon*(jk + klev*(jm + 5*ibl))], zepsec); + zrat = MYMAX(zsinksum[jm], zmax); zratio[jm] = zmax / zrat; } @@ -2348,7 +2348,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // recalculating the scale factor each time //-------------------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zsinksum[jm] = (double) 0.0; + zsinksum[jm] = (dtype) 0.0; } //---------------- @@ -2364,8 +2364,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- // recalculate scaling factor //--------------------------- - zmm = fmax(zqx[jl + klon*(jk + klev*(jm + 5*ibl))], zepsec); - zrr = fmax(zsinksum[jm], zmm); + zmm = MYMAX(zqx[jl + klon*(jk + klev*(jm + 5*ibl))], zepsec); + zrr = MYMAX(zsinksum[jm], zmm); zratio[jm] = zmm / zrr; //------ // scale @@ -2374,7 +2374,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //DIR$ IVDEP //DIR$ PREFERVECTOR for (jn = 0; jn <= 5 + -1; jn += 1) { - if (zsolqa[jm + 5*jn] < (double) 0.0) { + if (zsolqa[jm + 5*jn] < (dtype) 0.0) { zsolqa[jm + 5*jn] = zsolqa[jm + 5*jn]*zzratio; zsolqa[jn + 5*jm] = zsolqa[jn + 5*jm]*zzratio; } @@ -2394,7 +2394,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // diagonals: microphysical sink terms+transport //---------------------------------------------- if (jn + 1 == jm + 1) { - zqlhs[jn + 5*jm] = (double) 1.0 + zfallsink[jm]; + zqlhs[jn + 5*jm] = (dtype) 1.0 + zfallsink[jm]; for (jo = 0; jo <= 5 + -1; jo += 1) { zqlhs[jn + 5*jm] = zqlhs[jn + 5*jm] + zsolqb[jo + 5*jn]; } @@ -2414,7 +2414,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------- // sum the explicit source and sink //--------------------------------- - zexplicit = (double) 0.0; + zexplicit = (dtype) 0.0; for (jn = 0; jn <= 5 + -1; jn += 1) { zexplicit = zexplicit + zsolqa[jm + 5*jn]; // sum over middle index } @@ -2467,7 +2467,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jn = 0; jn <= 5 - 1 + -1; jn += 1) { if (zqxn[jn] < zepsec) { zqxn[4] = zqxn[4] + zqxn[jn]; - zqxn[jn] = (double) 0.0; + zqxn[jn] = (dtype) 0.0; } } @@ -2494,7 +2494,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zqpretot = zpfplsx[jl + klon*(1 + jk + (klev + 1)*(3 + 5*ibl))] + zpfplsx[jl + klon*(1 + jk + (klev + 1)*(2 + 5*ibl))]; if (zqpretot < zepsec) { - zcovptot = (double) 0.0; + zcovptot = (dtype) 0.0; } //###################################################################### @@ -2572,17 +2572,17 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------- // Fluxes: //-------- - pfsqlf[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqif[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqrf[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqsf[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfcqlng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfcqnng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfcqrng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; //rain - pfcqsng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; //snow + pfsqlf[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqif[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqrf[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqsf[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfcqlng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfcqnng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfcqrng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; //rain + pfcqsng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; //snow // fluxes due to turbulence - pfsqltur[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqitur[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; + pfsqltur[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqitur[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; for (jk = 0; jk <= klev + -1; jk += 1) { @@ -2623,7 +2623,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Ice , LS scheme minus detrainment pfsqif[jl + klon*(1 + jk + (klev + 1)*ibl)] = pfsqif[jl + klon*(1 + jk + (klev + 1)*ibl)] + (zqxn2d[jl + klon*(jk + klev*(1 + 5*ibl))] - zqx0[jl + klon*(jk + klev*(1 + 5*ibl))] + - pvfi[jl + klon*(jk + klev*ibl)]*ptsphy - ((double) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)])*zgdph_r; + pvfi[jl + klon*(jk + klev*ibl)]*ptsphy - ((dtype) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)])*zgdph_r; // ice, negative numbers pfcqnng[jl + klon*(1 + jk + (klev + 1)*ibl)] = pfcqnng[jl + klon*(1 + jk + (klev + 1)*ibl)] + zlneg[jl + klon*(jk + klev*(1 + 5*ibl))]*zgdph_r; diff --git a/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.h b/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.h index f8949673..daba64ed 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.h +++ b/src/cloudsc_hip/cloudsc/cloudsc_c_hoist.h @@ -12,39 +12,40 @@ #include "hip/hip_runtime.h" #include "yoecldp_c.h" #include +#include "dtype.h" -__global__ void __launch_bounds__(128, 1) cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, - const double * __restrict__ pt, - const double * __restrict__ pq, const double * __restrict__ tendency_tmp_t, - const double * __restrict__ tendency_tmp_q, const double * __restrict__ tendency_tmp_a, - const double * __restrict__ tendency_tmp_cld, double * __restrict__ tendency_loc_t, - double * __restrict__ tendency_loc_q, double * __restrict__ tendency_loc_a, - double * __restrict__ tendency_loc_cld, const double * __restrict__ pvfa, - const double * __restrict__ pvfl, const double * __restrict__ pvfi, const double * __restrict__ pdyna, - const double * __restrict__ pdynl, const double * __restrict__ pdyni, const double * __restrict__ phrsw, - double * __restrict__ phrlw, const double * __restrict__ pvervel, const double * __restrict__ pap, - const double * __restrict__ paph, const double * __restrict__ plsm, - const int * ktype, const double * __restrict__ plu, double * __restrict__ plude, - const double * __restrict__ psnde, const double * __restrict__ pmfu, const double * __restrict__ pmfd, - const double * __restrict__ pa, const double * __restrict__ pclv, const double * __restrict__ psupsat, - const double * __restrict__ plcrit_aer, const double * __restrict__ picrit_aer, - const double * __restrict__ pre_ice, const double * __restrict__ pccn, const double * __restrict__ pnice, - double * __restrict__ pcovptot, double * __restrict__ prainfrac_toprfz, - double * __restrict__ pfsqlf, double * __restrict__ pfsqif, double * __restrict__ pfcqnng, - double * __restrict__ pfcqlng, double * __restrict__ pfsqrf, double * __restrict__ pfsqsf, - double * __restrict__ pfcqrng, double * __restrict__ pfcqsng, - double * __restrict__ pfsqltur, double * __restrict__ pfsqitur, - double * __restrict__ pfplsl, double * __restrict__ pfplsn, double * __restrict__ pfhpsl, - double * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, - double rg, double rd, double rcpd, double retv, double rlvtt, double rlstt, double rlmlt, double rtt, - double rv, double r2es, double r3les, double r3ies, double r4les, double r4ies, double r5les, - double r5ies, double r5alvcp, double r5alscp, double ralvdcp, double ralsdcp, double ralfdcp, - double rtwat, double rtice, double rticecu, double rtwat_rtice_r, double rtwat_rticecu_r, - double rkoop1, double rkoop2, - double * __restrict__ zfoealfa, double * __restrict__ ztp1, double * __restrict__ zli, - double * __restrict__ za, double * __restrict__ zaorig, double * __restrict__ zliqfrac, - double * __restrict__ zicefrac, double * __restrict__ zqx, double * __restrict__ zqx0, - double * __restrict__ zpfplsx, double * __restrict__ zlneg, double * __restrict__ zqxn2d, - double * __restrict__ zqsmix, double * __restrict__ zqsliq, double * __restrict__ zqsice, - double * __restrict__ zfoeewmt, double * __restrict__ zfoeew, double * __restrict__ zfoeeliqt); +__global__ void __launch_bounds__(128, 1) cloudsc_c(int kidia, int kfdia, int klon, dtype ptsphy, + const dtype * __restrict__ pt, + const dtype * __restrict__ pq, const dtype * __restrict__ tendency_tmp_t, + const dtype * __restrict__ tendency_tmp_q, const dtype * __restrict__ tendency_tmp_a, + const dtype * __restrict__ tendency_tmp_cld, dtype * __restrict__ tendency_loc_t, + dtype * __restrict__ tendency_loc_q, dtype * __restrict__ tendency_loc_a, + dtype * __restrict__ tendency_loc_cld, const dtype * __restrict__ pvfa, + const dtype * __restrict__ pvfl, const dtype * __restrict__ pvfi, const dtype * __restrict__ pdyna, + const dtype * __restrict__ pdynl, const dtype * __restrict__ pdyni, const dtype * __restrict__ phrsw, + dtype * __restrict__ phrlw, const dtype * __restrict__ pvervel, const dtype * __restrict__ pap, + const dtype * __restrict__ paph, const dtype * __restrict__ plsm, + const int * ktype, const dtype * __restrict__ plu, dtype * __restrict__ plude, + const dtype * __restrict__ psnde, const dtype * __restrict__ pmfu, const dtype * __restrict__ pmfd, + const dtype * __restrict__ pa, const dtype * __restrict__ pclv, const dtype * __restrict__ psupsat, + const dtype * __restrict__ plcrit_aer, const dtype * __restrict__ picrit_aer, + const dtype * __restrict__ pre_ice, const dtype * __restrict__ pccn, const dtype * __restrict__ pnice, + dtype * __restrict__ pcovptot, dtype * __restrict__ prainfrac_toprfz, + dtype * __restrict__ pfsqlf, dtype * __restrict__ pfsqif, dtype * __restrict__ pfcqnng, + dtype * __restrict__ pfcqlng, dtype * __restrict__ pfsqrf, dtype * __restrict__ pfsqsf, + dtype * __restrict__ pfcqrng, dtype * __restrict__ pfcqsng, + dtype * __restrict__ pfsqltur, dtype * __restrict__ pfsqitur, + dtype * __restrict__ pfplsl, dtype * __restrict__ pfplsn, dtype * __restrict__ pfhpsl, + dtype * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, + dtype rg, dtype rd, dtype rcpd, dtype retv, dtype rlvtt, dtype rlstt, dtype rlmlt, dtype rtt, + dtype rv, dtype r2es, dtype r3les, dtype r3ies, dtype r4les, dtype r4ies, dtype r5les, + dtype r5ies, dtype r5alvcp, dtype r5alscp, dtype ralvdcp, dtype ralsdcp, dtype ralfdcp, + dtype rtwat, dtype rtice, dtype rticecu, dtype rtwat_rtice_r, dtype rtwat_rticecu_r, + dtype rkoop1, dtype rkoop2, + dtype * __restrict__ zfoealfa, dtype * __restrict__ ztp1, dtype * __restrict__ zli, + dtype * __restrict__ za, dtype * __restrict__ zaorig, dtype * __restrict__ zliqfrac, + dtype * __restrict__ zicefrac, dtype * __restrict__ zqx, dtype * __restrict__ zqx0, + dtype * __restrict__ zpfplsx, dtype * __restrict__ zlneg, dtype * __restrict__ zqxn2d, + dtype * __restrict__ zqsmix, dtype * __restrict__ zqsliq, dtype * __restrict__ zqsice, + dtype * __restrict__ zfoeewmt, dtype * __restrict__ zfoeew, dtype * __restrict__ zfoeeliqt); diff --git a/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.cpp b/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.cpp index 07d267cc..e59bc4c0 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.cpp +++ b/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.cpp @@ -11,34 +11,34 @@ #include "cloudsc_c.h" #include -__global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, - const double * __restrict__ pt, - const double * __restrict__ pq, const double * __restrict__ tendency_tmp_t, - const double * __restrict__ tendency_tmp_q, const double * __restrict__ tendency_tmp_a, - const double * __restrict__ tendency_tmp_cld, double * __restrict__ tendency_loc_t, - double * __restrict__ tendency_loc_q, double * __restrict__ tendency_loc_a, - double * __restrict__ tendency_loc_cld, const double * __restrict__ pvfa, - const double * __restrict__ pvfl, const double * __restrict__ pvfi, const double * __restrict__ pdyna, - const double * __restrict__ pdynl, const double * __restrict__ pdyni, const double * __restrict__ phrsw, - double * __restrict__ phrlw, const double * __restrict__ pvervel, const double * __restrict__ pap, - const double * __restrict__ paph, const double * __restrict__ plsm, - const int * ktype, const double * __restrict__ plu, double * __restrict__ plude, - const double * __restrict__ psnde, const double * __restrict__ pmfu, const double * __restrict__ pmfd, - const double * __restrict__ pa, const double * __restrict__ pclv, const double * __restrict__ psupsat, - const double * __restrict__ plcrit_aer, const double * __restrict__ picrit_aer, - const double * __restrict__ pre_ice, const double * __restrict__ pccn, const double * __restrict__ pnice, - double * __restrict__ pcovptot, double * __restrict__ prainfrac_toprfz, - double * __restrict__ pfsqlf, double * __restrict__ pfsqif, double * __restrict__ pfcqnng, - double * __restrict__ pfcqlng, double * __restrict__ pfsqrf, double * __restrict__ pfsqsf, - double * __restrict__ pfcqrng, double * __restrict__ pfcqsng, - double * __restrict__ pfsqltur, double * __restrict__ pfsqitur, - double * __restrict__ pfplsl, double * __restrict__ pfplsn, double * __restrict__ pfhpsl, - double * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, - double rg, double rd, double rcpd, double retv, double rlvtt, double rlstt, double rlmlt, double rtt, - double rv, double r2es, double r3les, double r3ies, double r4les, double r4ies, double r5les, - double r5ies, double r5alvcp, double r5alscp, double ralvdcp, double ralsdcp, double ralfdcp, - double rtwat, double rtice, double rticecu, double rtwat_rtice_r, double rtwat_rticecu_r, - double rkoop1, double rkoop2) { +__global__ void cloudsc_c(int kidia, int kfdia, int klon, dtype ptsphy, + const dtype * __restrict__ pt, + const dtype * __restrict__ pq, const dtype * __restrict__ tendency_tmp_t, + const dtype * __restrict__ tendency_tmp_q, const dtype * __restrict__ tendency_tmp_a, + const dtype * __restrict__ tendency_tmp_cld, dtype * __restrict__ tendency_loc_t, + dtype * __restrict__ tendency_loc_q, dtype * __restrict__ tendency_loc_a, + dtype * __restrict__ tendency_loc_cld, const dtype * __restrict__ pvfa, + const dtype * __restrict__ pvfl, const dtype * __restrict__ pvfi, const dtype * __restrict__ pdyna, + const dtype * __restrict__ pdynl, const dtype * __restrict__ pdyni, const dtype * __restrict__ phrsw, + dtype * __restrict__ phrlw, const dtype * __restrict__ pvervel, const dtype * __restrict__ pap, + const dtype * __restrict__ paph, const dtype * __restrict__ plsm, + const int * ktype, const dtype * __restrict__ plu, dtype * __restrict__ plude, + const dtype * __restrict__ psnde, const dtype * __restrict__ pmfu, const dtype * __restrict__ pmfd, + const dtype * __restrict__ pa, const dtype * __restrict__ pclv, const dtype * __restrict__ psupsat, + const dtype * __restrict__ plcrit_aer, const dtype * __restrict__ picrit_aer, + const dtype * __restrict__ pre_ice, const dtype * __restrict__ pccn, const dtype * __restrict__ pnice, + dtype * __restrict__ pcovptot, dtype * __restrict__ prainfrac_toprfz, + dtype * __restrict__ pfsqlf, dtype * __restrict__ pfsqif, dtype * __restrict__ pfcqnng, + dtype * __restrict__ pfcqlng, dtype * __restrict__ pfsqrf, dtype * __restrict__ pfsqsf, + dtype * __restrict__ pfcqrng, dtype * __restrict__ pfcqsng, + dtype * __restrict__ pfsqltur, dtype * __restrict__ pfsqitur, + dtype * __restrict__ pfplsl, dtype * __restrict__ pfplsn, dtype * __restrict__ pfhpsl, + dtype * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, + dtype rg, dtype rd, dtype rcpd, dtype retv, dtype rlvtt, dtype rlstt, dtype rlmlt, dtype rtt, + dtype rv, dtype r2es, dtype r3les, dtype r3ies, dtype r4les, dtype r4ies, dtype r5les, + dtype r5ies, dtype r5alvcp, dtype r5alscp, dtype ralvdcp, dtype ralsdcp, dtype ralfdcp, + dtype rtwat, dtype rtice, dtype rticecu, dtype rtwat_rtice_r, dtype rtwat_rticecu_r, + dtype rkoop1, dtype rkoop2) { //------------------------------------------------------------------------------- // Declare input/output arguments @@ -53,105 +53,105 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, const int klev = 137; // Number of levels - double zlcond1, zlcond2, zlevapl, zlevapi, zrainaut, zsnowaut, zliqcld, zicecld; - double zlevap, zleros; + dtype zlcond1, zlcond2, zlevapl, zlevapi, zrainaut, zsnowaut, zliqcld, zicecld; + dtype zlevap, zleros; // condensation and evaporation terms // autoconversion terms - double zfokoop; - double zfoealfa; - double zicenuclei; // number concentration of ice nuclei - - double zlicld; - double zacond; - double zaeros; - double zlfinalsum; - double zdqs; - double ztold; - double zqold; - double zdtgdp; - double zrdtgdp; - double ztrpaus; - double zcovpclr; - double zpreclr; - double zcovptot; - double zcovpmax; - double zqpretot; - double zdpevap; - double zdtforc; - double zdtdiab; - double ztp1[2]; - double zldefr; - double zldifdt; - double zdtgdpf; - double zlcust[5]; - double zacust; - double zmf; - - double zrho; - double ztmp1, ztmp2, ztmp3; - double ztmp4, ztmp5, ztmp6, ztmp7; - double zalfawm; + dtype zfokoop; + dtype zfoealfa; + dtype zicenuclei; // number concentration of ice nuclei + + dtype zlicld; + dtype zacond; + dtype zaeros; + dtype zlfinalsum; + dtype zdqs; + dtype ztold; + dtype zqold; + dtype zdtgdp; + dtype zrdtgdp; + dtype ztrpaus; + dtype zcovpclr; + dtype zpreclr; + dtype zcovptot; + dtype zcovpmax; + dtype zqpretot; + dtype zdpevap; + dtype zdtforc; + dtype zdtdiab; + dtype ztp1[2]; + dtype zldefr; + dtype zldifdt; + dtype zdtgdpf; + dtype zlcust[5]; + dtype zacust; + dtype zmf; + + dtype zrho; + dtype ztmp1, ztmp2, ztmp3; + dtype ztmp4, ztmp5, ztmp6, ztmp7; + dtype zalfawm; // Accumulators of A,B,and C factors for cloud equations - double zsolab; // -ve implicit CC - double zsolac; // linear CC - double zanew; - double zanewm1; + dtype zsolab; // -ve implicit CC + dtype zsolac; // linear CC + dtype zanew; + dtype zanewm1; - double zgdp; + dtype zgdp; //---for flux calculation - double zda; - double zli; - double za[2]; - double zaorig; + dtype zda; + dtype zli; + dtype za[2]; + dtype zaorig; int llflag; int llo1; int icall, ik, jk, jl, jm, jn, jo, jlen, is; - double zdp, zpaphd; + dtype zdp, zpaphd; - double zalfa; + dtype zalfa; // & ZALFACU, ZALFALS - double zalfaw; - double zbeta, zbeta1; - double zcfpr; - double zcor; - double zcdmax; - double zmin; - double zlcondlim; - double zdenom; - double zdpmxdt; - double zdpr; - double zdtdp; - double ze; - double zepsec; - double zfac, zfaci, zfacw; - double zgdcp; - double zinew; - double zlcrit; - double zmfdn; - double zprecip; - double zqe; - double zqsat, zqtmst, zrdcp; - double zrhc, zsig, zsigk; - double zwtot; - double zzco, zzdl, zzrh, zzzdt, zqadj; - double zqnew, ztnew; - double zrg_r, zgdph_r, zcons1, zcond, zcons1a; - double zlfinal; - double zmelt; - double zevap; - double zfrz; - double zvpliq, zvpice; - double zadd, zbdd, zcvds, zice0, zdepos; - double zsupsat; - double zfall; - double zre_ice; - double zrldcp; - double zqp1env; + dtype zalfaw; + dtype zbeta, zbeta1; + dtype zcfpr; + dtype zcor; + dtype zcdmax; + dtype zmin; + dtype zlcondlim; + dtype zdenom; + dtype zdpmxdt; + dtype zdpr; + dtype zdtdp; + dtype ze; + dtype zepsec; + dtype zfac, zfaci, zfacw; + dtype zgdcp; + dtype zinew; + dtype zlcrit; + dtype zmfdn; + dtype zprecip; + dtype zqe; + dtype zqsat, zqtmst, zrdcp; + dtype zrhc, zsig, zsigk; + dtype zwtot; + dtype zzco, zzdl, zzrh, zzzdt, zqadj; + dtype zqnew, ztnew; + dtype zrg_r, zgdph_r, zcons1, zcond, zcons1a; + dtype zlfinal; + dtype zmelt; + dtype zevap; + dtype zfrz; + dtype zvpliq, zvpice; + dtype zadd, zbdd, zcvds, zice0, zdepos; + dtype zsupsat; + dtype zfall; + dtype zre_ice; + dtype zrldcp; + dtype zqp1env; //---------------------------- // Arrays for new microphysics @@ -168,18 +168,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, int llindex1[5]; // index variable int llindex3[5*5]; // index variable - double zmax; - double zrat; + dtype zmax; + dtype zrat; int iorder[5]; // array for sorting explicit terms - double zliqfrac; - double zicefrac; - double zqx[5]; - double zqx0[5]; - double zqxn[5]; // new values for zqx at time+1 - double zqxfg[5]; // first guess values including precip - double zqxnm1[5]; // new values for zqx at time+1 at level above - double zfluxq[5]; // fluxes convergence of species (needed?) + dtype zliqfrac; + dtype zicefrac; + dtype zqx[5]; + dtype zqx0[5]; + dtype zqxn[5]; // new values for zqx at time+1 + dtype zqxfg[5]; // first guess values including precip + dtype zqxnm1[5]; // new values for zqx at time+1 at level above + dtype zfluxq[5]; // fluxes convergence of species (needed?) // Keep the following for possible future total water variance scheme? //REAL(KIND=JPRB) :: ZTL(KLON,KLEV) ! liquid water temperature //REAL(KIND=JPRB) :: ZABETA(KLON,KLEV) ! cloud fraction @@ -187,34 +187,34 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //REAL(KIND=JPRB) :: ZQTMIN(KLON,KLEV) //REAL(KIND=JPRB) :: ZQTMAX(KLON,KLEV) - double zlneg[5]; - double zmeltmax; - double zfrzmax; - double zicetot; + dtype zlneg[5]; + dtype zmeltmax; + dtype zfrzmax; + dtype zicetot; - double zqxn2d[5]; + dtype zqxn2d[5]; - double zqsmix; + dtype zqsmix; //REAL(KIND=JPRB) :: ZQSBIN(KLON,KLEV) ! binary switched ice/liq saturation - double zqsliq; - double zqsice; + dtype zqsliq; + dtype zqsice; //REAL(KIND=JPRB) :: ZRHM(KLON,KLEV) ! diagnostic mixed phase RH //REAL(KIND=JPRB) :: ZRHL(KLON,KLEV) ! RH wrt liq //REAL(KIND=JPRB) :: ZRHI(KLON,KLEV) ! RH wrt ice - double zfoeewmt; - double zfoeew; - double zfoeeliqt; + dtype zfoeewmt; + dtype zfoeew; + dtype zfoeeliqt; //REAL(KIND=JPRB) :: ZFOEEICET(KLON,KLEV) - double zdqsliqdt, zdqsicedt, zdqsmixdt; - double zcorqsliq; - double zcorqsice; + dtype zdqsliqdt, zdqsicedt, zdqsmixdt; + dtype zcorqsliq; + dtype zcorqsice; //REAL(KIND=JPRB) :: ZCORQSBIN(KLON) - double zcorqsmix; - double zevaplimliq, zevaplimice, zevaplimmix; + dtype zcorqsmix; + dtype zevaplimliq, zevaplimice, zevaplimmix; //------------------------------------------------------- // SOURCE/SINK array for implicit and explicit terms @@ -235,60 +235,60 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // i.e. A positive value is a sink!????? weird... //------------------------------------------------------- - double zsolqa[5*5]; // explicit sources and sinks - double zsolqb[5*5]; // implicit sources and sinks + dtype zsolqa[5*5]; // explicit sources and sinks + dtype zsolqb[5*5]; // implicit sources and sinks // e.g. microphysical pathways between ice variables. - double zqlhs[5*5]; // n x n matrix storing the LHS of implicit solver - double zvqx[5]; // fall speeds of three categories - double zexplicit; - double zratio[5], zsinksum[5]; + dtype zqlhs[5*5]; // n x n matrix storing the LHS of implicit solver + dtype zvqx[5]; // fall speeds of three categories + dtype zexplicit; + dtype zratio[5], zsinksum[5]; // for sedimentation source/sink terms - double zfallsink[5]; - double zfallsrce[5]; + dtype zfallsink[5]; + dtype zfallsrce[5]; // for convection detrainment source and subsidence source/sink terms - double zconvsrce[5]; - double zconvsink[5]; + dtype zconvsrce[5]; + dtype zconvsink[5]; // for supersaturation source term from previous timestep - double zpsupsatsrce[5]; + dtype zpsupsatsrce[5]; // Numerical fit to wet bulb temperature - double ztw1 = (double) 1329.31; - double ztw2 = (double) 0.0074615; - double ztw3 = (double) 0.85E5; - double ztw4 = (double) 40.637; - double ztw5 = (double) 275.0; - - double zsubsat; // Subsaturation for snow melting term - double ztdmtw0; // Diff between dry-bulb temperature and + dtype ztw1 = (dtype) 1329.31; + dtype ztw2 = (dtype) 0.0074615; + dtype ztw3 = (dtype) 0.85E5; + dtype ztw4 = (dtype) 40.637; + dtype ztw5 = (dtype) 275.0; + + dtype zsubsat; // Subsaturation for snow melting term + dtype ztdmtw0; // Diff between dry-bulb temperature and // temperature when wet-bulb = 0degC // Variables for deposition term - double ztcg; // Temperature dependent function for ice PSD - double zfacx1i, zfacx1s; // PSD correction factor - double zaplusb, zcorrfac, zcorrfac2, zpr02, zterm1, zterm2; // for ice dep - double zcldtopdist; // Distance from cloud top - double zinfactor; // No. of ice nuclei factor for deposition + dtype ztcg; // Temperature dependent function for ice PSD + dtype zfacx1i, zfacx1s; // PSD correction factor + dtype zaplusb, zcorrfac, zcorrfac2, zpr02, zterm1, zterm2; // for ice dep + dtype zcldtopdist; // Distance from cloud top + dtype zinfactor; // No. of ice nuclei factor for deposition // Autoconversion/accretion/riming/evaporation int iwarmrain; int ievaprain; int ievapsnow; int idepice; - double zrainacc; - double zraincld; - double zsnowrime; - double zsnowcld; - double zesatliq; - double zfallcorr; - double zlambda; - double zevap_denom; - double zcorr2; - double zka; - double zconst; - double ztemp; + dtype zrainacc; + dtype zraincld; + dtype zsnowrime; + dtype zsnowcld; + dtype zesatliq; + dtype zfallcorr; + dtype zlambda; + dtype zevap_denom; + dtype zcorr2; + dtype zka; + dtype zconst; + dtype ztemp; // Rain freezing int llrainliq; // True if majority of raindrops are liquid (no ice core) @@ -300,28 +300,28 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------- // SCM budget statistics //---------------------- - double zrain; + dtype zrain; - double zhook_handle; - double ztmpl, ztmpi, ztmpa; + dtype zhook_handle; + dtype ztmpl, ztmpi, ztmpa; - double zmm, zrr; - double zrg; + dtype zmm, zrr; + dtype zrg; - double zzsum, zzratio; - double zepsilon; + dtype zzsum, zzratio; + dtype zepsilon; - double zcond1, zqp; + dtype zcond1, zqp; - double psum_solqa; + dtype psum_solqa; int ibl; int i_llfall_0; - //double zqx[5 * klev]; - //double zqx0[5 * klev]; - double zpfplsx[5 * 2]; - //double zlneg[5 * klev]; - //double zqxn2d[5 * klev]; + //dtype zqx[5 * klev]; + //dtype zqx0[5 * klev]; + dtype zpfplsx[5 * 2]; + //dtype zlneg[5 * klev]; + //dtype zqxn2d[5 * klev]; jl = threadIdx.x; ibl = blockIdx.x; @@ -330,7 +330,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, int jk_ip1; int jk_im1; - zepsilon = (double) 100.*DBL_EPSILON; + zepsilon = (dtype) 100.*DBL_EPSILON; // --------------------------------------------------------------------- // Set version of warm-rain autoconversion/accretion @@ -360,13 +360,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // --------------------- // Some simple constants // --------------------- - zqtmst = (double) 1.0 / ptsphy; + zqtmst = (dtype) 1.0 / ptsphy; zgdcp = rg / rcpd; zrdcp = rd / rcpd; zcons1a = rcpd / (rlmlt*rg*(*yrecldp).rtaumel); - zepsec = (double) 1.E-14; - zrg_r = (double) 1.0 / rg; - zrldcp = (double) 1.0 / (ralsdcp - ralvdcp); + zepsec = (dtype) 1.E-14; + zrg_r = (dtype) 1.0 / rg; + zrldcp = (dtype) 1.0 / (ralsdcp - ralvdcp); // Note: Defined in module/yoecldp.F90 // NCLDQL=1 ! liquid cloud water @@ -398,42 +398,42 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // INITIALIZATION OF OUTPUT TENDENCIES // ----------------------------------------------- for (jk = 0; jk <= klev + -1; jk += 1) { - tendency_loc_t[jl + klon*(jk + klev*ibl)] = (double) 0.0; - tendency_loc_q[jl + klon*(jk + klev*ibl)] = (double) 0.0; - tendency_loc_a[jl + klon*(jk + klev*ibl)] = (double) 0.0; + tendency_loc_t[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; + tendency_loc_q[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; + tendency_loc_a[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; } for (jm = 0; jm <= 5 - 1 + -1; jm += 1) { for (jk = 0; jk <= klev + -1; jk += 1) { - tendency_loc_cld[jl + klon*(jk + klev*(jm + 5*ibl))] = (double) 0.0; + tendency_loc_cld[jl + klon*(jk + klev*(jm + 5*ibl))] = (dtype) 0.0; } } //-- These were uninitialized : meaningful only when we compare error differences for (jk = 0; jk <= klev + -1; jk += 1) { - pcovptot[jl + klon*(jk + klev*ibl)] = (double) 0.0; - tendency_loc_cld[jl + klon*(jk + klev*(5 - 1 + 5*(ibl)))] = (double) 0.0; + pcovptot[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; + tendency_loc_cld[jl + klon*(jk + klev*(5 - 1 + 5*(ibl)))] = (dtype) 0.0; } //-------- // Fluxes: //-------- - pfsqlf[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqif[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqrf[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqsf[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfcqlng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfcqnng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfcqrng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; //rain - pfcqsng[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; //snow + pfsqlf[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqif[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqrf[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqsf[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfcqlng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfcqnng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfcqrng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; //rain + pfcqsng[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; //snow // fluxes due to turbulence - pfsqltur[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; - pfsqitur[jl + klon*(0 + (klev + 1)*ibl)] = (double) 0.0; + pfsqltur[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; + pfsqitur[jl + klon*(0 + (klev + 1)*ibl)] = (dtype) 0.0; // ------------------------- // set up fall speeds in m/s // ------------------------- - zvqx[4] = (double) 0.0; - zvqx[0] = (double) 0.0; + zvqx[4] = (dtype) 0.0; + zvqx[0] = (dtype) 0.0; zvqx[1] = (*yrecldp).rvice; zvqx[2] = (*yrecldp).rvrain; zvqx[3] = (*yrecldp).rvsnow; @@ -441,7 +441,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, llfall[i_llfall_0] = false; } for (jm = 0; jm <= 5 + -1; jm += 1) { - if (zvqx[jm] > (double) 0.0) { + if (zvqx[jm] > (dtype) 0.0) { llfall[jm] = true; } // falling species @@ -450,7 +450,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Need to rationalise this at some point llfall[1] = false; - prainfrac_toprfz[jl + klon*ibl] = (double) 0.0; // rain fraction at top of refreezing layer + prainfrac_toprfz[jl + klon*ibl] = (dtype) 0.0; // rain fraction at top of refreezing layer llrainliq = true; // Assume all raindrops are liquid initially //###################################################################### @@ -461,18 +461,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reset single level variables //----------------------------- - zanewm1 = (double) 0.0; - zda = (double) 0.0; - zcovpclr = (double) 0.0; - zcovpmax = (double) 0.0; - zcovptot = (double) 0.0; - zcldtopdist = (double) 0.0; + zanewm1 = (dtype) 0.0; + zda = (dtype) 0.0; + zcovpclr = (dtype) 0.0; + zcovpmax = (dtype) 0.0; + zcovptot = (dtype) 0.0; + zcldtopdist = (dtype) 0.0; //------------- // zero arrays //------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zpfplsx[0 + 2*jm] = (double) 0.0; // precip fluxes - zpfplsx[1 + 2*jm] = (double) 0.0; + zpfplsx[0 + 2*jm] = (dtype) 0.0; // precip fluxes + zpfplsx[1 + 2*jm] = (dtype) 0.0; } // ---------------------- @@ -508,8 +508,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } for (jm = 0; jm <= 5 + -1; jm += 1) { - zqxn2d[jm] = (double) 0.0; // end of timestep values in 2D - zlneg[jm] = (double) 0.0; // negative input check + zqxn2d[jm] = (dtype) 0.0; // end of timestep values in 2D + zlneg[jm] = (dtype) 0.0; // negative input check } @@ -527,7 +527,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*ibl)] = tendency_loc_t[jl + klon*(jk + klev*ibl)] - ralvdcp*zqadj; zqx[4] = zqx[4] + zqx[0]; - zqx[0] = (double) 0.0; + zqx[0] = (dtype) 0.0; // Evaporate small cloud ice water amounts zlneg[1] = zlneg[1] + zqx[1]; @@ -537,10 +537,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*ibl)] = tendency_loc_t[jl + klon*(jk + klev*ibl)] - ralsdcp*zqadj; zqx[4] = zqx[4] + zqx[1]; - zqx[1] = (double) 0.0; + zqx[1] = (dtype) 0.0; // Set cloud cover to zero - za[jk_i] = (double) 0.0; + za[jk_i] = (dtype) 0.0; } @@ -563,7 +563,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, tendency_loc_t[jl + klon*(jk + klev*ibl)] - ralsdcp*zqadj; } zqx[4] = zqx[4] + zqx[jm]; - zqx[jm] = (double) 0.0; + zqx[jm] = (dtype) 0.0; } } @@ -573,32 +573,32 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------------- // old *diagnostic* mixed phase saturation //---------------------------------------- - zfoealfa = ((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))); - zfoeewmt = fmin(((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* - exp((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)) + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))* - exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))) / pap[jl + klon*(jk + klev*ibl)], (double) 0.5); + zfoealfa = ((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))); + zfoeewmt = MYMIN(((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* + MYEXP((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)) + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))* + MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))) / pap[jl + klon*(jk + klev*ibl)], (dtype) 0.5); zqsmix = zfoeewmt; - zqsmix = zqsmix / ((double) 1.0 - retv*zqsmix); + zqsmix = zqsmix / ((dtype) 1.0 - retv*zqsmix); //--------------------------------------------- // ice saturation T<273K // liquid water saturation for T>273K //--------------------------------------------- - zalfa = ((double)(fmax(0.0, copysign(1.0, ztp1[jk_i] - rtt)))); - zfoeew = fmin((zalfa*((double)(r2es*exp((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)))) + - ((double) 1.0 - zalfa)*((double)(r2es*exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))) / - pap[jl + klon*(jk + klev*ibl)], (double) 0.5); - zfoeew = fmin((double) 0.5, zfoeew); - zqsice = zfoeew / ((double) 1.0 - retv*zfoeew); + zalfa = ((dtype)(MYMAX(0.0, copysign(1.0, ztp1[jk_i] - rtt)))); + zfoeew = MYMIN((zalfa*((dtype)(r2es*MYEXP((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)))) + + ((dtype) 1.0 - zalfa)*((dtype)(r2es*MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))) / + pap[jl + klon*(jk + klev*ibl)], (dtype) 0.5); + zfoeew = MYMIN((dtype) 0.5, zfoeew); + zqsice = zfoeew / ((dtype) 1.0 - retv*zfoeew); //---------------------------------- // liquid water saturation //---------------------------------- - zfoeeliqt = fmin(((double)(r2es*exp((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)))) / - pap[jl + klon*(jk + klev*ibl)], (double) 0.5); + zfoeeliqt = MYMIN(((dtype)(r2es*MYEXP((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)))) / + pap[jl + klon*(jk + klev*ibl)], (dtype) 0.5); zqsliq = zfoeeliqt; - zqsliq = zqsliq / ((double) 1.0 - retv*zqsliq); + zqsliq = zqsliq / ((dtype) 1.0 - retv*zqsliq); // !---------------------------------- // ! ice water saturation @@ -611,7 +611,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //------------------------------------------ // Ensure cloud fraction is between 0 and 1 //------------------------------------------ - za[jk_i] = fmax((double) 0.0, fmin((double) 1.0, za[jk_i])); + za[jk_i] = MYMAX((dtype) 0.0, MYMIN((dtype) 1.0, za[jk_i])); //------------------------------------------------------------------- // Calculate liq/ice fractions (no longer a diagnostic relationship) @@ -619,10 +619,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zli = zqx[0] + zqx[1]; if (zli > (*yrecldp).rlmin) { zliqfrac = zqx[0] / zli; - zicefrac = (double) 1.0 - zliqfrac; + zicefrac = (dtype) 1.0 - zliqfrac; } else { - zliqfrac = (double) 0.0; - zicefrac = (double) 0.0; + zliqfrac = (dtype) 0.0; + zicefrac = (dtype) 0.0; } //###################################################################### @@ -682,37 +682,37 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Set KLON arrays to zero //--------------------------------- - zlicld = (double) 0.0; - zrainaut = (double) 0.0; // currently needed for diags - zrainacc = (double) 0.0; // currently needed for diags - zsnowaut = (double) 0.0; // needed - zldefr = (double) 0.0; - zacust = (double) 0.0; // set later when needed - zqpretot = (double) 0.0; - zlfinalsum = (double) 0.0; + zlicld = (dtype) 0.0; + zrainaut = (dtype) 0.0; // currently needed for diags + zrainacc = (dtype) 0.0; // currently needed for diags + zsnowaut = (dtype) 0.0; // needed + zldefr = (dtype) 0.0; + zacust = (dtype) 0.0; // set later when needed + zqpretot = (dtype) 0.0; + zlfinalsum = (dtype) 0.0; // Required for first guess call - zlcond1 = (double) 0.0; - zlcond2 = (double) 0.0; - zsupsat = (double) 0.0; - zlevapl = (double) 0.0; - zlevapi = (double) 0.0; + zlcond1 = (dtype) 0.0; + zlcond2 = (dtype) 0.0; + zsupsat = (dtype) 0.0; + zlevapl = (dtype) 0.0; + zlevapi = (dtype) 0.0; //------------------------------------- // solvers for cloud fraction //------------------------------------- - zsolab = (double) 0.0; - zsolac = (double) 0.0; + zsolab = (dtype) 0.0; + zsolac = (dtype) 0.0; - zicetot = (double) 0.0; + zicetot = (dtype) 0.0; //------------------------------------------ // reset matrix so missing pathways are set //------------------------------------------ for (jm = 0; jm <= 5 + -1; jm += 1) { for (jn = 0; jn <= 5 + -1; jn += 1) { - zsolqb[jn + 5*jm] = (double) 0.0; - zsolqa[jn + 5*jm] = (double) 0.0; + zsolqb[jn + 5*jm] = (dtype) 0.0; + zsolqa[jn + 5*jm] = (dtype) 0.0; } } @@ -720,12 +720,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // reset new microphysics variables //---------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zfallsrce[jm] = (double) 0.0; - zfallsink[jm] = (double) 0.0; - zconvsrce[jm] = (double) 0.0; - zconvsink[jm] = (double) 0.0; - zpsupsatsrce[jm] = (double) 0.0; - zratio[jm] = (double) 0.0; + zfallsrce[jm] = (dtype) 0.0; + zfallsink[jm] = (dtype) 0.0; + zconvsrce[jm] = (dtype) 0.0; + zconvsink[jm] = (dtype) 0.0; + zpsupsatsrce[jm] = (dtype) 0.0; + zratio[jm] = (dtype) 0.0; } @@ -739,7 +739,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zrho = pap[jl + klon*(jk + klev*ibl)] / (rd*ztp1[jk_i]); // p/RT air density zdtgdp = ptsphy*zgdp; // dt g/dp - zrdtgdp = zdp*((double) 1.0 / (ptsphy*rg)); // 1/(dt g/dp) + zrdtgdp = zdp*((dtype) 1.0 / (ptsphy*rg)); // 1/(dt g/dp) if (jk + 1 > 1) { zdtgdpf = ptsphy*rg / (pap[jl + klon*(jk + klev*ibl)] - pap[jl + klon*(-1 + @@ -752,35 +752,35 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reminder: retv=rv/rd-1 // liquid - zfacw = r5les / (pow((ztp1[jk_i] - r4les), 2)); - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeeliqt); + zfacw = r5les / (MYPOW((ztp1[jk_i] - r4les), 2)); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeeliqt); zdqsliqdt = zfacw*zcor*zqsliq; - zcorqsliq = (double) 1.0 + ralvdcp*zdqsliqdt; + zcorqsliq = (dtype) 1.0 + ralvdcp*zdqsliqdt; // ice - zfaci = r5ies / (pow((ztp1[jk_i] - r4ies), 2)); - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeew); + zfaci = r5ies / (MYPOW((ztp1[jk_i] - r4ies), 2)); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeew); zdqsicedt = zfaci*zcor*zqsice; - zcorqsice = (double) 1.0 + ralsdcp*zdqsicedt; + zcorqsice = (dtype) 1.0 + ralsdcp*zdqsicedt; // diagnostic mixed zalfaw = zfoealfa; zalfawm = zalfaw; - zfac = zalfaw*zfacw + ((double) 1.0 - zalfaw)*zfaci; - zcor = (double) 1.0 / ((double) 1.0 - retv*zfoeewmt); + zfac = zalfaw*zfacw + ((dtype) 1.0 - zalfaw)*zfaci; + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zfoeewmt); zdqsmixdt = zfac*zcor*zqsmix; - zcorqsmix = (double) 1.0 + ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* - ralvdcp + (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zdqsmixdt; + zcorqsmix = (dtype) 1.0 + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* + ralvdcp + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zdqsmixdt; // evaporation/sublimation limits - zevaplimmix = fmax((zqsmix - zqx[4]) / zcorqsmix, (double) 0.0); - zevaplimliq = fmax((zqsliq - zqx[4]) / zcorqsliq, (double) 0.0); - zevaplimice = fmax((zqsice - zqx[4]) / zcorqsice, (double) 0.0); + zevaplimmix = MYMAX((zqsmix - zqx[4]) / zcorqsmix, (dtype) 0.0); + zevaplimliq = MYMAX((zqsliq - zqx[4]) / zcorqsliq, (dtype) 0.0); + zevaplimice = MYMAX((zqsice - zqx[4]) / zcorqsice, (dtype) 0.0); //-------------------------------- // in-cloud consensate amount //-------------------------------- - ztmpa = (double) 1.0 / fmax(za[jk_i], zepsec); + ztmpa = (dtype) 1.0 / MYMAX(za[jk_i], zepsec); zliqcld = zqx[0]*ztmpa; zicecld = zqx[1]*ztmpa; zlicld = zliqcld + zicecld; @@ -820,14 +820,14 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 3.1.1 Supersaturation limit (from Koop) //----------------------------------- // Needs to be set for all temperatures - zfokoop = ((double)(fmin(rkoop1 - rkoop2*ztp1[jk_i], (double)(r2es*exp((r3les*(ztp1[jk_i] - rtt))/ - (ztp1[jk_i] - r4les)))*1.0/(double)(r2es*exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies)))))); + zfokoop = ((dtype)(MYMIN(rkoop1 - rkoop2*ztp1[jk_i], (dtype)(r2es*MYEXP((r3les*(ztp1[jk_i] - rtt))/ + (ztp1[jk_i] - r4les)))*1.0/(dtype)(r2es*MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies)))))); if (ztp1[jk_i] >= rtt || (*yrecldp).nssopt == 0) { - zfac = (double) 1.0; - zfaci = (double) 1.0; + zfac = (dtype) 1.0; + zfaci = (dtype) 1.0; } else { - zfac = za[jk_i] + zfokoop*((double) 1.0 - za[jk_i]); + zfac = za[jk_i] + zfokoop*((dtype) 1.0 - za[jk_i]); zfaci = ptsphy / (*yrecldp).rkooptau; } @@ -838,14 +838,14 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //------------------------------------------------------------------- // Calculate supersaturation to add to cloud - if (za[jk_i] > (double) 1.0 - (*yrecldp).ramin) { - zsupsat = fmax((zqx[4] - zfac*zqsice) / zcorqsice, (double) 0.0); + if (za[jk_i] > (dtype) 1.0 - (*yrecldp).ramin) { + zsupsat = MYMAX((zqx[4] - zfac*zqsice) / zcorqsice, (dtype) 0.0); } else { // Calculate environmental humidity supersaturation - zqp1env = (zqx[4] - za[jk_i]*zqsice) / fmax((double) 1.0 - za[jk_i], zepsilon); + zqp1env = (zqx[4] - za[jk_i]*zqsice) / MYMAX((dtype) 1.0 - za[jk_i], zepsilon); //& SIGN(MAX(ABS(1.0_JPRB-ZA(JL,JK)),ZEPSILON),1.0_JPRB-ZA(JL,JK)) - zsupsat = fmax(((double) 1.0 - za[jk_i])*(zqp1env - zfac*zqsice) / - zcorqsice, (double) 0.0); + zsupsat = MYMAX(((dtype) 1.0 - za[jk_i])*(zqp1env - zfac*zqsice) / + zcorqsice, (dtype) 0.0); } //------------------------------------------------------------------- @@ -871,7 +871,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } // Increase cloud amount using RKOOPTAU timescale - zsolac = ((double) 1.0 - za[jk_i])*zfaci; + zsolac = ((dtype) 1.0 - za[jk_i])*zfaci; } @@ -899,7 +899,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } // Increase cloud amount using RKOOPTAU timescale - zsolac = ((double) 1.0 - za[jk_i])*zfaci; + zsolac = ((dtype) 1.0 - za[jk_i])*zfaci; // Store cloud budget diagnostics if required } @@ -930,7 +930,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zalfaw = zfoealfa; zconvsrce[0] = zalfaw*plude[jl + klon*(jk + klev*ibl)]; zconvsrce[1] = - ((double) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)]; + ((dtype) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)]; zsolqa[0 + 5*(0)] = zsolqa[0 + 5*(0)] + zconvsrce[0]; zsolqa[1 + 5*(1)] = @@ -938,7 +938,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, } else { - plude[jl + klon*(jk + klev*ibl)] = (double) 0.0; + plude[jl + klon*(jk + klev*ibl)] = (dtype) 0.0; } // *convective snow detrainment source @@ -967,7 +967,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------- if (jk + 1 > (*yrecldp).ncldtop) { - zmf = fmax((double) 0.0, (pmfu[jl + klon*(jk + klev*ibl)] + pmfd[jl + + zmf = MYMAX((dtype) 0.0, (pmfu[jl + klon*(jk + klev*ibl)] + pmfd[jl + klon*(jk + klev*ibl)])*zdtgdp); zacust = zmf*zanewm1; @@ -983,7 +983,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // since there is no prognostic memory for in-cloud humidity, i.e. // we always assume cloud is saturated. - zdtdp = zrdcp*(double) 0.5*(ztp1[jk_im1] + ztp1[jk_i]) / paph[jl + + zdtdp = zrdcp*(dtype) 0.5*(ztp1[jk_im1] + ztp1[jk_i]) / paph[jl + klon*(jk + (klev + 1)*ibl)]; zdtforc = zdtdp*(pap[jl + klon*(jk + klev*ibl)] - pap[jl + klon*(-1 + jk + klev*ibl)]); @@ -992,9 +992,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jm = 0; jm <= 5 + -1; jm += 1) { if (!llfall[jm] && iphase[jm] > 0) { - zlfinal = fmax((double) 0.0, zlcust[jm] - zdqs); //lim to zero + zlfinal = MYMAX((dtype) 0.0, zlcust[jm] - zdqs); //lim to zero // no supersaturation allowed incloud ---V - zevap = fmin((zlcust[jm] - zlfinal), zevaplimmix); + zevap = MYMIN((zlcust[jm] - zlfinal), zevaplimmix); // ZEVAP=0.0_JPRB zlfinal = zlcust[jm] - zevap; zlfinalsum = zlfinalsum + zlfinal; // sum @@ -1007,7 +1007,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Reset the cloud contribution if no cloud water survives to this level: if (zlfinalsum < zepsec) { - zacust = (double) 0.0; + zacust = (dtype) 0.0; } zsolac = zsolac + zacust; @@ -1022,7 +1022,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (jk + 1 < klev) { - zmfdn = fmax((double) 0.0, (pmfu[jl + klon*(1 + jk + klev*ibl)] + pmfd[jl + + zmfdn = MYMAX((dtype) 0.0, (pmfu[jl + klon*(1 + jk + klev*ibl)] + pmfd[jl + klon*(1 + jk + klev*ibl)])*zdtgdp); zsolab = zsolab + zmfdn; @@ -1061,10 +1061,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // ZQE=(ZQX(JL,JK,NCLDQV)-ZA(JL,JK)*ZQSMIX(JL,JK))/& // & MAX(ZEPSEC,1.0_JPRB-ZA(JL,JK)) // ZE=ZLDIFDT(JL)*MAX(ZQSMIX(JL,JK)-ZQE,0.0_JPRB) - ze = zldifdt*fmax(zqsmix - zqx[4], (double) 0.0); + ze = zldifdt*MYMAX(zqsmix - zqx[4], (dtype) 0.0); zleros = za[jk_i]*ze; - zleros = fmin(zleros, zevaplimmix); - zleros = fmin(zleros, zli); + zleros = MYMIN(zleros, zevaplimmix); + zleros = MYMIN(zleros, zli); zaeros = zleros / zlicld; //if linear term // Erosion is -ve LINEAR in L,A @@ -1097,17 +1097,17 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zdtdp = zrdcp*ztp1[jk_i] / pap[jl + klon*(jk + klev*ibl)]; zdpmxdt = zdp*zqtmst; - zmfdn = (double) 0.0; + zmfdn = (dtype) 0.0; if (jk + 1 < klev) { zmfdn = pmfu[jl + klon*(1 + jk + klev*ibl)] + pmfd[jl + klon*(1 + jk + klev*ibl)]; } - zwtot = pvervel[jl + klon*(jk + klev*ibl)] + (double) 0.5*rg*(pmfu[jl + + zwtot = pvervel[jl + klon*(jk + klev*ibl)] + (dtype) 0.5*rg*(pmfu[jl + klon*(jk + klev*ibl)] + pmfd[jl + klon*(jk + klev*ibl)] + zmfdn); - zwtot = fmin(zdpmxdt, fmax(-zdpmxdt, zwtot)); + zwtot = MYMIN(zdpmxdt, MYMAX(-zdpmxdt, zwtot)); zzzdt = phrsw[jl + klon*(jk + klev*ibl)] + phrlw[jl + klon*(jk + klev*ibl)]; zdtdiab = - fmin(zdpmxdt*zdtdp, fmax(-zdpmxdt*zdtdp, zzzdt))*ptsphy + ralfdcp*zldefr; + MYMIN(zdpmxdt*zdtdp, MYMAX(-zdpmxdt*zdtdp, zzzdt))*ptsphy + ralfdcp*zldefr; // Note: ZLDEFR should be set to the difference between the mixed phase functions // in the convection and cloud scheme, but this is not calculated, so is zero and // the functions must be the same @@ -1115,36 +1115,36 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zqold = zqsmix; ztold = ztp1[jk_i]; ztp1[jk_i] = ztp1[jk_i] + zdtforc; - ztp1[jk_i] = fmax(ztp1[jk_i], (double) 160.0); + ztp1[jk_i] = MYMAX(ztp1[jk_i], (dtype) 160.0); llflag = true; // Formerly a call to CUADJTQ(..., ICALL=5) - zqp = (double) 1.0 / pap[jl + klon*(jk + klev*ibl)]; - zqsat = ((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* - exp((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)) + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))* - exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies)))))*zqp; - zqsat = fmin((double) 0.5, zqsat); - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsat); + zqp = (dtype) 1.0 / pap[jl + klon*(jk + klev*ibl)]; + zqsat = ((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* + MYEXP((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)) + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))* + MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies)))))*zqp; + zqsat = MYMIN((dtype) 0.5, zqsat); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsat); zqsat = zqsat*zcor; - zcond = (zqsmix - zqsat) / ((double) 1.0 + zqsat*zcor*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* - (1.0/pow(ztp1[jk_i] - r4les, 2)) + ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* - (1.0/pow(ztp1[jk_i] - r4ies, 2))))); - ztp1[jk_i] = ztp1[jk_i] + ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond; + zcond = (zqsmix - zqsat) / ((dtype) 1.0 + zqsat*zcor*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* + (1.0/MYPOW(ztp1[jk_i] - r4les, 2)) + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* + (1.0/MYPOW(ztp1[jk_i] - r4ies, 2))))); + ztp1[jk_i] = ztp1[jk_i] + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond; zqsmix = zqsmix - zcond; - zqsat = ((double)(r2es*((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* - exp((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)) + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))* - exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies)))))*zqp; - zqsat = fmin((double) 0.5, zqsat); - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsat); + zqsat = ((dtype)(r2es*((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))* + MYEXP((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)) + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))* + MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies)))))*zqp; + zqsat = MYMIN((dtype) 0.5, zqsat); + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsat); zqsat = zqsat*zcor; - zcond1 = (zqsmix - zqsat) / ((double) 1.0 + zqsat*zcor*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* - (1.0/pow(ztp1[jk_i] - r4les, 2)) + ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* - (1.0/pow(ztp1[jk_i] - r4ies, 2))))); - ztp1[jk_i] = ztp1[jk_i] + ((double)((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + - (1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond1; + zcond1 = (zqsmix - zqsat) / ((dtype) 1.0 + zqsat*zcor*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* + (1.0/MYPOW(ztp1[jk_i] - r4les, 2)) + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* + (1.0/MYPOW(ztp1[jk_i] - r4ies, 2))))); + ztp1[jk_i] = ztp1[jk_i] + ((dtype)((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*ralvdcp + + (1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*ralsdcp))*zcond1; zqsmix = zqsmix - zcond1; zdqs = zqsmix - zqold; @@ -1159,13 +1159,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Previous function based on DELTA DISTRIBUTION in cloud: - if (zdqs > (double) 0.0) { + if (zdqs > (dtype) 0.0) { // If subsidence evaporation term is turned off, then need to use updated // liquid and cloud here? // ZLEVAP = MAX(ZA(JL,JK)+ZACUST(JL),1.0_JPRB)*MIN(ZDQS(JL),ZLICLD(JL)+ZLFINALSUM(JL)) - zlevap = za[jk_i]*fmin(zdqs, zlicld); - zlevap = fmin(zlevap, zevaplimmix); - zlevap = fmin(zlevap, fmax(zqsmix - zqx[4], (double) 0.0)); + zlevap = za[jk_i]*MYMIN(zdqs, zlicld); + zlevap = MYMIN(zlevap, zevaplimmix); + zlevap = MYMIN(zlevap, MYMAX(zqsmix - zqx[4], (dtype) 0.0)); // For first guess call zlevapl = zliqfrac*zlevap; @@ -1186,23 +1186,23 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // (1) Increase of cloud water in existing clouds if (za[jk_i] > zepsec && zdqs <= -(*yrecldp).rlmin) { - zlcond1 = fmax(-zdqs, (double) 0.0); //new limiter + zlcond1 = MYMAX(-zdqs, (dtype) 0.0); //new limiter //old limiter (significantly improves upper tropospheric humidity rms) - if (za[jk_i] > (double) 0.99) { - zcor = (double) 1.0 / ((double) 1.0 - retv*zqsmix); - zcdmax = (zqx[4] - zqsmix) / ((double) 1.0 + zcor*zqsmix*((double)(((double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* - (1.0/pow(ztp1[jk_i] - r4les, 2)) + ((1.0 - (double)(fmin(1.0, pow((fmax(rtice, fmin(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* - (1.0/pow(ztp1[jk_i] - r4ies, 2))))); + if (za[jk_i] > (dtype) 0.99) { + zcor = (dtype) 1.0 / ((dtype) 1.0 - retv*zqsmix); + zcdmax = (zqx[4] - zqsmix) / ((dtype) 1.0 + zcor*zqsmix*((dtype)(((dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2)))*r5alvcp)* + (1.0/MYPOW(ztp1[jk_i] - r4les, 2)) + ((1.0 - (dtype)(MYMIN(1.0, MYPOW((MYMAX(rtice, MYMIN(rtwat, ztp1[jk_i])) - rtice)*rtwat_rtice_r, 2))))*r5alscp)* + (1.0/MYPOW(ztp1[jk_i] - r4ies, 2))))); } else { zcdmax = (zqx[4] - za[jk_i]*zqsmix) / za[jk_i]; } - zlcond1 = fmax(fmin(zlcond1, zcdmax), (double) 0.0); + zlcond1 = MYMAX(MYMIN(zlcond1, zcdmax), (dtype) 0.0); // end old limiter zlcond1 = za[jk_i]*zlcond1; if (zlcond1 < (*yrecldp).rlmin) { - zlcond1 = (double) 0.0; + zlcond1 = (dtype) 0.0; } //------------------------------------------------------------------------- @@ -1224,7 +1224,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // (2) Generation of new clouds (da/dt>0) - if (zdqs <= -(*yrecldp).rlmin && za[jk_i] < (double) 1.0 - zepsec) { + if (zdqs <= -(*yrecldp).rlmin && za[jk_i] < (dtype) 1.0 - zepsec) { //--------------------------- // Critical relative humidity @@ -1233,9 +1233,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zsigk = pap[jl + klon*(jk + klev*ibl)] / paph[jl + klon*(klev + (klev + 1)*ibl)]; // Increase RHcrit to 1.0 towards the surface (eta>0.8) - if (zsigk > (double) 0.8) { - zrhc = (*yrecldp).ramid + ((double) 1.0 - (*yrecldp).ramid)*(pow(((zsigk - - (double) 0.8) / (double) 0.2), 2)); + if (zsigk > (dtype) 0.8) { + zrhc = (*yrecldp).ramid + ((dtype) 1.0 - (*yrecldp).ramid)*(MYPOW(((zsigk - + (dtype) 0.8) / (dtype) 0.2), 2)); } // Commented out for CY37R1 to reduce humidity in high trop and strat @@ -1250,14 +1250,14 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- if ((*yrecldp).nssopt == 0) { // No scheme - zqe = (zqx[4] - za[jk_i]*zqsice) / fmax(zepsec, (double) 1.0 - + zqe = (zqx[4] - za[jk_i]*zqsice) / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); - zqe = fmax((double) 0.0, zqe); + zqe = MYMAX((dtype) 0.0, zqe); } else if ((*yrecldp).nssopt == 1) { // Tompkins - zqe = (zqx[4] - za[jk_i]*zqsice) / fmax(zepsec, (double) 1.0 - + zqe = (zqx[4] - za[jk_i]*zqsice) / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); - zqe = fmax((double) 0.0, zqe); + zqe = MYMAX((dtype) 0.0, zqe); } else if ((*yrecldp).nssopt == 2) { // Lohmann and Karcher zqe = zqx[4]; @@ -1268,7 +1268,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk_i] >= rtt || (*yrecldp).nssopt == 0) { // No ice supersaturation allowed - zfac = (double) 1.0; + zfac = (dtype) 1.0; } else { // Ice supersaturation zfac = zfokoop; @@ -1277,33 +1277,33 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zqe >= zrhc*zqsice*zfac && zqe < zqsice*zfac) { // note: not **2 on 1-a term if ZQE is used. // Added correction term ZFAC to numerator 15/03/2010 - zacond = -((double) 1.0 - za[jk_i])*zfac*zdqs / fmax((double) + zacond = -((dtype) 1.0 - za[jk_i])*zfac*zdqs / MYMAX((dtype) 2.0*(zfac*zqsice - zqe), zepsec); - zacond = fmin(zacond, (double) 1.0 - za[jk_i]); //PUT THE LIMITER BACK + zacond = MYMIN(zacond, (dtype) 1.0 - za[jk_i]); //PUT THE LIMITER BACK // Linear term: // Added correction term ZFAC 15/03/2010 - zlcond2 = -zfac*zdqs*(double) 0.5*zacond; //mine linear + zlcond2 = -zfac*zdqs*(dtype) 0.5*zacond; //mine linear // new limiter formulation - zzdl = (double) 2.0*(zfac*zqsice - zqe) / fmax(zepsec, (double) 1.0 - za[jk_i]); + zzdl = (dtype) 2.0*(zfac*zqsice - zqe) / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); // Added correction term ZFAC 15/03/2010 if (zfac*zdqs < -zzdl) { // ZLCONDLIM=(ZA(JL,JK)-1.0_JPRB)*ZDQS(JL)-ZQSICE(JL,JK)+ZQX(JL,JK,NCLDQV) zlcondlim = - (za[jk_i] - (double) 1.0)*zfac*zdqs - zfac*zqsice + zqx[4]; - zlcond2 = fmin(zlcond2, zlcondlim); + (za[jk_i] - (dtype) 1.0)*zfac*zdqs - zfac*zqsice + zqx[4]; + zlcond2 = MYMIN(zlcond2, zlcondlim); } - zlcond2 = fmax(zlcond2, (double) 0.0); + zlcond2 = MYMAX(zlcond2, (dtype) 0.0); - if (zlcond2 < (*yrecldp).rlmin || ((double) 1.0 - za[jk_i]) < zepsec + if (zlcond2 < (*yrecldp).rlmin || ((dtype) 1.0 - za[jk_i]) < zepsec ) { - zlcond2 = (double) 0.0; - zacond = (double) 0.0; + zlcond2 = (dtype) 0.0; + zacond = (dtype) 0.0; } - if (zlcond2 == (double) 0.0) { - zacond = (double) 0.0; + if (zlcond2 == (dtype) 0.0) { + zacond = (dtype) 0.0; } // Large-scale generation is LINEAR in A and LINEAR in L @@ -1357,7 +1357,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (za[jk_im1] < (*yrecldp).rcldtopcf && za[jk_i] >= (*yrecldp) .rcldtopcf) { - zcldtopdist = (double) 0.0; + zcldtopdist = (dtype) 0.0; } else { zcldtopdist = zcldtopdist + zdp / (zrho*rg); } @@ -1370,37 +1370,37 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk_i] < rtt && zqxfg[0] > (*yrecldp).rlmin) { // T<273K - zvpice = (((double)(r2es*exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))*rv) / rd; + zvpice = (((dtype)(r2es*MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))*rv) / rd; zvpliq = zvpice*zfokoop; - zicenuclei = (double) 1000.0*exp((double) 12.96*(zvpliq - zvpice) / zvpliq - - (double) 0.639); + zicenuclei = (dtype) 1000.0*MYEXP((dtype) 12.96*(zvpliq - zvpice) / zvpliq + - (dtype) 0.639); //------------------------------------------------ // 2.4e-2 is conductivity of air // 8.8 = 700**1/3 = density of ice to the third //------------------------------------------------ - zadd = rlstt*(rlstt / (rv*ztp1[jk_i]) - (double) 1.0) / ((double) + zadd = rlstt*(rlstt / (rv*ztp1[jk_i]) - (dtype) 1.0) / ((dtype) 2.4E-2*ztp1[jk_i]); - zbdd = rv*ztp1[jk_i]*pap[jl + klon*(jk + klev*ibl)] / ((double) + zbdd = rv*ztp1[jk_i]*pap[jl + klon*(jk + klev*ibl)] / ((dtype) 2.21*zvpice); - zcvds = (double) 7.8*(pow((zicenuclei / zrho), (double) 0.666))*(zvpliq - - zvpice) / ((double) 8.87*(zadd + zbdd)*zvpice); + zcvds = (dtype) 7.8*(MYPOW((zicenuclei / zrho), (dtype) 0.666))*(zvpliq - + zvpice) / ((dtype) 8.87*(zadd + zbdd)*zvpice); //----------------------------------------------------- // RICEINIT=1.E-12_JPRB is initial mass of ice particle //----------------------------------------------------- - zice0 = fmax(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); + zice0 = MYMAX(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); //------------------ // new value of ice: //------------------ - zinew = pow(((double) 0.666*zcvds*ptsphy + (pow(zice0, (double) 0.666))), - (double) 1.5); + zinew = MYPOW(((dtype) 0.666*zcvds*ptsphy + (MYPOW(zice0, (dtype) 0.666))), + (dtype) 1.5); //--------------------------- // grid-mean deposition rate: //--------------------------- - zdepos = fmax(za[jk_i]*(zinew - zice0), (double) 0.0); + zdepos = MYMAX(za[jk_i]*(zinew - zice0), (dtype) 0.0); //-------------------------------------------------------------------- // Limit deposition to liquid water amount @@ -1411,7 +1411,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // flux from the clear sky to the cloudy area. We thus rely on the // supersaturation check to clean up any remaining supersaturation //-------------------------------------------------------------------- - zdepos = fmin(zdepos, zqxfg[0]); // limit to liquid water amount + zdepos = MYMIN(zdepos, zqxfg[0]); // limit to liquid water amount //-------------------------------------------------------------------- // At top of cloud, reduce deposition rate near cloud top to account for @@ -1420,9 +1420,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // ZDEPOS = ZDEPOS*MIN(RDEPLIQREFRATE+ZCLDTOPDIST(JL)/RDEPLIQREFDEPTH,1.0_JPRB) // Change to include dependence on ice nuclei concentration // to increase deposition rate with decreasing temperatures - zinfactor = fmin(zicenuclei / (double) 15000., (double) 1.0); - zdepos = zdepos*fmin(zinfactor + ((double) 1.0 - zinfactor)*((*yrecldp) - .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (double) 1.0 + zinfactor = MYMIN(zicenuclei / (dtype) 15000., (dtype) 1.0); + zdepos = zdepos*MYMIN(zinfactor + ((dtype) 1.0 - zinfactor)*((*yrecldp) + .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (dtype) 1.0 ); //-------------- @@ -1451,7 +1451,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (za[jk_im1] < (*yrecldp).rcldtopcf && za[jk_i] >= (*yrecldp) .rcldtopcf) { - zcldtopdist = (double) 0.0; + zcldtopdist = (dtype) 0.0; } else { zcldtopdist = zcldtopdist + zdp / (zrho*rg); } @@ -1464,37 +1464,37 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk_i] < rtt && zqxfg[0] > (*yrecldp).rlmin) { // T<273K - zvpice = (((double)(r2es*exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))*rv) / rd; + zvpice = (((dtype)(r2es*MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))*rv) / rd; zvpliq = zvpice*zfokoop; - zicenuclei = (double) 1000.0*exp((double) 12.96*(zvpliq - zvpice) / zvpliq - - (double) 0.639); + zicenuclei = (dtype) 1000.0*MYEXP((dtype) 12.96*(zvpliq - zvpice) / zvpliq + - (dtype) 0.639); //----------------------------------------------------- // RICEINIT=1.E-12_JPRB is initial mass of ice particle //----------------------------------------------------- - zice0 = fmax(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); + zice0 = MYMAX(zicecld, zicenuclei*(*yrecldp).riceinit / zrho); // Particle size distribution - ztcg = (double) 1.0; - zfacx1i = (double) 1.0; + ztcg = (dtype) 1.0; + zfacx1i = (dtype) 1.0; zaplusb = (*yrecldp).rcl_apb1*zvpice - (*yrecldp).rcl_apb2*zvpice*ztp1[jk_i] + - pap[jl + klon*(jk + klev*ibl)]*(*yrecldp).rcl_apb3*(pow(ztp1[jk_i], (double) 3.)); - zcorrfac = pow(((double) 1.0 / zrho), (double) 0.5); - zcorrfac2 = (pow((ztp1[jk_i] / (double) 273.0), (double) 1.5)) - *((double) 393.0 / (ztp1[jk_i] + (double) 120.0)); + pap[jl + klon*(jk + klev*ibl)]*(*yrecldp).rcl_apb3*(MYPOW(ztp1[jk_i], (dtype) 3.)); + zcorrfac = MYPOW(((dtype) 1.0 / zrho), (dtype) 0.5); + zcorrfac2 = (MYPOW((ztp1[jk_i] / (dtype) 273.0), (dtype) 1.5)) + *((dtype) 393.0 / (ztp1[jk_i] + (dtype) 120.0)); zpr02 = zrho*zice0*(*yrecldp).rcl_const1i / (ztcg*zfacx1i); - zterm1 = (zvpliq - zvpice)*(pow(ztp1[jk_i], (double) 2.0)) + zterm1 = (zvpliq - zvpice)*(MYPOW(ztp1[jk_i], (dtype) 2.0)) *zvpice*zcorrfac2*ztcg*(*yrecldp).rcl_const2i*zfacx1i / (zrho*zaplusb*zvpice); - zterm2 = (double) 0.65*(*yrecldp).rcl_const6i*(pow(zpr02, (*yrecldp) - .rcl_const4i)) + (*yrecldp).rcl_const3i*(pow(zcorrfac, (double) 0.5)) - *(pow(zrho, (double) 0.5))*(pow(zpr02, (*yrecldp).rcl_const5i)) / - (pow(zcorrfac2, (double) 0.5)); + zterm2 = (dtype) 0.65*(*yrecldp).rcl_const6i*(MYPOW(zpr02, (*yrecldp) + .rcl_const4i)) + (*yrecldp).rcl_const3i*(MYPOW(zcorrfac, (dtype) 0.5)) + *(MYPOW(zrho, (dtype) 0.5))*(MYPOW(zpr02, (*yrecldp).rcl_const5i)) / + (MYPOW(zcorrfac2, (dtype) 0.5)); - zdepos = fmax(za[jk_i]*zterm1*zterm2*ptsphy, (double) 0.0); + zdepos = MYMAX(za[jk_i]*zterm1*zterm2*ptsphy, (dtype) 0.0); //-------------------------------------------------------------------- // Limit deposition to liquid water amount @@ -1505,7 +1505,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // flux from the clear sky to the cloudy area. We thus rely on the // supersaturation check to clean up any remaining supersaturation //-------------------------------------------------------------------- - zdepos = fmin(zdepos, zqxfg[0]); // limit to liquid water amount + zdepos = MYMIN(zdepos, zqxfg[0]); // limit to liquid water amount //-------------------------------------------------------------------- // At top of cloud, reduce deposition rate near cloud top to account for @@ -1513,9 +1513,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------------------- // Change to include dependence on ice nuclei concentration // to increase deposition rate with decreasing temperatures - zinfactor = fmin(zicenuclei / (double) 15000., (double) 1.0); - zdepos = zdepos*fmin(zinfactor + ((double) 1.0 - zinfactor)*((*yrecldp) - .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (double) 1.0 + zinfactor = MYMIN(zicenuclei / (dtype) 15000., (dtype) 1.0); + zdepos = zdepos*MYMIN(zinfactor + ((dtype) 1.0 - zinfactor)*((*yrecldp) + .rdepliqrefrate + zcldtopdist / (*yrecldp).rdepliqrefdepth), (dtype) 1.0 ); //-------------- @@ -1537,7 +1537,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------- // revise in-cloud consensate amount //---------------------------------- - ztmpa = (double) 1.0 / fmax(za[jk_i], zepsec); + ztmpa = (dtype) 1.0 / MYMAX(za[jk_i], zepsec); zliqcld = zqxfg[0]*ztmpa; zicecld = zqxfg[1]*ztmpa; zlicld = zliqcld + zicecld; @@ -1570,7 +1570,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zre_ice = pre_ice[jl + klon*(jk + klev*ibl)]; // The exponent value is from // Morrison et al. JAS 2005 Appendix - zvqx[1] = (double) 0.002*(pow(zre_ice, (double) 1.0)); + zvqx[1] = (dtype) 0.002*(MYPOW(zre_ice, (dtype) 1.0)); } zfall = zvqx[jm]*zrho; //------------------------------------------------- @@ -1604,19 +1604,19 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // zero. //--------------------------------------------------------------- if (zqpretot > zepsec) { - zcovptot = (double) 1.0 - (((double) 1.0 - zcovptot)*((double) 1.0 - - fmax(za[jk_i], za[jk_im1]))) / ((double) 1.0 - fmin(za[jk_im1], (double) 1.0 - (double) 1.E-06)); // here!!! - zcovptot = fmax(zcovptot, (*yrecldp).rcovpmin); - zcovpclr = fmax((double) 0.0, zcovptot - za[jk_i]); // clear sky proportion + zcovptot = (dtype) 1.0 - (((dtype) 1.0 - zcovptot)*((dtype) 1.0 - + MYMAX(za[jk_i], za[jk_im1]))) / ((dtype) 1.0 - MYMIN(za[jk_im1], (dtype) 1.0 - (dtype) 1.E-06)); // here!!! + zcovptot = MYMAX(zcovptot, (*yrecldp).rcovpmin); + zcovpclr = MYMAX((dtype) 0.0, zcovptot - za[jk_i]); // clear sky proportion zraincld = zqxfg[2] / zcovptot; zsnowcld = zqxfg[3] / zcovptot; - zcovpmax = fmax(zcovptot, zcovpmax); + zcovpmax = MYMAX(zcovptot, zcovpmax); } else { - zraincld = (double) 0.0; - zsnowcld = (double) 0.0; - zcovptot = (double) 0.0; // no flux - reset cover - zcovpclr = (double) 0.0; // reset clear sky proportion - zcovpmax = (double) 0.0; // reset max cover for ZZRH calc + zraincld = (dtype) 0.0; + zsnowcld = (dtype) 0.0; + zcovptot = (dtype) 0.0; // no flux - reset cover + zcovpclr = (dtype) 0.0; // reset clear sky proportion + zcovpmax = (dtype) 0.0; // reset max cover for ZZRH calc } //---------------------------------------------------------------------- @@ -1629,18 +1629,18 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------------- if (zicecld > zepsec) { - zzco = ptsphy*(*yrecldp).rsnowlin1*exp((*yrecldp).rsnowlin2*(ztp1[jk_i] - rtt)); + zzco = ptsphy*(*yrecldp).rsnowlin1*MYEXP((*yrecldp).rsnowlin2*(ztp1[jk_i] - rtt)); if ((*yrecldp).laericeauto) { zlcrit = picrit_aer[jl + klon*(jk + klev*ibl)]; // 0.3 = N**0.333 with N=0.027 - zzco = zzco*(pow(((*yrecldp).rnice / pnice[jl + klon*(jk + klev*ibl)]), - (double) 0.333)); + zzco = zzco*(MYPOW(((*yrecldp).rnice / pnice[jl + klon*(jk + klev*ibl)]), + (dtype) 0.333)); } else { zlcrit = (*yrecldp).rlcritsnow; } - zsnowaut = zzco*((double) 1.0 - exp(-(pow((zicecld / zlcrit), 2)))); + zsnowaut = zzco*((dtype) 1.0 - MYEXP(-(MYPOW((zicecld / zlcrit), 2)))); zsolqb[3 + 5*(1)] = zsolqb[3 + 5*(1)] + zsnowaut; } @@ -1666,13 +1666,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if ((*yrecldp).laerliqautolsp) { zlcrit = plcrit_aer[jl + klon*(jk + klev*ibl)]; // 0.3 = N**0.333 with N=125 cm-3 - zzco = zzco*(pow(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), - (double) 0.333)); + zzco = zzco*(MYPOW(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), + (dtype) 0.333)); } else { // Modify autoconversion threshold dependent on: // land (polluted, high CCN, smaller droplets, higher threshold) // sea (clean, low CCN, larger droplets, lower threshold) - if (plsm[jl + klon*ibl] > (double) 0.5) { + if (plsm[jl + klon*ibl] > (dtype) 0.5) { zlcrit = (*yrecldp).rclcrit_land; // land } else { zlcrit = (*yrecldp).rclcrit_sea; // ocean @@ -1685,23 +1685,23 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to REPLACE this with an explicit collection parametrization //------------------------------------------------------------------ zprecip = (zpfplsx[jk_i + 2*(3)] + zpfplsx[jk_i + 2*(2) - ]) / fmax(zepsec, zcovptot); - zcfpr = (double) 1.0 + (*yrecldp).rprc1*sqrt(fmax(zprecip, (double) 0.0)); + ]) / MYMAX(zepsec, zcovptot); + zcfpr = (dtype) 1.0 + (*yrecldp).rprc1*sqrt(MYMAX(zprecip, (dtype) 0.0)); // ZCFPR=1.0_JPRB + RPRC1*SQRT(MAX(ZPRECIP,0.0_JPRB))*& // &ZCOVPTOT(JL)/(MAX(ZA(JL,JK),ZEPSEC)) if ((*yrecldp).laerliqcoll) { // 5.0 = N**0.333 with N=125 cm-3 - zcfpr = zcfpr*(pow(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), - (double) 0.333)); + zcfpr = zcfpr*(MYPOW(((*yrecldp).rccn / pccn[jl + klon*(jk + klev*ibl)]), + (dtype) 0.333)); } zzco = zzco*zcfpr; - zlcrit = zlcrit / fmax(zcfpr, zepsec); + zlcrit = zlcrit / MYMAX(zcfpr, zepsec); - if (zliqcld / zlcrit < (double) 20.0) { + if (zliqcld / zlcrit < (dtype) 20.0) { // Security for exp for some compilers - zrainaut = zzco*((double) 1.0 - exp(-(pow((zliqcld / zlcrit), 2)))); + zrainaut = zzco*((dtype) 1.0 - MYEXP(-(MYPOW((zliqcld / zlcrit), 2)))); } else { zrainaut = zzco; } @@ -1720,7 +1720,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------------------------- } else if (iwarmrain == 2) { - if (plsm[jl + klon*ibl] > (double) 0.5) { + if (plsm[jl + klon*ibl] > (dtype) 0.5) { // land zconst = (*yrecldp).rcl_kk_cloud_num_land; zlcrit = (*yrecldp).rclcrit_land; @@ -1732,26 +1732,26 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zliqcld > zlcrit) { - zrainaut = (double) 1.5*za[jk_i]*ptsphy*(*yrecldp) - .rcl_kkaau*(pow(zliqcld, (*yrecldp).rcl_kkbauq))*(pow(zconst, (*yrecldp + zrainaut = (dtype) 1.5*za[jk_i]*ptsphy*(*yrecldp) + .rcl_kkaau*(MYPOW(zliqcld, (*yrecldp).rcl_kkbauq))*(MYPOW(zconst, (*yrecldp ).rcl_kkbaun)); - zrainaut = fmin(zrainaut, zqxfg[0]); + zrainaut = MYMIN(zrainaut, zqxfg[0]); if (zrainaut < zepsec) { - zrainaut = (double) 0.0; + zrainaut = (dtype) 0.0; } - zrainacc = (double) 2.0*za[jk_i]*ptsphy*(*yrecldp) - .rcl_kkaac*(pow((zliqcld*zraincld), (*yrecldp).rcl_kkbac)); + zrainacc = (dtype) 2.0*za[jk_i]*ptsphy*(*yrecldp) + .rcl_kkaac*(MYPOW((zliqcld*zraincld), (*yrecldp).rcl_kkbac)); - zrainacc = fmin(zrainacc, zqxfg[0]); + zrainacc = MYMIN(zrainacc, zqxfg[0]); if (zrainacc < zepsec) { - zrainacc = (double) 0.0; + zrainacc = (dtype) 0.0; } } else { - zrainaut = (double) 0.0; - zrainacc = (double) 0.0; + zrainaut = (dtype) 0.0; + zrainacc = (dtype) 0.0; } // If temperature < 0, then autoconversion produces snow rather than rain @@ -1785,21 +1785,21 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (ztp1[jk_i] <= rtt && zliqcld > zepsec) { // Fallspeed air density correction - zfallcorr = pow(((*yrecldp).rdensref / zrho), (double) 0.4); + zfallcorr = MYPOW(((*yrecldp).rdensref / zrho), (dtype) 0.4); //------------------------------------------------------------------ // Riming of snow by cloud water - implicit in lwc //------------------------------------------------------------------ - if (zsnowcld > zepsec && zcovptot > (double) 0.01) { + if (zsnowcld > zepsec && zcovptot > (dtype) 0.01) { // Calculate riming term // Factor of liq water taken out because implicit - zsnowrime = (double) 0.3*zcovptot*ptsphy*(*yrecldp) - .rcl_const7s*zfallcorr*(pow((zrho*zsnowcld*(*yrecldp).rcl_const1s), + zsnowrime = (dtype) 0.3*zcovptot*ptsphy*(*yrecldp) + .rcl_const7s*zfallcorr*(MYPOW((zrho*zsnowcld*(*yrecldp).rcl_const1s), (*yrecldp).rcl_const8s)); // Limit snow riming term - zsnowrime = fmin(zsnowrime, (double) 1.0); + zsnowrime = MYMIN(zsnowrime, (dtype) 1.0); zsolqb[3 + 5*(0)] = zsolqb[3 + 5*(0)] + zsnowrime; @@ -1837,13 +1837,13 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //---------------------------------------------------------------------- zicetot = zqxfg[1] + zqxfg[3]; - zmeltmax = (double) 0.0; + zmeltmax = (dtype) 0.0; // If there are frozen hydrometeors present and dry-bulb temperature > 0degC if (zicetot > zepsec && ztp1[jk_i] > rtt) { // Calculate subsaturation - zsubsat = fmax(zqsice - zqx[4], (double) 0.0); + zsubsat = MYMAX(zqsice - zqx[4], (dtype) 0.0); // Calculate difference between dry-bulb (ZTP1) and the temperature // at which the wet-bulb=0degC (rtt-ZSUBSAT*....) using an approx. @@ -1855,8 +1855,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Not implicit yet... // Ensure ZCONS1 is positive so that ZMELTMAX=0 if ZTDMTW0<0 zcons1 = - fabs(ptsphy*((double) 1.0 + (double) 0.5*ztdmtw0) / (*yrecldp).rtaumel); - zmeltmax = fmax(ztdmtw0*zcons1*zrldcp, (double) 0.0); + MYABS(ptsphy*((dtype) 1.0 + (dtype) 0.5*ztdmtw0) / (*yrecldp).rtaumel); + zmeltmax = MYMAX(ztdmtw0*zcons1*zrldcp, (dtype) 0.0); } // Loop over frozen hydrometeors (ice, snow) @@ -1866,7 +1866,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, if (zmeltmax > zepsec && zicetot > zepsec) { // Apply melting in same proportion as frozen hydrometeor fractions zalfa = zqxfg[jm] / zicetot; - zmelt = fmin(zqxfg[jm], zalfa*zmeltmax); + zmelt = MYMIN(zqxfg[jm], zalfa*zmeltmax); // needed in first guess // This implies that zqpretot has to be recalculated below // since is not conserved here if ice falls and liquid doesn't @@ -1890,7 +1890,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // store rain/snow fraction for precip type diagnosis // If mostly rain, then supercooled rain slow to freeze // otherwise faster to freeze (snow or ice pellets) - zqpretot = fmax(zqx[3] + zqx[2], zepsec); + zqpretot = MYMAX(zqx[3] + zqx[2], zepsec); prainfrac_toprfz[jl + klon*ibl] = zqx[2] / zqpretot; if (prainfrac_toprfz[jl + klon*ibl] > 0.8) { llrainliq = true; @@ -1909,27 +1909,27 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Slope of rain particle size distribution zlambda = - pow(((*yrecldp).rcl_fac1 / (zrho*zqx[2])), (*yrecldp).rcl_fac2); + MYPOW(((*yrecldp).rcl_fac1 / (zrho*zqx[2])), (*yrecldp).rcl_fac2); // Calculate freezing rate based on Bigg(1953) and Wisner(1972) ztemp = (*yrecldp).rcl_fzrab*(ztp1[jk_i] - rtt); - zfrz = ptsphy*((*yrecldp).rcl_const5r / zrho)*(exp(ztemp) - (double) 1.) - *(pow(zlambda, (*yrecldp).rcl_const6r)); - zfrzmax = fmax(zfrz, (double) 0.0); + zfrz = ptsphy*((*yrecldp).rcl_const5r / zrho)*(MYEXP(ztemp) - (dtype) 1.) + *(MYPOW(zlambda, (*yrecldp).rcl_const6r)); + zfrzmax = MYMAX(zfrz, (dtype) 0.0); } else { // Majority of raindrops only partially melted // Refreeze with a shorter timescale (reverse of melting...for now) - zcons1 = fabs(ptsphy*((double) 1.0 + (double) 0.5*(rtt - ztp1[jk_i]) + zcons1 = MYABS(ptsphy*((dtype) 1.0 + (dtype) 0.5*(rtt - ztp1[jk_i]) ) / (*yrecldp).rtaumel); - zfrzmax = fmax((rtt - ztp1[jk_i])*zcons1*zrldcp, (double) 0.0); + zfrzmax = MYMAX((rtt - ztp1[jk_i])*zcons1*zrldcp, (dtype) 0.0); } if (zfrzmax > zepsec) { - zfrz = fmin(zqx[2], zfrzmax); + zfrz = MYMIN(zqx[2], zfrzmax); zsolqa[3 + 5*(2)] = zsolqa[3 + 5*(2)] + zfrz; zsolqa[2 + 5*(3)] = zsolqa[2 + 5*(3)] - zfrz; } @@ -1942,12 +1942,12 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // 4.4c FREEZING of LIQUID //---------------------------------------------------------------------- // not implicit yet... - zfrzmax = fmax(((*yrecldp).rthomo - ztp1[jk_i])*zrldcp, (double) 0.0); + zfrzmax = MYMAX(((*yrecldp).rthomo - ztp1[jk_i])*zrldcp, (dtype) 0.0); jm = 1; jn = imelt[-1 + jm]; if (zfrzmax > zepsec && zqxfg[-1 + jm] > zepsec) { - zfrz = fmin(zqxfg[-1 + jm], zfrzmax); + zfrz = MYMIN(zqxfg[-1 + jm], zfrzmax); zsolqa[-1 + jn + 5*(-1 + jm)] = zsolqa[-1 + jn + 5*(-1 + jm)] + zfrz; zsolqa[-1 + jm + 5*(-1 + jn)] = zsolqa[-1 + jm + 5*(-1 + jn)] - zfrz; } @@ -1964,21 +1964,21 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Rain - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax) - *zcovpmax / fmax(zepsec, (double) 1.0 - za[jk_i]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax) + *zcovpmax / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); - zqe = (zqx[4] - za[jk_i]*zqsliq) / fmax(zepsec, (double) 1.0 - + zqe = (zqx[4] - za[jk_i]*zqsliq) / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsliq)); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsliq)); llo1 = zcovpclr > zepsec && zqxfg[2] > zepsec && zqe < zzrh*zqsliq; if (llo1) { // note: zpreclr is a rain flux - zpreclr = zqxfg[2]*zcovpclr / copysign(fmax(fabs(zcovptot*zdtgdp), + zpreclr = zqxfg[2]*zcovpclr / copysign(MYMAX(MYABS(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); //-------------------------------------- @@ -1986,11 +1986,11 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------- zbeta1 = sqrt(pap[jl + klon*(jk + klev*ibl)] / paph[jl + klon*(klev + (klev - + 1)*ibl)]) / (*yrecldp).rvrfactor*zpreclr / fmax(zcovpclr, zepsec); + + 1)*ibl)]) / (*yrecldp).rvrfactor*zpreclr / MYMAX(zcovpclr, zepsec); - zbeta = rg*(*yrecldp).rpecons*(double) 0.5*(pow(zbeta1, (double) 0.5777)); + zbeta = rg*(*yrecldp).rpecons*(dtype) 0.5*(MYPOW(zbeta1, (dtype) 0.5777)); - zdenom = (double) 1.0 + zbeta*ptsphy*zcorqsliq; + zdenom = (dtype) 1.0 + zbeta*ptsphy*zcorqsliq; zdpr = zcovpclr*zbeta*(zqsliq - zqe) / zdenom*zdp*zrg_r; zdpevap = zdpr*zdtgdp; @@ -2002,7 +2002,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Evaporate rain - zevap = fmin(zdpevap, zqxfg[2]); + zevap = MYMIN(zdpevap, zqxfg[2]); zsolqa[4 + 5*(2)] = zsolqa[4 + 5*(2)] + zevap; zsolqa[2 + 5*(4)] = zsolqa[2 + 5*(4)] - zevap; @@ -2012,7 +2012,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk_i])*zevap / zqxfg[2])); // Update fg field @@ -2032,9 +2032,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to avoid cloud formation and saturation of the grid box //----------------------------------------------------------------------- // Limit RH for rain evaporation dependent on precipitation fraction - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax) - *zcovpmax / fmax(zepsec, (double) 1.0 - za[jk_i]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax) + *zcovpmax / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); // Critical relative humidity //ZRHC=RAMID @@ -2046,9 +2046,9 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //ZZRH = MIN(ZRHC,ZZRH) // Further limit RH for rain evaporation to 80% (RHcrit in free troposphere) - zzrh = fmin((double) 0.8, zzrh); + zzrh = MYMIN((dtype) 0.8, zzrh); - zqe = fmax((double) 0.0, fmin(zqx[4], zqsliq)); + zqe = MYMAX((dtype) 0.0, MYMIN(zqx[4], zqsliq)); llo1 = zcovpclr > zepsec && zqxfg[2] > zepsec && zqe < zzrh*zqsliq; @@ -2061,33 +2061,33 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zpreclr = zqxfg[2] / zcovptot; // Fallspeed air density correction - zfallcorr = pow(((*yrecldp).rdensref / zrho), 0.4); + zfallcorr = MYPOW(((*yrecldp).rdensref / zrho), 0.4); // Saturation vapour pressure with respect to liquid phase - zesatliq = rv / rd*((double)(r2es*exp((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)))); + zesatliq = rv / rd*((dtype)(r2es*MYEXP((r3les*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4les)))); // Slope of particle size distribution - zlambda = pow(((*yrecldp).rcl_fac1 / (zrho*zpreclr)), (*yrecldp).rcl_fac2); // ZPRECLR=kg/kg + zlambda = MYPOW(((*yrecldp).rcl_fac1 / (zrho*zpreclr)), (*yrecldp).rcl_fac2); // ZPRECLR=kg/kg zevap_denom = (*yrecldp).rcl_cdenom1*zesatliq - (*yrecldp) .rcl_cdenom2*ztp1[jk_i]*zesatliq + (*yrecldp) - .rcl_cdenom3*(pow(ztp1[jk_i], (double) 3.))*pap[jl + klon*(jk + + .rcl_cdenom3*(MYPOW(ztp1[jk_i], (dtype) 3.))*pap[jl + klon*(jk + klev*ibl)]; // Temperature dependent conductivity - zcorr2 = (pow((ztp1[jk_i] / (double) 273.), (double) 1.5))*(double) - 393. / (ztp1[jk_i] + (double) 120.); + zcorr2 = (MYPOW((ztp1[jk_i] / (dtype) 273.), (dtype) 1.5))*(dtype) + 393. / (ztp1[jk_i] + (dtype) 120.); zka = (*yrecldp).rcl_ka273*zcorr2; - zsubsat = fmax(zzrh*zqsliq - zqe, (double) 0.0); + zsubsat = MYMAX(zzrh*zqsliq - zqe, (dtype) 0.0); - zbeta = ((double) 0.5 / zqsliq)*(pow(ztp1[jk_i], (double) 2.)) - *zesatliq*(*yrecldp).rcl_const1r*(zcorr2 / zevap_denom)*((double) 0.78 / - (pow(zlambda, (*yrecldp).rcl_const4r)) + (*yrecldp) - .rcl_const2r*(pow((zrho*zfallcorr), (double) 0.5)) / ((pow(zcorr2, - (double) 0.5))*(pow(zlambda, (*yrecldp).rcl_const3r)))); + zbeta = ((dtype) 0.5 / zqsliq)*(MYPOW(ztp1[jk_i], (dtype) 2.)) + *zesatliq*(*yrecldp).rcl_const1r*(zcorr2 / zevap_denom)*((dtype) 0.78 / + (MYPOW(zlambda, (*yrecldp).rcl_const4r)) + (*yrecldp) + .rcl_const2r*(MYPOW((zrho*zfallcorr), (dtype) 0.5)) / ((MYPOW(zcorr2, + (dtype) 0.5))*(MYPOW(zlambda, (*yrecldp).rcl_const3r)))); - zdenom = (double) 1.0 + zbeta*ptsphy; //*ZCORQSLIQ(JL) + zdenom = (dtype) 1.0 + zbeta*ptsphy; //*ZCORQSLIQ(JL) zdpevap = zcovpclr*zbeta*ptsphy*zsubsat / zdenom; //--------------------------------------------------------- @@ -2098,7 +2098,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Limit rain evaporation - zevap = fmin(zdpevap, zqxfg[2]); + zevap = MYMIN(zdpevap, zqxfg[2]); zsolqa[4 + 5*(2)] = zsolqa[4 + 5*(2)] + zevap; zsolqa[2 + 5*(4)] = zsolqa[2 + 5*(4)] - zevap; @@ -2108,7 +2108,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk_i])*zevap / zqxfg[2])); // Update fg field @@ -2125,21 +2125,21 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Snow if (ievapsnow == 1) { - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax) - *zcovpmax / fmax(zepsec, (double) 1.0 - za[jk_i]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); - zqe = (zqx[4] - za[jk_i]*zqsice) / fmax(zepsec, (double) 1.0 - + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax) + *zcovpmax / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); + zqe = (zqx[4] - za[jk_i]*zqsice) / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsice)); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsice)); llo1 = zcovpclr > zepsec && zqxfg[3] > zepsec && zqe < zzrh*zqsice; if (llo1) { // note: zpreclr is a rain flux a - zpreclr = zqxfg[3]*zcovpclr / copysign(fmax(fabs(zcovptot*zdtgdp), + zpreclr = zqxfg[3]*zcovpclr / copysign(MYMAX(MYABS(zcovptot*zdtgdp), zepsilon), zcovptot*zdtgdp); //-------------------------------------- @@ -2147,11 +2147,11 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //-------------------------------------- zbeta1 = sqrt(pap[jl + klon*(jk + klev*ibl)] / paph[jl + klon*(klev + (klev - + 1)*ibl)]) / (*yrecldp).rvrfactor*zpreclr / fmax(zcovpclr, zepsec); + + 1)*ibl)]) / (*yrecldp).rvrfactor*zpreclr / MYMAX(zcovpclr, zepsec); - zbeta = rg*(*yrecldp).rpecons*(pow(zbeta1, (double) 0.5777)); + zbeta = rg*(*yrecldp).rpecons*(MYPOW(zbeta1, (dtype) 0.5777)); - zdenom = (double) 1.0 + zbeta*ptsphy*zcorqsice; + zdenom = (dtype) 1.0 + zbeta*ptsphy*zcorqsice; zdpr = zcovpclr*zbeta*(zqsice - zqe) / zdenom*zdp*zrg_r; zdpevap = zdpr*zdtgdp; @@ -2163,7 +2163,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------------------------------- // Evaporate snow - zevap = fmin(zdpevap, zqxfg[3]); + zevap = MYMIN(zdpevap, zqxfg[3]); zsolqa[4 + 5*(3)] = zsolqa[4 + 5*(3)] + zevap; zsolqa[3 + 5*(4)] = zsolqa[3 + 5*(4)] - zevap; @@ -2173,7 +2173,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk_i])*zevap / zqxfg[3])); //Update first guess field @@ -2188,54 +2188,54 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //----------------------------------------------------------------------- // Calculate relative humidity limit for snow evaporation //----------------------------------------------------------------------- - zzrh = (*yrecldp).rprecrhmax + ((double) 1.0 - (*yrecldp).rprecrhmax) - *zcovpmax / fmax(zepsec, (double) 1.0 - za[jk_i]); - zzrh = fmin(fmax(zzrh, (*yrecldp).rprecrhmax), (double) 1.0); - zqe = (zqx[4] - za[jk_i]*zqsice) / fmax(zepsec, (double) 1.0 - + zzrh = (*yrecldp).rprecrhmax + ((dtype) 1.0 - (*yrecldp).rprecrhmax) + *zcovpmax / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); + zzrh = MYMIN(MYMAX(zzrh, (*yrecldp).rprecrhmax), (dtype) 1.0); + zqe = (zqx[4] - za[jk_i]*zqsice) / MYMAX(zepsec, (dtype) 1.0 - za[jk_i]); //--------------------------------------------- // humidity in moistest ZCOVPCLR part of domain //--------------------------------------------- - zqe = fmax((double) 0.0, fmin(zqe, zqsice)); + zqe = MYMAX((dtype) 0.0, MYMIN(zqe, zqsice)); llo1 = zcovpclr > zepsec && zqx[3] > zepsec && zqe < zzrh*zqsice; if (llo1) { // Calculate local precipitation (kg/kg) zpreclr = zqx[3] / zcovptot; - zvpice = ((double)(r2es*exp((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))*rv / rd; + zvpice = ((dtype)(r2es*MYEXP((r3ies*(ztp1[jk_i] - rtt))/(ztp1[jk_i] - r4ies))))*rv / rd; // Particle size distribution // ZTCG increases Ni with colder temperatures - essentially a // Fletcher or Meyers scheme? - ztcg = (double) 1.0; //v1 EXP(RCL_X3I*(273.15_JPRB-ZTP1(JL,JK))/8.18_JPRB) + ztcg = (dtype) 1.0; //v1 EXP(RCL_X3I*(273.15_JPRB-ZTP1(JL,JK))/8.18_JPRB) // ZFACX1I modification is based on Andrew Barrett's results - zfacx1s = (double) 1.0; //v1 (ZICE0/1.E-5_JPRB)**0.627_JPRB + zfacx1s = (dtype) 1.0; //v1 (ZICE0/1.E-5_JPRB)**0.627_JPRB zaplusb = (*yrecldp).rcl_apb1*zvpice - (*yrecldp).rcl_apb2*zvpice*ztp1[jk_i] + - pap[jl + klon*(jk + klev*ibl)]*(*yrecldp).rcl_apb3*(pow(ztp1[jk_i], 3)); - zcorrfac = pow((1.0 / zrho), 0.5); + pap[jl + klon*(jk + klev*ibl)]*(*yrecldp).rcl_apb3*(MYPOW(ztp1[jk_i], 3)); + zcorrfac = MYPOW((1.0 / zrho), 0.5); zcorrfac2 = - (pow((ztp1[jk_i] / 273.0), 1.5))*(393.0 / (ztp1[jk_i] + 120.0)) + (MYPOW((ztp1[jk_i] / 273.0), 1.5))*(393.0 / (ztp1[jk_i] + 120.0)) ; zpr02 = zrho*zpreclr*(*yrecldp).rcl_const1s / (ztcg*zfacx1s); - zterm1 = (zqsice - zqe)*(pow(ztp1[jk_i], 2)) + zterm1 = (zqsice - zqe)*(MYPOW(ztp1[jk_i], 2)) *zvpice*zcorrfac2*ztcg*(*yrecldp).rcl_const2s*zfacx1s / (zrho*zaplusb*zqsice); - zterm2 = 0.65*(*yrecldp).rcl_const6s*(pow(zpr02, (*yrecldp).rcl_const4s)) + - (*yrecldp).rcl_const3s*(pow(zcorrfac, 0.5))*(pow(zrho, 0.5))*(pow(zpr02, - (*yrecldp).rcl_const5s)) / (pow(zcorrfac2, 0.5)); + zterm2 = 0.65*(*yrecldp).rcl_const6s*(MYPOW(zpr02, (*yrecldp).rcl_const4s)) + + (*yrecldp).rcl_const3s*(MYPOW(zcorrfac, 0.5))*(MYPOW(zrho, 0.5))*(MYPOW(zpr02, + (*yrecldp).rcl_const5s)) / (MYPOW(zcorrfac2, 0.5)); - zdpevap = fmax(zcovpclr*zterm1*zterm2*ptsphy, (double) 0.0); + zdpevap = MYMAX(zcovpclr*zterm1*zterm2*ptsphy, (dtype) 0.0); //-------------------------------------------------------------------- // Limit evaporation to snow amount //-------------------------------------------------------------------- - zevap = fmin(zdpevap, zevaplimice); - zevap = fmin(zevap, zqx[3]); + zevap = MYMIN(zdpevap, zevaplimice); + zevap = MYMIN(zevap, zqx[3]); zsolqa[4 + 5*(3)] = zsolqa[4 + 5*(3)] + zevap; @@ -2246,7 +2246,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // to mimic the previous scheme which had a diagnostic // 2-flux treatment, abandoned due to the new prognostic precip //------------------------------------------------------------- - zcovptot = fmax((*yrecldp).rcovpmin, zcovptot - fmax((double) 0.0, + zcovptot = MYMAX((*yrecldp).rcovpmin, zcovptot - MYMAX((dtype) 0.0, (zcovptot - za[jk_i])*zevap / zqx[3])); //Update first guess field @@ -2278,10 +2278,10 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- // 5.1 solver for cloud cover //--------------------------- - zanew = (za[jk_i] + zsolac) / ((double) 1.0 + zsolab); - zanew = fmin(zanew, (double) 1.0); + zanew = (za[jk_i] + zsolac) / ((dtype) 1.0 + zsolab); + zanew = MYMIN(zanew, (dtype) 1.0); if (zanew < (*yrecldp).ramin) { - zanew = (double) 0.0; + zanew = (dtype) 0.0; } zda = zanew - zaorig; //--------------------------------- @@ -2303,7 +2303,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jn = 0; jn <= 5 + -1; jn += 1) { llindex3[jn + 5*jm] = false; } - zsinksum[jm] = (double) 0.0; + zsinksum[jm] = (dtype) 0.0; } //---------------------------- @@ -2319,8 +2319,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // calculate overshoot and scaling factor //--------------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zmax = fmax(zqx[jm], zepsec); - zrat = fmax(zsinksum[jm], zmax); + zmax = MYMAX(zqx[jm], zepsec); + zrat = MYMAX(zsinksum[jm], zmax); zratio[jm] = zmax / zrat; } @@ -2329,7 +2329,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // recalculating the scale factor each time //-------------------------------------------- for (jm = 0; jm <= 5 + -1; jm += 1) { - zsinksum[jm] = (double) 0.0; + zsinksum[jm] = (dtype) 0.0; } //---------------- @@ -2345,8 +2345,8 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------- // recalculate scaling factor //--------------------------- - zmm = fmax(zqx[jm], zepsec); - zrr = fmax(zsinksum[jm], zmm); + zmm = MYMAX(zqx[jm], zepsec); + zrr = MYMAX(zsinksum[jm], zmm); zratio[jm] = zmm / zrr; //------ // scale @@ -2355,7 +2355,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //DIR$ IVDEP //DIR$ PREFERVECTOR for (jn = 0; jn <= 5 + -1; jn += 1) { - if (zsolqa[jm + 5*jn] < (double) 0.0) { + if (zsolqa[jm + 5*jn] < (dtype) 0.0) { zsolqa[jm + 5*jn] = zsolqa[jm + 5*jn]*zzratio; zsolqa[jn + 5*jm] = zsolqa[jn + 5*jm]*zzratio; } @@ -2375,7 +2375,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // diagonals: microphysical sink terms+transport //---------------------------------------------- if (jn + 1 == jm + 1) { - zqlhs[jn + 5*jm] = (double) 1.0 + zfallsink[jm]; + zqlhs[jn + 5*jm] = (dtype) 1.0 + zfallsink[jm]; for (jo = 0; jo <= 5 + -1; jo += 1) { zqlhs[jn + 5*jm] = zqlhs[jn + 5*jm] + zsolqb[jo + 5*jn]; } @@ -2395,7 +2395,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, //--------------------------------- // sum the explicit source and sink //--------------------------------- - zexplicit = (double) 0.0; + zexplicit = (dtype) 0.0; for (jn = 0; jn <= 5 + -1; jn += 1) { zexplicit = zexplicit + zsolqa[jm + 5*jn]; // sum over middle index } @@ -2448,7 +2448,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, for (jn = 0; jn <= 5 - 1 + -1; jn += 1) { if (zqxn[jn] < zepsec) { zqxn[4] = zqxn[4] + zqxn[jn]; - zqxn[jn] = (double) 0.0; + zqxn[jn] = (dtype) 0.0; } } @@ -2474,7 +2474,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, zqpretot = zpfplsx[jk_ip1 + 2*(3)] + zpfplsx[jk_ip1 + 2*(2)]; if (zqpretot < zepsec) { - zcovptot = (double) 0.0; + zcovptot = (dtype) 0.0; } //###################################################################### @@ -2601,7 +2601,7 @@ __global__ void cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, // Ice , LS scheme minus detrainment pfsqif[jl + klon*(1 + jk + (klev + 1)*ibl)] = pfsqif[jl + klon*(1 + jk + (klev + 1)*ibl)] + (zqxn2d[1] - zqx0[1] + pvfi[jl + klon*(jk + klev*ibl) - ]*ptsphy - ((double) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)])*zgdph_r; + ]*ptsphy - ((dtype) 1.0 - zalfaw)*plude[jl + klon*(jk + klev*ibl)])*zgdph_r; // ice, negative numbers pfcqnng[jl + klon*(1 + jk + (klev + 1)*ibl)] = pfcqnng[jl + klon*(1 + jk + (klev + 1)*ibl)] + zlneg[1]*zgdph_r; diff --git a/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.h b/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.h index e4d0364b..2db230ca 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.h +++ b/src/cloudsc_hip/cloudsc/cloudsc_c_k_caching.h @@ -12,33 +12,34 @@ #include "hip/hip_runtime.h" #include "yoecldp_c.h" #include +#include "dtype.h" -__global__ void __launch_bounds__(128, 1) cloudsc_c(int kidia, int kfdia, int klon, double ptsphy, - const double * __restrict__ pt, - const double * __restrict__ pq, const double * __restrict__ tendency_tmp_t, - const double * __restrict__ tendency_tmp_q, const double * __restrict__ tendency_tmp_a, - const double * __restrict__ tendency_tmp_cld, double * __restrict__ tendency_loc_t, - double * __restrict__ tendency_loc_q, double * __restrict__ tendency_loc_a, - double * __restrict__ tendency_loc_cld, const double * __restrict__ pvfa, - const double * __restrict__ pvfl, const double * __restrict__ pvfi, const double * __restrict__ pdyna, - const double * __restrict__ pdynl, const double * __restrict__ pdyni, const double * __restrict__ phrsw, - double * __restrict__ phrlw, const double * __restrict__ pvervel, const double * __restrict__ pap, - const double * __restrict__ paph, const double * __restrict__ plsm, - const int * ktype, const double * __restrict__ plu, double * __restrict__ plude, - const double * __restrict__ psnde, const double * __restrict__ pmfu, const double * __restrict__ pmfd, - const double * __restrict__ pa, const double * __restrict__ pclv, const double * __restrict__ psupsat, - const double * __restrict__ plcrit_aer, const double * __restrict__ picrit_aer, - const double * __restrict__ pre_ice, const double * __restrict__ pccn, const double * __restrict__ pnice, - double * __restrict__ pcovptot, double * __restrict__ prainfrac_toprfz, - double * __restrict__ pfsqlf, double * __restrict__ pfsqif, double * __restrict__ pfcqnng, - double * __restrict__ pfcqlng, double * __restrict__ pfsqrf, double * __restrict__ pfsqsf, - double * __restrict__ pfcqrng, double * __restrict__ pfcqsng, - double * __restrict__ pfsqltur, double * __restrict__ pfsqitur, - double * __restrict__ pfplsl, double * __restrict__ pfplsn, double * __restrict__ pfhpsl, - double * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, - double rg, double rd, double rcpd, double retv, double rlvtt, double rlstt, double rlmlt, double rtt, - double rv, double r2es, double r3les, double r3ies, double r4les, double r4ies, double r5les, - double r5ies, double r5alvcp, double r5alscp, double ralvdcp, double ralsdcp, double ralfdcp, - double rtwat, double rtice, double rticecu, double rtwat_rtice_r, double rtwat_rticecu_r, - double rkoop1, double rkoop2); +__global__ void __launch_bounds__(128, 1) cloudsc_c(int kidia, int kfdia, int klon, dtype ptsphy, + const dtype * __restrict__ pt, + const dtype * __restrict__ pq, const dtype * __restrict__ tendency_tmp_t, + const dtype * __restrict__ tendency_tmp_q, const dtype * __restrict__ tendency_tmp_a, + const dtype * __restrict__ tendency_tmp_cld, dtype * __restrict__ tendency_loc_t, + dtype * __restrict__ tendency_loc_q, dtype * __restrict__ tendency_loc_a, + dtype * __restrict__ tendency_loc_cld, const dtype * __restrict__ pvfa, + const dtype * __restrict__ pvfl, const dtype * __restrict__ pvfi, const dtype * __restrict__ pdyna, + const dtype * __restrict__ pdynl, const dtype * __restrict__ pdyni, const dtype * __restrict__ phrsw, + dtype * __restrict__ phrlw, const dtype * __restrict__ pvervel, const dtype * __restrict__ pap, + const dtype * __restrict__ paph, const dtype * __restrict__ plsm, + const int * ktype, const dtype * __restrict__ plu, dtype * __restrict__ plude, + const dtype * __restrict__ psnde, const dtype * __restrict__ pmfu, const dtype * __restrict__ pmfd, + const dtype * __restrict__ pa, const dtype * __restrict__ pclv, const dtype * __restrict__ psupsat, + const dtype * __restrict__ plcrit_aer, const dtype * __restrict__ picrit_aer, + const dtype * __restrict__ pre_ice, const dtype * __restrict__ pccn, const dtype * __restrict__ pnice, + dtype * __restrict__ pcovptot, dtype * __restrict__ prainfrac_toprfz, + dtype * __restrict__ pfsqlf, dtype * __restrict__ pfsqif, dtype * __restrict__ pfcqnng, + dtype * __restrict__ pfcqlng, dtype * __restrict__ pfsqrf, dtype * __restrict__ pfsqsf, + dtype * __restrict__ pfcqrng, dtype * __restrict__ pfcqsng, + dtype * __restrict__ pfsqltur, dtype * __restrict__ pfsqitur, + dtype * __restrict__ pfplsl, dtype * __restrict__ pfplsn, dtype * __restrict__ pfhpsl, + dtype * __restrict__ pfhpsn, struct TECLDP *yrecldp, int ngpblks, + dtype rg, dtype rd, dtype rcpd, dtype retv, dtype rlvtt, dtype rlstt, dtype rlmlt, dtype rtt, + dtype rv, dtype r2es, dtype r3les, dtype r3ies, dtype r4les, dtype r4ies, dtype r5les, + dtype r5ies, dtype r5alvcp, dtype r5alscp, dtype ralvdcp, dtype ralsdcp, dtype ralfdcp, + dtype rtwat, dtype rtice, dtype rticecu, dtype rtwat_rtice_r, dtype rtwat_rticecu_r, + dtype rkoop1, dtype rkoop2); diff --git a/src/cloudsc_hip/cloudsc/cloudsc_driver.cpp b/src/cloudsc_hip/cloudsc/cloudsc_driver.cpp index dc7efc79..25ebafce 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_driver.cpp +++ b/src/cloudsc_hip/cloudsc/cloudsc_driver.cpp @@ -28,87 +28,87 @@ inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=tr void cloudsc_driver(int numthreads, int numcols, int nproma) { - double *tend_tmp_u; - double *tend_tmp_v; - double *tend_tmp_t; - double *tend_tmp_q; - double *tend_tmp_o3; - double *tend_tmp_a; - double *tend_tmp_cld; - - double *tend_loc_u; - double *tend_loc_v; - double *tend_loc_t; - double *tend_loc_q; - double *tend_loc_o3; - double *tend_loc_a; - double *tend_loc_cld; - - double *tend_cml_u; - double *tend_cml_v; - double *tend_cml_t; - double *tend_cml_q; - double *tend_cml_o3; - double *tend_cml_a; - double *tend_cml_cld; - - double ptsphy; //! Physics timestep - - double *plcrit_aer; - double *picrit_aer; - double *pre_ice; - double *pccn; //! liquid cloud condensation nuclei - double *pnice; //! ice number concentration (cf. CCN) - double *pt; //! T at start of callpar - double *pq; //! Q at start of callpar - double *pvfa; //! CC from VDF scheme - double *pvfl; //! Liq from VDF scheme - double *pvfi; //! Ice from VDF scheme - double *pdyna; //! CC from Dynamics - double *pdynl; //! Liq from Dynamics - double *pdyni; //! Liq from Dynamics - double *phrsw; //! Short-wave heating rate - double *phrlw; //! Long-wave heating rate - double *pvervel; //! Vertical velocity - double *pap; //! Pressure on full levels - double *paph; //! Pressure on half levels - double *plsm; //! Land fraction (0-1) + dtype *tend_tmp_u; + dtype *tend_tmp_v; + dtype *tend_tmp_t; + dtype *tend_tmp_q; + dtype *tend_tmp_o3; + dtype *tend_tmp_a; + dtype *tend_tmp_cld; + + dtype *tend_loc_u; + dtype *tend_loc_v; + dtype *tend_loc_t; + dtype *tend_loc_q; + dtype *tend_loc_o3; + dtype *tend_loc_a; + dtype *tend_loc_cld; + + dtype *tend_cml_u; + dtype *tend_cml_v; + dtype *tend_cml_t; + dtype *tend_cml_q; + dtype *tend_cml_o3; + dtype *tend_cml_a; + dtype *tend_cml_cld; + + dtype ptsphy; //! Physics timestep + + dtype *plcrit_aer; + dtype *picrit_aer; + dtype *pre_ice; + dtype *pccn; //! liquid cloud condensation nuclei + dtype *pnice; //! ice number concentration (cf. CCN) + dtype *pt; //! T at start of callpar + dtype *pq; //! Q at start of callpar + dtype *pvfa; //! CC from VDF scheme + dtype *pvfl; //! Liq from VDF scheme + dtype *pvfi; //! Ice from VDF scheme + dtype *pdyna; //! CC from Dynamics + dtype *pdynl; //! Liq from Dynamics + dtype *pdyni; //! Liq from Dynamics + dtype *phrsw; //! Short-wave heating rate + dtype *phrlw; //! Long-wave heating rate + dtype *pvervel; //! Vertical velocity + dtype *pap; //! Pressure on full levels + dtype *paph; //! Pressure on half levels + dtype *plsm; //! Land fraction (0-1) int *ldcum; int *ktype; //! Convection type 0,1,2 - double *plu; //! Conv. condensate - double *plude; //! Conv. detrained water - double *plude_tmp; - double *psnde; //! Conv. detrained snow - double *pmfu; //! Conv. mass flux up - double *pmfd; //! Conv. mass flux down - double *pa; //! Original Cloud fraction (t) - - double *pclv; - double *psupsat; - - double *pcovptot; //! Precip fraction - double *prainfrac_toprfz; - double *pfsqlf; //! Flux of liquid - double *pfsqif; //! Flux of ice - double *pfcqlng; //! -ve corr for liq - double *pfcqnng; //! -ve corr for ice - double *pfsqrf; //! Flux diagnostics - double *pfsqsf; //! for DDH, generic - double *pfcqrng; //! rain - double *pfcqsng; //! snow - double *pfsqltur; //! liquid flux due to VDF - double *pfsqitur; //! ice flux due to VDF - double *pfplsl; //! liq+rain sedim flux - double *pfplsn; //! ice+snow sedim flux - double *pfhpsl; //! Enthalpy flux for liq - double *pfhpsn; //! Enthalpy flux for ice + dtype *plu; //! Conv. condensate + dtype *plude; //! Conv. detrained water + dtype *plude_tmp; + dtype *psnde; //! Conv. detrained snow + dtype *pmfu; //! Conv. mass flux up + dtype *pmfd; //! Conv. mass flux down + dtype *pa; //! Original Cloud fraction (t) + + dtype *pclv; + dtype *psupsat; + + dtype *pcovptot; //! Precip fraction + dtype *prainfrac_toprfz; + dtype *pfsqlf; //! Flux of liquid + dtype *pfsqif; //! Flux of ice + dtype *pfcqlng; //! -ve corr for liq + dtype *pfcqnng; //! -ve corr for ice + dtype *pfsqrf; //! Flux diagnostics + dtype *pfsqsf; //! for DDH, generic + dtype *pfcqrng; //! rain + dtype *pfcqsng; //! snow + dtype *pfsqltur; //! liquid flux due to VDF + dtype *pfsqitur; //! ice flux due to VDF + dtype *pfplsl; //! liq+rain sedim flux + dtype *pfplsn; //! ice+snow sedim flux + dtype *pfhpsl; //! Enthalpy flux for liq + dtype *pfhpsn; //! Enthalpy flux for ice /* Define or query data dimensions from input file */ int klon, nlev; int nblocks = (numcols / nproma) + min(numcols % nproma, 1); - double zinfo[4][numthreads]; - const double zhpm = 12482329.0; // IBM P7 HPM flop count for 100 points at L137 + dtype zinfo[4][numthreads]; + const dtype zhpm = 12482329.0; // IBM P7 HPM flop count for 100 points at L137 int nclv; // number of microphysics variables int ncldql; // liquid cloud water @@ -128,204 +128,204 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { query_state(&klon, &nlev); - tend_loc_t = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_loc_q = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_loc_a = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_loc_cld = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - tend_cml_t = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_cml_q = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_cml_a = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_cml_cld = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - tend_tmp_t = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_tmp_q = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_tmp_a = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_tmp_cld = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - - plcrit_aer = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - picrit_aer = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pre_ice = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pccn = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pnice = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pt = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pq = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvfa = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvfl = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvfi = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pdyna = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pdynl = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pdyni = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - phrsw = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - phrlw = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvervel = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pap = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - paph = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - plsm = (double*) malloc( sizeof(double) * nblocks*nproma ); + tend_loc_t = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_loc_q = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_loc_a = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_loc_cld = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + tend_cml_t = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_cml_q = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_cml_a = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_cml_cld = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + tend_tmp_t = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_tmp_q = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_tmp_a = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_tmp_cld = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + + plcrit_aer = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + picrit_aer = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pre_ice = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pccn = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pnice = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pt = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pq = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvfa = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvfl = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvfi = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pdyna = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pdynl = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pdyni = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + phrsw = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + phrlw = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvervel = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pap = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + paph = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + plsm = (dtype*) malloc( sizeof(dtype) * nblocks*nproma ); ldcum = (int*) malloc( sizeof(int) * nblocks*nproma ); ktype = (int*) malloc( sizeof(int) * nblocks*nproma ); - plu = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - plude = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - psnde = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pmfu = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pmfd = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pa = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pclv = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - psupsat = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pcovptot = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - prainfrac_toprfz = (double*) malloc( sizeof(double) * nblocks*nproma ); - pfsqlf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqif = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqnng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqlng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqrf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqsf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqrng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqsng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqltur = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqitur = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfplsl = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfplsn = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfhpsl = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfhpsn = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - - - double rg; - double rd; - double rcpd; - double retv; - double rlvtt; - double rlstt; - double rlmlt; - double rtt; - double rv; - double r2es; - double r3les; - double r3ies; - double r4les; - double r4ies; - double r5les; - double r5ies; - double r5alvcp; - double r5alscp; - double ralvdcp; - double ralsdcp; - double ralfdcp; - double rtwat; - double rtice; - double rticecu; - double rtwat_rtice_r; - double rtwat_rticecu_r; - double rkoop1; - double rkoop2; + plu = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + plude = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + psnde = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pmfu = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pmfd = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pa = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pclv = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + psupsat = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pcovptot = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + prainfrac_toprfz = (dtype*) malloc( sizeof(dtype) * nblocks*nproma ); + pfsqlf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqif = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqnng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqlng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqrf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqsf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqrng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqsng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqltur = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqitur = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfplsl = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfplsn = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfhpsl = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfhpsn = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + + + dtype rg; + dtype rd; + dtype rcpd; + dtype retv; + dtype rlvtt; + dtype rlstt; + dtype rlmlt; + dtype rtt; + dtype rv; + dtype r2es; + dtype r3les; + dtype r3ies; + dtype r4les; + dtype r4ies; + dtype r5les; + dtype r5ies; + dtype r5alvcp; + dtype r5alscp; + dtype ralvdcp; + dtype ralsdcp; + dtype ralfdcp; + dtype rtwat; + dtype rtice; + dtype rticecu; + dtype rtwat_rtice_r; + dtype rtwat_rticecu_r; + dtype rkoop1; + dtype rkoop2; // device declarations - double *d_plcrit_aer; - double *d_picrit_aer; - double *d_pre_ice; - double *d_pccn; - double *d_pnice; - double *d_pt; - double *d_pq; - double *d_tend_loc_t; - double *d_tend_loc_q; - double *d_tend_loc_a; - double *d_tend_loc_cld; - double *d_tend_tmp_t; - double *d_tend_tmp_q; - double *d_tend_tmp_a; - double *d_tend_tmp_cld; - double *d_pvfa; - double *d_pvfl; - double *d_pvfi; - double *d_pdyna; - double *d_pdynl; - double *d_pdyni; - double *d_phrsw; - double *d_phrlw; - double *d_pvervel; - double *d_pap; - double *d_paph; - double *d_plsm; + dtype *d_plcrit_aer; + dtype *d_picrit_aer; + dtype *d_pre_ice; + dtype *d_pccn; + dtype *d_pnice; + dtype *d_pt; + dtype *d_pq; + dtype *d_tend_loc_t; + dtype *d_tend_loc_q; + dtype *d_tend_loc_a; + dtype *d_tend_loc_cld; + dtype *d_tend_tmp_t; + dtype *d_tend_tmp_q; + dtype *d_tend_tmp_a; + dtype *d_tend_tmp_cld; + dtype *d_pvfa; + dtype *d_pvfl; + dtype *d_pvfi; + dtype *d_pdyna; + dtype *d_pdynl; + dtype *d_pdyni; + dtype *d_phrsw; + dtype *d_phrlw; + dtype *d_pvervel; + dtype *d_pap; + dtype *d_paph; + dtype *d_plsm; int *d_ktype; - double *d_plu; - double *d_plude; - double *d_psnde; - double *d_pmfu; - double *d_pmfd; - double *d_pa; - double *d_pclv; - double *d_psupsat; + dtype *d_plu; + dtype *d_plude; + dtype *d_psnde; + dtype *d_pmfu; + dtype *d_pmfd; + dtype *d_pa; + dtype *d_pclv; + dtype *d_psupsat; struct TECLDP *d_yrecldp; - double *d_pcovptot; - double *d_prainfrac_toprfz; - double *d_pfsqlf; - double *d_pfsqif; - double *d_pfcqnng; - double *d_pfcqlng; - double *d_pfsqrf; - double *d_pfsqsf; - double *d_pfcqrng; - double *d_pfcqsng; - double *d_pfsqltur; - double *d_pfsqitur; - double *d_pfplsl; - double *d_pfplsn; - double *d_pfhpsl; - double *d_pfhpsn; + dtype *d_pcovptot; + dtype *d_prainfrac_toprfz; + dtype *d_pfsqlf; + dtype *d_pfsqif; + dtype *d_pfcqnng; + dtype *d_pfcqlng; + dtype *d_pfsqrf; + dtype *d_pfsqsf; + dtype *d_pfcqrng; + dtype *d_pfcqsng; + dtype *d_pfsqltur; + dtype *d_pfsqitur; + dtype *d_pfplsl; + dtype *d_pfplsn; + dtype *d_pfhpsl; + dtype *d_pfhpsn; // end device declarations - hipMalloc(&d_plcrit_aer, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_picrit_aer, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pre_ice, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pccn, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pnice, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pt, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pq, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_t, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_q, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_a, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_cld, sizeof(double) * nblocks*nlev*nproma*nclv); - hipMalloc(&d_tend_tmp_t, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_tmp_q, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_tmp_a, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_tmp_cld, sizeof(double) * nblocks*nlev*nproma*nclv); - hipMalloc(&d_pvfa, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pvfl, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pvfi, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pdyna, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pdynl, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pdyni, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_phrsw, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_phrlw, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pvervel, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pap, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_paph, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_plsm, sizeof(double) * nblocks*nproma); + hipMalloc(&d_plcrit_aer, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_picrit_aer, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pre_ice, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pccn, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pnice, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pt, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pq, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_t, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_q, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_a, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv); + hipMalloc(&d_tend_tmp_t, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_tmp_q, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_tmp_a, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_tmp_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv); + hipMalloc(&d_pvfa, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pvfl, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pvfi, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pdyna, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pdynl, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pdyni, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_phrsw, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_phrlw, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pvervel, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pap, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_paph, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_plsm, sizeof(dtype) * nblocks*nproma); hipMalloc(&d_ktype, sizeof(int) * nblocks*nproma); - hipMalloc(&d_plu, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_plude, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_psnde, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pmfu, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pmfd, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pa, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pclv, sizeof(double) * nblocks*nlev*nproma*nclv); - hipMalloc(&d_psupsat, sizeof(double) * nblocks*nlev*nproma); + hipMalloc(&d_plu, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_plude, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_psnde, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pmfu, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pmfd, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pa, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pclv, sizeof(dtype) * nblocks*nlev*nproma*nclv); + hipMalloc(&d_psupsat, sizeof(dtype) * nblocks*nlev*nproma); hipMalloc(&d_yrecldp, sizeof(struct TECLDP)); - hipMalloc(&d_pcovptot, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_prainfrac_toprfz, sizeof(double) * nblocks*nproma); - hipMalloc(&d_pfsqlf, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqif, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqnng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqlng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqrf, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqsf, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqrng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqsng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqltur, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqitur, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfplsl, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfplsn, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfhpsl, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfhpsn, sizeof(double) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pcovptot, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_prainfrac_toprfz, sizeof(dtype) * nblocks*nproma); + hipMalloc(&d_pfsqlf, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqif, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqnng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqlng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqrf, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqsf, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqrng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqsng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqltur, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqitur, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfplsl, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfplsn, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfhpsl, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfhpsn, sizeof(dtype) * nblocks*(nlev+1)*nproma); load_state(klon, nlev, nclv, numcols, nproma, &ptsphy, plcrit_aer, picrit_aer, pre_ice, pccn, pnice, pt, pq, @@ -342,42 +342,42 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { &rkoop1, &rkoop2 ); // host to device - hipMemcpy(d_plcrit_aer, plcrit_aer, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_picrit_aer, picrit_aer, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pre_ice, pre_ice, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pccn, pccn, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pnice, pnice, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pt, pt, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pq, pq, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_t, tend_loc_t, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_q, tend_loc_q, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_a, tend_loc_a, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_cld, tend_loc_cld, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_t, tend_tmp_t, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_q, tend_tmp_q, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_a, tend_tmp_a, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_cld, tend_tmp_cld, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); - hipMemcpy(d_pvfa, pvfa, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pvfl, pvfl, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pvfi, pvfi, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pdyna, pdyna, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pdynl, pdynl, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pdyni, pdyni, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_phrsw, phrsw, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_phrlw, phrlw, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pvervel, pvervel, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pap, pap, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_paph, paph, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_plsm, plsm, sizeof(double) * nblocks*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plcrit_aer, plcrit_aer, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_picrit_aer, picrit_aer, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pre_ice, pre_ice, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pccn, pccn, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pnice, pnice, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pt, pt, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pq, pq, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_t, tend_loc_t, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_q, tend_loc_q, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_a, tend_loc_a, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_cld, tend_loc_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_t, tend_tmp_t, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_q, tend_tmp_q, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_a, tend_tmp_a, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_cld, tend_tmp_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); + hipMemcpy(d_pvfa, pvfa, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pvfl, pvfl, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pvfi, pvfi, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pdyna, pdyna, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pdynl, pdynl, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pdyni, pdyni, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_phrsw, phrsw, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_phrlw, phrlw, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pvervel, pvervel, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pap, pap, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_paph, paph, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plsm, plsm, sizeof(dtype) * nblocks*nproma, hipMemcpyHostToDevice); hipMemcpy(d_ktype, ktype, sizeof(int) * nblocks*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_plu, plu, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_plude, plude, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_psnde, psnde, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pmfu, pmfu, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pmfd, pmfd, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pa, pa, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pclv, pclv, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); - hipMemcpy(d_psupsat, psupsat, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plu, plu, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plude, plude, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_psnde, psnde, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pmfu, pmfu, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pmfd, pmfd, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pa, pa, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pclv, pclv, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); + hipMemcpy(d_psupsat, psupsat, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); hipMemcpy(d_yrecldp, yrecldp, sizeof(TECLDP), hipMemcpyHostToDevice); // end host to device @@ -389,8 +389,8 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { double start = omp_get_wtime(); dim3 blockdim(nproma, 1, 1); - //dim3 griddim(1, 1, ceil(((double)numcols) / ((double)nproma))); - dim3 griddim(ceil(((double)numcols) / ((double)nproma)), 1, 1); + //dim3 griddim(1, 1, ceil(((dtype)numcols) / ((dtype)nproma))); + dim3 griddim(ceil(((dtype)numcols) / ((dtype)nproma)), 1, 1); int jkglo = 0; int ibl = (jkglo - 1) / nproma + 1; int icend = min(nproma, numcols - jkglo + 1); @@ -423,36 +423,36 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { double end = omp_get_wtime(); // device to host - hipMemcpy(tend_loc_t, d_tend_loc_t, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(tend_loc_q, d_tend_loc_q, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(tend_loc_a, d_tend_loc_a, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(tend_loc_cld, d_tend_loc_cld, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyDeviceToHost); - hipMemcpy(phrlw, d_phrlw, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(plude, d_plude, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_t, d_tend_loc_t, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_q, d_tend_loc_q, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_a, d_tend_loc_a, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_cld, d_tend_loc_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyDeviceToHost); + hipMemcpy(phrlw, d_phrlw, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(plude, d_plude, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); hipMemcpy(yrecldp, d_yrecldp, sizeof(TECLDP), hipMemcpyDeviceToHost); - hipMemcpy(pcovptot, d_pcovptot, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(prainfrac_toprfz, d_prainfrac_toprfz, sizeof(double) * nblocks*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqlf, d_pfsqlf, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqif, d_pfsqif, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqnng, d_pfcqnng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqlng, d_pfcqlng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqrf, d_pfsqrf, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqsf, d_pfsqsf, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqrng, d_pfcqrng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqsng, d_pfcqsng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqltur, d_pfsqltur, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqitur, d_pfsqitur, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfplsl, d_pfplsl, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfplsn, d_pfplsn, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfhpsl, d_pfhpsl, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfhpsn, d_pfhpsn, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pcovptot, d_pcovptot, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(prainfrac_toprfz, d_prainfrac_toprfz, sizeof(dtype) * nblocks*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqlf, d_pfsqlf, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqif, d_pfsqif, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqnng, d_pfcqnng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqlng, d_pfcqlng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqrf, d_pfsqrf, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqsf, d_pfsqsf, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqrng, d_pfcqrng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqsng, d_pfcqsng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqltur, d_pfsqltur, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqitur, d_pfsqitur, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfplsl, d_pfplsl, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfplsn, d_pfplsn, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfhpsl, d_pfhpsl, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfhpsn, d_pfhpsn, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); // end device to host /* int msec = diff * 1000 / CLOCKS_PER_SEC; */ zinfo[0][tid] = end - start; - zinfo[1][tid] = (double) coreid; - zinfo[2][tid] = (double) icalls; - zinfo[3][tid] = (double) igpc; + zinfo[1][tid] = (dtype) coreid; + zinfo[2][tid] = (dtype) icalls; + zinfo[3][tid] = (dtype) igpc; double t2 = omp_get_wtime(); @@ -461,7 +461,7 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { "NUMOMP", "NGPTOT", "#GP-cols", "#BLKS", "NPROMA", "tid#", "Time(msec)", "MFlops/s", "col/s"); double zfrac, zmflops, zthrput; for (int t = 0; t < numthreads; t++) { - const double tloc = zinfo[0][t]; + const dtype tloc = zinfo[0][t]; const int coreid = (int) zinfo[1][t]; const int icalls = (int) zinfo[2][t]; const int igpc = (int) zinfo[3][t]; @@ -480,7 +480,7 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { zfrac = 1.0; if (tdiff > 0.0) { zmflops = 1.0e-06 * zfrac * zhpm * ((double)numcols / 100.) / tdiff; - zthrput = (double)numcols/tdiff; + zthrput = (dtype)numcols/tdiff; } else { zmflops = 0.0; zthrput = 0.0; diff --git a/src/cloudsc_hip/cloudsc/cloudsc_driver.h b/src/cloudsc_hip/cloudsc/cloudsc_driver.h index 6892a4cc..2d43ab24 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_driver.h +++ b/src/cloudsc_hip/cloudsc/cloudsc_driver.h @@ -19,5 +19,6 @@ #include "load_state.h" #include "cloudsc_c.h" #include "cloudsc_validate.h" +#include "dtype.h" void cloudsc_driver(int numthreads, int numcols, int nproma); diff --git a/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.cpp b/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.cpp index d8090966..af9ceddd 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.cpp +++ b/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.cpp @@ -28,87 +28,87 @@ inline void gpuAssert(hipError_t code, const char *file, int line, bool abort=tr void cloudsc_driver(int numthreads, int numcols, int nproma) { - double *tend_tmp_u; - double *tend_tmp_v; - double *tend_tmp_t; - double *tend_tmp_q; - double *tend_tmp_o3; - double *tend_tmp_a; - double *tend_tmp_cld; - - double *tend_loc_u; - double *tend_loc_v; - double *tend_loc_t; - double *tend_loc_q; - double *tend_loc_o3; - double *tend_loc_a; - double *tend_loc_cld; - - double *tend_cml_u; - double *tend_cml_v; - double *tend_cml_t; - double *tend_cml_q; - double *tend_cml_o3; - double *tend_cml_a; - double *tend_cml_cld; - - double ptsphy; //! Physics timestep - - double *plcrit_aer; - double *picrit_aer; - double *pre_ice; - double *pccn; //! liquid cloud condensation nuclei - double *pnice; //! ice number concentration (cf. CCN) - double *pt; //! T at start of callpar - double *pq; //! Q at start of callpar - double *pvfa; //! CC from VDF scheme - double *pvfl; //! Liq from VDF scheme - double *pvfi; //! Ice from VDF scheme - double *pdyna; //! CC from Dynamics - double *pdynl; //! Liq from Dynamics - double *pdyni; //! Liq from Dynamics - double *phrsw; //! Short-wave heating rate - double *phrlw; //! Long-wave heating rate - double *pvervel; //! Vertical velocity - double *pap; //! Pressure on full levels - double *paph; //! Pressure on half levels - double *plsm; //! Land fraction (0-1) + dtype *tend_tmp_u; + dtype *tend_tmp_v; + dtype *tend_tmp_t; + dtype *tend_tmp_q; + dtype *tend_tmp_o3; + dtype *tend_tmp_a; + dtype *tend_tmp_cld; + + dtype *tend_loc_u; + dtype *tend_loc_v; + dtype *tend_loc_t; + dtype *tend_loc_q; + dtype *tend_loc_o3; + dtype *tend_loc_a; + dtype *tend_loc_cld; + + dtype *tend_cml_u; + dtype *tend_cml_v; + dtype *tend_cml_t; + dtype *tend_cml_q; + dtype *tend_cml_o3; + dtype *tend_cml_a; + dtype *tend_cml_cld; + + dtype ptsphy; //! Physics timestep + + dtype *plcrit_aer; + dtype *picrit_aer; + dtype *pre_ice; + dtype *pccn; //! liquid cloud condensation nuclei + dtype *pnice; //! ice number concentration (cf. CCN) + dtype *pt; //! T at start of callpar + dtype *pq; //! Q at start of callpar + dtype *pvfa; //! CC from VDF scheme + dtype *pvfl; //! Liq from VDF scheme + dtype *pvfi; //! Ice from VDF scheme + dtype *pdyna; //! CC from Dynamics + dtype *pdynl; //! Liq from Dynamics + dtype *pdyni; //! Liq from Dynamics + dtype *phrsw; //! Short-wave heating rate + dtype *phrlw; //! Long-wave heating rate + dtype *pvervel; //! Vertical velocity + dtype *pap; //! Pressure on full levels + dtype *paph; //! Pressure on half levels + dtype *plsm; //! Land fraction (0-1) int *ldcum; int *ktype; //! Convection type 0,1,2 - double *plu; //! Conv. condensate - double *plude; //! Conv. detrained water - double *plude_tmp; - double *psnde; //! Conv. detrained snow - double *pmfu; //! Conv. mass flux up - double *pmfd; //! Conv. mass flux down - double *pa; //! Original Cloud fraction (t) - - double *pclv; - double *psupsat; - - double *pcovptot; //! Precip fraction - double *prainfrac_toprfz; - double *pfsqlf; //! Flux of liquid - double *pfsqif; //! Flux of ice - double *pfcqlng; //! -ve corr for liq - double *pfcqnng; //! -ve corr for ice - double *pfsqrf; //! Flux diagnostics - double *pfsqsf; //! for DDH, generic - double *pfcqrng; //! rain - double *pfcqsng; //! snow - double *pfsqltur; //! liquid flux due to VDF - double *pfsqitur; //! ice flux due to VDF - double *pfplsl; //! liq+rain sedim flux - double *pfplsn; //! ice+snow sedim flux - double *pfhpsl; //! Enthalpy flux for liq - double *pfhpsn; //! Enthalpy flux for ice + dtype *plu; //! Conv. condensate + dtype *plude; //! Conv. detrained water + dtype *plude_tmp; + dtype *psnde; //! Conv. detrained snow + dtype *pmfu; //! Conv. mass flux up + dtype *pmfd; //! Conv. mass flux down + dtype *pa; //! Original Cloud fraction (t) + + dtype *pclv; + dtype *psupsat; + + dtype *pcovptot; //! Precip fraction + dtype *prainfrac_toprfz; + dtype *pfsqlf; //! Flux of liquid + dtype *pfsqif; //! Flux of ice + dtype *pfcqlng; //! -ve corr for liq + dtype *pfcqnng; //! -ve corr for ice + dtype *pfsqrf; //! Flux diagnostics + dtype *pfsqsf; //! for DDH, generic + dtype *pfcqrng; //! rain + dtype *pfcqsng; //! snow + dtype *pfsqltur; //! liquid flux due to VDF + dtype *pfsqitur; //! ice flux due to VDF + dtype *pfplsl; //! liq+rain sedim flux + dtype *pfplsn; //! ice+snow sedim flux + dtype *pfhpsl; //! Enthalpy flux for liq + dtype *pfhpsn; //! Enthalpy flux for ice /* Define or query data dimensions from input file */ int klon, nlev; int nblocks = (numcols / nproma) + min(numcols % nproma, 1); - double zinfo[4][numthreads]; - const double zhpm = 12482329.0; // IBM P7 HPM flop count for 100 points at L137 + dtype zinfo[4][numthreads]; + const dtype zhpm = 12482329.0; // IBM P7 HPM flop count for 100 points at L137 int nclv; // number of microphysics variables int ncldql; // liquid cloud water @@ -128,240 +128,240 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { query_state(&klon, &nlev); - tend_loc_t = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_loc_q = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_loc_a = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_loc_cld = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - tend_cml_t = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_cml_q = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_cml_a = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_cml_cld = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - tend_tmp_t = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_tmp_q = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_tmp_a = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - tend_tmp_cld = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - plcrit_aer = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - picrit_aer = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pre_ice = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pccn = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pnice = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pt = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pq = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvfa = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvfl = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvfi = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pdyna = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pdynl = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pdyni = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - phrsw = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - phrlw = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pvervel = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pap = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - paph = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - plsm = (double*) malloc( sizeof(double) * nblocks*nproma ); + tend_loc_t = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_loc_q = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_loc_a = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_loc_cld = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + tend_cml_t = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_cml_q = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_cml_a = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_cml_cld = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + tend_tmp_t = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_tmp_q = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_tmp_a = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + tend_tmp_cld = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + plcrit_aer = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + picrit_aer = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pre_ice = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pccn = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pnice = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pt = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pq = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvfa = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvfl = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvfi = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pdyna = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pdynl = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pdyni = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + phrsw = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + phrlw = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pvervel = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pap = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + paph = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + plsm = (dtype*) malloc( sizeof(dtype) * nblocks*nproma ); ldcum = (int*) malloc( sizeof(int) * nblocks*nproma ); ktype = (int*) malloc( sizeof(int) * nblocks*nproma ); - plu = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - plude = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - psnde = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pmfu = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pmfd = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pa = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pclv = (double*) malloc( sizeof(double) * nblocks*nlev*nproma*nclv ); - psupsat = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - pcovptot = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - prainfrac_toprfz = (double*) malloc( sizeof(double) * nblocks*nproma ); - pfsqlf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqif = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqnng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqlng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqrf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqsf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqrng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfcqsng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqltur = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfsqitur = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfplsl = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfplsn = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfhpsl = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - pfhpsn = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - - - double rg; - double rd; - double rcpd; - double retv; - double rlvtt; - double rlstt; - double rlmlt; - double rtt; - double rv; - double r2es; - double r3les; - double r3ies; - double r4les; - double r4ies; - double r5les; - double r5ies; - double r5alvcp; - double r5alscp; - double ralvdcp; - double ralsdcp; - double ralfdcp; - double rtwat; - double rtice; - double rticecu; - double rtwat_rtice_r; - double rtwat_rticecu_r; - double rkoop1; - double rkoop2; + plu = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + plude = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + psnde = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pmfu = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pmfd = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pa = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pclv = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma*nclv ); + psupsat = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + pcovptot = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + prainfrac_toprfz = (dtype*) malloc( sizeof(dtype) * nblocks*nproma ); + pfsqlf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqif = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqnng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqlng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqrf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqsf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqrng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfcqsng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqltur = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfsqitur = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfplsl = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfplsn = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfhpsl = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + pfhpsn = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + + + dtype rg; + dtype rd; + dtype rcpd; + dtype retv; + dtype rlvtt; + dtype rlstt; + dtype rlmlt; + dtype rtt; + dtype rv; + dtype r2es; + dtype r3les; + dtype r3ies; + dtype r4les; + dtype r4ies; + dtype r5les; + dtype r5ies; + dtype r5alvcp; + dtype r5alscp; + dtype ralvdcp; + dtype ralsdcp; + dtype ralfdcp; + dtype rtwat; + dtype rtice; + dtype rticecu; + dtype rtwat_rtice_r; + dtype rtwat_rticecu_r; + dtype rkoop1; + dtype rkoop2; // device declarations - double *d_plcrit_aer; - double *d_picrit_aer; - double *d_pre_ice; - double *d_pccn; - double *d_pnice; - double *d_pt; - double *d_pq; - double *d_tend_loc_t; - double *d_tend_loc_q; - double *d_tend_loc_a; - double *d_tend_loc_cld; - double *d_tend_tmp_t; - double *d_tend_tmp_q; - double *d_tend_tmp_a; - double *d_tend_tmp_cld; - double *d_pvfa; - double *d_pvfl; - double *d_pvfi; - double *d_pdyna; - double *d_pdynl; - double *d_pdyni; - double *d_phrsw; - double *d_phrlw; - double *d_pvervel; - double *d_pap; - double *d_paph; - double *d_plsm; + dtype *d_plcrit_aer; + dtype *d_picrit_aer; + dtype *d_pre_ice; + dtype *d_pccn; + dtype *d_pnice; + dtype *d_pt; + dtype *d_pq; + dtype *d_tend_loc_t; + dtype *d_tend_loc_q; + dtype *d_tend_loc_a; + dtype *d_tend_loc_cld; + dtype *d_tend_tmp_t; + dtype *d_tend_tmp_q; + dtype *d_tend_tmp_a; + dtype *d_tend_tmp_cld; + dtype *d_pvfa; + dtype *d_pvfl; + dtype *d_pvfi; + dtype *d_pdyna; + dtype *d_pdynl; + dtype *d_pdyni; + dtype *d_phrsw; + dtype *d_phrlw; + dtype *d_pvervel; + dtype *d_pap; + dtype *d_paph; + dtype *d_plsm; int *d_ktype; - double *d_plu; - double *d_plude; - double *d_psnde; - double *d_pmfu; - double *d_pmfd; - double *d_pa; - double *d_pclv; - double *d_psupsat; + dtype *d_plu; + dtype *d_plude; + dtype *d_psnde; + dtype *d_pmfu; + dtype *d_pmfd; + dtype *d_pa; + dtype *d_pclv; + dtype *d_psupsat; struct TECLDP *d_yrecldp; - double *d_pcovptot; - double *d_prainfrac_toprfz; - double *d_pfsqlf; - double *d_pfsqif; - double *d_pfcqnng; - double *d_pfcqlng; - double *d_pfsqrf; - double *d_pfsqsf; - double *d_pfcqrng; - double *d_pfcqsng; - double *d_pfsqltur; - double *d_pfsqitur; - double *d_pfplsl; - double *d_pfplsn; - double *d_pfhpsl; - double *d_pfhpsn; - double *d_zfoealfa; - double *d_ztp1; - double *d_zli; - double *d_za; - double *d_zaorig; - double *d_zliqfrac; - double *d_zicefrac; - double *d_zqx; - double *d_zqx0; - double *d_zpfplsx; - double *d_zlneg; - double *d_zqxn2d; - double *d_zqsmix; - double *d_zqsliq; - double *d_zqsice; - double *d_zfoeewmt; - double *d_zfoeew; - double *d_zfoeeliqt; + dtype *d_pcovptot; + dtype *d_prainfrac_toprfz; + dtype *d_pfsqlf; + dtype *d_pfsqif; + dtype *d_pfcqnng; + dtype *d_pfcqlng; + dtype *d_pfsqrf; + dtype *d_pfsqsf; + dtype *d_pfcqrng; + dtype *d_pfcqsng; + dtype *d_pfsqltur; + dtype *d_pfsqitur; + dtype *d_pfplsl; + dtype *d_pfplsn; + dtype *d_pfhpsl; + dtype *d_pfhpsn; + dtype *d_zfoealfa; + dtype *d_ztp1; + dtype *d_zli; + dtype *d_za; + dtype *d_zaorig; + dtype *d_zliqfrac; + dtype *d_zicefrac; + dtype *d_zqx; + dtype *d_zqx0; + dtype *d_zpfplsx; + dtype *d_zlneg; + dtype *d_zqxn2d; + dtype *d_zqsmix; + dtype *d_zqsliq; + dtype *d_zqsice; + dtype *d_zfoeewmt; + dtype *d_zfoeew; + dtype *d_zfoeeliqt; // end device declarations // - hipMalloc(&d_plcrit_aer, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_picrit_aer, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pre_ice, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pccn, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pnice, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pt, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pq, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_t, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_q, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_a, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_loc_cld, sizeof(double) * nblocks*nlev*nproma*nclv); - hipMalloc(&d_tend_tmp_t, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_tmp_q, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_tmp_a, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_tend_tmp_cld, sizeof(double) * nblocks*nlev*nproma*nclv); - hipMalloc(&d_pvfa, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pvfl, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pvfi, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pdyna, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pdynl, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pdyni, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_phrsw, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_phrlw, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pvervel, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pap, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_paph, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_plsm, sizeof(double) * nblocks*nproma); + hipMalloc(&d_plcrit_aer, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_picrit_aer, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pre_ice, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pccn, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pnice, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pt, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pq, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_t, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_q, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_a, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_loc_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv); + hipMalloc(&d_tend_tmp_t, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_tmp_q, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_tmp_a, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_tend_tmp_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv); + hipMalloc(&d_pvfa, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pvfl, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pvfi, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pdyna, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pdynl, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pdyni, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_phrsw, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_phrlw, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pvervel, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pap, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_paph, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_plsm, sizeof(dtype) * nblocks*nproma); hipMalloc(&d_ktype, sizeof(int) * nblocks*nproma); - hipMalloc(&d_plu, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_plude, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_psnde, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pmfu, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pmfd, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pa, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_pclv, sizeof(double) * nblocks*nlev*nproma*nclv); - hipMalloc(&d_psupsat, sizeof(double) * nblocks*nlev*nproma); + hipMalloc(&d_plu, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_plude, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_psnde, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pmfu, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pmfd, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pa, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_pclv, sizeof(dtype) * nblocks*nlev*nproma*nclv); + hipMalloc(&d_psupsat, sizeof(dtype) * nblocks*nlev*nproma); hipMalloc(&d_yrecldp, sizeof(struct TECLDP)); - hipMalloc(&d_pcovptot, sizeof(double) * nblocks*nlev*nproma); - hipMalloc(&d_prainfrac_toprfz, sizeof(double) * nblocks*nproma); - hipMalloc(&d_pfsqlf, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqif, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqnng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqlng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqrf, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqsf, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqrng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfcqsng, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqltur, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfsqitur, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfplsl, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfplsn, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfhpsl, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_pfhpsn, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zfoealfa, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_ztp1, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zli, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_za, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zaorig, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zliqfrac, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zicefrac, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zqx, sizeof(double) * nblocks*(nlev+1)*nproma*nclv); - hipMalloc(&d_zqx0, sizeof(double) * nblocks*(nlev+1)*nproma*nclv); - hipMalloc(&d_zpfplsx, sizeof(double) * nblocks*(nlev+1)*nproma*nclv); - hipMalloc(&d_zlneg, sizeof(double) * nblocks*(nlev+1)*nproma*nclv); - hipMalloc(&d_zqxn2d, sizeof(double) * nblocks*(nlev+1)*nproma*nclv); - hipMalloc(&d_zqsmix, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zqsliq, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zqsice, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zfoeewmt, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zfoeew, sizeof(double) * nblocks*(nlev+1)*nproma); - hipMalloc(&d_zfoeeliqt, sizeof(double) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pcovptot, sizeof(dtype) * nblocks*nlev*nproma); + hipMalloc(&d_prainfrac_toprfz, sizeof(dtype) * nblocks*nproma); + hipMalloc(&d_pfsqlf, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqif, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqnng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqlng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqrf, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqsf, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqrng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfcqsng, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqltur, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfsqitur, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfplsl, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfplsn, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfhpsl, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_pfhpsn, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zfoealfa, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_ztp1, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zli, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_za, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zaorig, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zliqfrac, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zicefrac, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zqx, sizeof(dtype) * nblocks*(nlev+1)*nproma*nclv); + hipMalloc(&d_zqx0, sizeof(dtype) * nblocks*(nlev+1)*nproma*nclv); + hipMalloc(&d_zpfplsx, sizeof(dtype) * nblocks*(nlev+1)*nproma*nclv); + hipMalloc(&d_zlneg, sizeof(dtype) * nblocks*(nlev+1)*nproma*nclv); + hipMalloc(&d_zqxn2d, sizeof(dtype) * nblocks*(nlev+1)*nproma*nclv); + hipMalloc(&d_zqsmix, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zqsliq, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zqsice, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zfoeewmt, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zfoeew, sizeof(dtype) * nblocks*(nlev+1)*nproma); + hipMalloc(&d_zfoeeliqt, sizeof(dtype) * nblocks*(nlev+1)*nproma); // load_state(klon, nlev, nclv, numcols, nproma, &ptsphy, plcrit_aer, picrit_aer, @@ -379,42 +379,42 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { &rkoop1, &rkoop2 ); // host to device - hipMemcpy(d_plcrit_aer, plcrit_aer, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_picrit_aer, picrit_aer, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pre_ice, pre_ice, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pccn, pccn, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pnice, pnice, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pt, pt, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pq, pq, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_t, tend_loc_t, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_q, tend_loc_q, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_a, tend_loc_a, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_loc_cld, tend_loc_cld, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_t, tend_tmp_t, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_q, tend_tmp_q, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_a, tend_tmp_a, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_tend_tmp_cld, tend_tmp_cld, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); - hipMemcpy(d_pvfa, pvfa, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pvfl, pvfl, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pvfi, pvfi, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pdyna, pdyna, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pdynl, pdynl, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pdyni, pdyni, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_phrsw, phrsw, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_phrlw, phrlw, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pvervel, pvervel, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pap, pap, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_paph, paph, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_plsm, plsm, sizeof(double) * nblocks*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plcrit_aer, plcrit_aer, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_picrit_aer, picrit_aer, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pre_ice, pre_ice, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pccn, pccn, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pnice, pnice, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pt, pt, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pq, pq, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_t, tend_loc_t, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_q, tend_loc_q, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_a, tend_loc_a, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_loc_cld, tend_loc_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_t, tend_tmp_t, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_q, tend_tmp_q, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_a, tend_tmp_a, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_tend_tmp_cld, tend_tmp_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); + hipMemcpy(d_pvfa, pvfa, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pvfl, pvfl, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pvfi, pvfi, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pdyna, pdyna, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pdynl, pdynl, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pdyni, pdyni, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_phrsw, phrsw, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_phrlw, phrlw, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pvervel, pvervel, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pap, pap, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_paph, paph, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plsm, plsm, sizeof(dtype) * nblocks*nproma, hipMemcpyHostToDevice); hipMemcpy(d_ktype, ktype, sizeof(int) * nblocks*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_plu, plu, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_plude, plude, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_psnde, psnde, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pmfu, pmfu, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pmfd, pmfd, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pa, pa, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); - hipMemcpy(d_pclv, pclv, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); - hipMemcpy(d_psupsat, psupsat, sizeof(double) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plu, plu, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_plude, plude, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_psnde, psnde, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pmfu, pmfu, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pmfd, pmfd, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pa, pa, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); + hipMemcpy(d_pclv, pclv, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyHostToDevice); + hipMemcpy(d_psupsat, psupsat, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyHostToDevice); hipMemcpy(d_yrecldp, yrecldp, sizeof(TECLDP), hipMemcpyHostToDevice); // end host to device @@ -426,8 +426,8 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { double start = omp_get_wtime(); dim3 blockdim(nproma, 1, 1); - //dim3 griddim(1, 1, ceil(((double)numcols) / ((double)nproma))); - dim3 griddim(ceil(((double)numcols) / ((double)nproma)), 1, 1); + //dim3 griddim(1, 1, ceil(((dtype)numcols) / ((dtype)nproma))); + dim3 griddim(ceil(((dtype)numcols) / ((dtype)nproma)), 1, 1); int jkglo = 0; int ibl = (jkglo - 1) / nproma + 1; int icend = min(nproma, numcols - jkglo + 1); @@ -465,35 +465,35 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { double end = omp_get_wtime(); // device to host - hipMemcpy(tend_loc_t, d_tend_loc_t, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(tend_loc_q, d_tend_loc_q, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(tend_loc_a, d_tend_loc_a, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(tend_loc_cld, d_tend_loc_cld, sizeof(double) * nblocks*nlev*nproma*nclv, hipMemcpyDeviceToHost); - hipMemcpy(phrlw, d_phrlw, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(plude, d_plude, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_t, d_tend_loc_t, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_q, d_tend_loc_q, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_a, d_tend_loc_a, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(tend_loc_cld, d_tend_loc_cld, sizeof(dtype) * nblocks*nlev*nproma*nclv, hipMemcpyDeviceToHost); + hipMemcpy(phrlw, d_phrlw, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(plude, d_plude, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); hipMemcpy(yrecldp, d_yrecldp, sizeof(TECLDP), hipMemcpyDeviceToHost); - hipMemcpy(pcovptot, d_pcovptot, sizeof(double) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); - hipMemcpy(prainfrac_toprfz, d_prainfrac_toprfz, sizeof(double) * nblocks*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqlf, d_pfsqlf, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqif, d_pfsqif, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqnng, d_pfcqnng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqlng, d_pfcqlng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqrf, d_pfsqrf, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqsf, d_pfsqsf, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqrng, d_pfcqrng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfcqsng, d_pfcqsng, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqltur, d_pfsqltur, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfsqitur, d_pfsqitur, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfplsl, d_pfplsl, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfplsn, d_pfplsn, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfhpsl, d_pfhpsl, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); - hipMemcpy(pfhpsn, d_pfhpsn, sizeof(double) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pcovptot, d_pcovptot, sizeof(dtype) * nblocks*nlev*nproma, hipMemcpyDeviceToHost); + hipMemcpy(prainfrac_toprfz, d_prainfrac_toprfz, sizeof(dtype) * nblocks*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqlf, d_pfsqlf, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqif, d_pfsqif, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqnng, d_pfcqnng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqlng, d_pfcqlng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqrf, d_pfsqrf, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqsf, d_pfsqsf, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqrng, d_pfcqrng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfcqsng, d_pfcqsng, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqltur, d_pfsqltur, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfsqitur, d_pfsqitur, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfplsl, d_pfplsl, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfplsn, d_pfplsn, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfhpsl, d_pfhpsl, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); + hipMemcpy(pfhpsn, d_pfhpsn, sizeof(dtype) * nblocks*(nlev+1)*nproma, hipMemcpyDeviceToHost); /* int msec = diff * 1000 / CLOCKS_PER_SEC; */ zinfo[0][tid] = end - start; - zinfo[1][tid] = (double) coreid; - zinfo[2][tid] = (double) icalls; - zinfo[3][tid] = (double) igpc; + zinfo[1][tid] = (dtype) coreid; + zinfo[2][tid] = (dtype) icalls; + zinfo[3][tid] = (dtype) igpc; double t2 = omp_get_wtime(); @@ -502,7 +502,7 @@ void cloudsc_driver(int numthreads, int numcols, int nproma) { "NUMOMP", "NGPTOT", "#GP-cols", "#BLKS", "NPROMA", "tid#", "Time(msec)", "MFlops/s", "col/s"); double zfrac, zmflops, zthrput; for (int t = 0; t < numthreads; t++) { - const double tloc = zinfo[0][t]; + const dtype tloc = zinfo[0][t]; const int coreid = (int) zinfo[1][t]; const int icalls = (int) zinfo[2][t]; const int igpc = (int) zinfo[3][t]; diff --git a/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.h b/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.h index aca23ab7..7fbad57c 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.h +++ b/src/cloudsc_hip/cloudsc/cloudsc_driver_hoist.h @@ -19,5 +19,6 @@ #include "load_state.h" #include "cloudsc_c_hoist.h" #include "cloudsc_validate.h" +#include "dtype.h" void cloudsc_driver(int numthreads, int numcols, int nproma); diff --git a/src/cloudsc_hip/cloudsc/cloudsc_validate.cpp b/src/cloudsc_hip/cloudsc/cloudsc_validate.cpp index ab81204d..bc076be3 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_validate.cpp +++ b/src/cloudsc_hip/cloudsc/cloudsc_validate.cpp @@ -10,17 +10,18 @@ #include "cloudsc_validate.h" -#include +#include #include +#include +//#include -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#define max(a, b) (((a) > (b)) ? (a) : (b)) +#define min(a,b) (((a)<(b))?(a):(b)) -void print_error(const char *name, double zminval, double zmaxval, double zmaxerr, - double zerrsum, double zsum, double zavgpgp, int ndim) +void print_error(const char *name, dtype zminval, dtype zmaxval, dtype zmaxerr, + dtype zerrsum, dtype zsum, dtype zavgpgp, int ndim) { - double zrelerr, zeps = DBL_EPSILON; + dtype zrelerr, zeps = std::numeric_limits::epsilon(); int iopt = 0; if (zerrsum < zeps) { zrelerr = 0.0; @@ -45,87 +46,101 @@ void print_error(const char *name, double zminval, double zmaxval, double zmaxer } -void validate_1d(const char *name, double * v_ref, double * v_field, int nlon, int ngptot, int nblocks) +void validate_1d(const char *name, dtype * v_ref, dtype * v_field, int nlon, int ngptot, int nblocks) { /* Computes and prints errors in the "L2 norm sense" */ int b, bsize, jk; double zminval, zmaxval, zdiff, zmaxerr, zerrsum, zsum, zrelerr, zavgpgp; - - zminval = +DBL_MAX; - zmaxval = -DBL_MAX; + //dtype (*field)[nlon] = (dtype (*)[nlon]) v_field; + //dtype (*reference)[nlon] = (dtype (*)[nlon]) v_ref; + double field_val, ref_val; + zminval = +std::numeric_limits::max(); + zmaxval = -std::numeric_limits::max(); zmaxerr = 0.0; zerrsum = 0.0; zsum = 0.0; - #pragma omp parallel for default(shared) private(b, bsize, jk) \ - reduction(min:zminval) reduction(max:zmaxval,zmaxerr) reduction(+:zerrsum,zsum) +// #pragma omp parallel for default(shared) private(b, bsize, jk) \ +// reduction(min:zminval) reduction(max:zmaxval,zmaxerr) reduction(+:zerrsum,zsum) for (b = 0; b < nblocks; b++) { bsize = min(nlon, ngptot - b*nlon); // field block size for (jk = 0; jk < bsize; jk++) { - zminval = fmin(zminval, v_field[b*nlon+jk]); - zmaxval = fmax(zmaxval, v_field[b*nlon+jk]); + field_val = (double) v_field[b*nlon+jk]; + ref_val = (double) v_ref[b*nlon+jk]; + + zminval = fmin(zminval, field_val); + zmaxval = fmax(zmaxval, field_val); // Difference against reference result in one-norm sense - zdiff = fabs(v_field[b*nlon+jk] - v_ref[b*nlon+jk]); + zdiff = fabs(field_val - ref_val); zmaxerr = fmax(zmaxerr, zdiff); zerrsum = zerrsum + zdiff; - zsum = zsum + abs(v_ref[b*nlon+jk]); + zsum = zsum + fabs(ref_val); } } zavgpgp = zerrsum / (double) ngptot; - print_error(name, zminval, zmaxval, zmaxerr, zerrsum, zsum, zavgpgp, 2); + print_error(name, (dtype)zminval, (dtype)zmaxval, (dtype)zmaxerr, (dtype)zerrsum, (dtype)zsum, (dtype)zavgpgp, 2); } -void validate_2d(const char *name, double *v_ref, double *v_field, int nlon, int nlev, int ngptot, int nblocks) +void validate_2d(const char *name, dtype *v_ref, dtype *v_field, int nlon, int nlev, int ngptot, int nblocks) { /* Computes and prints errors in the "L2 norm sense" */ int b, bsize, jl, jk; double zminval, zmaxval, zdiff, zmaxerr, zerrsum, zsum, zrelerr, zavgpgp; +// dtype (*field)[nlev][nlon] = (dtype (*)[nlev][nlon]) v_field; +// dtype (*reference)[nlev][nlon] = (dtype (*)[nlev][nlon]) v_ref; + double field_val, ref_val; - zminval = +DBL_MAX; - zmaxval = -DBL_MAX; + zminval = +std::numeric_limits::max(); + zmaxval = -std::numeric_limits::max(); zmaxerr = 0.0; zerrsum = 0.0; zsum = 0.0; - #pragma omp parallel for default(shared) private(b, bsize, jl, jk) \ - reduction(min:zminval) reduction(max:zmaxval,zmaxerr) reduction(+:zerrsum,zsum) +// #pragma omp parallel for default(shared) private(b, bsize, jl, jk) \ +// reduction(min:zminval) reduction(max:zmaxval,zmaxerr) reduction(+:zerrsum,zsum) + for (b = 0; b < nblocks; b++) { bsize = min(nlon, ngptot - b*nlon); // field block size for (jl = 0; jl < nlev; jl++) { for (jk = 0; jk < bsize; jk++) { - zminval = fmin(zminval, v_field[b*nlev*nlon+jl*nlon+jk]); - zmaxval = fmax(zmaxval, v_field[b*nlev*nlon+jl*nlon+jk]); + field_val = (double) v_field[b*nlev*nlon+jl*nlon+jk]; + ref_val = (double) v_ref[b*nlev*nlon+jl*nlon+jk]; + zminval = fmin(zminval, field_val); + zmaxval = fmax(zmaxval, field_val); // Difference against reference result in one-norm sense - zdiff = fabs(v_field[b*nlev*nlon+jl*nlon+jk] - v_ref[b*nlev*nlon+jl*nlon+jk]); + zdiff = fabs(field_val - ref_val); zmaxerr = fmax(zmaxerr, zdiff); zerrsum = zerrsum + zdiff; - zsum = zsum + abs(v_ref[b*nlev*nlon+jl*nlon+jk]); + zsum = zsum + fabs(ref_val); } } } - zavgpgp = zerrsum / (double) ngptot; - print_error(name, zminval, zmaxval, zmaxerr, zerrsum, zsum, zavgpgp, 2); + + zavgpgp = zerrsum / (dtype) ngptot; + print_error(name, (dtype)zminval, (dtype)zmaxval, (dtype)zmaxerr, (dtype)zerrsum, (dtype)zsum, (dtype)zavgpgp, 2); } -void validate_3d(const char *name, double *v_ref, double *v_field, int nlon, +void validate_3d(const char *name, dtype *v_ref, dtype *v_field, int nlon, int nlev, int nclv, int ngptot, int nblocks) { /* Computes and prints errors in the "L2 norm sense" */ int b, bsize, jl, jk, jm; - double zminval, zmaxval, zdiff, zmaxerr, zerrsum, zsum, zrelerr, zavgpgp; + dtype zminval, zmaxval, zdiff, zmaxerr, zerrsum, zsum, zrelerr, zavgpgp; +// dtype (*field)[nclv][nlev][nlon] = (dtype (*)[nclv][nlev][nlon]) v_field; +// dtype (*reference)[nclv][nlev][nlon] = (dtype (*)[nclv][nlev][nlon]) v_ref; - zminval = +DBL_MAX; - zmaxval = -DBL_MAX; + zminval = +std::numeric_limits::max(); + zmaxval = -std::numeric_limits::max(); zmaxerr = 0.0; zerrsum = 0.0; zsum = 0.0; - #pragma omp parallel for default(shared) private(b, bsize, jl, jk, jm) \ - reduction(min:zminval) reduction(max:zmaxval,zmaxerr) reduction(+:zerrsum,zsum) +// #pragma omp parallel for default(shared) private(b, bsize, jl, jk, jm) \ +// reduction(min:zminval) reduction(max:zmaxval,zmaxerr) reduction(+:zerrsum,zsum) for (b = 0; b < nblocks; b++) { bsize = min(nlon, ngptot - b*nlon); // field block size for (jm = 0; jm < nclv; jm++) { @@ -142,40 +157,40 @@ void validate_3d(const char *name, double *v_ref, double *v_field, int nlon, } } } - } - zavgpgp = zerrsum / (double) ngptot; + } + zavgpgp = zerrsum / (dtype) ngptot; print_error(name, zminval, zmaxval, zmaxerr, zerrsum, zsum, zavgpgp, 2); } int cloudsc_validate(const int nlon, const int nlev, const int nclv, const int ngptot, const int nproma, - double *plude, double *pcovptot, double *prainfrac_toprfz, double *pfsqlf, double *pfsqif, - double *pfcqlng, double *pfcqnng, double *pfsqrf, double *pfsqsf, double *pfcqrng, double *pfcqsng, - double *pfsqltur, double *pfsqitur, double *pfplsl, double *pfplsn, double *pfhpsl, double *pfhpsn, - double *tend_loc_a, double *tend_loc_q, double *tend_loc_t, double *tend_loc_cld) + dtype *plude, dtype *pcovptot, dtype *prainfrac_toprfz, dtype *pfsqlf, dtype *pfsqif, + dtype *pfcqlng, dtype *pfcqnng, dtype *pfsqrf, dtype *pfsqsf, dtype *pfcqrng, dtype *pfcqsng, + dtype *pfsqltur, dtype *pfsqitur, dtype *pfplsl, dtype *pfplsn, dtype *pfhpsl, dtype *pfhpsn, + dtype *tend_loc_a, dtype *tend_loc_q, dtype *tend_loc_t, dtype *tend_loc_cld) { const int nblocks = (ngptot / nproma) + min(ngptot % nproma, 1); - double *ref_plude = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - double *ref_pcovptot = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - double *ref_prainfrac_toprfz = (double*) malloc( sizeof(double) * nblocks*nproma ); - double *ref_pfsqlf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfsqif = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfcqlng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfcqnng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfsqrf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfsqsf = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfcqrng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfcqsng = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfsqltur = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfsqitur = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfplsl = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfplsn = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfhpsl = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_pfhpsn = (double*) malloc( sizeof(double) * nblocks*(nlev+1)*nproma ); - double *ref_tend_loc_a = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - double *ref_tend_loc_q = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - double *ref_tend_loc_t = (double*) malloc( sizeof(double) * nblocks*nlev*nproma ); - double *ref_tend_loc_cld = (double*) malloc( sizeof(double) * nblocks*nclv*nlev*nproma ); + dtype *ref_plude = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + dtype *ref_pcovptot = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + dtype *ref_prainfrac_toprfz = (dtype*) malloc( sizeof(dtype) * nblocks*nproma ); + dtype *ref_pfsqlf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfsqif = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfcqlng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfcqnng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfsqrf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfsqsf = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfcqrng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfcqsng = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfsqltur = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfsqitur = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfplsl = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfplsn = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfhpsl = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_pfhpsn = (dtype*) malloc( sizeof(dtype) * nblocks*(nlev+1)*nproma ); + dtype *ref_tend_loc_a = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + dtype *ref_tend_loc_q = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + dtype *ref_tend_loc_t = (dtype*) malloc( sizeof(dtype) * nblocks*nlev*nproma ); + dtype *ref_tend_loc_cld = (dtype*) malloc( sizeof(dtype) * nblocks*nclv*nlev*nproma ); load_reference(nlon, nlev, nclv, ngptot, nproma, ref_plude, ref_pcovptot, ref_prainfrac_toprfz, ref_pfsqlf, ref_pfsqif, diff --git a/src/cloudsc_hip/cloudsc/cloudsc_validate.h b/src/cloudsc_hip/cloudsc/cloudsc_validate.h index 155b4274..b6fe3a67 100644 --- a/src/cloudsc_hip/cloudsc/cloudsc_validate.h +++ b/src/cloudsc_hip/cloudsc/cloudsc_validate.h @@ -9,9 +9,10 @@ */ #include "load_state.h" +#include "dtype.h" int cloudsc_validate(const int nlon, const int nlev, const int nclv, const int ngptot, const int nproma, - double *plude, double *pcovptot, double *prainfrac_toprfz, double *pfsqlf, double *pfsqif, - double *pfcqlng, double *pfcqnng, double *pfsqrf, double *pfsqsf, double *pfcqrng, double *pfcqsng, - double *pfsqltur, double *pfsqitur, double *pfplsl, double *pfplsn, double *pfhpsl, double *pfhpsn, - double *tend_loc_a, double *tend_loc_q, double *tend_loc_t, double *tend_loc_cld); + dtype *plude, dtype *pcovptot, dtype *prainfrac_toprfz, dtype *pfsqlf, dtype *pfsqif, + dtype *pfcqlng, dtype *pfcqnng, dtype *pfsqrf, dtype *pfsqsf, dtype *pfcqrng, dtype *pfcqsng, + dtype *pfsqltur, dtype *pfsqitur, dtype *pfplsl, dtype *pfplsn, dtype *pfhpsl, dtype *pfhpsn, + dtype *tend_loc_a, dtype *tend_loc_q, dtype *tend_loc_t, dtype *tend_loc_cld); diff --git a/src/cloudsc_hip/cloudsc/dtype.h b/src/cloudsc_hip/cloudsc/dtype.h new file mode 100644 index 00000000..c9954978 --- /dev/null +++ b/src/cloudsc_hip/cloudsc/dtype.h @@ -0,0 +1,41 @@ +/* + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * In applying this licence, ECMWF does not waive the privileges and immunities + * granted to it by virtue of its status as an intergovernmental organisation + * nor does it submit to any jurisdiction. + */ + +#ifndef CLOUDSC_DTYPE_H +#define CLOUDSC_DTYPE_H + +// FLOATING POINT PRECISION +#ifdef SINGLE +typedef float dtype; +#else +typedef double dtype; +#endif + + +// MATH FUNCTIONS +#ifdef SINGLE + +#define MYMAX(x,y) fmaxf(x,y) +#define MYMIN(x,y) fminf(x,y) +#define MYEXP(x) exp(x) +#define MYPOW(x,y) pow(x,y) +#define MYPOWN(x,y) pow(x,y) +#define MYABS(x) fabs(x) + +#else + +#define MYMAX(x,y) fmax(x,y) +#define MYMIN(x,y) fmin(x,y) +#define MYEXP(x) exp(x) +#define MYPOW(x,y) pow(x,y) +#define MYPOWN(x,y) pow(x,y) +#define MYABS(x) fabs(x) + +#endif // SINGLE + +#endif // CLOUDSC_DTYPE_H diff --git a/src/cloudsc_hip/cloudsc/load_state.cpp b/src/cloudsc_hip/cloudsc/load_state.cpp index 767fe257..2614ec7f 100644 --- a/src/cloudsc_hip/cloudsc/load_state.cpp +++ b/src/cloudsc_hip/cloudsc/load_state.cpp @@ -9,6 +9,7 @@ */ #include "load_state.h" +#include #include #ifdef HAVE_SERIALBOX @@ -32,11 +33,13 @@ void read_hdf5_int(hid_t file_id, const char *name, int *field) { status = H5Dclose(dataset_id); } -void read_hdf5(hid_t file_id, const char *name, double *field) { +void read_hdf5(hid_t file_id, const char *name, dtype *field) { hid_t dataset_id; herr_t status; + double dbl_field; dataset_id = H5Dopen2(file_id, name, H5P_DEFAULT); - status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, field); + status = H5Dread(dataset_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, &dbl_field); + *field = (dtype)dbl_field; status = H5Dclose(dataset_id); } #endif @@ -58,15 +61,15 @@ void query_state(int *klon, int *klev) hid_t file_id, dataset_id; herr_t status; file_id = H5Fopen(INPUT_FILE, H5F_ACC_RDWR, H5P_DEFAULT); - + read_hdf5_int(file_id, "/KLEV", klev); read_hdf5_int(file_id, "/KLON", klon); - + status = H5Fclose(file_id); -#endif +#endif } -void expand_1d(double *buffer, double *field_in, int nlon, int nproma, int ngptot, int nblocks) +void expand_1d(dtype *buffer, dtype *field_in, int nlon, int nproma, int ngptot, int nblocks) { int b, i, buf_start_idx, buf_idx; @@ -96,7 +99,7 @@ void expand_1d_int(int *buffer, int *field_in, int nlon, int nproma, int ngptot, } -void expand_2d(double *buffer_in, double *field_in, int nlon, int nlev, int nproma, int ngptot, int nblocks) +void expand_2d(dtype *buffer_in, dtype *field_in, int nlon, int nlev, int nproma, int ngptot, int nblocks) { int b, l, i, buf_start_idx, buf_idx; @@ -112,7 +115,7 @@ void expand_2d(double *buffer_in, double *field_in, int nlon, int nlev, int npro } } -void expand_3d(double *buffer_in, double *field_in, int nlon, int nlev, int nclv, int nproma, int ngptot, int nblocks) +void expand_3d(dtype *buffer_in, dtype *field_in, int nlon, int nlev, int nclv, int nproma, int ngptot, int nblocks) { int b, l, c, i, buf_start_idx, buf_idx; @@ -132,19 +135,23 @@ void expand_3d(double *buffer_in, double *field_in, int nlon, int nlev, int nclv #ifdef HAVE_SERIALBOX void load_and_expand_1d(serialboxSerializer_t *serializer, serialboxSavepoint_t* savepoint, - const char *name, int nlon, int nproma, int ngptot, int nblocks, double *field) + const char *name, int nlon, int nproma, int ngptot, int nblocks, dtype *field) { - double buffer[nlon]; + double dbl_buffer[nlon]; + dtype buffer[nlon]; int strides[1] = {1}; - serialboxSerializerRead(serializer, name, savepoint, buffer, strides, 1); - expand_1d((double *)buffer, field, nlon, nproma, ngptot, nblocks); + serialboxSerializerRead(serializer, name, savepoint, dbl_buffer, strides, 1); + for (int i=0;iramid = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RAMID"); - yrecldp->rcldiff = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDIFF"); - yrecldp->rcldiff_convi = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDIFF_CONVI"); - yrecldp->rclcrit = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLCRIT"); - yrecldp->rclcrit_sea = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLCRIT_SEA"); - yrecldp->rclcrit_land = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLCRIT_LAND"); - yrecldp->rkconv = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RKCONV"); - yrecldp->rprc1 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPRC1"); - yrecldp->rprc2 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPRC2"); - yrecldp->rcldmax = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDMAX"); - yrecldp->rpecons = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPECONS"); - yrecldp->rvrfactor = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVRFACTOR"); - yrecldp->rprecrhmax = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPRECRHMAX"); - yrecldp->rtaumel = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RTAUMEL"); - yrecldp->ramin = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RAMIN"); - yrecldp->rlmin = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RLMIN"); - yrecldp->rkooptau = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RKOOPTAU"); - - yrecldp->rcldtopp = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDTOPP"); - yrecldp->rlcritsnow = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RLCRITSNOW"); - yrecldp->rsnowlin1 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RSNOWLIN1"); - yrecldp->rsnowlin2 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RSNOWLIN2"); - yrecldp->ricehi1 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RICEHI1"); - yrecldp->ricehi2 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RICEHI2"); - yrecldp->riceinit = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RICEINIT"); - yrecldp->rvice = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVICE"); - yrecldp->rvrain = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVRAIN"); - yrecldp->rvsnow = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVSNOW"); - yrecldp->rthomo = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RTHOMO"); - yrecldp->rcovpmin = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCOVPMIN"); - yrecldp->rccn = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCN"); - yrecldp->rnice = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RNICE"); - yrecldp->rccnom = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCNOM"); - yrecldp->rccnss = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCNSS"); - yrecldp->rccnsu = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCNSU"); - yrecldp->rcldtopcf = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDTOPCF"); - yrecldp->rdepliqrefrate = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDEPLIQREFRATE"); - yrecldp->rdepliqrefdepth = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDEPLIQREFDEPTH"); - yrecldp->rcl_kkaac = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKAac"); - yrecldp->rcl_kkbac = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKBac"); - yrecldp->rcl_kkaau = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKAau"); - yrecldp->rcl_kkbauq = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKBauq"); - yrecldp->rcl_kkbaun = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKBaun"); - yrecldp->rcl_kk_cloud_num_sea = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KK_cloud_num_sea"); - yrecldp->rcl_kk_cloud_num_land = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KK_cloud_num_land"); - yrecldp->rcl_ai = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_AI"); - yrecldp->rcl_bi = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_BI"); - yrecldp->rcl_ci = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CI"); - yrecldp->rcl_di = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DI"); - yrecldp->rcl_x1i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X1I"); - yrecldp->rcl_x2i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X2I"); - yrecldp->rcl_x3i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X3I"); - yrecldp->rcl_x4i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X4I"); - yrecldp->rcl_const1i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST1I"); - yrecldp->rcl_const2i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST2I"); - yrecldp->rcl_const3i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST3I"); - yrecldp->rcl_const4i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST4I"); - yrecldp->rcl_const5i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST5I"); - yrecldp->rcl_const6i = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST6I"); - yrecldp->rcl_apb1 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_APB1"); - yrecldp->rcl_apb2 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_APB2"); - yrecldp->rcl_apb3 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_APB3"); - yrecldp->rcl_as = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_AS"); - yrecldp->rcl_bs = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_BS"); - yrecldp->rcl_cs = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CS"); - yrecldp->rcl_ds = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DS"); - yrecldp->rcl_x1s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X1S"); - yrecldp->rcl_x2s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X2S"); - yrecldp->rcl_x3s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X3S"); - yrecldp->rcl_x4s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X4S"); - yrecldp->rcl_const1s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST1S"); - yrecldp->rcl_const2s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST2S"); - yrecldp->rcl_const3s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST3S"); - yrecldp->rcl_const4s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST4S"); - yrecldp->rcl_const5s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST5S"); - yrecldp->rcl_const6s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST6S"); - yrecldp->rcl_const7s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST7S"); - yrecldp->rcl_const8s = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST8S"); - yrecldp->rdenswat = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDENSWAT"); - yrecldp->rdensref = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDENSREF"); - yrecldp->rcl_ar = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_AR"); - yrecldp->rcl_br = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_BR"); - yrecldp->rcl_cr = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CR"); - yrecldp->rcl_dr = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DR"); - yrecldp->rcl_x1r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X1R"); - yrecldp->rcl_x2r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X2R"); - yrecldp->rcl_x4r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X4R"); - yrecldp->rcl_ka273 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KA273"); - yrecldp->rcl_cdenom1 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CDENOM1"); - yrecldp->rcl_cdenom2 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CDENOM2"); - yrecldp->rcl_cdenom3 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CDENOM3"); - yrecldp->rcl_schmidt = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_SCHMIDT"); - yrecldp->rcl_dynvisc = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DYNVISC"); - yrecldp->rcl_const1r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST1R"); - yrecldp->rcl_const2r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST2R"); - yrecldp->rcl_const3r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST3R"); - yrecldp->rcl_const4r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST4R"); - yrecldp->rcl_fac1 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FAC1"); - yrecldp->rcl_fac2 = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FAC2"); - yrecldp->rcl_const5r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST5R"); - yrecldp->rcl_const6r = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST6R"); - yrecldp->rcl_fzrab = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FZRAB"); - yrecldp->rcl_fzrbb = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FZRBB"); - yrecldp->lcldextra = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LCLDEXTRA"); - yrecldp->lcldbudget = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LCLDBUDGET"); - yrecldp->nssopt = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NSSOPT"); - yrecldp->ncldtop = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NCLDTOP"); - yrecldp->naeclbc = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLBC"); - yrecldp->naecldu = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLDU"); - yrecldp->naeclom = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLOM"); - yrecldp->naeclss = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLSS"); - yrecldp->naeclsu = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLSU"); - yrecldp->nclddiag = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NCLDDIAG"); - yrecldp->naercld = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAERCLD"); - yrecldp->laerliqautolsp = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQAUTOLSP"); - yrecldp->laerliqautocp = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQAUTOCP"); - yrecldp->laerliqautocpb = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQAUTOCPB"); - yrecldp->laerliqcoll = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQCOLL"); - yrecldp->laericesed = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERICESED"); - yrecldp->laericeauto = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERICEAUTO"); - yrecldp->nshapep = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NSHAPEP"); - yrecldp->nshapeq = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NSHAPEQ"); - yrecldp->nbeta = serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NBETA"); + *rg = (dtype) serialboxMetainfoGetFloat64(metainfo, "RG"); + *rd = (dtype) serialboxMetainfoGetFloat64(metainfo, "RD"); + *rcpd = (dtype) serialboxMetainfoGetFloat64(metainfo, "RCPD"); + *retv = (dtype) serialboxMetainfoGetFloat64(metainfo, "RETV"); + *rlvtt = (dtype) serialboxMetainfoGetFloat64(metainfo, "RLVTT"); + *rlstt = (dtype) serialboxMetainfoGetFloat64(metainfo, "RLSTT"); + *rlmlt = (dtype) serialboxMetainfoGetFloat64(metainfo, "RLMLT"); + *rtt = (dtype) serialboxMetainfoGetFloat64(metainfo, "RTT"); + *rv = (dtype) serialboxMetainfoGetFloat64(metainfo, "RV"); + *r2es = (dtype) serialboxMetainfoGetFloat64(metainfo, "R2ES"); + *r3les = (dtype) serialboxMetainfoGetFloat64(metainfo, "R3LES"); + *r3ies = (dtype) serialboxMetainfoGetFloat64(metainfo, "R3IES"); + *r4les = (dtype) serialboxMetainfoGetFloat64(metainfo, "R4LES"); + *r4ies = (dtype) serialboxMetainfoGetFloat64(metainfo, "R4IES"); + *r5les = (dtype) serialboxMetainfoGetFloat64(metainfo, "R5LES"); + *r5ies = (dtype) serialboxMetainfoGetFloat64(metainfo, "R5IES"); + *r5alvcp = (dtype) serialboxMetainfoGetFloat64(metainfo, "R5ALVCP"); + *r5alscp = (dtype) serialboxMetainfoGetFloat64(metainfo, "R5ALSCP"); + *ralvdcp = (dtype) serialboxMetainfoGetFloat64(metainfo, "RALVDCP"); + *ralsdcp = (dtype) serialboxMetainfoGetFloat64(metainfo, "RALSDCP"); + *ralfdcp = (dtype) serialboxMetainfoGetFloat64(metainfo, "RALFDCP"); + *rtwat = (dtype) serialboxMetainfoGetFloat64(metainfo, "RTWAT"); + *rtice = (dtype) serialboxMetainfoGetFloat64(metainfo, "RTICE"); + *rticecu = (dtype) serialboxMetainfoGetFloat64(metainfo, "RTICECU"); + *rtwat_rtice_r = (dtype) serialboxMetainfoGetFloat64(metainfo, "RTWAT_RTICE_R"); + *rtwat_rticecu_r = (dtype) serialboxMetainfoGetFloat64(metainfo, "RTWAT_RTICECU_R"); + *rkoop1 = (dtype) serialboxMetainfoGetFloat64(metainfo, "RKOOP1"); + *rkoop2 = (dtype) serialboxMetainfoGetFloat64(metainfo, "RKOOP2"); + + yrecldp->ramid = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RAMID"); + yrecldp->rcldiff = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDIFF"); + yrecldp->rcldiff_convi = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDIFF_CONVI"); + yrecldp->rclcrit = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLCRIT"); + yrecldp->rclcrit_sea = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLCRIT_SEA"); + yrecldp->rclcrit_land = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLCRIT_LAND"); + yrecldp->rkconv = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RKCONV"); + yrecldp->rprc1 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPRC1"); + yrecldp->rprc2 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPRC2"); + yrecldp->rcldmax = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDMAX"); + yrecldp->rpecons = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPECONS"); + yrecldp->rvrfactor = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVRFACTOR"); + yrecldp->rprecrhmax = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RPRECRHMAX"); + yrecldp->rtaumel = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RTAUMEL"); + yrecldp->ramin = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RAMIN"); + yrecldp->rlmin = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RLMIN"); + yrecldp->rkooptau = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RKOOPTAU"); + + yrecldp->rcldtopp = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDTOPP"); + yrecldp->rlcritsnow = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RLCRITSNOW"); + yrecldp->rsnowlin1 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RSNOWLIN1"); + yrecldp->rsnowlin2 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RSNOWLIN2"); + yrecldp->ricehi1 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RICEHI1"); + yrecldp->ricehi2 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RICEHI2"); + yrecldp->riceinit = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RICEINIT"); + yrecldp->rvice = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVICE"); + yrecldp->rvrain = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVRAIN"); + yrecldp->rvsnow = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RVSNOW"); + yrecldp->rthomo = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RTHOMO"); + yrecldp->rcovpmin = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCOVPMIN"); + yrecldp->rccn = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCN"); + yrecldp->rnice = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RNICE"); + yrecldp->rccnom = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCNOM"); + yrecldp->rccnss = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCNSS"); + yrecldp->rccnsu = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCCNSU"); + yrecldp->rcldtopcf = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCLDTOPCF"); + yrecldp->rdepliqrefrate = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDEPLIQREFRATE"); + yrecldp->rdepliqrefdepth = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDEPLIQREFDEPTH"); + yrecldp->rcl_kkaac = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKAac"); + yrecldp->rcl_kkbac = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKBac"); + yrecldp->rcl_kkaau = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKAau"); + yrecldp->rcl_kkbauq = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKBauq"); + yrecldp->rcl_kkbaun = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KKBaun"); + yrecldp->rcl_kk_cloud_num_sea = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KK_cloud_num_sea"); + yrecldp->rcl_kk_cloud_num_land = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KK_cloud_num_land"); + yrecldp->rcl_ai = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_AI"); + yrecldp->rcl_bi = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_BI"); + yrecldp->rcl_ci = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CI"); + yrecldp->rcl_di = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DI"); + yrecldp->rcl_x1i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X1I"); + yrecldp->rcl_x2i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X2I"); + yrecldp->rcl_x3i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X3I"); + yrecldp->rcl_x4i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X4I"); + yrecldp->rcl_const1i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST1I"); + yrecldp->rcl_const2i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST2I"); + yrecldp->rcl_const3i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST3I"); + yrecldp->rcl_const4i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST4I"); + yrecldp->rcl_const5i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST5I"); + yrecldp->rcl_const6i = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST6I"); + yrecldp->rcl_apb1 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_APB1"); + yrecldp->rcl_apb2 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_APB2"); + yrecldp->rcl_apb3 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_APB3"); + yrecldp->rcl_as = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_AS"); + yrecldp->rcl_bs = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_BS"); + yrecldp->rcl_cs = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CS"); + yrecldp->rcl_ds = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DS"); + yrecldp->rcl_x1s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X1S"); + yrecldp->rcl_x2s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X2S"); + yrecldp->rcl_x3s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X3S"); + yrecldp->rcl_x4s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X4S"); + yrecldp->rcl_const1s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST1S"); + yrecldp->rcl_const2s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST2S"); + yrecldp->rcl_const3s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST3S"); + yrecldp->rcl_const4s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST4S"); + yrecldp->rcl_const5s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST5S"); + yrecldp->rcl_const6s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST6S"); + yrecldp->rcl_const7s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST7S"); + yrecldp->rcl_const8s = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST8S"); + yrecldp->rdenswat = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDENSWAT"); + yrecldp->rdensref = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RDENSREF"); + yrecldp->rcl_ar = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_AR"); + yrecldp->rcl_br = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_BR"); + yrecldp->rcl_cr = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CR"); + yrecldp->rcl_dr = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DR"); + yrecldp->rcl_x1r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X1R"); + yrecldp->rcl_x2r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X2R"); + yrecldp->rcl_x4r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_X4R"); + yrecldp->rcl_ka273 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_KA273"); + yrecldp->rcl_cdenom1 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CDENOM1"); + yrecldp->rcl_cdenom2 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CDENOM2"); + yrecldp->rcl_cdenom3 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CDENOM3"); + yrecldp->rcl_schmidt = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_SCHMIDT"); + yrecldp->rcl_dynvisc = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_DYNVISC"); + yrecldp->rcl_const1r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST1R"); + yrecldp->rcl_const2r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST2R"); + yrecldp->rcl_const3r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST3R"); + yrecldp->rcl_const4r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST4R"); + yrecldp->rcl_fac1 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FAC1"); + yrecldp->rcl_fac2 = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FAC2"); + yrecldp->rcl_const5r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST5R"); + yrecldp->rcl_const6r = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_CONST6R"); + yrecldp->rcl_fzrab = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FZRAB"); + yrecldp->rcl_fzrbb = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_RCL_FZRBB"); + yrecldp->lcldextra = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LCLDEXTRA"); + yrecldp->lcldbudget = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LCLDBUDGET"); + yrecldp->nssopt = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NSSOPT"); + yrecldp->ncldtop = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NCLDTOP"); + yrecldp->naeclbc = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLBC"); + yrecldp->naecldu = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLDU"); + yrecldp->naeclom = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLOM"); + yrecldp->naeclss = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLSS"); + yrecldp->naeclsu = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAECLSU"); + yrecldp->nclddiag = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NCLDDIAG"); + yrecldp->naercld = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NAERCLD"); + yrecldp->laerliqautolsp = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQAUTOLSP"); + yrecldp->laerliqautocp = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQAUTOCP"); + yrecldp->laerliqautocpb = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQAUTOCPB"); + yrecldp->laerliqcoll = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERLIQCOLL"); + yrecldp->laericesed = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERICESED"); + yrecldp->laericeauto = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_LAERICEAUTO"); + yrecldp->nshapep = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NSHAPEP"); + yrecldp->nshapeq = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NSHAPEQ"); + yrecldp->nbeta = (dtype) serialboxMetainfoGetFloat64(metainfo, "YRECLDP_NBETA"); serialboxSerializerDestroySavepointVector(savepoints, 1); serialboxSerializerDestroy(serializer); @@ -644,19 +686,15 @@ void load_state(const int nlon, const int nlev, const int nclv, const int ngptot status = H5Fclose(file_id); #endif - } - - /* Read reference result into memory */ void load_reference(const int nlon, const int nlev, const int nclv, const int ngptot, const int nproma, - double *plude, double *pcovptot, double *prainfrac_toprfz, double *pfsqlf, double *pfsqif, - double *pfcqlng, double *pfcqnng, double *pfsqrf, double *pfsqsf, double *pfcqrng, double *pfcqsng, - double *pfsqltur, double *pfsqitur, double *pfplsl, double *pfplsn, double *pfhpsl, double *pfhpsn, - double *tend_loc_a, double *tend_loc_q, double *tend_loc_t, double *tend_loc_cld) + dtype *plude, dtype *pcovptot, dtype *prainfrac_toprfz, dtype *pfsqlf, dtype *pfsqif, + dtype *pfcqlng, dtype *pfcqnng, dtype *pfsqrf, dtype *pfsqsf, dtype *pfcqrng, dtype *pfcqsng, + dtype *pfsqltur, dtype *pfsqitur, dtype *pfplsl, dtype *pfplsn, dtype *pfhpsl, dtype *pfhpsn, + dtype *tend_loc_a, dtype *tend_loc_q, dtype *tend_loc_t, dtype *tend_loc_cld) { - int nblocks = (ngptot / nproma) + min(ngptot % nproma, 1); #ifdef HAVE_SERIALBOX @@ -721,5 +759,4 @@ void load_reference(const int nlon, const int nlev, const int nclv, const int ng status = H5Fclose(file_id); #endif - } diff --git a/src/cloudsc_hip/cloudsc/load_state.h b/src/cloudsc_hip/cloudsc/load_state.h index 65fbf8c2..bd9a457c 100644 --- a/src/cloudsc_hip/cloudsc/load_state.h +++ b/src/cloudsc_hip/cloudsc/load_state.h @@ -11,30 +11,31 @@ #include #include #include "yoecldp_c.h" +#include "dtype.h" struct TECLDP ; void query_state(int *klon, int *klev); void load_state(const int nlon, const int nlev, const int nclv, const int ngptot, const int nproma, - double* ptsphy, double* plcrit_aer, double* picrit_aer, - double* pre_ice, double* pccn, double* pnice, double* pt, double* pq, - double* tend_cml_t, double* tend_cml_q, double* tend_cml_a, double* tend_cml_cld, - double* tend_tmp_t, double* tend_tmp_q, double* tend_tmp_a, double* tend_tmp_cld, - double* pvfa, double* pvfl, double* pvfi, double* pdyna, double* pdynl, double* pdyni, - double* phrsw, double* phrlw, double* pvervel, double* pap, double* paph, double* plsm, - int* ktype, double* plu, double* plude, double* psnde, double* pmfu, - double* pmfd, double* pa, double* pclv, double* psupsat, struct TECLDP* yrecldp, - double* rg, double* rd, double* rcpd, double* retv, double* rlvtt, double* rlstt, - double* rlmlt, double* rtt, double* rv, double* r2es, double* r3les, double* r3ies, - double* r4les, double* r4ies, double* r5les, double* r5ies, double* r5alvcp, double* r5alscp, - double* ralvdcp, double* ralsdcp, double* ralfdcp, double* rtwat, - double* rtice, double* rticecu, double* rtwat_rtice_r, double *rtwat_rticecu_r, - double* rkoop1, double* rkoop2); + dtype* ptsphy, dtype* plcrit_aer, dtype* picrit_aer, + dtype* pre_ice, dtype* pccn, dtype* pnice, dtype* pt, dtype* pq, + dtype* tend_cml_t, dtype* tend_cml_q, dtype* tend_cml_a, dtype* tend_cml_cld, + dtype* tend_tmp_t, dtype* tend_tmp_q, dtype* tend_tmp_a, dtype* tend_tmp_cld, + dtype* pvfa, dtype* pvfl, dtype* pvfi, dtype* pdyna, dtype* pdynl, dtype* pdyni, + dtype* phrsw, dtype* phrlw, dtype* pvervel, dtype* pap, dtype* paph, dtype* plsm, + int* ktype, dtype* plu, dtype* plude, dtype* psnde, dtype* pmfu, + dtype* pmfd, dtype* pa, dtype* pclv, dtype* psupsat, struct TECLDP* yrecldp, + dtype* rg, dtype* rd, dtype* rcpd, dtype* retv, dtype* rlvtt, dtype* rlstt, + dtype* rlmlt, dtype* rtt, dtype* rv, dtype* r2es, dtype* r3les, dtype* r3ies, + dtype* r4les, dtype* r4ies, dtype* r5les, dtype* r5ies, dtype* r5alvcp, dtype* r5alscp, + dtype* ralvdcp, dtype* ralsdcp, dtype* ralfdcp, dtype* rtwat, + dtype* rtice, dtype* rticecu, dtype* rtwat_rtice_r, dtype *rtwat_rticecu_r, + dtype* rkoop1, dtype* rkoop2); void load_reference(const int nlon, const int nlev, const int nclv, const int ngptot, const int nproma, - double *plude, double *pcovptot, double *prainfrac_toprfz, double *pfsqlf, double *pfsqif, - double *pfcqlng, double *pfcqnng, double *pfsqrf, double *pfsqsf, double *pfcqrng, double *pfcqsng, - double *pfsqltur, double *pfsqitur, double *pfplsl, double *pfplsn, double *pfhpsl, double *pfhpsn, - double *tend_loc_a, double *tend_loc_q, double *tend_loc_t, double *tend_loc_cld); + dtype *plude, dtype *pcovptot, dtype *prainfrac_toprfz, dtype *pfsqlf, dtype *pfsqif, + dtype *pfcqlng, dtype *pfcqnng, dtype *pfsqrf, dtype *pfsqsf, dtype *pfcqrng, dtype *pfcqsng, + dtype *pfsqltur, dtype *pfsqitur, dtype *pfplsl, dtype *pfplsn, dtype *pfhpsl, dtype *pfhpsn, + dtype *tend_loc_a, dtype *tend_loc_q, dtype *tend_loc_t, dtype *tend_loc_cld); diff --git a/src/cloudsc_hip/cloudsc/yoecldp_c.h b/src/cloudsc_hip/cloudsc/yoecldp_c.h index 7fcace99..4061f0d0 100644 --- a/src/cloudsc_hip/cloudsc/yoecldp_c.h +++ b/src/cloudsc_hip/cloudsc/yoecldp_c.h @@ -11,6 +11,8 @@ #ifndef YOECLDP_H #define YOECLDP_H +#include "dtype.h" + //int nclv; // number of microphysics variables //int ncldql; // liquid cloud water //int ncldqi; // ice cloud water @@ -19,108 +21,108 @@ //int ncldqv; // vapour struct TECLDP { - double ramid; - double rcldiff; - double rcldiff_convi; - double rclcrit; - double rclcrit_sea; - double rclcrit_land; - double rkconv; - double rprc1; - double rprc2; - double rcldmax; - double rpecons; - double rvrfactor; - double rprecrhmax; - double rtaumel; - double ramin; - double rlmin; - double rkooptau; - double rcldtopp; - double rlcritsnow; - double rsnowlin1; - double rsnowlin2; - double ricehi1; - double ricehi2; - double riceinit; - double rvice; - double rvrain; - double rvsnow; - double rthomo; - double rcovpmin; - double rccn; - double rnice; - double rccnom; - double rccnss; - double rccnsu; - double rcldtopcf; - double rdepliqrefrate; - double rdepliqrefdepth; - double rcl_kkaac; - double rcl_kkbac; - double rcl_kkaau; - double rcl_kkbauq; - double rcl_kkbaun; - double rcl_kk_cloud_num_sea; - double rcl_kk_cloud_num_land; - double rcl_ai; - double rcl_bi; - double rcl_ci; - double rcl_di; - double rcl_x1i; - double rcl_x2i; - double rcl_x3i; - double rcl_x4i; - double rcl_const1i; - double rcl_const2i; - double rcl_const3i; - double rcl_const4i; - double rcl_const5i; - double rcl_const6i; - double rcl_apb1; - double rcl_apb2; - double rcl_apb3; - double rcl_as; - double rcl_bs; - double rcl_cs; - double rcl_ds; - double rcl_x1s; - double rcl_x2s; - double rcl_x3s; - double rcl_x4s; - double rcl_const1s; - double rcl_const2s; - double rcl_const3s; - double rcl_const4s; - double rcl_const5s; - double rcl_const6s; - double rcl_const7s; - double rcl_const8s; - double rdenswat; - double rdensref; - double rcl_ar; - double rcl_br; - double rcl_cr; - double rcl_dr; - double rcl_x1r; - double rcl_x2r; - double rcl_x4r; - double rcl_ka273; - double rcl_cdenom1; - double rcl_cdenom2; - double rcl_cdenom3; - double rcl_schmidt; - double rcl_dynvisc; - double rcl_const1r; - double rcl_const2r; - double rcl_const3r; - double rcl_const4r; - double rcl_fac1; - double rcl_fac2; - double rcl_const5r; - double rcl_const6r; - double rcl_fzrab; - double rcl_fzrbb; + dtype ramid; + dtype rcldiff; + dtype rcldiff_convi; + dtype rclcrit; + dtype rclcrit_sea; + dtype rclcrit_land; + dtype rkconv; + dtype rprc1; + dtype rprc2; + dtype rcldmax; + dtype rpecons; + dtype rvrfactor; + dtype rprecrhmax; + dtype rtaumel; + dtype ramin; + dtype rlmin; + dtype rkooptau; + dtype rcldtopp; + dtype rlcritsnow; + dtype rsnowlin1; + dtype rsnowlin2; + dtype ricehi1; + dtype ricehi2; + dtype riceinit; + dtype rvice; + dtype rvrain; + dtype rvsnow; + dtype rthomo; + dtype rcovpmin; + dtype rccn; + dtype rnice; + dtype rccnom; + dtype rccnss; + dtype rccnsu; + dtype rcldtopcf; + dtype rdepliqrefrate; + dtype rdepliqrefdepth; + dtype rcl_kkaac; + dtype rcl_kkbac; + dtype rcl_kkaau; + dtype rcl_kkbauq; + dtype rcl_kkbaun; + dtype rcl_kk_cloud_num_sea; + dtype rcl_kk_cloud_num_land; + dtype rcl_ai; + dtype rcl_bi; + dtype rcl_ci; + dtype rcl_di; + dtype rcl_x1i; + dtype rcl_x2i; + dtype rcl_x3i; + dtype rcl_x4i; + dtype rcl_const1i; + dtype rcl_const2i; + dtype rcl_const3i; + dtype rcl_const4i; + dtype rcl_const5i; + dtype rcl_const6i; + dtype rcl_apb1; + dtype rcl_apb2; + dtype rcl_apb3; + dtype rcl_as; + dtype rcl_bs; + dtype rcl_cs; + dtype rcl_ds; + dtype rcl_x1s; + dtype rcl_x2s; + dtype rcl_x3s; + dtype rcl_x4s; + dtype rcl_const1s; + dtype rcl_const2s; + dtype rcl_const3s; + dtype rcl_const4s; + dtype rcl_const5s; + dtype rcl_const6s; + dtype rcl_const7s; + dtype rcl_const8s; + dtype rdenswat; + dtype rdensref; + dtype rcl_ar; + dtype rcl_br; + dtype rcl_cr; + dtype rcl_dr; + dtype rcl_x1r; + dtype rcl_x2r; + dtype rcl_x4r; + dtype rcl_ka273; + dtype rcl_cdenom1; + dtype rcl_cdenom2; + dtype rcl_cdenom3; + dtype rcl_schmidt; + dtype rcl_dynvisc; + dtype rcl_const1r; + dtype rcl_const2r; + dtype rcl_const3r; + dtype rcl_const4r; + dtype rcl_fac1; + dtype rcl_fac2; + dtype rcl_const5r; + dtype rcl_const6r; + dtype rcl_fzrab; + dtype rcl_fzrbb; int lcldextra, lcldbudget; int nssopt; int ncldtop; @@ -133,11 +135,11 @@ struct TECLDP { int laerliqcoll; int laericesed; int laericeauto; - double nshapep; - double nshapeq; + dtype nshapep; + dtype nshapeq; int nbeta; - //double rbeta[0][100]; - //double rbetap1[0][100]; + //dtype rbeta[0][100]; + //dtype rbetap1[0][100]; } ; //struct TECLDP *yrecldp;