0001
0002 function [Agal,elemstiff]=mc_calc_stiffness2(fwd_model,img)
0003
0004
0005
0006
0007 if(nargin==1)
0008 img=fwd_model; fwd_model=img.fwd_model;
0009 end
0010
0011
0012
0013 nodestruc=fwd_model.nodes; nodedim=size(nodestruc,2); nnodes=size(nodestruc,1);
0014 elemstruc=fwd_model.elems; nelems=size(elemstruc,1);
0015
0016
0017 eletype=fwd_model.approx_type;
0018 if(strcmp(eletype,'tri3'))
0019 dim=2; order1=0; order2=2;
0020 elseif(strcmp(eletype,'tri6'))
0021 dim=2; order1=2; order2=4;
0022 elseif(strcmp(eletype,'tri10'))
0023 dim=2; order1=4; order2=7;
0024 elseif(strcmp(eletype,'tet4'))
0025 dim=3; order1=0; order2=2;
0026 elseif(strcmp(eletype,'tet10'))
0027 dim=3; order1=2; order2=4;
0028 else
0029 error('Element type not recognised for integration rules');
0030 end
0031 [weight1,xcoord1,ycoord1,zcoord1]=gauss_points(dim,order1);
0032 for kk=1:size(weight1,2)
0033 dphi(:,:,kk) = element_d_shape_function(eletype,xcoord1(kk),ycoord1(kk),zcoord1(kk));
0034 end
0035
0036 [weight2,xcoord2,ycoord2,zcoord2]=gauss_points(dim,order2);
0037 for kk=1:size(weight2,2)
0038 phi(:,kk) = element_shape_function(eletype,xcoord2(kk),ycoord2(kk),zcoord2(kk));
0039 end
0040
0041
0042 Agal=zeros(nnodes,nnodes);
0043
0044
0045 for i=nelems:-1:1
0046
0047 eleminodelist=elemstruc(i,:);
0048
0049
0050 thise = nodestruc(eleminodelist,:);
0051
0052
0053 if(nodedim==2); jacobianelem = ...
0054 [thise(2,1)-thise(1,1),thise(2,2)-thise(1,2); ...
0055 thise(3,1)-thise(1,1),thise(3,2)-thise(1,2)];
0056 elseif(nodedim==3); jacobianelem = ...
0057 [thise(2,1)-thise(1,1),thise(2,2)-thise(1,2),thise(2,3)-thise(1,3); ...
0058 thise(3,1)-thise(1,1),thise(3,2)-thise(1,2),thise(3,3)-thise(1,3); ...
0059 thise(4,1)-thise(1,1),thise(4,2)-thise(1,2),thise(4,3)-thise(1,3)];
0060 end
0061
0062
0063
0064 magjacelem=abs(det(jacobianelem));
0065
0066
0067 Ammat=0;
0068 for kk=1:size(weight1,2)
0069 Ammat = Ammat + weight1(kk)* ...
0070 (jacobianelem\dphi(:,:,kk))'* ...
0071 (jacobianelem\dphi(:,:,kk))*magjacelem;
0072 end
0073
0074
0075 Mmmat=0;
0076 for kk=1:size(weight2,2)
0077 Mmmat = Mmmat + weight2(kk)* ...
0078 (phi(:,kk))* ...
0079 (phi(:,kk))' * magjacelem;
0080 end
0081
0082
0083 elemstiff(i).elemstiff = Ammat;
0084 elemstiff(i).elemmass = Mmmat;
0085
0086
0087 stiff=Ammat*img.elem_data(i);
0088
0089
0090 Agal(elemstruc(i,:), elemstruc(i,:)) = Agal(elemstruc(i,:), elemstruc(i,:)) + stiff;
0091
0092 end
0093
0094 end