rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
VelocitySpace.m
1 classdef VelocitySpace < ILocalizedOperator & ISeparableOperator
2 
3  properties (Constant)
4  id = 'L_velocity';
5 
6  ret_vars = {'velocity'};
7  arg_vars = {'saturation', 'pressure'};
8  arg_vars_short = {'S', 'P'};
9  end
10 
11  methods (Static)
12  function [cell_eind, cell_glob2loc, lind_cands, nind_cands] = compute_TM_global_pre(model_data, TM)
13  lind_cands = zeros(1, model_data.gn_edges);
14 
15  % valid boundary indices
16  vis = (model_data.gEI ~= 0);
17  % valid row indices
18  rowinds = repmat((1:size(model_data.gEI,1))', 1, 4);
19  vrowinds = rowinds(vis);
20  % valid col indices
21  colinds = repmat((1:4), size(model_data.gEI,1), 1);
22  vcolinds = colinds(vis);
23 
24  lind_cands(model_data.gEI(vis)) = vrowinds;
25  rind_cands = zeros(1, model_data.gn_edges);
26  rind_cands(model_data.gEI(vis)) = model_data.grid.NBI(vis);
27 
28  cell_eind = unique([lind_cands(TM), rind_cands(TM(TM <= model_data.gn_inner_edges))]);
29 
30  nind_cands = zeros(1, model_data.gn_edges);
31  nind_cands(model_data.gEI(vis)) = vcolinds;
32 
33  cell_glob2loc = zeros(max(cell_eind),1);
34  cell_glob2loc(cell_eind) = 1:length(cell_eind);
35 
36  end
37 
38  function [nmd] = compute_TM_global_grid(model_data, TM, cell_eind, cell_glob2loc, lind_cands, nind_cands)
39 
40  grid = model_data.grid;
41 
42  llind_cands = cell_glob2loc(lind_cands(TM));
43  lnind_cands = nind_cands(TM)';
44  if isa(grid,'rectgrid') || isa(grid,'triagrid') || isa(grid,'onedgrid')
45  nmd.grid_local_ext = gridpart(grid,cell_eind);
46 
47  gle = nmd.grid_local_ext;
48  mask = zeros(size(gle.NBI));
49  lr_inds = sub2ind(size(mask), llind_cands, lnind_cands);
50  mask(lr_inds) = 1;
51  lr_inds_pos = find(gle.NBI(lr_inds) > 0);
52  lr_inds_pos = lr_inds(lr_inds_pos);
53  mask(sub2ind(size(mask), gle.NBI(lr_inds_pos), gle.INB(lr_inds_pos))) = 1;
54  gle.NBI(~mask) = -20;
55 
56 % [tmp_i, tmp_j] = find(nmd.grid_local_ext.NBI(lrind_cands, :) < 0);
57 % nmd.grid_local_ext.NBI(sub2ind(size(nmd.grid_local_ext.NBI), lrind_cands, tmp_j)) = -10;
58 
59  [nmd.gEI, nmd.gn_inner_edges, nmd.gn_boundary_edges] ...
60  = compute_edge_indices(nmd.grid_local_ext);
61  nmd.gn_edges = nmd.gn_inner_edges + nmd.gn_boundary_edges;
62  else
63  error('unsupported grid');
64  end
65 
66  nmd.TM_global_args{1} = cell_eind;
67  nmd.TM_global_args{2} = cell_eind;
68 
69  end
70 
71  function eind_local = compute_TM_global_post(nmd, TM, cell_glob2loc, lind_cands, nind_cands)
72  subset = sub2ind(size(nmd.grid_local_ext.NBI), cell_glob2loc(lind_cands(TM)), nind_cands(TM)');
73  eind_local = nmd.gEI(subset);
74  end
75 
76  end
77 
78  methods
79  function [INC, INCoff, J] = apply(this, model, model_data, sim_data, NU_ind)
80  %function INC = apply(this, model, model_data, sim_data, NU_ind)
81 
82  S = sim_data.S;
83  P = sim_data.P;
84  if ~isfield(sim_data, 'n')
85  sim_data.n = model_data.gn_edges;
86  end
87 
88  if nargin <= 4 || isempty(NU_ind)
89  NU_ind = (1:sim_data.n);
90  end
91 
92  if ~isfield(sim_data, 'm')
93  sim_data.m = length(S) + length(P);
94  end
95 
96  num_diff_flux_u = fv_num_diff_flux_pressure_gradient(model, model_data, P, S);
97 
98  UKL = -num_diff_flux_u.G;
99 
100  INC = UKL(NU_ind);
101 
102  INCoff = [];
103 
104  if nargout > 2
105 
106  u_diff_p_s = fv_frechet_operators_diff_flux_pressure_gradient(model, model_data, P, S, NU_ind);
107 
108  n = length(NU_ind);
109  UN_ind = zeros(sim_data.n,1);
110  UN_ind(NU_ind) = 1:n;
111  if ~isfield(sim_data, 'Poff')
112  sim_data.Poff = length(S);
113  end
114  m = sim_data.m;
115 
116  sp21 = sparse(UN_ind(u_diff_p_s.si), u_diff_p_s.sj, u_diff_p_s.svals, n, m);
117  sp22 = sparse(UN_ind(u_diff_p_s.pi), u_diff_p_s.pj+sim_data.Poff, u_diff_p_s.pvals, n, m);
118  J = -(sp21+sp22);
119  end
120 
121  end
122 
123  function [LL, bb] = full_matrix(this, descr, model_data, params)
124 
125  grid = model_data.grid;
126  n = model_data.gn_edges;
127  if nargin <= 3
128  params = [];
129  end
130  if ~isfield(params, 'm')
131  params.m = grid.nelements;
132  end
133  u_diff_p_s = fv_frechet_operators_diff_flux_pressure_gradient(descr, model_data, ones(params.m, 1), ones(params.m, 1));
134 
135  LL = -sparse(u_diff_p_s.pi, u_diff_p_s.pj, u_diff_p_s.pvals, n, params.m);
136  bb = [];
137  end
138 
139  function [LL_comps, bb_comps] = components(this, descr, model_data)
140  [LL,bb] = full_matrix(this, descr, model_data);
141  LL_comps = {LL};
142  bb_comps = {bb};
143  end
144 
145  function [LL_coeffs, bb_coeffs] = coefficients(this, descr)
146  LL_coeffs = 1;
147  bb_coeffs = [];
148  end
149 
150 
151  function ret_size = ret_size(this, model_data, NU_ind)
152  if nargin == 2 || isempty(NU_ind)
153  NU_ind = 1:model_data.gn_edges;
154  end
155  ret_size = length(NU_ind);
156  end
157 
158  function arg_size = arg_size(this, model_data, NU_ind)
159  if nargin == 2 || isempty(NU_ind)
160  arg_size = 2* model_data.grid.nelements + model_data.gn_edges;
161  else
162  arg_size = 2 * model_data.grid.nelements + length(NU_ind);
163  end
164 
165  end
166 
167  function [LL_comps, bb_comps] = gram_project_components(this, rmodel, detailed_data)
168 
169  dd_prs = get_by_description(detailed_data, 'pressure');
170  RB_prs = dd_prs.RB;
171 
172  dd_vel = get_by_description(detailed_data, 'velocity');
173  RB_vel = dd_vel.RB;
174 
175  L_comps = components(this, rmodel.descr, dd_prs.model_data);
176  LL_comps = cellfun(@(X) X * RB_prs, L_comps, 'UniformOutput', false);
177 
178  A = inner_product_matrix(this, dd_prs.model_data);
179 
180  LL_comps = cellfun(@(X) RB_vel' * A * X, ...
181  LL_comps, 'UniformOutput', false);
182  bb_comps = {};
183  end
184 
185  function ipm = inner_product_matrix(this, model_data)
186 % ipm = 1;
187  ipm = model_data.diamondWinv;
188  end
189 
190  function [nmd, eind, eind_local] = compute_TM_global(this, model_data, TM)
191 
192  [cell_eind, cell_glob2loc, lind_cands, nind_cands] = ...
193  Fv.TwoPhase.VelocitySpace.compute_TM_global_pre...
194  (model_data, TM);
195 
196  [nmd] = ...
197  Fv.TwoPhase.VelocitySpace.compute_TM_global_grid...
198  (model_data, TM, cell_eind, cell_glob2loc, lind_cands, nind_cands);
199 
200  [eind_local] = ...
201  Fv.TwoPhase.VelocitySpace.compute_TM_global_post...
202  (nmd, TM, cell_glob2loc, lind_cands, nind_cands);
203 
204  eind = TM;
205  end
206  end
207 end
Interface for a localized operator that fulfills the so-called -independent DOF dependence.
function [ gEI , in_edges , b_edges , i_ints_bigger , b_ints ] = compute_edge_indices(gridbase grid)
edge index matrix. This matrix maps each edge specified by the tuple (element_id, local_edge_id) to a...
function spm = fv_frechet_operators_diff_flux_pressure_gradient(model, model_data, P, S, NU_ind)
computes a jacobian of implicit non-linear convective contributions to time evolution matrices at a p...
A triangular conforming grid in two dimensions.
Definition: triagrid.m:17
A cartesian rectangular grid in two dimensions with axis parallel elements.
Definition: rectgrid.m:17
a one dimensional grid implementation
Definition: onedgrid.m:17
function num_flux_mat = fv_num_diff_flux_pressure_gradient(model, model_data, P, S)
computes a numerical diffusive flux for a diffusion problem