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
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.
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.
20 % required fields of model as required by conv_flux
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'
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
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
40 % Bernard Haasdonk 11.4.2006
42 % determine affine_decomposition_mode as integer
43 decomp_mode = model.decomp_mode;
46 if ~isempty(model_data)
47 grid = model_data.grid;
52 nfaces = size(grid.ECX,2);
53 UU = repmat(U,1,nfaces);
57 conv_flux_ptr = model.conv_flux_ptr;
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!!');
71 if model.flux_linear && model.divclean_mode
72 error(
'divergence clearning has to be adjusted!!')
73 % % ensure that no affine decomposition is wanted!!!
75 % error(
'no simultaneous affine decomposition and divergence cleaning!');
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));
83 %
if isequal(model.divclean_mode,
'sweep')
85 % disp(
'performing divergence cleaning by sweeping');
87 % Vclean = divergence_clean_sweep(model,model_data,V);
88 % elseif isequal(model.divclean_mode,
'optimize')
90 % disp(
'performing divergence cleaning by optimization');
92 % Vclean = divergence_clean_optimize(model, model_data,V);
94 % error(
'unknown divergence_cleaning mode!');
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), ...
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)
', ...
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));
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), ...
128 ff = conv_flux_ptr(PP, repmat(UU(:),PP_nums,1)
',model);
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));
137 flux_mat{q} = reshape(f,[2,size(UU)]);
142 % lambda only reasonable in
case of no affine decomposition
144 % flux_mat.lambda = f.lambda;
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...