Skip to content

Commit e9fc8ef

Browse files
authored
Merge branch 'main' into multiplatform-builds
2 parents 861aa1d + f1ced19 commit e9fc8ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1314
-906
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repos:
2626
# - id: include-what-you-use
2727

2828
- repo: https://github.com/python-jsonschema/check-jsonschema
29-
rev: 0.29.3
29+
rev: 0.30.0
3030
hooks:
3131
- id: check-github-workflows
3232
- repo: meta

CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
cmake_minimum_required(VERSION 3.20)
22
# made with help from Zhu Liang-Jun of IGSNRR in Beijing
33
# modified for GitHub by Trevor James Smith of Ouranos in Montreal
4+
# modified for lpsolve support by Maxim Krassovski of DFO
45

56
# optional cmake command line arguments (e.g, "cmake -D COMPILE_LIB=ON" .)
67
option(COMPILE_LIB "If ON, will create a dynamic lib file (default: OFF)" OFF)
78
option(COMPILE_EXE "If ON, will create a executable file (default: ON)" ON)
89
option(PYTHON, "If ON, will create a share library for python (default: OFF)" OFF)
10+
option(LPSOLVE,"If ON, will link to lp_solve optimization library (default: OFF)" OFF)
911

1012
# Setup Project
1113
PROJECT(Raven CXX)
@@ -14,15 +16,16 @@ PROJECT(Raven CXX)
1416
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
1517

1618
# Find NetCDF
17-
find_package(NetCDF)
19+
find_package(NetCDF) #may also be 'netCDF'
20+
find_package(netCDF)
1821

1922
# find header & source
2023
file(GLOB HEADER "src/*.h")
2124
file(GLOB SOURCE "src/*.cpp")
2225

2326
# Create library with Python bindings
2427
# To work, install pybind11, making sure it comes with cmake files (conda install -c conda-forge pybind11)
25-
if (PYTHON)
28+
if(PYTHON)
2629
SET(PYBIND11_NEWPYTHON ON)
2730
find_package(Python COMPONENTS REQUIRED Interpreter Development)
2831
find_package(pybind11 CONFIG REQUIRED)
@@ -45,13 +48,22 @@ if(COMPILE_EXE)
4548
)
4649
target_compile_definitions(Raven PUBLIC STANDALONE)
4750
set_target_properties(Raven PROPERTIES LINKER_LANGUAGE CXX)
51+
if(LPSOLVE)
52+
target_link_directories(Raven PRIVATE lib/lp_solve) # where liblpsolve55.so is located
53+
target_link_libraries(Raven lpsolve55)
54+
add_definitions(-D_LPSOLVE_)
55+
endif()
4856
endif()
4957

50-
IF(NETCDF_FOUND)
58+
if(NETCDF_FOUND)
5159
add_definitions(-Dnetcdf)
5260
include_directories(${NetCDF_INCLUDE_DIRS})
5361
target_link_libraries(Raven NetCDF::NetCDF)
54-
ENDIF()
62+
elseif(netCDF_FOUND)
63+
add_definitions(-Dnetcdf)
64+
include_directories(${NetCDF_INCLUDE_DIRS})
65+
target_link_libraries(Raven netcdf)
66+
endif()
5567

5668
source_group("Header Files" FILES ${HEADER})
5769
source_group("Source Files" FILES ${SOURCE})

src/Advection.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ CmvAdvection::CmvAdvection(string constit_name,
2525
_constit_ind=pTransModel->GetConstituentIndex(constit_name);
2626

2727
int nAdvConnections =pTransModel->GetNumAdvConnections();
28+
int nWaterStores =pTransModel->GetNumWaterCompartments();
2829
CHydroProcessABC::DynamicSpecifyConnections(3*nAdvConnections+1);//+2 once GW added
30+
//CHydroProcessABC::DynamicSpecifyConnections(nAdvConnections+nWaterStores+1);//+2 once GW added
2931

3032
for (int q=0;q<nAdvConnections;q++) //for regular advection
3133
{
@@ -42,18 +44,29 @@ CmvAdvection::CmvAdvection(string constit_name,
4244
iFrom[2*nAdvConnections+q]=pModel->GetStateVarIndex(CONSTITUENT_SRC,_constit_ind);
4345
iTo [2*nAdvConnections+q]=iTo[q];
4446
}
47+
//for Dirichlet source corrections
48+
//for (int ii = 0; ii < nWaterStores; ii++) {
49+
// iFrom[nAdvConnections+ii]=pModel->GetStateVarIndex(CONSTITUENT_SRC,_constit_ind);
50+
// iTo [nAdvConnections+ii]=pTransModel->GetStorWaterIndex(ii);
51+
// }
52+
4553
//advection into surface water
4654
int iSW=pModel->GetStateVarIndex(SURFACE_WATER);
4755
int m=pTransModel->GetLayerIndex(_constit_ind,iSW);
4856
iFrom[3*nAdvConnections]=pModel->GetStateVarIndex(CONSTITUENT,m);
4957
iTo [3*nAdvConnections]=pModel->GetStateVarIndex(CONSTITUENT_SW,0);
5058

59+
//iFrom[nAdvConnections+nWaterStores]=pModel->GetStateVarIndex(CONSTITUENT,m);
60+
//iTo [nAdvConnections+nWaterStores]=pModel->GetStateVarIndex(CONSTITUENT_SW,0);
61+
5162
//advection into groundwater
5263
//int iGW=pModel->GetStateVarIndex(GROUNDWATER);
5364
//int m=pTransModel->GetLayerIndex(constit_ind,iGW);
5465
//iFrom[3*nAdvConnections+1]=pModel->GetStateVarIndex(CONSTITUENT,m);
5566
//iTo [3*nAdvConnections+1]=pModel->GetStateVarIndex(CONSTITUENT_GW,0);
5667

68+
//iFrom[nAdvConnections+nWaterStores+1]=pModel->GetStateVarIndex(CONSTITUENT,m);
69+
//iTo [nAdvConnections+nWaterStores+1]=pModel->GetStateVarIndex(CONSTITUENT_SW,0);
5770
}
5871

5972
//////////////////////////////////////////////////////////////////
@@ -223,6 +236,8 @@ void CmvAdvection::GetRatesOfChange(const double *state_vars,
223236
mass =sv[iFrom[q]];
224237
dirichlet_mass=Cs*sv[iFromWater]; //Cs*V
225238
rates[nAdvConnections+q]+=(dirichlet_mass-mass)/Options.timestep; //From CONSTITUENT_SRC
239+
//iiFromWater=pTransModel->GetWaterStorIndexFromSVIndex(iFromWater);
240+
//rates[nAdvConnections+iiFromWater]+=(dirichlet_mass-mass)/Options.timestep; //From CONSTITUENT_SRC //JRC: Reduced memory edit (or _aStorIndex[iFromWater])
226241
sv[iFrom[q]]=dirichlet_mass; //override previous mass/enthalpy
227242
}
228243

@@ -237,6 +252,8 @@ void CmvAdvection::GetRatesOfChange(const double *state_vars,
237252
mass =sv[iTo[q]];
238253
dirichlet_mass=Cs*sv[iToWater]; //C*V
239254
rates[2*nAdvConnections+q]+=(dirichlet_mass-mass)/Options.timestep; //From CONSTITUENT_SRC
255+
//iiToWater=pTransModel->GetWaterStorIndexFromSVIndex(iToWater);
256+
//rates[nAdvConnections+iiToWater]+=(dirichlet_mass-mass)/Options.timestep; //From CONSTITUENT_SRC //JRC: Reduced memory edit (or _aStorIndex[iFromWater] of size _nWaterStores)
240257
sv[iTo[q]]=dirichlet_mass; //override previous mass/enthalpy
241258
}
242259

src/CapillaryRise.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,11 @@ void CmvCapillaryRise::ApplyConstraints( const double *storage,
167167
double min_stor=g_min_storage;
168168

169169
//cant remove more than is there
170-
rates[0]=threshMin(rates[0],max(storage[iFrom[0]],min_stor)/Options.timestep,0.0);
170+
rates[0]=min(rates[0],max(storage[iFrom[0]],min_stor)/Options.timestep);
171171

172172
//exceedance of max "to" compartment
173173
//water flow simply slows (or stops) so that receptor will not overfill during tstep
174-
rates[0]=threshMin(rates[0],
175-
(pHRU->GetStateVarMax(iTo[0],storage,Options)-storage[iTo[0]])/Options.timestep,0.0);
174+
if (!Options.allow_soil_overfill){
175+
rates[0]=min(rates[0],(pHRU->GetStateVarMax(iTo[0],storage,Options)-storage[iTo[0]])/Options.timestep);
176+
}
176177
}

src/CommonFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ string GetProcessName(process_type p)
5050
case(SNOWSQUEEZE): {name="Liquid snow release"; break;}
5151
case(REFREEZE): {name="Snow Refreeze"; break;}
5252
case(SUBLIMATION): {name="Sublimation"; break;}
53-
case(SNOW_BALANCE): {name="Snow Melt & Refreeze"; break;}
53+
case(SNOW_BALANCE): {name="Snow Balance"; break;}
5454
case(GLACIER_MELT): {name="Glacier Melt"; break;}
5555
case(GLACIER_RELEASE): {name="Glacier Release"; break;}
5656
case(GLACIER_INFIL): {name="Glacier Infiltration"; break;}

src/ConstituentModel.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,7 @@ void CConstituentModel::WriteOutputFileHeaders(const optStruct &Options)
730730
_OUTPUT<<", sensible (r) "<<kg<<", conductive (r) " << kg << ", latent (r) "<<kg<<", GW mixing (r) "<<kg<<", radiant (r) "<<kg<<", friction (r)"<<kg<< endl;//TMP DEBUG
731731
}
732732

733-
//Pollutograph / stream temperatures file
733+
// Pollutograph / stream temperatures file
734734
//--------------------------------------------------------------------
735735
if(!_is_passive) {
736736
if(_type!=ENTHALPY) { filename=_name+"Pollutographs.csv"; }
@@ -1262,14 +1262,14 @@ void CConstituentModel::WriteMinorOutput(const optStruct &Options,const time_str
12621262

12631263
double latent_flux=0;
12641264
double Q_sens(0.0),Q_cond(0.0),Q_lat(0.0),Q_GW(0.0),Q_rad(0.0),Q_fric(0.0);
1265-
double Qs,Qc,Ql,Qg,Qr,Qlw,Qlw_in,Qf,Tave;
1265+
double Qs,Qc,Ql,Qg,Qr,Qlw,Qlw_in,Qltrl,Qf,Tave;
12661266
if(_type==ENTHALPY)
12671267
{
12681268
pEnthalpyModel=(CEnthalpyModel*)(this);
12691269
latent_flux =pEnthalpyModel->GetAvgLatentHeatFlux()*(area*M2_PER_KM2)*Options.timestep; // [MJ] (loss term)t)
12701270

12711271
for(int p=0;p<_pModel->GetNumSubBasins();p++) {
1272-
pEnthalpyModel->GetEnergyLossesFromReach(p,Qs,Qc,Ql,Qg,Qr,Qlw_in,Qlw,Qf,Tave);
1272+
pEnthalpyModel->GetEnergyLossesFromReach(p,Qs,Qc,Ql,Qg,Qr,Qlw_in,Qlw,Qltrl,Qf,Tave);
12731273
Q_sens+=Qs;Q_cond+=Qc;Q_lat+=Ql;Q_GW+=Qg;Q_rad+=Qr+Qlw+Qlw_in; Q_fric+=Qf;
12741274
}
12751275
}
@@ -1529,7 +1529,7 @@ void CConstituentModel::WriteNetCDFMinorOutput(const optStruct& Options,const ti
15291529

15301530
CEnthalpyModel *pEnthalpyModel=NULL; //Necessary evil to reduce code duplication rather than having an entirely separate WriteMinorOutput for Enthalpy
15311531
if (_type==ENTHALPY){
1532-
CEnthalpyModel *pEnthalpyModel=(CEnthalpyModel*)(this);
1532+
pEnthalpyModel=(CEnthalpyModel*)(this);
15331533
}
15341534

15351535
if((Options.suppressICs) && (tt.model_time==0.0)) { return; }

src/ControlStructures.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ bool COutflowRegime::AreConditionsMet(const time_struct& tt) const
283283
//////////////////////////////////////////////////////////////////
284284
/// \brief returns outflow from control structure for given stage, with prioritized constraints applied
285285
/// \param h [in] stage, in [m]
286-
/// \param Q_start [in] outflow at start of timestep [m3/s]
286+
/// \param Q_start [in] control structure outflow at start of timestep [m3/s]
287287
/// \returns outflow, in [m3/s]
288288
//
289289
double COutflowRegime::GetOutflow(const double &h, const double &h_start, const double &Q_start, const long &target_SBID, const double &drefelev) const
@@ -292,7 +292,8 @@ double COutflowRegime::GetOutflow(const double &h, const double &h_star
292292
double rivdepth = _pModel->GetSubBasinByID(target_SBID)->GetRiverDepth();
293293

294294
double Q = _pCurve->GetDischarge(h, h_start, Q_start, rivdepth, drefelev);
295-
double dQdt = (Q-Q_start)/tstep;
295+
296+
double dQdt = (Q-Q_start)/tstep; //m3/s/d
296297

297298
//apply constraints here
298299
for (int j = _nConstraints-1; j >=0; j--) //priority from first to last

src/ControlStructures.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class COutflowRegime
7878
void AddRegimeConstraint(RegimeConstraint *pCond);
7979

8080
bool AreConditionsMet(const time_struct &tt) const;
81-
double GetOutflow(const double &h, const double &Qstart, const double &hstart, const long &target_SBID, const double &drefelev) const;
81+
double GetOutflow(const double &h, const double &hstart, const double &Qstart, const long &target_SBID, const double &drefelev) const;
8282
};
8383

8484

0 commit comments

Comments
 (0)