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

Public Types

enum  Types { Distributed , SemiDistributed , Lumped , Undefined }
 

Public Member Functions

 HydroUnit (double area=UNDEFINED, Types type=Undefined)
 
void Reset ()
 
void SaveAsInitialState ()
 
void SetProperties (HydroUnitSettings &unitSettings)
 
void AddProperty (std::unique_ptr< HydroUnitProperty > property)
 
double GetPropertyDouble (std::string_view name, std::string_view unit="") const
 
float GetPropertyFloat (std::string_view name, std::string_view unit="") const
 
string GetPropertyString (std::string_view name) const
 
bool HasProperty (std::string_view name) const
 
void SetParameterOverride (const string &key, float value)
 
bool HasParameterOverride (const string &key) const
 
const float * GetParameterOverridePointer (const string &key) const
 
void SetParameterOverrideMonthly (const string &key, const vecFloat &values)
 
vector< std::pair< float *, const vecFloat * > > GetMonthlyParameterOverrides ()
 
void AddBrick (std::unique_ptr< Brick > brick)
 
void AddSplitter (std::unique_ptr< Splitter > splitter)
 
bool HasForcing (VariableType type) const
 
void AddForcing (std::unique_ptr< Forcing > forcing)
 
Forcing * GetForcing (VariableType type) const
 
void ResetForcingUpdates ()
 
void AddLateralConnection (HydroUnit *receiver, double fraction, const string &type="")
 
void ReserveBricks (size_t count)
 
void ReserveLandCoverBricks (size_t count)
 
void ReserveSplitters (size_t count)
 
void ReserveLateralConnections (size_t count)
 
void ReserveForcings (size_t count)
 
int GetBrickCount () const
 
int GetSplitterCount () const
 
Brick * GetBrick (size_t index) const
 
bool HasBrick (std::string_view name) const
 
Brick * GetBrick (std::string_view name) const
 
Brick * TryGetBrick (std::string_view name) const
 
std::vector< Brick * > GetSnowpacks () const
 
double GetSnowCoverFraction (double sweThreshold=0.1) const
 
double GetSnowAlbedo (double albedoLand, double sweThreshold=0.1) const
 
LandCover * GetLandCover (std::string_view name) const
 
LandCover * TryGetLandCover (std::string_view name) const
 
Splitter * GetSplitter (size_t index) const
 
bool HasSplitter (std::string_view name) const
 
Splitter * GetSplitter (std::string_view name) const
 
Splitter * TryGetSplitter (std::string_view name) const
 
bool IsValid (bool checkProcesses=true) const
 
void Validate () const
 
bool ChangeLandCoverAreaFraction (std::string_view name, double fraction)
 
bool FixLandCoverFractionsTotal ()
 
void RestoreInitialAreaFractions ()
 
LandCover * GetGenericLandCover () const
 
Types GetType () const
 
void SetId (int id)
 
double GetArea () const
 
int GetId () const
 
void SetStructureId (int structureId)
 
int GetStructureId () const
 
std::vector< HydroUnitLateralConnection * > GetLateralConnections () const
 

Protected Attributes

Types _type
 
int _id
 
int _structureId = 1
 
double _area
 
std::vector< std::unique_ptr< HydroUnitProperty > > _properties
 
std::vector< std::unique_ptr< HydroUnitLateralConnection > > _lateralConnections
 
std::vector< std::unique_ptr< Brick > > _bricks
 
std::unordered_map< string, Brick * > _brickMap
 
std::vector< LandCover * > _landCoverBricks
 
std::unordered_map< string, LandCover * > _landCoverMap
 
std::vector< std::unique_ptr< Splitter > > _splitters
 
std::unordered_map< string, Splitter * > _splitterMap
 
std::vector< std::unique_ptr< Forcing > > _forcing
 
std::unordered_map< VariableType, Forcing * > _forcingMap
 
std::unordered_map< string, float > _paramOverrides
 
std::unordered_map< string, vecFloat > _paramOverridesMonthly
 

Member Function Documentation

◆ AddBrick()

void HydroUnit::AddBrick ( std::unique_ptr< Brick > brick)

Add a brick to the hydro unit.

Parameters
brickThe brick to add.

◆ AddForcing()

void HydroUnit::AddForcing ( std::unique_ptr< Forcing > forcing)

Attach a forcing to the hydro unit.

Parameters
forcingThe forcing to attach.

◆ AddLateralConnection()

void HydroUnit::AddLateralConnection ( HydroUnit * receiver,
double fraction,
const string & type = "" )

Add a lateral connection to the hydro unit.

Parameters
receiverThe hydro unit that receives the lateral connection.
fractionThe fraction of the flow that is transferred.
typeThe type of the lateral connection (optional). It is unused in the current implementation, but can be used for future extensions (for example, to differentiate between snow and groundwater).

◆ AddProperty()

void HydroUnit::AddProperty ( std::unique_ptr< HydroUnitProperty > property)

Add a property to the hydro unit.

Parameters
propertyThe property to add.

◆ AddSplitter()

void HydroUnit::AddSplitter ( std::unique_ptr< Splitter > splitter)

Add a splitter to the hydro unit.

Parameters
splitterThe splitter to add.

◆ ChangeLandCoverAreaFraction()

bool HydroUnit::ChangeLandCoverAreaFraction ( std::string_view name,
double fraction )

Change the area fraction of a land cover in the hydro unit. Ensure that the sum of all land cover fractions is equal to 1.

Parameters
nameThe name of the land cover to change.
fractionThe new area fraction of the land cover.
Returns
True on success; false if the fraction is outside [0, 1] or the land cover was not found.

◆ FixLandCoverFractionsTotal()

bool HydroUnit::FixLandCoverFractionsTotal ( )

Fix the land cover fractions to ensure that they sum to 1.

Returns
True if the fractions were fixed successfully, false otherwise.

◆ GetArea()

double HydroUnit::GetArea ( ) const
inlinenodiscard

Get the area of the hydro unit.

Returns
The area of the hydro unit [m²]

◆ GetBrick() [1/2]

Brick * HydroUnit::GetBrick ( size_t index) const
nodiscard

Get a brick by its index.

Parameters
indexThe index of the brick to get.
Returns
The brick at the specified index.

◆ GetBrick() [2/2]

Brick * HydroUnit::GetBrick ( std::string_view name) const
nodiscard

Get a brick by its name.

Parameters
nameThe name of the brick to get.
Returns
The brick with the specified name.

◆ GetBrickCount()

int HydroUnit::GetBrickCount ( ) const
nodiscard

Get the number of bricks in the hydro unit.

Returns
The number of bricks.

◆ GetForcing()

Forcing * HydroUnit::GetForcing ( VariableType type) const
nodiscard

Get a forcing of a specific type.

Parameters
typeThe type of forcing to get.
Returns
The forcing of the specified type.

◆ GetGenericLandCover()

LandCover * HydroUnit::GetGenericLandCover ( ) const
nodiscard

Get the generic land cover that absorbs area changes ('open', or its 'ground'/'generic'/'generic_land_cover' aliases).

Returns
Pointer to the generic land cover, or nullptr if none is defined.

◆ GetId()

int HydroUnit::GetId ( ) const
inlinenodiscard

Get the ID of the hydro unit.

Returns
The ID of the hydro unit.

◆ GetLandCover()

LandCover * HydroUnit::GetLandCover ( std::string_view name) const
nodiscard

Get a land cover by its name.

Parameters
nameThe name of the land cover to get.
Returns
The land cover with the specified name.

◆ GetLateralConnections()

std::vector< HydroUnitLateralConnection * > HydroUnit::GetLateralConnections ( ) const
nodiscard

Get the lateral connections of the hydro unit.

Returns
A vector of lateral connections associated with the hydro unit.

◆ GetMonthlyParameterOverrides()

vector< std::pair< float *, const vecFloat * > > HydroUnit::GetMonthlyParameterOverrides ( )
nodiscard

Get the per-unit monthly parameter overrides, as pairs of the value to write and the 12 monthly values to pick from. Registered with the ParametersUpdater.

Returns
The monthly overrides (pointers into this unit's override storage).

◆ GetParameterOverridePointer()

const float * HydroUnit::GetParameterOverridePointer ( const string & key) const
nodiscard

Get a stable pointer to a per-unit parameter override value (for the brick/process to read live). The key must exist (HasParameterOverride).

Parameters
keyThe override key ("<brickName>:<paramName>").
Returns
Pointer to the override value.

◆ GetPropertyDouble()

double HydroUnit::GetPropertyDouble ( std::string_view name,
std::string_view unit = "" ) const
nodiscard

Get a numeric property of the hydro unit.

Parameters
nameThe name of the property to get.
unitThe unit of the property to get.
Returns
The value of the property.

◆ GetPropertyFloat()

float HydroUnit::GetPropertyFloat ( std::string_view name,
std::string_view unit = "" ) const
nodiscard

Get a float property of the hydro unit.

Parameters
nameThe name of the property to get.
unitThe unit of the property to get.
Returns
The value of the property.

◆ GetPropertyString()

string HydroUnit::GetPropertyString ( std::string_view name) const
nodiscard

Get a property of the hydro unit as a string.

Parameters
nameThe name of the property to get.
Returns
The value of the property as a string.

◆ GetSnowAlbedo()

double HydroUnit::GetSnowAlbedo ( double albedoLand,
double sweThreshold = 0.1 ) const
nodiscard

Get the area-weighted surface albedo of the hydro unit for the PREVAH ET reduction: the snow-covered snowpacks contribute their (age-dependent) snow albedo weighted by their parent land-cover fraction, the rest of the unit contributes the snow-free ground albedo: albedo = albedoLand * (1 - snowfrac) + sum_c fraction_c * snowAlbedo_c

Parameters
albedoLandthe snow-free ground albedo [-].
sweThresholdsnow water equivalent above which a snowpack counts as snow-covered [mm].
Returns
the area-weighted albedo of the hydro unit [0, 1].

◆ GetSnowCoverFraction()

double HydroUnit::GetSnowCoverFraction ( double sweThreshold = 0.1) const
nodiscard

Get the snow-covered area fraction of the hydro unit: the sum of the parent land-cover fractions of the snowpacks currently holding snow (used e.g. by the PREVAH snow-albedo ET reduction).

Parameters
sweThresholdsnow water equivalent above which a snowpack counts as snow-covered [mm].
Returns
the snow-covered fraction of the hydro unit [0, 1].

◆ GetSnowpacks()

std::vector< Brick * > HydroUnit::GetSnowpacks ( ) const
inlinenodiscard

Get a vector of all snowpack bricks in the hydro unit.

Returns
A vector of pointers to the snowpack bricks.

◆ GetSplitter() [1/2]

Splitter * HydroUnit::GetSplitter ( size_t index) const
nodiscard

Get a splitter by its index.

Parameters
indexThe index of the splitter to get.
Returns
The splitter at the specified index.

◆ GetSplitter() [2/2]

Splitter * HydroUnit::GetSplitter ( std::string_view name) const
nodiscard

Get a splitter by its name.

Parameters
nameThe name of the splitter to get.
Returns
The splitter with the specified name.

◆ GetSplitterCount()

int HydroUnit::GetSplitterCount ( ) const
nodiscard

Get the number of splitters in the hydro unit.

Returns
The number of splitters.

◆ GetStructureId()

int HydroUnit::GetStructureId ( ) const
inlinenodiscard

Get the model-structure ID used by this hydro unit.

Returns
The model-structure ID (defaults to 1).

◆ GetType()

Types HydroUnit::GetType ( ) const
inline

Get the type of the hydro unit.

Returns
The type of the hydro unit.

◆ HasBrick()

bool HydroUnit::HasBrick ( std::string_view name) const
nodiscard

Check if the hydro unit has a brick with a specific name.

Parameters
nameThe name of the brick to check for.
Returns
True if the hydro unit has the brick, false otherwise.

◆ HasForcing()

bool HydroUnit::HasForcing ( VariableType type) const
nodiscard

Check if the hydro unit has a forcing of a specific type.

Parameters
typeThe type of forcing to check for.
Returns
True if the hydro unit has the forcing, false otherwise.

◆ HasParameterOverride()

bool HydroUnit::HasParameterOverride ( const string & key) const
nodiscard

Check whether a per-unit parameter override exists for a given key.

Parameters
keyThe override key ("<brickName>:<paramName>").
Returns
true if an override exists.

◆ HasProperty()

bool HydroUnit::HasProperty ( std::string_view name) const
nodiscard

Check whether the hydro unit has a numeric or string property with a given name.

Parameters
nameThe name of the property to look for.
Returns
true if a property with that name exists.

◆ HasSplitter()

bool HydroUnit::HasSplitter ( std::string_view name) const
nodiscard

Check if the hydro unit has a splitter with a specific name.

Parameters
nameThe name of the splitter to check for.
Returns
True if the hydro unit has the splitter, false otherwise.

◆ IsValid()

bool HydroUnit::IsValid ( bool checkProcesses = true) const
nodiscard

Check if the hydro unit is properly configured.

Returns
True if everything is correctly defined, false otherwise.

◆ ReserveBricks()

void HydroUnit::ReserveBricks ( size_t count)

Reserve space for a number of bricks in the hydro unit.

Parameters
countThe number of bricks to reserve space for.

◆ ReserveForcings()

void HydroUnit::ReserveForcings ( size_t count)

Reserve space for a number of forcings in the hydro unit.

Parameters
countThe number of forcings to reserve space for.

◆ ReserveLandCoverBricks()

void HydroUnit::ReserveLandCoverBricks ( size_t count)

Reserve space for a number of land cover bricks in the hydro unit.

Parameters
countThe number of land cover bricks to reserve space for.

◆ ReserveLateralConnections()

void HydroUnit::ReserveLateralConnections ( size_t count)

Reserve space for a number of lateral connections in the hydro unit.

Parameters
countThe number of lateral connections to reserve space for.

◆ ReserveSplitters()

void HydroUnit::ReserveSplitters ( size_t count)

Reserve space for a number of splitters in the hydro unit.

Parameters
countThe number of splitters to reserve space for.

◆ Reset()

void HydroUnit::Reset ( )

Reset the hydro unit to its initial state.

◆ ResetForcingUpdates()

void HydroUnit::ResetForcingUpdates ( )

Reset all dynamic forcing overrides set during the current timestep.

◆ RestoreInitialAreaFractions()

void HydroUnit::RestoreInitialAreaFractions ( )

Restore the area fractions of all land covers to their initial extents without touching the stored contents (used after the spin-up phase).

◆ SaveAsInitialState()

void HydroUnit::SaveAsInitialState ( )

Save the current state of the hydro unit as the initial state.

◆ SetId()

void HydroUnit::SetId ( int id)
inline

Set the ID of the hydro unit.

Parameters
idThe ID to set.

◆ SetParameterOverride()

void HydroUnit::SetParameterOverride ( const string & key,
float value )

Set a per-unit override value for a model parameter, keyed by "<brickName>:<paramName>". Used for spatial (per-unit) parameters: the brick or process reads this value instead of the shared settings value.

Parameters
keyThe override key ("<brickName>:<paramName>").
valueThe per-unit parameter value.

◆ SetParameterOverrideMonthly()

void HydroUnit::SetParameterOverrideMonthly ( const string & key,
const vecFloat & values )

Set the 12 monthly values of a per-unit parameter override, keyed by "<brickName>:<paramName>". Used for parameters that are both spatial and monthly (e.g. a field capacity built from a per-unit soil map and a monthly rooting depth). The value the brick reads is seeded with the annual mean and is then rewritten at every month change by the ParametersUpdater.

Parameters
keyThe override key ("<brickName>:<paramName>").
valuesThe 12 monthly values (January to December).

◆ SetProperties()

void HydroUnit::SetProperties ( HydroUnitSettings & unitSettings)

Set the properties of the hydro unit.

Parameters
unitSettingsThe settings to set.

◆ SetStructureId()

void HydroUnit::SetStructureId ( int structureId)
inline

Set the model-structure ID used by this hydro unit. Units sharing the same subsurface use the same structure; an exclusive land cover (e.g. a lake) can place a unit on a different structure variant. Defaults to 1.

Parameters
structureIdThe model-structure ID to use when building this unit.

◆ TryGetBrick()

Brick * HydroUnit::TryGetBrick ( std::string_view name) const
nodiscard

Try to get a brick by its name without throwing.

Parameters
nameThe name of the brick to get.
Returns
The brick with the specified name, or nullptr if not found.

◆ TryGetLandCover()

LandCover * HydroUnit::TryGetLandCover ( std::string_view name) const
nodiscard

Try to get a land cover brick by its name without throwing.

Parameters
nameThe name of the land cover to get.
Returns
The land cover with the specified name, or nullptr if not found.

◆ TryGetSplitter()

Splitter * HydroUnit::TryGetSplitter ( std::string_view name) const
nodiscard

Try to get a splitter by its name without throwing.

Parameters
nameThe name of the splitter to get.
Returns
The splitter with the specified name, or nullptr if not found.

◆ Validate()

void HydroUnit::Validate ( ) const

Validate that the hydro unit is properly configured. Throws an exception if validation fails.

Exceptions
ModelConfigErrorif validation fails.

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