1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
//
// Write Fluent file
// Johannes Gerstmayr, University Linz
//
#include <mystdlib.h>
#include <myadt.hpp>
#include <linalg.hpp>
#include <csg.hpp>
#include <meshing.hpp>
#include "writeuser.hpp"
namespace netgen
{
void WriteFluentFormat (const Mesh & mesh,
const filesystem::path & filename)
{
cout << "start writing fluent export" << endl;
int np = mesh.GetNP();
int ne = mesh.GetNE();
int nse = mesh.GetNSE();
int i, j;
ofstream outfile (filename);
char str[100];
outfile.precision(6);
//outfile.setf (ios::fixed, ios::floatfield);
//outfile.setf (ios::showpoint);
outfile << "(0 \"Exported file from NETGEN \")" << endl;
outfile << "(0 \"Dimension:\")" << endl;
outfile << "(2 3)" << endl << endl;
outfile << "(0 \"Nodes:\")" << endl;
//number of nodes:
snprintf (str, size(str), "(10 (0 1 %x 1))",np); //hexadecimal!!!
outfile << str << endl;
//nodes of zone 1:
snprintf (str, size(str), "(10 (7 1 %x 1)(",np); //hexadecimal!!!
outfile << str << endl;
for (i = 1; i <= np; i++)
{
const Point3d & p = mesh.Point(i);
//outfile.width(10);
outfile << p.X() << " ";
outfile << p.Y() << " ";
outfile << p.Z() << "\n";
}
outfile << "))" << endl << endl;
//write faces with elements
outfile << "(0 \"Faces:\")" << endl;
Element2d face, face2;
int /* i2, */ j2;
NgArray<INDEX_3> surfaceelp;
NgArray<int> surfaceeli;
Array<ElementIndex> locels;
//no cells=no tets
//no faces=2*tets
int noverbface = 2*ne-nse/2;
snprintf (str, size(str), "(13 (0 1 %x 0))",(noverbface+nse)); //hexadecimal!!!
outfile << str << endl;
snprintf (str, size(str), "(13 (4 1 %x 2 3)(",noverbface); //hexadecimal!!!
outfile << str << endl;
const_cast<Mesh&> (mesh).BuildElementSearchTree(3);
for (i = 1; i <= ne; i++)
{
if (ne > 2000)
{
if (i%2000 == 0)
{
cout << (double)i/(double)ne*100. << "%" << endl;
}
}
Element el = mesh.VolumeElement(i);
//if (inverttets)
// el.Invert();
//outfile << el.GetIndex() << " ";
if (el.GetNP() != 4) {cout << "only tet-meshes supported in write fluent!" << endl;}
//faces:
Box3d box;
el.GetBox(mesh.Points(), box);
box.IncreaseRel(1e-6);
mesh.GetIntersectingVolEls(box.PMin(),box.PMax(),locels);
// int nel = locels.Size();
// int locind;
//cout << "nel=" << nel << endl;
for (j = 1; j <= el.GetNFaces(); j++)
{
el.GetFace(j, face);
face.Invert();
int eli2 = 0;
int stopsig = 0;
for (auto locind : locels)
{
Element el2 = mesh[locind];
//if (inverttets)
// el2.Invert();
for (j2 = 1; j2 <= el2.GetNFaces(); j2++)
{
el2.GetFace(j2, face2);
if (face2.HasFace(face)) {eli2 = locind+1; stopsig = 1; break;}
}
if (stopsig) break;
}
if (eli2==i) cout << "error in WRITE_FLUENT!!!" << endl;
if (eli2 > i) //don't write faces two times!
{
//i: left cell, eli: right cell
outfile << hex << face.PNum(2) << " "
<< hex << face.PNum(1) << " "
<< hex << face.PNum(3) << " "
<< hex << i << " "
<< hex << eli2 << "\n";
}
if (eli2 == 0)
{
surfaceelp.Append(INDEX_3(face.PNum(2),face.PNum(1),face.PNum(3)));
surfaceeli.Append(i);
}
}
}
outfile << "))" << endl;
snprintf (str, size(str), "(13 (2 %x %x 3 3)(",(noverbface+1),noverbface+nse); //hexadecimal!!!
outfile << str << endl;
for (i = 1; i <= surfaceelp.Size(); i++)
{
outfile << hex << surfaceelp.Get(i).I1() << " "
<< hex << surfaceelp.Get(i).I2() << " "
<< hex << surfaceelp.Get(i).I3() << " "
<< hex << surfaceeli.Get(i) << " " << 0 << "\n";
}
outfile << "))" << endl << endl;
outfile << "(0 \"Cells:\")" << endl;
snprintf (str, size(str), "(12 (0 1 %x 0))",ne); //hexadecimal!!!
outfile << str << endl;
snprintf (str, size(str), "(12 (1 1 %x 1 2))",ne); //hexadecimal!!!
outfile << str << endl << endl;
outfile << "(0 \"Zones:\")\n"
<< "(45 (1 fluid fluid)())\n"
// << "(45 (2 velocity-inlet velocity_inlet.1)())\n"
// << "(45 (3 pressure-outlet pressure_outlet.2)())\n"
<< "(45 (2 wall wall)())\n"
<< "(45 (4 interior default-interior)())\n" << endl;
cout << "done" << endl;
}
static RegisterUserFormat reg_fluent ("Fluent Format", {".mesh"}, nullopt, WriteFluentFormat);
}
|