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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2012-2016 OpenFOAM Foundation
9 Copyright (C) 2020 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
30#include "vectorTools.H"
31
32// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33
35(
36 const dictionary& motionDict
37)
38:
39 aspectRatioDict_(motionDict.subOrEmptyDict("cellAspectRatioControl")),
40 aspectRatio_(aspectRatioDict_.getOrDefault<scalar>("aspectRatio", 1)),
41 aspectRatioDirection_
42 (
43 aspectRatioDict_.getOrDefault<vector>
44 (
45 "aspectRatioDirection",
46 Zero
47 )
48 )
49{
50 // Normalise the direction
51 aspectRatioDirection_.normalise();
52
53 Info<< nl
54 << "Cell Aspect Ratio Control" << nl
55 << " Ratio : " << aspectRatio_ << nl
56 << " Direction : " << aspectRatioDirection_
57 << endl;
58}
59
60
61// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62
64{}
65
66
67// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
68
70(
71 vector& alignmentDir,
72 scalar& targetFaceArea,
73 scalar& targetCellSize
74) const
75{
76 const scalar cosAngle =
77 mag(vectorTools::cosPhi(alignmentDir, aspectRatioDirection_));
78
79 // Change target face area based on aspect ratio
80 targetFaceArea +=
81 targetFaceArea
82 *(aspectRatio_ - 1.0)
83 *(1.0 - cosAngle);
84
85 // Change target cell size based on aspect ratio
86 targetCellSize +=
87 targetCellSize
88 *(aspectRatio_ - 1.0)
89 *cosAngle;
90
91 alignmentDir *= 0.5*targetCellSize;
92}
93
94
96(
97 const vector& alignmentDir,
98 const scalar targetCellSize,
99 const scalar rABMag,
101) const
102{
103 const scalar cosAngle =
104 mag(vectorTools::cosPhi(alignmentDir, aspectRatioDirection_));
105
106 delta +=
107 0.5
108 *delta
109 *cosAngle
110 *(targetCellSize/rABMag)
111 *(aspectRatio_ - 1.0);
112}
113
114
115// ************************************************************************* //
scalar delta
virtual ~cellAspectRatioControl()
Destructor.
void updateCellSizeAndFaceArea(vector &alignmentDir, scalar &targetFaceArea, scalar &targetCellSize) const
void updateDeltaVector(const vector &alignmentDir, const scalar targetCellSize, const scalar rABMag, vector &delta) const
A Vector of values with scalar precision, where scalar is float/double depending on the compilation f...
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:107
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53