rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
DetailedModel.m
1 classdef DetailedModel < Greedy.User.FVDetailedModelDefault
2  % Detailed model for a linear evolution problem with a @ref fv discretization
3  %
4  % This is a detailed model for a problem of the type
5  % @f{align}
6  % \partial_t u(x;t,\mu) - {\cal L}(t,\mu)[u(x,t;\mu)] &= 0 \qquad &\text{in }& \Omega \times [0, T], \\\\
7  % u(x;0,\mu) &= u_0(x;\mu) \qquad &\text{in }& \Omega \times \{0\}
8  % @f}
9  % with suitable boundary conditions and linear operators
10  % `{\cal L}(t,\mu) : {\cal W} \to {\cal W}` parametrized over the
11  % time-parameter domain `[0,T] \times {\cal M}`.
12  %
13  % The numerical scheme for the numerical solution of this problem is assumed
14  % to be of the following type:
15  % @f{align*}
16  % u_h(\cdot;t^0,\mu) &= {\cal M}_h[u_0] \\\\
17  % \left(\text{Id} - \Delta t^k {\cal L}_{h, I}(t^{k+1},\mu)\right)[u_h(\cdot;t^{k+1},\mu)]
18  % &=
19  % \left(\text{Id} + \Delta t^k {\cal L}_{h, E}(t^{k},\mu)\right)[u_h(\cdot;t^{k},\mu)]
20  % @f}
21  % with the following ingredients:
22  % - a time discretization `0 = t^0 \leq t^1 = t^0 + \Delta t^0 \leq \ldots
23  % \leq t^{K+1} = t^{K} + \Delta t^{K} = T`,
24  % - solution snapshots `u_h(\cdot;t,\mu) \in { cal W }_h ` for all
25  % parameters and time instances `(t,\mu) \in [0,T] \times { \cal M }`
26  % - separable operators for the discretization `{\cal L}_{h, I}(t,\mu):{\cal
27  % W}_h \to {\cal W}_h`, `{\cal L}_{h, E}(t,\mu):{\cal W}_h \to {\cal W}_h`
28  % and separable initial data `u_0` in the parameter argument. That is these
29  % must be decomposable like
30  % @f{align*}
31  % {\cal L}_{h, *}(t,\mu) &= \sum_{q=1}^{q_*} \sigma_*^q(\mu) {\cal L}^q_{h, *}(t) \\\\
32  % u_0(x;\mu) &= \sum_{q=1}^{u_0} \sigma_{u_0}^q(\mu) u_0(x)
33  % @f} and
34  % - a projection operator `{\cal M}_h : {\cal W} \to {\cal W}_h`
35 
36 
37  properties(Constant)
38  % This constant is used for a consistency check of the model descr with
39  % help of Greedy.Remove.IDetailedModelBase.struct_check()
40  ddescr_checks = struct(...
41  'mass_matrix', {{@(x) isequal(class(x), 'function_handle')}}...
42  );
43  end
44 
45  methods
46  function dm = DetailedModel(descr)
47  % function dm = DetailedModel(descr)
48  % constructor based on problem description
49  %
50  % Parameters:
51  % descr: structure describing the problem and the descretization
52  dm = dm@Greedy.User.FVDetailedModelDefault(descr);
53  if ~IDetailedModel.struct_check(descr, ...
55  error('Consistency check for LinEvol.DetailedModel failed.');
56  end
57  end
58 
59  function this = set_mu(this, mu)
60  % function this = set_mu(this, mu, propagate)
61  % sets the active parameter vector `\mu \in {\cal M}`
62  %
63  % The parameter set here, is used by the detailed_simulation() function.
64  %
65  % The default implementation sets all fieldnames 'descr.mu_names' in the
66  % #descr struct.
67  %
68  % Parameters:
69  % mu: The parameter vector `\boldsymbol\mu`.
70  %
71  % Return values:
72  % this: handle of type IDetailedModel to the changed DetailedModel
73 
74  assert(length(mu) == length(this.descr.mu_names));
75 
76  this.descr.mexptr('set_mu', mu);
77  end
78 
79  function mu = get_mu(this)
80  % function mu = get_mu(this)
81  % returns the active parameter vector `\boldsymbol\mu \in {\cal M}`
82  %
83  % The default implementation returns a vector of the values of the fields
84  % of the #descr structure with names 'descr.mu_names'.
85  %
86  % Return values:
87  % mu: The parameter vector `\boldsymbol\mu`
88 
89  mu = this.descr.mexptr('get_mu');
90  end
91  function sim_data = detailed_simulation(this, model_data)
92  sim_data = this.descr.mexptr('detailed_simulation');
93  end
94 
95  function model_data = gen_model_data(this)
96  model_data.id = this.descr.mexptr('gen_model_data');
97  model_data.mexptr = this.descr.mexptr;
98  end
99 
100  function p = plot_sim_data(this, model_data, sim_data, plot_params)
101 
102  if ~isfield(plot_params, 'gcf') || isempty(plot_params.gcf)
103  ud.descr = this.descr;
104  ud.dmodel = this;
105  ud.sim_data = sim_data;
106  fig_handle = default_plot_control;
107  set(fig_handle, 'UserData', ud);
108  else
109  fig_handle = plot_params.gcf;
110  end
111  fig_ud = get(fig_handle, 'UserData');
112  if ~isempty(fig_ud) && isfield(fig_ud, 'plot_dir')
113  plot_dir = fig_ud.plot_dir;
114  else
115  args = ['-c ', sim_data.cell_array_name, ' ', sim_data.outdir, ' ', sim_data.prefix];
116  [status, res] = system([fullfile(rbmatlabhome, 'dune', 'time_scene_vis.sh'), ' ', args]);
117  plot_dir = strtrim(res);
118  set(fig_handle, 'CloseRequestFcn', @LinEvolDune.DetailedModel.close_figure_and_vtk_plot);
119  fig_ud.plot_dir = plot_dir;
120  set(fig_handle, 'UserData', fig_ud);
121  pause(1);
122  end
123 
124  if ~isfield(plot_params, 'timestep')
125  plot_params.timestep = 0;
126  end
127 
128  if isfield(plot_params, 'reload_required') && plot_params.reload_required
129  LinEvolDune.DetailedModel.issue_plot_command(plot_dir, ['reload ', num2str(plot_params.timestep)]);
130  else
131  LinEvolDune.DetailedModel.issue_plot_command(plot_dir, ['time ', num2str(plot_params.timestep)]);
132  end
133  p = fig_handle;
134  end
135  end
136 
137  methods (Static)
139  function U = get_dofs_from_sim_data(sim_data)
140 
141  U = sim_data.a;
142  end
143 
144  function U = get_dofs_at_time(sim_data, time)
145  U = sim_data.a;
146  end
147  end
148 
149  methods (Static, Hidden=true)
150 
151  function issue_plot_command(plot_dir, command)
152  f = fopen(fullfile(plot_dir, 'control.cfg'), 'w');
153  fprintf(f, command);
154  fclose(f);
155  system(['kill -SIGINT $(cat ', fullfile(plot_dir, 'tsv.pid'), ')']);
156  end
157 
158  function close_figure_and_vtk_plot(src, event)
159  fig_ud = get(gcf, 'UserData');
160  if ~isempty(fig_ud) && isfield(fig_ud, 'plot_dir')
161  plot_dir = fig_ud.plot_dir;
162  try
163  LinEvolDune.DetailedModel.issue_plot_command(plot_dir, 'exit');
164  pause(0.5);
165  catch me
166  disp('Could not issue the exit command to the Paraview renderer');
167  disp(me.message);
168  end
169  if exist(fullfile(plot_dir, 'tsv.pid'), 'file')
170  system(['rm -rf ', plot_dir]);
171  end
172  end
173  closereq
174  end
175  end
176 
177 end
static function ok = struct_check(descr, checks)
executes checks on the fields of a structure object
Definition: IModel.m:210
Reduced basis implementation for linear evolution equations.
Interface classes to be implemented by the Greedy.Algorithm user.
static const ddescr_checks
This constant is used for a consistency check of the model descr with help of Greedy.Remove.IDetailedModelBase.struct_check()
Definition: DetailedModel.m:63
Interface specialization of an IDetailedModel ready to use with Greedy algorithms for (time dependent...
This is the interface for a detailed model providing methods to compute high dimensional simulation s...
Detailed model for a linear evolution problem with a Finite volume discretization.
Definition: DetailedModel.m:18
function p = plot_sim_data(model, model_data, sim_data, plot_params)
function performing the plot of the simulation results as specified in model.
Definition: plot_sim_data.m:17
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1
Detailed model for a linear evolution problem with a Finite volume discretization.
Definition: DetailedModel.m:18
function varargout = default_plot_control(varargin)
DEFAULT_PLOT_CONTROL M-file for default_plot_control.fig DEFAULT_PLOT_CONTROL, by itself...