ContinuityModel Module
API Reference
The base components define foundational functionality of the ContinuityModel
class for maintaining continuity.
Base Components
ContinuityModel.h
-
class ContinuityModel
- #include <ContinuityModel.h>
The main
ContinuityModel
class for the Triangle Model that enforces continuity in the water distribution system.Created by bernardo on 1/12/17.
Subclassed by ContinuityModelRealization, ContinuityModelROF
Public Functions
-
ContinuityModel(vector<WaterSource*> &water_sources, vector<Utility*> &utilities, vector<MinEnvFlowControl*> &min_env_flow_controls, const Graph &water_sources_graph, const vector<vector<int>> &water_sources_to_utilities, vector<double> &utilities_rdm, vector<double> &water_sources_rdm, unsigned long realization_id)
Constructs a ContinuityModel object to simulate water flow and demand.
This constructor initializes a continuity model, linking water sources, utilities, and minimum environmental flow controls to simulate water distribution and demand over time. It sets up various internal tables and vectors for faster calculations and ensures proper linking of utilities to water sources. Additionally, it handles initialization for various properties like capacities and realization data.
- Parameters:
water_sources – A vector of pointers to the water sources in the model.
utilities – A vector of pointers to the utilities in the model.
min_env_flow_controls – A vector of pointers to the minimum environmental flow controls.
water_sources_graph – A graph representing the water sources and their relationships.
water_sources_to_utilities – A matrix mapping each utility to the water sources it uses.
utilities_rdm – A vector of randomization factors for the utilities.
water_sources_rdm – A vector of randomization factors for the water sources.
realization_id – An identifier for the current realization.
- Throws:
invalid_argument – If any of the water sources are not correctly linked to utilities, or if utilities lack storage capacity, an exception is thrown.
-
ContinuityModel(ContinuityModel &continuity_model)
Copy constructor for a new Continuity Model object.
- Parameters:
continuity_model – A reference to the ContinuityModel object to be copied.
- Returns:
A new ContinuityModel object with the same properties as the original.
-
virtual ~ContinuityModel()
Destructor for ContinuityModel to clean up dynamically allocated resources.
This destructor is responsible for deleting all dynamically allocated objects associated with the ContinuityModel instance, including water sources, utilities, and minimum environmental flow controls. It ensures proper cleanup to avoid memory leaks when the model is no longer needed.
This is a virtual function meant to be overridden by subclasses to ensure proper cleanup of any additional resources they may have allocated.
-
void continuityStep(int week, int rof_realization = -1, bool apply_demand_buffer = false, bool apply_demand_projection = false)
Performs a single step of the continuity calculation for water sources and utilities.
This function performs a mass balance calculation for each water source in the continuity model, updating the available volume and accounting for upstream spillage, wastewater discharges, and demand projections. It also updates the minimum environmental flows and utility storage volumes.
- Parameters:
week – The current week of the simulation.
rof_realization – The realization index for the ROF calculation (use
NON_INITIALIZED
for a regular simulation).apply_demand_buffer – Flag to indicate whether to apply the demand buffer to the simulation.
apply_demand_projection – Flag to indicate whether to apply the demand projection to the simulation.
- Returns:
void
-
void setRealization(unsigned long realization_id, vector<double> &utilities_rdm, vector<double> &water_sources_rdm)
Sets the realization ID for utilities, water sources, and minimum environmental flow controls.
This function assigns a specific realization ID to each utility, water source, and minimum environmental flow control in the continuity model. This ensures that the correct realization data is used for the simulation.
- Parameters:
realization_id – The ID of the realization to be set.
utilities_rdm – A vector containing random demand values for each utility, indexed by utility ID.
water_sources_rdm – A vector containing random demand values for each water source, indexed by source ID.
- Returns:
void
-
vector<int> getOnlineDownstreamSources()
Retrieves a list of online downstream water sources for each water source.
This function iterates through the water sources in topological order and identifies the first online downstream source for each water source. The result is a vector where each element represents the first online downstream source for the corresponding water source, or
NON_INITIALIZED
if no online downstream source is found.- Returns:
A vector of integers representing the IDs of the online downstream sources for each water source.
-
const vector<WaterSource*> &getContinuity_water_sources() const
Retrieves the list of water sources in the continuity model.
This function returns a constant reference to the vector of water sources that are included in the continuity model. The water sources represent all sources involved in the model’s calculations for continuity.
- Returns:
A constant reference to the vector of
WaterSource
pointers.
-
const vector<Utility*> &getContinuity_utilities() const
Retrieves the list of utilities in the continuity model.
This function returns a constant reference to the vector of utilities that are included in the continuity model. The utilities represent all entities that rely on the water sources for their operations in the model’s calculations.
- Returns:
A constant reference to the vector of
Utility
pointers.
Public Members
-
const unsigned long realization_id
An unsigned long integer representing the realization id.
Protected Attributes
-
vector<WaterSource*> continuity_water_sources
A vector of WaterSource objects representing the water sources in the system.
-
vector<Utility*> continuity_utilities
A vector of Utility objects representing the utilities in the system.
-
vector<MinEnvFlowControl*> min_env_flow_controls
A vector of MinEnvFlowControl objects representing the minimum environmental flow controls in the system.
-
Graph water_sources_graph
A bidirectional Graph object representing the connections between the water sources in the system.
-
vector<vector<int>> water_sources_to_utilities
A 2D vector of integers representing the water sources supplying each utility, irrespective of their online/offline status.
-
vector<vector<int>> water_sources_online_to_utilities
A 2D vector of integers representing the water sources supplying each utility that are is already built and functional.
-
vector<vector<int>> utilities_to_water_sources
A 2D vector of integers representing the utilities that draw water from each water source.
-
vector<int> downstream_sources
A vector of integers representing the downstream source of each water source.
-
const vector<int> sources_topological_order
A vector of integers representing the topological order of each water source.
-
vector<double> water_sources_capacities
A vector of doubles representing the capacities of each water source.
-
vector<double> utilities_capacities
A vector of doubles representing the capacities of each utility.
-
vector<vector<double>> demands
A 2D vector of doubles representing the demand timeseries of each utility.
-
vector<double> utilities_rdm
A vector of doubles representing the DU factor multipliers for each utility’s water demands.
-
vector<double> water_sources_rdm
A vector of doubles representing the DU factor multipliers scaling the construction, permitting, and financing aspects of a water source.
-
const int n_utilities
An integer representing the number of utilities in the system.
-
const int n_sources
An integer representing the number of water sources in the system.
-
int delta_realization_weeks[NUMBER_REALIZATIONS_ROF + 1]
An array of integers representing the number of weeks to be added to the current week to get the actual current week of the realization.
-
ContinuityModel(vector<WaterSource*> &water_sources, vector<Utility*> &utilities, vector<MinEnvFlowControl*> &min_env_flow_controls, const Graph &water_sources_graph, const vector<vector<int>> &water_sources_to_utilities, vector<double> &utilities_rdm, vector<double> &water_sources_rdm, unsigned long realization_id)
-
namespace std