Skip to content

Commit

Permalink
pseudo_framework_cfe (#14)
Browse files Browse the repository at this point in the history
* added pseudo-framework example for coupling with CFE, removed the standalone example.

* updated readme and install instructions.

* added realization file for cfe, and updated CI workflow.

* set soil_storage to non-zero in the unittest, 0 triggers assertion.

* a minor change

* removed the extra dash '-' from '--DCFE'

* modified CI .ymal file to have unique submod IDs.

* removed a comma.

* minor changes to CI yaml file to build CFE.

* Update INSTALL.md

* Update INSTALL.md

---------

Co-authored-by: Rachel McDaniel <61248457+rlmcdaniel@users.noreply.github.com>
  • Loading branch information
ajkhattak and rlmcdaniel authored May 9, 2024
1 parent 9bf77fc commit 8ae1d74
Show file tree
Hide file tree
Showing 15 changed files with 675 additions and 595 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/build_and_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
steps:
- name: Checkout the commit
uses: actions/checkout@v4

# - name: check gcc version
# run: gcc --version

Expand All @@ -45,13 +45,17 @@ jobs:
fi
sed -i 's/\${CXX}/g++/' run_unittest.sh
./run_unittest.sh
- name: Build and Run Standalone
- name: Build and Run CFE
run: |
git clone https://github.com/NOAA-OWP/cfe extern/cfe
if [ -d build ]; then
rm -rf build
fi
mkdir build && cd build
cmake ../ -DSTANDALONE=ON
cmake ../ -DCFE=ON
make && cd ..
./run_smp.sh STANDALONE
./run_smp.sh CFE
- name: Build and Run with Topmodel
run: |
Expand All @@ -60,6 +64,6 @@ jobs:
rm -rf build
fi
mkdir build && cd build
cmake ../ -DWITHTOPMODEL=ON
cmake ../ -DTOPMODEL=ON
make && cd ..
./run_smp.sh WITHTOPMODEL
./run_smp.sh TOPMODEL
18 changes: 14 additions & 4 deletions .github/workflows/ngen_integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,32 @@ jobs:
with:
repository: noaa-owp/ngen

- name: Build CFE
uses: actions/checkout@v4
with:
repository: noaa-owp/cfe

- name: Build CFE Library
run: |
cmake -B cmake_build -S . -DNGEN=ON
make -C cmake_build

- name: Build Topmodel
id: submod_build_4
id: submod_build_2
uses: ./.github/actions/ngen-submod-build
with:
mod-dir: "extern/topmodel/"
targets: "topmodelbmi"

- name: Build PET
id: submod_build_5
id: submod_build_3
uses: ./.github/actions/ngen-submod-build
with:
mod-dir: "extern/evapotranspiration/evapotranspiration"
targets: "petbmi"

- name: Build SLoTH
id: submod_build_6
id: submod_build_4
uses: ./.github/actions/ngen-submod-build
with:
mod-dir: "extern/sloth/"
Expand All @@ -91,7 +101,7 @@ jobs:
- name: Run Ngen Test for SMP
run: |
mv ${{ steps.ngen_id1.outputs.build-dir }} ./ngen-build/
inputfile='extern/SoilMoistureProfiles/SoilMoistureProfiles/realizations/realization_config_smp.json'
inputfile='extern/SoilMoistureProfiles/SoilMoistureProfiles/realizations/realization_config_smp_cfe.json'
./ngen-build/ngen ./data/catchment_data.geojson "cat-27" ./data/nexus_data.geojson "nex-26" $inputfile

- name: Run Ngen Test with Topmodel
Expand Down
38 changes: 19 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,23 @@ set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_COMPILER $ENV{CC})
set(CMAKE_CXX_COMPILER $ENV{CXX})

set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")

project(smpbmi VERSION 1.0.0 DESCRIPTION "OWP SMP BMI Module Shared Library")

option(NGEN "NGEN" OFF)
option(STANDALONE "STANDALONE" OFF)
option(WITHTOPMODEL "WITHTOPMODEL" OFF)
option(CFE "CFE" OFF)
option(TOPMODEL "TOPMODEL" OFF)

if(NGEN)
add_definitions(-DNGEN)
endif()

if(STANDALONE)
message("${Red} Standalone Soil moisture profile (using conceptual/layered reservoir)! ${ColourReset}")
set(exe_name "smp_standalone")
elseif(WITHTOPMODEL)
if(CFE)
message("${Red} Soil moisture profile for CFE! ${ColourReset}")
set(exe_name "smp_cfe")
elseif(TOPMODEL)
message("${Red} Soil moisture profile for topmodel (watertable-based)! ${ColourReset}")
set(exe_name "smp_topmodel")
endif()
Expand All @@ -43,19 +40,22 @@ set(SMP_LIB_DESC_CMAKE "OWP SMP BMI Module Shared Library")
add_compile_definitions(BMI_ACTIVE)

# add the executable
if(STANDALONE)
add_executable(${exe_name} ./src/main_soil_moisture.cxx ./src/bmi_soil_moisture_profile.cxx src/soil_moisture_profile.cxx)
elseif(WITHTOPMODEL)
add_executable(${exe_name} ./src/main_smp_topmodel.cxx ./extern/topmodel/src/topmodel.c ./extern/topmodel/src/bmi_topmodel.c)

add_library(smplib ./src/bmi_soil_moisture_profile.cxx ./src/soil_moisture_profile.cxx ./include/bmi_soil_moisture_profile.hxx ./include/soil_moisture_profile.hxx)
target_link_libraries(${exe_name} LINK_PUBLIC smplib)
target_include_directories(${exe_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/extern/)
if(CFE)
add_executable(${exe_name} ./src/main_smp_cfe.cxx ./extern/cfe/src/cfe.c ./extern/cfe/src/bmi_cfe.c
./extern/cfe/src/giuh.c ./extern/cfe/src/conceptual_reservoir.c ./extern/cfe/src/nash_cascade.c)
target_include_directories(${exe_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/extern/cfe/include)
elseif(TOPMODEL)
add_executable(${exe_name} ./src/main_smp_topmodel.cxx ./extern/topmodel/src/topmodel.c ./extern/topmodel/src/bmi_topmodel.c)
target_include_directories(${exe_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/extern/topmodel/include)
endif()


if(WITHTOPMODEL OR STANDALONE)
target_link_libraries(${exe_name} PRIVATE m)
if(TOPMODEL OR CFE)
add_library(smplib ./src/bmi_soil_moisture_profile.cxx ./src/soil_moisture_profile.cxx ./include/bmi_soil_moisture_profile.hxx
./include/soil_moisture_profile.hxx)
target_link_libraries(${exe_name} LINK_PUBLIC smplib)
target_include_directories(${exe_name} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_link_libraries(${exe_name} PRIVATE m)
endif()


Expand Down
29 changes: 15 additions & 14 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
# Installation instructions
Detailed instructions on how to build and run SoilMoistureProfiles for different setups/modes (standalone, with topmodel, and nextgen framework) are provided below. The schemes assume you have [GCC](https://gcc.gnu.org) and [CMAKE](https://cmake.org/) on your machine. These are simple examples providing a one-way coupling (model --> SoilMoistureProfiles) and are only for demonstration purposes. However, in real examples when coupled to other models, the soil moisture profiles effect freeze-thaw and other hydrological processes (such as infiltration).
Detailed instructions on how to build and run SoilMoistureProfiles for different setups/modes (pseudo framework with a conceptual soil reservoir, pseudo framework with soil moisture deficit, and nextgen framework) are provided below. The schemes assume you have [GCC](https://gcc.gnu.org) and [CMAKE](https://cmake.org/) on your machine. These are simple examples providing a one-way coupling (model --> SoilMoistureProfiles) and are only for demonstration purposes. However, in real examples when coupled to other models, the soil moisture profiles effect freeze-thaw and other hydrological processes (such as infiltration).

**Note**: Before running the following examples, it is recommended to run the unittests [tests](https://github.com/NOAA-OWP/SoilMoistureProfiles/tree/ajk/doc_update/tests).

## Standalone example
The example runs SMP for a hypothetical conceptual soil reservoir (with prescribed soil_storage and soil_storage_change SMP BMI input variables) to compute `watertable` and `soil_moisture_profile` and compare the results against benchmark results. The hypothetical conceptual soil reservoir mimics CFE.
## Pseudo framework example (CFE)
This example couples SMP to the [Conceptual Functional Equivalent (CFE)](https://github.com/NOAA-OWP/cfe) model which uses a conceptual soil reservoir. SMP is used to compute `watertable` and `soil_moisture_profile`.
### Build
```
git clone https://github.com/NOAA-OWP/SoilMoistureProfiles && cd SoilMoistureProfiles
git clone https://github.com/NOAA-OWP/cfe extern/cfe
mkdir build && cd build
cmake ../ -DSTANDALONE=ON
cmake ../ -DCFE=ON
make && cd ..
```

### Run
<pre>
Run: <a href="https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/run_sft.sh">./run_smp.sh</a> STANDALONE (from SoilMoistureProfiles directory)
Run: <a href="https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/run_sft.sh">./run_smp.sh</a> CFE (from SoilMoistureProfiles directory)
</pre>

## Pseudo framework example
An example coupling TopModel to SMP to compute `watertable` and `soil_moisture_profile` from soil moisture deficit.
## Pseudo framework example (TopModel)
This example couples [TopModel](https://github.com/NOAA-OWP/topmodel), which tracks soil moisture deficit, to SMP. SMP is used to compute `watertable` and the `soil_moisture_profile` from the soil moisture deficit.
### Build
```
git clone https://github.com/NOAA-OWP/SoilMoistureProfiles && cd SoilMoistureProfiles
git clone https://github.com/NOAA-OWP/SoilMoistureProfiles && cd SoilMoistureProfiles
git clone https://github.com/NOAA-OWP/topmodel extern/topmodel
mkdir build && cd build
cmake ../ -DWITHTOPMODEL=ON
cmake ../ -DTOPMODEL=ON
make && cd ..
```
### Run
<pre>
Run: <a href="https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/run_sft.sh"> ./run_smp.sh</a> WITHTOPMODEL (from SoilMoistureProfiles directory)
Run: <a href="https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/run_sft.sh"> ./run_smp.sh</a> TOPMODEL (from SoilMoistureProfiles directory)
</pre>

## Nextgen framework example
Detailed instructions for running and building SoilMoistureProfiles coupled to other models (for instance, CFE or SFT) in the nextgen framework are provided at [instructions](https://github.com/NOAA-OWP/SoilFreezeThaw/blob/master/INSTALL.md).
The [nextgen framework](https://github.com/NOAA-OWP/ngen) allows the user to easily couple different BMI enabled models, including SMP. Detailed instructions for running and building SoilMoistureProfiles coupled to other models (for instance, CFE or [SoilFreezeThaw](https://github.com/NOAA-OWP/SoilFreezeThaw)) in the nextgen framework are provided at [instructions](https://github.com/NOAA-OWP/SoilFreezeThaw/blob/master/INSTALL.md). Once nextgen is built, refer to the commands below to run the SMP examples in nextgen.
### Build
```
mkdir smp && cd smp (in the nextgen directory)
Expand All @@ -44,12 +45,12 @@ ln -s extern/SoilMoistureProfiles/SoilMoistureProfiles/realizations
cp extern/topmodel/topmodel/data/* data
```
### Run
- Standalone example
- SMP with CFE example
```
../cmake_build/ngen data/catchment_data.geojson cat-27 data/nexus_data.geojson nex-26 realizations/realization_config_smp.json
```
- With Topmodel example
- SMP with Topmodel example
```
cp ./extern/topmodel/topmodel/data/* data
../cmake_build/ngen data/catchment_data.geojson cat-27 data/nexus_data.geojson nex-26 realizations/realization_config_smp_topmodel.json
```
```
38 changes: 16 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,40 @@
# SoilMoistureProfiles
The soil moisture profiles schemes provide soil moisture distributed over a one-dimensional vertical column. These schemes facilitate coupling among different models such as (CFE and SFT or LASAM and SFT). The following three schemes are provided here to compute vertical soil moisture profiles.
* Scheme for conceptual soil reservoirs (e.g., **[CFE](https://github.com/NOAA-OWP/cfe))**
The soil moisture profiles schemes provide soil moisture distributed over a one-dimensional vertical column and depth to water table. These schemes facilitate coupling among hydrological and thermal models such as (CFE and SFT or LASAM and SFT). It can also be coupled with conceptual hydrologic models to compute rootzone-based actual evapotranspiration. The following three schemes are provided here to compute vertical soil moisture profiles and water table depth.
* Scheme for conceptual soil reservoirs (e.g., **[CFE](https://github.com/NOAA-OWP/cfe))**
* Schemes for layered soil reservoirs (e.g., **[LGAR](https://github.com/NOAA-OWP/LGAR-C))**
* Schemes for topmodel (details are provided below; **[TopModel](https://github.com/NOAA-OWP/topmodel))**

## Conceptual soil reservoir
For conceptual reservoirs, see the following schematic and algorithm. We use the Clap-Hornberger soil moisture characteristic function here, and **soil moisture storage** is the main input passed through a BMI.
For conceptual reservoirs, see the following schematic and algorithm. We use the Clap-Hornberger soil moisture characteristic function here, and **soil_storage** and **soil_storage_chage** are the two inputs passed through BMI.

![smp_schematic](https://user-images.githubusercontent.com/15165757/164322224-479477d7-2275-4ce3-a00b-9270cc0d3201.png)

## Layered soil reservoir
For layered soil reservoirs, the two options include
For layered soil reservoirs, the two options include
* constant by layer, and Clap-Horngerger soil moisture characteristic function for the profile below the depth of the last layer
* linearly interpolated profile between consecutive layers, and Clap-Horngerger soil moisture characteristic function for the profile below the depth of the last layer

## Topmodel based soil reservoir
* (flux-based method) A method using an iterative scheme to first compute watertable depth and then soil moisture profile ([Blazkova et al. (2002)](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2001WR000912))
* (deficit-based method) A method using catchment deficit to first compute watertable depth and then soil moisture profile ([Franchini et al. (1996)](https://www.sciencedirect.com/science/article/abs/pii/S0022169496800151)


## Build and Run Instructions
Detailed instructions on how to build and run SoilMoistureProfiels (SMP) can be found here [INSTALL](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/INSTALL.md).
Detailed instructions on how to build and run SoilMoistureProfiels (SMP) can be found here [INSTALL](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/main/INSTALL.md).
- Test examples highlights
- Unittest: (see [tests](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/tests/README.md))
- Standalone: An example computing `watertable` and `soil_moisture_profile` using a soil conceptual reservoir (see [build/run](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/INSTALL.md#standalone-example))
- With topmodel: An example coupling TopModel to SMP (Soil Moisture Profiles) to compute `watertable` and `soil_moisture_profile` (see [build/run](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/INSTALL.md#pseudo-framework-example))
- Nextgen examples: Realization files for the two above examples (Standalone and with topmodel) are provided [here](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/realizations) (see [build/run](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/INSTALL.md#nextgen-framework-example)).
- Unittest: (see [tests](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/main/tests/README.md))
- With CFE: An example coupling CFE with SMP (Soil Moisture Profiles) to compute `watertable` and `soil_moisture_profile` (see [build/run](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/main/INSTALL.mdd#pseudo-framework-example-1))
- With topmodel: An example coupling TopModel to SMP (Soil Moisture Profiles) to compute `watertable` and `soil_moisture_profile` (see [build/run](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/main/INSTALL.md#pseudo-framework-example-2))
- Nextgen examples: Realization files for the two above examples (Standalone and with topmodel) are provided [here](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/main/realizations) (see [build/run](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/main/INSTALL.md#nextgen-framework-example)).

## Model Configuration File
Detailed description of the parameters for model configuration is provided ([here](https://github.com/NOAA-OWP/SoilMoistureProfiles/tree/ajk/doc_update/configs/README.md))
Detailed description of the parameters for model configuration is provided ([here](https://github.com/NOAA-OWP/SoilMoistureProfiles/tree/main/configs/README.md))

## Getting help
For questions, please contact Ahmad Jan (ahmad.jan(at)noaa.gov), the main developer/maintainer of the repository.

## Known issues or raise an issue
We are constantly looking to improve the model and/or fix bugs as they arise. Please see the Git Issues for known issues or if you want to suggest adding a capability or to report a bug, please open an issue.

## Getting involved
See general instructions to contribute to the model development ([instructions](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/ajk/doc_update/CONTRIBUTING.md)) or simply fork the repository and submit a pull request.






See general instructions to contribute to the model development ([instructions](https://github.com/NOAA-OWP/SoilMoistureProfiles/blob/main/CONTRIBUTING.md)) or simply fork the repository and submit a pull request.
32 changes: 32 additions & 0 deletions configs/config_cfe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
forcing_file=./extern/cfe/forcings/cat87_01Dec2015.csv
soil_params.depth=2.0[m]
soil_params.b=4.05[]
soil_params.satdk=0.00000338[m s-1]
soil_params.satpsi=0.355[m]
soil_params.slop=0.01[m/m]
soil_params.smcmax=0.439[m/m]
soil_params.wltsmc=0.066[m/m]
soil_params.expon=1.0[]
soil_params.expon_secondary=1.0[]
max_gw_storage=0.25[m]
Cgw=1.8e-05[m h-1]
expon=6.0[]
gw_storage=0.125[m/m]
alpha_fc=0.33[]
soil_storage=0.585626[m/m]
K_nash=0.03[]
K_lf=0.01[]
nash_storage=0.0,0.0
giuh_ordinates=0.06,0.51,0.28,0.12,0.03
num_timesteps=1
verbosity=1
surface_runoff_scheme=GIUH
surface_partitioning_scheme=Xinanjiang
a_Xinanjiang_inflection_point_parameter=1
b_Xinanjiang_shape_parameter=1
x_Xinanjiang_shape_parameter=1
urban_decimal_fraction=0.0
DEBUG=0
#surface_partitioning_scheme=Schaake
#ice_fraction=0
#ice_content_threshold=0.15
73 changes: 0 additions & 73 deletions realizations/realization_config_smp.json

This file was deleted.

Loading

0 comments on commit 8ae1d74

Please sign in to comment.