Skip to content

Commit

Permalink
Provide the whole history in operator (#20)
Browse files Browse the repository at this point in the history
* Provide the whole history in operator

* Fix example
  • Loading branch information
marcbasquensmunoz authored Oct 22, 2024
1 parent 019abc7 commit c55fe09
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/src/nonhistory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ using BoreholeNetworksSimulator
#

Δt = 3600.
Nt = 8760
Nt = 2#8760

medium = GroundMedium=1e-6, λ=3., T0=10.)
borehole = SingleUPipeBorehole(H=100., D=10.)
Expand Down
2 changes: 1 addition & 1 deletion examples/Braedstrup/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ options = SimulationOptions(
seasonal_configuration
end

function BoreholeNetworksSimulator.operate(operator::SeasonalOperator, i, options, Tfin, Tfout, Tb, q)
function BoreholeNetworksSimulator.operate(operator::SeasonalOperator, i, options, X)
active_network = options.configurations[operator.seasonal_configuration[i]]
BoreholeOperation(active_network, operator.mass_flows)
end
Expand Down
2 changes: 1 addition & 1 deletion examples/tekniska/prop_m.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct VariableMFOperator{T <: Number} <: Operator
mass_flows::Vector{T}
end

function BoreholeNetworksSimulator.operate(operator::VariableMFOperator, step, options, Tin, Tout, Tb, q)
function BoreholeNetworksSimulator.operate(operator::VariableMFOperator, step, options, X)
operator.mass_flows .= operator.mass_flow_series[step]
BoreholeOperation(options.configurations[1], operator.mass_flows)
end
Expand Down
2 changes: 1 addition & 1 deletion examples/tekniska/toggle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include("defs.jl")
mass_flow_containers::Vector{T}
end

function BoreholeNetworksSimulator.operate(operator::ToggleOperator, step, options, Tin, Tout, Tb, q)
function BoreholeNetworksSimulator.operate(operator::ToggleOperator, step, options, X)
@unpack mass_flow, Q_threshold, single_branch, hours_used, toggle, mass_flow_containers = operator
current_load = options.constraint.Q_tot[step]

Expand Down
1 change: 1 addition & 0 deletions src/BoreholeNetworksSimulator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ export BoreholeOperation, Operator, SimpleOperator, operate
export simulate!, compute_parameters, load_cache!, save_cache, initialize
export n_branches
export ThermophysicalProperties
export extract_Tfin, extract_Tfout, extract_Tb, extract_q

end # module
12 changes: 9 additions & 3 deletions src/modular/interfaces/Operator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
Interface for operation strategies.
Required functions:
- `operate(::Operator, i, options, Tfin, Tfout, Tb, q)`: Return a `BoreholeOperation`.
- `operate(::Operator, step, options, X)`
The implementation of `operate` must return an instance of `BoreholeOperation`, specifying the network topology and the mass flows per branch for the current time step.
`step` is the current time step, `options` contains the provided simulation options and `X` contains the time series up to the time step `step-1` of
the inlet fluid temperature, the outlet fluid temperature, the wall temperature and the heat extraction rate, for each borehole in the borefield.
To get `Tfin`, `Tfout`, `Tb`, and `q` from `X`, use the functions `extract_Tfin`, `extract_Tfout`, `extract_Tb`, `extract_q`, or get them manually at the
indices [1:2:2Nb, :], [2:2:2Nb, :], [2Nb+1:3Nb, :], [3Nb+1:end, :], respectively.
"""
abstract type Operator end

@required Operator begin
operate(::Operator, i, options, Tfin, Tfout, Tb, q)
@required Operator begin
operate(::Operator, step, options, X)
end
2 changes: 1 addition & 1 deletion src/modular/operators/SimpleOperator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct SimpleOperator{T <: Number} <: Operator
end
SimpleOperator(;mass_flow, branches) = SimpleOperator(mass_flow .* ones(eltype(mass_flow), branches))

function operate(operator::SimpleOperator, i, options, Tin, Tout, Tb, q)
function operate(operator::SimpleOperator, i, options, X)
network = options.configurations[1]
BoreholeOperation(network, operator.mass_flows)
end
2 changes: 1 addition & 1 deletion src/modular/simulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function simulate!(;operator, options::SimulationOptions, containers::Simulation

# Simulation loop
for i = Ts:Nt
operation = @views operate(operator, i, options, X[1:2:2Nb, 1:i], X[2:2:2Nb, 1:i], X[2Nb+1:3Nb, 1:i], X[3Nb+1:end, 1:i])
operation = @views operate(operator, i, options, X[:, 1:i-1])
operation = unwrap(operation)

for (j, branch) in enumerate(operation.network.branches)
Expand Down
6 changes: 6 additions & 0 deletions src/modular/utils/solution_extract.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

get_Nb(X) = Int(size(X)[1] / 4)
extract_Tfin(X) = @view X[1:2:2*get_Nb(X), :]
extract_Tfout(X) = @view X[2:2:2*get_Nb(X), :]
extract_Tb(X) = @view X[2*get_Nb(X)+1:3*get_Nb(X), :]
extract_q(X) = @view X[3*get_Nb(X)+1:end, :]

0 comments on commit c55fe09

Please sign in to comment.