0001 function [fwd_mdl, mat_indices]= ...
0002 gmsh_mk_fwd_model( vol_filename, name, eprefix,stim_pattern, z_contact)
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 if isempty(name);
0024 name = ['fwd_mdl based on ', vol_filename];
0025 end
0026
0027 if nargin < 4
0028 stim_pattern=[];
0029 end
0030
0031 if nargin<3 || isempty(eprefix);
0032 eprefix = 'electrode-';
0033 end
0034
0035 if nargin<5
0036 z_contact=0.01;
0037 end
0038
0039
0040
0041 [srf,vtx,fc,bc,simp,edg,mat_ind,phys_names] = gmsh_read_mesh(vol_filename);
0042 fwd_mdl= construct_fwd_model(srf,vtx,simp,bc, name, ...
0043 stim_pattern, eprefix, z_contact, fc,phys_names);
0044 mat_indices= mk_mat_indices( mat_ind);
0045 if isempty(srf)
0046 fwd_mdl.boundary = find_boundary(fwd_mdl);
0047 end
0048
0049 fwd_mdl.mat_idx = mat_indices;
0050
0051
0052 function fwd_mdl= construct_fwd_model(srf,vtx,simp,bc, name, ...
0053 stim_pattern, eprefix, z_contact, fc, phys_names)
0054 mdl.nodes = vtx;
0055 mdl.elems = simp;
0056 mdl.boundary = srf;
0057 mdl.boundary_numbers=fc;
0058 mdl.gnd_node = 1;
0059 mdl.name = name;
0060
0061
0062 if ~isempty(stim_pattern)
0063 mdl.stimulation= stim_pattern;
0064 end
0065
0066
0067 electrodes = find_elec(phys_names,eprefix,z_contact);
0068 if ~isempty(fieldnames(electrodes));
0069 mdl.electrode = electrodes;
0070 end
0071 mdl.solve= 'eidors_default';
0072 mdl.jacobian= 'eidors_default';
0073 mdl.system_mat= 'eidors_default';
0074
0075 fwd_mdl= eidors_obj('fwd_model', mdl);
0076
0077
0078
0079 function mat_indices= mk_mat_indices( mat_ind);
0080
0081
0082 sort_mi= sort(mat_ind(:));
0083 find_mi= find( diff([-1e8;sort_mi]) );
0084 len_mi = diff([find_mi;length(sort_mi)+1]);
0085 [jnk,idxs]= sort(-len_mi);
0086 l_idxs= length(idxs);
0087 mat_indices= cell(1, l_idxs);
0088 for i= 1:l_idxs;
0089 mat_idx_i= sort_mi(find_mi(idxs(i)));
0090 mat_indices{i}= find(mat_ind == mat_idx_i);
0091 end
0092
0093
0094 function electrodes = find_elec(phys_names,prefix,z_contact)
0095 electrodes = struct();
0096 phys_elecs = find(arrayfun(@(x)strncmp(x.name,prefix,length(prefix)),phys_names));
0097 for i = 1:length(phys_elecs)
0098 cur_elec = arrayfun(@(x)strcmp(sprintf('%s%d',prefix,i),x.name),phys_names(phys_elecs));
0099 electrodes(i).nodes = unique(phys_names(phys_elecs(cur_elec)).nodes(:));
0100 electrodes(i).z_contact = z_contact;
0101 end