diff --git a/.gitignore b/.gitignore index 298b31e..ac07c89 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,9 @@ forcing rAnalysis/test.R *.*.swp *.DS_Store +/vcpkg/ +/Testing/ +/dist/ +/build/ +/.idea/ +/cmake-build-debug-msys2/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e64fe39 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.26) +set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake" CACHE STRING "Vcpkg toolchain file") +project(SHUD) + +set(CMAKE_CXX_STANDARD 11) + +if(CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(VCPKG_TARGET_TRIPLET "x64-linux" CACHE STRING "" FORCE) +elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(VCPKG_TARGET_TRIPLET "x64-osx" CACHE STRING "" FORCE) +endif() + + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/dist/bin) + +find_package (OpenMP) +find_package(SUNDIALS CONFIG REQUIRED) +set(COVDE_LIB "SUNDIALS::cvode_static") + +add_subdirectory(src) +enable_testing() +add_subdirectory(test) + + + + diff --git a/Makefile b/Makefile deleted file mode 100644 index 1e60633..0000000 --- a/Makefile +++ /dev/null @@ -1,157 +0,0 @@ -# ----------------------------------------------------------------- -# Version: 1.0 -# Date: Nov 2019 -# Makefile for SHUD v 1.0 -# ----------------------------------------------------------------- -# Programmer: Lele Shu (lele.shu@gmail.com) -# SHUD model is a heritage of Penn State Integrated Hydrologic Model (PIHM). -# ----------------------------------------------------------------- -# Prerequisite: -# 1 install sundials 5.0+ via https://computation.llnl.gov/projects/sundials/sundials-software. -# 2 If parallel-computing is prefered, please install OpenMP. -# For mac: -# 
 brew install llvm clang -# brew install libomp -# compile flags for OpenMP: -# -Xpreprocessor -fopenmp -lomp -# Library/Include paths: -# -L/usr/local/opt/libomp/lib -# -I/usr/local/opt/libomp/include -# -# ----------------------------------------------------------------- -# Configure this File: -# 1 Path of SUNDIALS_DIR. [CRITICAL] -# 2 Path of OpenMP if parallel is preffered. -# 3 Path of SRC_DIR, default is "SRC_DIR = ." -# 4 Path of BUILT_DIR, default is "BUILT_DIR = ." -# ----------------------------------------------------------------- -SUNDIALS_DIR = $(HOME)/sundials -# SUNDIALS_DIR = /usr/local/sundials - - -SHELL = /bin/sh -BUILDDIR = . -SRC_DIR = src - -LIB_SYS = /usr/local/lib/ -INC_OMP = /usr/local/opt/libomp/include -LIB_OMP = /usr/local/opt/libomp/lib -LIB_SUN = ${SUNDIALS_DIR}/lib - -INC_MPI = /usr/local/opt/open-mpi - -TARGET_EXEC = ${BUILDDIR}/shud -TARGET_OMP = ${BUILDDIR}/shud_omp -TARGET_DEBUG = ${BUILDDIR}/shud_debug - -MAIN_shud = ${SRC_DIR}/main.cpp -MAIN_OMP = ${SRC_DIR}/main.cpp -MAIN_DEBUG = ${SRC_DIR}/main.cpp - -# If compile on Cluster -# CC = g++ -# MPICC = mpic++ -# LK_OMP = -fopenmp -lsundials_nvecopenmp -# export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${SUNDIALS_DIR}/lib - -CC = /usr/bin/g++ -MPICC = /usr/local/bin/mpic++ -CFLAGS = -O3 -g -std=c++14 -#STCFLAG = -static - -SRC = ${SRC_DIR}/classes/*.cpp \ - ${SRC_DIR}/ModelData/*.cpp \ - ${SRC_DIR}/Model/*.cpp \ - ${SRC_DIR}/Equations/*.cpp - -SRC_H = ${SRC_DIR}/classes/*.hpp \ - ${SRC_DIR}/ModelData/*.hpp \ - ${SRC_DIR}/Model/*.hpp \ - ${SRC_DIR}/Equations/*.hpp - - -INCLUDES = -I ${SUNDIALS_DIR}/include \ - -I ${INC_OMP} \ - -I ${SRC_DIR}/Model \ - -I ${SRC_DIR}/ModelData \ - -I ${SRC_DIR}/classes \ - -I ${SRC_DIR}/Equations - - -LIBRARIES = -L ${LIB_OMP} \ - -L ${LIB_SUN} \ - -L ${LIB_SYS} - -RPATH = '-Wl,-rpath,${LIB_SUN}' - -LK_FLAGS = -lm -lsundials_cvode -lsundials_nvecserial -LK_OMP = -Xpreprocessor -fopenmp -lomp -lsundials_nvecopenmp -LK_DYLN = "LD_LIBRARY_PATH=${LIB_SUN}" - -all: - make clean - make shud - @echo -check: - ls ${SUNDIALS_DIR} - ls ${SUNDIALS_DIR}/lib - ./shud - @echo -help: - @(echo) - @echo "Usage:" - @(echo ' make all - make both shud and shud_omp') - @(echo ' make cvode - install SUNDIALS/CVODE to ~/sundials') - @(echo ' make shud - make shud executable') - @(echo ' make shud_omp - make shud_omp with OpenMP support') - @(echo) - @(echo ' make clean - remove all executable files') - @(echo) -cvode CVODE: - @echo '...Install SUNDIALS/CVODE for your ...' - chmod +x configure - ./configure - @echo - -shud SHUD: ${MAIN_shud} $(SRC) $(SRC_H) - @echo '...Compiling shud ...' - @echo $(CC) $(CFLAGS) ${STCFLAG} ${INCLUDES} ${LIBRARIES} ${RPATH} -o ${TARGET_EXEC} ${MAIN_shud} $(SRC) $(LK_FLAGS) - @echo - @echo - $(CC) $(CFLAGS) ${INCLUDES} ${STCFLAG} ${LIBRARIES} ${RPATH} -o ${TARGET_EXEC} ${MAIN_shud} $(SRC) $(LK_FLAGS) - @echo - @echo - @echo " ${TARGET_EXEC} is compiled successfully!" - @echo - -shud_omp: ${MAIN_OMP} $(SRC) $(SRC_H) - @echo '...Compiling shud_OpenMP ...' - @echo $(CC) $(CFLAGS) ${STCFLAG} ${RPATH} -D_OPENMP_ON ${INCLUDES} ${LIBRARIES} -o ${TARGET_OMP} ${MAIN_OMP} $(SRC) $(LK_FLAGS) $(LK_OMP) - @echo - @echo - $(CC) $(CFLAGS) ${STCFLAG} ${RPATH} -D_OPENMP_ON ${INCLUDES} ${LIBRARIES} -o ${TARGET_OMP} ${MAIN_OMP} $(SRC) $(LK_FLAGS) $(LK_OMP) - @echo - @echo " ${TARGET_OMP} is compiled successfully!" - @echo - @echo - -clean: - @echo "Cleaning ... " - @echo - @echo " rm -f *.o" - @rm -f *.o - - @echo " rm -f ${TARGET_EXEC}" - @rm -f ${TARGET_EXEC} - - @echo " rm -f ${TARGET_OMP}" - @rm -f ${TARGET_OMP} - - @echo - @echo "Done." - @echo - - - - - diff --git a/Script/installSundials.sh b/Script/installSundials.sh deleted file mode 100755 index c2a25ed..0000000 --- a/Script/installSundials.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/bash -path="~/sundials" -installPath="InstallSundials" -echo "Trying to download and install SUNDIALS/CVODE solver for you." -echo "" -read -p "Where to install?(Default: $path) :" path -path=${path:-~/sundials} -echo $path - -echo "Installing SUNDIALS to $path" -echo "Installing examples to $path/example" -echo "" - -rm -rf $installPath -rm -rf sundials-master - -echo "download from github: \n wget https://codeload.github.com/LLNL/sundials/zip/master" -wget -c https://codeload.github.com/LLNL/sundials/zip/master -O sundials-master.zip - -echo "unzip sundials-master.zip" -unzip sundials-master.zip - -mkdir $installPath -echo "cd $installPath" -cd $installPath -rm -rf builddir - -echo "makedir builddir" -mkdir builddir -echo "cd builddir" -cd builddir/ - -#ccmake ../../sundials/ -echo "start configure...." -cmake -DCMAKE_INSTALL_PREFIX=$path \ - -DEXAMPLES_INSTALL_PATH="$path/example" \ - -DBUILD_CVODE=ON \ - -DBUILD_CVODES=OFF \ - -DBUILD_ARKODE=OFF \ - -DBUILD_CVODES=OFF \ - -DBUILD_IDA=OFF \ - -DBUILD_IDAS=OFF \ - -DBUILD_KINSOL=OFF \ - -DOPENMP_ENABLE=OFF \ - ../../sundials-master - -echo "make" -make - -echo "make install" -make install diff --git a/configure b/configure deleted file mode 100755 index 40b1b93..0000000 --- a/configure +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash -path="~/sundials" -installPath="InstallSundials" -echo "Trying to download and install SUNDIALS/CVODE solver for you." -echo "" -#read -p "Where to install?(Default: $path) :" path -#path=${path:-~/sundials} -echo $path - -echo "Installing SUNDIALS to $path" -echo "Installing examples to $path/example" -echo "" - -rm -rf $installPath -#rm -rf sundials-master - -echo wget -c https://github.com/LLNL/sundials/releases/download/v6.0.0/cvode-6.0.0.tar.gz -O cvode.tar.gz -#wget -c https://github.com/LLNL/sundials/releases/download/v6.0.0/cvode-6.0.0.tar.gz -O cvode.tar.gz - -echo tar xvf cvode.tar.gz -tar xvf cvode.tar.gz - - -mkdir $installPath - -echo "cd $installPath" -cd $installPath - -rm -rf builddir - -echo "makedir builddir" -mkdir builddir - -echo "cd builddir" -cd builddir/ - -#ccmake ../../sundials/ -echo "start configure...." -cmake -DCMAKE_INSTALL_PREFIX=$path \ - -DEXAMPLES_INSTALL_PATH="$path/example" \ - -DBUILD_CVODE=ON \ - -DBUILD_CVODES=OFF \ - -DBUILD_ARKODE=OFF \ - -DBUILD_CVODES=OFF \ - -DBUILD_IDA=OFF \ - -DBUILD_IDAS=OFF \ - -DBUILD_KINSOL=OFF \ - -DOPENMP_ENABLE=ON \ - ../../cvode-6.0.0 - -echo "make" -make - -echo "make install" -make install diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..7995c0d --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,25 @@ +cmake_minimum_required(VERSION 3.26) + +aux_source_directory(./classes MAIN_CLASSES) +aux_source_directory(./Equations MAIN_EQUATIONS) +aux_source_directory(./Model MAIN_MODEL) +aux_source_directory(./ModelData MAIN_MODEL_DATA) + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + . + classes + Equations + Model + ModelData +) + + +add_library(${PROJECT_NAME}_lib STATIC ${MAIN_CLASSES} ${MAIN_EQUATIONS} ${MAIN_MODEL} ${MAIN_MODEL_DATA}) +target_link_libraries(${PROJECT_NAME}_lib ${COVDE_LIB} OpenMP::OpenMP_CXX) + +#target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) + + +add_executable(${PROJECT_NAME} main.cpp ) +target_link_libraries(${PROJECT_NAME} ${PROJECT_NAME}_lib) \ No newline at end of file diff --git a/src/classes/River.hpp b/src/classes/River.hpp index 06bdd7f..1d93bf8 100644 --- a/src/classes/River.hpp +++ b/src/classes/River.hpp @@ -6,7 +6,7 @@ #ifndef River_hpp #define River_hpp -#include +#include #include "Macros.hpp" #include "Node.hpp" #include "functions.hpp" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..f7cbe02 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.26) +project(SHUDTest) +add_definitions(-DTestDataPath="${CMAKE_SOURCE_DIR}/") + +find_package(GTest) + + +aux_source_directory(. SRC_LIST) + +add_executable(${PROJECT_NAME} + ${SRC_LIST} +) +target_link_libraries(${PROJECT_NAME} + GTest::gtest + ${COVDE_LIB} + SHUD_lib +) + +add_test(${PROJECT_NAME} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${PROJECT_NAME} -maxwarnings 10000) diff --git a/test/TestCase.cpp b/test/TestCase.cpp new file mode 100644 index 0000000..2bea413 --- /dev/null +++ b/test/TestCase.cpp @@ -0,0 +1,22 @@ +// +// Created by clz on 2024/10/23. +// + +#include "gtest/gtest.h" + +class TestCase : public ::testing::Test { + +protected: + void SetUp() override { + filePath = TestDataPath; + } + void TearDown() override { + } +public: + std::string filePath ; +}; + +TEST_F(TestCase, CCW) { + std::cout<<"ccw case test"<=" : "6.2.0" + }, + { + "name" : "gtest", + "version>=" : "1.14.0#1" + }], + "builtin-baseline" : "c8582b4d83dbd36e1bebc08bf166b5eb807996b0", + "overrides" : [ { + "name" : "sundials", + "version" : "6.2.0#0" + } ] +} diff --git "a/\347\274\226\350\257\221\350\257\264\346\230\216.md" "b/\347\274\226\350\257\221\350\257\264\346\230\216.md" new file mode 100644 index 0000000..06de239 --- /dev/null +++ "b/\347\274\226\350\257\221\350\257\264\346\230\216.md" @@ -0,0 +1,32 @@ +# 编译说明 + +## 编译环境准备 + +### windows +1. 安装Mingw开发环境,推荐使用Msys2,具体参考官网:https://www.msys2.org/ +2. 将Mingw开发环境添加到系统路径,cmd中可以使用gcc命令 +3. 安装CMake构建工具 +4. 安装vcpkg至源代码根路径并运行启动脚本,具体参考vcpkg官网: https://learn.microsoft.com/zh-cn/vcpkg/get_started/get-started?pivots=shell-bash + +### linux +1. 安装GCC开发套件(gcc g++ gdb 等) +2. 安装CMake构建工具 +3. 安装vcpkg至源代码根路径并运行启动脚本,具体参考vcpkg官网: https://learn.microsoft.com/zh-cn/vcpkg/get_started/get-started?pivots=shell-bash + +## 编译步骤 +命令行进入到源代码的根路径 + +### windows +```shell +cmake -DCMAKE_BUILD_TYPE=Release -DVCPKG_TARGET_TRIPLET="x64-mingw-static" -S . -B build -G "Unix Makefiles" +cmake --build build -j 4 +``` +### linux +```shell +cmake -DCMAKE_BUILD_TYPE=Release -S . -B build -G "Unix Makefiles" +cmake --build build -j 4 +``` + +## 编译成果 + +编译形成的可执行文件位于源代码根路径下的 /dist/bin/ 下 \ No newline at end of file