Newer
Older
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software

Christophe Geuzaine
committed
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
#include "Gmsh.h"
#include "Numeric.h"
#include "Context.h"
extern Context_T CTX;
template<class T>
static void GetQualityMeasure(std::vector<T*>& ele,
double &gamma, double &gammaMin, double &gammaMax,
double &eta, double &etaMin, double &etaMax,
double &rho, double &rhoMin, double &rhoMax,
double quality[3][100])
for(unsigned int i = 0; i < ele.size(); i++){
double g = ele[i]->gammaShapeMeasure();
gamma += g;
gammaMin = std::min(gammaMin, g);
gammaMax = std::max(gammaMax, g);
double e = ele[i]->etaShapeMeasure();
eta += e;
etaMin = std::min(etaMin, e);
etaMax = std::max(etaMax, e);
double r = ele[i]->rhoShapeMeasure();
rho += r;
rhoMin = std::min(rhoMin, r);
rhoMax = std::max(rhoMax, r);
for(int j = 0; j < 100; j++){
if(g > j / 100. && g <= (j + 1) / 100.) quality[0][j]++;
if(e > j / 100. && e <= (j + 1) / 100.) quality[1][j]++;
if(r > j / 100. && r <= (j + 1) / 100.) quality[2][j]++;
}
}
void GetStatistics(double stat[50], double quality[3][100])
for(int i = 0; i < 50; i++) stat[i] = 0.;
GModel *m = GModel::current();
stat[0] = m->numVertex();
stat[1] = m->numEdge();
stat[2] = m->numFace();
stat[3] = m->numRegion();
std::map<int, std::vector<GEntity*> > physicals[4];
stat[45] = physicals[0].size() + physicals[1].size() +
physicals[2].size() + physicals[3].size();
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it)
stat[4] += (*it)->mesh_vertices.size();
for(GModel::fiter it = m->firstFace(); it != m->lastFace(); ++it){
stat[5] += (*it)->mesh_vertices.size();
stat[7] += (*it)->triangles.size();
stat[8] += (*it)->quadrangles.size();
}
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){
stat[6] += (*it)->mesh_vertices.size();
stat[9] += (*it)->tetrahedra.size();
stat[10] += (*it)->hexahedra.size();
stat[11] += (*it)->prisms.size();
stat[12] += (*it)->pyramids.size();
}
stat[13] = CTX.mesh_timer[0];
stat[14] = CTX.mesh_timer[1];
stat[15] = CTX.mesh_timer[2];
if(quality){
for(int i = 0; i < 3; i++)
for(int j = 0; j < 100; j++)
quality[i][j] = 0.;
double gamma=0., gammaMin=1., gammaMax=0.;
double eta=0., etaMin=1., etaMax=0.;
double rho=0., rhoMin=1., rhoMax=0.;
for(GModel::riter it = m->firstRegion(); it != m->lastRegion(); ++it){
GetQualityMeasure((*it)->tetrahedra, gamma, gammaMin, gammaMax,
eta, etaMin, etaMax, rho, rhoMin, rhoMax, quality);
GetQualityMeasure((*it)->hexahedra, gamma, gammaMin, gammaMax,
eta, etaMin, etaMax, rho, rhoMin, rhoMax, quality);
GetQualityMeasure((*it)->prisms, gamma, gammaMin, gammaMax,
eta, etaMin, etaMax, rho, rhoMin, rhoMax, quality);
GetQualityMeasure((*it)->pyramids, gamma, gammaMin, gammaMax,
eta, etaMin, etaMax, rho, rhoMin, rhoMax, quality);
double N = stat[9] + stat[10] + stat[11] + stat[12];
stat[17] = N ? gamma / N : 0.;
stat[18] = gammaMin;
stat[19] = gammaMax;
stat[20] = N ? eta / N : 0.;
stat[21] = etaMin;
stat[22] = etaMax;
stat[23] = N ? rho / N : 0;
stat[24] = rhoMin;
stat[25] = rhoMax;
stat[26] = List_Nbr(CTX.post.list);
for(int i = 0; i < List_Nbr(CTX.post.list); i++) {
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
stat[27] += v->NbSP + v->NbVP + v->NbTP;
stat[28] += v->NbSL + v->NbVL + v->NbTL;
stat[29] += v->NbST + v->NbVT + v->NbTT;
stat[30] += v->NbSQ + v->NbVQ + v->NbTQ;
stat[31] += v->NbSS + v->NbVS + v->NbTS;
stat[32] += v->NbSH + v->NbVH + v->NbTH;
stat[33] += v->NbSI + v->NbVI + v->NbTI;
stat[34] += v->NbSY + v->NbVY + v->NbTY;
stat[35] += v->NbT2 + v->NbT3;
if(v->Visible) {
if(v->DrawPoints)
stat[36] +=
(v->DrawScalars ? v->NbSP : 0) + (v->DrawVectors ? v->NbVP : 0) +
(v->DrawTensors ? v->NbTP : 0);
if(v->DrawLines)
stat[37] +=
(v->DrawScalars ? v->NbSL : 0) + (v->DrawVectors ? v->NbVL : 0) +
(v->DrawTensors ? v->NbTL : 0);
if(v->DrawTriangles)
stat[38] +=
(v->DrawScalars ? v->NbST : 0) + (v->DrawVectors ? v->NbVT : 0) +
(v->DrawTensors ? v->NbTT : 0);
if(v->DrawQuadrangles)
stat[39] +=
(v->DrawScalars ? v->NbSQ : 0) + (v->DrawVectors ? v->NbVQ : 0) +
(v->DrawTensors ? v->NbTQ : 0);
if(v->DrawTetrahedra)
stat[40] +=
(v->DrawScalars ? v->NbSS : 0) + (v->DrawVectors ? v->NbVS : 0) +
(v->DrawTensors ? v->NbTS : 0);
if(v->DrawHexahedra)
stat[41] +=
(v->DrawScalars ? v->NbSH : 0) + (v->DrawVectors ? v->NbVH : 0) +
(v->DrawTensors ? v->NbTH : 0);
if(v->DrawPrisms)
stat[42] +=
(v->DrawScalars ? v->NbSI : 0) + (v->DrawVectors ? v->NbVI : 0) +
(v->DrawTensors ? v->NbTI : 0);
if(v->DrawPyramids)
stat[43] +=
(v->DrawScalars ? v->NbSY : 0) + (v->DrawVectors ? v->NbVY : 0) +
(v->DrawTensors ? v->NbTY : 0);
if(v->DrawStrings)
stat[44] += v->NbT2 + v->NbT3;
}
}
if(CTX.expert_mode || !m->numVertex()) return false;
// try to detect obvious mistakes in characteristic lenghts (one of
// the most common cause for erroneous bug reports on the mailing
// list)
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); ++it)
sumAllLc += (*it)->prescribedMeshSizeAtVertex();
if(!sumAllLc || pow(CTX.lc / sumAllLc, dim) > 1.e10)
return !GetBinaryAnswer("Your choice of characteristic lengths will likely produce\n"
"a very large mesh. Do you really want to continue?\n\n"
"(To disable this warning in the future, select `Enable\n"
"expert mode' in the option dialog.)",
"Continue", "Cancel");
return false;
}
double t1 = Cpu();
std::for_each(m->firstEdge(), m->lastEdge(), meshGEdge());
double t2 = Cpu();
Msg(INFO, "Mesh 1D complete (%g s)", CTX.mesh_timer[0]);
Msg(STATUS1, "Mesh");
}
if(CTX.mesh.algo2d == ALGO_2D_DELAUNAY && !CTX.expert_mode){
if(!GetBinaryAnswer("The 2D Delaunay algorithm is still highly experimental\n"
"and produces triangles with random orientations. Do you\n"
"really want to continue?\n\n"
"(To disable this warning in the future, select `Enable\n"
"expert mode' in the option dialog.)",
"Continue", "Cancel")) return;
}
double t1 = Cpu();
// boundary layers are special: their generation (including vertices
// and curve meshes) is global as it depends on a smooth normal
// field generated from the surface mesh of the source surfaces
if(!Mesh2DWithBoundaryLayers(m))
std::for_each(m->firstFace(), m->lastFace(), meshGFace());
double t2 = Cpu();
Msg(INFO, "Mesh 2D complete (%g s)", CTX.mesh_timer[1]);
Msg(STATUS1, "Mesh");
}
void FindConnectedRegions(std::vector<GRegion*> &delaunay,
std::vector<std::vector<GRegion*> > &connected)
{
// FIXME: need to split region vector into connected components here!
connected.push_back(delaunay);
}
double t1 = Cpu();
std::for_each(m->firstRegion(), m->lastRegion(), meshGRegionExtruded());
// then subdivide if necessary (unfortunately the subdivision is a
// global operation, which can require changing the surface mesh!)
// then mesh all the non-delaunay regions
std::vector<GRegion*> delaunay;
std::for_each(m->firstRegion(), m->lastRegion(), meshGRegion(delaunay));
// and finally mesh the delaunay regions (again, this is global; but
// we mesh each connected part separately for performance and mesh
// quality reasons)
std::vector<std::vector<GRegion*> > connected;
FindConnectedRegions(delaunay, connected);
for(unsigned int i = 0; i < connected.size(); i++)
MeshDelaunayVolume(connected[i]);
double t2 = Cpu();
Msg(INFO, "Mesh 3D complete (%g s)", CTX.mesh_timer[2]);
Msg(STATUS1, "Mesh");
}
std::for_each(m->firstRegion(), m->lastRegion(), optimizeMeshGRegion());
Msg(INFO, "I'm busy! Ask me that later...");
return;
}
GModel *m = GModel::current();
int old = m->getMeshStatus(false);
std::for_each(m->firstRegion(), m->lastRegion(), deMeshGRegion());
std::for_each(m->firstFace(), m->lastFace(), deMeshGFace());
}
std::for_each(m->firstRegion(), m->lastRegion(), deMeshGRegion());
}
}
if(m->getMeshStatus() >= 2)
std::for_each(m->firstFace(), m->lastFace(), orientMeshGFace());
if(m->getMeshStatus() && CTX.mesh.order > 1)
SetOrderN(m, CTX.mesh.order, CTX.mesh.second_order_linear,
Msg(INFO, "%d vertices %d elements", m->numVertices(), m->numElements());