Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/interface/writedolfin.cpp
3206 views
1
//
2
// Write dolfin file
3
//
4
// by
5
// Kent-Andre Mardal <[email protected]>
6
7
8
#include <mystdlib.h>
9
10
#include <myadt.hpp>
11
#include <linalg.hpp>
12
#include <csg.hpp>
13
#include <meshing.hpp>
14
15
namespace netgen
16
{
17
18
#include "writeuser.hpp"
19
20
21
22
void WriteDolfinFormat (const Mesh & mesh, const string & filename)
23
{
24
cout << "start writing dolfin export" << endl;
25
26
int np = mesh.GetNP();
27
int ne = mesh.GetNE();
28
int nse = mesh.GetNSE();
29
int nsd = mesh.GetDimension();
30
int invertsurf = mparam.inverttrigs;
31
int i, j;
32
33
ofstream outfile (filename.c_str());
34
35
char str[100];
36
outfile.precision(8);
37
outfile.setf (ios::fixed, ios::floatfield);
38
outfile.setf (ios::showpoint);
39
40
if ( nsd == 3) {
41
42
outfile << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" <<endl;
43
outfile << ""<<endl;
44
45
outfile << "<dolfin xmlns:dolfin=\"http://www.phi.chalmers.se/dolfin/\">"<<endl;
46
outfile << " <mesh celltype=\"tetrahedron\" dim=\"3\">" <<endl;
47
outfile << " <vertices size=\""<<np<<"\">"<<endl;
48
for (i = 1; i <= np; i++) {
49
const Point3d & p = mesh.Point(i);
50
outfile << " <vertex index=\""<<i-1<<"\" x=\""<<p.X()<<"\" y=\""<<p.Y()<<"\" z=\""<<p.Z()<<"\"/>"<<endl;
51
}
52
outfile << " </vertices>"<<endl;
53
54
55
56
outfile << " <cells size=\""<<ne<<"\">"<<endl;
57
for (i = 1; i <= ne; i++) {
58
const Element & el = mesh.VolumeElement(i);
59
60
outfile << " <tetrahedron index=\""<<i-1<<"\" v0=\""<<el.PNum(1)-1<<"\" v1=\""<<el.PNum(2)-1<<"\" v2=\""<<el.PNum(3)-1<<"\" v3=\""<<el.PNum(4)-1<<"\"/>"<<endl;
61
}
62
outfile << " </cells>"<<endl;
63
}
64
outfile << " </mesh>"<<endl;
65
outfile << "</dolfin>"<<endl;
66
67
cout << "done writing dolfin export" << endl;
68
}
69
}
70
71