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