Path: blob/devel/ElmerGUI/Application/src/meshingthread.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* ElmerGUI meshingthread *26* *27*****************************************************************************28* *29* Authors: Mikko Lyly, Juha Ruokolainen and Peter R�back *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*****************************************************************************/3940#include <QtGui>41#include <iostream>42#include <stdio.h>43#include "meshingthread.h"4445using namespace std;4647MeshingThread::MeshingThread(QObject *parent)48: QThread(parent)49{50this->setTerminationEnabled(true);51}525354MeshingThread::~MeshingThread()55{56}5758nglib::Ng_Mesh* MeshingThread::getNgMesh()59{60return this->ngmesh;61}6263void MeshingThread::generate(int generatorType,64QString cs,65TetlibAPI *tetlibAPI,66nglib::Ng_Mesh *ngmesh,67nglib::Ng_STL_Geometry *nggeom,68nglib::Ng_Geometry_2D *nggeom2d,69int ngDim,70nglib::Ng_Meshing_Parameters *mp)71{72this->generatorType = generatorType;7374this->tetgenControlString = cs;75this->tetlibAPI = tetlibAPI;76this->in = tetlibAPI->in;77this->out = tetlibAPI->out;7879this->delegate_tetrahedralize = tetlibAPI->delegate_tetrahedralize;8081this->ngmesh = ngmesh;82this->nggeom = nggeom;83this->nggeom2d = nggeom2d;84this->mp = mp;85this->ngDim = ngDim;8687if (!isRunning()) {88cout << "Starting meshing thread with low priority" << endl;89cout.flush();90start(LowPriority);91} else {92cout << "Meshing thread is already running" << endl;93cout.flush();94return;95}96}9798void MeshingThread::stopMeshing()99{100cout << "Terminating meshing thread... ";101cout.flush();102103terminate();104// wait();105106cout << "done" << endl;107cout.flush();108}109110void MeshingThread::run()111{112QString qs;113char ss[1024];114115if(generatorType == GEN_TETLIB) {116117cout << "tetlib: control string: "118#if WITH_QT5 || WITH_QT6119<< string(tetgenControlString.toLatin1()) << endl;120#else121<< string(tetgenControlString.toAscii()) << endl;122#endif123cout << "tetlib: input points: " << in->numberofpoints << endl;124cout.flush();125126out->deinitialize();127out->initialize();128129#if WITH_QT5 || WITH_QT6130sprintf(ss, "%s", (const char*)(tetgenControlString.toLatin1()));131#else132sprintf(ss, "%s", (const char*)(tetgenControlString.toAscii()));133#endif134135if(delegate_tetrahedralize)136delegate_tetrahedralize(1, NULL, ss, in, out, NULL, NULL);137138cout << "tetlib: nodes: " << out->numberofpoints << endl;139cout << "tetlib: elements: " << out->numberoftetrahedra << endl;140cout << "tetlib: boundary elements: " << out->numberoftrifaces << endl;141cout.flush();142143} else if(generatorType == GEN_NGLIB) {144145int rv = 0;146147if(ngDim == 3) {148149cout << "3D meshing..." << endl;150151rv = nglib::Ng_STL_GenerateSurfaceMesh(nggeom, ngmesh, mp);152cout << "Generate Surface Mesh: Ng_result=" << rv << endl;153154rv = nglib::Ng_GenerateVolumeMesh(ngmesh, mp);155cout << "Generate Volume Mesh: Ng_result=" << rv << endl;156157int np = nglib::Ng_GetNP(ngmesh);158cout << "Meshing thread: nodes: " << np << endl;159160int ne = nglib::Ng_GetNE(ngmesh);161cout << "Meshing thread: elements: " << ne << endl;162163int nse = nglib::Ng_GetNSE(ngmesh);164cout << "Meshing thread: boundary elements: " << nse << endl;165cout.flush();166167} else if(ngDim == 2) {168169cout << "2D meshing..." << endl;170171rv = nglib::Ng_GenerateMesh_2D(nggeom2d, &ngmesh, mp);172cout << "Generate 2D Mesh: Ng_result=" << rv << endl;173174int np = nglib::Ng_GetNP_2D(ngmesh);175cout << "Meshing thread: nodes: " << np << endl;176177int ne = nglib::Ng_GetNE_2D(ngmesh);178cout << "Meshing thread: elements: " << ne << endl;179180int nse = nglib::Ng_GetNSeg_2D(ngmesh);181cout << "Meshing thread: boundary elements: " << nse << endl;182cout.flush();183184} else {185186cout << "Illegal spatial dimension: " << ngDim << endl;187188}189190} else {191192cout << "Meshgen: unknown generator type\n";193cout.flush();194195}196}197198199