-
Notifications
You must be signed in to change notification settings - Fork 9
/
capacityEstimate.m
411 lines (322 loc) · 17.3 KB
/
capacityEstimate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
function exploreCapacity(varargin)
% opt - structure containing variables that can be overridden by user at
% command line
% var - structure containing variables that user cannot override at command
% line
gravity on;
% Initializing 'opt'
rhoCref = 760 * kilogram / meter ^3;
opt.grid_coarsening = 2;
opt.default_formation = 'Sognefjordfm';
opt.window_size = [1024 768];
opt.seafloor_depth = 100 * meter;
opt.seafloor_temp = 7; % in Celsius
opt.temp_gradient = 35.6; % degrees per kilometer
opt.water_density = 1000; % kg per m3
opt.press_deviation = 0; % pressure devation from hydrostatic (percent)
opt.res_sat_co2 = 0.21;
opt.res_sat_wat = 0.11;
opt.dis_max = (53 * kilogram / meter^3) / rhoCref; % value from CO2store
opt = merge_options(opt, varargin{:});
% Initializing 'var'
var.Gt_cached = struct();
var.current_formation = '';
var.co2 = CO2props('sharp_phase_boundary', true);
set_formation(opt.default_formation, false);
%% Setting up interactive interface
var.h = figure('KeyPressFcn', @(obj, e) parse_keypress(e.Key));
set_size(var.h, opt.window_size(1), opt.window_size(2));
% Graphical window
var.ax = axes('parent', var.h, 'position', [0.05, 0.12, 0.5, 0.87]);
% Formation selection
names = formation_names();
fsel = uicontrol('parent', var.h, ...
'style', 'popup', ...
'units', 'normalized', ...
'position', [0.05, 0.0 0.3 0.05], ...
'string', listify(names), ...
'value', formation_number(var.current_formation));
set (fsel, 'Callback', @(es, ed) set_formation(names{get(es, 'Value')}, true));
% Radiobuttons for selection of data to map
buttons = setup_button_group([.625, .60, .3, .38]);
% Set sliders
[s1, l1, v1] = add_slider('Temperature gradient (deg. C per km)', 'temp_gradient', 10, 50, [.59, .5, .35, .03]);%#ok
[s2, l2, v2] = add_slider('Pressure deviation from hydrostatic (%)', 'press_deviation', -50, 50, [.59, .43, .35, .03]);%#ok
[s3, l3, v3] = add_slider('Residual CO2 saturation', 'res_sat_co2', 0, 0.5, [.59, .36, .35, .03]);%#ok
[s4, l4, v4] = add_slider('Residual brine saturation', 'res_sat_wat', 0, 0.5, [.59, .29, .35, .03]);%#ok
[s5, l5, v5] = add_slider('Max dissolution', 'dis_max', 0, (100*kilogram/meter^3)/rhoCref, [.59, .22, .35, .03]);%#ok
% Total figure reporting window
rep_area = uicontrol('parent', var.h, ...
'style', 'text', ...
'units', 'normalized', ...
'position', [0.59, 0.02, 0.35, 0.16], ...
'horizontalalignment', 'left', ...
'fontsize', 12, ...
'string', 'uninitialized');
%% Launching by calling redraw function
redraw();
% ============================= HELPER FUNCTIONS =============================
function p = compute_pressure()
Gt = var.Gt_cached.(var.current_formation).Gt;
p = (Gt.cells.z * opt.water_density * norm(gravity)).* (1+opt.press_deviation/100);
end
% ----------------------------------------------------------------------------
function t = compute_temperature()
% NB: returns value in Celsius, not Kelvin
Gt = var.Gt_cached.(var.current_formation).Gt;
t = opt.seafloor_temp + (Gt.cells.z - opt.seafloor_depth) .* opt.temp_gradient ./ 1000;
end
% ----------------------------------------------------------------------------
function cum_cap = compute_cumul_trapcap()
[~, strap] = recompute_trapcap();
Gt = var.Gt_cached.(var.current_formation).Gt;
ta = var.Gt_cached.(var.current_formation).ta;
trees = maximizeTrapping(Gt, 'res', ta, 'calculateAll', true, 'removeOverlap', false);
tvols = [trees.value];%#ok
int_tr = find(ta.trap_regions); %#ok ixs of cells spilling into interior trap
[dummy, reindex] = sort([trees.root], 'ascend');%#ok
cum_cap = zeros(Gt.cells.num, 1);
for i = 1:numel(ta.trap_z) % loop over each trap
% ix of cells spilling directly into this trap
cix = find(ta.trap_regions == i);
% cell indices of all cells of this trap, and its upstream traps
aix = find(ismember(ta.traps, [trees(reindex(i)).traps]));
% compute total structural trap capacity (in mass terms) of these
% cells, and store result
cum_cap(cix) = sum(strap(aix));%#ok
end
end
% ----------------------------------------------------------------------------
function [H1, strap, btrap_res, btrap_dis] = recompute_trapcap()
p = compute_pressure();
t = compute_temperature() + 273.15;
Gt = var.Gt_cached.(var.current_formation).Gt;
ta = var.Gt_cached.(var.current_formation).ta;
poro = var.Gt_cached.(var.current_formation).poro;
% computing structural trap heights (H1) for each cell
trapcells = find(ta.traps);
H1 = zeros(Gt.cells.num, 1);
if ~isempty(trapcells)
H1(trapcells) = ta.trap_z(ta.traps(trapcells)) - Gt.cells.z(trapcells);
end
H1=min(H1,Gt.cells.H);
H2 = Gt.cells.H - H1;
assert(all(H1<=Gt.cells.H));
% Computing total trapping volume in structural traps (dissolved and
% structurally trapped
strap_pvol_tot = Gt.cells.volumes .* H1 .* poro;
strap_pvol_co2_plume = strap_pvol_tot .* (1 - opt.res_sat_wat);
strap_pvol_co2_diss = strap_pvol_tot .* opt.res_sat_wat .* opt.dis_max;
strap = strap_pvol_co2_plume .* var.co2.rho(p,t) + ...
strap_pvol_co2_diss .* rhoCref;
% Computing total trapping volume below structural traps (dissolved and
% residually trapped
btrap_pvol_tot = Gt.cells.volumes .* H2 .* poro;
btrap_pvol_co2_residual = btrap_pvol_tot .* opt.res_sat_co2;
btrap_pvol_co2_dissol = btrap_pvol_tot .* (1-opt.res_sat_co2) .* opt.dis_max;
btrap_res = btrap_pvol_co2_residual .* var.co2.rho(p,t);
btrap_dis = btrap_pvol_co2_dissol .* rhoCref;
end
% ----------------------------------------------------------------------------
function [slider, label, vdisplay] = add_slider(label, field, minval, maxval, pos)
slider = uicontrol('parent', var.h, ...
'style', 'slider', ...
'units', 'normalized', ...
'position', pos, ...
'value', opt.(field), ...
'min', minval, ...
'max', maxval);
label = uicontrol('parent', var.h, ...
'style', 'text', ...
'units', 'normalized', ...
'position', [pos(1), pos(2) + pos(4), pos(3), pos(4)], ...
'horizontalalignment', 'left', ...
'string', label);
set(label, 'BackgroundColor', get(gcf, 'color'));
vdisplay = uicontrol('parent', var.h, ...
'style', 'text', ...
'units', 'normalized', ...
'position', [pos(1) + pos(3) + 0.01, pos(2) - 0.005, 0.05, pos(4)], ...
'horizontalalignment', 'left', ...
'string', num2str(opt.(field)));
set(vdisplay, 'BackgroundColor', get(gcf, 'color'));
set(slider, 'Callback', @(es, ed) update_after_slider_change(get(es, 'Value'), vdisplay, field));
end
% ----------------------------------------------------------------------------
function update_after_slider_change(val, vdisp, field)
opt.(field) = val;
set(vdisp, 'string', sprintf('%6.2f',val));
redraw();
end
% ----------------------------------------------------------------------------
function bgroup = setup_button_group(pos)
% Create radiobutton group
bgroup = uibuttongroup('Visible', 'off', ...
'units', 'normalized', ...
'position', pos, ...
'SelectionChangeFcn', @redraw);
% Create radiobuttons
r1 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'caprock depth (m)', ...
'units', 'normalized', ...
'position', [0.1, 0.07, 0.8 0.1], ...
'HandleVisibility', 'off'); %#ok
r2 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'formation thickness (m)', ...
'units', 'normalized', ...
'position', [0.1, 0.16, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
r3 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'caprock temperature (C)', ...
'units', 'normalized', ...
'position', [0.1, 0.25, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
r4 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'caprock pressure (MPa)', ...
'units', 'normalized', ...
'position', [0.1, 0.34, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
r5 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'caprock topography', ...
'units', 'normalized', ...
'position', [0.1, 0.43, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
r6 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'caprock co2 density (kg/m3)', ...
'units', 'normalized', ...
'position', [0.1, 0.52, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
r7 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'total capacity (tonnes/m2)', ...
'units', 'normalized', ...
'position', [0.1, 0.61, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
r8 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'structural trap capacity (Mt)', ...
'units', 'normalized', ...
'position', [0.1, 0.70, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
r9 = uicontrol(bgroup, 'style', 'radiobutton', ...
'string', 'reachable structural capacity (Mt)', ...
'units', 'normalized', ...
'position', [0.1, 0.79, 0.8, 0.1], ...
'HandleVisibility', 'off'); %#ok
set(bgroup, 'Visible', 'on');
end
% ----------------------------------------------------------------------------
function parse_keypress(key)
% Handling of keypresses should go in here. Dummy for now.
switch key
case 'uparrow'
case 'downarrow'
case 'leftarrow'
case 'rightarrow'
end
end
% ----------------------------------------------------------------------------
function set_formation(name, do_redraw)
default_poro = 0.2;
var.current_formation = name;
if ~isfield(var.Gt_cached, var.current_formation)
[Gt, rock] = getFormationTopGrid(var.current_formation, opt.grid_coarsening);
var.Gt_cached.(var.current_formation).Gt = Gt;
var.Gt_cached.(var.current_formation).poro = rock.poro;
var.Gt_cached.(var.current_formation).ta = trapAnalysis(Gt, false);
end
if any(isnan(var.Gt_cached.(var.current_formation).poro))
assert(all(isnan(var.Gt_cached.(var.current_formation).poro)));
warning(['NaN porosity value encountered. Replacing with default ' ...
'value']);
var.Gt_cached.(var.current_formation).poro = default_poro;
end
if do_redraw
redraw();
end
end
% ----------------------------------------------------------------------------
function str = capacity_report()
[~, strap, btrap_res, btrap_dis] = recompute_trapcap();
tot_trap_capa = strap + btrap_res + btrap_dis;
sum_tot = sum(tot_trap_capa);
str = sprintf('Total trapping capacity: %.2f Gtons\n\n', sum_tot / giga / 1e3);
str = [str, sprintf('Breakdown:\n')];
str = [str, sprintf('Structural: %.2f Gtons (%5.2f%%)\n', sum(strap) / giga / 1e3, (sum(strap) / sum_tot) * 100)];
str = [str, sprintf('Residual: %.2f Gtons (%5.2f%%)\n', sum(btrap_res) / giga / 1e3, sum(btrap_res / sum_tot) * 100)];
str = [str, sprintf('Dissolved: %.2f Gtons (%5.2f%%)\n', sum(btrap_dis) / giga / 1e3, sum(btrap_dis / sum_tot) * 100)];
end
% ----------------------------------------------------------------------------
function redraw(varargin)
axes(var.ax); cla;
axis auto;
Gt = var.Gt_cached.(var.current_formation).Gt;
ta = var.Gt_cached.(var.current_formation).ta;
% Report total trapping figures
set(rep_area, 'string', capacity_report());
% Determine what to plot
switch (get(get(buttons, 'selectedobject'), 'String'))
case 'caprock depth (m)'
plotCellData(Gt.parent, Gt.cells.z, 'edgealpha', 0.2);
colorbar; rotate3d on;
case 'formation thickness (m)'
plotCellData(Gt.parent, Gt.cells.H, 'edgealpha', 0.2);
colorbar; rotate3d on;
case 'caprock temperature (C)'
plotCellData(Gt.parent, compute_temperature(), 'edgealpha', 0.2);
colorbar; rotate3d on;
case 'caprock pressure (MPa)'
plotCellData(Gt.parent, compute_pressure() / 1e6, 'edgealpha', 0.2);
colorbar; rotate3d on;
case 'caprock topography'
colorbar('off'); rotate3d off; view(0, 90);
mapPlot(gcf, Gt, 'traps', ta.traps, 'rivers', ta.cell_lines);
case 'caprock co2 density (kg/m3)'
t = opt.seafloor_temp + (Gt.cells.z - opt.seafloor_depth) .* opt.temp_gradient ./ 1000;
p = (Gt.cells.z * opt.water_density * norm(gravity)) .* (1+opt.press_deviation/100);
plotCellData(Gt.parent, var.co2.rho(p, t + 273.15), 'edgealpha', 0.2);
colorbar; rotate3d on;
case 'total capacity (tonnes/m2)'
[~, strap, btrap_res, btrap_dis] = recompute_trapcap();
tot_cap = (strap + btrap_res + btrap_dis) ./ Gt.cells.volumes ./ 1e3;
plotCellData(Gt.parent, tot_cap, 'edgealpha', 0.2);
colorbar; rotate3d on;
case 'structural trap capacity (Mt)'
trapcells = ta.traps~=0;
[~, strap] = recompute_trapcap();
trapcaps = accumarray(ta.traps(trapcells), strap(trapcells));
trapcap_tot = ones(size(ta.traps)) * NaN;
trapcap_tot(trapcells) = trapcaps(ta.traps(trapcells));
plotGrid(Gt.parent, 'facecolor','none', 'edgealpha', 0.1);
plotCellData(Gt.parent, trapcap_tot/1e3/1e6, 'edgecolor','none');
colorbar; rotate3d on;
case 'reachable structural capacity (Mt)'
cumul_trap = compute_cumul_trapcap();
plotCellData(Gt.parent, cumul_trap/1e9, 'edgealpha', 0.2);
colorbar; rotate3d on;
end
% plotGrid(var.Gt_cached.(var.current_formation).Gt);
end
end
% ============================================================================
function num = formation_number(name)
num = find(cellfun(@(x) strcmpi(x, name), formation_names()), 1);
end
% ----------------------------------------------------------------------------
function str = listify(names)
str = cellfun(@(x) [x,'|'], names, 'uniformoutput', false);
str = [str{:}];
str = str(1:end-1);
end
% ----------------------------------------------------------------------------
function names = formation_names()
names = {'Brentgrp', 'Brynefm', 'Fensfjordfm', 'Gassumfm', 'Huginfmeast', ...
'Huginfmwest', 'Johansenfm', 'Krossfjordfm', 'Pliocenesand', ...
'Sandnesfm', 'Skadefm', 'Sleipnerfm', 'Sognefjordfm', 'Statfjordfm', ...
'Ulafm', 'Utsirafm', 'Stofm', 'Nordmelafm', 'Tubaenfm', ...
'Bjarmelandfm', 'Arefm', 'Garnfm', 'Ilefm', 'Tiljefm'};
end
% ----------------------------------------------------------------------------
function h = set_size(h, res_x, res_y)
% Utility function to resize a graphical window
pos = get(h, 'position');
set(h, 'position', [pos(1:2), res_x, res_y]);
end