rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
t_part_detailed_simulation.m
1 function sim_data = t_part_detailed_simulation(model, model_data)
2 %function sim_data = t_part_detailed_simulation(model, model_data)
3 %
4 %function performing a t-partition detailed simulation for the underlying
5 %base model. In case that no t-partition indication is given in params a
6 %simulation is performed for the whole time domain. If a special
7 %t-partition is indicated a simulation for this partition is performed
8 %using precomputed parameter solutions as initial conditions if they have
9 %been saved to disc.
10 %
11 % changes in this function must be done when using higher order time
12 % integration methods.
13 %
14 % Generated fields of sim_data:
15 % U: solution
16 % y: output if available
17 % sim_data_t: cell array where the results from the several time
18 % partitions are saved.
19 %
20 % Markus Dihlmann 11.02.11
21 
22 
23 sim_data = [];
24 partial_simulation = 0; %sim_data only for one specific part or not
25 
26 base_model = model.base_model;
27 
28 nr_t_parts = length(model.t_part_range);
29 sim_data_t = cell(1,nr_t_parts);
30 
31 if (isfield(model,'t_part_for_simulation'))
32  stop_part = model.t_part_for_simulation;
33  partial_simulation = 1 ;
34 else
35  stop_part = nr_t_parts;
36 end
37 
38 for t_part_ind = 1:stop_part
39  base_model.starting_time_step = model.t_part_range{t_part_ind}(1);
40  base_model.stopping_time_step = model.t_part_range{t_part_ind}(2); %must be changed for higher order time integrations
41 
42  if(t_part_ind > 1)
43  base_model.starting_time_step = model.t_part_range{t_part_ind}(1);
44  temp = sim_data_t{t_part_ind-1}.U(:,end);
45  base_model.init_values_algorithm = @(mod,mod_data)temp;
46  end
47 
48  sim_data_t{t_part_ind} = detailed_simulation(base_model, model_data);
49  %sim_data_t{t_part_ind} = filecache_function(@detailed_simulation,base_model, model_data);
50 
51 end
52 
53 %construct output struct sim_data
54 if partial_simulation
55  i=stop_part;
56  sim_data_t_fields = fieldnames(sim_data_t{i});
57  for j=1:length(sim_data_t_fields)
58  if isnumeric(getfield(sim_data_t{i},sim_data_t_fields{j}))
59  if ~isfield(sim_data,sim_data_t_fields{j})
60  sim_data = setfield(sim_data,sim_data_t_fields{j},getfield(sim_data_t{i},sim_data_t_fields{j}));
61  else
62  sim_data = setfield(sim_data,sim_data_t_fields{j},[getfield(sim_data,sim_data_t_fields{j}),getfield(sim_data_t{i},sim_data_t_fields{j})]);
63  end
64  end
65  end
66 else
67  %glue all infomation fields from sim_data_t together
68  for i = 1: length(sim_data_t)
69  sim_data_t_fields = fieldnames(sim_data_t{i});
70  for j=1:length(sim_data_t_fields)
71  if isnumeric(getfield(sim_data_t{i},sim_data_t_fields{j}))
72  if ~isfield(sim_data,sim_data_t_fields{j})
73  sim_data = setfield(sim_data,sim_data_t_fields{j},getfield(sim_data_t{i},sim_data_t_fields{j}));
74  else
75  len=size(getfield(sim_data_t{i},sim_data_t_fields{j}),2);
76  if len>1
77  extension_vec = getfield(sim_data_t{i},sim_data_t_fields{j});
78  sim_data = setfield(sim_data,sim_data_t_fields{j},[getfield(sim_data,sim_data_t_fields{j}),extension_vec(:,2:len)]);
79  else
80  sim_data = setfield(sim_data,sim_data_t_fields{j},[getfield(sim_data,sim_data_t_fields{j}),getfield(sim_data_t{i},sim_data_t_fields{j})]);
81  end
82  end
83  end
84  end
85  end
86 end
87 
88 
89 sim_data.sim_data_t = sim_data_t;
90 
function varargout = filecache_function(funcptr, varargin)
function used for file-caching other function calls.