Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writetochnog.cpp
3206 views
1
//
2
// Write Tochnog file
3
//
4
// by
5
//
6
// Andreas Seltmann
7
// email: [email protected]
8
//
9
#include <mystdlib.h>
10
11
#include <myadt.hpp>
12
#include <linalg.hpp>
13
#include <csg.hpp>
14
#include <meshing.hpp>
15
16
17
namespace netgen
18
{
19
#include "writeuser.hpp"
20
21
22
void WriteTochnogFormat (const Mesh & mesh,
23
const string & filename)
24
{
25
cout << "\nWrite Tochnog Volume Mesh" << endl;
26
27
ofstream outfile (filename.c_str());
28
29
outfile << "(Nodes and Elements generated with NETGEN" << endl;
30
outfile << " " << filename << ")" << endl;
31
32
outfile.precision(8);
33
34
outfile << "(Nodes)" << endl;
35
36
int np = mesh.GetNP();
37
int ne = mesh.GetNE();
38
int i, j;
39
40
for (i = 1; i <= np; i++)
41
{
42
outfile << "node " << " " << i << " ";
43
outfile << mesh.Point(i)(0) << " ";
44
outfile << mesh.Point(i)(1) << " ";
45
outfile << mesh.Point(i)(2) << "\n";
46
}
47
48
int elemcnt = 0; //element counter
49
int finished = 0;
50
int indcnt = 1; //index counter
51
52
while (!finished)
53
{
54
int actcnt = 0;
55
const Element & el1 = mesh.VolumeElement(1);
56
int non = el1.GetNP();
57
if (non == 4)
58
{
59
outfile << "(Elements, type=-tet4)" << endl;
60
}
61
else
62
{
63
cout << "unsupported Element type!!!" << endl;
64
}
65
66
for (i = 1; i <= ne; i++)
67
{
68
const Element & el = mesh.VolumeElement(i);
69
70
if (el.GetIndex() == indcnt)
71
{
72
actcnt++;
73
if (el.GetNP() != non)
74
{
75
cout << "different element-types in a subdomain are not possible!!!" << endl;
76
continue;
77
}
78
79
elemcnt++;
80
outfile << "element " << elemcnt << " -tet4 ";
81
if (non == 4)
82
{
83
outfile << el.PNum(1) << " ";
84
outfile << el.PNum(2) << " ";
85
outfile << el.PNum(4) << " ";
86
outfile << el.PNum(3) << "\n";
87
}
88
else
89
{
90
cout << "unsupported Element type!!!" << endl;
91
for (j = 1; j <= el.GetNP(); j++)
92
{
93
outfile << el.PNum(j);
94
if (j != el.GetNP()) outfile << ", ";
95
}
96
outfile << "\n";
97
}
98
}
99
}
100
indcnt++;
101
if (elemcnt == ne) {finished = 1; cout << "all elements found by Index!" << endl;}
102
if (actcnt == 0) {finished = 1;}
103
}
104
105
cout << "done" << endl;
106
}
107
108
}
109
110