Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writeelmer.cpp
3206 views
1
2
//
3
// Write Elmer file
4
//
5
//
6
7
#include <mystdlib.h>
8
9
#include <myadt.hpp>
10
#include <linalg.hpp>
11
#include <csg.hpp>
12
#include <meshing.hpp>
13
#include <sys/stat.h>
14
15
16
namespace netgen
17
{
18
#include "writeuser.hpp"
19
20
21
22
void WriteElmerFormat (const Mesh &mesh,
23
const string &filename)
24
{
25
cout << "write elmer mesh files" << endl;
26
int np = mesh.GetNP();
27
int ne = mesh.GetNE();
28
int nse = mesh.GetNSE();
29
int i, j;
30
char str[200];
31
32
int inverttets = mparam.inverttets;
33
int invertsurf = mparam.inverttrigs;
34
35
#ifdef WIN32
36
char a[256];
37
sprintf( a, "mkdir %s", filename.c_str() );
38
system( a );
39
#else
40
int rc = mkdir(filename.c_str(), S_IRWXU|S_IRWXG);
41
#endif
42
43
sprintf( str, "%s/mesh.header", filename.c_str() );
44
ofstream outfile_h(str);
45
sprintf( str, "%s/mesh.nodes", filename.c_str() );
46
ofstream outfile_n(str);
47
sprintf( str, "%s/mesh.elements", filename.c_str() );
48
ofstream outfile_e(str);
49
sprintf( str, "%s/mesh.boundary", filename.c_str() );
50
ofstream outfile_b(str);
51
52
// fill hashtable
53
54
INDEX_3_HASHTABLE<int> face2volelement(ne);
55
56
for (i = 1; i <= ne; i++)
57
{
58
const Element & el = mesh.VolumeElement(i);
59
INDEX_3 i3;
60
int k, l;
61
for (j = 1; j <= 4; j++) // loop over faces of tet
62
{
63
l = 0;
64
for (k = 1; k <= 4; k++)
65
if (k != j)
66
{
67
l++;
68
i3.I(l) = el.PNum(k);
69
}
70
i3.Sort();
71
face2volelement.Set (i3, i);
72
}
73
}
74
75
// outfile.precision(6);
76
// outfile.setf (ios::fixed, ios::floatfield);
77
// outfile.setf (ios::showpoint);
78
79
outfile_h << np << " " << ne << " " << nse << "\n";
80
outfile_h << "2" << "\n";
81
outfile_h << "303 " << nse << "\n";
82
outfile_h << "504 " << ne << "\n";
83
84
for (i = 1; i <= np; i++)
85
{
86
const Point3d & p = mesh.Point(i);
87
88
outfile_n << i << " -1 ";
89
outfile_n << p.X() << " ";
90
outfile_n << p.Y() << " ";
91
outfile_n << p.Z() << "\n";
92
}
93
94
for (i = 1; i <= ne; i++)
95
{
96
Element el = mesh.VolumeElement(i);
97
if (inverttets) el.Invert();
98
sprintf( str, "5%02d", (int)el.GetNP() );
99
outfile_e << i << " " << el.GetIndex() << " " << str << " ";
100
for (j = 1; j <= el.GetNP(); j++)
101
{
102
outfile_e << " ";
103
outfile_e << el.PNum(j);
104
}
105
outfile_e << "\n";
106
}
107
108
for (i = 1; i <= nse; i++)
109
{
110
Element2d el = mesh.SurfaceElement(i);
111
if (invertsurf) el.Invert();
112
sprintf( str, "3%02d", (int)el.GetNP() );
113
{
114
INDEX_3 i3;
115
for (j = 1; j <= 3; j++) i3.I(j) = el.PNum(j);
116
i3.Sort();
117
118
int elind = face2volelement.Get(i3);
119
outfile_b << i << " " << mesh.GetFaceDescriptor(el.GetIndex()).BCProperty() <<
120
" " << elind << " 0 " << str << " ";
121
}
122
for (j = 1; j <= el.GetNP(); j++)
123
{
124
outfile_b << " ";
125
outfile_b << el.PNum(j);
126
}
127
outfile_b << "\n";
128
}
129
}
130
131
}
132
133