Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyiyin97 committed Jan 27, 2023
1 parent 96c86c6 commit 74b61ed
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 8 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci-runtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI-JutulDarcyAD

on:
# Trigger the workflow on push to main or pull request
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
version:
- '1.7'

os:
- ubuntu-latest
- macos-latest
arch:
- x64

steps:
- name: Checkout JutulDarcyAD
uses: actions/checkout@v2

- name: Setup julia
uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}

- name: Build
uses: julia-actions/julia-buildpkg@latest

- name: Run tests
uses: julia-actions/julia-runtest@latest
28 changes: 23 additions & 5 deletions examples/inv_2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,23 @@ trans_z_init = reshape(x_init[(n[1]-1)*n[end]+1:end], n[1], n[end]-1)

fig=figure(figsize=(20,12));
subplot(1,3,1);
imshow(trans_x_init', vmin=minimum(trans_x), vmax=maximum(trans_x)); colorbar(); title("initial transmissibility")
imshow(trans_x_init', vmin=minimum(trans_x), vmax=maximum(trans_x)); colorbar(); title("initial transmissibility x")
subplot(1,3,2);
imshow(trans_x0', vmin=minimum(trans_x), vmax=maximum(trans_x)); colorbar(); title("inverted transmissibility")
imshow(trans_x0', vmin=minimum(trans_x), vmax=maximum(trans_x)); colorbar(); title("inverted transmissibility x")
subplot(1,3,3);
imshow(trans_x', vmin=minimum(trans_x), vmax=maximum(trans_x)); colorbar(); title("true transmissibility")
savefig("transx.png", bbox_inches="tight", dpi=300)
state0 = S(x0, q)
imshow(trans_x', vmin=minimum(trans_x), vmax=maximum(trans_x)); colorbar(); title("true transmissibility x")
savefig("trans_x.png", bbox_inches="tight", dpi=300)

fig=figure(figsize=(20,12));
subplot(1,3,1);
imshow(trans_z_init', vmin=minimum(trans_z), vmax=maximum(trans_z)); colorbar(); title("initial transmissibility z")
subplot(1,3,2);
imshow(trans_z0', vmin=minimum(trans_z), vmax=maximum(trans_z)); colorbar(); title("inverted transmissibility z")
subplot(1,3,3);
imshow(trans_z', vmin=minimum(trans_z), vmax=maximum(trans_z)); colorbar(); title("true transmissibility z")
savefig("trans_z.png", bbox_inches="tight", dpi=300)

state0 = S(x0, q)

fig=figure(figsize=(20,12));
subplot(1,3,1);
Expand All @@ -103,4 +112,13 @@ subplot(1,3,2);
imshow(reshape(state0.states[end].Saturations, n[1], n[end])', vmin=0, vmax=1); colorbar(); title("inverted saturation")
subplot(1,3,3);
imshow(reshape(state.states[end].Saturations, n[1], n[end])', vmin=0, vmax=1); colorbar(); title("true saturation")
savefig("saturation.png", bbox_inches="tight", dpi=300)

fig=figure(figsize=(20,12));
subplot(1,3,1);
imshow(reshape(state_init.states[end].Pressure, n[1], n[end])', vmin=minimum(state.states[end].Pressure), vmax=maximum(state.states[end].Pressure)); colorbar(); title("initial pressure")
subplot(1,3,2);
imshow(reshape(state0.states[end].Pressure, n[1], n[end])', vmin=minimum(state.states[end].Pressure), vmax=maximum(state.states[end].Pressure)); colorbar(); title("inverted pressure")
subplot(1,3,3);
imshow(reshape(state.states[end].Pressure, n[1], n[end])', vmin=minimum(state.states[end].Pressure), vmax=maximum(state.states[end].Pressure)); colorbar(); title("true pressure")
savefig("pressure.png", bbox_inches="tight", dpi=300)
2 changes: 2 additions & 0 deletions src/FlowAD/Types/jutulForce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ function force(M::jutulModel{D, T}, f::jutulForce{D, T}; ρCO2::T=T(501.9)) wher
src = [SourceTerm(cell[i], f.irate[i] * ρCO2, fractional_flow = [T(f.irate[i] > 0), T(1)-T(f.irate[i] > 0)]) for i = 1:length(f.loc)]
return setup_forces(model, sources = src)
end

==(A::jutulForce{D, T}, B::jutulForce{D, T}) where {D,T} = (A.irate == B.irate && A.loc == B.loc)
4 changes: 3 additions & 1 deletion src/FlowAD/Types/jutulModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ function model_(M::jutulModel{D, T}) where {D, T}
model = SimulationModel(G, sys)
replace_variables!(model, RelativePermeabilities = kr)
return model
end
end

==(A::jutulModel{D, T}, B::jutulModel{D, T}) where {D,T} = (A.n == B.n && A.d == B.d && A.ϕ == B.ϕ && A.K == B.K)
4 changes: 3 additions & 1 deletion src/FlowAD/Types/jutulState.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,6 @@ for op in [:+, :-, :*, :/]
@eval function $(op)(A::jutulAllState{T}, B::jutulAllState{T}) where T
return A(broadcast($(op), vec(A), vec(B)))
end
end
end

==(A::jutulAllState{T}, B::jutulAllState{T}) where {T} = vec(A) == vec(B)
2 changes: 1 addition & 1 deletion src/JutulDarcyAD.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module JutulDarcyAD
using ChainRulesCore
import Jutul: JutulGeometry, get_facepos, compute_face_trans, compute_half_face_trans, expand_perm
import Jutul: SimulationModel
import Base: +, -, *, /
import Base: +, -, *, /, ==
import Base: display, length, size, getindex, setindex!, IndexStyle, vec, firstindex, lastindex
import LinearAlgebra: norm, dot
import ChainRulesCore: rrule
Expand Down
3 changes: 3 additions & 0 deletions test/runtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ include("test_utils.jl")

include("test_conversion.jl")
include("test_jutulState.jl")
include("test_jutulForce.jl")
include("test_jutulModel.jl")

include("test_gradient.jl")
10 changes: 10 additions & 0 deletions test/test_jutulForce.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@testset "Test jutulForce" begin

d = (1.0, 20.0, 3.0)
inj_loc = (3, 1, 9) .* d
prod_loc = (28, 1, 9) .* d
irate = rand()
q = jutulForce(irate, [inj_loc, prod_loc])
q1 = jutulForce([irate, -irate], [inj_loc, prod_loc])
@test q == q1
end
17 changes: 17 additions & 0 deletions test/test_jutulModel.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@testset "Test jutulModel" begin

@info "set up model"
n = (rand(3:5), rand(3:5), rand(3:5))
d = 10 .* (rand(), rand(), rand())
K = 200 * rand() * md * ones(n)
ϕ = rand()
model = jutulModel(n, d, ϕ, K1to3(K))

@test model.n == n
@test model.d == d
@test model.ϕ == ϕ
@test model.K == K1to3(K)

model1 = jutulModel(n, d, ϕ, K1to3(K))
@test model1 == model
end
7 changes: 7 additions & 0 deletions test/test_jutulState.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@ model, init_state = setup_model_state()
init_state[rdm_idx] = rdm_num
@test init_state[rdm_idx] == rdm_num
@test vec(init_state) == init_state[1:end]

@info "test =="
init_state1 = deepcopy(init_state)
init_state1[1] = 0.2
@test init_state1 != init_state
init_state[1] = 0.2
@test init_state1 == init_state
end

0 comments on commit 74b61ed

Please sign in to comment.