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