cellAspectRatioControl.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM 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 OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cellAspectRatioControl.H"
27 #include "vectorTools.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 Foam::cellAspectRatioControl::cellAspectRatioControl
32 (
33  const dictionary& motionDict
34 )
35 :
36  aspectRatioDict_(motionDict.subOrEmptyDict("cellAspectRatioControl")),
37  aspectRatio_(aspectRatioDict_.lookupOrDefault<scalar>("aspectRatio", 1.0)),
38  aspectRatioDirection_
39  (
40  aspectRatioDict_.lookupOrDefault<vector>
41  (
42  "aspectRatioDirection",
43  Zero
44  )
45  )
46 {
47  // Normalise the direction
48  aspectRatioDirection_ /= mag(aspectRatioDirection_) + SMALL;
49 
50  Info<< nl
51  << "Cell Aspect Ratio Control" << nl
52  << " Ratio : " << aspectRatio_ << nl
53  << " Direction : " << aspectRatioDirection_
54  << endl;
55 }
56 
57 
58 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
59 
61 {}
62 
63 
64 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
65 
67 (
68  vector& alignmentDir,
69  scalar& targetFaceArea,
70  scalar& targetCellSize
71 ) const
72 {
73  const scalar cosAngle =
74  mag(vectorTools::cosPhi(alignmentDir, aspectRatioDirection_));
75 
76  // Change target face area based on aspect ratio
77  targetFaceArea +=
78  targetFaceArea
79  *(aspectRatio_ - 1.0)
80  *(1.0 - cosAngle);
81 
82  // Change target cell size based on aspect ratio
83  targetCellSize +=
84  targetCellSize
85  *(aspectRatio_ - 1.0)
86  *cosAngle;
87 
88  alignmentDir *= 0.5*targetCellSize;
89 }
90 
91 
93 (
94  const vector& alignmentDir,
95  const scalar targetCellSize,
96  const scalar rABMag,
97  vector& delta
98 ) const
99 {
100  const scalar cosAngle =
101  mag(vectorTools::cosPhi(alignmentDir, aspectRatioDirection_));
102 
103  delta +=
104  0.5
105  *delta
106  *cosAngle
107  *(targetCellSize/rABMag)
108  *(aspectRatio_ - 1.0);
109 }
110 
111 
112 // ************************************************************************* //
scalar delta
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
void updateCellSizeAndFaceArea(vector &alignmentDir, scalar &targetFaceArea, scalar &targetCellSize) const
Vector< scalar > vector
A scalar version of the templated Vector.
Definition: vector.H:49
virtual ~cellAspectRatioControl()
Destructor.
T cosPhi(const Vector< T > &a, const Vector< T > &b, const T &tolerance=SMALL)
Calculate angle between a and b in radians.
Definition: vectorTools.H:105
void updateDeltaVector(const vector &alignmentDir, const scalar targetCellSize, const scalar rABMag, vector &delta) const
static const zero Zero
Definition: zero.H:91
static const char nl
Definition: Ostream.H:262
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)