Skip to content

Commit

Permalink
Merge pull request #40 from sintefmath/fix-mrst-output
Browse files Browse the repository at this point in the history
Fix MRST output writing
  • Loading branch information
moyner authored Apr 14, 2024
2 parents e20031f + bb3026a commit 2796645
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 23 deletions.
2 changes: 1 addition & 1 deletion 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.21"
version = "0.2.22"

[deps]
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
Expand Down
76 changes: 54 additions & 22 deletions src/input_simulation/mrst_input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1340,13 +1340,14 @@ function mrst_well_ctrl(model, wdata, is_comp, rhoS)
end

"""
simulate_mrst_case(file_name)
ws, states = simulate_mrst_case(file_name)
simulate_mrst_case(file_name; <keyword arguments>)
Simulate a MRST case from `file_name` as exported by `writeJutulInput` in MRST.
# Arguments
- `file_name::String`: The path to a `.mat` file that is to be simulated.
- `file_name::String`: The path to a `.mat` or `.data` file that is to be
simulated.
# Keyword arguments
- `extra_outputs::Vector{Symbol} = [:Saturations]`: Additional variables to
Expand Down Expand Up @@ -1395,7 +1396,11 @@ function simulate_mrst_case(fn; extra_outputs::Vector{Symbol} = [:Saturations],
plot = false,
linear_solver = :bicgstab,
kwarg...)
fn = get_mrst_input_path(fn)
ext = lowercase(last(splitext(fn)))
is_data = ext == ".data"
if !is_data
fn = get_mrst_input_path(fn)
end
if split_wells
fg = :perwell
else
Expand All @@ -1412,20 +1417,46 @@ function simulate_mrst_case(fn; extra_outputs::Vector{Symbol} = [:Saturations],
@info "This is the first call to simulate_mrst_case. Compilation may take some time..." maxlog = 1
end
block_backend = linear_solver != :direct && linear_solver != :lu
case, mrst_data = setup_case_from_mrst(fn, block_backend = block_backend, steps = steps,
backend = backend,
nthreads = nthreads,
split_wells = split_wells,
facility_grouping = fg,
general_ad = general_ad,
minbatch = minbatch,
wells = wells,
dp_max_abs = dp_max_abs,
dp_max_rel = dp_max_rel,
p_min = p_min,
p_max = p_max,
dz_max = dz_max,
ds_max = ds_max);
if is_data
case, deck = setup_case_from_data_file(fn,
block_backend = block_backend,
include_data = true,
steps = steps,
backend = backend,
nthreads = nthreads,
split_wells = split_wells,
facility_grouping = fg,
general_ad = general_ad,
minbatch = minbatch,
dp_max_abs = dp_max_abs,
dp_max_rel = dp_max_rel,
p_min = p_min,
p_max = p_max,
dz_max = dz_max,
ds_max = ds_max
)
# A bit of a hack
mrst_data = deck
else
case, mrst_data = setup_case_from_mrst(fn,
block_backend = block_backend,
steps = steps,
backend = backend,
nthreads = nthreads,
split_wells = split_wells,
facility_grouping = fg,
general_ad = general_ad,
minbatch = minbatch,
wells = wells,
dp_max_abs = dp_max_abs,
dp_max_rel = dp_max_rel,
p_min = p_min,
p_max = p_max,
dz_max = dz_max,
ds_max = ds_max
)
deck = mrst_data["deck"]
end
model = case.model
forces = case.forces
dt = case.dt
Expand Down Expand Up @@ -1464,11 +1495,12 @@ function simulate_mrst_case(fn; extra_outputs::Vector{Symbol} = [:Saturations],
output_path = nothing
end
sim, cfg = setup_reservoir_simulator(
case,
case;
mode = mode,
linear_solver = linear_solver,
output_path = output_path;
kwarg...)
output_path = output_path,
kwarg...
)
M = first(values(models))
sys = M.system
if sys isa CompositionalSystem
Expand All @@ -1487,7 +1519,7 @@ function simulate_mrst_case(fn; extra_outputs::Vector{Symbol} = [:Saturations],
if verbose
jutul_message("MRST model", "Starting simulation of $s system with $nc cells and $nph phases and $ncomp components.")
end
rspec = mrst_data["deck"]["RUNSPEC"]
rspec = deck["RUNSPEC"]
if haskey(rspec, "START")
start = DateTime(0) + Day(rspec["START"])
else
Expand Down Expand Up @@ -1601,7 +1633,7 @@ function write_reservoir_simulator_output_to_mrst(model, states, reports, forces
end
states = states[ix]
reports = reports[ix]
wd = full_well_outputs(model, states, forces, shortname = true)
wd = full_well_outputs(model, states, forces)
wd_m = Dict{String, Any}()
for k in keys(wd)
tmp = Dict{String, Any}()
Expand Down
6 changes: 6 additions & 0 deletions test/mrst_cases.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,9 @@ end
@testset "Egg" begin
test_mrst_case("egg", otol = 0.02)
end

@testset "MRST simulations" begin
simulate_mrst_case("spe1", write_mrst = true, output_path = joinpath(tempdir(), "spe1"))
pth = JutulDarcy.GeoEnergyIO.test_input_file_path("spe1", "BENCH_SPE1.DATA")
simulate_mrst_case(pth, write_mrst = true, output_path = joinpath(tempdir(), "spe1_data"))
end

4 comments on commit 2796645

@moyner
Copy link
Member Author

@moyner moyner commented on 2796645 Apr 14, 2024

Choose a reason for hiding this comment

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

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

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

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.22 -m "<description of version>" 2796645f425806cc504d72336b3d8a9cc112d56e
git push origin v0.2.22

@moyner
Copy link
Member Author

@moyner moyner commented on 2796645 Apr 14, 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

@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 updated: JuliaRegistries/General/104895

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.22 -m "<description of version>" 2796645f425806cc504d72336b3d8a9cc112d56e
git push origin v0.2.22

Please sign in to comment.