From b8d945aae767065df5c8d516422ff92573febf87 Mon Sep 17 00:00:00 2001 From: visr Date: Thu, 28 Mar 2024 16:52:29 +0000 Subject: [PATCH] deploy: ae2fdf9af57735041088d3824ee2c943cdbb6a83 --- build/index.html | 376 ++++++++++++++++++++-------------------- core/allocation.html | 34 ++-- core/equations.html | 4 +- core/validation.html | 4 +- python/test-models.html | 2 +- search.json | 4 +- 6 files changed, 212 insertions(+), 212 deletions(-) diff --git a/build/index.html b/build/index.html index 73c9e270f..f9a8d1038 100644 --- a/build/index.html +++ b/build/index.html @@ -278,11 +278,11 @@

solve!
  • write_results
  • -

    source

    +

    source

    # Ribasim.configModule.

    module config

    Ribasim.config is a submodule of Ribasim to handle the configuration of a Ribasim model. It is implemented using the Configurations package. A full configuration is represented by Config, which is the main API. Ribasim.config is a submodule mainly to avoid name clashes between the configuration sections and the rest of Ribasim.

    -

    source

    +

    source

    @@ -290,18 +290,18 @@

    1.2 Types

    # Ribasim.AllocationType.

    Object for all information about allocation allocationnetworkids: The unique sorted allocation network IDs allocation models: The allocation models for the main network and subnetworks corresponding to allocationnetworkids mainnetworkconnections: (fromid, toid) from the main network to the subnetwork per subnetwork priorities: All used priority values. subnetworkdemands: The demand of an edge from the main network to a subnetwork recorddemand: A record of demands and allocated flows for nodes that have these. record_flow: A record of all flows computed by allocation optimization, eventually saved to output file

    -

    source

    +

    source

    # Ribasim.AllocationModelType.

    Store information for a subnetwork used for allocation.

    allocationnetworkid: The ID of this allocation network capacity: The capacity per edge of the allocation network, as constrained by nodes that have a maxflowrate problem: The JuMP.jl model for solving the allocation problem Δt_allocation: The time interval between consecutive allocation solves

    -

    source

    +

    source

    # Ribasim.AllocationModelMethod.

    Construct the JuMP.jl problem for allocation.

    Inputs

    allocationnetworkid: the ID of this allocation network p: Ribasim problem parameters Δt_allocation: The timestep between successive allocation solves

    Outputs

    An AllocationModel object.

    -

    source

    +

    source

    # Ribasim.BasinType.

    Requirements:

      @@ -311,22 +311,22 @@

      source

      +

      source

      # Ribasim.DiscreteControlType.

      nodeid: node ID of the DiscreteControl node; these are not unique but repeated by the amount of conditions of this DiscreteControl node listennodeid: the ID of the node being condition on variable: the name of the variable in the condition greaterthan: The threshold value in the condition conditionvalue: The current value of each condition controlstate: Dictionary: node ID => (control state, control state start) logic_mapping: Dictionary: (control node ID, truth state) => control state record: Namedtuple with discrete control information for results

      -

      source

      +

      source

      # Ribasim.EdgeMetadataType.

      Type for storing metadata of edges in the graph: id: ID of the edge (only used for labeling flow output) type: type of the edge allocationnetworkidsource: ID of allocation network where this edge is a source (0 if not a source) fromid: the node ID of the source node toid: the node ID of the destination node allocationflow: whether this edge has a flow in an allocation network node_ids: if this edge has allocation flow, these are all the nodes from the physical layer this edge consists of

      -

      source

      +

      source

      # Ribasim.FlatVectorType.

      struct FlatVector{T} <: AbstractVector{T}

      A FlatVector is an AbstractVector that iterates the T of a Vector{Vector{T}}.

      Each inner vector is assumed to be of equal length.

      It is similar to Iterators.flatten, though that doesn’t work with the Tables.Column interface, which needs length and getindex support.

      -

      source

      +

      source

      # Ribasim.FlowBoundaryType.

      nodeid: node ID of the FlowBoundary node active: whether this node is active and thus contributes flow flowrate: target flow rate

      -

      source

      +

      source

      # Ribasim.FractionalFlowType.

      Requirements:

        @@ -335,16 +335,16 @@

        source

        +

        source

        # Ribasim.InNeighborsType.

        Iterate over incoming neighbors of a given label in a MetaGraph, only for edges of edge_type

        -

        source

        +

        source

        # Ribasim.LevelBoundaryType.

        node_id: node ID of the LevelBoundary node active: whether this node is active level: the fixed level of this ‘infinitely big basin’

        -

        source

        +

        source

        # Ribasim.LevelDemandType.

        nodeid: node ID of the LevelDemand node minlevel: The minimum target level of the connected basin(s) max_level: The maximum target level of the connected basin(s) priority: If in a shortage state, the priority of the demand of the connected basin(s)

        -

        source

        +

        source

        # Ribasim.LinearResistanceType.

        Requirements:

          @@ -352,7 +352,7 @@

          source

          +

          source

          # Ribasim.ManningResistanceType.

          This is a simple Manning-Gauckler reach connection.

            @@ -382,48 +382,48 @@

            source

            +

            source

            # Ribasim.ModelType.

            Model(config_path::AbstractString)
             Model(config::Config)

            Initialize a Model.

            The Model struct is an initialized model, combined with the Config used to create it and saved results. The Basic Model Interface (BMI) is implemented on the Model. A Model can be created from the path to a TOML configuration file, or a Config object.

            -

            source

            +

            source

            # Ribasim.NodeMetadataType.

            Type for storing metadata of nodes in the graph type: type of the node allocationnetworkid: Allocation network ID (0 if not in subnetwork)

            -

            source

            +

            source

            # Ribasim.OutNeighborsType.

            Iterate over outgoing neighbors of a given label in a MetaGraph, only for edges of edge_type

            -

            source

            +

            source

            # Ribasim.OutletType.

            nodeid: node ID of the Outlet node active: whether this node is active and thus contributes flow flowrate: target flow rate minflowrate: The minimal flow rate of the outlet maxflowrate: The maximum flow rate of the outlet controlmapping: dictionary from (nodeid, controlstate) to target flow rate ispid_controlled: whether the flow rate of this outlet is governed by PID control

            -

            source

            +

            source

            # Ribasim.PidControlType.

            PID control currently only supports regulating basin levels.

            nodeid: node ID of the PidControl node active: whether this node is active and thus sets flow rates listennodeid: the id of the basin being controlled pidparams: a vector interpolation for parameters changing over time. The parameters are respectively target, proportional, integral, derivative, where the last three are the coefficients for the PID equation. error: the current error; basintarget - currentlevel

            -

            source

            +

            source

            # Ribasim.PumpType.

            nodeid: node ID of the Pump node active: whether this node is active and thus contributes flow flowrate: target flow rate minflowrate: The minimal flow rate of the pump maxflowrate: The maximum flow rate of the pump controlmapping: dictionary from (nodeid, controlstate) to target flow rate ispid_controlled: whether the flow rate of this pump is governed by PID control

            -

            source

            +

            source

            # Ribasim.SubgridType.

            Subgrid linearly interpolates basin levels.

            -

            source

            +

            source

            # Ribasim.TabulatedRatingCurveType.

            struct TabulatedRatingCurve{C}

            Rating curve from level to flow rate. The rating curve is a lookup table with linear interpolation in between. Relation can be updated in time, which is done by moving data from the time field into the tables, which is done in the update_tabulated_rating_curve callback.

            Type parameter C indicates the content backing the StructVector, which can be a NamedTuple of Vectors or Arrow Primitives, and is added to avoid type instabilities.

            nodeid: node ID of the TabulatedRatingCurve node active: whether this node is active and thus contributes flows tables: The current Q(h) relationships time: The time table used for updating the tables controlmapping: dictionary from (nodeid, controlstate) to Q(h) and/or active state

            -

            source

            +

            source

            # Ribasim.TerminalType.

            node_id: node ID of the Terminal node

            -

            source

            +

            source

            # Ribasim.UserDemandType.

            demand: water flux demand of UserDemand per priority over time. Each UserDemand has a demand for all priorities, which is 0.0 if it is not provided explicitly. realizedbmi: Cumulative inflow volume, for read or reset by BMI only. active: whether this node is active and thus demands water allocated: water flux currently allocated to UserDemand per priority returnfactor: the factor in [0,1] of how much of the abstracted water is given back to the system min_level: The level of the source basin below which the UserDemand does not abstract

            -

            source

            +

            source

            # Ribasim.config.ConfigMethod.

            Config(config_path::AbstractString; kwargs...)

            Parse a TOML file to a Config. Keys can be overruled using keyword arguments. To overrule keys from a subsection, e.g. dt from the solver section, use underscores: solver_dt.

            -

            source

            +

            source

            @@ -432,225 +432,225 @@

            # BasicModelInterface.finalizeMethod.

            BMI.finalize(model::Model)::Model

            Write all results to the configured files.

            -

            source

            +

            source

            # BasicModelInterface.initializeMethod.

            BMI.initialize(T::Type{Model}, config_path::AbstractString)::Model

            Initialize a Model from the path to the TOML configuration file.

            -

            source

            +

            source

            # CommonSolve.solve!Method.

            solve!(model::Model)::ODESolution

            Solve a Model until the configured endtime.

            -

            source

            +

            source

            # Ribasim.add_basin_term!Method.

            Add a term to the expression of the objective function corresponding to the demand of a basin.

            -

            source

            +

            source

            # Ribasim.add_constraints_absolute_value!Method.

            Minimizing |expr| can be achieved by introducing a new variable exprabs and posing the following constraints: exprabs >= expr expr_abs >= -expr

            -

            source

            +

            source

            # Ribasim.add_constraints_absolute_value_flow_demand!Method.

            Add constraints so that variables Fabsflow_demand act as the absolute value of the expression comparing flow to a flow buffer to the flow demand.

            -

            source

            +

            source

            # Ribasim.add_constraints_absolute_value_level_demand!Method.

            Add constraints so that variables Fabslevel_demand act as the absolute value of the expression comparing flow to a basin to its demand.

            -

            source

            +

            source

            # Ribasim.add_constraints_absolute_value_user_demand!Method.

            Add constraints so that variables Fabsuser_demand act as the absolute value of the expression comparing flow to a UserDemand to its demand.

            -

            source

            +

            source

            # Ribasim.add_constraints_basin_flow!Method.

            Add the Basin flow constraints to the allocation problem. The constraint indices are the Basin node IDs.

            Constraint: flow out of basin <= basin capacity

            -

            source

            +

            source

            # Ribasim.add_constraints_buffer!Method.

            Add the buffer outflow constraints to the allocation problem. The constraint indices are the node IDs of the nodes that have a flow demand.

            Constraint: flow out of buffer <= flow buffer capacity

            -

            source

            +

            source

            # Ribasim.add_constraints_capacity!Method.

            Add the flow capacity constraints to the allocation problem. Only finite capacities get a constraint. The constraint indices are (edgesourceid, edgedstid).

            Constraint: flow over edge <= edge capacity

            -

            source

            +

            source

            # Ribasim.add_constraints_conservation_basin!Method.

            Add the basin flow conservation constraints to the allocation problem. The constraint indices are Basin node IDs.

            Constraint: sum(flows out of basin) == sum(flows into basin) + flow from storage and vertical fluxes

            -

            source

            +

            source

            # Ribasim.add_constraints_conservation_flow_demand!Method.

            Add the conservation constraints for connector nodes with a flow demand to the allocation problem. The constraint indices are node IDs of the nodes with the flow demand (so not the IDs of the FlowDemand nodes).

            Constraint: flow into node + flow out of buffer = flow out of node + flow into buffer

            -

            source

            +

            source

            # Ribasim.add_constraints_conservation_subnetwork!Method.

            Add the subnetwork inlet flow conservation constraints to the allocation problem. The constraint indices are node IDs subnetwork inlet edge dst IDs.

            Constraint: sum(flows into node) == sum(flows out of node)

            -

            source

            +

            source

            # Ribasim.add_constraints_flow_demand_outflow!Method.

            Add the flow demand node outflow constraints to the allocation problem. The constraint indices are the node IDs of the nodes that have a flow demand.

            Constraint: flow out of node with flow demand <= ∞ if not at flow demand priority, 0.0 otherwise

            -

            source

            +

            source

            # Ribasim.add_constraints_fractional_flow!Method.

            Add the fractional flow constraints to the allocation problem. The constraint indices are allocation edges over a fractional flow node.

            Constraint: flow after fractional_flow node <= fraction * inflow

            -

            source

            +

            source

            # Ribasim.add_constraints_source!Method.

            Add the source constraints to the allocation problem. The actual threshold values will be set before each allocation solve. The constraint indices are (edgesourceid, edgedstid).

            Constraint: flow over source edge <= source flow in subnetwork

            -

            source

            +

            source

            # Ribasim.add_constraints_user_source!Method.

            Add capacity constraints to the outflow edge of UserDemand nodes. The constraint indices are the UserDemand node IDs.

            Constraint: flow over UserDemand edge outflow edge <= cumulative return flow from previous priorities

            -

            source

            +

            source

            # Ribasim.add_flow!Method.

            Add the given flow q to the existing flow over the edge between the given nodes.

            -

            source

            +

            source

            # Ribasim.add_flow_demand_term!Method.

            Add a term to the expression of the objective function corresponding to the demand of a node with a a flow demand.

            -

            source

            +

            source

            # Ribasim.add_objective_term!Function.

            Add a term to the objective function given by the objective type, depending in the provided flow variable and the associated demand.

            -

            source

            +

            source

            # Ribasim.add_subnetwork_connections!Method.

            Add the edges connecting the main network work to a subnetwork to both the main network and subnetwork allocation network.

            -

            source

            +

            source

            # Ribasim.add_user_demand_term!Method.

            Add a term to the expression of the objective function corresponding to the demand of a UserDemand.

            -

            source

            +

            source

            # Ribasim.add_variables_absolute_value!Method.

            Certain allocation distribution types use absolute values in the objective function. Since most optimization packages do not support the absolute value function directly, New variables are introduced that act as the absolute value of an expression by posing the appropriate constraints.

            -

            source

            +

            source

            # Ribasim.add_variables_basin!Method.

            Add the variables for supply/demand of a basin to the problem. The variable indices are the node_ids of the basins with a level demand in the subnetwork.

            -

            source

            +

            source

            # Ribasim.add_variables_flow!Method.

            Add the flow variables F to the allocation problem. The variable indices are (edgesourceid, edgedstid). Non-negativivity constraints are also immediately added to the flow variables.

            -

            source

            +

            source

            # Ribasim.add_variables_flow_buffer!Method.

            Add the variables for supply/demand of a node with a flow demand to the problem. The variable indices are the node_ids of the nodes with a flow demand in the subnetwork.

            -

            source

            +

            source

            # Ribasim.adjust_capacities_basin!Method.

            Set the capacities of the basin outflows. 2 cases:

            • Before the first allocation solve, set the capacities to their full capacity if there is surplus storage;
            • Before an allocation solve, subtract the flow used by allocation for the previous priority from the capacities.
            -

            source

            +

            source

            # Ribasim.adjust_capacities_buffers!Method.

            Adjust the capacities of the flow buffers of nodes with a flow demand. 2 cases:

            • Before the first allocation solve, set the capacities to 0.0;
            • Before an allocation solve, add the flow into the buffer and remove the flow out of the buffer from the buffer capacity.
            -

            source

            +

            source

            # Ribasim.adjust_capacities_edge!Method.

            Set the values of the edge capacities. 2 cases:

            • Before the first allocation solve, set the edge capacities to their full capacity;
            • Before an allocation solve, subtract the flow used by allocation for the previous priority from the edge capacities.
            -

            source

            +

            source

            # Ribasim.adjust_capacities_flow_demand_outflow!Method.

            Set the capacity of the outflow edge from a node with a flow demand:

            • To Inf if the current priority is other than the priority of the flow demand
            • To 0.0 if the current priority is equal to the priority of the flow demand
            -

            source

            +

            source

            # Ribasim.adjust_capacities_returnflow!Method.

            Add the return flow fraction of the inflow to the UserDemand nodes to the capacity of the outflow source.

            -

            source

            +

            source

            # Ribasim.adjust_capacities_source!Method.

            Adjust the source flows.

            -

            source

            +

            source

            # Ribasim.adjust_demands_flow!Method.

            Set the demand of the flow demand nodes. 2 cases:

            • Before the first allocation solve, set the demands to their full value;
            • Before an allocation solve, subtract the flow trough the node with a flow demand from the total flow demand (which will be used at the priority of the flow demand only).
            -

            source

            +

            source

            # Ribasim.all_neighbor_labels_typeMethod.

            Get the in- and outneighbor node IDs of the given node ID (label) over the given edge type in the graph.

            -

            source

            +

            source

            # Ribasim.allocate!Method.

            Update the allocation optimization problem for the given subnetwork with the problem state and flows, solve the allocation problem and assign the results to the UserDemand.

            -

            source

            +

            source

            # Ribasim.allocation_graphMethod.

            Build the graph used for the allocation problem.

            -

            source

            +

            source

            # Ribasim.allocation_graph_used_nodes!Method.

            Find all nodes in the subnetwork which will be used in the allocation network. Some nodes are skipped to optimize allocation optimization.

            -

            source

            +

            source

            # Ribasim.allocation_problemMethod.

            Construct the allocation problem for the current subnetwork as a JuMP.jl model.

            -

            source

            +

            source

            # Ribasim.allocation_tableMethod.

            Create an allocation result table for the saved data

            -

            source

            +

            source

            # Ribasim.assign_allocations!Method.

            Assign the allocations to the UserDemand as determined by the solution of the allocation problem.

            -

            source

            +

            source

            # Ribasim.basin_bottomMethod.

            Return the bottom elevation of the basin with index i, or nothing if it doesn’t exist

            -

            source

            +

            source

            # Ribasim.basin_bottomsMethod.

            Get the bottom on both ends of a node. If only one has a bottom, use that for both.

            -

            source

            +

            source

            # Ribasim.basin_tableMethod.

            Create the basin result table from the saved data

            -

            source

            +

            source

            # Ribasim.create_callbacksMethod.

            Create the different callbacks that are used to store results and feed the simulation with new data. The different callbacks are combined to a CallbackSet that goes to the integrator. Returns the CallbackSet and the SavedValues for flow.

            -

            source

            +

            source

            # Ribasim.create_graphMethod.

            Return a directed metagraph with data of nodes (NodeMetadata): NodeMetadata

            and data of edges (EdgeMetadata): EdgeMetadata

            -

            source

            +

            source

            # Ribasim.create_storage_tablesMethod.

            Read the Basin / profile table and return all area and level and computed storage values

            -

            source

            +

            source

            # Ribasim.datetime_sinceMethod.

            datetime_since(t::Real, t0::DateTime)::DateTime

            Convert a Real that represents the seconds passed since the simulation start to the nearest DateTime. This is used to convert between the solver’s inner float time, and the calendar.

            -

            source

            +

            source

            # Ribasim.datetimesMethod.

            Get all saved times as a Vector{DateTime}

            -

            source

            +

            source

            # Ribasim.discrete_control_affect!Method.

            Change parameters based on the control logic.

            -

            source

            +

            source

            # Ribasim.discrete_control_affect_downcrossing!Method.

            An downcrossing means that a condition (always greater than) becomes false.

            -

            source

            +

            source

            # Ribasim.discrete_control_affect_upcrossing!Method.

            An upcrossing means that a condition (always greater than) becomes true.

            -

            source

            +

            source

            # Ribasim.discrete_control_conditionMethod.

            Listens for changes in condition truths.

            -

            source

            +

            source

            # Ribasim.discrete_control_tableMethod.

            Create a discrete control result table from the saved data

            -

            source

            +

            source

            # Ribasim.expand_logic_mappingMethod.

            Replace the truth states in the logic mapping which contain wildcards with all possible explicit truth states.

            -

            source

            +

            source

            # Ribasim.find_allocation_graph_edges!Method.

            This loop finds allocation network edges in several ways:

            • Between allocation network nodes whose equivalent in the subnetwork are directly connected
            • Between allocation network nodes whose equivalent in the subnetwork are connected with one or more allocation network nodes in between
            -

            source

            +

            source

            # Ribasim.find_subnetwork_connections!Method.

            Find the edges from the main network to a subnetwork.

            -

            source

            +

            source

            # Ribasim.findlastgroupMethod.

            For an element id and a vector of elements ids, get the range of indices of the last consecutive block of id. Returns the empty range 1:0 if id is not in ids.

            -

            source

            +

            source

            # Ribasim.findsortedMethod.

            Find the index of element x in a sorted collection a. Returns the index of x if it exists, or nothing if it doesn’t. If x occurs more than once, throw an error.

            -

            source

            +

            source

            # Ribasim.flow_tableMethod.

            Create a flow result table from the saved data

            -

            source

            +

            source

            # Ribasim.formulate_flow!Method.

            Directed graph: outflow is positive!

            -

            source

            +

            source

            # Ribasim.formulate_flow!Method.

            Conservation of energy for two basins, a and b:

            h_a + v_a^2 / (2 * g) = h_b + v_b^2 / (2 * g) + S_f * L + C / 2 * g * (v_b^2 - v_a^2)
            @@ -678,16 +678,16 @@

            source

            +

            source

            # Ribasim.formulate_flow!Method.

            Directed graph: outflow is positive!

            -

            source

            +

            source

            # Ribasim.get_area_and_levelMethod.

            Compute the area and level of a basin given its storage. Also returns darea/dlevel as it is needed for the Jacobian.

            -

            source

            +

            source

            # Ribasim.get_basin_capacityMethod.

            Get the capacity of the basin, i.e. the maximum flow that can be abstracted from the basin if it is in a state of surplus storage (0 if no reference levels are provided by a level_demand node). Storages are converted to flows by dividing by the allocation timestep.

            -

            source

            +

            source

            # Ribasim.get_basin_dataMethod.

            Get several variables associated with a basin:

              @@ -697,135 +697,135 @@

              source

              +

              source

              # Ribasim.get_basin_demandMethod.

              Get the demand of the basin, i.e. how large a flow the basin needs to get to its minimum target level (0 if no reference levels are provided by a level_demand node). Storages are converted to flows by dividing by the allocation timestep.

              -

              source

              +

              source

              # Ribasim.get_chunk_sizesMethod.

              Get the chunk sizes for DiffCache; differentiation w.r.t. u and t (the latter only if a Rosenbrock algorithm is used).

              -

              source

              +

              source

              # Ribasim.get_compressorMethod.

              Get the compressor based on the Results section

              -

              source

              +

              source

              # Ribasim.get_flowMethod.

              Get the flow over the given edge (val is needed for get_tmp from ForwardDiff.jl).

              -

              source

              +

              source

              # Ribasim.get_fractional_flow_connected_basinsMethod.

              Get the node type specific indices of the fractional flows and basins, that are consecutively connected to a node of given id.

              -

              source

              +

              source

              # Ribasim.get_jac_prototypeMethod.

              Get a sparse matrix whose sparsity matches the sparsity of the Jacobian of the ODE problem. All nodes are taken into consideration, also the ones that are inactive.

              In Ribasim the Jacobian is typically sparse because each state only depends on a small number of other states.

              Note: the name ‘prototype’ does not mean this code is a prototype, it comes from the naming convention of this sparsity structure in the differentialequations.jl docs.

              -

              source

              +

              source

              # Ribasim.get_levelMethod.

              Get the current water level of a node ID. The ID can belong to either a Basin or a LevelBoundary. storage: tells ForwardDiff whether this call is for differentiation or not

              -

              source

              +

              source

              # Ribasim.get_scalar_interpolationMethod.

              Linear interpolation of a scalar with constant extrapolation.

              -

              source

              +

              source

              # Ribasim.get_storage_from_levelMethod.

              Get the storage of a basin from its level.

              -

              source

              +

              source

              # Ribasim.get_storages_and_levelsMethod.

              Get the storage and level of all basins as matrices of nbasin × ntime

              -

              source

              +

              source

              # Ribasim.get_storages_from_levelsMethod.

              Compute the storages of the basins based on the water level of the basins.

              -

              source

              +

              source

              # Ribasim.get_tstopsMethod.

              From an iterable of DateTimes, find the times the solver needs to stop

              -

              source

              +

              source

              # Ribasim.get_valueMethod.

              Get a value for a condition. Currently supports getting levels from basins and flows from flow boundaries.

              -

              source

              +

              source

              # Ribasim.get_ΔtMethod.

              Get the time interval between (flow) saves

              -

              source

              +

              source

              # Ribasim.id_indexMethod.

              Get the index of an ID in a set of indices.

              -

              source

              +

              source

              # Ribasim.indicate_allocation_flow!Method.

              Add to the edge metadata that the given edge is used for allocation flow. If the edge does not exist, it is created.

              -

              source

              +

              source

              # Ribasim.inflow_idMethod.

              Get the unique inneighbor over a flow edge.

              -

              source

              +

              source

              # Ribasim.inflow_idsMethod.

              Get the inneighbors over flow edges.

              -

              source

              +

              source

              # Ribasim.inflow_ids_allocationMethod.

              Get the inneighbors of the given ID such that the connecting edge is an allocation flow edge.

              -

              source

              +

              source

              # Ribasim.inneighbor_labels_typeMethod.

              Get the inneighbor node IDs of the given node ID (label) over the given edge type in the graph.

              -

              source

              +

              source

              # Ribasim.inoutflow_idsMethod.

              Get the in- and outneighbors over flow edges.

              -

              source

              +

              source

              # Ribasim.integrate_flows!Method.

              Integrate flows over the last timestep

              -

              source

              +

              source

              # Ribasim.is_allocation_sourceMethod.

              Find out whether the given edge is a source for an allocation network.

              -

              source

              +

              source

              # Ribasim.is_current_moduleMethod.

              is_current_module(log::LogMessageType)::Bool
               Returns true if the log message is from the current module or a submodule.
               
               See https://github.com/JuliaLogging/LoggingExtras.jl/blob/d35e7c8cfc197853ee336ace17182e6ed36dca24/src/CompositionalLoggers/earlyfiltered.jl#L39
               for the information available in log.
              -

              source

              +

              source

              # Ribasim.is_flow_constrainingMethod.

              Whether the given node node is flow constraining by having a maximum flow rate.

              -

              source

              +

              source

              # Ribasim.is_flow_direction_constrainingMethod.

              Whether the given node is flow direction constraining (only in direction of edges).

              -

              source

              +

              source

              # Ribasim.load_dataMethod.

              load_data(db::DB, config::Config, nodetype::Symbol, kind::Symbol)::Union{Table, Query, Nothing}

              Load data from Arrow files if available, otherwise the database. Returns either an Arrow.Table, SQLite.Query or nothing if the data is not present.

              -

              source

              +

              source

              # Ribasim.load_structvectorMethod.

              load_structvector(db::DB, config::Config, ::Type{T})::StructVector{T}

              Load data from Arrow files if available, otherwise the database. Always returns a StructVector of the given struct type T, which is empty if the table is not found. This function validates the schema, and enforces the required sort order.

              -

              source

              +

              source

              # Ribasim.low_storage_factorMethod.

              If id is a Basin with storage below the threshold, return a reduction factor != 1

              -

              source

              +

              source

              # Ribasim.mainMethod.

              main(toml_path::AbstractString)::Cint
               main(ARGS::Vector{String})::Cint
               main()::Cint

              This is the main entry point of the application. Performs argument parsing and sets up logging for both terminal and file. Calls Ribasim.run() and handles exceptions to convert to exit codes.

              -

              source

              +

              source

              # Ribasim.metadata_from_edgeMethod.

              Get the metadata of an edge in the graph from an edge of the underlying DiGraph.

              -

              source

              +

              source

              # Ribasim.nodefieldsMethod.

              Get all node fieldnames of the parameter object.

              -

              source

              +

              source

              # Ribasim.nodetypeMethod.

              From a SchemaVersion(“ribasim.flowboundary.static”, 1) return (:FlowBoundary, :static)

              -

              source

              +

              source

              # Ribasim.outflow_idMethod.

              Get the unique outneighbor over a flow edge.

              -

              source

              +

              source

              # Ribasim.outflow_idsMethod.

              Get the outneighbors over flow edges.

              -

              source

              +

              source

              # Ribasim.outflow_ids_allocationMethod.

              Get the outneighbors of the given ID such that the connecting edge is an allocation flow edge.

              -

              source

              +

              source

              # Ribasim.outneighbor_labels_typeMethod.

              Get the outneighbor node IDs of the given node ID (label) over the given edge type in the graph.

              -

              source

              +

              source

              # Ribasim.parse_static_and_timeMethod.

              Process the data in the static and time tables for a given node type. The ‘defaults’ named tuple dictates how missing data is filled in. ‘time_interpolatables’ is a vector of Symbols of parameter names for which a time interpolation (linear) object must be constructed. The control mapping for DiscreteControl is also constructed in this function. This function currently does not support node states that are defined by more than one row in a table, as is the case for TabulatedRatingCurve.

              -

              source

              +

              source

              # Ribasim.pkgversionMethod.

              Get the package version of a given module

              -

              source

              +

              source

              # Ribasim.process_allocation_graph_edges!Method.

              For the composite allocation network edges:

                @@ -833,101 +833,101 @@

                source

                +

                source

                # Ribasim.profile_storageMethod.

                Calculate a profile storage by integrating the areas over the levels

                -

                source

                +

                source

                # Ribasim.qh_interpolationMethod.

                From a table with columns nodeid, flowrate (Q) and level (h), create a LinearInterpolation from level to flow rate for a given node_id.

                -

                source

                +

                source

                # Ribasim.reduction_factorMethod.

                Function that goes smoothly from 0 to 1 in the interval [0,threshold], and is constant outside this interval.

                -

                source

                +

                source

                # Ribasim.runMethod.

                run(config_file::AbstractString)::Model
                 run(config::Config)::Model

                Run a Model, given a path to a TOML configuration file, or a Config object. Running a model includes initialization, solving to the end with [solve!](@ref) and writing results with write_results.

                -

                source

                +

                source

                # Ribasim.save_allocation_flows!Method.

                Save the allocation flows per basin and physical edge.

                -

                source

                +

                source

                # Ribasim.save_demands_and_allocations!Method.

                Save the demands and allocated flows for UserDemand and Basin. Note: Basin supply (negative demand) is only saved for the first priority.

                -

                source

                +

                source

                # Ribasim.save_flowMethod.

                Compute the average flows over the last saveat interval and write them to SavedValues

                -

                source

                +

                source

                # Ribasim.save_subgrid_levelMethod.

                Interpolate the levels and save them to SavedValues

                -

                source

                +

                source

                # Ribasim.save_vertical_fluxMethod.

                Compute the average vertical fluxes over the last saveat interval and write them to SavedValues

                -

                source

                +

                source

                # Ribasim.scalar_interpolation_derivativeMethod.

                Derivative of scalar interpolation.

                -

                source

                +

                source

                # Ribasim.seconds_sinceMethod.

                seconds_since(t::DateTime, t0::DateTime)::Float64

                Convert a DateTime to a float that is the number of seconds since the start of the simulation. This is used to convert between the solver’s inner float time, and the calendar.

                -

                source

                +

                source

                # Ribasim.set_current_value!Method.

                From a timeseries table time, load the most recent applicable data into table. table must be a NamedTuple of vectors with all variables that must be loaded. The most recent applicable data is non-NaN data for a given ID that is on or before t.

                -

                source

                +

                source

                # Ribasim.set_flow!Method.

                Set the given flow q over the edge between the given nodes.

                -

                source

                +

                source

                # Ribasim.set_fractional_flow_in_allocation!Method.

                Update the fractional flow fractions in an allocation problem.

                -

                source

                +

                source

                # Ribasim.set_initial_capacities_returnflow!Method.

                Set the initial capacities of the UserDemand return flow sources to 0.

                -

                source

                +

                source

                # Ribasim.set_initial_discrete_controlled_parameters!Method.

                Set parameters of nodes that are controlled by DiscreteControl to the values corresponding to the initial state of the model.

                -

                source

                +

                source

                # Ribasim.set_is_pid_controlled!Method.

                Set ispidcontrolled to true for those pumps and outlets that are PID controlled

                -

                source

                +

                source

                # Ribasim.set_objective_priority!Method.

                Set the objective for the given priority. For an objective with absolute values this also involves adjusting constraints.

                -

                source

                +

                source

                # Ribasim.set_static_value!Method.

                Load data from a source table static into a destination table. Data is matched based on the node_id, which is sorted.

                -

                source

                +

                source

                # Ribasim.set_table_row!Method.

                Update table at row index i, with the values of a given row. table must be a NamedTuple of vectors with all variables that must be loaded. The row must contain all the column names that are present in the table. If a value is missing, it is not set.

                -

                source

                +

                source

                # Ribasim.sorted_table!Method.

                Depending on if a table can be sorted, either sort it or assert that it is sorted.

                Tables loaded from the database into memory can be sorted. Tables loaded from Arrow files are memory mapped and can therefore not be sorted.

                -

                source

                +

                source

                # Ribasim.tsavesMethod.

                Get all saved times in seconds since start

                -

                source

                +

                source

                # Ribasim.update_allocation!Method.

                Solve the allocation problem for all demands and assign allocated abstractions.

                -

                source

                +

                source

                # Ribasim.update_basinMethod.

                Load updates from ‘Basin / time’ into the parameters

                -

                source

                +

                source

                # Ribasim.update_jac_prototype!Method.

                Method for nodes that do not contribute to the Jacobian

                -

                source

                +

                source

                # Ribasim.update_jac_prototype!Method.

                The controlled basin affects itself and the basins upstream and downstream of the controlled pump affect eachother if there is a basin upstream of the pump. The state for the integral term and the controlled basin affect eachother, and the same for the integral state and the basin upstream of the pump if it is indeed a basin.

                -

                source

                +

                source

                # Ribasim.update_jac_prototype!Method.

                If both the unique node upstream and the unique node downstream of these nodes are basins, then these directly depend on eachother and affect the Jacobian 2x Basins always depend on themselves.

                -

                source

                +

                source

                # Ribasim.update_jac_prototype!Method.

                If both the unique node upstream and the nodes down stream (or one node further if a fractional flow is in between) are basins, then the downstream basin depends on the upstream basin(s) and affect the Jacobian as many times as there are downstream basins Upstream basins always depend on themselves.

                -

                source

                +

                source

                # Ribasim.update_tabulated_rating_curve!Method.

                Load updates from ‘TabulatedRatingCurve / time’ into the parameters

                -

                source

                +

                source

                # Ribasim.update_vertical_flux!Method.

                Smoothly let the evaporation flux go to 0 when at small water depths Currently at less than 0.1 m.

                -

                source

                +

                source

                # Ribasim.valid_discrete_controlMethod.

                Check:

                  @@ -935,60 +935,60 @@

                  source

                  +

                  source

                  # Ribasim.valid_edge_typesMethod.

                  Check that only supported edge types are declared.

                  -

                  source

                  +

                  source

                  # Ribasim.valid_edgesMethod.

                  Test for each node given its node type whether the nodes that

                  are downstream (‘down-edge’) of this node are of an allowed type

                  -

                  source

                  +

                  source

                  # Ribasim.valid_flow_ratesMethod.

                  Test whether static or discrete controlled flow rates are indeed non-negative.

                  -

                  source

                  +

                  source

                  # Ribasim.valid_fractional_flowMethod.

                  Check that nodes that have fractional flow outneighbors do not have any other type of outneighbor, that the fractions leaving a node add up to ≈1 and that the fractions are non-negative.

                  -

                  source

                  +

                  source

                  # Ribasim.valid_n_neighborsMethod.

                  Test for each node given its node type whether it has an allowed number of flow/control inneighbors and outneighbors

                  -

                  source

                  +

                  source

                  # Ribasim.valid_profilesMethod.

                  Check whether the profile data has no repeats in the levels and the areas start positive.

                  -

                  source

                  +

                  source

                  # Ribasim.valid_sourcesMethod.

                  The source nodes must only have one allocation outneighbor and no allocation inneighbors.

                  -

                  source

                  +

                  source

                  # Ribasim.valid_subgridMethod.

                  Validate the entries for a single subgrid element.

                  -

                  source

                  +

                  source

                  # Ribasim.water_balance!Method.

                  The right hand side function of the system of ODEs set up by Ribasim.

                  -

                  source

                  +

                  source

                  # Ribasim.write_arrowMethod.

                  Write a result table to disk as an Arrow file

                  -

                  source

                  +

                  source

                  # Ribasim.write_resultsMethod.

                  write_results(model::Model)::Model

                  Write all results to the Arrow files as specified in the model configuration.

                  -

                  source

                  +

                  source

                  # Ribasim.config.algorithmMethod.

                  Create an OrdinaryDiffEqAlgorithm from solver config

                  -

                  source

                  +

                  source

                  # Ribasim.config.convert_dtMethod.

                  Convert the dt from our Config to SciML stepsize control arguments

                  -

                  source

                  +

                  source

                  # Ribasim.config.convert_saveatMethod.

                  Convert the saveat Float64 from our Config to SciML’s saveat

                  -

                  source

                  +

                  source

                  # Ribasim.config.input_pathMethod.

                  Construct a path relative to both the TOML directory and the optional input_dir

                  -

                  source

                  +

                  source

                  # Ribasim.config.results_pathMethod.

                  Construct a path relative to both the TOML directory and the optional results_dir

                  -

                  source

                  +

                  source

                  # Ribasim.config.snake_caseMethod.

                  Convert a string from CamelCase to snake_case.

                  -

                  source

                  +

                  source

                  @@ -1009,7 +1009,7 @@

                  source

                  +

                  source

                  @@ -1017,10 +1017,10 @@

                  1.5 Macros

                  # Ribasim.config.@addfieldsMacro.

                  Add fieldnames with Union{String, Nothing} type to struct expression. Requires (option?) use before it.

                  -

                  source

                  +

                  source

                  # Ribasim.config.@addnodetypesMacro.

                  Add all TableOption subtypes as fields to struct expression. Requires (option?) use before it.

                  -

                  source

                  +

                  source

                  @@ -1031,8 +1031,8 @@

                  Ribasim.config
                • Ribasim.config.algorithms
                • Ribasim.Allocation
                • -
                • Ribasim.AllocationModel
                • Ribasim.AllocationModel
                • +
                • Ribasim.AllocationModel
                • Ribasim.Basin
                • Ribasim.DiscreteControl
                • Ribasim.EdgeMetadata
                • @@ -1122,8 +1122,8 @@

                  Ribasim.findsorted
                • Ribasim.flow_table
                • Ribasim.formulate_flow!
                • -
                • Ribasim.formulate_flow!
                • Ribasim.formulate_flow!
                • +
                • Ribasim.formulate_flow!
                • Ribasim.get_area_and_level
                • Ribasim.get_basin_capacity
                • Ribasim.get_basin_data
                • @@ -1191,10 +1191,10 @@

                  Ribasim.tsaves
                • Ribasim.update_allocation!
                • Ribasim.update_basin
                • -
                • Ribasim.update_jac_prototype!
                • -
                • Ribasim.update_jac_prototype!
                • Ribasim.update_jac_prototype!
                • +
                • Ribasim.update_jac_prototype!
                • Ribasim.update_jac_prototype!
                • +
                • Ribasim.update_jac_prototype!
                • Ribasim.update_tabulated_rating_curve!
                • Ribasim.update_vertical_flux!
                • Ribasim.valid_discrete_control
                • diff --git a/core/allocation.html b/core/allocation.html index a8cac33db..156482f6d 100644 --- a/core/allocation.html +++ b/core/allocation.html @@ -548,7 +548,7 @@

                  4.4 Example

                  The following is an example of an optimization problem for the example shown here:

                  -
                  +
                  Code
                  using Ribasim
                  @@ -573,34 +573,34 @@ 

                  println(p.allocation.allocation_models[1].problem)

                  -
                  Min F_abs_user_demand[UserDemand #13] + F_abs_user_demand[UserDemand #6] + F_abs_user_demand[UserDemand #3]
                  +
                  Min F_abs_user_demand[UserDemand #3] + F_abs_user_demand[UserDemand #6] + F_abs_user_demand[UserDemand #13]
                   Subject to
                  - flow_conservation_basin[Basin #12] : F[(Basin #12, UserDemand #13)] - F[(TabulatedRatingCurve #7, Basin #12)] = 0
                  - flow_conservation_basin[Basin #2] : F[(Basin #2, Basin #5)] - F[(UserDemand #3, Basin #2)] - F[(FlowBoundary #1, Basin #2)] - F[(Basin #5, Basin #2)] + F[(Basin #2, UserDemand #3)] = 0
                  - flow_conservation_basin[Basin #5] : -F[(Basin #2, Basin #5)] - F[(UserDemand #6, Basin #5)] + F[(Basin #5, Basin #2)] + F[(Basin #5, UserDemand #6)] + F[(Basin #5, TabulatedRatingCurve #7)] = 0
                  - abs_positive_user_demand[UserDemand #13] : -F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0
                  - abs_positive_user_demand[UserDemand #6] : -F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0
                  + flow_conservation_basin[Basin #12] : -F[(TabulatedRatingCurve #7, Basin #12)] + F[(Basin #12, UserDemand #13)] = 0
                  + flow_conservation_basin[Basin #2] : F[(Basin #2, Basin #5)] - F[(Basin #5, Basin #2)] - F[(UserDemand #3, Basin #2)] - F[(FlowBoundary #1, Basin #2)] + F[(Basin #2, UserDemand #3)] = 0
                  + flow_conservation_basin[Basin #5] : -F[(Basin #2, Basin #5)] + F[(Basin #5, Basin #2)] + F[(Basin #5, TabulatedRatingCurve #7)] - F[(UserDemand #6, Basin #5)] + F[(Basin #5, UserDemand #6)] = 0
                    abs_positive_user_demand[UserDemand #3] : -F[(Basin #2, UserDemand #3)] + F_abs_user_demand[UserDemand #3] ≥ -1.5
                  - abs_negative_user_demand[UserDemand #13] : F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0
                  - abs_negative_user_demand[UserDemand #6] : F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0
                  + abs_positive_user_demand[UserDemand #6] : -F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0
                  + abs_positive_user_demand[UserDemand #13] : -F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0
                    abs_negative_user_demand[UserDemand #3] : F[(Basin #2, UserDemand #3)] + F_abs_user_demand[UserDemand #3] ≥ 1.5
                  + abs_negative_user_demand[UserDemand #6] : F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0
                  + abs_negative_user_demand[UserDemand #13] : F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0
                    source[(FlowBoundary #1, Basin #2)] : F[(FlowBoundary #1, Basin #2)] ≤ 1
                  - F[(UserDemand #13, Terminal #10)] ≤ 0
                  - F[(UserDemand #6, Basin #5)] ≤ 0
                    F[(UserDemand #3, Basin #2)] ≤ 0
                  + F[(UserDemand #6, Basin #5)] ≤ 0
                  + F[(UserDemand #13, Terminal #10)] ≤ 0
                    fractional_flow[(TabulatedRatingCurve #7, Basin #12)] : F[(TabulatedRatingCurve #7, Basin #12)] - 0.4 F[(Basin #5, TabulatedRatingCurve #7)] ≤ 0
                  + F[(TabulatedRatingCurve #7, Basin #12)] ≥ 0
                    F[(Basin #2, Basin #5)] ≥ 0
                  - F[(UserDemand #3, Basin #2)] ≥ 0
                  - F[(FlowBoundary #1, Basin #2)] ≥ 0
                  - F[(UserDemand #6, Basin #5)] ≥ 0
                    F[(Basin #12, UserDemand #13)] ≥ 0
                    F[(Basin #5, Basin #2)] ≥ 0
                  - F[(Basin #5, UserDemand #6)] ≥ 0
                    F[(TabulatedRatingCurve #7, Terminal #10)] ≥ 0
                  - F[(TabulatedRatingCurve #7, Basin #12)] ≥ 0
                    F[(Basin #5, TabulatedRatingCurve #7)] ≥ 0
                  - F[(Basin #2, UserDemand #3)] ≥ 0
                  + F[(UserDemand #6, Basin #5)] ≥ 0
                  + F[(UserDemand #3, Basin #2)] ≥ 0
                  + F[(Basin #5, UserDemand #6)] ≥ 0
                  + F[(FlowBoundary #1, Basin #2)] ≥ 0
                    F[(UserDemand #13, Terminal #10)] ≥ 0
                  + F[(Basin #2, UserDemand #3)] ≥ 0
                   
                  diff --git a/core/equations.html b/core/equations.html index 36bca3d04..87e6f6a39 100644 --- a/core/equations.html +++ b/core/equations.html @@ -427,7 +427,7 @@

                  Here \(p > 0\) is the threshold value which determines the interval \([0,p]\) of the smooth transition between \(0\) and \(1\), see the plot below.

                  -
                  +
                  Code
                  import numpy as np
                  @@ -475,7 +475,7 @@ 

                  diff --git a/core/validation.html b/core/validation.html index 6b1a326ce..8a66ad2dc 100644 --- a/core/validation.html +++ b/core/validation.html @@ -262,7 +262,7 @@

                  Validation

                  1 Connectivity

                  In the table below, each column shows which node types are allowed to be downstream (or ‘down-control’) of the node type at the top of the column.

                  -
                  +
                  Code
                  using Ribasim
                  @@ -546,7 +546,7 @@ 

                  1 Connectivity

                  2 Neighbor amounts

                  The table below shows for each node type between which bounds the amount of in- and outneighbors must be, for both flow and control edges.

                  -
                  +
                  Code
                  flow_in_min = Vector{String}()
                  diff --git a/python/test-models.html b/python/test-models.html
                  index 1933bf199..cfcfd11f8 100644
                  --- a/python/test-models.html
                  +++ b/python/test-models.html
                  @@ -227,7 +227,7 @@ 

                  Test models

                  Ribasim developers use the following models in their testbench and in order to test new features.

                  -
                  +
                  Code
                  import ribasim_testmodels
                  diff --git a/search.json b/search.json
                  index 64e8d3c5e..aa1bd4143 100644
                  --- a/search.json
                  +++ b/search.json
                  @@ -482,7 +482,7 @@
                       "href": "core/equations.html#sec-reduction_factor",
                       "title": "Equations",
                       "section": "2.1 The reduction factor",
                  -    "text": "2.1 The reduction factor\nAt several points in the equations below a reduction factor is used. This is a term that makes certain transitions more smooth, for instance when a pump stops providing water when its source basin dries up. The reduction factor is given by\n\\[\\begin{align}\n    \\phi(x; p) =\n    \\begin{cases}\n    0 &\\text{if}\\quad x < 0 \\\\\n        -2 \\left(\\frac{x}{p}\\right)^3 + 3\\left(\\frac{x}{p}\\right)^2 &\\text{if}\\quad 0 \\le x \\le p \\\\\n        1 &\\text{if}\\quad x > p\n    \\end{cases}\n\\end{align}\\]\nHere \\(p > 0\\) is the threshold value which determines the interval \\([0,p]\\) of the smooth transition between \\(0\\) and \\(1\\), see the plot below.\n\n\nCode\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef f(x, p = 3):\n    x_scaled = x / p\n    phi = (-2 * x_scaled + 3) * x_scaled**2\n    phi = np.where(x < 0, 0, phi)\n    phi = np.where(x > p, 1, phi)\n\n    return phi\n\nfontsize = 15\np = 3\nN = 100\nx_min = -1\nx_max = 4\nx = np.linspace(x_min,x_max,N)\nphi = f(x,p)\n\nfig,ax = plt.subplots(dpi=80)\nax.plot(x,phi)\n\ny_lim = ax.get_ylim()\n\nax.set_xticks([0,p], [0,\"$p$\"], fontsize=fontsize)\nax.set_yticks([0,1], [0,1], fontsize=fontsize)\nax.hlines([0,1],x_min,x_max, color = \"k\", ls = \":\", zorder=-1)\nax.vlines([0,p], *y_lim, color = \"k\", ls = \":\")\nax.set_xlim(x_min,x_max)\nax.set_xlabel(\"$x$\", fontsize=fontsize)\nax.set_ylabel(\"$\\phi(x;p)$\", fontsize=fontsize)\nax.set_ylim(y_lim)\n\nfig.tight_layout()\nplt.show()\n\n\n<>:31: SyntaxWarning:\n\ninvalid escape sequence '\\p'\n\n<>:31: SyntaxWarning:\n\ninvalid escape sequence '\\p'\n\n/tmp/ipykernel_5013/665069857.py:31: SyntaxWarning:\n\ninvalid escape sequence '\\p'",
                  +    "text": "2.1 The reduction factor\nAt several points in the equations below a reduction factor is used. This is a term that makes certain transitions more smooth, for instance when a pump stops providing water when its source basin dries up. The reduction factor is given by\n\\[\\begin{align}\n    \\phi(x; p) =\n    \\begin{cases}\n    0 &\\text{if}\\quad x < 0 \\\\\n        -2 \\left(\\frac{x}{p}\\right)^3 + 3\\left(\\frac{x}{p}\\right)^2 &\\text{if}\\quad 0 \\le x \\le p \\\\\n        1 &\\text{if}\\quad x > p\n    \\end{cases}\n\\end{align}\\]\nHere \\(p > 0\\) is the threshold value which determines the interval \\([0,p]\\) of the smooth transition between \\(0\\) and \\(1\\), see the plot below.\n\n\nCode\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ndef f(x, p = 3):\n    x_scaled = x / p\n    phi = (-2 * x_scaled + 3) * x_scaled**2\n    phi = np.where(x < 0, 0, phi)\n    phi = np.where(x > p, 1, phi)\n\n    return phi\n\nfontsize = 15\np = 3\nN = 100\nx_min = -1\nx_max = 4\nx = np.linspace(x_min,x_max,N)\nphi = f(x,p)\n\nfig,ax = plt.subplots(dpi=80)\nax.plot(x,phi)\n\ny_lim = ax.get_ylim()\n\nax.set_xticks([0,p], [0,\"$p$\"], fontsize=fontsize)\nax.set_yticks([0,1], [0,1], fontsize=fontsize)\nax.hlines([0,1],x_min,x_max, color = \"k\", ls = \":\", zorder=-1)\nax.vlines([0,p], *y_lim, color = \"k\", ls = \":\")\nax.set_xlim(x_min,x_max)\nax.set_xlabel(\"$x$\", fontsize=fontsize)\nax.set_ylabel(\"$\\phi(x;p)$\", fontsize=fontsize)\nax.set_ylim(y_lim)\n\nfig.tight_layout()\nplt.show()\n\n\n<>:31: SyntaxWarning:\n\ninvalid escape sequence '\\p'\n\n<>:31: SyntaxWarning:\n\ninvalid escape sequence '\\p'\n\n/tmp/ipykernel_5084/665069857.py:31: SyntaxWarning:\n\ninvalid escape sequence '\\p'",
                       "crumbs": [
                         "Julia core",
                         "Equations"
                  @@ -977,7 +977,7 @@
                       "href": "core/allocation.html#example",
                       "title": "Allocation",
                       "section": "4.4 Example",
                  -    "text": "4.4 Example\nThe following is an example of an optimization problem for the example shown here:\n\n\nCode\nusing Ribasim\nusing Ribasim: NodeID\nusing SQLite\nusing ComponentArrays: ComponentVector\n\ntoml_path = normpath(@__DIR__, \"../../generated_testmodels/allocation_example/ribasim.toml\")\np = Ribasim.Model(toml_path).integrator.p\nu = ComponentVector(; storage = zeros(length(p.basin.node_id)))\n\nallocation_model = p.allocation.allocation_models[1]\nt = 0.0\npriority_idx = 1\n\nRibasim.set_flow!(p.graph, NodeID(:FlowBoundary, 1), NodeID(:Basin, 2), 1.0)\n\nRibasim.adjust_capacities_edge!(allocation_model, p, priority_idx)\nRibasim.adjust_capacities_source!(allocation_model, p, priority_idx)\nRibasim.set_objective_priority!(allocation_model, p, u, t, priority_idx)\n\nprintln(p.allocation.allocation_models[1].problem)\n\n\nMin F_abs_user_demand[UserDemand #13] + F_abs_user_demand[UserDemand #6] + F_abs_user_demand[UserDemand #3]\nSubject to\n flow_conservation_basin[Basin #12] : F[(Basin #12, UserDemand #13)] - F[(TabulatedRatingCurve #7, Basin #12)] = 0\n flow_conservation_basin[Basin #2] : F[(Basin #2, Basin #5)] - F[(UserDemand #3, Basin #2)] - F[(FlowBoundary #1, Basin #2)] - F[(Basin #5, Basin #2)] + F[(Basin #2, UserDemand #3)] = 0\n flow_conservation_basin[Basin #5] : -F[(Basin #2, Basin #5)] - F[(UserDemand #6, Basin #5)] + F[(Basin #5, Basin #2)] + F[(Basin #5, UserDemand #6)] + F[(Basin #5, TabulatedRatingCurve #7)] = 0\n abs_positive_user_demand[UserDemand #13] : -F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0\n abs_positive_user_demand[UserDemand #6] : -F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0\n abs_positive_user_demand[UserDemand #3] : -F[(Basin #2, UserDemand #3)] + F_abs_user_demand[UserDemand #3] ≥ -1.5\n abs_negative_user_demand[UserDemand #13] : F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0\n abs_negative_user_demand[UserDemand #6] : F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0\n abs_negative_user_demand[UserDemand #3] : F[(Basin #2, UserDemand #3)] + F_abs_user_demand[UserDemand #3] ≥ 1.5\n source[(FlowBoundary #1, Basin #2)] : F[(FlowBoundary #1, Basin #2)] ≤ 1\n F[(UserDemand #13, Terminal #10)] ≤ 0\n F[(UserDemand #6, Basin #5)] ≤ 0\n F[(UserDemand #3, Basin #2)] ≤ 0\n fractional_flow[(TabulatedRatingCurve #7, Basin #12)] : F[(TabulatedRatingCurve #7, Basin #12)] - 0.4 F[(Basin #5, TabulatedRatingCurve #7)] ≤ 0\n F[(Basin #2, Basin #5)] ≥ 0\n F[(UserDemand #3, Basin #2)] ≥ 0\n F[(FlowBoundary #1, Basin #2)] ≥ 0\n F[(UserDemand #6, Basin #5)] ≥ 0\n F[(Basin #12, UserDemand #13)] ≥ 0\n F[(Basin #5, Basin #2)] ≥ 0\n F[(Basin #5, UserDemand #6)] ≥ 0\n F[(TabulatedRatingCurve #7, Terminal #10)] ≥ 0\n F[(TabulatedRatingCurve #7, Basin #12)] ≥ 0\n F[(Basin #5, TabulatedRatingCurve #7)] ≥ 0\n F[(Basin #2, UserDemand #3)] ≥ 0\n F[(UserDemand #13, Terminal #10)] ≥ 0",
                  +    "text": "4.4 Example\nThe following is an example of an optimization problem for the example shown here:\n\n\nCode\nusing Ribasim\nusing Ribasim: NodeID\nusing SQLite\nusing ComponentArrays: ComponentVector\n\ntoml_path = normpath(@__DIR__, \"../../generated_testmodels/allocation_example/ribasim.toml\")\np = Ribasim.Model(toml_path).integrator.p\nu = ComponentVector(; storage = zeros(length(p.basin.node_id)))\n\nallocation_model = p.allocation.allocation_models[1]\nt = 0.0\npriority_idx = 1\n\nRibasim.set_flow!(p.graph, NodeID(:FlowBoundary, 1), NodeID(:Basin, 2), 1.0)\n\nRibasim.adjust_capacities_edge!(allocation_model, p, priority_idx)\nRibasim.adjust_capacities_source!(allocation_model, p, priority_idx)\nRibasim.set_objective_priority!(allocation_model, p, u, t, priority_idx)\n\nprintln(p.allocation.allocation_models[1].problem)\n\n\nMin F_abs_user_demand[UserDemand #3] + F_abs_user_demand[UserDemand #6] + F_abs_user_demand[UserDemand #13]\nSubject to\n flow_conservation_basin[Basin #12] : -F[(TabulatedRatingCurve #7, Basin #12)] + F[(Basin #12, UserDemand #13)] = 0\n flow_conservation_basin[Basin #2] : F[(Basin #2, Basin #5)] - F[(Basin #5, Basin #2)] - F[(UserDemand #3, Basin #2)] - F[(FlowBoundary #1, Basin #2)] + F[(Basin #2, UserDemand #3)] = 0\n flow_conservation_basin[Basin #5] : -F[(Basin #2, Basin #5)] + F[(Basin #5, Basin #2)] + F[(Basin #5, TabulatedRatingCurve #7)] - F[(UserDemand #6, Basin #5)] + F[(Basin #5, UserDemand #6)] = 0\n abs_positive_user_demand[UserDemand #3] : -F[(Basin #2, UserDemand #3)] + F_abs_user_demand[UserDemand #3] ≥ -1.5\n abs_positive_user_demand[UserDemand #6] : -F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0\n abs_positive_user_demand[UserDemand #13] : -F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0\n abs_negative_user_demand[UserDemand #3] : F[(Basin #2, UserDemand #3)] + F_abs_user_demand[UserDemand #3] ≥ 1.5\n abs_negative_user_demand[UserDemand #6] : F[(Basin #5, UserDemand #6)] + F_abs_user_demand[UserDemand #6] ≥ 0\n abs_negative_user_demand[UserDemand #13] : F[(Basin #12, UserDemand #13)] + F_abs_user_demand[UserDemand #13] ≥ 0\n source[(FlowBoundary #1, Basin #2)] : F[(FlowBoundary #1, Basin #2)] ≤ 1\n F[(UserDemand #3, Basin #2)] ≤ 0\n F[(UserDemand #6, Basin #5)] ≤ 0\n F[(UserDemand #13, Terminal #10)] ≤ 0\n fractional_flow[(TabulatedRatingCurve #7, Basin #12)] : F[(TabulatedRatingCurve #7, Basin #12)] - 0.4 F[(Basin #5, TabulatedRatingCurve #7)] ≤ 0\n F[(TabulatedRatingCurve #7, Basin #12)] ≥ 0\n F[(Basin #2, Basin #5)] ≥ 0\n F[(Basin #12, UserDemand #13)] ≥ 0\n F[(Basin #5, Basin #2)] ≥ 0\n F[(TabulatedRatingCurve #7, Terminal #10)] ≥ 0\n F[(Basin #5, TabulatedRatingCurve #7)] ≥ 0\n F[(UserDemand #6, Basin #5)] ≥ 0\n F[(UserDemand #3, Basin #2)] ≥ 0\n F[(Basin #5, UserDemand #6)] ≥ 0\n F[(FlowBoundary #1, Basin #2)] ≥ 0\n F[(UserDemand #13, Terminal #10)] ≥ 0\n F[(Basin #2, UserDemand #3)] ≥ 0",
                       "crumbs": [
                         "Julia core",
                         "Allocation"