hydrobricks
Loading...
Searching...
No Matches
ModelHydro Class Reference

Public Member Functions

 ModelHydro (Subbasin *subbasin=nullptr)
 
ModelResult InitializeWithBasin (SettingsModel &modelSettings, SettingsBasin &basinSettings)
 
ModelResult Initialize (SettingsModel &modelSettings, SettingsBasin &basinSettings, bool checkProcesses=true)
 
void UpdateParameters (SettingsModel &modelSettings)
 
bool IsValid () const
 
void Validate () const
 
bool ForcingLoaded () const
 
ModelResult Run ()
 
void OpenLog (const string &directory)
 
void CloseLog ()
 
void Reset ()
 
void SaveAsInitialState ()
 
bool DumpOutputs (const string &path)
 
axd GetOutletDischarge () const
 
axd GetSubbasinDischarge (int subbasinId) const
 
int GetSubbasinCount () const
 
vecInt GetSubbasinIds () const
 
vecInt GetSubbasinDownstreamIds () const
 
axd GetSubbasinLocalAreas () const
 
axd GetSubbasinDrainedAreas () const
 
axd GetReachLengths () const
 
axd GetReachSlopes () const
 
axd GetReachTravelTimes () const
 
vecInt GetReachSubreachCounts () const
 
string GetChannelRoutingScheme () const
 
HydroUnit * GetHydroUnitById (int id) const
 
std::vector< HydroUnit * > GetHydroUnits () const
 
double GetTotalOutletDischarge () const
 
double GetTotalET () const
 
double GetTotalWaterStorageChanges () const
 
double GetTotalSnowStorageChanges () const
 
double GetTotalGlacierStorageChanges () const
 
bool AddTimeSeries (std::unique_ptr< TimeSeries > timeSeries)
 
bool AddAction (Action *action)
 
int GetActionCount () const
 
int GetSporadicActionItemCount () const
 
bool CreateTimeSeries (const string &varName, const axd &time, const axi &ids, const axxd &data)
 
void ClearTimeSeries ()
 
bool AttachTimeSeriesToHydroUnits ()
 
Subbasin * GetSubbasin () const
 
void SetSubbasin (Subbasin *subbasin)
 
RiverNetwork * GetNetwork () const
 
TimeMachine * GetTimeMachine ()
 
Processor * GetProcessor ()
 
Logger * GetLogger ()
 
ActionsManager * GetActionsManager ()
 
axxd GetHydroUnitValues (const string &label) const
 
axxd GetHydroUnitFractions (const string &label) const
 
vecStr GetRecordedHydroUnitLabels () const
 
vecStr GetRecordedHydroUnitFractionLabels () const
 
vecInt GetHydroUnitIds () const
 
axd GetHydroUnitAreas () const
 
string GetHydroUnitLabelBasis (const string &label) const
 
axd GetHydroUnitSubbasinFractions () const
 

Protected Attributes

std::vector< std::unique_ptr< Processor > > _processors
 
std::unique_ptr< RiverNetwork > _network
 
Subbasin * _subbasin
 
std::vector< Subbasin * > _subbasins
 
TimeMachine _timer
 
Logger _logger
 
ActionsManager _actionsManager
 
ParametersUpdater _parametersUpdater
 
std::vector< std::unique_ptr< TimeSeries > > _timeSeries
 
int _spinupSteps = 0
 
LogFile _log
 

Member Function Documentation

◆ AddAction()

bool ModelHydro::AddAction ( Action * action)

Add an action to the model.

Parameters
actionaction to add.
Returns
true if the action was added successfully.

◆ AddTimeSeries()

bool ModelHydro::AddTimeSeries ( std::unique_ptr< TimeSeries > timeSeries)

Add a time series to the model.

Parameters
timeSeriestime series to add.
Returns
true if the time series was added successfully.

◆ AttachTimeSeriesToHydroUnits()

bool ModelHydro::AttachTimeSeriesToHydroUnits ( )

Attach the time series to the hydro units.

Returns
true if the time series were attached successfully.

◆ ClearTimeSeries()

void ModelHydro::ClearTimeSeries ( )

Clear the time series.

◆ CloseLog()

void ModelHydro::CloseLog ( )

Flush and close the model's own log file.

◆ CreateTimeSeries()

bool ModelHydro::CreateTimeSeries ( const string & varName,
const axd & time,
const axi & ids,
const axxd & data )

Create a time series and add it to the model.

Parameters
varNamename of the variable.
timetime series data.
idsids of the data.
datadata to add.
Returns
true if the time series was created and added successfully.

◆ DumpOutputs()

bool ModelHydro::DumpOutputs ( const string & path)

Dump the outputs as betCDF file to the specified path.

Parameters
pathpath to dump the outputs.
Returns
true if the dump was successful.

◆ ForcingLoaded()

bool ModelHydro::ForcingLoaded ( ) const
nodiscard

Check if the forcing data were loaded.

Returns
true if the forcing data were loaded.

◆ GetActionCount()

int ModelHydro::GetActionCount ( ) const
nodiscard

Get the number of actions in the model.

Returns
number of actions.

◆ GetActionsManager()

ActionsManager * ModelHydro::GetActionsManager ( )
inline

Get the actions manager.

Returns
pointer to the actions manager.

◆ GetChannelRoutingScheme()

string ModelHydro::GetChannelRoutingScheme ( ) const
nodiscard

Get the name of the channel routing scheme in use.

Returns
the scheme name ('none' without a river network).

◆ GetHydroUnitAreas()

axd ModelHydro::GetHydroUnitAreas ( ) const
nodiscard

Get the areas of the hydro units in the recorded order.

Returns
array of hydro unit areas.

◆ GetHydroUnitById()

HydroUnit * ModelHydro::GetHydroUnitById ( int id) const
nodiscard

Get a hydro unit by ID, in any subbasin.

Parameters
idThe ID of the hydro unit.
Returns
the hydro unit, or nullptr if the ID is unknown.

◆ GetHydroUnitFractions()

axxd ModelHydro::GetHydroUnitFractions ( const string & label) const
nodiscard

Get the recorded land-cover fraction series for a given fraction label (land cover name), read from the in-memory logger. Fractions are recorded only when record_all is enabled.

Parameters
labelthe land cover name (e.g. "glacier").
Returns
the recorded fraction series as a 2D array (time steps x hydro units).

◆ GetHydroUnitIds()

vecInt ModelHydro::GetHydroUnitIds ( ) const
nodiscard

Get the ids of the hydro units in the recorded order.

Returns
vector of hydro unit ids.

◆ GetHydroUnitLabelBasis()

string ModelHydro::GetHydroUnitLabelBasis ( const string & label) const
nodiscard

Get the area basis of a recorded hydro unit component: "land_cover" (over the area of its land cover), "hydro_unit" (over the unit) or "subbasin" (over the local area of the subbasin).

Parameters
labelthe component label (e.g. "glacier:melt:output").
Returns
the area basis.

◆ GetHydroUnits()

std::vector< HydroUnit * > ModelHydro::GetHydroUnits ( ) const
nodiscard

Get every hydro unit of the model, subbasin after subbasin in processing order.

Returns
the hydro units.

◆ GetHydroUnitSubbasinFractions()

axd ModelHydro::GetHydroUnitSubbasinFractions ( ) const
nodiscard

Get the share of its subbasin's area covered by each hydro unit, in recorded order.

Returns
vector of area fractions.

◆ GetHydroUnitValues()

axxd ModelHydro::GetHydroUnitValues ( const string & label) const
nodiscard

Get the recorded hydro unit value series for a given component label, read from the in-memory logger (no file dump). Requires the component to have been recorded (e.g. with record_all enabled).

Parameters
labelthe recorded component label (e.g. "glacier:melt:output").
Returns
the recorded series as a 2D array (time steps x hydro units).

◆ GetLogger()

Logger * ModelHydro::GetLogger ( )
inline

Get the logger.

Returns
pointer to the logger.

◆ GetNetwork()

RiverNetwork * ModelHydro::GetNetwork ( ) const
inline

Get the river network (the tree of subbasins), owned by the model once InitializeWithBasin has run.

Returns
the river network, or nullptr when the subbasin was provided externally.

◆ GetOutletDischarge()

axd ModelHydro::GetOutletDischarge ( ) const

Get the outlet discharge series.

Returns
outlet discharge series.

◆ GetProcessor()

Processor * ModelHydro::GetProcessor ( )
inline

Get the processor.

Returns
pointer to the processor. Get the processor of the outlet subbasin (the only one for a single subbasin).
the processor, or nullptr before initialization.

◆ GetReachLengths()

axd ModelHydro::GetReachLengths ( ) const
nodiscard

Get the length of the reach of every subbasin [m], in the order of GetSubbasinIds().

Returns
the reach lengths.

◆ GetReachSlopes()

axd ModelHydro::GetReachSlopes ( ) const
nodiscard

Get the slope of the reach of every subbasin [m/m], in the order of GetSubbasinIds().

Returns
the reach slopes.

◆ GetReachSubreachCounts()

vecInt ModelHydro::GetReachSubreachCounts ( ) const
nodiscard

Get the number of sub reaches the reach of every subbasin is divided into, in the order of GetSubbasinIds(). Always 1 except with Muskingum-Cunge, and only once the model has run a step.

Returns
the sub reach counts.

◆ GetReachTravelTimes()

axd ModelHydro::GetReachTravelTimes ( ) const
nodiscard

Get the travel time of the reach of every subbasin [days], at the reference discharge, in the order of GetSubbasinIds(). With the discharge-dependent schemes the travel time of a step differs from it.

Returns
the reach travel times.

◆ GetRecordedHydroUnitFractionLabels()

vecStr ModelHydro::GetRecordedHydroUnitFractionLabels ( ) const
nodiscard

Get the labels of the recorded land-cover fractions.

Returns
vector of recorded fraction labels (land cover names).

◆ GetRecordedHydroUnitLabels()

vecStr ModelHydro::GetRecordedHydroUnitLabels ( ) const
nodiscard

Get the labels of the recorded hydro unit components.

Returns
vector of recorded component labels.

◆ GetSporadicActionItemCount()

int ModelHydro::GetSporadicActionItemCount ( ) const
nodiscard

Get the number of sporadic action items in the model (i.e., actions that are not recursive).

Returns
number of sporadic action items.

◆ GetSubbasin()

Subbasin * ModelHydro::GetSubbasin ( ) const
inline

Get the subbasin.

Returns
pointer to the subbasin.

◆ GetSubbasinDischarge()

axd ModelHydro::GetSubbasinDischarge ( int subbasinId) const
nodiscard

Get the discharge at the outlet of a subbasin [mm over its drained area].

Parameters
subbasinIdThe ID of the subbasin.
Returns
the discharge time series.

◆ GetTimeMachine()

TimeMachine * ModelHydro::GetTimeMachine ( )
inline

Get the time machine (timer).

Returns
pointer to the timer.

◆ GetTotalET()

double ModelHydro::GetTotalET ( ) const
nodiscard

Get the total amount of water lost by evapotranspiration.

Returns
total amount of water lost by evapotranspiration.

◆ GetTotalOutletDischarge()

double ModelHydro::GetTotalOutletDischarge ( ) const
nodiscard

Get the total outlet discharge.

Returns
total outlet discharge.

◆ GetTotalSnowStorageChanges()

double ModelHydro::GetTotalSnowStorageChanges ( ) const
nodiscard

Get the total change in snow storage.

Returns
total change in snow storage.

◆ GetTotalWaterStorageChanges()

double ModelHydro::GetTotalWaterStorageChanges ( ) const
nodiscard

Get the total change in water storage.

Returns
total change in water storage.

◆ Initialize()

ModelResult ModelHydro::Initialize ( SettingsModel & modelSettings,
SettingsBasin & basinSettings,
bool checkProcesses = true )

Initialize the model.

Parameters
modelSettingssettings of the model.
basinSettingssettings of the basin.
checkProcesseswhether to check the processes during validation.
Returns
true if the initialization was successful.

◆ InitializeWithBasin()

ModelResult ModelHydro::InitializeWithBasin ( SettingsModel & modelSettings,
SettingsBasin & basinSettings )

Initialize the model along with the basin.

Parameters
modelSettingssettings of the model.
basinSettingssettings of the basin.
Returns
true if the initialization was successful.

◆ IsValid()

bool ModelHydro::IsValid ( ) const
nodiscard

Check that everything is correctly defined.

Returns
true if everything is correctly defined.

◆ OpenLog()

void ModelHydro::OpenLog ( const string & directory)

Open the model's own log file (hydrobricks_<timestamp>.log) in the given directory. The messages logged while this model initializes, runs or updates go there instead of the global log file, so that several models can log independently.

Parameters
directorydirectory of the log file.

◆ Reset()

void ModelHydro::Reset ( )

Reset the model.

◆ Run()

ModelResult ModelHydro::Run ( )
nodiscard

Run the model.

Returns
true if the model run was successful.

◆ SaveAsInitialState()

void ModelHydro::SaveAsInitialState ( )

Save the model state as initial conditions.

◆ SetSubbasin()

void ModelHydro::SetSubbasin ( Subbasin * subbasin)
inline

Set the subbasin (non-owning; caller retains ownership).

Parameters
subbasinpointer to the subbasin.

◆ UpdateParameters()

void ModelHydro::UpdateParameters ( SettingsModel & modelSettings)

Update the model parameters.

Parameters
modelSettingssettings of the model.

◆ Validate()

void ModelHydro::Validate ( ) const

Validate that everything is correctly defined. Throws an exception if validation fails.

Exceptions
ModelConfigErrorif validation fails.

The documentation for this class was generated from the following files: