meshSurfaceOptimizerOptimizePoint.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 "meshSurfaceOptimizer.H"
31 #include "meshOctree.H"
32 #include "triangle.H"
33 #include "plane.H"
34 #include "surfaceOptimizer.H"
35 
36 //#define DEBUGSmooth
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
46 (
47  const label bpI,
48  const bool transformIntoPlane
49 ) const
50 {
51  if( vertexType_[bpI] & LOCKED )
52  return;
53 
54  const point newP = newPositionLaplacian(bpI, transformIntoPlane);
55 
56  meshSurfaceEngineModifier surfaceModifier(surfaceEngine_);
57  surfaceModifier.moveBoundaryVertex(bpI, newP);
58 }
59 
61 (
62  const label bpI,
63  const bool transformIntoPlane
64 ) const
65 {
66  if( vertexType_[bpI] & LOCKED )
67  return;
68 
69  const point newP = newPositionLaplacianFC(bpI, transformIntoPlane);
70 
71  meshSurfaceEngineModifier surfaceModifier(surfaceEngine_);
72  surfaceModifier.moveBoundaryVertex(bpI, newP);
73 }
74 
76 (
77  const label bpI,
78  const scalar tol
79 )
80 {
81  if( vertexType_[bpI] & LOCKED )
82  return;
83 
84  const pointFieldPMG& points = surfaceEngine_.points();
85  const labelList& bPoints = surfaceEngine_.boundaryPoints();
86 
87  # ifdef DEBUGSmooth
88  Info << "Smoothing boundary node " << bpI << endl;
89  Info << "Node label in the mesh is " << bPoints[bpI] << endl;
90  Info << "Point coordinates " << points[bPoints[bpI]] << endl;
91  # endif
92 
93  //- project vertices onto the plane
94  const vector& pNormal = surfaceEngine_.pointNormals()[bpI];
95  if( magSqr(pNormal) < VSMALL )
96  return;
97 
98  const plane pl(points[bPoints[bpI]], pNormal);
99 
100  DynList<point> pts;
101  DynList<triFace> trias;
102  vector vecX, vecY;
103  if( !transformIntoPlane(bpI, pl, vecX, vecY, pts, trias) )
104  {
105  Warning << "Cannot transform into plane" << endl;
106  return;
107  }
108 
109  surfaceOptimizer so(pts, trias);
110  point newPoint = so.optimizePoint(tol);
111 
112  const point newP
113  (
114  points[bPoints[bpI]] +
115  vecX * newPoint.x() +
116  vecY * newPoint.y()
117  );
118 
119  meshSurfaceEngineModifier sm(surfaceEngine_);
120  sm.moveBoundaryVertex(bpI, newP);
121 }
122 
124 {
125  if( vertexType_[bpI] & LOCKED )
126  return;
127 
129  const labelList& bPoints = surfaceEngine_.boundaryPoints();
130 
131  const point pos = newEdgePositionLaplacian(bpI);
132  const point newP = 0.5 * (pos + points[bPoints[bpI]]);
133 
134  # ifdef DEBUGSearch
135  Info << "New position for point is " << newP << endl;
136  # endif
137 
139 }
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 } // End namespace Foam
144 
145 // ************************************************************************* //
Foam::meshSurfaceOptimizer::nodeDisplacementLaplacianFC
void nodeDisplacementLaplacianFC(const label bpI, const bool transformIntoPlane=true) const
Definition: meshSurfaceOptimizerOptimizePoint.C:61
Foam::surfaceOptimizer::optimizePoint
point optimizePoint(const scalar tol=0.1)
optimizes position of a central point in the simplex
Definition: surfaceOptimizer.C:382
Foam::meshSurfaceOptimizer::nodeDisplacementLaplacian
void nodeDisplacementLaplacian(const label bpI, const bool transformIntoPlane=true) const
Definition: meshSurfaceOptimizerOptimizePoint.C:46
triangle.H
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::Warning
messageStream Warning
Foam::meshSurfaceOptimizer::LOCKED
@ LOCKED
Definition: meshSurfaceOptimizer.H:248
Foam::meshSurfaceOptimizer::newEdgePositionLaplacian
point newEdgePositionLaplacian(const label bpI) const
Definition: meshSurfaceOptimizerI.H:398
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::meshSurfaceOptimizer::nodeDisplacementSurfaceOptimizer
void nodeDisplacementSurfaceOptimizer(const label bpI, const scalar tol=1.0)
smooth the node using surface optimizer
Definition: meshSurfaceOptimizerOptimizePoint.C:76
meshOctree.H
Foam::plane
Geometric class that creates a 2D plane and can return the intersection point between a line and the ...
Definition: plane.H:60
Foam::meshSurfaceEngineModifier
Definition: meshSurfaceEngineModifier.H:48
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
plane.H
Foam::Info
messageStream Info
Foam::meshSurfaceOptimizer::vertexType_
List< direction > vertexType_
type of surface vertex
Definition: meshSurfaceOptimizer.H:70
Foam::meshSurfaceEngineModifier::moveBoundaryVertex
void moveBoundaryVertex(const label bpI, const point &newP)
relocate the selected boundary vertex and update geometry data
Definition: meshSurfaceEngineModifier.C:77
Foam::meshSurfaceEngine::points
const pointFieldPMG & points() const
Definition: meshSurfaceEngineI.H:49
Foam::Vector::x
const Cmpt & x() const
Definition: VectorI.H:65
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynList
Definition: DynList.H:53
Foam::meshSurfaceOptimizer::surfaceEngine_
const meshSurfaceEngine & surfaceEngine_
const reference to the mesh surface
Definition: meshSurfaceOptimizer.H:67
surfaceOptimizer.H
Foam::surfaceOptimizer
Definition: surfaceOptimizer.H:50
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
points
const pointField & points
Definition: gmvOutputHeader.H:1
meshSurfaceEngineModifier.H
Foam::meshSurfaceEngine::boundaryPoints
const labelList & boundaryPoints() const
Definition: meshSurfaceEngineI.H:84
Foam::meshSurfaceOptimizer::edgeNodeDisplacement
void edgeNodeDisplacement(const label bpI) const
smooth edge node
Definition: meshSurfaceOptimizerOptimizePoint.C:123
Foam::Vector::y
const Cmpt & y() const
Definition: VectorI.H:71
Foam::pointFieldPMG
Definition: pointFieldPMG.H:50
meshSurfaceOptimizer.H
Foam::magSqr
dimensioned< scalar > magSqr(const dimensioned< Type > &)
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:190