fwd_solve

PURPOSE ^

FWD_SOLVE: calculate data from a fwd_model object and an image

SYNOPSIS ^

function data = fwd_solve(fwd_model, img)

DESCRIPTION ^

 FWD_SOLVE: calculate data from a fwd_model object and an image
 
 fwd_solve can be called as
    data= fwd_solve( img)
 or (deprecated)
    data= fwd_solve( fwd_model, img)

 in each case it will call the fwd_model.solve
                        or img.fwd_model.solve method

 For reconstructions on dual meshes, the interpolation matrix
    is defined as fwd_model.coarse2fine. If required, this takes
    coarse2fine * x_coarse = x_fine

 data      is a measurement data structure
 fwd_model is a fwd_model structure
 img       is an img structure

 Options: (not available on all solvers)
    img.fwd_solve.get_all_meas = 1 (data.volt = all FEM nodes, but not CEM)
    img.fwd_solve.get_all_nodes= 1 (data.volt = all nodes, including CEM)
    img.fwd_solve.get_elec_curr= 1 (data.elec_curr = current on electrodes)

 Parameters:
    fwd_model.background = constant conductivity offset added to elem_data
    fwd_model.coarse2fine = linear mapping between img.elem_data and model parameters
    img.params_mapping = function mapping img.elem_data to model parameters

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function data = fwd_solve(fwd_model, img)
0002 % FWD_SOLVE: calculate data from a fwd_model object and an image
0003 %
0004 % fwd_solve can be called as
0005 %    data= fwd_solve( img)
0006 % or (deprecated)
0007 %    data= fwd_solve( fwd_model, img)
0008 %
0009 % in each case it will call the fwd_model.solve
0010 %                        or img.fwd_model.solve method
0011 %
0012 % For reconstructions on dual meshes, the interpolation matrix
0013 %    is defined as fwd_model.coarse2fine. If required, this takes
0014 %    coarse2fine * x_coarse = x_fine
0015 %
0016 % data      is a measurement data structure
0017 % fwd_model is a fwd_model structure
0018 % img       is an img structure
0019 %
0020 % Options: (not available on all solvers)
0021 %    img.fwd_solve.get_all_meas = 1 (data.volt = all FEM nodes, but not CEM)
0022 %    img.fwd_solve.get_all_nodes= 1 (data.volt = all nodes, including CEM)
0023 %    img.fwd_solve.get_elec_curr= 1 (data.elec_curr = current on electrodes)
0024 %
0025 % Parameters:
0026 %    fwd_model.background = constant conductivity offset added to elem_data
0027 %    fwd_model.coarse2fine = linear mapping between img.elem_data and model parameters
0028 %    img.params_mapping = function mapping img.elem_data to model parameters
0029 %
0030 
0031 % (C) 2005 Andy Adler. License: GPL version 2 or version 3
0032 % $Id: fwd_solve.m 5699 2018-03-07 15:52:44Z alistair_boyle $
0033 
0034 if nargin == 1
0035    img= fwd_model;
0036 else
0037    warning('EIDORS:DeprecatedInterface', ...
0038       ['Calling FWD_SOLVE with two arguments is deprecated and will cause' ...
0039        ' an error in a future version. First argument ignored.']);
0040 end
0041 ws = warning('query','EIDORS:DeprecatedInterface');
0042 warning off EIDORS:DeprecatedInterface
0043 
0044 fwd_model= img.fwd_model;
0045 
0046 
0047 fwd_model= prepare_model( fwd_model );
0048 
0049 % TODO: This should be handled by the data_mapper
0050 if isfield(img,'params_mapping')
0051 %     fwd_model data is provided using a mapping function
0052     mapping_function= img.params_mapping.function;
0053     img= feval(mapping_function,img);
0054 end
0055 if isfield(fwd_model,'coarse2fine') && isfield(img,'elem_data')
0056    c2f= fwd_model.coarse2fine;
0057    if size(img.elem_data,1)==size(c2f,2)
0058 %     fwd_model data is provided on coarse mesh
0059       img.elem_data = c2f * img.elem_data; 
0060 
0061       if isfield(fwd_model,'background')
0062           img.elem_data = img.elem_data + fwd_model.background; 
0063       end
0064    end
0065 end
0066 
0067 if ~isfield(fwd_model, 'electrode')
0068    error('EIDORS: attempting to solve on model without electrodes');
0069 end
0070 if ~isfield(fwd_model, 'stimulation')
0071    error('EIDORS: attempting to solve on model without stimulation patterns');
0072 end
0073 
0074 solver = fwd_model.solve;
0075 if ischar(solver)
0076     solver = str2func(solver);
0077 end
0078 
0079 copt.fstr = 'fwd_solve';
0080 n_frames = size(img.elem_data,2);
0081 for frame = 1:n_frames;
0082    imgn = img; imgn.elem_data = imgn.elem_data(:,frame,:,:);
0083    copt.cache_obj = imgn;
0084    copt.boost_priority = -2; % fmdl evaluations are low priority
0085    tmp = eidors_cache(solver, {imgn}, copt);
0086    data(frame) = eidors_obj('data',tmp);  % create data object
0087 end
0088 
0089 if isa(fwd_model.solve,'function_handle')
0090     solver = func2str(fwd_model.solve);
0091 else
0092     solver = fwd_model.solve;
0093 end
0094 if strcmp(solver,'eidors_default');
0095     solver = eidors_default('get','fwd_solve');
0096 end
0097 if isfield(fwd_model,'measured_quantity') && ~isfield(data,'measured_quantity')
0098    warning('EIDORS:MeasurementQuantityObliviousSolver',...
0099       ['The solver %s did not handle the requested measurement quantity properly.\n'...
0100        'The results may be incorrect. Please check the code to verify.'], ...
0101        solver);
0102 elseif isfield(fwd_model,'measured_quantity') ... 
0103         && isfield(data,'measured_quantity') ...
0104         && ~strcmp(fwd_model.measured_quantity, data.measured_quantity)
0105    error('EIDORS:MeasurementQuantityDisagreement',...
0106        'The solver %s return measurements as %s, while %s was expected.',...
0107        solver, data.measured_quantity, fwd_model.measured_quantity);
0108 end
0109     
0110 warning on EIDORS:DeprecatedInterface
0111 
0112 
0113 function mdl = prepare_model( mdl )
0114 mdl = mdl_normalize(mdl,mdl_normalize(mdl));
0115 if ~isfield(mdl,'elems');
0116     return;
0117 end
0118 
0119 mdl.elems  = double(mdl.elems);
0120 mdl.n_elem = size(mdl.elems,1);
0121 mdl.n_node = size(mdl.nodes,1);
0122 if isfield(mdl,'electrode');
0123     mdl.n_elec = length(mdl.electrode);
0124 else
0125     mdl.n_elec = 0;
0126 end

Generated on Tue 31-Dec-2019 17:03:26 by m2html © 2005