~ubuntu-branches/ubuntu/intrepid/gmsh/intrepid

« back to all changes in this revision

Viewing changes to Mesh/2D_BGMesh.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Emmet Hikory
  • Date: 2007-05-07 10:01:37 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070507100137-6j0rzz1ucbn0m2jt
Tags: 2.0.7-1ubuntu1
* Merged with Debian unstable.  Remaining Ubuntu changes:
  - Add .desktop file
  - Add icon
* Added XSBC-Original-Maintainer
* Removed Application Category from gmsh.desktop
* Link against GLU (fixes FTBFS)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// $Id: 2D_BGMesh.cpp,v 1.17 2006/01/06 00:34:25 geuzaine Exp $
2
 
//
3
 
// Copyright (C) 1997-2006 C. Geuzaine, J.-F. Remacle
4
 
//
5
 
// This program is free software; you can redistribute it and/or modify
6
 
// it under the terms of the GNU General Public License as published by
7
 
// the Free Software Foundation; either version 2 of the License, or
8
 
// (at your option) any later version.
9
 
//
10
 
// This program is distributed in the hope that it will be useful,
11
 
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
// GNU General Public License for more details.
14
 
//
15
 
// You should have received a copy of the GNU General Public License
16
 
// along with this program; if not, write to the Free Software
17
 
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18
 
// USA.
19
 
// 
20
 
// Please report all bugs and problems to <gmsh@geuz.org>.
21
 
 
22
 
#include "Gmsh.h"
23
 
#include "Numeric.h"
24
 
#include "Mesh.h"
25
 
#include "2D_Mesh.h"
26
 
 
27
 
extern Mesh *THEM;
28
 
 
29
 
// Compute Calcul the charact. length on 1 pt by interpolating in the
30
 
// background mesh
31
 
 
32
 
double find_quality(MPoint center, DocRecord * BGMESH)
33
 
{
34
 
  int i;
35
 
  Delaunay *del;
36
 
  PointRecord *pPointArray;
37
 
  PointNumero a, b, c;
38
 
  double qual, q1, q2, q3, X[3], Y[3], u, v, det, Xp, Yp;
39
 
  double Exp = 2., r, deno, nume;
40
 
 
41
 
  if((del = Find_Triangle(center, BGMESH, BOF)) == NULL) {
42
 
    Msg(GERROR, "Exterior point (%g,%g)", center.v, center.h);
43
 
    return 1.e-15;
44
 
  }
45
 
 
46
 
  pPointArray = BGMESH->points;
47
 
 
48
 
  a = del->t.a;
49
 
  b = del->t.b;
50
 
  c = del->t.c;
51
 
 
52
 
  Xp = center.h;
53
 
  Yp = center.v;
54
 
 
55
 
  X[0] = pPointArray[a].where.h;
56
 
  X[1] = pPointArray[b].where.h;
57
 
  X[2] = pPointArray[c].where.h;
58
 
 
59
 
  Y[0] = pPointArray[a].where.v;
60
 
  Y[1] = pPointArray[b].where.v;
61
 
  Y[2] = pPointArray[c].where.v;
62
 
 
63
 
  q1 = pPointArray[a].quality;
64
 
  q2 = pPointArray[b].quality;
65
 
  q3 = pPointArray[c].quality;
66
 
 
67
 
  det = (X[2] - X[0]) * (Y[1] - Y[0]) - (Y[2] - Y[0]) * (X[1] - X[0]);
68
 
 
69
 
  if(det != 0.0) {
70
 
    u = ((Xp - X[0]) * (Y[1] - Y[0]) - (Yp - Y[0]) * (X[1] - X[0])) / det;
71
 
    v = ((X[2] - X[0]) * (Yp - Y[0]) - (Y[2] - Y[0]) * (Xp - X[0])) / det;
72
 
  }
73
 
  else {
74
 
    Msg(WARNING, "Degenerated triangle (det=%g)", det);
75
 
    u = v = 0.0;
76
 
  }
77
 
 
78
 
  if(u >= -1.e-8 && v >= -1.e-8 && 1. - u - v >= -1.e-8) {
79
 
    qual = q1 * (1. - u - v) + q2 * v + q3 * u;
80
 
    return (qual);
81
 
  }
82
 
  else {
83
 
    pPointArray = BGMESH->points;
84
 
    deno = nume = 0.0;
85
 
    for(i = 0; i < BGMESH->numPoints; i++) {
86
 
      r = sqrt(DSQR(center.h - pPointArray[i].where.h) +
87
 
               DSQR(center.v - pPointArray[i].where.v));
88
 
      r = pow(r, Exp);
89
 
      if(r < 1.e-10)
90
 
        return (pPointArray[i].quality);
91
 
      nume += pPointArray[i].quality / r;
92
 
      deno += 1. / r;
93
 
    }
94
 
    return (nume / deno);
95
 
  }
96
 
}