|
1 | 1 | function [perm_upscaled, pc_upscaled, krw, krg, mip] = upscale(... |
2 | 2 | dr, saturations, params, options, porosities, permeabilities) |
| 3 | +arguments |
| 4 | + dr (1,3) double |
| 5 | + saturations (1, :) double |
| 6 | + params (1,1) Params |
| 7 | + options (1,1) Options |
| 8 | + porosities (:,:,:) double |
| 9 | + permeabilities (:,:,:,3) double |
| 10 | +end |
3 | 11 |
|
4 | 12 | if max(porosities,[],'all') <= 0 |
5 | 13 | error('inactive cell'); |
6 | 14 | end |
7 | 15 |
|
8 | | -mip(1:length(saturations)) = struct('sw',nan,'sub_sw',[]); |
| 16 | +mip = repmat(construct_mip_cell_data(),1,numel(saturations)); |
9 | 17 |
|
10 | 18 | % apply thresholds before proceeding |
11 | 19 | small_poro = porosities < options.m_poro_threshold; |
|
49 | 57 |
|
50 | 58 | entry_pressures = params.cap_pressure.func(1,porosities,permeabilities); |
51 | 59 | pc_max = params.cap_pressure.func(params.sw_resid,porosities,permeabilities); |
52 | | -pc_points = linspace(max(pc_max(isfinite(pc_max))),min(entry_pressures(:)),length(saturations)); |
| 60 | +is_pc_max_finite = isfinite(pc_max(:)); |
| 61 | +pc_max_finite = pc_max(:); |
| 62 | +pc_max_finite = pc_max_finite(is_pc_max_finite); |
| 63 | +pc_points = linspace(max(pc_max_finite),min(entry_pressures(:)),length(saturations)); |
53 | 64 |
|
54 | 65 | for index_saturation = 1:length(saturations) |
55 | 66 |
|
|
61 | 72 | calc_endpoint = index_saturation == 1 || index_saturation == length(saturations); |
62 | 73 | max_iterations = calc_endpoint*1000 + ~calc_endpoint*100; |
63 | 74 | err_prev = Inf; |
| 75 | + pc_mid_tot = 0; |
| 76 | + sub_sw = zeros(0,0,0); coder.varsize('sub_sw'); |
64 | 77 | for iteration_num=1:max_iterations |
65 | 78 | [pc_mid_tot, sw_mid, pc_mid, sub_sw, converged, err] = mip_iteration(... |
66 | 79 | sw_target, dr, entry_pressures, porosities, permeabilities, pc_mid, ... |
|
109 | 122 | pc_upscaled = [pc_upscaled,pc_upscaled_extra]; |
110 | 123 |
|
111 | 124 | sw_upscaled(end+1) = sw_extra(1); |
112 | | -krw(:,end+1) = 0; |
113 | | -krg(:,end+1) = max(params.krg.data(:,2)); |
| 125 | +krw = extend_cols_with(krw,0); |
| 126 | +krg = extend_cols_with(krg,max(params.krg.data(:,2))); |
114 | 127 |
|
115 | 128 | sw_upscaled(end+1) = sw_extra(2); |
116 | | -krw(:,end+1) = max(params.krw.data(:,2)); |
117 | | -krg(:,end+1) = 0; |
| 129 | +krw = extend_cols_with(krw,max(params.krw.data(:,2))); |
| 130 | +krg = extend_cols_with(krg,0); |
118 | 131 |
|
119 | 132 | [sw_upscaled,unique_idx] = unique(sw_upscaled); |
120 | 133 | pc_upscaled = pc_upscaled(unique_idx); |
|
205 | 218 | krw = K_phase_upscaled(4:6)'; |
206 | 219 |
|
207 | 220 | end |
| 221 | + |
| 222 | +function kr = extend_cols_with(kr,value) |
| 223 | +krx = kr(1,:); |
| 224 | +kry = kr(2,:); |
| 225 | +krz = kr(3,:); |
| 226 | + |
| 227 | +krx(end+1) = value; |
| 228 | +kry(end+1) = value; |
| 229 | +krz(end+1) = value; |
| 230 | +kr = [krx;kry;krz]; |
| 231 | +end |
| 232 | + |
| 233 | +function mip_cell_data = construct_mip_cell_data() |
| 234 | +sub_sw = zeros(0,0,0); |
| 235 | +coder.varsize('sub_sw'); |
| 236 | +mip_cell_data = struct('sw',nan,'sub_sw',sub_sw); |
| 237 | +end |
0 commit comments