Changeset 1342
- Timestamp:
- 07/17/09 09:01:18 (16 years ago)
- Location:
- issm/trunk/src/m/utils/Mesh
- Files:
-
- 2 added
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/src/m/utils/Mesh/MeshQuality.m
r1341 r1342 1 function meshquality(md);1 function MeshQuality(md,epsilon,hmin,hmax); 2 2 %MESHQUALITY - compute mesh quality 3 3 % 4 4 % Usage: 5 % meshquality(md);5 % MeshQuality(md,epsilon,hmin,hmax); 6 6 7 t1=clock; fprintf('%s',' computing Hessian...'); 8 %initialization 9 field=md.vel_obs; 7 %Get some variables from the model 8 index=md.elements; 10 9 x=md.x; 11 10 y=md.y; 12 index=md.elements;13 numberofgrids=md.numberofgrids;14 numberofelements=md.numberofelements;15 gradx=zeros(numberofgrids,1);16 grady=zeros(numberofgrids,1);17 metric=zeros(numberofelements,3);18 11 19 12 %2d geometric parameter (do not change) 20 13 scale=2/9; 21 hmin=500;22 hmax=10^6;23 epsilon=5;24 14 25 %build some usefull variables 26 line=index(:); 27 linesize=3*numberofelements; 15 %Compute Hessian 16 hessian=ComputeHessian(index,x,y,md.vel_obs,'node'); 28 17 29 %get areas and nodal functions coefficients N(x,y)=alpha x + beta y + gamma 30 [alpha beta]=GetNodalFunctionsCoeff(index,md.x,md.y); 31 areas=GetAreas(index,md.x,md.y); 32 33 %Compute gradient for each element 34 grad_elx=sum(field(index).*alpha,2); 35 grad_ely=sum(field(index).*beta,2); 36 37 %update weights that holds the volume of all the element holding the grid i 38 weights=sparse(line,ones(linesize,1),repmat(areas,3,1),numberofgrids,1); 39 40 %Compute gradient for each grid (average of the elements around) 41 gradx=sparse(line,ones(linesize,1),repmat(areas.*grad_elx,3,1),numberofgrids,1); 42 grady=sparse(line,ones(linesize,1),repmat(areas.*grad_ely,3,1),numberofgrids,1); 43 gradx=gradx./weights; 44 grady=grady./weights; 45 46 %Compute hessian for each element 47 hessian_elem=[sum(gradx(index).*alpha,2) sum(grady(index).*alpha,2) sum(grady(index).*beta,2)]; 48 49 %Compute Hessian on the nodes (average of the elements around) 50 hessian=[sparse(line,ones(linesize,1),repmat(areas.*hessian_elem(:,1),3,1),numberofgrids,1)./weights ... 51 sparse(line,ones(linesize,1),repmat(areas.*hessian_elem(:,2),3,1),numberofgrids,1)./weights ... 52 sparse(line,ones(linesize,1),repmat(areas.*hessian_elem(:,3),3,1),numberofgrids,1)./weights ]; 53 t2=clock;fprintf('%s\n',[' done (' num2str(etime(t2,t1)) ' seconds)']); 54 55 t1=clock; fprintf('%s',' computing metric...'); 56 %first, find the eigen values of eah line of H=[hessian(i,1) hessian(i,2); hessian(i,2) hessian(i,3)] 57 a=hessian(:,1); b=hessian(:,2); d=hessian(:,3); 58 lambda1=0.5*((a+d)+sqrt(4*b.^2+(a-d).^2)); 59 lambda2=0.5*((a+d)-sqrt(4*b.^2+(a-d).^2)); 60 pos1=find(lambda1==0); 61 pos2=find(lambda2==0); 62 63 %Modify the eigen values to control the shape of the elements 64 lambda1=min(max(abs(lambda1)*scale/epsilon,1/hmax^2),1/hmin^2); 65 lambda2=min(max(abs(lambda2)*scale/epsilon,1/hmax^2),1/hmin^2); 66 67 %compute eigen vectors 68 norm1=sqrt(8*b.^2+2*(d-a).^2+2*(d-a).*sqrt((a-d).^2+4*b.^2)); 69 v1x=2*b./norm1; 70 v1y=((d-a)+sqrt((a-d).^2+4*b.^2))./norm1; 71 norm2=sqrt(8*b.^2+2*(d-a).^2-2*(d-a).*sqrt((a-d).^2+4*b.^2)); 72 v2x=2*b./norm2; 73 v2y=((d-a)-sqrt((a-d).^2+4*b.^2))./norm2; 74 75 %Compute new metric (for each node M=V*Lambda*V^-1) 76 metric=full([(v1x.*v2y-v1y.*v2x).^(-1).*(lambda1.*v2y.*v1x-lambda2.*v1y.*v2x) ... 77 (v1x.*v2y-v1y.*v2x).^(-1).*(lambda1.*v1y.*v2y-lambda2.*v1y.*v2y) ... 78 (v1x.*v2y-v1y.*v2x).^(-1).*(-lambda1.*v2x.*v1y+lambda2.*v1x.*v2y)]); 79 80 %some corrections for 0 eigen values 81 metric(pos1,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos1),1); 82 metric(pos2,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos2),1); 83 if length(md.gridonwater)==numberofgrids; 18 %Compute metric 19 if length(md.gridonwater)==md.numberofgrids, 84 20 pos=find(md.gridonwater); 85 metric(pos,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos),1); 21 else 22 pos=[]; 86 23 end 87 88 %take care of water elements 89 if length(md.gridonwater)==numberofgrids; 90 pos=find(md.gridonwater); 91 metric(pos,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos),1); 92 end 93 94 if any(isnan(metric)), 95 error('YamsCall error message: NaN in the metric...') 96 end 97 t2=clock;fprintf('%s\n',[' done (' num2str(etime(t2,t1)) ' seconds)']); 24 metric=ComputeMetric(hessian,scale,epsilon,hmin,hmax,pos); 98 25 99 26 %Get Areas … … 122 49 123 50 %compute quality: 124 Q=4*sqrt(3)*V./(L1+L2+L3); 125 126 %display 127 X=0:0.1:4; 128 hist(Q,X); 129 xlim([0 3]); 130 title('mesh quality distribution'); 51 quality=4*sqrt(3)*V./(L1+L2+L3); 131 52 132 53 %compute error 133 %{134 %a=hessian_elem(:,1); b=hessian_elem(:,2); d=hessian_elem(:,3);135 54 a=hessian(:,1); b=hessian(:,2); d=hessian(:,3); 136 55 a=a(index)*[1;1;1]/3; … … 141 60 lambda1=min(max(abs(lambda1)*scale/epsilon,1/hmax^2),1/hmin^2); 142 61 lambda2=min(max(abs(lambda2)*scale/epsilon,1/hmax^2),1/hmin^2); 143 if length(md. elementonwater)==numberofelements;62 if length(md.gridonwater)==md.numberofgrids; 144 63 pos=find(md.gridonwater); 145 lambda1(pos)=0;146 lambda2(pos)=0;147 end148 %}149 if length(md.gridonwater)==numberofgrids;150 64 lambda1(pos)=0; 151 65 lambda2(pos)=0; … … 159 73 160 74 %display 161 plotmodel(md,'data',epsilon,'title','Interpolation error','figure',2,'log',10) 162 163 disp(['Average interpolation error = ' num2str(mean(epsilon)) ' m/yr']); 164 disp(['Maximum interpolation error = ' num2str(max(epsilon)) ' m/yr']); 75 X=0:0.1:4; hist(quality,X); xlim([0 3]); title('mesh quality distribution','FontSize',14); 76 plotmodel(md,'data',epsilon,'title','Interpolation error','figure',2) 77 disp(sprintf('\n%s','Mesh Quality')); 78 disp(sprintf(' %s %g','Average Mesh quality:',mean(quality))); 79 disp(sprintf(' %s %g','Maximum interpolation error:',max(quality))); 80 disp(sprintf('\n%s','Interpolation Error')); 81 disp(sprintf(' %s %g %s','Average interpolation error:',mean(epsilon),'m/yr')); 82 disp(sprintf(' %s %g %s','Maximum interpolation error:',max(epsilon),'m/yr')); -
issm/trunk/src/m/utils/Mesh/YamsCall.m
r1336 r1342 19 19 global ISSM_DIR 20 20 21 t1=clock; fprintf('%s',' computing Hessian...');22 %initialization23 index=md.elements;24 numberofgrids=md.numberofgrids;25 numberofelements=md.numberofelements;26 gradx=zeros(numberofgrids,1);27 grady=zeros(numberofgrids,1);28 metric=zeros(numberofelements,3);29 30 21 %2d geometric parameter (do not change) 31 22 scale=2/9; 32 23 33 %build some usefull variables 34 line=index(:); 35 summation=1/3*ones(3,1); 36 linesize=3*numberofelements; 37 38 %get areas and nodal functions coefficients N(x,y)=alpha x + beta y + gamma 39 [alpha beta]=GetNodalFunctionsCoeff(index,md.x,md.y); 40 areas=GetAreas(index,md.x,md.y); 41 42 %Compute gradient for each element 43 grad_elx=sum(field(index).*alpha,2); 44 grad_ely=sum(field(index).*beta,2); 45 46 %update weights that holds the volume of all the element holding the grid i 47 weights=sparse(line,ones(linesize,1),repmat(areas,3,1),numberofgrids,1); 48 49 %Compute gradient for each grid (average of the elements around) 50 gradx=sparse(line,ones(linesize,1),repmat(areas.*grad_elx,3,1),numberofgrids,1); 51 grady=sparse(line,ones(linesize,1),repmat(areas.*grad_ely,3,1),numberofgrids,1); 52 gradx=gradx./weights; 53 grady=grady./weights; 54 55 %Compute hessian for each element 56 hessian=[sum(gradx(index).*alpha,2) sum(grady(index).*alpha,2) sum(grady(index).*beta,2)]; 57 58 %Compute Hessian on the nodes (average of the elements around) 59 hessian=[sparse(line,ones(linesize,1),repmat(areas.*hessian(:,1),3,1),numberofgrids,1)./weights ... 60 sparse(line,ones(linesize,1),repmat(areas.*hessian(:,2),3,1),numberofgrids,1)./weights ... 61 sparse(line,ones(linesize,1),repmat(areas.*hessian(:,3),3,1),numberofgrids,1)./weights ]; 24 %Compute Hessian 25 t1=clock; fprintf('%s',' computing Hessian...'); 26 hessian=ComputeHessian(md.elements,md.x,md.y,field,'node'); 62 27 t2=clock;fprintf('%s\n',[' done (' num2str(etime(t2,t1)) ' seconds)']); 63 28 29 %Compute metric 64 30 t1=clock; fprintf('%s',' computing metric...'); 65 %first, find the eigen values of eah line of H=[hessian(i,1) hessian(i,2); hessian(i,2) hessian(i,3)] 66 a=hessian(:,1); b=hessian(:,2); d=hessian(:,3); 67 lambda1=0.5*((a+d)+sqrt(4*b.^2+(a-d).^2)); 68 lambda2=0.5*((a+d)-sqrt(4*b.^2+(a-d).^2)); 69 pos1=find(lambda1==0); 70 pos2=find(lambda2==0); 71 72 %Modify the eigen values to control the shape of the elements 73 lambda1=min(max(abs(lambda1)*scale/epsilon,1/hmax^2),1/hmin^2); 74 lambda2=min(max(abs(lambda2)*scale/epsilon,1/hmax^2),1/hmin^2); 75 76 %compute eigen vectors 77 norm1=sqrt(8*b.^2+2*(d-a).^2+2*(d-a).*sqrt((a-d).^2+4*b.^2)); 78 v1x=2*b./norm1; 79 v1y=((d-a)+sqrt((a-d).^2+4*b.^2))./norm1; 80 norm2=sqrt(8*b.^2+2*(d-a).^2-2*(d-a).*sqrt((a-d).^2+4*b.^2)); 81 v2x=2*b./norm2; 82 v2y=((d-a)-sqrt((a-d).^2+4*b.^2))./norm2; 83 84 %Compute new metric (for each node M=V*Lambda*V^-1) 85 metric=full([(v1x.*v2y-v1y.*v2x).^(-1).*(lambda1.*v2y.*v1x-lambda2.*v1y.*v2x) ... 86 (v1x.*v2y-v1y.*v2x).^(-1).*(lambda1.*v1y.*v2y-lambda2.*v1y.*v2y) ... 87 (v1x.*v2y-v1y.*v2x).^(-1).*(-lambda1.*v2x.*v1y+lambda2.*v1x.*v2y)]); 88 89 %some corrections for 0 eigen values 90 metric(pos1,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos1),1); 91 metric(pos2,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos2),1); 92 93 %take care of water elements 94 if length(md.gridonwater)==numberofgrids; 31 if length(md.gridonwater)==md.numberofgrids, 95 32 pos=find(md.gridonwater); 96 metric(pos,:)=repmat([1/hmax^2 0 1/hmax^2],length(pos),1); 33 else 34 pos=[]; 97 35 end 98 99 if any(isnan(metric)), 100 error('YamsCall error message: NaN in the metric...') 101 end 36 metric=ComputeMetric(hessian,scale,epsilon,hmin,hmax,pos); 102 37 t2=clock;fprintf('%s\n',[' done (' num2str(etime(t2,t1)) ' seconds)']); 103 38 104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Build FILES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 105 39 %write files 106 40 t1=clock; fprintf('%s',' writing initial mesh files...'); 107 41 save -ascii carre0.met metric … … 132 66 t2=clock;fprintf('%s\n',[' done (' num2str(etime(t2,t1)) ' seconds)']); 133 67 134 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% call Yams %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%135 136 68 %call yams 137 69 fprintf('%s\n',' call Yams...'); 138 system(['yams2-linux -O 1 -v 1-ecp -hgrad ' num2str(gradation) ' carre0 carre1']);70 system(['yams2-linux -O 1 -v 2 -ecp -hgrad ' num2str(gradation) ' carre0 carre1']); 139 71 140 72 %plug new mesh
Note:
See TracChangeset
for help on using the changeset viewer.