Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writefluent.cpp
3206 views
//1// Write Fluent file2// Johannes Gerstmayr, University Linz3//45#include <mystdlib.h>67#include <myadt.hpp>8#include <linalg.hpp>9#include <csg.hpp>10#include <meshing.hpp>1112namespace netgen13{1415#include "writeuser.hpp"16171819void WriteFluentFormat (const Mesh & mesh,20const string & filename)2122{23cout << "start writing fluent export" << endl;2425int np = mesh.GetNP();26int ne = mesh.GetNE();27int nse = mesh.GetNSE();28int i, j;2930ofstream outfile (filename.c_str());31char str[100];3233outfile.precision(6);34//outfile.setf (ios::fixed, ios::floatfield);35//outfile.setf (ios::showpoint);3637outfile << "(0 \"Exported file from NETGEN \")" << endl;38outfile << "(0 \"Dimension:\")" << endl;39outfile << "(2 3)" << endl << endl;4041outfile << "(0 \"Nodes:\")" << endl;4243//number of nodes:44sprintf(str,"(10 (0 1 %x 1))",np); //hexadecimal!!!45outfile << str << endl;4647//nodes of zone 1:48sprintf(str,"(10 (7 1 %x 1)(",np); //hexadecimal!!!49outfile << str << endl;50for (i = 1; i <= np; i++)51{52const Point3d & p = mesh.Point(i);5354//outfile.width(10);55outfile << p.X() << " ";56outfile << p.Y() << " ";57outfile << p.Z() << "\n";58}59outfile << "))" << endl << endl;6061//write faces with elements6263outfile << "(0 \"Faces:\")" << endl;6465Element2d face, face2;66int i2, j2;67ARRAY<INDEX_3> surfaceelp;68ARRAY<int> surfaceeli;69ARRAY<int> locels;7071//no cells=no tets72//no faces=2*tets7374int noverbface = 2*ne-nse/2;7576sprintf(str,"(13 (0 1 %x 0))",(noverbface+nse)); //hexadecimal!!!77outfile << str << endl;7879sprintf(str,"(13 (4 1 %x 2 3)(",noverbface); //hexadecimal!!!80outfile << str << endl;8182const_cast<Mesh&> (mesh).BuildElementSearchTree();8384for (i = 1; i <= ne; i++)85{86if (ne > 2000)87{88if (i%2000 == 0)89{90cout << (double)i/(double)ne*100. << "%" << endl;91}92}9394Element el = mesh.VolumeElement(i);95//if (inverttets)96// el.Invert();9798//outfile << el.GetIndex() << " ";99if (el.GetNP() != 4) {cout << "only tet-meshes supported in write fluent!" << endl;}100101//faces:102103Box3d box;104el.GetBox(mesh.Points(), box);105box.IncreaseRel(1e-6);106107mesh.GetIntersectingVolEls(box.PMin(),box.PMax(),locels);108int nel = locels.Size();109int locind;110111//cout << "nel=" << nel << endl;112113for (j = 1; j <= el.GetNFaces(); j++)114{115el.GetFace(j, face);116face.Invert();117int eli2 = 0;118int stopsig = 0;119120for (i2 = 1; i2 <= nel; i2++)121{122locind = locels.Get(i2);123//cout << " locind=" << locind << endl;124125Element el2 = mesh.VolumeElement(locind);126//if (inverttets)127// el2.Invert();128129for (j2 = 1; j2 <= el2.GetNFaces(); j2++)130{131el2.GetFace(j2, face2);132133if (face2.HasFace(face)) {eli2 = locind; stopsig = 1; break;}134}135if (stopsig) break;136}137138if (eli2==i) cout << "error in WRITE_FLUENT!!!" << endl;139140if (eli2 > i) //don't write faces two times!141{142//i: left cell, eli: right cell143outfile << hex << face.PNum(2) << " "144<< hex << face.PNum(1) << " "145<< hex << face.PNum(3) << " "146<< hex << i << " "147<< hex << eli2 << "\n";148}149if (eli2 == 0)150{151surfaceelp.Append(INDEX_3(face.PNum(2),face.PNum(1),face.PNum(3)));152surfaceeli.Append(i);153}154}155}156outfile << "))" << endl;157158sprintf(str,"(13 (2 %x %x 3 3)(",(noverbface+1),noverbface+nse); //hexadecimal!!!159outfile << str << endl;160161for (i = 1; i <= surfaceelp.Size(); i++)162{163outfile << hex << surfaceelp.Get(i).I1() << " "164<< hex << surfaceelp.Get(i).I2() << " "165<< hex << surfaceelp.Get(i).I3() << " "166<< hex << surfaceeli.Get(i) << " " << 0 << "\n";167}168169outfile << "))" << endl << endl;170171outfile << "(0 \"Cells:\")" << endl;172173sprintf(str,"(12 (0 1 %x 0))",ne); //hexadecimal!!!174outfile << str << endl;175176sprintf(str,"(12 (1 1 %x 1 2))",ne); //hexadecimal!!!177outfile << str << endl << endl;178179180181182outfile << "(0 \"Zones:\")\n"183<< "(45 (1 fluid fluid)())\n"184// << "(45 (2 velocity-inlet velocity_inlet.1)())\n"185// << "(45 (3 pressure-outlet pressure_outlet.2)())\n"186<< "(45 (2 wall wall)())\n"187<< "(45 (4 interior default-interior)())\n" << endl;188189cout << "done" << endl;190}191192}193194195