Commit e868f05f authored by Ethan Coon's avatar Ethan Coon
Browse files

rework of makefiles

parent 9ca2fc3f
...@@ -11,17 +11,15 @@ cc_fortran_wrappers: fortran ...@@ -11,17 +11,15 @@ cc_fortran_wrappers: fortran
$(MAKE) -C cc_fortran_wrappers all $(MAKE) -C cc_fortran_wrappers all
cc: cc:
$(MAKE) -C cc all echo "header only"
fortran: fortran:
$(MAKE) -C fortran all $(MAKE) -C fortran all
clean: clean:
$(MAKE) -C cc clean
$(MAKE) -C fortran clean $(MAKE) -C fortran clean
allclean: allclean:
$(MAKE) -C cc clean
$(MAKE) -C fortran clean $(MAKE) -C fortran clean
......
#ifndef ELM_CANOPY_HYDROLOGY_HH_
#define ELM_CANOPY_HYDROLOGY_HH_
#include "CanopyHydrology_decl.hh"
#include "CanopyHydrology_Interception_impl.hh"
#include "CanopyHydrology_FracWet_impl.hh"
#include "CanopyHydrology_FracH2OSfc_impl.hh"
#include "CanopyHydrology_SnowWater_impl.hh"
#endif
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <string>
#include "landunit_varcon.h"
#include "CanopyHydrology_cpp.hh"
using namespace std;
using std::min ;
using std::max ;
namespace ELM {
NATURE 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*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+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;
}
frac_h2osfc = 0.5*(1.00+erf(d/(sigma*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 = 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;
}
}
}
\ No newline at end of file
#ifndef CANOPY_HYDROLOGY_FRACWET_IMPL_HH_
#define CANOPY_HYDROLOGY_FRACWET_IMPL_HH_
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <cmath> #include <cmath>
#include <string> #include <string>
#include "CanopyHydrology_cpp.hh"
using namespace std; using namespace std;
using std::min ; using std::min ;
...@@ -40,4 +43,6 @@ NATURE void CanopyHydrology_FracWet(const int& frac_veg_nosno, ...@@ -40,4 +43,6 @@ NATURE void CanopyHydrology_FracWet(const int& frac_veg_nosno,
} }
} }
\ No newline at end of file
#endif
#ifndef CANOPYHYDROLOGY_INTERCEPTION_IMPL_HH_
#define CANOPYHYDROLOGY_INTERCEPTION_IMPL_HH_
#include <algorithm> #include <algorithm>
#include <stdio.h> #include <stdio.h>
#include <cmath> #include <cmath>
...@@ -5,7 +9,6 @@ ...@@ -5,7 +9,6 @@
#include <string> #include <string>
#include "landunit_varcon.h" #include "landunit_varcon.h"
#include "column_varcon.h" #include "column_varcon.h"
#include "CanopyHydrology_cpp.hh"
using namespace std; using namespace std;
using std::min ; using std::min ;
...@@ -152,4 +155,7 @@ namespace ELM { ...@@ -152,4 +155,7 @@ namespace ELM {
} }
} }
} }
\ No newline at end of file
#endif
#ifndef CANOPY_HYDROLOGY_SNOWWATER_IMPL_HH_
#define CANOPY_HYDROLOGY_SNOWWATER_IMPL_HH_
#include <stdio.h> #include <stdio.h>
#include <cmath> #include <cmath>
#include "landunit_varcon.h" #include "landunit_varcon.h"
#include "column_varcon.h" #include "column_varcon.h"
#include "clm_varpar.h" #include "clm_varpar.h"
#include "clm_varctl.h" #include "clm_varctl.h"
#include "CanopyHydrology_cpp.hh"
using namespace std; using namespace std;
using std::min ; using std::min ;
...@@ -252,3 +254,5 @@ if (ltype==istwet && t_grnd>tfrz) { ...@@ -252,3 +254,5 @@ if (ltype==istwet && t_grnd>tfrz) {
} }
} }
#endif
#ifndef ELM_CANOPY_HYDROLOGY_CPP_HH_
#define ELM_CANOPY_HYDROLOGY_CPP_HH_
#ifndef NATURE
#define NATURE
#endif
namespace ELM {
NATURE 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, // need to be fixed
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) ;
NATURE void CanopyHydrology_FracWet(const int& frac_veg_nosno,
const double& h2ocan,
const double& elai,
const double& esai,
const double& dewmx,
double& fwet,
double& fdry) ;
template<typename Array_d>
NATURE 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_air_temp,
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& integrated_snow,
Array_d swe_old,
Array_d h2osoi_liq,
Array_d h2osoi_ice,
Array_d t_soisno,
Array_d frac_iceold,
int& snow_level,
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) ;
NATURE 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) ;
} // namespace
#endif
OBJECT = ../
default: all
include $(OBJECT)config/Makefile.config
# Order is important due to .mod file creation
OBJS =CanopyHydrology_Interception.cpp.o \
CanopyHydrology_FracWet.cpp.o \
CanopyHydrology_FracH2OSfc.cpp.o
all: $(OBJS)
$(AR) cr libelm.a $(OBJS)
clean:
@$(ELM_CLEAN);
@cd $(ELM_UTILS_DIR); $(ELM_CLEAN)
#ifndef COLUMN_VARPAR_H_
#define COLUMN_VARPAR_H_
static const int nlevsno = 5 ; static const int nlevsno = 5 ;
#endif
#ifndef COLUMN_VARCON_HH_
#define COLUMN_VARCON_HH_
static const int icol_roof = isturb_MIN*10 + 1; static const int icol_roof = isturb_MIN*10 + 1;
static const int icol_sunwall = isturb_MIN*10 + 2; static const int icol_sunwall = isturb_MIN*10 + 2;
static const int icol_shadewall = isturb_MIN*10 + 3; static const int icol_shadewall = isturb_MIN*10 + 3;
static const int icol_road_imperv = isturb_MIN*10 + 4; static const int icol_road_imperv = isturb_MIN*10 + 4;
static const int icol_road_perv = isturb_MIN*10 + 5; static const int icol_road_perv = isturb_MIN*10 + 5;
#endif
#ifndef LANDUNIT_VARCON_HH_
#define LANDUNIT_VARCON_HH_
static const int istsoil = 1 ; static const int istsoil = 1 ;
static const int istcrop = 2 ; static const int istcrop = 2 ;
...@@ -19,3 +20,5 @@ ...@@ -19,3 +20,5 @@
// character(len=landunit_name_length), public :: landunit_names(max_lunit) ; // character(len=landunit_name_length), public :: landunit_names(max_lunit) ;
static const int numurbl = isturb_MAX - isturb_MIN + 1 ; static const int numurbl = isturb_MAX - isturb_MIN + 1 ;
#endif
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
# Users should change these # Users should change these
# ------------------------------------------------------------------ # ------------------------------------------------------------------
#ifndef CONFIG_DONE
#define CONFIG_DONE
# Available from: git clone https://code.ornl.gov/isp/acme_inputdata # Available from: git clone https://code.ornl.gov/isp/acme_inputdata
ELM_DATA_LOCATION ?= /home/7hp/Downloads/acme_inputdata ELM_DATA_LOCATION ?= /home/7hp/Downloads/acme_inputdata
#ELM_DATA_LOCATION ?= /Users/uec/codes/elm/kernels/repos/acme_inputdata #ELM_DATA_LOCATION ?= /Users/uec/codes/elm/kernels/repos/acme_inputdata
...@@ -9,19 +13,26 @@ ELM_DATA_LOCATION ?= /home/7hp/Downloads/acme_inputdata ...@@ -9,19 +13,26 @@ ELM_DATA_LOCATION ?= /home/7hp/Downloads/acme_inputdata
# assumes you have a working NETCDF. This can easily be the version built by # assumes you have a working NETCDF. This can easily be the version built by
# ATS as a part of an ATS installation. # ATS as a part of an ATS installation.
NETCDF_ROOT ?= /usr/local NETCDF_ROOT ?= /usr/local
MPI_LIB_ROOT ?= /usr/lib/x86_64-linux-gnu/openmpi #NETCDF_ROOT ?= $(AMANZI_TPLS_DIR)
# assumes you have a working gfortran # assumes you have a working gfortran
FC = gfortran FC ?= gfortran
FC_FLAGS += -fimplicit-none -free -g3 -fbounds-check -fbacktrace FC_FLAGS ?= -fimplicit-none -free -g3 -fbounds-check -fbacktrace
FC_LIB_ROOT = /usr/lib/gcc/x86_64-linux-gnu/8 #/usr/local/Cellar/gcc/8.2.0/lib/gcc/8 FC_LIB_ROOT ?= /usr/lib/gcc/x86_64-linux-gnu/8
#FC_LIB_ROOT ?= /usr/local/Cellar/gcc/8.2.0/lib/gcc/8
# assumes you have a working c++ compiler # assumes you have a working c++ compiler
CC ?= gcc CC ?= gcc
#CC ?= clang
CXX ?= g++ CXX ?= g++
MPICC ?= mpicc #CXX ?= clang++
MPICXX ?= mpic++
CPP_FLAGS += -g -Wall -Wshadow -std=c++11 MPICC ?= mpicc
CXXFLAGS += -g -Wall -Wshadow -std=c++11 MPICXX ?= mpic++
CXXFLAGS += -g -Wall -Wshadow -std=c++11
STD_LIB_ROOT = /usr STD_LIB_ROOT = /usr
# assumes you have a working CUDA # assumes you have a working CUDA
...@@ -31,17 +42,19 @@ CUDA_LIBS= -lopenblas -lpthread -lcudart -lcublas ...@@ -31,17 +42,19 @@ CUDA_LIBS= -lopenblas -lpthread -lcudart -lcublas
CUDA_LIBDIRS=/usr/local/cuda-10.0/lib64 CUDA_LIBDIRS=/usr/local/cuda-10.0/lib64
CUDA_INCDIRS=-I/usr/local/cuda-10.0/include CUDA_INCDIRS=-I/usr/local/cuda-10.0/include
# END of User specified things # END of User specified things
#---------------------------------------- #----------------------------------------
NETCDF_FLAGS = -L$(NETCDF_ROOT)/lib -lnetcdf
NETCDFF_FLAGS = -L$(NETCDF_ROOT)/lib -lnetcdff
NETCDF_INC_FLAGS = -I$(NETCDF_ROOT)/include
ELM_FLAGS = -L$(ELM_ROOT) -lelm
ELM_INC_FLAGS = -I$(ELM_ROOT)
GFORTRAN_FLAGS = -L$(FC_LIB_ROOT) -lgfortran
# linking flags # linking flags
CC_LD_FLAGS += -L$(SRCDIR) -lelm -L$(NETCDF_ROOT) -lnetcdf -L$(STD_LIB_ROOT)/lib -lstdc++ -L$(MPI_LIB_ROOT)/lib -L$(FC_LIB_ROOT) -lgfortran CUDA_LD_FLAGS = -L$(CUDA_LIBDIRS) -lpthread -lcudart -lcublas
FC_LD_FLAGS += -L$(SRCDIR) -lelm -L$(NETCDF_ROOT) -lnetcdff
CXX_LD_FLAGS += -L$(SRCDIR) -lelm -L$(NETCDF_ROOT) -lnetcdf
CUDA_LD_FLAGS += -L$(SRCDIR) -lelm -L$(NETCDF_ROOT) -lnetcdf -L$(CUDA_LIBDIRS) -lstdc++ -lpthread -lcudart -lcublas
# #
# rules # rules
...@@ -51,21 +64,14 @@ CUDA_LD_FLAGS += -L$(SRCDIR) -lelm -L$(NETCDF_ROOT) -lnetcdf -L$(CUDA_LIBDIRS) - ...@@ -51,21 +64,14 @@ CUDA_LD_FLAGS += -L$(SRCDIR) -lelm -L$(NETCDF_ROOT) -lnetcdf -L$(CUDA_LIBDIRS) -
.SUFFIXES: .cc.o .F90.o .cpp.o .cu.o .cc .F90 .cpp .cu .SUFFIXES: .cc.o .F90.o .cpp.o .cu.o .cc .F90 .cpp .cu
%.F90.o: %.F90 %.F90.o: %.F90
$(FC) $(FC_FLAGS) -c $< -o $@ $(FC) $(FC_FLAGS) $(NETCDF_INC_FLAGS) $(ELM_INC_FLAGS) -c $< -o $@
%.cc.o: %.cc
$(CC) $(CC_FLAGS) $(CPP_FLAGS) $(INC_FLAGS) -c $< -o $@
%.cpp.o: %.cpp %.cpp.o: %.cpp
$(CXX) $(CC_FLAGS) $(CXXFLAGS) $(INC_FLAGS) -c $< -o $@ $(CXX) $(CXXFLAGS) $(NETCDF_INC_FLAGS) $(ELM_INC_FLAGS) -c $< -o $@
%.cu.o: %.cu %.cu.o: %.cu
$(NVCC) $(CUDA_FLAGS) $(INC_FLAGS) -c $< -o $@ $(NVCC) $(CUDA_FLAGS) -c $< -o $@
SHELL = /bin/sh SHELL = /bin/sh
ELM_LIB = libelm.a
ELM_LIBS = -lelm
ELM_DIR = elm
ELM_UTILS_DIR = cime_utils
LIB_SUFFIX=.a LIB_SUFFIX=.a
M4 = M4 =
...@@ -82,3 +88,4 @@ ELM_CLEAN=$(RM) -f *.o *.ii *.int.c *.log *.log.* stamp-* core core.* stats -r t ...@@ -82,3 +88,4 @@ ELM_CLEAN=$(RM) -f *.o *.ii *.int.c *.log *.log.* stamp-* core core.* stats -r t
#endif
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#include "utils.hh" #include "utils.hh"
#include "readers.hh" #include "readers.hh"
#include "CanopyHydrology_cpp.hh" #include "CanopyHydrology.hh"
namespace ELM { namespace ELM {
...@@ -24,7 +24,7 @@ namespace Utils { ...@@ -24,7 +24,7 @@ namespace Utils {
static const int n_months = 12; static const int n_months = 12;
static const int n_pfts = 17; static const int n_pfts = 17;
static const int n_max_times = 31 * 24 * 2; // max days per month times hours per static const int n_max_times = 31 * 24 * 2; // max days per month times hours per
// day * half hour timestep // day * half hour timestep
static const int n_grid_cells = 24; static const int n_grid_cells = 24;
using MatrixState = MatrixStatic<n_grid_cells, n_pfts>; using MatrixState = MatrixStatic<n_grid_cells, n_pfts>;
...@@ -88,12 +88,14 @@ int main(int argc, char ** argv) ...@@ -88,12 +88,14 @@ int main(int argc, char ** argv)
// output state by the pft // output state by the pft
auto h2o_can = ELM::Utils::MatrixState(); h2o_can = 0.; auto h2o_can = ELM::Utils::MatrixState(); h2o_can = 0.;
std::cout << "Time\t Total Canopy Water\t Min Water\t Max Water" << std::endl; {
auto min_max = std::minmax_element(h2o_can.begin(), h2o_can.end()); std::cout << "Time\t Total Canopy Water\t Min Water\t Max Water" << std::endl;
std::cout << std::setprecision(16) auto min_max = std::minmax_element(h2o_can.begin(), h2o_can.end());
<< 0 << "\t" << std::accumulate(h2o_can.begin(), h2o_can.end(), 0.) std::cout << std::setprecision(16)
<< "\t" << *min_max.first << 0 << "\t" << std::accumulate(h2o_can.begin(), h2o_can.end(), 0.)
<< "\t" << *min_max.second << std::endl; << "\t" << *min_max.first
<< "\t" << *min_max.second << std::endl;
}
// main loop // main loop
// -- the timestep loop cannot/should not be parallelized // -- the timestep loop cannot/should not be parallelized
...@@ -114,19 +116,20 @@ int main(int argc, char ** argv) ...@@ -114,19 +116,20 @@ int main(int argc, char ** argv)
qflx_snwcp_liq(g,p), qflx_snwcp_ice(g,p), qflx_snwcp_liq(g,p), qflx_snwcp_ice(g,p),
qflx_snow_grnd_patch(g,p), qflx_rain_grnd(g,p)); qflx_snow_grnd_patch(g,p), qflx_rain_grnd(g,p));
// qflx_prec_intr[g], qflx_irrig[g], qflx_prec_grnd[g], // qflx_prec_intr[g], qflx_irrig[g], qflx_prec_grnd[g],
// qflx_snwcp_liq[g], qflx_snwcp_ice[g], // qflx_snwcp_liq[g], qflx_snwcp_ice[g],
// qflx_snow_grnd_patch[g], qflx_rain_grnd[g]); // qflx_snow_grnd_patch[g], qflx_rain_grnd[g]);
//printf("%i %i %16.8g %16.8g %16.8g %16.8g %16.8g %16.8g\n", g, p, forc_rain(t,g), forc_snow(t,g), elai(g,p), esai(g,p), h2o_can(g,p), qflx_prec_intr[g]); //printf("%i %i %16.8g %16.8g %16.8g %16.8g %16.8g %16.8g\n", g, p, forc_rain(t,g), forc_snow(t,g), elai(g,p), esai(g,p), h2o_can(g,p), qflx_prec_intr[g]);
} }
} }
auto min_max = std::minmax_element(h2o_can.begin(), h2o_can.end()); {
std::cout << std::setprecision(16) auto min_max = std::minmax_element(h2o_can.begin(), h2o_can.end());
<< t+1 << "\t" << std::accumulate(h2o_can.begin(), h2o_can.end(), 0.) std::cout << std::setprecision(16)
<< "\t" << *min_max.first << t+1 << "\t" << std::accumulate(h2o_can.begin(), h2o_can.end(), 0.)
<< "\t" << *min_max.second << std::endl; << "\t" << *min_max.first
<< "\t" << *min_max.second << std::endl;
}
} }
return 0; return 0;
MPI_Finalize(); MPI_Finalize();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "utils.hh" #include "utils.hh"
#include "readers.hh" #include "readers.hh"
#include "CanopyHydrology_cpp.hh" #include "CanopyHydrology.hh"
namespace ELM { namespace ELM {
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "readers.hh" #include "readers.hh"
#include "CanopyHydrology_cpp.hh"