0001 function saveabaqus(node,face,elem,fname,heading)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 if(nargin==2)
0023 fname=face;
0024 face=[];
0025 elem=[];
0026 end
0027
0028 if(nargin==3)
0029 fname=elem;
0030 elem=[];
0031 end
0032
0033 fid=fopen(fname,'wt');
0034 if(fid==-1)
0035 error('You do not have permission to save mesh files.');
0036 end
0037
0038 fprintf(fid,'*HEADING\n');
0039 if(exist('heading','var'))
0040 fprintf(fid,'**%s\n',heading);
0041 end
0042 fprintf(fid,'*PREPRINT,MODEL=NO,HISTORY=NO,ECHO=NO\n');
0043
0044 if(~isempty(node))
0045 node=[(1:size(node,1))' node(:,1:3)];
0046 fprintf(fid,'*NODE, NSET=MeshNode\n');
0047 fprintf(fid,'%d,\t%e,\t%e,\t%e\n',node');
0048 end
0049
0050 if(~isempty(elem))
0051 if(size(elem,2)==4)
0052 elem(:,5)=0;
0053 labels=0;
0054 elseif(size(elem,2)<4)
0055 error('elem must have at least 4 columns');
0056 else
0057 labels=unique(elem(:,5));
0058 end
0059 len=length(labels);
0060 count=0;
0061 elsetall='';
0062 for i=1:len
0063 idx=find(elem(:,5)==labels(i));
0064 fprintf(fid,'*ELEMENT, ELSET=MeshTetra%d, TYPE=C3D4\n',labels(i));
0065 fprintf(fid,'%d,\t%d,\t%d,\t%d,\t%d\n',[count+(1:length(idx))' elem(idx,1:4)]');
0066 count=count+length(idx);
0067 if(length(elsetall)==0)
0068 elsetall=['MeshTetra' num2str(labels(i))];
0069 else
0070 elsetall=sprintf('%s,MeshTetra%d',elsetall,labels(i));
0071 end
0072 end
0073 if(length(elsetall))
0074 fprintf(fid,'*ELSET, ELSET=MeshTetraAll\n%s\n',elsetall);
0075 end
0076 end
0077
0078 if(~isempty(face))
0079 if(size(face,2)==3)
0080 face(:,4)=0;
0081 labels=0;
0082 elseif(size(face,2)<3)
0083 error('face must have at least 3 columns');
0084 else
0085 labels=unique(face(:,4));
0086 end
0087 len=length(labels);
0088 if(exist('count','var')==0)
0089 count=0;
0090 end
0091 elsetall='';
0092 for i=1:len
0093 idx=find(face(:,4)==labels(i));
0094 fprintf(fid,'*ELEMENT, ELSET=MeshTri%d, TYPE=S3R\n',labels(i));
0095 fprintf(fid,'%d,\t%d,\t%d,\t%d\n',[count+(1:length(idx))' face(idx,1:3)]');
0096 count=count+length(idx);
0097 if(length(elsetall)==0)
0098 elsetall=['MeshTetra' num2str(labels(i))];
0099 else
0100 elsetall=sprintf('%s,MeshTri%d',elsetall,labels(i));
0101 end
0102 end
0103 if(length(elsetall))
0104 fprintf(fid,'*ELSET, ELSET=MeshTriAll\n%s\n',elsetall);
0105 end
0106 end
0107
0108 fclose(fid);