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 5567 2017-06-20 10:54:28Z aadler $
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 copt.cache_obj = img;
0081 copt.boost_priority = -2; % fmdl evaluations are low priority
0082 data = eidors_cache(solver, {img}, copt);
0083 data= eidors_obj('data',data);  % create data object
0084 
0085 
0086 if isa(fwd_model.solve,'function_handle')
0087     solver = func2str(fwd_model.solve);
0088 else
0089     solver = fwd_model.solve;
0090 end
0091 if strcmp(solver,'eidors_default');
0092     solver = eidors_default('get','fwd_solve');
0093 end
0094 if isfield(fwd_model,'measured_quantity') && ~isfield(data,'measured_quantity')
0095    warning('EIDORS:MeasurementQuantityObliviousSolver',...
0096       ['The solver %s did not handle the requested measurement quantity properly.\n'...
0097        'The results may be incorrect. Please check the code to verify.'], ...
0098        solver);
0099 elseif isfield(fwd_model,'measured_quantity') ... 
0100         && isfield(data,'measured_quantity') ...
0101         && ~strcmp(fwd_model.measured_quantity, data.measured_quantity)
0102    error('EIDORS:MeasurementQuantityDisagreement',...
0103        'The solver %s return measurements as %s, while %s was expected.',...
0104        solver, data.measured_quantity, fwd_model.measured_quantity);
0105 end
0106     
0107 warning on EIDORS:DeprecatedInterface
0108 
0109 
0110 function mdl = prepare_model( mdl )
0111 mdl = mdl_normalize(mdl,mdl_normalize(mdl));
0112 if ~isfield(mdl,'elems');
0113     return;
0114 end
0115 
0116 mdl.elems  = double(mdl.elems);
0117 mdl.n_elem = size(mdl.elems,1);
0118 mdl.n_node = size(mdl.nodes,1);
0119 if isfield(mdl,'electrode');
0120     mdl.n_elec = length(mdl.electrode);
0121 else
0122     mdl.n_elec = 0;
0123 end

Generated on Wed 21-Jun-2017 09:29:07 by m2html © 2005