rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
DetailedModel.m
1 classdef DetailedModel < Greedy.User.FVDetailedModelDefault
2  % IDetailedModel implementation for a two phase flow system
3  %
4  % This is a detailed model for a problem of this type
5  %
6  %
7 
8  properties(Constant)
9  % This constant is used for a consistency check of the model descr with
10  % help of DetailedModelBaseIf.struct_check()
11  %
12  % This check is only executed if we use a Newton scheme
13  newton_checks = struct(...
14  'newton_steps', {{@isscalar}},...
15  'newton_epsilon', {{@isscalar}}...
16  );
17  end
18 
19  properties (Dependent)
20  % current time instance
21  t;
22 
23  % current time step
24  tstep;
25  end
26 
27  properties
28  % boolean flag indicating whether conditions of system matrices shall be computed.
29  compute_conditions = false;
30  end
31 
32  methods
33  function dm = DetailedModel(descr)
34  % function dm = DetailedModel(descr)
35  % constructor
36  %
37  % This checks and stores the model description structure
38  %
39  % Required fields of descr:
40  % newton_solver: boolean flag indicating whether we are using a Newton
41  % scheme for the discretization.
42  dm = dm@Greedy.User.FVDetailedModelDefault(descr);
43  if ~IDetailedModel.struct_check(descr, TwoPhaseFlow.DetailedModel.newton_checks)
44  error('Consistency check of description for Newton solver problems failed!');
45  end
46  end
47 
48  sim_data = detailed_simulation(model, model_data);
49 
50  sim_data = detailed_simulation_galerkin(model, detailed_data);
51 
52  sim_data = detailed_simulation_impes(model, model_data);
53 
54  model_data = gen_model_data(model);
55 
56  p = plot_sim_data(dmodel, model_data, sim_data, plot_params);
57 
58  function plot_error_sequence(dmodel, errs)
59  if length(errs.S) == dmodel.descr.nt+1
60  times = 0:dmodel.descr.dt:dmodel.descr.T;
61  else
62  times = 1:length(errs.S);
63  end
64  plot(times, errs.S, 'k-', times, errs.U, 'b:', times, errs.P, 'r-.');
65  legend('S', 'U', 'P');
66  end
67  end
68 
69  methods (Static)
70 
71  function U = get_dofs_from_sim_data(sim_data)
72 
73  if isfield(sim_data, 'Stemp');
74  U.S = [sim_data.S, sim_data.Stemp];
75  U.P = [sim_data.P, sim_data.Ptemp];
76  U.U = [sim_data.U, sim_data.Utemp];
77  else
78  U = sim_data;
79  end
80 
81 
82  end
83 
84  function snapshot = get_dofs_at_time(sim_data, time_index)
85 
86  snapshot.S = sim_data.S(:,time_index);
87  snapshot.U = sim_data.U(:,time_index);
88  snapshot.P = sim_data.P(:,time_index);
89  end
90 
91  end
92 
93  methods
94  function t = get.t(this)
95  t = this.descr.t;
96  end
97 
98  function set.t(this, t)
99  this.descr.t = t;
100  end
101 
102  function tstep = get.tstep(this)
103  tstep = this.descr.tstep;
104  end
105 
106  function set.tstep(this, tstep)
107  this.descr.tstep = tstep;
108  end
109  end
110 
111  methods(Static)
112  function errs = l2_error_sequence_algorithm(U, Uapprox, model_data)
113  if size(U, 1) == model_data.grid.nelements
114  A = model_data.W;
115  else
116  A = model_data.diamondWinv;
117  end
118  errs = fv_l2_error(U, Uapprox, A);
119  end
120 
121  function errs = l2_error_sequence_complete(U, Uapprox, model_data)
122  errs.S = fv_l2_error(U.S, Uapprox.S, model_data.W);
123  errs.U = fv_l2_error(U.U, Uapprox.U, model_data.diamondWinv);
124  errs.P = fv_l2_error(U.P, Uapprox.P, model_data.W);
125  end
126 
127  function errs = linfty_error_sequence_complete(U, Uapprox, model_data)
128  errs.S = fv_linfty_error(U.S, Uapprox.S, model_data.W);
129  errs.U = fv_linfty_error(U.U, Uapprox.U, model_data.diamondWinv);
130  errs.P = fv_linfty_error(U.P, Uapprox.P, model_data.W);
131  end
132  end
133 
134 end