rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
DetailedModel.m
1 classdef DetailedModel < IDetailedModel
2  % Detailed model for a linear stationary problem with a discretization
3  % implemented in Dune-RB
4  %
5  % This is a detailed model for a problem type 'rb_problem_type' =
6  % "LinStatDune"
7  %
8  % It solves discretization of the form
9  % `` A u = r, ``
10  % with a matrix `A` and a right hand side `r` returned by
11  % '[A,r] = descr.operators(descr, model_data)'
12  %
13  % Furthermore, an output fuctional can be defined by the description field
14  % 'descr.operators_output(descr, model_data);'
15 
16  methods
17  function dm = DetailedModel(descr)
18  % function dm = DetailedModel(descr)
19  % constructor based on problem description
20  %
21  % Parameters:
22  % descr: structure describing the problem and the descretization
23  dm = dm@IDetailedModel(descr);
24  end
25 
26  function this = set_mu(this, mu)
27  % function this = set_mu(this, mu, propagate)
28  % sets the active parameter vector `\mu \in {\cal M}`
29  %
30  % The parameter set here, is used by the detailed_simulation() function.
31  %
32  % The default implementation sets all fieldnames 'descr.mu_names' in the
33  % #descr struct.
34  %
35  % Parameters:
36  % mu: The parameter vector `\boldsymbol\mu`.
37  %
38  % Return values:
39  % this: handle of type IDetailedModel to the changed DetailedModel
40 
41  assert(length(mu) == length(this.descr.mu_names));
42 
43  this.descr.mexptr('set_mu', mu);
44  end
45 
46  function mu = get_mu(this)
47  % function mu = get_mu(this)
48  % returns the active parameter vector `\boldsymbol\mu \in {\cal M}`
49  %
50  % The default implementation returns a vector of the values of the fields
51  % of the #descr structure with names 'descr.mu_names'.
52  %
53  % Return values:
54  % mu: The parameter vector `\boldsymbol\mu`
55 
56  mu = this.descr.mexptr('get_mu');
57  end
58  function sim_data = detailed_simulation(this, model_data)
59  sim_data = this.descr.mexptr('detailed_simulation');
60  end
61 
62  function model_data = gen_model_data(this)
63  model_data.id = this.descr.mexptr('gen_model_data');
64  model_data.mexptr = this.descr.mexptr;
65  end
66 
67  function p = plot_sim_data(this, model_data, sim_data, plot_params)
68 
69  if ~isfield(plot_params, 'gcf') || isempty(plot_params.gcf)
70  ud.descr = this.descr;
71  ud.dmodel = this;
72  ud.sim_data = sim_data;
73  fig_handle = lin_stat_plot_control;
74  set(fig_handle, 'UserData', ud);
75  else
76  fig_handle = plot_params.gcf;
77  end
78  fig_ud = get(fig_handle, 'UserData');
79  if ~isempty(fig_ud) && isfield(fig_ud, 'plot_dir')
80  plot_dir = fig_ud.plot_dir;
81  else
82  outdir = fullfile(this.descr.run_dir, sim_data.outdir);
83  args = ['-c ', sim_data.cell_array_name, ' ', outdir, ' ', sim_data.prefix];
84  [status, res] = system([fullfile(rbmatlabhome, 'dune', 'lin_stat_visualize.sh'), ' ', args]);
85  plot_dir = strtrim(res);
86  set(fig_handle, 'CloseRequestFcn', @LinEvolDune.DetailedModel.close_figure_and_vtk_plot);
87  fig_ud.plot_dir = plot_dir;
88  set(fig_handle, 'UserData', fig_ud);
89  pause(1);
90  end
91 
92  if ~isfield(plot_params, 'angle')
93  plot_params.angle = 0;
94  end
95 
96  if isfield(plot_params, 'reload_required') && plot_params.reload_required
97  LinStatDune.DetailedModel.issue_plot_command(plot_dir, ['reload ', num2str(plot_params.angle)]);
98  else
99  LinStatDune.DetailedModel.issue_plot_command(plot_dir, ['update ', num2str(plot_params.angle)]);
100  end
101  p = fig_handle;
102  end
103  end
104 
105  methods (Static)
106 
107  function U = get_dofs_from_sim_data(sim_data)
108 
109  U = sim_data.uN;
110  end
111 
112 % function U = get_dofs_at_time(sim_data, time)
113 % U = sim_data.a;
114 % end
115  end
116 
117  methods (Static, Hidden=true)
118 
119  function issue_plot_command(plot_dir, command)
120  f = fopen(fullfile(plot_dir, 'control.cfg'), 'w');
121  fprintf(f, command);
122  fclose(f);
123  system(['kill -SIGINT $(cat ', fullfile(plot_dir, 'tsv.pid'), ')']);
124  end
125 
126  function close_figure_and_vtk_plot(src, event)
127  fig_ud = get(gcf, 'UserData');
128  if ~isempty(fig_ud) && isfield(fig_ud, 'plot_dir')
129  plot_dir = fig_ud.plot_dir;
130  try
131  LinEvolDune.DetailedModel.issue_plot_command(plot_dir, 'exit');
132  pause(0.5);
133  catch me
134  disp('Could not issue the exit command to the Paraview renderer');
135  disp(me.message);
136  end
137  if exist(fullfile(plot_dir, 'tsv.pid'), 'file')
138  system(['rm -rf ', plot_dir]);
139  end
140  end
141  closereq
142  end
143  end
145 end
Detailed model for a linear stationary problem with a discretization implemented in Dune-RB...
Definition: DetailedModel.m:18
This is the interface for a detailed model providing methods to compute high dimensional simulation s...
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