cellShapeControl.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2019 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 "cellShapeControl.H"
27 #include "pointField.H"
28 #include "scalarField.H"
29 #include "triadField.H"
32 #include "cellSizeFunction.H"
33 #include "indexedVertexOps.H"
34 
35 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39  defineTypeNameAndDebug(cellShapeControl, 0);
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
46 (
47  const Time& runTime,
48  const cvControls& foamyHexMeshControls,
49  const searchableSurfaces& allGeometry,
50  const conformationSurfaces& geometryToConformTo
51 )
52 :
53  dictionary
54  (
55  foamyHexMeshControls.foamyHexMeshDict().subDict("motionControl")
56  ),
57  geometryToConformTo_(geometryToConformTo),
58  defaultCellSize_(foamyHexMeshControls.defaultCellSize()),
59  minimumCellSize_(foamyHexMeshControls.minimumCellSize()),
60  shapeControlMesh_(runTime),
61  aspectRatio_(*this),
62  sizeAndAlignment_
63  (
64  runTime,
65  subDict("shapeControlFunctions"),
66  geometryToConformTo_,
67  defaultCellSize_
68  )
69 {}
70 
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
75 {}
76 
77 
78 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
79 
81 (
82  const pointField& pts
83 ) const
84 {
85  scalarField cellSizes(pts.size());
86 
87  forAll(pts, i)
88  {
89  cellSizes[i] = cellSize(pts[i]);
90  }
91 
92  return cellSizes;
93 }
94 
95 
96 Foam::scalar Foam::cellShapeControl::cellSize(const point& pt) const
97 {
98  barycentric bary;
100 
101  shapeControlMesh_.barycentricCoords(pt, bary, ch);
102 
103  scalar size = 0;
104 
105  if (shapeControlMesh_.dimension() < 3)
106  {
107  size = sizeAndAlignment_.cellSize(pt);
108  }
109  else if (shapeControlMesh_.is_infinite(ch))
110  {
111 // if (nFarPoints != 0)
112 // {
113 // for (label pI = 0; pI < 4; ++pI)
114 // {
115 // if (!ch->vertex(pI)->farPoint())
116 // {
117 // size = ch->vertex(pI)->targetCellSize();
118 // return size;
119 // }
120 // }
121 // }
122 
123 // cellShapeControlMesh::Vertex_handle nearV =
124 // shapeControlMesh_.nearest_vertex_in_cell
125 // (
126 // toPoint<cellShapeControlMesh::Point>(pt),
127 // ch
128 // );
129 //
130 // size = nearV->targetCellSize();
131 
132  // Find nearest surface. This can be quite slow if there are a lot of
133  // surfaces
134  size = sizeAndAlignment_.cellSize(pt);
135  }
136  else
137  {
138  label nFarPoints = 0;
139  for (label pI = 0; pI < 4; ++pI)
140  {
141  if (ch->vertex(pI)->farPoint())
142  {
143  nFarPoints++;
144  }
145  }
146 
147  if (nFarPoints != 0)
148  {
149  for (label pI = 0; pI < 4; ++pI)
150  {
151  if (!CGAL::indexedVertexOps::uninitialised(ch->vertex(pI)))
152  {
153  size = ch->vertex(pI)->targetCellSize();
154  return size;
155  }
156  }
157  }
158  else
159  {
160  forAll(bary, pI)
161  {
162  size += bary[pI]*ch->vertex(pI)->targetCellSize();
163  }
164  }
165  }
166 
167  return size;
168 }
169 
170 
172 {
173  barycentric bary;
175 
176  shapeControlMesh_.barycentricCoords(pt, bary, ch);
177 
178  tensor alignment = Zero;
179 
180  if (shapeControlMesh_.dimension() < 3 || shapeControlMesh_.is_infinite(ch))
181  {
182  alignment = tensor::I;
183  }
184  else
185  {
186  label nFarPoints = 0;
187  for (label pI = 0; pI < 4; ++pI)
188  {
189  if (ch->vertex(pI)->farPoint())
190  {
191  nFarPoints++;
192  }
193  }
194 
195 // if (nFarPoints != 0)
196 // {
197 // for (label pI = 0; pI < 4; ++pI)
198 // {
199 // if (!ch->vertex(pI)->farPoint())
200 // {
201 // alignment = ch->vertex(pI)->alignment();
202 // }
203 // }
204 // }
205 // else
206  {
207  triad tri;
208 
209  for (label pI = 0; pI < 4; ++pI)
210  {
211  if (bary[pI] > small)
212  {
213  tri += triad(bary[pI]*ch->vertex(pI)->alignment());
214  }
215  }
216 
217  tri.normalize();
218  tri.orthogonalize();
219  tri = tri.sortxyz();
220 
221  alignment = tri;
222  }
223 
224 // cellShapeControlMesh::Vertex_handle nearV =
225 // shapeControlMesh_.nearest_vertex_in_cell
226 // (
227 // toPoint<cellShapeControlMesh::Point>(pt),
228 // ch
229 // );
230 //
231 // alignment = nearV->alignment();
232  }
233 
234  return alignment;
235 }
236 
237 
239 (
240  const point& pt,
241  scalar& size,
242  tensor& alignment
243 ) const
244 {
245  barycentric bary;
247 
248  shapeControlMesh_.barycentricCoords(pt, bary, ch);
249 
250  alignment = Zero;
251  size = 0;
252 
253  if (shapeControlMesh_.dimension() < 3 || shapeControlMesh_.is_infinite(ch))
254  {
255  // Find nearest surface
256  size = sizeAndAlignment_.cellSize(pt);
257  alignment = tensor::I;
258  }
259  else
260  {
261  label nFarPoints = 0;
262  for (label pI = 0; pI < 4; ++pI)
263  {
264  if (ch->vertex(pI)->farPoint())
265  {
266  nFarPoints++;
267  }
268  }
269 
270  if (nFarPoints != 0)
271  {
272  for (label pI = 0; pI < 4; ++pI)
273  {
274  if (!CGAL::indexedVertexOps::uninitialised(ch->vertex(pI)))
275  {
276  size = ch->vertex(pI)->targetCellSize();
277  alignment = ch->vertex(pI)->alignment();
278  }
279  }
280  }
281  else
282  {
283  triad tri;
284 
285  for (label pI = 0; pI < 4; ++pI)
286  {
287  size += bary[pI]*ch->vertex(pI)->targetCellSize();
288 
289  if (bary[pI] > small)
290  {
291  tri += triad(bary[pI]*ch->vertex(pI)->alignment());
292  }
293  }
294 
295  tri.normalize();
296  tri.orthogonalize();
297  tri = tri.sortxyz();
298 
299  alignment = tri;
300 
301 // cellShapeControlMesh::Vertex_handle nearV =
302 // shapeControlMesh_.nearest_vertex
303 // (
304 // toPoint<cellShapeControlMesh::Point>(pt)
305 // );
306 //
307 // alignment = nearV->alignment();
308  }
309  }
310 
311  for (label dir = 0; dir < 3; dir++)
312  {
313  triad v = alignment;
314 
315  if (!v.set(dir) || size == 0)
316  {
317  // Force orthogonalization of triad.
318 
319  scalar dotProd = great;
320  if (dir == 0)
321  {
322  dotProd = v[1] & v[2];
323 
324  v[dir] = v[1] ^ v[2];
325  }
326  if (dir == 1)
327  {
328  dotProd = v[0] & v[2];
329 
330  v[dir] = v[0] ^ v[2];
331  }
332  if (dir == 2)
333  {
334  dotProd = v[0] & v[1];
335 
336  v[dir] = v[0] ^ v[1];
337  }
338 
339  v.normalize();
340  v.orthogonalize();
341 
342  Pout<< "Dot prod = " << dotProd << endl;
343  Pout<< "Alignment = " << v << endl;
344 
345  alignment = v;
346 
347 // FatalErrorInFunction
348 // << "Point has bad alignment! "
349 // << pt << " " << size << " " << alignment << nl
350 // << "Bary Coords = " << bary << nl
351 // << ch->vertex(0)->info() << nl
352 // << ch->vertex(1)->info() << nl
353 // << ch->vertex(2)->info() << nl
354 // << ch->vertex(3)->info()
355 // << abort(FatalError);
356  }
357  }
358 }
359 
360 
361 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Barycentric< scalar > barycentric
A scalar version of the templated Barycentric.
Definition: barycentric.H:45
void cellSizeAndAlignment(const point &pt, scalar &size, tensor &alignment) const
tensor cellAlignment(const point &pt) const
Return the cell alignment at the given location.
~cellShapeControl()
Destructor.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
bool uninitialised(const VertexType &v)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
static const zero Zero
Definition: zero.H:97
static const Tensor I
Definition: Tensor.H:83
defineTypeNameAndDebug(combustionModel, 0)
CellSizeDelaunay::Cell_handle Cell_handle
vector point
Point is a vector.
Definition: point.H:41
cellShapeControl(const Time &runTime, const cvControls &foamyHexMeshControls, const searchableSurfaces &allGeometry, const conformationSurfaces &geometryToConformTo)
Construct from dictionary and references to conformalVoronoiMesh and.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
Tensor< scalar > tensor
Tensor of scalars.
Definition: tensor.H:51
Namespace for OpenFOAM.
scalar cellSize(const point &pt) const
Return the cell size at the given location.