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