rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
detailed_simulation_impes.m
1 function sim_data = detailed_simulation_impes(dmodel, model_data)
2 % function sim_data = detailed_simulation(dmodel, model_data)
3 % executes a detailed simulation for a given parameter
4 %
5 % required fields of model:
6 % T : final time
7 % nt : number of time-steps
8 % `0 = t_0 \leq t_1 \leq \cdots \leq t^K+1 = T`, i.e. `K+1`.
9 %
10 % optional fields of model:
11 % data_const_in_time : if this optional field is 1, the time
12 % evolution is performed with constant operators,
13 % i.e. only the initial-time-operators are computed
14 % and used throughout the time simulation.
15 %
16 % Return values:
17 % sim_data: structure holding the `H`-dimensional simulation data.
18 % fl: debug output holding the flux evaluations returned by the
19 % 'L_E_local_ptr' operator.
20 %
21 % Generated fields of sim_data:
22 % U: matrix of size `H \times K+1` holding for each time step the solution
23 % dof vector.
24 % Unewton: matrix of size `H \times K+1+\sum_{k=0}^K n_{\text{Newton}}(k)`
25 % holding for each time step and each Newton iteration the
26 % intermediate solution dof vectors.
27 %
28 
29 
30 % Martin Drohmann 9.12.2007 based on detailed_nonlin_evol_simulation.m by
31 % Bernard Haasdonk
32 
33 if nargin ~= 2
34  error('wrong number of parameters!');
35 end;
36 
37 if dmodel.verbose >= 9
38  disp('entered detailed simulation ');
39 end;
40 
41 if isempty(model_data)
42  model_data = gen_model_data(dmodel);
43 end;
44 
45 
46 % for a detailed simulation we do not need the affine parameter
47 % decomposition
48 dmodel.decomp_mode = 0;
49 
50 model = dmodel.descr;
51 
52 % initial values by midpoint evaluation
53 S0 = model.init_values_algorithm(model,model_data);
54 
55 S = zeros(length(S0(:)),model.nt+1);
56 U = 0.5*ones(model_data.gn_edges, model.nt+1);
57 P = 0.5*ones(length(S0(:)),model.nt+1);
58 exflags = zeros(1, model.nt+1);
59 outtext = cell(1, model.nt+1);
60 Slength = length(S0(:));
61 Ulength = model_data.gn_edges;
62 %totlength = 2*Slength+length(grid.VI);
63 S(:,1) = S0(:);
64 
65 model.dt = model.T / model.nt;
66 
67 for t = 1:model.nt
68  model.t = (t-1)*model.dt;
69  model.tstep = t;
70  if model.verbose > 19
71  disp(['entered time-loop step ',num2str(t), ' for non linear evolution equation']);
72  elseif model.verbose > 9
73  fprintf('.');
74  end;
75  fprintf('.');
76 
77  % V = zeros(totlength, model.newton_steps+1);
78  UP_last = [U(:,t); P(:,t)];
79 
80  model.t = model.t + model.dt;
81 
82 % Srhs = model.S_local_ptr(model, model_data, V(1:Slength+Ulength,n), []);
83 % Urhs = model.U_local_ptr(model, model_data, V(Slength+1:end,n), []);
84 % Prhs = model.P_local_ptr(model, model_data, V(Slength+Ulength+1:end,n), []);
85 % gradSM = model.S_op_matrix(model, model_data, V(Slength+1:Slength+Ulength,n), []);
86 % gradUM = model.U_op_matrix(model, model_data, V(1:Slength,n), []);
87 % gradPM = model.P_op_matrix(model, model_data, v(Slength+Ulength+1:end,n), []);
88 
89  fsolve_fun = @(X) sat_fun_imp(model, model_data, S(:, t), X, 0, Ulength);
90 
91  gplmmopts.Px = @(X) X;
92 % gplmmopts.HessFun = @(params, jac, dummy, arg) jac' * (jac * arg);
93  gplmmopts.Slength = Slength;
94  [UP_new, resnorm, FV, exitflag, output] = gplmm(fsolve_fun, UP_last, gplmmopts);
95 
96  exflags(t) = exitflag;
97  outtext{t} = output;
98 
99  U(:,t+1) = UP_new(1:Ulength);
100  P(:,t+1) = UP_new(Ulength+1:end);
101 
102  S(:,t+1) = S(:,t) - model.dt * sat_fun_es(model, model_data, U(:,t+1), S(:,t));
103 
104 end
105 
106 sim_data.S = S;
107 sim_data.U = U;
108 sim_data.P = P;
109 sim_data.exit_flags = exflags;
110 sim_data.outputs = outtext;
111 
112 if model.verbose > 9
113  fprintf('\n');
114 end
115 
116 function ret = sat_fun_es(descr, model_data, Uold, Sold)
117  L_sat_arg.S = Sold;
118  L_sat_arg.U = Uold;
119  L_sat_arg.m = length(Sold);
120  ret = descr.L_saturation.apply(descr, model_data, L_sat_arg);
121 
122 function [ret, J] = sat_fun_imp(descr, model_data, Sold, X, Uoff, Poff)
123 
124  arglength = length(X);
125 
126  L_vel_arg.S = Sold;
127  L_vel_arg.P = X(Poff+1:end);
128  L_vel_arg.Poff = Poff;
129  L_vel_arg.n = Poff-Uoff;
130  L_vel_arg.m = arglength;
131  [vel_ret, dummy, vel_Jret] = descr.L_velocity.apply(descr, model_data, L_vel_arg);
132 
133  L_div_arg.U = X(Uoff+1:Poff);
134  L_div_arg.Uoff = Uoff;
135  L_div_arg.m = arglength;
136  [div_ret, dummy, div_Jret] = descr.L_divergence.apply(descr, model_data, L_div_arg);
137 
138  [prs_ret, dummy, prs_Jret] = descr.L_pressure.apply(descr, model_data, L_vel_arg);
139 
140  ret = [vel_ret - X(Uoff+1:Poff); div_ret; prs_ret];
141  assert(all(~isnan(ret)));
142  assert(all(~isinf(ret)));
143 
144 % [ret2, Jret2] = fv_two_phase_space(descr, model_data, X);
145 % retlength = length(ret2);
146 
147  if nargout > 1
148 
149  n = size(vel_Jret,1);
150  sp_minus_U = sparse(1:n, Uoff+1:Poff, -1, n,arglength);
151  J = [ vel_Jret + sp_minus_U;
152  div_Jret;
153  prs_Jret ];
154 
155 % J2 = sparse(1:Uoff, 1:Uoff, ...
156 % 1/descr.dt * ones(1,Uoff), ...
157 % retlength, arglength) ...
158 % + Jret2;
159 % keyboard;
160  end
161 function Xproj = box_projection(X, Slength)
162 
163  SX = X(1:Slength);
164  SX(SX<0) = eps;
165  SX(SX>1) = 1-eps;
166  Xproj = [SX; X(Slength+1:end)];
167 
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
function [ xnew , resnorm , residual , exitflag , output , tempsols ] = gplmm(funptr, x0, params)
Global projected Levenberg-Marquard method.
Definition: gplmm.m:17