0001 function [e res] = calc_solution_error(imgc, imdl, vh, vi)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 switch imdl.reconst_type
0027 case 'difference'
0028 if nargin==4
0029 data = calc_difference_data(vh,vi,imdl.fwd_model);
0030 else
0031 if isstruct(vh)
0032 data = vh.meas;
0033 else
0034 data = vh;
0035 end
0036 end
0037 res = calc_diff_residual(imgc,imdl,data);
0038 case {'absolute', 'static'}
0039 if isstruct(vh)
0040 data = vh.meas;
0041 else
0042 data = vh;
0043 end
0044 res = calc_abs_residual(imgc,imdl,data);
0045 otherwise
0046 error('reconst_type not recognized');
0047 end
0048
0049
0050
0051 e = norm(res)/norm(data);
0052
0053
0054 function res = calc_abs_residual(imgc,imdl,data)
0055 fmdl = imdl.fwd_model;
0056
0057
0058 img = calc_jacobian_bkgnd(imdl);
0059 img = data_mapper(img);
0060 imgc = data_mapper(imgc);
0061
0062
0063 if size(img.elem_data,1) == size(imgc.elem_data,1)
0064 img.elem_data = imgc.elem_data;
0065 else
0066 img.elem_data = fmdl.coarse2fine*imgc.elem_data;
0067 end
0068 img = data_mapper(img);
0069
0070
0071 sim = fwd_solve(img);
0072
0073
0074 res = sim.meas - data;
0075
0076
0077
0078 function res = calc_diff_residual(imgc,imdl,data)
0079
0080 fmdl = imdl.fwd_model;
0081 img = calc_jacobian_bkgnd(imdl);
0082 simh = fwd_solve(img);
0083
0084
0085 img = data_mapper(img);
0086 imgc = data_mapper(imgc);
0087
0088 if ~isfield(imgc,'elem_data') && isfield(imgc,'node_data')
0089 eidors_msg('Solution error calculation for nodal solvers not supported (yet).',2);
0090 res = NaN;
0091 return
0092 end
0093
0094
0095 e_data = repmat(img.elem_data,1,size(imgc.elem_data,2));
0096 has_c2f = isfield(imgc.fwd_model,'coarse2fine');
0097 if ~has_c2f
0098 n_elems = num_elems(imgc.fwd_model);
0099 img.elem_data = e_data + imgc.elem_data(1:n_elems,:);
0100 else
0101 n_elems = size(imgc.fwd_model.coarse2fine,2);
0102 img.elem_data = e_data + fmdl.coarse2fine*imgc.elem_data(1:n_elems,:);
0103 end
0104 img = data_mapper(img,1);
0105
0106
0107 jnk = img;
0108 for i = fliplr(1:size(imgc.elem_data,2));
0109 jnk.elem_data = img.elem_data(:,i);
0110 tmp = fwd_solve(jnk);
0111 simi(:,i) = tmp.meas;
0112 end
0113 sim = calc_difference_data(simh,simi,fmdl);
0114
0115
0116 res = data - sim;