Path: blob/devel/ElmerGUI/Application/plugins/tetlib_api.cpp
3203 views
/*****************************************************************************1* *2* Elmer, A Finite Element Software for Multiphysical Problems *3* *4* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland *5* *6* This program is free software; you can redistribute it and/or *7* modify it under the terms of the GNU General Public License *8* as published by the Free Software Foundation; either version 2 *9* of the License, or (at your option) any later version. *10* *11* This program is distributed in the hope that it will be useful, *12* but WITHOUT ANY WARRANTY; without even the implied warranty of *13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *14* GNU General Public License for more details. *15* *16* You should have received a copy of the GNU General Public License *17* along with this program (in file fem/GPL-2); if not, write to the *18* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *19* Boston, MA 02110-1301, USA. *20* *21*****************************************************************************/2223/*****************************************************************************24* *25* ELMER/Mesh3D tetlib_api *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter Raback *30* Email: [email protected] *31* Web: http://www.csc.fi/elmer *32* Address: CSC - IT Center for Science Ltd. *33* Keilaranta 14 *34* 02101 Espoo, Finland *35* *36* Original Date: 15 Mar 2008 *37* *38*****************************************************************************/39#include "tetlib_api.h"40#include <iostream>41using namespace std;4243TetlibAPI::TetlibAPI()44{45}4647TetlibAPI::~TetlibAPI()48{49}5051bool TetlibAPI::loadTetlib()52{53cout << "Load tetgen plugin... ";5455libtet = new QLibrary("tetplugin");5657if(!libtet->load()) {58cout << "not found" << endl;59cout << "Tetgen functionality unavailable" << endl;60cout.flush();61return false;62}6364cout << "done" << endl;65cout.flush();6667ptetgenio = (tetgenio_t)libtet->resolve("CreateObjectOfTetgenio");6869if(!ptetgenio) {70cout << "Unable to resolve 'CreateObjectOfTetgenio'" << endl;71cout.flush();72return false;73}7475in = (ptetgenio)();76out = (ptetgenio)();7778delegate_tetrahedralize = (delegate_tetrahedralize_t)libtet->resolve("delegate_tetrahedralize");7980if(!delegate_tetrahedralize) {81cout << "Unable to resolve 'delegate_tetrahedralize'" << endl;82cout.flush();83return false;84}8586return true;87}8889// Populate Elmer's mesh structure:90//-----------------------------------------------------------------------------91mesh_t *TetlibAPI::createElmerMeshStructure()92{93Helpers helpers;94Meshutils meshutils;9596// Create new mesh structure:97mesh_t *mesh = new mesh_t;9899mesh->setNodes(0);100mesh->setPoints(0);101mesh->setEdges(0);102mesh->setSurfaces(0);103mesh->setElements(0);104105// Nodes:106mesh->setNodes(out->numberofpoints);107mesh->newNodeArray(mesh->getNodes());108109REAL *pointlist = out->pointlist;110111for(int i=0; i < mesh->getNodes(); i++) {112node_t *node = mesh->getNode(i);113114node->setX(0, *pointlist++);115node->setX(1, *pointlist++);116node->setX(2, *pointlist++);117118node->setIndex(-1); // default119}120121// Elements:122mesh->setElements(out->numberoftetrahedra);123mesh->newElementArray(mesh->getElements());124125int *tetrahedronlist = out->tetrahedronlist;126REAL *attribute = out->tetrahedronattributelist;127int na = out->numberoftetrahedronattributes;128129for(int i=0; i< mesh->getElements(); i++) {130element_t *element = mesh->getElement(i);131132element->setNature(PDE_BULK);133element->setCode(504);134element->setNodes(4);135element->newNodeIndexes(4);136137element->setNodeIndex(0, (*tetrahedronlist++) - out->firstnumber);138element->setNodeIndex(1, (*tetrahedronlist++) - out->firstnumber);139element->setNodeIndex(2, (*tetrahedronlist++) - out->firstnumber);140element->setNodeIndex(3, (*tetrahedronlist++) - out->firstnumber);141142element->setIndex(1); // default143// must have "A" in control string:144if(out->tetrahedronattributelist != (REAL*)NULL)145element->setIndex((int)attribute[na*(i+1)-1]);146}147148// Boundary elements:149mesh->setSurfaces(out->numberoftrifaces);150mesh->newSurfaceArray(mesh->getSurfaces());151152int *trifacelist = out->trifacelist;153int *face2tetlist = out->face2tetlist;154155for(int i=0; i < mesh->getSurfaces(); i++) {156surface_t *surface = mesh->getSurface(i);157158surface->setNature(PDE_BOUNDARY);159surface->setCode(303);160surface->setNodes(3);161surface->newNodeIndexes(3);162surface->setEdges(3);163surface->newEdgeIndexes(3);164165surface->setElements(2);166surface->newElementIndexes(2);167168surface->setIndex(1); // default169if(out->trifacemarkerlist != (int*)NULL)170surface->setIndex(out->trifacemarkerlist[i]);171172surface->setEdgeIndex(0, -1);173surface->setEdgeIndex(1, -1);174surface->setEdgeIndex(2, -1);175176surface->setElementIndex(0, -1);177surface->setElementIndex(1, -1);178179// must have "nn" in control string:180if(out->face2tetlist != (int*)NULL) {181surface->setElementIndex(0, (*face2tetlist++) - out->firstnumber);182surface->setElementIndex(1, (*face2tetlist++) - out->firstnumber);183}184185int u = (*trifacelist++) - out->firstnumber;186int v = (*trifacelist++) - out->firstnumber;187int w = (*trifacelist++) - out->firstnumber;188189surface->setNodeIndex(0, u);190surface->setNodeIndex(1, v);191surface->setNodeIndex(2, w);192}193194// Edges:195meshutils.findSurfaceElementEdges(mesh);196meshutils.findSurfaceElementNormals(mesh);197198// Points:199mesh->setPoints(0);200// mesh->point == NULL;201202mesh->setDim(3);203mesh->setCdim(3);204205return mesh;206}207208209