ng_mk_fwd_model

PURPOSE ^

NG_MK_FWD_MODEL: create a fwd_model object from a netgen vol file

SYNOPSIS ^

function [fwd_mdl]=ng_mk_fwd_model( ng_vol_filename, centres,name, stim_pattern, z_contact, postprocmesh)

DESCRIPTION ^

 NG_MK_FWD_MODEL: create a fwd_model object from a netgen vol file
 [fwd_mdl]= ...
      ng_mk_fwd_model( ng_vol_filename, centres, ...
                       name, stim_pattern, z_contact)

  ng_vol_filename:   filename output from netgen
  name:              name for object (if [] use ng_vol_filename)
  centres:           matrix of N x [x,y,z] electrode centres
                     centres can also be a Nx1 cell matrix of
                     functions which are 1 inside the electrode and 0 outside
  stim_pattern:      a stimulation pattern structure
                     empty ([]) if stim_pattern is not available
  z_contact:         vector or scalar electrode contact impedance

  fwd_mdl:           eidors format fwd_model
  fwd_mdl.mat_idx:   cell array of indices into netgen material properties
 (C) 2006 Andy Adler. (C) 2013 Alistair Boyle. License: GPL version 2 or version 3
 $Id: ng_mk_fwd_model.m 5908 2019-02-12 07:23:19Z aadler $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [fwd_mdl]= ...
0002              ng_mk_fwd_model( ng_vol_filename, centres, ...
0003                               name, stim_pattern, z_contact, postprocmesh)
0004 % NG_MK_FWD_MODEL: create a fwd_model object from a netgen vol file
0005 % [fwd_mdl]= ...
0006 %      ng_mk_fwd_model( ng_vol_filename, centres, ...
0007 %                       name, stim_pattern, z_contact)
0008 %
0009 %  ng_vol_filename:   filename output from netgen
0010 %  name:              name for object (if [] use ng_vol_filename)
0011 %  centres:           matrix of N x [x,y,z] electrode centres
0012 %                     centres can also be a Nx1 cell matrix of
0013 %                     functions which are 1 inside the electrode and 0 outside
0014 %  stim_pattern:      a stimulation pattern structure
0015 %                     empty ([]) if stim_pattern is not available
0016 %  z_contact:         vector or scalar electrode contact impedance
0017 %
0018 %  fwd_mdl:           eidors format fwd_model
0019 %  fwd_mdl.mat_idx:   cell array of indices into netgen material properties
0020 % (C) 2006 Andy Adler. (C) 2013 Alistair Boyle. License: GPL version 2 or version 3
0021 % $Id: ng_mk_fwd_model.m 5908 2019-02-12 07:23:19Z aadler $
0022 
0023 if isempty(name); 
0024    name = ['MDL from', ng_vol_filename];
0025 end
0026 
0027 if nargin<5
0028    z_contact=0.01; % singular if z_contact=0
0029 end
0030 
0031 % Model Geometry
0032 [srf,vtx,fc,bc,simp,edg,mat_ind] = ng_read_mesh(ng_vol_filename);
0033 if isempty(vtx); 
0034    error('EIDORS: ng_mk_fwd_model: Netgen meshing failed. Stopping');
0035 end
0036 if nargin>=6
0037     N_elec = max(size(centres));
0038     [srf,vtx,fc,bc,simp,edg,mat_ind] = feval(postprocmesh,...
0039         srf,vtx,fc,bc,simp,edg,mat_ind, N_elec);
0040 end
0041 fwd_mdl= construct_fwd_model(srf,vtx,simp,bc, name, ...
0042                              stim_pattern, centres, z_contact,fc);
0043 
0044 [fwd_mdl.mat_idx] = mk_mat_indices(mat_ind);
0045 
0046 if ~isfield(fwd_mdl,'normalize_measurements')
0047    fwd_mdl.normalize_measurements = 0;
0048 end
0049 
0050 % build fwd_model structure
0051 function fwd_mdl= construct_fwd_model(srf,vtx,simp,bc, name, ...
0052                        stim_pattern, centres, z_contact,fc)
0053 mdl.nodes    = vtx;
0054 mdl.elems    = simp;
0055 mdl.boundary = srf;
0056 mdl.boundary_numbers=fc;    
0057 mdl.gnd_node=    find_centre_node(vtx);
0058 mdl.np_fwd_solve.perm_sym =     '{n}';
0059 mdl.name = name;
0060 
0061 % Model Stimulation
0062 if ~isempty(stim_pattern)
0063    mdl.stimulation= stim_pattern;
0064 end
0065 
0066 nelec= size(centres,1);
0067 if nelec>0
0068    % Electrodes
0069    [elec,sels,electrodes] = ng_tank_find_elec(srf,vtx,bc,centres);
0070    if size(elec,1) ~= nelec
0071       error('Failed to find all the electrodes')
0072    end
0073 
0074    % set the z_contact
0075    z_contact= z_contact.*ones(nelec,1);
0076    for i=1:nelec
0077       electrodes(i).z_contact= z_contact(i);
0078    end
0079 
0080    mdl.electrode =     electrodes;
0081 end
0082 
0083 mdl.solve=      'eidors_default';
0084 mdl.jacobian=   'eidors_default';
0085 mdl.system_mat= 'eidors_default';
0086 
0087 fwd_mdl= eidors_obj('fwd_model', mdl);
0088 
0089 % Output mat_idx cell array of indices into each material
0090 % typei. Array order is the order of the specified material
0091 % (netgen 'tlo' statements in the .geo file).
0092 function [mat_idx] = mk_mat_indices( mat_ind);
0093   % find length of mat_indices
0094   % test example: mat_ind=[10 12 14 14 12 12 14 12];
0095 
0096   if isempty(mat_ind)
0097      mat_idx = [];
0098      return
0099   end
0100   mat_indices = unique( mat_ind );
0101   for i= 1:length(mat_indices);
0102      mat_idx{i}= find(mat_ind == mat_indices(i));
0103   end
0104 
0105 function gnd_node=    find_centre_node(vtx);
0106   %distance from zero
0107   d = sum( vtx.^2, 2);
0108   [jnk,gnd_node] = min(d);
0109   gnd_node= gnd_node(1);

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