1 function U0 = init_values(X,Y, params)
2 %
function U0 = init_values([X],[Y], params)
4 %
function constructing the initial values of the convection diffusion
5 % problem in the specified points and parameters
7 %
'blobs': u_0 = beta*exp(-gamma*((x-0.25).^2+(y-0.5).^2))* Xi(B_r) ...
8 % + (1-beta)*exp(-gamma*((x-0.25).^2+(y-0.7).^2))* Xi(B_r)
9 %
'homogeneous' u_0 = beta
10 %
'as_dirichlet' : evaluate dirichlet-data-
function at time 0
11 %
'waveproduct' : product of two sinus waves in both coordinate directions
12 %
'grey_image' : load grey value image as initial data
13 %
'function_ptr' : init
function given by
function
14 % pointer to complete evaluation:
15 % params.init_values_ptr
17 % allow call U = f(X,Y,params), where X, Y are
18 % vectors of the same size. Return is a vector of
19 % values in the corresponding points.
20 %
'decomp_function_ptr' : init
function given by
function
21 % pointer to components and coefficients:
22 % params.init_values_coefficients_ptr
24 % allow call U = f([],[],params)
25 % Return is a vector of length Q with (parameter
26 % dependent) coefficients in U.
27 % params.init_values_components_ptr
29 % allow call U = f(X,Y,params), where X, Y are
30 % vectors of the same size.
31 % Return of components is a cell array of vectors of
32 % the same size as X and Y with the point values
33 % of the components. Linear combination of
34 % components by coefficients then yields the
35 % complete evaluation.
37 % required fields of params:
38 % name_init_values :
'blobs',
'homogeneous',
'wave',
'leftright',
41 %
if name_init_values ==
'gradient_box'
42 % c_init_up : constant value on upper border of box
44 % c_init_lo : constant value on lower border of box
46 %
if name_init_values ==
'blobs'
47 % radius : radius of blob-cutoff circle
48 % gamma : spread of initial-value gaussian
49 % beta : value between 0 and 1 weighting two gauss-blobs
51 %
if name_init_values ==
'homogeneous'
52 % c_init : constant value in field
54 %
if name_init_values ==
'wave'
55 % a wave of values between 0 and c_init
56 % c_init* 0.5 * (sin(freq_x * x + freq_y * y) + 1)
57 % c_init : maximum value in field
58 % freq_x : frequency in x-direction
59 % freq_y : frequency in y-direction
61 %
if name_init_values ==
'waveproduct'
62 % a product of axis-dependent waves of values between
63 % c_init_min and c_init_max
64 % c_init_max : maximum value in field
65 % c_init_min : minimum value in field
66 % c_init_freq_x : frequency in x-direction
67 % c_init_freq_y : frequency in y-direction
68 % c_init_phase_x : phase shift
69 % c_init_phase_y : phase shift
71 %
if name_init_values ==
'leftright'
72 % c_init_left : constant value in field left of border
73 % c_init_right : constant value in field left of border
74 % c_init_middle : x-coordinate separation
76 %
if name_init_values ==
'as_dirichlet'
77 % parameters as required by dirichlet
function
79 %
if name_init_values ==
'grey_image'
80 % a grey value image is loaded mapping 0 to 0 and 255 to c_init
81 % with bilinear interpolation
82 % c_init : parameter weighting the components
83 % c_init_filename : name of image file
84 % c_init_xmin : image is mapped to specified rectangle
85 % c_init_xmax : image is mapped to specified rectangle
86 % c_init_ymin : image is mapped to specified rectangle
87 % c_init_ymax : image is mapped to specified rectangle
88 % c_init_xdivisions : vector of divisions, i.e intervals,
89 % e.g. borders of letters in an image
90 % determines number of components. c_init = 0
91 % => full weight to leftmost part of image
92 % c_init = 1 => full weight to complete image
94 % Function supports affine decomposition, i.e. different operation modes
95 % guided by optional field affine_decomp_mode in params. See also the
96 % contents.txt
for general explanation
98 % optional fields of params:
99 % mu_names : names of fields to be regarded as parameters in vector mu
100 % affine_decomp_mode: operation mode of the
function
101 %
'none' (
default): no parameter dependence or decomposition is
102 % performed. output is as described above.
103 %
'components': For each output argument a cell array of output
104 % arguments is returned representing the q-th component
105 % independent of the parameters given in mu_names
106 %
'coefficients': For each output argument a cell array of output
107 % arguments is returned representing the q-th coefficient
108 % dependent of the parameters given in mu_names
110 % in
'coefficients' mode, the parameters in brackets are empty
112 % Bernard Haasdonk 5.10.2005
114 decomp_mode = params.decomp_mode;
115 % flag indicating whether the computation respected the decomposition
116 respected_decomp_mode = 0;
118 if isequal(params.name_init_values,
'gradient_box')
119 % definition of the box
124 ymin = ymid-height/2;
125 ymax = ymid+ height/2;
129 I = (BX<width/2) & (BY<height/2);
130 % y = ymin => 0 + c_init_lo
131 % y = ymax => c_init_up + 0
132 U0 = (params.c_init_up * (Y(:)-ymin) + ...
133 + params.c_init_lo * (ymax-Y(:))) .* I / (ymax-ymin);
134 elseif decomp_mode == 1
138 I = (BX<width/2) & (BY<height/2);
139 U0{1} = (Y(:)-ymin) .* I / (ymax-ymin);
140 U0{2} = (ymax-Y(:)) .* I / (ymax-ymin);
141 else % decomp_mode == 2
142 U0 = [params.c_init_up, params.c_init_lo];
144 respected_decomp_mode = 1;
145 elseif isequal(params.name_init_values,
'blobs')
146 B1 = ((X(:)-0.25).^2+(Y(:)-0.5).^2);
147 B2 = ((X(:)-0.25).^2+(Y(:)-0.7).^2);
148 I1 = (B1<params.radius.^2);
149 I2 = (B2<params.radius.^2);
151 U0 = params.beta*exp(-params.gamma*B1).*I1 ...
152 + (1-params.beta)* exp(-params.gamma*B2).*I2;
153 elseif decomp_mode == 1
154 if ismember('gamma',params.mu_names) || ...
155 ismember('radius',params.mu_names)
156 error('affine decomp with respect to mu_names not possible!');
159 U0{1} = exp(-params.gamma*B1).*I1;
160 U0{2} = exp(-params.gamma*B2).*I2;
161 else % decomp_mode == 2
162 U0 = [params.beta, 1-params.beta];
164 respected_decomp_mode = 1;
165 elseif isequal(params.name_init_values,
'homogeneous')
167 U0 = params.c_init * ones(length(X),1);
168 elseif decomp_mode == 1
169 U0 = { ones(length(X),1) };
170 else % decomp_mode == 2
173 respected_decomp_mode = 1;
174 elseif isequal(params.name_init_values,
'wave')
176 U0 = params.c_init * 0.5 * (sin(params.freq_x * X(:) + ...
177 params.freq_y * Y(:) ) + 1 );
178 elseif decomp_mode == 1
179 % single component independent of mu_names
180 if ismember('freq_x',params.mu_names) || ...
181 ismember('freq.y',params.mu_names)
182 error('affine decomp with respect to mu_names not possible!');
184 U0 = {0.5 * (sin(params.freq_x * X(:) + ...
185 params.freq_y * Y(:) ) + 1 )};
186 else % decomp_mode == 2
189 respected_decomp_mode = 1;
191 elseif isequal(params.name_init_values,
'transformed_blobs')
192 % [X_trans, Y_trans] = geometry_transformation(X,Y,params);
195 % B{1} = ((X_trans(:) - 0.5).^2 +(Y_trans(:)-0.7).^2);
196 if any(ismember(fieldnames(params),
'blob_height'))
197 h = params.blob_height;
201 B{1} = ((X(:) - 0.5).^2 +(Y(:)-0.7).^2);
202 B{2} = ((X(:) - 0.8).^2 +(Y(:)-0.9).^2);
203 B{3} = ((X(:) - 0.8).^2 +(Y(:)-0.2).^2);
204 B{4} = ((X(:) - 0.2).^2 +(Y(:)-0.2).^2);
205 B{5} = ((X(:) - 0.2).^2 +(Y(:)-0.9).^2);
206 B{6} = ((X(:) - 0.4).^2 +(Y(:)-0.4).^2);
207 B{7} = ((X(:) - 0.6).^2 +(Y(:)-0.6).^2);
211 % p_mu = spline_select(params);
214 I{i} = (B{i} < 0.05.^2);
217 U0 = h .* I{1} + params.c_init * ones(length(X),1) + params.gravity * (Y + params.hill_height*ztrans);
219 U0 = U0 + h .* exp(-B{i}) .* I{i};
221 elseif decomp_mode == 1
227 U0{8} = ones(length(X),1);
228 if params.gravity ~= 0
233 U0 = [ h, h, h, h, h, h, h, params.c_init];
234 U0 = [ U0, params.gravity, params.gravity * params.hill_height ];
236 respected_decomp_mode = 1;
237 elseif isequal(params.name_init_values,
'waveproduct')
238 if (decomp_mode == 0) || (decomp_mode ==1)
239 Uinit = params.c_init_min + ...
240 (params.c_init_max-params.c_init_min) * ...
241 0.5 * (sin_sym(params.c_init_freq_x * X(:) + params.c_init_phase_x) ...
242 .* sin_sym(params.c_init_freq_y * Y(:) + params.c_init_phase_y) ...
245 % if ismember('c_init_freq_x',params.mu_names) | ...
246 % ismember('c_init_freq_y',params.mu_names) | ...
247 % ismember('c_init_min',params.mu_names) | ...
248 % ismember('c_init_max',params.mu_names) | ...
249 % ismember('c_init_phase_x',params.mu_names) | ...
250 % ismember('c_init_phase_y',params.mu_names)
251 % error('affine decomp with respect to mu_names not possible!');
261 respected_decomp_mode = 1;
263 elseif isequal(params.name_init_values,
'leftright')
264 i = (X <= params.init_middle);
265 U0 = params.c_init_left * i + (1-i) * params.c_init_right;
266 elseif isequal(params.name_init_values,'as_dirichlet')
268 % if as_dirichlet not decomposable => error there and not here.
269 respected_decomp_mode = 1;
271 elseif isequal(params.name_init_values,'grey_image')
272 ncomp = 1+length(params.c_init_xdivisions);
274 % determine components and perform linear combination
275 img = imread(params.c_init_filename)/255;
276 %erstmal ohne bilineare Interpolation:
277 XI = (X(:)-params.c_init_xmin)/(params.c_init_xmax- ...
278 params.c_init_xmin)* size(img,2);
280 XI = min(XI,size(img,2));
286 YI = (Y(:)-params.c_init_ymin)/(params.c_init_ymax- ...
287 params.c_init_ymin)* size(img,1);
289 YI = min(YI,size(img,1));
290 % reflect y coordinate
298 ind = sub2ind(size(img),YI,XI);
301 U0comp = cell(ncomp,1);
302 xdivs = [0;params.c_init_xdivisions(:);params.c_init_xmax];
304 U0 = zeros(length(X(:)),1);
305 fi = find( (X(:)<xdivs(i+1)) & (X(:)>=xdivs(i)));
313 % determine coefficients:
314 %coeff = zeros(ncomp,1);
315 coeff = (0:(ncomp-1))/ncomp;
316 coeff = (params.c_init - coeff)*ncomp;
317 coeff = min(coeff,1);
318 coeff = max(coeff,0);
320 % now
return the correct quantity
323 elseif decomp_mode == 0
324 U0 = lincomb_sequence(U0comp,coeff);
325 elseif decomp_mode == 1
328 respected_decomp_mode = 1;
330 elseif isequal(params.name_init_values,
'decomp_function_ptr')
332 U0 = params.init_values_coefficients_ptr([],[],params);
333 elseif decomp_mode == 1; % components
334 U0 = params.init_values_components_ptr(X,Y,params);
335 else % decomp_mode = 0, complete
336 Ucoefficients = params.init_values_coefficients_ptr([],[],params);
337 Ucomponents = params.init_values_components_ptr(X,Y,params);
338 U0 = lincomb_sequence(Ucomponents,Ucoefficients);
340 respected_decomp_mode = 1;
342 elseif isequal(params.name_init_values,'function_ptr')
343 U0 = params.init_values_ptr(X,Y,params);
344 respected_decomp_mode = 0;
347 error('unknown name_init_values');
350 if decomp_mode>0 && respected_decomp_mode==0
351 error('function does not support affine decomposition!');
354 % TO BE ADJUSTED TO NEW SYNTAX
function Udirichlet = dirichlet_values(model, X, Y)
UDIRICHLET = DIRICHLET_VALUES([X],[Y], MODEL) Examples dirichlet_values([0,1,2],[1,1,1],struct(name_dirichlet_values, homogeneous, ... c_dir, 1)) dirichlet_values([0:0.1:1],[0],struct(name_dirichlet_values, xstripes, ... c_dir, [0 1 2], ... dir_borders, [0.3 0.6])) dirichlet_values([0:0.1:1],[0],struct(name_dirichlet_values, box, ... c_dir, 1, ... dir_box_xrange, [0.3 0.6], ... dir_box_yrange, [-0.1 0.1]))