rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
test_two_phase_datafunc.m
Go to the documentation of this file.
1 function OK = test_two_phase_datafunc
2 % performing a test of the correct implementation of derivatives in
3 % TwoPhaseData class.
4 %
5 % It generates a simple '2x2' on which the gradients of the functions are
6 % computed numerically.
7 %
8 % Return values:
9 % OK: '1', if test is OK, '0' otherwise
10 
11 % Martin Drohmann 21.05.2008
12 
13  OK = 1;
14 
15  tpd = TwoPhaseData.Michel;
16  OK = check_two_phase(tpd, 'michel') & OK;
17  tpd = TwoPhaseData.BrooksCorey;
18  OK = check_two_phase(tpd, 'brooks_corey') & OK;
19  tpd = TwoPhaseData.MichelSimple;
20  OK = check_two_phase(tpd, 'michel_simple') & OK;
21 end
22 
23 function OK = check_two_phase(tpd, title_prefix)
24  descr = tpd.default_descr([]);
25  descr.h = 5e-7;
26 
27  OK = check_convergence(@water_permeability, @water_permeability_derivative, tpd, descr, [title_prefix, '_water']);
28  OK = check_convergence(@oil_permeability, @oil_permeability_derivative, tpd, descr, [title_prefix, '_oil']) & OK;
29  OK = check_convergence(@capillary_pressure, @capillary_pressure_derivative, tpd, descr, [title_prefix, '_pressure']) & OK;
30  OK = check_convergence(@capillary_pressure_derivative, @capillary_pressure_second_derivative, tpd, descr, [title_prefix, '_pressure_deriv']) & OK;
31  OK = check_convergence(@phi, @phi_derivative, tpd, descr, [title_prefix, '_phi']) & OK;
32  OK = check_convergence(@Phi, @phi, tpd, descr, [title_prefix, '_Phi']) & OK;
33  OK = check_convergence(@waterflow, @waterflow_derivative, tpd, descr, [title_prefix, '_waterflow']) & OK;
34  OK = check_convergence(@total_mobility, @total_mobility_deriv, tpd, descr, [title_prefix, '_mobility']) & OK;
35 end
36 
37 
38 function [OK] = check_convergence(f,df,tpd, descr, title)
39  % EOC convergence check of discrete gradient computations
40  OK = 1;
41 
42  maxerr = zeros(1,7);
43  h = 0.1;
44 
45  for refstep=1:7
46 
47  c_df = f(tpd, [], 0.1:h:0.9, descr);
48  if isfield(c_df, 'K')
49  c_df = diff(c_df.K) / h;
50  else
51  c_df = diff(c_df) / h;
52  end
53  df_c = df(tpd, [], 0.1+h/2:h:0.9-h/2, descr);
54  if isfield(df_c, 'K')
55  df_c = df_c.K;
56  end
57 
58  maxerr(refstep) = max(abs(df_c - c_df));
59 
60  h = h/2;
61 
62  end
63  eocrefstep = log(maxerr(1:end-1)./maxerr(2:end))/log(2);
64  if any(eocrefstep(1:3) ~=0) && (min(eocrefstep(3:end)) < 1.5 && max(maxerr(3:end)) > 1e-13)
65  disp(['gradient for ', title, ' incorrect!']);
66  disp(['EOC sequence has too small entries(<1.5): ', mat2str(eocrefstep)]);
67  keyboard;
68  OK = 0;
69  end
70 end
71