Home > vbmeg > external > iso2mesh > savemphtxt.m

savemphtxt

PURPOSE ^

SYNOPSIS ^

function savemphtxt(node, face, elem, filename)

DESCRIPTION ^

 savemphtxt(node, face, elem, filename)

 save tetrahedron mesh to comsol file (.mphtxt)

 author: Donghyeon Kim (danielkim<at> gist.ac.kr)
 date: 2011/09/29

 input:
      node: input, node list, dimension (nn,3)
      face: input, surface face element list with label, dimension (be,4)
      elem: input, tetrahedron element list with label, dimension (ne,5)
      filename: input, output file name

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function savemphtxt(node, face, elem, filename)
0002 %
0003 % savemphtxt(node, face, elem, filename)
0004 %
0005 % save tetrahedron mesh to comsol file (.mphtxt)
0006 %
0007 % author: Donghyeon Kim (danielkim<at> gist.ac.kr)
0008 % date: 2011/09/29
0009 %
0010 % input:
0011 %      node: input, node list, dimension (nn,3)
0012 %      face: input, surface face element list with label, dimension (be,4)
0013 %      elem: input, tetrahedron element list with label, dimension (ne,5)
0014 %      filename: input, output file name
0015 %
0016 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0017 %
0018 
0019 n_node = size(node,1);
0020 n_face = size(face,1);
0021 n_elem = size(elem,1);
0022 
0023 if(min(face(:,4))==0)
0024     face(:,4)=face(:,4)+1;
0025 end
0026 if(min(elem(:,5))==0)
0027     elem(:,5)=elem(:,5)+1;
0028 end
0029 
0030 fp = fopen(filename,'w');
0031 fprintf(fp,'# Created by iso2mesh (http://iso2mesh.sf.net)\n');
0032 fprintf(fp,'0 1\n1\n5 mesh1\n1\n3 obj\n\n');
0033 fprintf(fp,'0 0 1\n4 Mesh\n2\n3\n%d\n1\n',n_node);
0034 
0035 % Write Node information
0036 for i = 1:n_node
0037     fprintf(fp,'%.16f %.16f %.16f\n',node(i,1),node(i,2),node(i,3));
0038 end
0039 fprintf(fp, '\n2\n\n3 tri\n');
0040 
0041 % Write Tri information
0042 fprintf(fp, '\n3\n');
0043 fprintf(fp, '%d\n\n',n_face);
0044 for i = 1:n_face
0045     fprintf(fp,'%d %d %d\n',face(i,1),face(i,2),face(i,3));
0046 end
0047 fprintf(fp, '\n1\n0\n');
0048 fprintf(fp, '%d\n',n_face);
0049 for i = 1:n_face
0050     fprintf(fp,'%d\n',face(i,4));
0051 end
0052 fprintf(fp, '\n%d\n',n_face);
0053 for i = 1:n_face
0054     fprintf(fp,'0 0\n');
0055 end
0056 
0057 % Write Tet information
0058 fprintf(fp, '\n\n3 tet\n4\n\n%d\n', n_elem);
0059 for i = 1:n_elem
0060     fprintf(fp,'%d %d %d %d\n',elem(i,1),elem(i,2),elem(i,3),elem(i,4));
0061 end    
0062 fprintf(fp, '\n4\n0\n%d\n%d\n', n_elem);
0063 for i = 1:n_elem
0064     fprintf(fp,'%d\n',elem(i,5));
0065 end 
0066 fprintf(fp,'\n0\n');
0067 fclose(fp);
0068

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005