Skip to content

Commit

Permalink
Merge pull request #19 from sintefmath/parse
Browse files Browse the repository at this point in the history
Support for parsing and simulating .DATA files
  • Loading branch information
moyner committed Aug 7, 2023
2 parents 2abfb1f + e9f8ef0 commit dfd4f51
Show file tree
Hide file tree
Showing 36 changed files with 3,633 additions and 92 deletions.
46 changes: 26 additions & 20 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
name = "JutulDarcy"
uuid = "82210473-ab04-4dce-b31b-11573c4f8e0a"
authors = ["Olav Møyner <[email protected]>"]
version = "0.2.7"
version = "0.2.8"

This comment has been minimized.

Copy link
@moyner

moyner Aug 7, 2023

Author Member

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Jutul = "2b460a1a-8a2b-45b2-b125-b5c536396eb9"
Krylov = "ba0b0d4f-ebba-5204-a429-3ac8c609bfb7"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
MAT = "23992714-dd62-5051-b70f-ba57cb901cac"
MultiComponentFlash = "35e5bd01-9722-4017-9deb-64a5d32478ff"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
Parsers = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
Polyester = "f517fe37-dbe3-4b94-8317-1923a5111588"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -23,44 +26,47 @@ TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"
Tullio = "bc48ee85-29a4-5162-ae0b-a64e1601d4bc"

[weakdeps]
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
HYPRE = "b5ffcf37-a2bd-41ab-a3da-4bd9bc8ad771"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"

[extensions]
JutulDarcyGLMakieExt = "GLMakie"
JutulDarcyHYPREExt = "HYPRE"
JutulDarcyPartitionedArraysExt = ["PartitionedArrays", "MPI", "HYPRE"]

[compat]
AlgebraicMultigrid = "0.5.1"
DataStructures = "0.18.13"
DelimitedFiles = "1.9.1"
ForwardDiff = "0.10.30"
Jutul = "0.2.10"
HYPRE = "1.4.0"
Jutul = "0.2.12"
Krylov = "0.9.1"
LoopVectorization = "0.12.115"
MAT = "0.10.3"
MultiComponentFlash = "1.1.3"
OrderedCollections = "1.6.2"
Parsers = "2.7.1"
PartitionedArrays = "0.3.2"
Polyester = "0.6.11, 0.7.3"
PrecompileTools = "1.0.1"
PartitionedArrays = "0.3.2"
StaticArrays = "1.4.4"
TestItems = "0.1.0"
TimerOutputs = "0.5.19"
Tullio = "0.3.4"
HYPRE = "1.4.0"
julia = "1.7"
Krylov = "0.9.1"

[extras]
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
HYPRE = "b5ffcf37-a2bd-41ab-a3da-4bd9bc8ad771"
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestItemRunner = "f8b46487-2199-4994-9208-9a1283c18c0a"
TestItems = "1c621080-faea-4a02-84b6-bbd5e436b8fe"

[targets]
test = ["Test", "TestItemRunner", "TestItems", "HYPRE", "MPI", "PartitionedArrays"]

[weakdeps]
GLMakie = "e9467ef8-e4e7-5192-8a1a-b1aee30e663a"
HYPRE = "b5ffcf37-a2bd-41ab-a3da-4bd9bc8ad771"
PartitionedArrays = "5a9dfac6-5c52-46f7-8278-5e2210713be9"
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"

[extensions]
JutulDarcyGLMakieExt = "GLMakie"
JutulDarcyHYPREExt = "HYPRE"
JutulDarcyPartitionedArraysExt = ["PartitionedArrays", "MPI", "HYPRE"]
2 changes: 1 addition & 1 deletion ext/JutulDarcyGLMakieExt/well_plots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ function JutulDarcy.plot_well_results(well_data::Vector, time = nothing; start_d
else
c_key = :Paired_10
end
cmap = cgrad(c_key, nw, categorical=true)
cmap = cgrad(c_key, max(nw, 2), categorical=true)
end
wellstr = [String(x) for x in wells]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module JutulDarcyPartitionedArraysExt
function Jutul.parray_preconditioner_apply!(global_out, main_prec::CPRPreconditioner{<:BoomerAMGPreconditioner, <:Any}, X, preconditioners, simulator, arg...)
global_cell_vector = simulator.storage.distributed_cell_buffer
global_buf = simulator.storage.distributed_residual_buffer
map(local_values(X), preconditioners, ghost_values(X)) do x, prec, x_g
@tic "cpr first stage" map(local_values(X), preconditioners, ghost_values(X)) do x, prec, x_g
@. x_g = 0.0
JutulDarcy.apply_cpr_first_stage!(prec, x, arg...)
nothing
Expand All @@ -49,7 +49,7 @@ module JutulDarcyPartitionedArraysExt
# copy!(global_cell_vector, main_prec.p)
p_h = main_prec.p
@assert !isnothing(p_h) "CPR is not properly initialized."
map(own_values(global_cell_vector), preconditioners) do ov, prec
@tic "hypre GetValues" map(own_values(global_cell_vector), preconditioners) do ov, prec
helper = prec.pressure_precond.data[:assembly_helper]
indices = helper.indices
indices::Vector{HYPRE.HYPRE_BigInt}
Expand All @@ -59,29 +59,27 @@ module JutulDarcyPartitionedArraysExt
# End unsafe shenanigans

# consistent!(global_cell_vector) |> wait
map(own_values(global_buf), own_values(global_cell_vector), preconditioners) do dx, dp, prec
@tic "set dp" map(own_values(global_buf), own_values(global_cell_vector), preconditioners) do dx, dp, prec
bz = prec.block_size
for i in eachindex(dp)
JutulDarcy.set_dp!(dx, bz, dp, i)
end
nothing
end
if main_prec.full_system_correction
mul_ix = nothing
else
mul_ix = 1

@tic "correct residual" begin
mul!(X, main_prec.A_ps, global_buf, -1.0, true)
nothing
end
full_op = Jutul.parray_linear_system_operator(simulator.storage.simulators, global_buf)
mul!(X, full_op, global_buf, -1.0, true)

map(local_values(global_out), local_values(X), preconditioners, local_values(global_cell_vector), ghost_values(X)) do y, x, prec, dp, x_g
@tic "increment dp" map(local_values(global_out), local_values(X), preconditioners, local_values(global_cell_vector), ghost_values(X)) do y, x, prec, dp, x_g
@. x_g = 0.0
apply!(y, prec.system_precond, x, arg...)
bz = prec.block_size
JutulDarcy.increment_pressure!(y, dp, bz)
nothing
end
consistent!(global_out) |> wait
@tic "communication" consistent!(global_out) |> wait
global_out
end

Expand All @@ -90,7 +88,7 @@ module JutulDarcyPartitionedArraysExt
n = sim.storage.nc_process
comm = sim.storage.comm
if sim.storage[:number_of_processes] > 1
@assert sim.backend isa Jutul.MPI_PArrayBackend "Cannot use HYPRE with emulated multiple processes."
@assert sim.backend isa Jutul.MPI_PArrayBackend "Cannot use HYPRE with emulated multiple processes. Backend was $(sim.backend)"
end

function create_hypre_vector()
Expand All @@ -104,16 +102,25 @@ module JutulDarcyPartitionedArraysExt
cpr.r_p = create_hypre_vector()
cpr.p = create_hypre_vector()
cpr.np = n
if cpr.full_system_correction
mul_ix = nothing
else
mul_ix = 1
end
global_buf = sim.storage.distributed_residual_buffer
cpr.A_ps = Jutul.parray_linear_system_operator(sim.storage.simulators, global_buf)
end
A_p = cpr.A_p
A_ps = cpr.A_ps
r_p = cpr.r_p
x_p = cpr.p

map(sim.storage.simulators, preconditioners) do sim, prec
sys = sim.storage.LinearizedSystem
model = sim.model
storage = sim.storage
storage = Jutul.get_simulator_storage(sim)
model = Jutul.get_simulator_model(sim)
sys = storage.LinearizedSystem
prec.A_p = A_p
prec.A_ps = A_ps
prec.p = x_p
prec.r_p = r_p
prec.np = n
Expand Down
6 changes: 6 additions & 0 deletions src/InputParser/InputParser.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module InputParser
using Parsers, DelimitedFiles, Jutul, OrderedCollections, Dates
export parse_data_file

include("deckinput/parser.jl")
end
62 changes: 62 additions & 0 deletions src/InputParser/deckinput/keywords/grid.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:INIT})
data["INIT"] = true
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:COORDSYS})
read_record(f)
@warn "COORDSYS skipped."
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:COORD})
coord = parse_deck_matrix(f, Float64)
coord = swap_unit_system!(coord, units, Val(:length))
data["COORD"] = coord
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:ZCORN})
zcorn = parse_deck_vector(f, Float64)
zcorn = swap_unit_system!(zcorn, units, Val(:length))
data["ZCORN"] = zcorn
end

function parse_keyword!(data, outer_data, units, cfg, f, v::Union{Val{:PERMX}, Val{:PERMY}, Val{:PERMZ}})
k = unpack_val(v)
vals = parse_grid_vector(f, get_cartdims(outer_data), Float64)
vals = swap_unit_system!(vals, units, Val(:permeability))
data["$k"] = vals
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:PORO})
data["PORO"] = parse_grid_vector(f, get_cartdims(outer_data), Float64)
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:NTG})
data["NTG"] = parse_grid_vector(f, get_cartdims(outer_data), Float64)
end

function parse_keyword!(data, outer_data, units, cfg, f, v::Union{Val{:DX}, Val{:DY}, Val{:DZ}})
k = unpack_val(v)
data["$k"] = parse_grid_vector(f, get_cartdims(outer_data), Float64)
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:TOPS})
tops = parse_deck_vector(f, Float64)
data["TOPS"] = swap_unit_system!(tops, units, Val(:length))
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:DIMENS})
rec = read_record(f)
to_int = x -> Parsers.parse(Int, x)
d = to_int.(filter!(x -> length(x) > 0, split(only(rec), DECK_SPLIT_REGEX)))
data["DIMENS"] = d
set_cartdims!(outer_data, d)
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:SPECGRID})
rec = read_record(f)
tdims = [1, 1, 1, 1, "F"]
data["SPECGRID"] = parse_defaulted_line(rec, tdims)
set_cartdims!(outer_data, data["SPECGRID"][1:3])
end

8 changes: 8 additions & 0 deletions src/InputParser/deckinput/keywords/keywords.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include("runspec.jl")
include("grid.jl")
include("props.jl")
include("regions.jl")
include("schedule.jl")
include("solution.jl")
include("summary.jl")
include("special.jl")
88 changes: 88 additions & 0 deletions src/InputParser/deckinput/keywords/props.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:RPTPROPS})
read_record(f)
end

function parse_keyword!(data, outer_data, units, cfg, f, v::Union{Val{:SWOF}, Val{:SGOF}})
k = unpack_val(v)
sat_tab = parse_saturation_table(f, outer_data)
for tab in sat_tab
swap_unit_system_axes!(tab, units, (:identity, :identity, :identity, :pressure))
end
data["$k"] = sat_tab
end


function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:PVDG})
pvdg = parse_dead_pvt_table(f, outer_data)
for tab in pvdg
swap_unit_system_axes!(tab, units, (:pressure, :gas_formation_volume_factor, :viscosity))
end
data["PVDG"] = pvdg
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:PVTO})
pvto = parse_live_pvt_table(f, outer_data)
for tab in pvto
swap_unit_system_axes!(tab["data"], units, (:pressure, :liquid_formation_volume_factor, :viscosity))
swap_unit_system!(tab["key"], units, :u_rs)
end
data["PVTO"] = pvto
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:PVTW})
rec = read_record(f)
tdims = [NaN, NaN, NaN, NaN, NaN]
utypes = (:pressure, :liquid_formation_volume_factor, :compressibility, :viscosity, :compressibility)
nreg = number_of_tables(outer_data, :pvt)
out = []
for i = 1:nreg
t = parse_defaulted_line(rec, tdims)
swap_unit_system_axes!(t, units, utypes)
@assert all(isfinite, t) "PVTW cannot be defaulted, found defaulted record in region $i"
push!(out, t)
end
data["PVTW"] = out
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:PVCDO})
rec = read_record(f)
tdims = [NaN, NaN, NaN, NaN, NaN]
utypes = (:pressure, :liquid_formation_volume_factor, :compressibility, :viscosity, :compressibility)
nreg = number_of_tables(outer_data, :pvt)
out = []
for i = 1:nreg
t = parse_defaulted_line(rec, tdims)
swap_unit_system_axes!(t, units, utypes)
@assert all(isfinite, t) "PVCDO cannot be defaulted, found defaulted record in region $i"
push!(out, t)
end
data["PVCDO"] = out
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:ROCK})
rec = read_record(f)
tdims = [NaN, NaN, NaN, NaN, NaN, NaN]
utypes = [:pressure, :compressibility, :compressibility, :compressibility, :id, :id]
out = []
nreg = number_of_tables(outer_data, :pvt)
for i = 1:nreg
l = parse_defaulted_line(rec, tdims)
swap_unit_system_axes!(l, units, utypes)
push!(out, l)
end
data["ROCK"] = out
end

function parse_keyword!(data, outer_data, units, cfg, f, ::Val{:DENSITY})
rec = read_record(f)
tdims = [NaN, NaN, NaN]
nreg = number_of_tables(outer_data, :pvt)
out = []
for i = 1:nreg
t = parse_defaulted_line(rec, tdims)
swap_unit_system!(t, units, :density)
push!(out, t)
end
data["DENSITY"] = out
end
Empty file.
Loading

1 comment on commit dfd4f51

@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/89193

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.8 -m "<description of version>" dfd4f51fc43df74e5a8a8de5932c46971e9b41f9
git push origin v0.2.8

Please sign in to comment.