Commit 0ad59aa6 authored by Pillai, Himanshu's avatar Pillai, Himanshu
Browse files

Cleaning

parent b8c02f9e
Evaluation
================
| DRIVER | KERNEL | KERNEL |
|===================|=============|=============|
| PROGRAMMING MODEL | FORTRAN | C++ |
| --------------- | :---------: | :---------: |
| FORTRAN | Works | Works |
| C++ | X | Works |
| LEGION FORTRAN | X | X |
| FORTRAN | Works | X |
| C++ | Works | Works |
| LEGION FORTRAN | X | X |
| LEGION C++ | Partially | Works |
| KOKKOS Fortran | X | X |
| KOKKOS Fortran | X | X |
| KOKKOS C++ | X | Works |
| CUDA | X | Debugging |
| OpenMP/OpenACC | N/A | N/A |
......
SRCDIR = .
OBJECT = .
.PHONY: cc_fortran_wrappers cc_serial cc_kokkos fortran cuda
.PHONY: cc_fortran_wrappers cc fortran
default: all
all: cc_fortran_wrappers fortran cc_serial cc_kokkos cuda
all: cc_fortran_wrappers fortran cc
cc_fortran_wrappers: fortran
$(MAKE) -C cc_fortran_wrappers all
cc_serial:
$(MAKE) -C cc_serial all
cc_kokkos:
$(MAKE) -C cc_kokkos all
cc:
$(MAKE) -C cc all
fortran:
$(MAKE) -C fortran all
cuda:
$(MAKE) -C cuda all
clean:
$(MAKE) -C cc clean
$(MAKE) -C fortran clean
$(MAKE) -C cuda clean
allclean:
$(MAKE) -C cc_serial clean
$(MAKE) -C cc_kokkos clean
$(MAKE) -C cc clean
$(MAKE) -C fortran clean
$(MAKE) -C cuda clean
......@@ -7,6 +7,8 @@
#include "CanopyHydrology_cpp.hh"
using namespace std;
using std::min ;
using std::max ;
namespace ELM {
......@@ -14,7 +16,7 @@ void CanopyHydrology_FracH2OSfc(const double& dtime,
const double& min_h2osfc,
const int& ltype,
const double& micro_sigma,
double& h2osno,
const double& h2osno,
double& h2osfc,
double& h2osoi_liq,
double& frac_sno,
......@@ -45,7 +47,7 @@ void CanopyHydrology_FracH2OSfc(const double& dtime,
sigma=1.0e3 * micro_sigma ;
for(int l = 0 ; l < 10; l++) {
fd = 0.5*d*(1.00+erf(d/(sigma*sqrt(2.0)))) + sigma/sqrt(2.0*shr_const_pi)*std::exp(-std::pow(d,2)/(2.0*std::pow(sigma,2))) -h2osfc;
fd = 0.5*d*(1.00+erf(d/(sigma*sqrt(2.0)))) + sigma/sqrt(2.0*shr_const_pi)*exp(-pow(d,2)/(2.0*pow(sigma,2))) -h2osfc;
dfdd = 0.5*(1.00+erf(d/(sigma*sqrt(2.0))));
d = d - fd/dfdd;
......@@ -66,7 +68,7 @@ void CanopyHydrology_FracH2OSfc(const double& dtime,
if (frac_sno > (1.0 - frac_h2osfc) && h2osno > 0) {
if (frac_h2osfc > 0.010) {
frac_h2osfc = std::max(1.00 - frac_sno,0.010) ;
frac_h2osfc = max(1.00 - frac_sno,0.010) ;
frac_sno = 1.00 - frac_h2osfc; }
else {
frac_sno = 1.00 - frac_h2osfc;
......
......@@ -5,6 +5,8 @@
#include "CanopyHydrology_cpp.hh"
using namespace std;
using std::min ;
using std::max ;
namespace ELM {
......@@ -23,8 +25,8 @@ void CanopyHydrology_FracWet(const int& frac_veg_nosno,
if (h2ocan > 0.0) {
vegt = frac_veg_nosno*(elai + esai);
dewmxi = 1.00/dewmx;
fwet = std::pow(((dewmxi/vegt)*h2ocan), 2.0/3);
fwet = std::min(fwet,1.00);
fwet = pow(((dewmxi/vegt)*h2ocan), 2.0/3);
fwet = min(fwet,1.00);
fdry = (1.0-fwet)*elai/(elai+esai);
}
else{
......
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <string>
#include "landunit_varcon.h"
......@@ -8,9 +8,11 @@
#include "CanopyHydrology_cpp.hh"
using namespace std;
using std::min ;
using std::max ;
namespace ELM {
void CanopyHydrology_Interception(double dtime,
void CanopyHydrology_Interception(double dtime,
const double& forc_rain,
const double& forc_snow,
const double& irrig_rate,
......@@ -73,7 +75,7 @@ void CanopyHydrology_Interception(double dtime,
h2ocan = std::max(0.0, h2ocan + dtime*qflx_prec_intr);
h2ocan = max(0.0, h2ocan + dtime*qflx_prec_intr);
qflx_candrip = 0.0;
......
......@@ -7,11 +7,13 @@
#include "CanopyHydrology_cpp.hh"
using namespace std;
using std::min ;
using std::max ;
namespace ELM {
template<typename Array_d>
void CanopyHydrology_SnowWater(const double& dtime,
void CanopyHydrology_SnowWater(const double& dtime,
const double& qflx_floodg,
const int& ltype,
const int& ctype,
......@@ -97,9 +99,9 @@ template<typename Array_d>
} else {
if (forc_air_temp > tfrz + 2.) {
bifall=50. + 1.7*std::pow((17.0),1.5);
bifall=50. + 1.7*pow((17.0),1.5);
} else if (forc_air_temp > tfrz - 15.) {
bifall=50. + 1.7*std::pow((forc_air_temp - tfrz + 15.),1.5);
bifall=50. + 1.7*pow((forc_air_temp - tfrz + 15.),1.5);
} else {
bifall=50.;
}
......@@ -108,7 +110,7 @@ template<typename Array_d>
newsnow = (1. - frac_h2osfc) * qflx_snow_grnd_col * dtime;
// update integrated_snow
integrated_snow = std::max(integrated_snow,h2osno) ; //h2osno could be larger due to frost
integrated_snow = max(integrated_snow,h2osno) ; //h2osno could be larger due to frost
// snowmelt from previous time step * dtime
snowmelt = qflx_snow_melt * dtime;
......@@ -123,9 +125,9 @@ template<typename Array_d>
// first compute change from melt during previous time step
if(snowmelt > 0.) {
smr=std::min(1.,(h2osno)/(integrated_snow));
smr=min(1.,(h2osno)/(integrated_snow));
frac_sno = 1. - std::pow((acos(min(1.,(2.*smr - 1.)))/rpi),(n_melt)) ;
frac_sno = 1. - pow((acos(min(1.,(2.*smr - 1.)))/rpi),(n_melt)) ;
}
......@@ -135,8 +137,8 @@ template<typename Array_d>
frac_sno = fsno_new;
// reset integrated_snow after accumulation events
temp_intsnow= (h2osno + newsnow) / (0.5*(cos(rpi*std::pow((1.0-std::max(frac_sno,1e-6)),(1.0/n_melt))+1.0))) ;
integrated_snow = std::min(1.e8,temp_intsnow) ;
temp_intsnow= (h2osno + newsnow) / (0.5*(cos(rpi*pow((1.0-max(frac_sno,1e-6)),(1.0/n_melt))+1.0))) ;
integrated_snow = min(1.e8,temp_intsnow) ;
}
//====================================================================
......@@ -157,10 +159,10 @@ template<typename Array_d>
if (oldfflag == 1) {
// snow cover fraction in Niu et al. 2007
if(snow_depth > 0.0) {
frac_sno = tanh(snow_depth/(2.5*zlnd*std::pow((std::min(800.0,(h2osno+ newsnow)/snow_depth)/100.0),1.0)) ) ;
frac_sno = tanh(snow_depth/(2.5*zlnd*pow((min(800.0,(h2osno+ newsnow)/snow_depth)/100.0),1.0)) ) ;
}
if(h2osno < 1.0) {
frac_sno=std::min(frac_sno,h2osno);
frac_sno=min(frac_sno,h2osno);
}
}
......@@ -173,8 +175,8 @@ template<typename Array_d>
// make integrated_snow consistent w/ new fsno, h2osno
integrated_snow = 0. ;//reset prior to adding newsnow below
temp_intsnow= (h2osno + newsnow) / (0.5*(cos(rpi*std::pow((1.0-std::max(frac_sno,1e-6)),(1.0/n_melt)))+1.0));
integrated_snow = std::min(1.e8,temp_intsnow);
temp_intsnow= (h2osno + newsnow) / (0.5*(cos(rpi*pow((1.0-max(frac_sno,1e-6)),(1.0/n_melt)))+1.0));
integrated_snow = min(1.e8,temp_intsnow);
// update snow_depth and h2osno to be consistent with frac_sno, z_avg
if (subgridflag ==1 && !urbpoi) {
......@@ -186,7 +188,7 @@ template<typename Array_d>
if (oldfflag == 1) {
// snow cover fraction in Niu et al. 2007
if(snow_depth > 0.0) {
frac_sno = tanh(snow_depth/(2.5*zlnd*std::pow((std::min(800.0,newsnow/snow_depth)/100.0),1.0)) );
frac_sno = tanh(snow_depth/(2.5*zlnd*pow((min(800.0,newsnow/snow_depth)/100.0),1.0)) );
}
}
} else {
......
......@@ -3,7 +3,7 @@
namespace ELM {
void CanopyHydrology_Interception(double dtime,
void CanopyHydrology_Interception(double dtime,
const double& forc_rain,
const double& forc_snow,
const double& irrig_rate,
......@@ -23,7 +23,7 @@ namespace ELM {
void CanopyHydrology_FracWet(const int& frac_veg_nosno,
void CanopyHydrology_FracWet(const int& frac_veg_nosno,
const double& h2ocan,
const double& elai,
const double& esai,
......@@ -65,11 +65,11 @@ void CanopyHydrology_SnowWater(const double& dtime,
double& frac_sno) ;
void CanopyHydrology_FracH2OSfc(const double& dtime,
void CanopyHydrology_FracH2OSfc(const double& dtime,
const double& min_h2osfc,
const int& ltype,
const double& micro_sigma,
double& h2osno,
const double& h2osno,
double& h2osfc,
double& h2osoi_liq,
double& frac_sno,
......
#ifndef ELM_CANOPY_HYDROLOGY_FORT_HH_
#define ELM_CANOPY_HYDROLOGY_FORT_HH_
#include "CanopyHydrology_private.h"
namespace ELM {
inline void CanopyHydrology_Interception(double dtime,
const double& forc_rain,
const double& forc_snow,
const double& irrig_rate,
const int& ltype, const int& ctype,
const bool& urbpoi, const bool& do_capsnow,
const double& elai, const double& esai,
const double& dewmx, const int& frac_veg_nosno,
double& h2ocan,
int& n_irrig_steps_left,
double& qflx_prec_intr,
double& qflx_irrig,
double& qflx_prec_grnd,
double& qflx_snwcp_liq,
double& qflx_snwcp_ice,
double& qflx_snow_grnd_patch,
double& qflx_rain_grnd) {
canopyhydrology_interception_(&dtime, &forc_rain, &forc_snow, &irrig_rate,
&ltype, &ctype, &urbpoi, &do_capsnow, &elai, &esai,
&dewmx, &frac_veg_nosno, &h2ocan, &n_irrig_steps_left,
&qflx_prec_intr, &qflx_irrig, &qflx_prec_grnd,
&qflx_snwcp_liq, &qflx_snwcp_ice, & qflx_snow_grnd_patch, &qflx_rain_grnd);
}
inline void CanopyHydrology_FracWet(const int& frac_veg_nosno,
const double& h2ocan,
const double& elai,
const double& esai,
const double& dewmx,
double& fwet,
double& fdry) {
canopyhydrology_fracwet_(&frac_veg_nosno, &h2ocan, &elai, &esai, &dewmx, &fwet, &fdry);
}
template<typename Array_d>
void CanopyHydrology_SnowWater(const double& dtime,
const double& qflx_floodg,
const int& ltype,
const int& ctype,
const bool& urbpoi,
const bool& do_capsnow,
const int& oldfflag,
const double& forc_t,
const double& t_grnd,
const double& qflx_snow_grnd_col,
const double& qflx_snow_melt,
const double& n_melt,
const double& frac_h2osfc,
double& snow_depth,
double& h2osno,
double& int_snow,
Array_d& swe_old,
Array_d& h2osoi_liq,
Array_d& h2osoi_ice,
Array_d& t_soisno,
Array_d& frac_iceold,
int& snl,
Array_d& dz,
Array_d& z,
Array_d& zi,
int& newnode,
double& qflx_floodc,
double& qflx_snow_h2osfc,
double& frac_sno_eff,
double& frac_sno) {
canopyhydrology_snowwater_(&dtime, &qflx_floodg, &ltype, &ctype, &urbpoi,
&do_capsnow, &oldfflag, &forc_t, &t_grnd,
&qflx_snow_grnd_col, &qflx_snow_melt, &n_melt,
&frac_h2osfc, &snow_depth, &h2osno, &int_snow,
&swe_old[0], &h2osoi_liq[0], &h2osoi_ice[0], &t_soisno[0],
&frac_iceold[0], &snl, &dz[0], &z[0], &zi[0], &newnode,
&qflx_floodc, &qflx_snow_h2osfc, &frac_sno_eff, &frac_sno);
}
inline void CanopyHydrology_FracH2OSfc(const double& dtime,
const double& min_h2osfc,
const int& ltype,
const double& micro_sigma,
const double& h2osno,
double& h2osfc,
double& h2osoi_liq,
double& frac_sno,
double& frac_sno_eff,
double& qflx_h2osfc2topsoi,
double& frac_h2osfc,
bool no_update=false) {
canopyhydrology_frach2osfc_(&dtime, &min_h2osfc, &ltype, &micro_sigma, &h2osno,
&h2osfc, &h2osoi_liq, &frac_sno, &frac_sno_eff, &qflx_h2osfc2topsoi,
&frac_h2osfc, &no_update);
}
} // namespace
#endif
#ifndef ELM_CANOPY_HYDROLOGY_FORT_PRIVATE_HH_
#define ELM_CANOPY_HYDROLOGY_FORT_PRIVATE_HH_
extern "C" {
void canopyhydrology_interception_(const double* dtime,
const double* forc_rain,
const double* forc_snow,
const double* irrig_rate,
const int* ltype,
const int* ctype,
const bool* urbpoi,
const bool* do_capsnow,
const double* elai,
const double* esai,
const double* dewmx,
const int* frac_veg_nosno,
const double* h2ocan,
const int* n_irrig_steps_left,
const double* qflx_prec_intr,
const double* qflx_irrig,
const double* qflx_prec_grnd,
const double* qflx_snwcp_liq,
const double* qflx_snwcp_ice,
const double* qflx_snow_grnd_patch,
const double* qflx_rain_grnd);
void canopyhydrology_fracwet_(const int* frac_veg_nosno,
const double* h2ocan,
const double* elai,
const double* esai,
const double* dewmx,
const double* fwet,
const double* fdry);
void canopyhydrology_snowwater_(const double* dtime,
const double* qflx_floodg,
const int* ltype,
const int* ctype,
const bool* urbpoi,
const bool* do_capsnow,
const int* oldfflag,
const double* forc_t,
const double* t_grnd,
const double* qflx_snow_grnd_col,
const double* qflx_snow_melt,
const double* n_melt,
const double* frac_h2osfc,
const double* snow_depth,
const double* h2osno,
const double* int_snow,
const double* swe_old,
const double* h2osoi_liq,
const double* h2osoi_ice,
const double* t_soisno,
const double* frac_iceold,
const int* snl,
const double* dz,
const double* z,
const double* zi,
const int* newnode,
const double* qflx_floodc,
const double* qflx_snow_h2osfc,
const double* frac_sno_eff,
const double* frac_sno);
void canopyhydrology_frach2osfc_(const double* dtime,
const double* min_h2osfc,
const int* ltype,
const double* micro_sigma,
const double* h2osno,
const double* h2osfc,
const double* h2osoi_liq,
const double* frac_sno,
const double* frac_sno_eff,
const double* qflx_h2osfc2topsoi,
const double* frac_h2osfc,
const bool* no_update);
}
#endif
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <string>
#include "landunit_varcon.h"
#include "CanopyHydrology_cc.hh"
using namespace std;
namespace ELM {
void CanopyHydrology_FracH2OSfc(const double& dtime,
const double& min_h2osfc,
const int& ltype,
const double& micro_sigma,
const double& h2osno,
double& h2osfc,
double& h2osoi_liq,
double& frac_sno,
double& frac_sno_eff,
double& qflx_h2osfc2topsoi,
double& frac_h2osfc)
{
bool no_update = false;
double shr_const_pi=4.0e0*std::atan(1.0e0) ;
bool no_update_l ;
double d,fd,dfdd,sigma ;
if (!no_update) {
no_update_l = false; }
else { no_update_l = no_update; }
qflx_h2osfc2topsoi = 0.0 ;
if ( ltype == istsoil || ltype == istcrop) {
if (h2osfc > min_h2osfc) {
d=0.0 ;
sigma=1.0e3 * micro_sigma ;
for(int l = 0 ; l < 10; l++) {
fd = 0.5*d*(1.00+std::erf(d/(sigma*std::sqrt(2.0)))) + sigma/std::sqrt(2.0*shr_const_pi)*std::exp(-std::pow(d,2)/(2.0*std::pow(sigma,2))) -h2osfc;
dfdd = 0.5*(1.00+std::erf(d/(sigma*std::sqrt(2.0))));
d = d - fd/dfdd;
}
frac_h2osfc = 0.5*(1.00+std::erf(d/(sigma*std::sqrt(2.0)))) ; }
else {
frac_h2osfc = 0.0 ;
h2osoi_liq = h2osoi_liq + h2osfc ;
qflx_h2osfc2topsoi = h2osfc/dtime ;
h2osfc=0.0 ;
}
if (!no_update_l) {
if (frac_sno > (1.0 - frac_h2osfc) && h2osno > 0) {
if (frac_h2osfc > 0.010) {
frac_h2osfc = std::max(1.00 - frac_sno,0.010) ;
frac_sno = 1.00 - frac_h2osfc; }
else {
frac_sno = 1.00 - frac_h2osfc;
}
frac_sno_eff=frac_sno;
}
}
}
else {
frac_h2osfc = 0.0;
}
}
}
#include <algorithm>
#include <iostream>
#include <cmath>
#include <string>
#include "CanopyHydrology_cc.hh"
using namespace std;
namespace ELM {
void CanopyHydrology_FracWet(const int& frac_veg_nosno,
const double& h2ocan,
const double& elai,
const double& esai,
const double& dewmx,
double& fwet,
double& fdry)
{
double vegt, dewmxi ;
if (frac_veg_nosno == 1) {
if (h2ocan > 0.0) {
vegt = frac_veg_nosno*(elai + esai);
dewmxi = 1.00/dewmx;
fwet = std::pow(((dewmxi/vegt)*h2ocan), 2.0/3);
fwet = std::min(fwet,1.00);
fdry = (1.0-fwet)*elai/(elai+esai);
}
else{
fwet = 0.0;
fdry = 0.0 ;
} }
else{
fwet = 0.0;
fdry = 0.0;
}
}
}
\ No newline at end of file