Skip to content

Commit a9c26ac

Browse files
committed
feat(options): ✨ save sub-saturations from MIP step
Adds support for saving MIP step sub-saturations Introduces an option to save sub-saturations during the MIP step. Updates the `Options` class to include a `save_mip_step` method and a corresponding flag. Modifies related functions to handle and store sub-saturation data when the option is enabled. Enhances debugging and analysis capabilities by retaining intermediate MIP results. Enables a posteriori downscaling capabilities.
1 parent 78be939 commit a9c26ac

File tree

5 files changed

+34
-5
lines changed

5 files changed

+34
-5
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"plot",
99
"matlab",
1010
"export",
11-
"matlab-repo-init"
11+
"matlab-repo-init",
12+
"options"
1213
]
1314
}

demo.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ function demo(args)
3737

3838
sub_rock = downscale_all(grid,rock,mask,downscale_params);
3939

40+
options = Options().save_mip_step(true);
41+
4042
strata_trapped = strata_trapper(grid, sub_rock, params, ...
41-
mask=mask, options=Options(), ...
43+
mask=mask, options=options, ...
4244
enable_waitbar=args.show_progress,...
4345
parfor_arg=args.parfor_arg...
4446
);

src/Options.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,12 @@
33
sat_num_points (1,1) uint32 {mustBePositive} = 40
44
sat_tol (1,1) double {mustBeNonnegative} = 1e-4
55
hydrostatic_correction (1,1) logical = false
6+
m_save_mip_step (1,1) {mustBeOfClass(m_save_mip_step,'logical')} = false;
7+
end
8+
9+
methods % builders
10+
function self = save_mip_step(self,flag)
11+
self.m_save_mip_step = flag;
12+
end
613
end
714
end

src/upscale.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function [perm_upscaled, pc_upscaled, krw, krg] = upscale(...
1+
function [perm_upscaled, pc_upscaled, krw, krg, mip] = upscale(...
22
dr, saturations, params, options, porosities, permeabilities)
33

44
if max(porosities,[],'all') <= 0
@@ -28,6 +28,8 @@
2828
pc_max = params.cap_pressure.func(params.sw_resid,porosities,permeabilities);
2929
pc_points = linspace(max(pc_max(isfinite(pc_max))),min(entry_pressures(:)),length(saturations));
3030

31+
mip(1:length(saturations)) = struct('sw',nan,'sub_sw',[]);
32+
3133
for index_saturation = 1:length(saturations)
3234

3335
sw_target = saturations(index_saturation);
@@ -65,6 +67,11 @@
6567

6668
[krg(:,index_saturation), krw(:,index_saturation)] = calc_relative_permeabilities( ...
6769
dr_sub, perm_upscaled_mD, Kg_sub_mD, Kw_sub_mD);
70+
71+
if options.m_save_mip_step
72+
mip(index_saturation).sw = sw_mid;
73+
mip(index_saturation).sub_sw = sub_sw;
74+
end
6875
end
6976

7077
% NOTE: we expect only small negative values as computational errors
@@ -128,6 +135,7 @@
128135
sub_sw(~isfinite(sub_sw)) = 1;
129136
sw_mid = sum(sub_sw.*pore_volumes,'all')/pore_volume;
130137

138+
% FIXME: Pc should converge as well as Sw
131139
pc_mid_tot = sum((1-sub_sw).*pore_volumes.*pc_mid,"all")/(pore_volume*(1-sw_mid));
132140

133141
if sw_mid >=1

strata_trapper.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,26 @@
3535
num_sub = zeros(subset_len,1);
3636
elapsed = zeros(subset_len,1);
3737

38+
if options.m_save_mip_step
39+
mip(1:subset_len,1:numel(saturations)) = struct('sw',nan,'sub_sw',[]);
40+
else
41+
mip = struct([]);
42+
end
43+
3844
% for cell_index = 1:subset_len
3945
parfor (cell_index = 1:subset_len, args.parfor_arg)
4046
sub_porosity = sub_rock(cell_index).poro;
4147
sub_permeability = sub_rock(cell_index).perm;
4248

4349
timer_start = tic;
4450

45-
[perm_upscaled_cell, pc_upscaled, krw_cell, krg_cell] = upscale(...
51+
[perm_upscaled_cell, pc_upscaled, krw_cell, krg_cell, mip_cell] = upscale(...
4652
DR(cell_index,:), saturations, params, options, sub_porosity, sub_permeability);
4753

54+
if options.m_save_mip_step
55+
mip(cell_index,:) = mip_cell;
56+
end
57+
4858
for i = 1:3
4959
krg_cell(i,:) = monotonize(saturations, krg_cell(i,:), -1);
5060
end
@@ -78,7 +88,8 @@
7888
'porosity',poro_upscaled, ...
7989
'params', params, ...
8090
'options', args.options, ...
81-
'grid', grid ...
91+
'grid', grid, ...
92+
'mip', mip ...
8293
);
8394

8495
perf.num_coarse = subset_len;

0 commit comments

Comments
 (0)