Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writeelmer.cpp
3206 views
1//2// Write Elmer file3//4//56#include <mystdlib.h>78#include <myadt.hpp>9#include <linalg.hpp>10#include <csg.hpp>11#include <meshing.hpp>12#include <sys/stat.h>131415namespace netgen16{17#include "writeuser.hpp"18192021void WriteElmerFormat (const Mesh &mesh,22const string &filename)23{24cout << "write elmer mesh files" << endl;25int np = mesh.GetNP();26int ne = mesh.GetNE();27int nse = mesh.GetNSE();28int i, j;29char str[200];3031int inverttets = mparam.inverttets;32int invertsurf = mparam.inverttrigs;3334#ifdef WIN3235char a[256];36sprintf( a, "mkdir %s", filename.c_str() );37system( a );38#else39int rc = mkdir(filename.c_str(), S_IRWXU|S_IRWXG);40#endif4142sprintf( str, "%s/mesh.header", filename.c_str() );43ofstream outfile_h(str);44sprintf( str, "%s/mesh.nodes", filename.c_str() );45ofstream outfile_n(str);46sprintf( str, "%s/mesh.elements", filename.c_str() );47ofstream outfile_e(str);48sprintf( str, "%s/mesh.boundary", filename.c_str() );49ofstream outfile_b(str);5051// fill hashtable5253INDEX_3_HASHTABLE<int> face2volelement(ne);5455for (i = 1; i <= ne; i++)56{57const Element & el = mesh.VolumeElement(i);58INDEX_3 i3;59int k, l;60for (j = 1; j <= 4; j++) // loop over faces of tet61{62l = 0;63for (k = 1; k <= 4; k++)64if (k != j)65{66l++;67i3.I(l) = el.PNum(k);68}69i3.Sort();70face2volelement.Set (i3, i);71}72}7374// outfile.precision(6);75// outfile.setf (ios::fixed, ios::floatfield);76// outfile.setf (ios::showpoint);7778outfile_h << np << " " << ne << " " << nse << "\n";79outfile_h << "2" << "\n";80outfile_h << "303 " << nse << "\n";81outfile_h << "504 " << ne << "\n";8283for (i = 1; i <= np; i++)84{85const Point3d & p = mesh.Point(i);8687outfile_n << i << " -1 ";88outfile_n << p.X() << " ";89outfile_n << p.Y() << " ";90outfile_n << p.Z() << "\n";91}9293for (i = 1; i <= ne; i++)94{95Element el = mesh.VolumeElement(i);96if (inverttets) el.Invert();97sprintf( str, "5%02d", (int)el.GetNP() );98outfile_e << i << " " << el.GetIndex() << " " << str << " ";99for (j = 1; j <= el.GetNP(); j++)100{101outfile_e << " ";102outfile_e << el.PNum(j);103}104outfile_e << "\n";105}106107for (i = 1; i <= nse; i++)108{109Element2d el = mesh.SurfaceElement(i);110if (invertsurf) el.Invert();111sprintf( str, "3%02d", (int)el.GetNP() );112{113INDEX_3 i3;114for (j = 1; j <= 3; j++) i3.I(j) = el.PNum(j);115i3.Sort();116117int elind = face2volelement.Get(i3);118outfile_b << i << " " << mesh.GetFaceDescriptor(el.GetIndex()).BCProperty() <<119" " << elind << " 0 " << str << " ";120}121for (j = 1; j <= el.GetNP(); j++)122{123outfile_b << " ";124outfile_b << el.PNum(j);125}126outfile_b << "\n";127}128}129130}131132133