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 | Copyright (C) 2012-2015 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 
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 defineTypeNameAndDebug(cellSizeAndAlignmentControls, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
38 
39 bool Foam::cellSizeAndAlignmentControls::evalCellSizeFunctions
40 (
41  const point& pt,
42  scalar& minSize,
43  label& maxPriority
44 ) const
45 {
46  bool anyFunctionFound = false;
47 
48  // Regions requesting with the same priority take the smallest
49 
50  if (controlFunctions_.size())
51  {
52  // Maintain priority of current hit. Initialise so it always goes
53  // through at least once.
54  label previousPriority = labelMin;
55 
56  forAll(controlFunctions_, i)
57  {
58  const cellSizeAndAlignmentControl& cSF = controlFunctions_[i];
59 
60  if (isA<searchableSurfaceControl>(cSF))
61  {
62  const searchableSurfaceControl& sSC =
63  refCast<const searchableSurfaceControl>(cSF);
64 
65  anyFunctionFound = sSC.cellSize(pt, minSize, previousPriority);
66 
67  if (previousPriority > maxPriority)
68  {
69  maxPriority = previousPriority;
70  }
71  }
72  }
73  }
74 
75  return anyFunctionFound;
76 }
77 
78 
79 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
80 
81 Foam::cellSizeAndAlignmentControls::cellSizeAndAlignmentControls
82 (
83  const Time& runTime,
84  const dictionary& shapeControlDict,
85  const conformationSurfaces& geometryToConformTo,
86  const scalar& defaultCellSize
87 )
88 :
89  shapeControlDict_(shapeControlDict),
90  geometryToConformTo_(geometryToConformTo),
91  controlFunctions_(shapeControlDict_.size()),
92  defaultCellSize_(defaultCellSize)
93 {
94  label functionI = 0;
95 
96  forAllConstIter(dictionary, shapeControlDict_, iter)
97  {
98  word shapeControlEntryName = iter().keyword();
99 
100  const dictionary& controlFunctionDict
101  (
102  shapeControlDict_.subDict(shapeControlEntryName)
103  );
104 
105  Info<< nl << "Shape Control : " << shapeControlEntryName << endl;
106  Info<< incrIndent;
107 
108  controlFunctions_.set
109  (
110  functionI,
112  (
113  runTime,
114  shapeControlEntryName,
115  controlFunctionDict,
116  geometryToConformTo_,
118  )
119  );
120 
121  Info<< decrIndent;
122 
123  functionI++;
124  }
125 
126  // Sort controlFunctions_ by maxPriority
127  SortableList<label> functionPriorities(functionI);
128 
129  forAll(controlFunctions_, funcI)
130  {
131  functionPriorities[funcI] = controlFunctions_[funcI].maxPriority();
132  }
133 
134  functionPriorities.reverseSort();
135 
136  labelList invertedFunctionPriorities =
137  invert(functionPriorities.size(), functionPriorities.indices());
138 
139  controlFunctions_.reorder(invertedFunctionPriorities);
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
144 
146 {}
147 
148 
149 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
150 
152 (
153  const point& pt
154 ) const
155 {
156  scalar size = defaultCellSize_;
157  label maxPriority = -1;
158 
159  evalCellSizeFunctions(pt, size, maxPriority);
160 
161  return size;
162 }
163 
164 
166 (
167  const point& pt,
168  label& maxPriority
169 ) const
170 {
171  scalar size = defaultCellSize_;
172  maxPriority = -1;
173 
174  evalCellSizeFunctions(pt, size, maxPriority);
175 
176  return size;
177 }
178 
179 
180 // ************************************************************************* //
scalar cellSize(const point &pt) const
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static autoPtr< cellSizeAndAlignmentControl > New(const Time &runTime, const word &name, const dictionary &controlFunctionDict, const conformationSurfaces &geometryToConformTo, const scalar &defaultCellSize)
Return a reference to the selected cellShapeControl.
labelList invert(const label len, const labelUList &)
Invert one-to-one map. Unmapped elements will be -1.
Definition: ListOps.C:37
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
static const char nl
Definition: Ostream.H:262
defineTypeNameAndDebug(combustionModel, 0)
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:237
virtual ~cellSizeAndAlignmentControls()
Destructor.
vector point
Point is a vector.
Definition: point.H:41
messageStream Info
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:230
static const label labelMin
Definition: label.H:61
Namespace for OpenFOAM.