1 function sim_data = lin_ds_detailed_simulation_euler_forward(model,model_data)
2 %
function sim_data = lin_ds_detailed_simulation_euler_forward(model,model_data)
4 %
function performing a general time evolution of a linear dynamical
5 % system by euler forward time discretization
7 % @f[ d/dt x = A(t,\mu) x + B(t,\mu) u @f]
8 % @f[ y = C(t,\mu) x + D(t,\mu) u \quad \mbox{
for } t = [0,T] @f]
9 % @f[ x(0) = x_0(\mu) @f]
11 % required fields of model:
13 % nt : number of time-intervals until T, i.e. nt+1
14 % solution slices are computed
15 % x0_function_ptr: pointer to
function for computing the
16 % initvalues-DOF with arguments (model)
17 % A_function_ptr: pointer to
function for computing the matrix A
18 % B_function_ptr: pointer to
function for computing the matrix B
19 % C_function_ptr: pointer to
function for computing the matrix C
20 % D_function_ptr: pointer to
function for computing the matrix D
21 % u_function_ptr: pointer to input
function u(t)
22 % data_const_in_time :
if this optional field is 1, the time
23 % evolution is performed with constant operators,
24 % i.e. only the initial-time-operators are computed
25 % and used throughout the time simulation.
26 % affinely_decomposed:
if this optional field is set, model_data is
27 % assumed to contain the components of the matrices and online
28 % assembly is performed by coefficient-component linear combinaton
29 % save_time_indices: list of integer time indices between 0 and nt,
30 % which are to be computed, stored and returned
33 % X: solution DOF-vector X(:,t) for all times t=1,...,nt+1
36 % Bernard Haasdonk 2.4.2009
39 disp('entered detailed simulation ');
42 %model.affine_decomp_mode = 'complete';
43 model.decomp_mode = 0;
44 model = model.set_time(model,0);
47 if isfield(model,'save_time_indices')
48 save_time_index = zeros(1,model.nt+1);
49 save_time_index(model.save_time_indices(:)+1) = 1;
50 save_time_indices = find(save_time_index==1)-1;
52 save_time_index = ones(1,model.nt+1);
53 save_time_indices = 1:(model.nt+1);
56 % initial values by midpoint evaluation
58 if ~model.affinely_decomposed
59 xt = model.x0_function_ptr(model,model_data);
60 C = model.C_function_ptr(model,model_data);
62 old_decomp_mode = model.decomp_mode;
63 model.decomp_mode = 2;
64 x0_coeff = model.x0_function_ptr(model,[]);
65 xt = lincomb_sequence(model_data.x0_components,x0_coeff);
66 C_coeff = model.C_function_ptr(model,[]);
67 C = lincomb_sequence(model_data.C_components,C_coeff);
68 model.decomp_mode = old_decomp_mode;
70 D = model.D_function_ptr(model,model_data); % no decomposition required
71 X = zeros(length(xt(:)),length(save_time_indices));
72 Y = zeros(size(C,1),length(save_time_indices));
73 time_indices = zeros(1,length(save_time_indices));
74 time = zeros(1,length(save_time_indices));
76 t_column = 1; % next column index to be filled in output
77 t_ind = 0; % current t_ind between 0 and nt
78 t = 0; % absolute time between 0 and T
81 if save_time_index(t_ind+1)
83 time_indices(t_column) = t_ind;
85 u = model.u_function_ptr(model);
86 Y(:,t_column) = C * xt + D * u;
87 t_column = t_column + 1;
90 model.dt = model.T/model.nt;
91 operators_required = 1;
93 % loop over time-steps
94 for t_ind = 1:model.nt
95 t = model.dt * (t_ind-1); % compute new x and y at time t
97 disp(['entered time-loop step ',num2str(t_ind)]);
102 % get matrices and bias-vector
103 model = model.set_time(model,t);
105 if operators_required
106 if ~model.affinely_decomposed
107 A = model.A_function_ptr(model,model_data);
108 B = model.B_function_ptr(model,model_data);
109 % C and D required at time t+dt;
110 model = model.set_time(model,t+model.dt);
111 % model.t = t+model.dt;
112 C = model.C_function_ptr(model,model_data);
113 D = model.D_function_ptr(model,model_data);
114 model = model.set_time(model,t);
117 model.decomp_mode = 2;
118 A_coeff = model.A_function_ptr(model,[]);
119 B_coeff = model.B_function_ptr(model,[]);
120 model = model.set_time(model,t+model.dt);
121 %model.t = t+model.dt;
122 C_coeff = model.C_function_ptr(model,[]);
123 model.decomp_mode = old_decomp_mode;
124 D = model.D_function_ptr(model,[]); % no decomposition of D
125 model = model.set_time(model,t);
127 A = lincomb_sequence(model_data.A_components,A_coeff);
128 B = lincomb_sequence(model_data.B_components,B_coeff);
129 C = lincomb_sequence(model_data.C_components,C_coeff);
132 if model.data_const_in_time
133 operators_required = 0;
136 u = model.u_function_ptr(model);
137 xt = xt + model.dt * A * xt + model.dt * B * u;
138 % X(:,t_ind+1) = X(:,t_ind) + model.dt * (A * X(:,t_ind) + B * u);
139 %Y(:,t_ind+1) = C * X(:,t_ind) + D * u;
141 if save_time_index(t_ind+1)
143 time_indices(t_column) = t_ind;
144 % y evaluation requires + dt !!
145 model = model.set_time(model,t+model.dt);
146 %model.t = t + model.dt;
147 u = model.u_function_ptr(model);
148 Y(:,t_column) = C * xt + D * u;
150 t_column = t_column + 1;
163 sim_data.time = time;
164 sim_data.time_indices = time_indices;
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...