edge_refined_elem_mapper

PURPOSE ^

EDGE_REFINED_ELEM_MAPPER: map elements from coarse to dense model

SYNOPSIS ^

function [index_simp]=edge_refined_elem_mapper( mdl_coarse, mdl_dense)

DESCRIPTION ^

 EDGE_REFINED_ELEM_MAPPER: map elements from coarse to dense model
 Calculates the index array mapping each dense mesh (from netgen)
  simp onto a coarse mesh (from netgen) simp.

 Usage:
  [index_simp]=edge_refined_elem_mapper( mdl_coarse, mdl_dense)

 (C) 2005 David Stephenson. Licensed under GPL v 2
 $Id: edge_refined_elem_mapper.m 5019 2015-05-25 07:56:23Z bgrychtol $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [index_simp]=edge_refined_elem_mapper( mdl_coarse, mdl_dense)
0002 % EDGE_REFINED_ELEM_MAPPER: map elements from coarse to dense model
0003 % Calculates the index array mapping each dense mesh (from netgen)
0004 %  simp onto a coarse mesh (from netgen) simp.
0005 %
0006 % Usage:
0007 %  [index_simp]=edge_refined_elem_mapper( mdl_coarse, mdl_dense)
0008 %
0009 % (C) 2005 David Stephenson. Licensed under GPL v 2
0010 % $Id: edge_refined_elem_mapper.m 5019 2015-05-25 07:56:23Z bgrychtol $
0011 
0012 warning('EIDORS:deprecated','EDGE_REFINED_ELEM_MAPPER is deprecated as of 06-Jun-2012. Use MK_C2F_MAPPING instead.');
0013 
0014 index_simp = eidors_obj('get-cache', {mdl_dense, mdl_coarse}, 'index_simp');
0015 if ~isempty(index_simp)
0016    eidors_msg('edge_refined_elem_mapper: using cached value', 2);
0017    return
0018 end
0019 
0020 vtx_coarse =  mdl_coarse.nodes;
0021 simp_coarse = mdl_coarse.elems;
0022 vtx_dense =  mdl_dense.nodes;
0023 simp_dense = mdl_dense.elems;
0024 
0025 eidors_msg('edge_refined_elem_mapper: lookup_bld',4);
0026 [lookup]=lookup_bld(simp_coarse,simp_dense);
0027 
0028 eidors_msg('edge_refined_elem_mapper: center_of_simps',4);
0029 [center_simp_dense]=center_of_simps(simp_dense, vtx_dense);
0030 
0031 eidors_msg('edge_refined_elem_mapper: midpoints',4);
0032 [vtx_midpoints_coarse]=midpoints(vtx_coarse,simp_coarse);
0033 
0034 eidors_msg('edge_refined_elem_mapper: calc_h_refinement_centers',4);
0035 [center_h_refined_simps]=calc_h_refinement_centers(simp_coarse,vtx_coarse,vtx_midpoints_coarse);
0036 
0037 eidors_msg('edge_refined_elem_mapper: calc_simp_index',4);
0038 [index_simp] = calc_simp_index(simp_dense,center_simp_dense,center_h_refined_simps,lookup);
0039 
0040 % Cache the restult - it depends on both dense and coarse mdl
0041 eidors_obj('set-cache', {mdl_dense, mdl_coarse}, 'index_simp', index_simp);
0042 eidors_msg('edge_refined_elem_mapper: setting cached value', 2);
0043 
0044 
0045 function [lookup]=lookup_bld(simp_coarse,simp_dense);
0046 
0047 % This function calculates the lookup matrix of the dual mesh system (h-refinement) & is used for calculating index_simp.
0048 %
0049 % simp_coarse = the coarse mesh simp array.
0050 % simp_dense = the dense mesh simp array.
0051 
0052 a=size(simp_coarse,1); % i.e the number of coarse mesh elements
0053 b=size(simp_dense,1); % i.e the number of dense mesh elements
0054 
0055 lookup=zeros(b,1);
0056 
0057 x=1;
0058 y=8;
0059 
0060 for i=1:a;
0061 
0062    for ii=x:y;
0063 
0064       lookup(ii)=i;
0065 
0066       ii=ii+1;
0067 
0068    end
0069 
0070    x=x+8;
0071    y=y+8;
0072 
0073 end
0074 
0075 
0076 function [vtx_midpoints]=midpoints(vtx,simp);
0077 
0078 % Calculates The x y z co-ordinates of the 6 midpoints of a 4 node simp.
0079 %
0080 % vtx = The vertices matrix
0081 % simp = The simplices matrix
0082 % vtx_midpoints = The x y z co-ordinates of the 6 midpoints of a 4 node simp
0083 
0084 % Preallocation
0085 
0086 vtx_midpoints=zeros(size(simp,1),18);
0087 
0088 for i=1:size(simp,1);
0089 
0090 % Simp node 1~2
0091 x1=vtx(simp(i,1),1);
0092 y1=vtx(simp(i,1),2);
0093 z1=vtx(simp(i,1),3);
0094 x2=vtx(simp(i,2),1);
0095 y2=vtx(simp(i,2),2);
0096 z2=vtx(simp(i,2),3);
0097 
0098 
0099 x_mid=((x1+x2)/2);
0100 y_mid=((y1+y2)/2);
0101 z_mid=((z1+z2)/2);
0102 
0103 vtx_midpoints(i,1)=x_mid;
0104 vtx_midpoints(i,2)=y_mid;
0105 vtx_midpoints(i,3)=z_mid;
0106 
0107 % Simp node 1~3
0108 x1=vtx(simp(i,1),1);
0109 y1=vtx(simp(i,1),2);
0110 z1=vtx(simp(i,1),3);
0111 x2=vtx(simp(i,3),1);
0112 y2=vtx(simp(i,3),2);
0113 z2=vtx(simp(i,3),3);
0114 
0115 x_mid=((x1+x2)/2);
0116 y_mid=((y1+y2)/2);
0117 z_mid=((z1+z2)/2);
0118 
0119 vtx_midpoints(i,4)=x_mid;
0120 vtx_midpoints(i,5)=y_mid;
0121 vtx_midpoints(i,6)=z_mid;
0122 
0123 % Simp node 1~4
0124 x1=vtx(simp(i,1),1);
0125 y1=vtx(simp(i,1),2);
0126 z1=vtx(simp(i,1),3);
0127 x2=vtx(simp(i,4),1);
0128 y2=vtx(simp(i,4),2);
0129 z2=vtx(simp(i,4),3);
0130 
0131 x_mid=((x1+x2)/2);
0132 y_mid=((y1+y2)/2);
0133 z_mid=((z1+z2)/2);
0134 
0135 vtx_midpoints(i,7)=x_mid;
0136 vtx_midpoints(i,8)=y_mid;
0137 vtx_midpoints(i,9)=z_mid;
0138 
0139 % Simp node 2~3
0140 x1=vtx(simp(i,2),1);
0141 y1=vtx(simp(i,2),2);
0142 z1=vtx(simp(i,2),3);
0143 x2=vtx(simp(i,3),1);
0144 y2=vtx(simp(i,3),2);
0145 z2=vtx(simp(i,3),3);
0146 
0147 x_mid=((x1+x2)/2);
0148 y_mid=((y1+y2)/2);
0149 z_mid=((z1+z2)/2);
0150 
0151 vtx_midpoints(i,10)=x_mid;
0152 vtx_midpoints(i,11)=y_mid;
0153 vtx_midpoints(i,12)=z_mid;
0154 
0155 
0156 % Simp node 2~4
0157 x1=vtx(simp(i,2),1);
0158 y1=vtx(simp(i,2),2);
0159 z1=vtx(simp(i,2),3);
0160 x2=vtx(simp(i,4),1);
0161 y2=vtx(simp(i,4),2);
0162 z2=vtx(simp(i,4),3);
0163 
0164 x_mid=((x1+x2)/2);
0165 y_mid=((y1+y2)/2);
0166 z_mid=((z1+z2)/2);
0167 
0168 vtx_midpoints(i,13)=x_mid;
0169 vtx_midpoints(i,14)=y_mid;
0170 vtx_midpoints(i,15)=z_mid;
0171 
0172 % Simp node 3~4
0173 x1=vtx(simp(i,3),1);
0174 y1=vtx(simp(i,3),2);
0175 z1=vtx(simp(i,3),3);
0176 x2=vtx(simp(i,4),1);
0177 y2=vtx(simp(i,4),2);
0178 z2=vtx(simp(i,4),3);
0179 
0180 x_mid=((x1+x2)/2);
0181 y_mid=((y1+y2)/2);
0182 z_mid=((z1+z2)/2);
0183 
0184 vtx_midpoints(i,16)=x_mid;
0185 vtx_midpoints(i,17)=y_mid;
0186 vtx_midpoints(i,18)=z_mid;
0187 
0188 i=i+1;
0189 
0190 end
0191 
0192 function [center_h_refined_simps]=calc_h_refinement_centers(simp,vtx,vtx_midpoints);
0193 
0194 % This function calculates the center of mass of each h-refined simp from the coarse mesh.
0195 %
0196 % vtx      = The vertices matrix
0197 % simp     = The simplices matrix
0198 % vtx_midpoints  = The x y z co-ordinates of the 6 midpoints of a 4 node simp
0199 % center_h_refined_simps = the center of mass of each h-refined simp from the coarse mesh
0200 
0201 vtx_dave_1=[];
0202 vtx_dave_2=[];
0203 simp_dave=[1 5 6 7;2 5 8 9;3 6 8 10;4 7 9 10;5 6 7 9;5 6 8 9;6 7 9 10;6 8 9 10];
0204 center_simp_proximity=[];
0205 
0206 for i=1:size(simp,1);
0207 
0208    vtx_dave_1(1,1)=vtx(simp(i,1),1);
0209    vtx_dave_1(1,2)=vtx(simp(i,1),2);
0210    vtx_dave_1(1,3)=vtx(simp(i,1),3);
0211 
0212    vtx_dave_1(2,1)=vtx(simp(i,2),1);
0213    vtx_dave_1(2,2)=vtx(simp(i,2),2);
0214    vtx_dave_1(2,3)=vtx(simp(i,2),3);
0215 
0216    vtx_dave_1(3,1)=vtx(simp(i,3),1);
0217    vtx_dave_1(3,2)=vtx(simp(i,3),2);
0218    vtx_dave_1(3,3)=vtx(simp(i,3),3);
0219 
0220    vtx_dave_1(4,1)=vtx(simp(i,4),1);
0221    vtx_dave_1(4,2)=vtx(simp(i,4),2);
0222    vtx_dave_1(4,3)=vtx(simp(i,4),3);
0223 
0224    vtx_dave_2(1,1)=vtx_midpoints(i,1);
0225    vtx_dave_2(1,2)=vtx_midpoints(i,2);
0226    vtx_dave_2(1,3)=vtx_midpoints(i,3);
0227 
0228    vtx_dave_2(2,1)=vtx_midpoints(i,4);
0229    vtx_dave_2(2,2)=vtx_midpoints(i,5);
0230    vtx_dave_2(2,3)=vtx_midpoints(i,6);
0231 
0232    vtx_dave_2(3,1)=vtx_midpoints(i,7);
0233    vtx_dave_2(3,2)=vtx_midpoints(i,8);
0234    vtx_dave_2(3,3)=vtx_midpoints(i,9);
0235 
0236    vtx_dave_2(4,1)=vtx_midpoints(i,10);
0237    vtx_dave_2(4,2)=vtx_midpoints(i,11);
0238    vtx_dave_2(4,3)=vtx_midpoints(i,12);
0239 
0240    vtx_dave_2(5,1)=vtx_midpoints(i,13);
0241    vtx_dave_2(5,2)=vtx_midpoints(i,14);
0242    vtx_dave_2(5,3)=vtx_midpoints(i,15);
0243 
0244    vtx_dave_2(6,1)=vtx_midpoints(i,16);
0245    vtx_dave_2(6,2)=vtx_midpoints(i,17);
0246    vtx_dave_2(6,3)=vtx_midpoints(i,18);
0247 
0248    vtx_dave=[vtx_dave_1;vtx_dave_2];
0249 
0250    [center_simp_dave]=center_of_simps(simp_dave,vtx_dave);
0251 
0252    center_simp_proximity=[center_simp_proximity;center_simp_dave];
0253 
0254    vtx_dave_1=[];
0255    vtx_dave_2=[];
0256 
0257    i=i+1;
0258 
0259 end
0260 
0261 center_h_refined_simps=center_simp_proximity;
0262 
0263 
0264 
0265 function [index_simp] = calc_simp_index(simp_dense,centre_simp_dense,center_h_refined_simps,lookup);
0266 
0267 % Calculates the index array mapping each dense mesh (from netgen) simp onto a coarse mesh (from netgen) simp.
0268 %
0269 % simp_dense = The dense mesh simplices matrix
0270 % centre_simp_dense = The center of mass of each (netgen) dense mesh element
0271 % center_h_refined_simps = The center of mass of each h-refined simp from the coarse mesh
0272 % lookup = the lookup matrix of the dual mesh system (h-refinement)
0273 
0274 % Array pre-allocation
0275 
0276 dist_simp=zeros(size(simp_dense,1),1);
0277 index_simp=zeros(size(simp_dense,1),2);
0278 mat_dense=zeros(size(simp_dense,1),1);
0279 
0280 % Down to business ...
0281 
0282 h = waitbar(0,'Calculating Simplex Map');
0283 
0284 for id=1:size(simp_dense,1);   % for all dense center of simplicies
0285 
0286    waitbar(id/size(simp_dense,1))
0287 
0288    % find the x,y,z co-ord difference
0289    dx=centre_simp_dense(id,1)-center_h_refined_simps(:,1);
0290    dy=centre_simp_dense(id,2)-center_h_refined_simps(:,2);
0291    dz=centre_simp_dense(id,3)-center_h_refined_simps(:,3);
0292 
0293    dist_simp=sqrt((dx.^2)+(dy.^2)+(dz.^2));
0294 
0295 
0296    [m,I]=min(dist_simp);   % index out the minimum distance from the dense mesh to the id'th center of simplex
0297 
0298    index_simp(id,1)=lookup(I);
0299 
0300    index_simp(id,2)=m;   % write the actual minimum distance (as a quality control procedure)
0301 
0302 end
0303 
0304 close(h)
0305 
0306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0307 % This is part of the EIDORS suite.
0308 % Copyright (c) D.R Stephenson 2004
0309 % Copying permitted under terms of GNU GPL
0310 % See enclosed file gpl.html for details.
0311 % EIDORS 3D version XXX
0312 % MATLAB Version 6.5.0.180913a (R13)
0313 % MATLAB License Number: 1560
0314 % Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 1)
0315 % Java VM Version: Java 1.3.1_01 with Sun Microsystems Inc. Java HotSpot(TM) Client VM
0316 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0317 
0318 
0319

Generated on Fri 30-Dec-2022 19:44:54 by m2html © 2005