Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/Application/plugins/tetlib_api.cpp
3203 views
1
/*****************************************************************************
2
* *
3
* Elmer, A Finite Element Software for Multiphysical Problems *
4
* *
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *
6
* *
7
* This program is free software; you can redistribute it and/or *
8
* modify it under the terms of the GNU General Public License *
9
* as published by the Free Software Foundation; either version 2 *
10
* of the License, or (at your option) any later version. *
11
* *
12
* This program is distributed in the hope that it will be useful, *
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15
* GNU General Public License for more details. *
16
* *
17
* You should have received a copy of the GNU General Public License *
18
* along with this program (in file fem/GPL-2); if not, write to the *
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
20
* Boston, MA 02110-1301, USA. *
21
* *
22
*****************************************************************************/
23
24
/*****************************************************************************
25
* *
26
* ELMER/Mesh3D tetlib_api *
27
* *
28
*****************************************************************************
29
* *
30
* Authors: Mikko Lyly, Juha Ruokolainen and Peter Raback *
31
* Email: [email protected] *
32
* Web: http://www.csc.fi/elmer *
33
* Address: CSC - IT Center for Science Ltd. *
34
* Keilaranta 14 *
35
* 02101 Espoo, Finland *
36
* *
37
* Original Date: 15 Mar 2008 *
38
* *
39
*****************************************************************************/
40
#include "tetlib_api.h"
41
#include <iostream>
42
using namespace std;
43
44
TetlibAPI::TetlibAPI()
45
{
46
}
47
48
TetlibAPI::~TetlibAPI()
49
{
50
}
51
52
bool TetlibAPI::loadTetlib()
53
{
54
cout << "Load tetgen plugin... ";
55
56
libtet = new QLibrary("tetplugin");
57
58
if(!libtet->load()) {
59
cout << "not found" << endl;
60
cout << "Tetgen functionality unavailable" << endl;
61
cout.flush();
62
return false;
63
}
64
65
cout << "done" << endl;
66
cout.flush();
67
68
ptetgenio = (tetgenio_t)libtet->resolve("CreateObjectOfTetgenio");
69
70
if(!ptetgenio) {
71
cout << "Unable to resolve 'CreateObjectOfTetgenio'" << endl;
72
cout.flush();
73
return false;
74
}
75
76
in = (ptetgenio)();
77
out = (ptetgenio)();
78
79
delegate_tetrahedralize = (delegate_tetrahedralize_t)libtet->resolve("delegate_tetrahedralize");
80
81
if(!delegate_tetrahedralize) {
82
cout << "Unable to resolve 'delegate_tetrahedralize'" << endl;
83
cout.flush();
84
return false;
85
}
86
87
return true;
88
}
89
90
// Populate Elmer's mesh structure:
91
//-----------------------------------------------------------------------------
92
mesh_t *TetlibAPI::createElmerMeshStructure()
93
{
94
Helpers helpers;
95
Meshutils meshutils;
96
97
// Create new mesh structure:
98
mesh_t *mesh = new mesh_t;
99
100
mesh->setNodes(0);
101
mesh->setPoints(0);
102
mesh->setEdges(0);
103
mesh->setSurfaces(0);
104
mesh->setElements(0);
105
106
// Nodes:
107
mesh->setNodes(out->numberofpoints);
108
mesh->newNodeArray(mesh->getNodes());
109
110
REAL *pointlist = out->pointlist;
111
112
for(int i=0; i < mesh->getNodes(); i++) {
113
node_t *node = mesh->getNode(i);
114
115
node->setX(0, *pointlist++);
116
node->setX(1, *pointlist++);
117
node->setX(2, *pointlist++);
118
119
node->setIndex(-1); // default
120
}
121
122
// Elements:
123
mesh->setElements(out->numberoftetrahedra);
124
mesh->newElementArray(mesh->getElements());
125
126
int *tetrahedronlist = out->tetrahedronlist;
127
REAL *attribute = out->tetrahedronattributelist;
128
int na = out->numberoftetrahedronattributes;
129
130
for(int i=0; i< mesh->getElements(); i++) {
131
element_t *element = mesh->getElement(i);
132
133
element->setNature(PDE_BULK);
134
element->setCode(504);
135
element->setNodes(4);
136
element->newNodeIndexes(4);
137
138
element->setNodeIndex(0, (*tetrahedronlist++) - out->firstnumber);
139
element->setNodeIndex(1, (*tetrahedronlist++) - out->firstnumber);
140
element->setNodeIndex(2, (*tetrahedronlist++) - out->firstnumber);
141
element->setNodeIndex(3, (*tetrahedronlist++) - out->firstnumber);
142
143
element->setIndex(1); // default
144
// must have "A" in control string:
145
if(out->tetrahedronattributelist != (REAL*)NULL)
146
element->setIndex((int)attribute[na*(i+1)-1]);
147
}
148
149
// Boundary elements:
150
mesh->setSurfaces(out->numberoftrifaces);
151
mesh->newSurfaceArray(mesh->getSurfaces());
152
153
int *trifacelist = out->trifacelist;
154
int *face2tetlist = out->face2tetlist;
155
156
for(int i=0; i < mesh->getSurfaces(); i++) {
157
surface_t *surface = mesh->getSurface(i);
158
159
surface->setNature(PDE_BOUNDARY);
160
surface->setCode(303);
161
surface->setNodes(3);
162
surface->newNodeIndexes(3);
163
surface->setEdges(3);
164
surface->newEdgeIndexes(3);
165
166
surface->setElements(2);
167
surface->newElementIndexes(2);
168
169
surface->setIndex(1); // default
170
if(out->trifacemarkerlist != (int*)NULL)
171
surface->setIndex(out->trifacemarkerlist[i]);
172
173
surface->setEdgeIndex(0, -1);
174
surface->setEdgeIndex(1, -1);
175
surface->setEdgeIndex(2, -1);
176
177
surface->setElementIndex(0, -1);
178
surface->setElementIndex(1, -1);
179
180
// must have "nn" in control string:
181
if(out->face2tetlist != (int*)NULL) {
182
surface->setElementIndex(0, (*face2tetlist++) - out->firstnumber);
183
surface->setElementIndex(1, (*face2tetlist++) - out->firstnumber);
184
}
185
186
int u = (*trifacelist++) - out->firstnumber;
187
int v = (*trifacelist++) - out->firstnumber;
188
int w = (*trifacelist++) - out->firstnumber;
189
190
surface->setNodeIndex(0, u);
191
surface->setNodeIndex(1, v);
192
surface->setNodeIndex(2, w);
193
}
194
195
// Edges:
196
meshutils.findSurfaceElementEdges(mesh);
197
meshutils.findSurfaceElementNormals(mesh);
198
199
// Points:
200
mesh->setPoints(0);
201
// mesh->point == NULL;
202
203
mesh->setDim(3);
204
mesh->setCdim(3);
205
206
return mesh;
207
}
208
209