Skip to content

Commit

Permalink
Merge pull request #51 from sintefmath/hyst
Browse files Browse the repository at this point in the history
Hysteresis & relperm refactoring
  • Loading branch information
moyner authored Aug 2, 2024
2 parents f3867c7 + ba36514 commit b2150a0
Show file tree
Hide file tree
Showing 20 changed files with 1,630 additions and 738 deletions.
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "JutulDarcy"
uuid = "82210473-ab04-4dce-b31b-11573c4f8e0a"
authors = ["Olav Møyner <[email protected]>"]
version = "0.2.26"
version = "0.2.27"

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Expand Down Expand Up @@ -47,10 +47,10 @@ Dates = "1"
DelimitedFiles = "1.9.1"
DocStringExtensions = "0.9.3"
ForwardDiff = "0.10.30"
GLMakie = "0.9.2"
GLMakie = "0.10.0"
GeoEnergyIO = "1.1.3"
HYPRE = "1.4.0"
Jutul = "0.2.34"
Jutul = "0.2.35"
Krylov = "0.9.1"
LinearAlgebra = "1"
LoopVectorization = "0.12.115"
Expand All @@ -64,7 +64,7 @@ ProgressMeter = "1.7.2"
SparseArrays = "1"
StaticArrays = "1.4.4"
Statistics = "1"
TestItems = "0.1.0, 1"
TestItems = "1.0.0"
TimerOutputs = "0.5.19"
Tullio = "0.3.4"
julia = "1.7"
Expand Down
14 changes: 7 additions & 7 deletions docs/src/man/basics/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## General

```@docs
FluidVolume
JutulDarcy.FluidVolume
```

## Reservoir parameters
Expand All @@ -15,20 +15,20 @@ JutulDarcy.Transmissibilities
```

```@docs
reservoir_transmissibility
JutulDarcy.reservoir_transmissibility
```

### Other

```@docs
TwoPointGravityDifference
ConnateWater
EndPointScalingCoefficients
JutulDarcy.TwoPointGravityDifference
JutulDarcy.ConnateWater
JutulDarcy.EndPointScalingCoefficients
```

## Well parameters

```@docs
WellIndices
PerforationGravityDifference
JutulDarcy.WellIndices
JutulDarcy.PerforationGravityDifference
```
19 changes: 18 additions & 1 deletion src/facility/controls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,11 @@ function translate_limit(control::InjectorControl, name, val)
# Lower limit, total volumetric surface rate
target_limit = TotalRateTarget(val)
is_lower = true
elseif name == :resv_rate
# Upper limit, total volumetric reservoir rate
target_limit = TotalReservoirRateTarget(val)
else
error("$name limit not supported for well acting as producer.")
error("$name limit not supported for well acting as injector.")
end
return (target_limit, is_lower)
end
Expand Down Expand Up @@ -246,6 +249,20 @@ function well_target(control::InjectorControl, target::SurfaceVolumeTarget, well
return t/control.mixture_density
end


"""
Well target contribution from well itself (reservoir volume, injector)
"""
function well_target(control::InjectorControl, target::TotalReservoirRateTarget, well_model, well_state, surface_densities, surface_volume_fractions)
w_phases = get_phases(flow_system(well_model.system))
t = 0.0
rho = well_state.PhaseMassDensities
for (ix, mix) in control.phases
t += mix/rho[ix, 1]
end
return t
end

"""
Well target contribution from well itself (surface volume, injector)
"""
Expand Down
28 changes: 28 additions & 0 deletions src/facility/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,23 @@ struct TotalRateTarget{T} <: SurfaceVolumeTarget where T<:AbstractFloat
end
Base.show(io::IO, t::TotalRateTarget) = print(io, "TotalRateTarget with value $(t.value) [m^3/s]")

"""
TotalReservoirRateTarget(q)
Well target of specified total rate (sum of all phases) with value `q` at reservoir
conditions.
Often used for both [`InjectorControl`](@ref) [`ProducerControl`](@ref).
"""
struct TotalReservoirRateTarget{T} <: WellTarget where T<:AbstractFloat
value::T
function TotalReservoirRateTarget(v::T) where T
isfinite(v) || throw(ArgumentError("Rate must be finite, was $v"))'
return new{T}(v)
end
end
Base.show(io::IO, t::TotalReservoirRateTarget) = print(io, "TotalReservoirRateTarget with value $(t.value) [m^3/s]")

"""
HistoricalReservoirVoidageTarget(q, weights)
Expand Down Expand Up @@ -565,6 +582,17 @@ function well_target_information(t::Union{TotalRateTarget, Val{:rate}})
)
end


function well_target_information(t::Union{TotalReservoirRateTarget, Val{:resv_rate}})
return well_target_information(
symbol = :resv_rate,
description = "Surface total rate",
explanation = "Total volumetric rate at reservoir conditions. This is the sum of all phases. For most models, it is the sum of the mass rates divided by the prescribed surface densities.",
unit_type = :reservoir_volume_per_time,
unit_label = "m³/s"
)
end

function well_target_information(t::Union{SurfaceWaterRateTarget, Val{:wrat}})
return well_target_information(
symbol = :wrat,
Expand Down
22 changes: 18 additions & 4 deletions src/init/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,28 @@ function equilibriate_state!(init, depths, model, sys, contacts, depth, datum_pr
s_eval = zeros(nph, nc_total)
s_eval[:, cells] .= s
phases = get_phases(sys)
if length(phases) == 3 && AqueousPhase() in phases
phase_ind = phase_indices(model.system)
if length(phases) == 3
swcon = zeros(nc_total)
if !ismissing(s_min)
if AqueousPhase() in phases && !ismissing(s_min)
swcon[cells] .= s_min[1]
end
evaluate_relative_permeability_no_scaling!(kr, relperm, model, s_eval, cells, swcon)
for c in cells
update_three_phase_relperm!(kr, relperm, phase_ind, s_eval, nothing, c, swcon[c], nothing, nothing)
end
else
evaluate_relative_permeability_no_scaling!(kr, relperm, model, s_eval, cells)
ph = relperm.phases
if ph == :wo
kr1, kr2 = relperm.krw, relperm.krow
elseif ph == :og
kr1, kr2 = relperm.krog, relperm.krg
else
@assert ph == :wg
kr1, kr2 = relperm.krw, relperm.krg
end
for c in cells
update_two_phase_relperm!(kr, relperm, kr1, kr2, nothing, nothing, phase_ind, s_eval, nothing, c, nothing, nothing)
end
end
kr = kr[:, cells]
init[:Saturations] = s
Expand Down
11 changes: 9 additions & 2 deletions src/input_simulation/data_input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1601,8 +1601,8 @@ function injector_limits(; bhp = Inf, surface_rate = Inf, reservoir_rate = Inf)
if isfinite(surface_rate)
lims[:rate] = surface_rate
end
if !isinf(reservoir_rate)
@warn "Non-defaulted reservoir rate limit not supported: $reservoir_rate"
if isfinite(reservoir_rate)
lims[:resv_rate] = reservoir_rate
end
return NamedTuple(pairs(lims))
end
Expand All @@ -1629,6 +1629,13 @@ function injector_control(sys, streams, name, flag, type, ctype, surf_rate, res_
else
well_is_disabled = true
end
elseif ctype == "RESV"
is_rate = false
if isfinite(res_rate) && res_rate > MIN_ACTIVE_WELL_RATE
t = TotalReservoirRateTarget(res_rate)
else
well_is_disabled = true
end
else
# RESV, GRUP, THP
error("$ctype control not supported")
Expand Down
Loading

2 comments on commit b2150a0

@moyner
Copy link
Member Author

@moyner moyner commented on b2150a0 Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Changes

  • Rewritten rel. perm. code, should support all phase combinations
  • Hysteresis support for relative permeabilities (Killough, Carlsen, Jargon and pure imbibition with drainage equilibriation). Compatible with endpoint scaling.
  • Support for injection at reservoir conditions (RESV-type)
  • Improved docs & tests

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112295

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.27 -m "<description of version>" b2150a0f25fe15228fe94abeb3567750adcd37a4
git push origin v0.2.27

Please sign in to comment.