meshUntangler.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "demandDrivenData.H"
29 #include "meshUntangler.H"
30 #include "plane.H"
31 
32 //#define DEBUGSmooth
33 
34 #ifdef DEBUGSmooth
35 #include "Time.H"
36 #include "objectRegistry.H"
37 #endif
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 namespace Foam
42 {
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
47 (
48  partTetMeshSimplex& simplex
49 )
50 :
51  simplexSmoother(simplex)
52 {
53 }
54 
56 {}
57 
58 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
59 
60 void meshUntangler::optimizeNodePosition(const scalar /*tol*/)
61 {
62  # ifdef DEBUGSmooth
63  Info << "Untangling point " << pointI_ << endl;
64  # endif
65 
66  cutRegion cr(bb_);
67 
68  forAll(tets_, tetI)
69  {
70  const partTet& tet = tets_[tetI];
71  vector n
72  (
73  (points_[tet.b()] - points_[tet.a()]) ^
74  (points_[tet.c()] - points_[tet.a()])
75  );
76 
77  if( mag(n) < VSMALL ) continue;
78 
79  plane pl(points_[tet.a()], n);
80 
81  # ifdef DEBUGSmooth
82  Info << "tet.a() " << tet.a() << endl;
83  Info << "Cutting plane ref point " << pl.refPoint() << endl;
84  Info << "Cutting plane normal " << pl.normal() << endl;
85  # endif
86 
87  cr.planeCut(pl);
88  }
89 
90  if( cr.points().size() )
91  {
93 
94  const DynList<point, 64>& pts = cr.points();
95  forAll(pts, pI)
96  p += pts[pI];
97 
98  p /= pts.size();
99 
100  # ifdef DEBUGSmooth
101  Info << "Corners of the feasible region " << pts << endl;
102  # endif
103 
104  for(direction i=0;i<vector::nComponents;++i)
105  {
106  const scalar& val = p[i];
107  if( (val != val) || ((val - val) != (val - val)) )
108  return;
109  }
110 
111  points_[pointI_] = p;
112  }
113 }
114 
115 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
116 
117 } // End namespace Foam
118 
119 // ************************************************************************* //
Foam::plane::normal
const vector & normal() const
Return plane normal.
Definition: plane.C:248
Foam::meshUntangler::cutRegion::planeCut
void planeCut(const plane &plane)
cut the region woth the plane
Definition: meshUntanglerCutRegion.C:195
Foam::Vector< scalar >::zero
static const Vector zero
Definition: Vector.H:80
p
p
Definition: pEqn.H:62
Foam::partTetMeshSimplex
Definition: partTetMeshSimplex.H:52
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::partTet::b
label b() const
Definition: partTetI.H:68
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::partTet
Definition: partTet.H:53
objectRegistry.H
Foam::meshUntangler::optimizeNodePosition
void optimizeNodePosition(const scalar tol=0.001)
Definition: meshUntangler.C:60
Foam::VectorSpace< Vector< scalar >, scalar, 3 >::nComponents
@ nComponents
Number of components in this vector space.
Definition: VectorSpace.H:88
Foam::meshUntangler::cutRegion::points
const DynList< point, 64 > & points() const
return the vertices of the feasible region
Definition: meshUntangler.H:115
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::simplexSmoother
class for volume optimizer
Definition: simplexSmoother.H:56
plane.H
Foam::Info
messageStream Info
Foam::simplexSmoother::points_
DynList< point, 128 > & points_
mesh points
Definition: simplexSmoother.H:62
Foam::simplexSmoother::pointI_
const label pointI_
label of the point
Definition: simplexSmoother.H:68
Foam::simplexSmoother::tets_
const DynList< partTet, 128 > & tets_
list tets around the given vertex
Definition: simplexSmoother.H:65
Foam::partTet::c
label c() const
Definition: partTetI.H:73
meshUntangler.H
Foam::meshUntangler::cutRegion
Definition: meshUntangler.H:60
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynList
Definition: DynList.H:53
Foam::meshUntangler::meshUntangler
meshUntangler(partTetMeshSimplex &simplex)
Construct from partTetMeshSimplex.
Definition: meshUntangler.C:47
Foam::simplexSmoother::bb_
boundBox bb_
bound box
Definition: simplexSmoother.H:71
Foam::Vector< scalar >
Foam::plane::refPoint
const point & refPoint() const
Return or return plane base point.
Definition: plane.C:255
Foam::direction
unsigned char direction
Definition: direction.H:43
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::partTet::a
label a() const
Return vertices.
Definition: partTetI.H:63
Foam::meshUntangler::~meshUntangler
~meshUntangler()
Definition: meshUntangler.C:55