cellSizeAndAlignmentControls.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-2015 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
30
31// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32
33namespace Foam
34{
35defineTypeNameAndDebug(cellSizeAndAlignmentControls, 0);
36}
37
38
39// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
40
41bool Foam::cellSizeAndAlignmentControls::evalCellSizeFunctions
42(
43 const point& pt,
44 scalar& minSize,
45 label& maxPriority
46) const
47{
48 bool anyFunctionFound = false;
49
50 // Regions requesting with the same priority take the smallest
51
52 if (controlFunctions_.size())
53 {
54 // Maintain priority of current hit. Initialise so it always goes
55 // through at least once.
56 label previousPriority = labelMin;
57
58 forAll(controlFunctions_, i)
59 {
60 const cellSizeAndAlignmentControl& cSF = controlFunctions_[i];
61
62 if (isA<searchableSurfaceControl>(cSF))
63 {
64 const searchableSurfaceControl& sSC =
65 refCast<const searchableSurfaceControl>(cSF);
66
67 anyFunctionFound = sSC.cellSize(pt, minSize, previousPriority);
68
69 if (previousPriority > maxPriority)
70 {
71 maxPriority = previousPriority;
72 }
73 }
74 }
75 }
76
77 return anyFunctionFound;
78}
79
80
81// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
82
84(
85 const Time& runTime,
86 const dictionary& shapeControlDict,
87 const conformationSurfaces& geometryToConformTo,
88 const scalar& defaultCellSize
89)
90:
91 shapeControlDict_(shapeControlDict),
92 geometryToConformTo_(geometryToConformTo),
93 controlFunctions_(shapeControlDict_.size()),
94 defaultCellSize_(defaultCellSize)
95{
96 label functionI = 0;
97
98 for (const entry& dEntry : shapeControlDict_)
99 {
100 const word& shapeControlEntryName = dEntry.keyword();
101 const dictionary& controlFunctionDict = dEntry.dict();
102
103 Info<< nl << "Shape Control : " << shapeControlEntryName << endl;
105
106 controlFunctions_.set
107 (
108 functionI,
109 cellSizeAndAlignmentControl::New
110 (
111 runTime,
112 shapeControlEntryName,
113 controlFunctionDict,
114 geometryToConformTo_,
115 defaultCellSize_
116 )
117 );
118
120
121 functionI++;
122 }
123
124 // Sort controlFunctions_ by maxPriority
125 SortableList<label> functionPriorities(functionI);
126
127 forAll(controlFunctions_, funcI)
128 {
129 functionPriorities[funcI] = controlFunctions_[funcI].maxPriority();
130 }
131
132 functionPriorities.reverseSort();
133
134 labelList invertedFunctionPriorities =
135 invert(functionPriorities.size(), functionPriorities.indices());
136
137 controlFunctions_.reorder(invertedFunctionPriorities);
138}
139
140
141// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
142
144{}
145
146
147// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
148
150(
151 const point& pt
152) const
153{
154 scalar size = defaultCellSize_;
155 label maxPriority = -1;
156
157 evalCellSizeFunctions(pt, size, maxPriority);
158
159 return size;
160}
161
162
164(
165 const point& pt,
166 label& maxPriority
167) const
168{
169 scalar size = defaultCellSize_;
170 maxPriority = -1;
171
172 evalCellSizeFunctions(pt, size, maxPriority);
173
174 return size;
175}
176
177
178// ************************************************************************* //
virtual ~cellSizeAndAlignmentControls()
Destructor.
scalar cellSize(const point &pt) const
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
engineTime & runTime
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
constexpr label labelMin
Definition: label.H:60
messageStream Info
Information stream (stdout output on master, null elsewhere)
vector point
Point is a vector.
Definition: point.H:43
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:349
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:36
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:356
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333