Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2188 commits
Select commit Hold shift + click to select a range
0a61007
removing flux prints
ashleymedin Sep 12, 2025
3a17e46
cleaning globalPrintFlag
ashleymedin Sep 12, 2025
1272cb5
remove commented prints, put some on flags
ashleymedin Sep 12, 2025
2be2719
remove more globalPrint and print stateVars if needed
ashleymedin Sep 12, 2025
05fb212
just spaces
ashleymedin Sep 12, 2025
dc3e2fe
fixing for compilation
ashleymedin Sep 12, 2025
4361ab1
Update to intent attribute of out_SS4HG object in checkConv -- fixes …
seantrim Sep 12, 2025
1f88c0a
Merge pull request #67 from seantrim/checkConv_updates
ashleymedin Sep 12, 2025
1b12a62
Merge branch 'remove_numJacHomegrown' into develop
ashleymedin Sep 12, 2025
0c37f96
clean up of coupled_em
ashleymedin Sep 12, 2025
b33e6a6
Made eval8summa_wrapper a module subroutine
seantrim Sep 13, 2025
d6066d9
Made eval8summa_wrapper a module procedure in summaSolve4homegrown
seantrim Sep 13, 2025
d5723d2
Cleanup for eval8summa_wrapper in summaSolve4homegrown
seantrim Sep 13, 2025
d87fb2f
Minor cleanup for eval8summa_wrapper in summaSolve4homegrown
seantrim Sep 13, 2025
d2ff775
Made getBrackets a module subroutine in summaSolve4homegrown
seantrim Sep 13, 2025
a38d3c2
still fixing derivatives for pass through dense snow
ashleymedin Sep 16, 2025
58f0dc3
merging band and not band
ashleymedin Sep 16, 2025
816f919
fix enthalpy Jac merge
ashleymedin Sep 16, 2025
42b45cc
comments
ashleymedin Sep 16, 2025
9671089
comment
ashleymedin Sep 16, 2025
94cf863
combine flux part of jacobian
ashleymedin Sep 17, 2025
8683822
a little cleanup
ashleymedin Sep 17, 2025
21c3ccf
Merge pull request #68 from seantrim/summaSolve4homegrown_updates
ashleymedin Sep 17, 2025
735728c
fixes
ashleymedin Sep 18, 2025
a1c7d6b
Transformed safeRootfinder from an internal procedure to a module pro…
seantrim Sep 18, 2025
742c40e
a few typos
ashleymedin Sep 18, 2025
946b81e
Merge branch 'develop' of https://github.com/ashleymedin/summa into s…
seantrim Sep 19, 2025
f9d7142
Transform trustRegionRefinement into a module subroutine for external…
seantrim Sep 19, 2025
d015cc1
Cleanup of comments for argument list and declarations within summaSo…
seantrim Sep 19, 2025
c54f231
Reordered summaSolve4homegrown_module module procedures from high to …
seantrim Sep 19, 2025
113650d
Transform lineSearchRefinement into a module subroutine for external …
seantrim Sep 19, 2025
0c40f6c
Transform refine_Newton_step into a module subroutine for external ac…
seantrim Sep 19, 2025
de9ae6f
Merge pull request #69 from seantrim/summaSolve4homegrown_updates
ashleymedin Sep 19, 2025
ea18862
fixing band
ashleymedin Sep 20, 2025
e0fa5b2
fix band
ashleymedin Sep 20, 2025
13c72cd
fix git ignore
ashleymedin Sep 20, 2025
787ba8c
cleaning up
ashleymedin Sep 20, 2025
68eb315
Merge branch 'develop' into simplifyJac
ashleymedin Sep 20, 2025
e5f45e0
spaces
ashleymedin Sep 20, 2025
83d6dea
fixing loops
ashleymedin Sep 20, 2025
d08b1d0
fix jac
ashleymedin Sep 20, 2025
bfbc96f
Correction to error control from refine_Newton_step.
seantrim Sep 20, 2025
5898fd2
fixing Jacobian
ashleymedin Sep 20, 2025
2ffcc9b
Merge pull request #70 from seantrim/summaSolve4homegrown_updates
ashleymedin Sep 20, 2025
21a7cf0
Merge branch 'develop' into simplifyJac
ashleymedin Sep 20, 2025
9d173fc
more cleanup
ashleymedin Sep 23, 2025
2b036df
fixing typos
ashleymedin Sep 23, 2025
c5dd721
fixing Jac for dense snow
ashleymedin Sep 23, 2025
57f1fbe
just comments
ashleymedin Sep 25, 2025
ef22af4
warning for vGn_n<=1
ashleymedin Sep 25, 2025
9bc8d27
more param check
ashleymedin Sep 25, 2025
d5a4308
clarify
ashleymedin Sep 25, 2025
e298ce3
Merge branch 'develop' of https://github.com/ashleymedin/summa into d…
ashleymedin Sep 25, 2025
7bc31b7
Merge pull request #601 from ashleymedin/develop
wknoben Sep 25, 2025
208fc6b
just space cleanup, no code changes
ashleymedin Sep 25, 2025
2e79d10
fixing infiltration derivs
ashleymedin Sep 26, 2025
31f6aa5
only use surface infiltration derivatives if updated
ashleymedin Sep 26, 2025
a56bb58
fixing infiltration derivatives
ashleymedin Sep 26, 2025
131e466
Merge pull request #608 from ashleymedin/develop
wknoben Sep 26, 2025
c730ef5
adjusting test case to routing one
ashleymedin Oct 27, 2025
4273b3f
missed comma
ashleymedin Oct 27, 2025
2860e1f
typos
ashleymedin Oct 27, 2025
7b80a81
modifying test case
ashleymedin Oct 27, 2025
c6b44fc
updated readthedocs build files
wknoben Oct 30, 2025
788857c
moved guidelines for adding modular components to dedicated page
wknoben Oct 30, 2025
54062ee
added laugh test paper to references
wknoben Oct 30, 2025
5e0b601
fixed typo and minor change to mkdocs.yml text
wknoben Oct 30, 2025
6839aa6
typo in page config
wknoben Oct 30, 2025
8715a5d
new extentsion to ensure code block rendering works in dev docs
wknoben Oct 30, 2025
d6a84a2
added missing bracket
wknoben Oct 30, 2025
5209275
brought changes docs in line with current practice on main branch
wknoben Oct 30, 2025
d4d044b
moved assets/img folder over from main
wknoben Oct 30, 2025
c29f4ad
added new infiltration and saturation excess to model decisions
wknoben Oct 30, 2025
d1a492c
removed greenampt from surface excess list (shouldn't be there)
wknoben Oct 30, 2025
b24dfd3
merged updates from main with those from dev_sd
wknoben Oct 30, 2025
fc69a63
moved install docs over from main
wknoben Oct 30, 2025
67394af
moved references to top-level navigation item
wknoben Oct 30, 2025
8fdecf3
updating test case
ashleymedin Oct 30, 2025
4c1e080
fixing soil input for non Rosetta
ashleymedin Oct 30, 2025
81cfc7c
add_files forcing
ashleymedin Oct 30, 2025
5b84bef
added note about forcing files and NaN
wknoben Oct 30, 2025
d145d61
updated test case text to point to hydroshare
wknoben Oct 30, 2025
9128232
removing output
ashleymedin Oct 30, 2025
69326f2
shortened dependency list, put longer text at bottom of page
wknoben Oct 30, 2025
ccd9dc7
removed ATLAS from dependency list
wknoben Oct 30, 2025
4633d13
added sundials install instructions
wknoben Oct 30, 2025
8673fb0
moved makefile instructions to bottom of install page
wknoben Oct 30, 2025
2955b6a
moved contribution guidelines out of install instructions into develo…
wknoben Oct 30, 2025
ee7a74d
updated CMake instructions
wknoben Oct 30, 2025
91a33e9
Merge pull request #612 from CH-Earth/v4_docs_update
wknoben Oct 30, 2025
e375151
add build requirements for readthedocs build
wknoben Oct 30, 2025
11ea014
Merge pull request #613 from CH-Earth/v4_docs_update
wknoben Oct 30, 2025
e83bde7
Merge remote-tracking branch 'refs/remotes/origin/develop_ngen' into …
ashleymedin Oct 30, 2025
b1f025e
Merge branch 'develop_sundials' into develop_ngen
ashleymedin Oct 30, 2025
8349f33
git
ashleymedin Oct 31, 2025
c206e9a
keep directory for test
ashleymedin Oct 31, 2025
a6f2eed
have to run all hrus at same time
ashleymedin Oct 31, 2025
856ddda
test
ashleymedin Oct 31, 2025
1715249
prints, remove
ashleymedin Oct 31, 2025
1854eba
cat
ashleymedin Oct 31, 2025
30782c2
prints, remove
ashleymedin Oct 31, 2025
674bbfa
Merge branch 'develop_ngen' of https://github.com/ashleymedin/summa i…
ashleymedin Oct 31, 2025
c533464
typos
ashleymedin Oct 31, 2025
cec2537
prints remove
ashleymedin Oct 31, 2025
a0c13f5
Merge branch 'develop_ngen' of https://github.com/ashleymedin/summa i…
ashleymedin Oct 31, 2025
40162ba
fixing input output
ashleymedin Oct 31, 2025
f906c8b
back to runGRU mode
ashleymedin Oct 31, 2025
ddbe3fc
only running one hru for some reason
ashleymedin Oct 31, 2025
e182b3c
fixing err
ashleymedin Oct 31, 2025
fbd760f
prints
ashleymedin Oct 31, 2025
08123c2
globals
ashleymedin Oct 31, 2025
b2468d0
works except how writing output files
ashleymedin Nov 3, 2025
84771d1
restart files possible
ashleymedin Nov 3, 2025
12b82ab
spaces
ashleymedin Nov 3, 2025
7ed3a25
Merge branch 'develop_ngen' of https://github.com/ashleymedin/summa i…
ashleymedin Nov 3, 2025
a5aab55
fixing mean stats
ashleymedin Nov 4, 2025
1ef0578
typo
ashleymedin Nov 4, 2025
2799ee0
Merge branch 'develop_ngen' of https://github.com/ashleymedin/summa i…
ashleymedin Nov 4, 2025
746044c
prints remove
ashleymedin Nov 4, 2025
c32e4e9
remove convert files
ashleymedin Nov 4, 2025
fe1169c
updating test
ashleymedin Nov 4, 2025
9513fff
test example
ashleymedin Nov 4, 2025
feb360b
test routing
ashleymedin Nov 5, 2025
6229f00
a few missing typos from merge
ashleymedin Nov 5, 2025
e960622
test call
ashleymedin Nov 5, 2025
e5e3a87
fixing forcing
ashleymedin Nov 5, 2025
63b27b5
new scripts
ashleymedin Nov 10, 2025
007e5d8
fixed ngen test
ashleymedin Nov 11, 2025
beb77fc
fixing ngen build script
ashleymedin Nov 14, 2025
68c1d92
fixing examples
ashleymedin Nov 17, 2025
8bf9339
fix manager
ashleymedin Nov 17, 2025
0860676
sorting test basin
ashleymedin Nov 17, 2025
fc02c0e
file to keep folder
ashleymedin Nov 17, 2025
a6ed3e9
gitignore
ashleymedin Nov 17, 2025
b5573bd
bmi prints
ashleymedin Nov 17, 2025
c50a40a
Merge branch 'develop' of https://github.com/ashleymedin/summa into d…
ashleymedin Nov 17, 2025
f81bed1
updating provo test
ashleymedin Nov 18, 2025
ee62af3
fixing print errors that popped up in gcc15
ashleymedin Nov 29, 2025
ae0b5bc
Merge pull request #615 from ashleymedin/develop
wknoben Nov 29, 2025
895763b
lost from accidental global git ignore
ashleymedin Dec 3, 2025
ba6a0ca
removed extra space and moved FUSE params to more appropriate place
wknoben Dec 3, 2025
f7d48c5
moved FUSE params to more appropriate location
wknoben Dec 3, 2025
2b43ae2
updated docs with instructions on adding variables
wknoben Dec 3, 2025
fe80aa8
fixing rootingDepth bug
ashleymedin Dec 4, 2025
4685e1b
added scalarSaturatedArea variable to io_soilLiqFlx and io_surfaceFlx
wknoben Dec 4, 2025
5cc7d3b
renamed update_surfaceFlx_liquidFlux_computation_wetting_front to _ma…
wknoben Dec 4, 2025
22f330c
re-ordered sat and inf excess calculation to prepare for changes
wknoben Dec 4, 2025
6053adc
removed surfRun_IE decision from soilLiqFlx
wknoben Dec 4, 2025
1b99783
soilLiqFlx WIP - so far still produces expected outcomes
wknoben Dec 8, 2025
b267d7e
soilLiqFlx WIP (4/7 test cases identical)
wknoben Dec 9, 2025
7a09633
split FUSE PRMS into main and derivative function - matches old results
wknoben Dec 14, 2025
92fe4b1
split FUSE AVIC into main and derivative function - matches old
wknoben Dec 14, 2025
71f8768
split FUSE TOPM into main and derivative function - matches old
wknoben Dec 14, 2025
1ae2cb1
moved derivatives out of zero_SE - matches old results
wknoben Dec 14, 2025
95b3227
clarify comment
ashleymedin Dec 15, 2025
100ad34
comment change
ashleymedin Dec 15, 2025
2de4a21
Implemented Ashley's fix to dInfilRate_dWat, dInfilRate_dTk; all test…
wknoben Dec 28, 2025
1b50f54
moved Ashley's changes to comments
wknoben Dec 28, 2025
9ea79e7
propagated Ashley's changes to where FUSE variables are declared (all…
wknoben Dec 28, 2025
72bedfe
moved roundoff error as well
wknoben Dec 28, 2025
8ef5cc3
removed commented derivative code from PRMS, AVIC, TOPM main functions
wknoben Dec 28, 2025
c72f952
propagated ashley's bugfix (all tests still match)
wknoben Dec 28, 2025
0f5ad45
propagated Ashley's change to where FUSE params are (all tests match)
wknoben Dec 28, 2025
6814028
clean up of FUSE derivative functions
wknoben Dec 28, 2025
fa6da27
propagated Ashley's change to move Richards derivatives outside of FU…
wknoben Dec 28, 2025
d29674c
propagated Ashley's typo fixes (tests still match)
wknoben Dec 28, 2025
52c5769
updated some comments and renamed _validate_infiltration to _validate…
wknoben Dec 28, 2025
ae1b58f
Merge pull request #617 from ashleymedin/develop
wknoben Jan 5, 2026
727b1e8
add this to develop, initialization
ashleymedin Jan 6, 2026
538b5c8
not needed in print
ashleymedin Jan 6, 2026
7272ffc
small inconsistencies
ashleymedin Jan 6, 2026
0d121e5
for small bound violations
ashleymedin Jan 6, 2026
1167dfa
started work to split out derivatives (tests all match)
wknoben Jan 8, 2026
b1d6ac2
moved infiltration calculation outside of maxInfRate calculation
wknoben Jan 8, 2026
06a6fe2
moved homegrown derivatives out of big subroutine (all tests match)
wknoben Jan 8, 2026
1455b6c
renamed subroutine that now only calculates infRateMax (all tests mat…
wknoben Jan 8, 2026
e28369e
minor comment/formatting changes
wknoben Jan 8, 2026
1b751b9
further infrastructure re-ordering (all tests match)
wknoben Jan 8, 2026
4630b64
moved zero_IE derives; updated comments
wknoben Jan 9, 2026
3c18655
moved homegrown derivs into main derivs routine (all tests match)
wknoben Jan 9, 2026
443976c
cleaned up comments, no code changes
wknoben Jan 9, 2026
4fb96c2
renamed homegrown_SE derivative function to be more specific (all tes…
wknoben Jan 9, 2026
1a62882
Ashley: updated files with debug prints
wknoben Jan 9, 2026
604679a
Ashley: clean commit (no prints)
wknoben Jan 9, 2026
6645370
Moved things to prepare for FUSE+IE derivatives (all tests match)
wknoben Jan 9, 2026
0f73b89
removed superfluous print statements
wknoben Jan 9, 2026
68a88ef
further comment cleaning
wknoben Jan 9, 2026
ab863ce
fix units on Cm, comments only
ashleymedin Jan 12, 2026
6b749f9
error messages should be longer on ida, kinsol
ashleymedin Jan 13, 2026
99c2cc4
make cmessage longer coming out of run_oneGRU and run_oneHRU
ashleymedin Jan 13, 2026
4673336
typo error
ashleymedin Jan 19, 2026
1021258
fix installation instructions
ashleymedin Jan 20, 2026
385540a
fix installation instructions more
ashleymedin Jan 20, 2026
6ad3236
Merge pull request #616 from wknoben/add-variable-docs
wknoben Jan 22, 2026
698fc1d
fix bug in derivative placement. Also updated in base code, and after…
wknoben Jan 23, 2026
86b1dbe
adding in idaMaxDataWindowSteps parameter
ashleymedin Jan 25, 2026
e019d4f
fixed error message propagation (Ashley's changes)
wknoben Jan 26, 2026
7e9b151
comment clean-up
wknoben Jan 26, 2026
61796b4
Ashley changes 1 (all tests match)
wknoben Jan 26, 2026
27fc14a
Ashley changes 2 (all tests match)
wknoben Jan 26, 2026
0848504
removed SE and IE derivatives (Ashley's changes). Results don't exact…
wknoben Jan 27, 2026
d366b86
Ashley changes 5 (part; added deriv init; 3/7 test cases match)
wknoben Jan 27, 2026
7660b1e
root bouncing fix
ashleymedin Jan 28, 2026
5d0f1fb
integrated Ashley canges to many error messages, AC_max, S2, S2_max
wknoben Jan 28, 2026
18940d4
integrated many cosmetic changes (tests (mis)match as before)
wknoben Jan 28, 2026
e51dfd7
Propagated change to where root layer derivs are calculated (test out…
wknoben Jan 28, 2026
be4c4e3
moved noinf computations into dedicated routine
wknoben Jan 28, 2026
dab8c7a
moved derivatives into FUSE functions (tests now all perfect or withi…
wknoben Jan 28, 2026
211b2d4
minor changes to function names
wknoben Jan 28, 2026
64901af
minor clean up
wknoben Jan 28, 2026
c2efdce
moved SE calculation outside FUSE/homegrown routines (tests still per…
wknoben Jan 28, 2026
56f7122
minor renaming
wknoben Jan 29, 2026
c26eb73
removed variable Ac from routine (test still perfect or within 1E-20)
wknoben Jan 29, 2026
514ba42
moved computation_frozen_area (tests still as before)
wknoben Jan 29, 2026
610bb4c
combined infiltrating_area and validate_inf_area into _homegrown (tes…
wknoben Jan 29, 2026
daa99ab
cleaned some comments and error message
wknoben Jan 29, 2026
2f42abc
removed zero_IE (tests still same)
wknoben Jan 29, 2026
e0136f3
removed duplicate frozen_area calc as well as unneeded inf_update (te…
wknoben Jan 29, 2026
dd725de
removed scalarSatArea from _computation_homegrown (no longer needed, …
wknoben Jan 29, 2026
1f4c73c
updated scalarSoilControl code (tests still same)
wknoben Jan 29, 2026
599c4df
started revamp of infiltration routine - this change introduce what l…
wknoben Jan 29, 2026
ed89dd4
bugfix + code removal (tests still at 1E-19/1E-20)
wknoben Jan 29, 2026
6d76980
moved deriv initialization to init routine
wknoben Jan 30, 2026
c977502
removed update_gather_runoff_components, this also fixes a bug in sca…
wknoben Jan 30, 2026
64f67a0
removed imports
wknoben Jan 30, 2026
16cec65
removed surfRun_IE decision; updated comments
wknoben Jan 30, 2026
f8409d0
removed surfRun_IE decision; updated comment
wknoben Jan 30, 2026
41640a7
removed surfRun_IE; updated comment
wknoben Jan 30, 2026
2f4130e
removed surfRun_IE
wknoben Jan 30, 2026
70f9c1a
propagated Ashley's install instructions
wknoben Jan 30, 2026
e61e5a2
added the correct changed files; removed the incorrect ones
wknoben Jan 30, 2026
9eb1ff8
removed another incorrectly addef ile
wknoben Jan 30, 2026
968f1d3
Merge branch 'develop_sundials' into soilLiqFlx-update
wknoben Feb 2, 2026
03f98c3
Merge pull request #620 from wknoben/soilLiqFlx-update
wknoben Feb 3, 2026
1e80764
add idaDetectEvents as a parameter (default on), and change so idaMax…
ashleymedin Feb 5, 2026
8d96557
Merge commit '03f98c3ac839cc3c9e218d0089f6f59ee1feb65b' into develop
ashleymedin Feb 5, 2026
ef29573
plots
ashleymedin Feb 7, 2026
4bcca66
not needed
ashleymedin Feb 10, 2026
bac6cdf
fixing total soil depth non-compute, bug
ashleymedin Feb 11, 2026
cecb61b
noah mp remove unused
ashleymedin Feb 11, 2026
d5231ff
remove unneeded
ashleymedin Feb 11, 2026
90fae8d
soilUtils clean up
ashleymedin Feb 11, 2026
76fdaa4
space in noah-mp
ashleymedin Feb 11, 2026
cf5ee18
space
ashleymedin Feb 11, 2026
3fe29aa
dInfilRate_d weren't initialized, bug fix
ashleymedin Feb 12, 2026
245e7d8
fixing some conversion errors
ashleymedin Feb 12, 2026
6f76bb1
just spaces
ashleymedin Feb 12, 2026
c0e855c
Victoria's parallel Actors change
ashleymedin Feb 12, 2026
977a506
pass fullMatrix as variable so works in parallel
ashleymedin Feb 12, 2026
a4cced1
Merge pull request #618 from ashleymedin/develop
wknoben Feb 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# summa executable and bin directory
bin
summa.exe
summa_sundials.exe
# temporary files
*~
*.swp
Expand All @@ -27,6 +28,7 @@ summa.exe
*.layout
gmon.out
summa.exe.dSYM*
summa_sundials.exe.dSYM*
summaversion.inc
# makefile
make.out
Expand All @@ -35,3 +37,19 @@ Makefile-*
*.backup
# site directory from mkdocs
site/
# cmake_build containing cmake build objects
build/cmake_build
runinfo.txt
# OpenWQ source code
build/source/openwq/openwq
# pre-processing files
utils/pre-processing/*.nc
# vscode related files
.vscode
# test files
test_ngen/gauge_01073000/simulations/run_1/SUMMA/*.nc
test_ngen/domain_provo/forcing/*.nc
test_ngen/domain_provo/forcing/SUMMA_input/*.nc
test_ngen/domain_provo/simulations/run_1/SUMMA/*.nc
test_ngen/domain_provo/simulations/*.nc
test_ngen/domain_provo/simulations/*.csv
19 changes: 19 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Read the Docs configuration file for MkDocs projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"

mkdocs:
configuration: mkdocs.yml

# Specify the python packages we need to build properly
python:
install:
- requirements: docs/requirements.txt
36 changes: 0 additions & 36 deletions Dockerfile

This file was deleted.

252 changes: 252 additions & 0 deletions build/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
project(summa VERSION 4.0.0 LANGUAGES Fortran C CXX)

if(DEFINED ENV{FC})
set (CMAKE_Fortran_COMPILER $ENV{FC}) #for NextGen need, works for others
else()
set (CMAKE_Fortran_COMPILER gfortran)
endif()

#=========================================================================================
# SUMMA can be compiled with debug flags by specifiying -DCMAKE_BUILD_TYPE=Debug
#
# There are multiple options for building SUMMA, including using the
# Sundials suite of solvers and the NextGen framework.
# The options are set by specifying -DOPTION=ON when running cmake.
# For example to compile SUMMA with Sundials, use
# cmake -B ../cmake_build -S ../. -DUSE_SUNDIALS=ON
# cmake --build ../cmake_build --target all -j
#
# To compile SUMMA with Actors, see the Summa-Actors repo:
# https://github.com/uofs-simlab/Summa-Actors
#=========================================================================================

# Add options for build type
set(CMAKE_CONFIGURATION_TYPES Release Debug)

# Options: Enable each with cmake -DOPTION=ON
option(USE_SUNDIALS "Use IDA solver from SUNDIALS suite" OFF)
option(USE_NEXTGEN "Use NextGen Framework" OFF)
option(USE_OPENWQ "Use OpenWQ Framework" OFF)
set(EXT_TARGETS) # list of external targets to link to

# Set Default Executable Name
set(EXEC_NAME summa.exe)
# Set top-level directory
if (USE_NEXTGEN)
set(F_MASTER "${CMAKE_CURRENT_SOURCE_DIR}/summa")
else()
set(F_MASTER "${CMAKE_CURRENT_SOURCE_DIR}/..")
endif()

set(PARENT_DIR "${F_MASTER}")
set(EXEC_DIR "${F_MASTER}/bin")

# Handle optional external libraries
if (USE_SUNDIALS)
message("ENABLING SUNDIALS")
find_package(SUNDIALS REQUIRED)
list(APPEND EXT_TARGETS SUNDIALS::fida_mod_shared
SUNDIALS::fkinsol_mod_shared)
add_compile_definitions(SUNDIALS_ACTIVE)
set(EXEC_NAME summa_sundials.exe)
endif()

if (USE_NEXTGEN)
message("ENABLING NEXTGEN")
add_compile_definitions(NGEN_ACTIVE BMI_ACTIVE NGEN_FORCING_ACTIVE
NGEN_OUTPUT_ACTIVE)
add_subdirectory(../iso_c_fortran_bmi ${CMAKE_BINARY_DIR}/iso_c_bmi)
list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/summa/build/cmake/")
list(INSERT CMAKE_PREFIX_PATH 0 "${CMAKE_CURRENT_LIST_DIR}/summa/build/cmake/")
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran)
set(SUMMA_LIB_NAME_CMAKE summabmi)
set(SUMMA_LIB_DESC_CMAKE "Summa-Sundials BMI Module Shared Library")
else()
LIST(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/")
LIST(INSERT CMAKE_PREFIX_PATH 0 "${CMAKE_SOURCE_DIR}/cmake/")
endif()

# OpenWQ Framework
if (USE_OPENWQ)
message("ENABLING OPENWQ")
add_compile_definitions(OPENWQ_ACTIVE)
if (USE_SUNDIALS)
set(EXEC_NAME summa_sundials_openwq.exe)
else()
set(EXEC_NAME summa_openwq.exe)
endif()
endif()


get_filename_component(F_MASTER "${F_MASTER}" REALPATH)
get_filename_component(PARENT_DIR "${PARENT_DIR}" REALPATH)
get_filename_component(EXEC_DIR "${EXEC_DIR}" REALPATH)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXEC_DIR})

#=========================================================================================
# SET THE PATHS TO THE LIBRARIES AND INCLUDE FILES
#=========================================================================================

# NetCDF is found with a custom FindNetCDF.cmake file
find_package(NetCDF REQUIRED)
list(APPEND EXT_TARGETS NetCDF::NetCDF)

# Find LAPACK with user-specified links or automatic detection
option(SPECIFY_LAPACK_LINKS "Use specified LAPACK links" OFF)
if(SPECIFY_LAPACK_LINKS)
message("Using LAPACK links from LIBRARY_LINKS environment variable")
if(DEFINED ENV{LIBRARY_LINKS})
set(LIBRARY_LINKS $ENV{LIBRARY_LINKS})
else()
message(FATAL_ERROR "LIBRARY_LINKS environment variable not found. Set this variable or try -DSPECIFY_LAPACK_LINKS=OFF in build file.")
endif()
else()
message("Automatically detect LAPACK links")
set(LIBRARY_LINKS "")

# OpenBLAS
set(BLA_VENDOR OpenBLAS)
find_package(OpenBLAS REQUIRED COMPONENTS serial)
list(APPEND EXT_TARGETS OpenBLAS::OpenBLAS)
endif()

# Set compiler flags
set(FLAGS_OPT $ENV{FLAGS_OPT}) # get optional user-specified flags from environment variables
if(CMAKE_BUILD_TYPE MATCHES Debug)
message("\nSetting SUMMA Debug Options")
add_compile_definitions(DEBUG)
# Notes: - optimization -Og is selected here to maximize information displayed in debugging software (e.g., gdb)
# - however, it may be useful to vary the optimization level to test for optimization related issues
set(FLAGS_NOAH -g -Og -fbacktrace -Wall -fcheck=all,no-array-temps -Wfatal-errors -ffree-line-length-none -fPIC -ffree-form ${FLAGS_OPT})
set(FLAGS_ALL -g -Og -fbacktrace -Wall -fcheck=all,no-array-temps -Wfatal-errors -ffree-line-length-none -fPIC -cpp -frecursive ${FLAGS_OPT})
set(FLAGS_CXX -g -Og -fbacktrace -Wall -fcheck=all,no-array-temps -Wfatal-errors -std=c++17 ${FLAGS_OPT})
else()
message("\nSetting SUMMA Release Options")
if (CMAKE_Fortran_COMPILER MATCHES gfortran)
set(FLAGS_NOAH -O3 -Wfatal-errors -ffree-line-length-none -fPIC -ffree-form ${FLAGS_OPT})
set(FLAGS_ALL -O3 -Wfatal-errors -ffree-line-length-none -fPIC -cpp -frecursive ${FLAGS_OPT})
set(FLAGS_CXX -O3 -Wfatal-errors -std=c++17 ${FLAGS_OPT})
else(CMAKE_Fortran_COMPILER MATCHES ifx) # ifx does not currently compile SUMMA -- derived type modifications needed in source code
set(FLAGS_NOAH -O3 -heap-arrays -fPIC -free ${FLAGS_OPT})
set(FLAGS_ALL -O3 -heap-arrays -fPIC -cxxlib ${FLAGS_OPT})
set(FLAGS_CXX -O3 -std=c++17 ${FLAGS_OPT})
endif()
endif()

#=========================================================================================
# COMPILE PART 1: Define directory paths
#=========================================================================================

# Define directories that contains source code
set(DRIVER_DIR ${F_MASTER}/build/source/driver)
set(DSHARE_DIR ${F_MASTER}/build/source/dshare)
set(ENGINE_DIR ${F_MASTER}/build/source/engine)
set(HOOKUP_DIR ${F_MASTER}/build/source/hookup)
set(NETCDF_DIR ${F_MASTER}/build/source/netcdf)
set(NOAHMP_DIR ${F_MASTER}/build/source/noah-mp)

#=========================================================================================
# COMPILE PART 2: Assemble all of the SUMMA sub-routines
#=========================================================================================

# SUMMA Source Files are defined in the CMakeLists.txt file in the subdirectory
add_subdirectory(${F_MASTER}/build/source/)


#=========================================================================================
# COMPILE PART 3: Collect the subroutines into build groups depending on build type
#=========================================================================================

set(COMM_ALL ${NRPROC} ${HOOKUP} ${DATAMS} ${UTILMS})
set(SUMMA_ALL ${NETCDF} ${PRELIM} ${MODRUN} ${SOLVER} ${DRIVER})
set(MAIN_SUMMA ${DRIVER_DIR}/summa_driver.f90)

if (USE_NEXTGEN)
set(SUMMA_ALL ${SUMMA_ALL} ${DRIVER_NEXTGEN})
endif()

if (USE_SUNDIALS)
set(COMM_ALL ${COMM_ALL} ${DATAMS_SUNDIALS} ${UTILMS_SUNDIALS})
set(SUMMA_ALL ${SUMMA_ALL} ${MODRUN_SUNDIALS} ${SOLVER_SUNDIALS})
endif()

if (USE_OPENWQ)
add_subdirectory(${F_MASTER}/build/source/openwq)
if (DEFINED OPENWQ_ERROR)
message(FATAL_ERROR "OpenWQ build failed")
endif()
set(SUMMA_ALL ${SUMMA_ALL} ${OPENWQ_COUPLER})
list(APPEND EXT_TARGETS openWQ)
endif ()


# Define version number
set(VERSIONFILE ${DRIVER_DIR}/summaversion.inc)
execute_process(
COMMAND bash -c "git tag | tail -n 1"
OUTPUT_VARIABLE VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND date
OUTPUT_VARIABLE BUILDTIM
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND bash -c "git describe --long --all --always | sed 's#heads/##'"
OUTPUT_VARIABLE GITBRCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND git rev-parse HEAD
OUTPUT_VARIABLE GITHASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)

#=========================================================================================
# COMPILE PART 4: Do the compilation
#=========================================================================================

# update version information
file(WRITE ${VERSIONFILE} "character(len=64), parameter :: summaVersion = '${VERSION}'\n")
file(APPEND ${VERSIONFILE} "character(len=64), parameter :: buildTime = '${BUILDTIM}'\n")
file(APPEND ${VERSIONFILE} "character(len=64), parameter :: gitBranch = '${GITBRCH}'\n")
file(APPEND ${VERSIONFILE} "character(len=64), parameter :: gitHash = '${GITHASH}'")

# Build SUMMA_NOAHMP Object
add_library(SUMMA_NOAHMP OBJECT ${NOAHMP} ${NRUTIL})
target_compile_options(SUMMA_NOAHMP PRIVATE ${FLAGS_NOAH})

# Build SUMMA_COMM Object
add_library(SUMMA_COMM OBJECT ${COMM_ALL})
target_compile_options(SUMMA_COMM PRIVATE ${FLAGS_ALL})
target_link_libraries(SUMMA_COMM PUBLIC SUMMA_NOAHMP ${EXT_TARGETS} ${LIBRARY_LINKS})

# For NextGen, build SUMMA Shared Library and add the outside BMI libraries
if(USE_NEXTGEN)
if(WIN32)
add_library(summabmi ${SUMMA_ALL})
else()
add_library(summabmi SHARED ${SUMMA_ALL})
endif()
target_compile_options(summabmi PRIVATE ${FLAGS_ALL})
target_link_libraries(summabmi PUBLIC ${EXT_TARGETS} iso_c_bmi SUMMA_NOAHMP SUMMA_COMM)

set_target_properties(summabmi PROPERTIES VERSION ${PROJECT_VERSION})
include(GNUInstallDirs)

install(TARGETS summabmi
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
configure_file(summabmi.pc.in summabmi.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/summabmi.pc DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig)
else()
add_library(summa SHARED ${SUMMA_ALL})
target_compile_options(summa PRIVATE ${FLAGS_ALL})
target_link_libraries(summa PUBLIC ${EXT_TARGETS} SUMMA_NOAHMP SUMMA_COMM ${LIBRARY_LINKS})
add_executable(${EXEC_NAME} ${MAIN_SUMMA})
target_compile_options(${EXEC_NAME} PRIVATE ${FLAGS_ALL})
set_property(TARGET ${EXEC_NAME} PROPERTY LINKER_LANGUAGE Fortran)
target_link_libraries(${EXEC_NAME} summa ${EXT_TARGETS} ${LIBRARY_LINKS})
endif()
Loading