rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
fv_conv_flux_matrix.m
Go to the documentation of this file.
1 function [flux_mat, lambda] = fv_conv_flux_matrix(model,model_data,U,conv_flux_ptr)
2 %function [flux_mat[, lambda]] = fv_conv_flux_matrix(model,model_data,[U,conv_flux_ptr])
3 % function computing the flux matrix of a convection problem.
4 % simply reformatting the grid data suitably for pointwise evaluation
5 % by conv_flux. As evaluation points the points of suitable
6 % gauss-quadratures are chosen. The degree can be chosen in the
7 % model structure.
8 %
9 % in 'complete' (decomp_mode = 0) mode, flux_mat is a
10 % 2 x nelements x nfaces matrix. In decomp_mode = 1 a cell array of
11 % such and in decomp_mode = 2 a simple vector of coefficients.
12 %
13 % Optionally, a divergence cleaning is performed. Ensure, that the
14 % divergence cleaning is not performed out of a neuman boundary, as these
15 % values will be reevaluated in setting of the boundary values, so an
16 % inconsistency would occur in that case. Instead lead the cleaning
17 % sweeps out of the domain by dirichlet boundaries.
18 % alternatively a divergence cleaning by optimization is possible.
19 %
20 % required fields of model as required by conv_flux
21 %
22 % optional fields of model:
23 % divclean_mode: field, which indicates the divergence cleaning
24 % if it is set, further fields must be set:
25 % possibility: 'none', 'sweep' or 'optimize'
26 %
27 % in case of 'sweep' additionally required:
28 % divclean_sweeps: cell array with information on divergence cleaning
29 % sweeps. Each element contains three fields:
30 % start_elements : vector of element indices used
31 % as starting points for the sweep
32 % steps : number of rows/cols divergence cleansed
33 % direction : main direction of the block for cleaning
34 %
35 %
36 % Function supports affine decomposition, i.e. different operation modes
37 % guided by optional field decomp_mode in model. See also the
38 % contents.txt for general explanation
39 
40 % Bernard Haasdonk 11.4.2006
41 
42 % determine affine_decomposition_mode as integer
43 decomp_mode = model.decomp_mode;
44 
45 grid = [];
46 if ~isempty(model_data)
47  grid = model_data.grid;
48 end
49 flux_mat = [];
50 
51 if decomp_mode < 2
52  nfaces = size(grid.ECX,2);
53  UU = repmat(U,1,nfaces);
54 end;
55 
56 if nargin < 4
57  conv_flux_ptr = model.conv_flux_ptr;
58 end
59 
60 
61 
62 % if (~isequal(model.divclean_mode,'none')) & ...
63 % isfield(model,'use_velocity_matrixfile') & ...
64 % (model.use_velocity_matrixfile==1)
65 % model.divclean_mode = 'none';
66 % if model.verbose >= 5
67 % disp('divergence cleaning is skipped, as velocity from file is read!!');
68 % end;
69 % end;
70 
71 if model.flux_linear && model.divclean_mode
72  error('divergence clearning has to be adjusted!!')
73 % % ensure that no affine decomposition is wanted!!!
74 % if decomp_mode~=0
75 % error('no simultaneous affine decomposition and divergence cleaning!');
76 % end;
77 %
78 % % perform different cleaning methods:
79 % f = conv_flux_linearization(model,UU(:),grid.ECX(:), grid.ECY(:) );
80 % V.Vx = reshape(f.Vx,size(grid.ECX));
81 % V.Vy = reshape(f.Vy,size(grid.ECY));
82 %
83 % if isequal(model.divclean_mode,'sweep')
84 % if model.verbose>9
85 % disp('performing divergence cleaning by sweeping');
86 % end;
87 % Vclean = divergence_clean_sweep(model,model_data,V);
88 % elseif isequal(model.divclean_mode,'optimize')
89 % if model.verbose>9
90 % disp('performing divergence cleaning by optimization');
91 % end;
92 % Vclean = divergence_clean_optimize(model, model_data,V);
93 % else
94 % error('unknown divergence_cleaning mode!');
95 % end;
96 % % set resulting flux values
97 % flux_mat.Fx = Vclean.Vx.*UU;
98 % flux_mat.Fy = Vclean.Vy.*UU;
99 % % flux_mat.Fx = reshape(Vclean.Vx, size(UU)).*UU;
100 % % flux_mat.Fy = reshape(Vclean.Vy, size(UU)).*UU;
101 else % no cleaning: ordinary flux values
102  if decomp_mode == 2 % simply get coefficients from conv_flux and forward
103  flux_mat = conv_flux_ptr([],[],model);
104  elseif decomp_mode == 0
105  % compute f by quadratures
106  [elids, edgeids] = ind2sub(size(grid.VI),1:length(grid.VI(:)));
107  PP = edge_quad_points(grid,elids, edgeids, model.flux_quad_degree);
108  % ff = conv_flux(model,repmat(UU(:),model.flux_quad_degree,1), ...
109  % PP(1,:), PP(2,:));
110  PP_nums = size(PP,1)/(size(grid.ECX,1)*size(grid.ECX,2));
111  [ff, lambda] = conv_flux_ptr(PP,repmat(UU(:),PP_nums,1)', ...
112  model);
113  fx = edge_quad_eval_mean(grid, elids, edgeids,...
114  model.flux_quad_degree, ff(:,1));
115  fy = edge_quad_eval_mean(grid, elids, edgeids,...
116  model.flux_quad_degree, ff(:,2));
117  f = [fx(:),fy(:)]';
118 % TODO: test if results in rows are faster
119  flux_mat = reshape(f,[2,size(UU)]);
120 % flux_mat.Fy = reshape(f.Fy,size(UU));
121  elseif decomp_mode == 1
122 % f = conv_flux(UU(:),grid.ECX(:), grid.ECY(:), model );
123  [elids, edgeids] = ind2sub(size(grid.VI),1:length(grid.VI(:)));
124  PP = edge_quad_points(grid,elids, edgeids,model.flux_quad_degree);
125  PP_nums = size(PP,1)/(size(grid.ECX,1)*size(grid.ECX,2));
126 % ff = conv_flux_ptr(model, repmat(UU(:),PP_nums,1), ...
127 % PP(1,:), PP(2,:));
128  ff = conv_flux_ptr(PP, repmat(UU(:),PP_nums,1)',model);
129 
130  %f = cell(length(ff),1);
131  for q = 1:length(ff);
132  fx = edge_quad_eval_mean(grid,elids,edgeids,...
133  model.flux_quad_degree,ff{q}(:,1));
134  fy = edge_quad_eval_mean(grid,elids,edgeids,...
135  model.flux_quad_degree,ff{q}(:,2));
136  f = [fx(:),fy(:)]';
137  flux_mat{q} = reshape(f,[2,size(UU)]);
138  end;
139  end;
140 end;
141 
142 % lambda only reasonable in case of no affine decomposition
143 %if decomp_mode == 0
144 % flux_mat.lambda = f.lambda;
145 %end;
146 
147 
function [ flux_mat , lambda ] = fv_conv_flux_matrix(model, model_data, U, conv_flux_ptr)
function computing the flux matrix of a convection problem. simply reformatting the grid data suitabl...