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
5 % required fields of model:
7 % nt : number of time-steps
8 % `0 = t_0 \leq t_1 \leq \cdots \leq t^K+1 = T`, i.e. `K+1`.
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.
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.
21 % Generated fields of sim_data:
22 % U: matrix of size `H \times K+1` holding
for each time step the solution
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.
30 % Martin Drohmann 9.12.2007 based on detailed_nonlin_evol_simulation.m by
34 error(
'wrong number of parameters!');
37 if dmodel.verbose >= 9
38 disp(
'entered detailed simulation ');
41 if isempty(model_data)
42 model_data = gen_model_data(dmodel);
46 % for a detailed simulation we do not need the affine parameter
48 dmodel.decomp_mode = 0;
52 % initial values by midpoint evaluation
53 S0 = model.init_values_algorithm(model,model_data);
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);
65 model.dt = model.T / model.nt;
68 model.t = (t-1)*model.dt;
71 disp(['entered time-loop step ',num2str(t), ' for non linear evolution equation']);
77 % V = zeros(totlength, model.newton_steps+1);
78 UP_last = [U(:,t); P(:,t)];
80 model.t = model.t + model.dt;
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), []);
89 fsolve_fun = @(X) sat_fun_imp(model, model_data, S(:, t), X, 0, Ulength);
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);
96 exflags(t) = exitflag;
99 U(:,t+1) = UP_new(1:Ulength);
100 P(:,t+1) = UP_new(Ulength+1:end);
102 S(:,t+1) = S(:,t) - model.dt * sat_fun_es(model, model_data, U(:,t+1), S(:,t));
109 sim_data.exit_flags = exflags;
110 sim_data.outputs = outtext;
116 function ret = sat_fun_es(descr, model_data, Uold, Sold)
119 L_sat_arg.m = length(Sold);
120 ret = descr.L_saturation.apply(descr, model_data, L_sat_arg);
122 function [ret, J] = sat_fun_imp(descr, model_data, Sold, X, Uoff, Poff)
124 arglength = length(X);
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);
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);
138 [prs_ret, dummy, prs_Jret] = descr.L_pressure.apply(descr, model_data, L_vel_arg);
140 ret = [vel_ret - X(Uoff+1:Poff); div_ret; prs_ret];
141 assert(all(~isnan(ret)));
142 assert(all(~isinf(ret)));
144 % [ret2, Jret2] = fv_two_phase_space(descr, model_data, X);
145 % retlength = length(ret2);
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;
155 % J2 = sparse(1:Uoff, 1:Uoff, ...
156 % 1/descr.dt * ones(1,Uoff), ...
157 % retlength, arglength) ...
161 function Xproj = box_projection(X, Slength)
166 Xproj = [SX; X(Slength+1:end)];
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
function [ xnew , resnorm , residual , exitflag , output , tempsols ] = gplmm(funptr, x0, params)
Global projected Levenberg-Marquard method.