volumeOptimizer.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 "volumeOptimizer.H"
30 #include "tetrahedron.H"
31 #include "partTetMeshSimplex.H"
32 
33 //#define DEBUGSmooth
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
43  {
44  vector(-1.0, -1.0, -1.0),
45  vector(1.0, -1.0, -1.0),
46  vector(-1.0, 1.0, -1.0),
47  vector(1.0, 1.0, -1.0),
48  vector(-1.0, -1.0, 1.0),
49  vector(1.0, -1.0, 1.0),
50  vector(-1.0, 1.0, 1.0),
51  vector(1.0, 1.0, 1.0)
52  };
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
57 :
58  simplexSmoother(simplex)
59 {}
60 
62 {}
63 
64 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 // Member functions
66 
68 {
69  point& p = points_[pointI_];
70 
71  if( !bb_.contains(p) )
72  p = 0.5 * (bb_.max() + bb_.min());
73 
74  const scalar scale = 1.0 / bb_.mag();
75  forAll(points_, pI)
76  points_[pI] *= scale;
77  bb_.min() *= scale;
78  bb_.max() *= scale;
79 
80  //- find the optimum using divide and conquer
81  const scalar func = optimiseDivideAndConquer(tol);
82  const point copyP = p;
83 
84  //- check if the location can be improved using the steepest descent
85  const scalar funcAfter = optimiseSteepestDescent(tol);
86 
87  if( funcAfter > func )
88  p = copyP;
89 
90  //- scale back to the original size
91  forAll(points_, pI)
92  points_[pI] /= scale;
93  bb_.min() /= scale;
94  bb_.max() /= scale;
95 }
96 
97 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
98 
99 } // End namespace Foam
100 
101 // ************************************************************************* //
Foam::boundBox::mag
scalar mag() const
The magnitude of the bounding box span.
Definition: boundBoxI.H:90
Foam::volumeOptimizer::~volumeOptimizer
~volumeOptimizer()
Definition: volumeOptimizer.C:61
p
p
Definition: pEqn.H:62
Foam::partTetMeshSimplex
Definition: partTetMeshSimplex.H:52
Foam::volumeOptimizer::optimiseSteepestDescent
scalar optimiseSteepestDescent(const scalar tol)
optimise using the steepest descent
Definition: volumeOptimizerEvaluateGradients.C:286
Foam::boundBox::max
const point & max() const
Maximum describing the bounding box.
Definition: boundBoxI.H:60
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::simplexSmoother
class for volume optimizer
Definition: simplexSmoother.H:56
partTetMeshSimplex.H
volumeOptimizer.H
Foam::simplexSmoother::points_
DynList< point, 128 > & points_
mesh points
Definition: simplexSmoother.H:62
Foam::func
void func(FieldField< Field, Type > &f, const FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::boundBox::min
const point & min() const
Minimum describing the bounding box.
Definition: boundBoxI.H:54
Foam::simplexSmoother::pointI_
const label pointI_
label of the point
Definition: simplexSmoother.H:68
Foam::volumeOptimizer::optimizeNodePosition
void optimizeNodePosition(const scalar tol=0.001)
find the best position for the node
Definition: volumeOptimizer.C:67
Foam::volumeOptimizer::dirVecs
static const vector dirVecs[8]
direction vectors for divide and conquer algorithm
Definition: volumeOptimizer.H:59
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::vector
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
Foam::simplexSmoother::bb_
boundBox bb_
bound box
Definition: simplexSmoother.H:71
Foam::volumeOptimizer::volumeOptimizer
volumeOptimizer(partTetMeshSimplex &simplex)
construct from partTetMeshSimplex
Definition: volumeOptimizer.C:56
Foam::Vector< scalar >
Foam::boundBox::contains
bool contains(const point &) const
Contains point? (inside or on edge)
Definition: boundBoxI.H:170
Foam::volumeOptimizer::optimiseDivideAndConquer
scalar optimiseDivideAndConquer(const scalar tol)
optimize position using a divide and conquer algorithm
Definition: volumeOptimizerEvaluateGradients.C:222
tetrahedron.H