0001 function [fwd_model] = linear_reorder(fwd_model,ccw)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if isstr(fwd_model) && strcmp(fwd_model,'UNIT_TEST'); do_unit_test; return; end
0014
0015 if (nargin==1)
0016 ccw=-1;
0017 end
0018
0019 nodecoords = fwd_model.nodes;
0020 elementnodes = fwd_model.elems;
0021
0022 eletotal = size(elementnodes,1);
0023 elenode = size(elementnodes,2);
0024
0025 for e=1:eletotal;
0026
0027 enodes = elementnodes(e,:);
0028
0029 nd = nodecoords(enodes,:);
0030
0031
0032
0033 area= det([ones(elenode,1),nd]);
0034 areasign=sign(area);
0035
0036
0037 if(areasign == ccw)
0038 temp=enodes(elenode-1);
0039 enodes(elenode-1)=enodes(elenode);
0040 enodes(elenode) = temp;
0041
0042 end
0043 elementnodes(e,:)=enodes;
0044 end
0045 fwd_model.elems=elementnodes;
0046
0047
0048
0049 function do_unit_test
0050 imdl = mk_common_model('n3r2',32); fmdl = imdl.fwd_model;
0051 fm1 = linear_reorder(fmdl);
0052 vol1= test_linear_reorder( fm1 );
0053 ok = all(vol1>0);
0054 fprintf('test1 3d: OK=%d\n',ok);
0055
0056 fm1 = linear_reorder(fmdl, 1);
0057 vol1= test_linear_reorder( fm1 );
0058 ok = all(vol1<0);
0059 fprintf('test2 3d: OK=%d\n',ok);
0060
0061 imdl = mk_common_model('a2c2',8); fmdl = imdl.fwd_model;
0062 fm1 = linear_reorder(fmdl);
0063 vol1= test_linear_reorder( fm1 );
0064 ok = all(vol1>0);
0065 fprintf('test1 2d: OK=%d\n',ok);
0066
0067 fm1 = linear_reorder(fmdl, 1);
0068 vol1= test_linear_reorder( fm1 );
0069 ok = all(vol1<0);
0070 fprintf('test2 2d: OK=%d\n',ok);
0071
0072
0073
0074 function vol = test_linear_reorder(fwd_model)
0075
0076 dim=size(fwd_model.nodes,2); elee=size(fwd_model.elems,1);
0077
0078 for e=1:elee
0079 b=fwd_model.elems(e,:); [v]=fwd_model.nodes(b,:);
0080 for i=1:dim
0081 vv1(i,:)=v(i+1,:)-v(1,:);
0082 end
0083 vol(e)=det([vv1]);
0084 end
0085