FreeFOAM The Cross-Platform CFD Toolkit
referredCell.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) 2008-2010 OpenCFD Ltd.
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 "referredCell.H"
28 
29 namespace Foam
30 {
31 
32 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33 
34 void referredCell::setConstructionData
35 (
36  const polyMesh& mesh,
37  const label sourceCell
38 )
39 {
40  // Points
41 
42  const labelList& points = mesh.cellPoints()[sourceCell];
43 
44  vectorList sourceCellVertices(points.size());
45 
46  forAll(sourceCellVertices, sCV)
47  {
48  sourceCellVertices[sCV] = mesh.points()[points[sCV]];
49  }
50 
51  vertexPositions_ = referPositions(sourceCellVertices);
52 
53 
54  // Edges
55 
56  const labelList& edges = mesh.cellEdges()[sourceCell];
57 
58  edgeList sourceCellEdges(edges.size());
59 
60  forAll(sourceCellEdges, sCE)
61  {
62  sourceCellEdges[sCE] = mesh.edges()[edges[sCE]];
63  }
64 
65  locallyMapEdgeList(points, sourceCellEdges);
66 
67 
68  // Faces
69 
70  labelList faces(mesh.cells()[sourceCell]);
71 
72  vectorList sourceCellFaceCentres(faces.size());
73 
74  vectorList sourceCellFaceAreas(faces.size());
75 
76  labelListList sourceCellFaces(faces.size());
77 
78  forAll(faces, f)
79  {
80  sourceCellFaces[f] = mesh.faces()[faces[f]];
81 
82  sourceCellFaceCentres[f] = mesh.faceCentres()[faces[f]];
83 
84  sourceCellFaceAreas[f] = mesh.faceAreas()[faces[f]];
85  }
86 
87  locallyMapFaceList(points, sourceCellFaces);
88 
89  faceCentres_ = referPositions(sourceCellFaceCentres);
90 
91  faceAreas_ = rotateVectors(sourceCellFaceAreas);
92 }
93 
94 
95 void referredCell::locallyMapEdgeList
96 (
97  const labelList& points,
98  const edgeList& sourceCellEdges
99 )
100 {
101  edges_.setSize(sourceCellEdges.size());
102 
103  forAll(sourceCellEdges, sCE)
104  {
105  const edge& e(sourceCellEdges[sCE]);
106 
107  edges_[sCE].start() = findIndex(points, e.start());
108 
109  edges_[sCE].end() = findIndex(points, e.end());
110 
111  if
112  (
113  edges_[sCE].start() == -1
114  || edges_[sCE].end() == -1
115  )
116  {
117  FatalErrorIn("Foam::referredCell::locallyMapEdgeList")
118  << "edgeList and points labelList for "
119  << "referred cell do not match: "
120  << nl << "points: " << points
121  << nl << "egdes: " << sourceCellEdges
122  << abort(FatalError);
123  }
124  }
125 }
126 
127 
128 void referredCell::locallyMapFaceList
129 (
130  const labelList& points,
131  const labelListList& sourceCellFaces
132 )
133 {
134  faces_.setSize(sourceCellFaces.size());
135 
136  forAll(sourceCellFaces, sCF)
137  {
138  const labelList& sourceCellFace(sourceCellFaces[sCF]);
139 
140  labelList& localFace(faces_[sCF]);
141 
142  localFace.setSize(sourceCellFace.size());
143 
144  forAll(sourceCellFace, p)
145  {
146  localFace[p] = findIndex(points, sourceCellFace[p]);
147 
148  if (localFace[p] == -1)
149  {
150  FatalErrorIn("Foam::referredCell::locallyMapEdgeList")
151  << "edgeList and points labelList for "
152  << "referred cell do not match: "
153  << nl << "points: " << points
154  << nl << "faces: " << sourceCellFaces
155  << abort(FatalError);
156  }
157  }
158  }
159 }
160 
161 
162 vector referredCell::referPosition(const vector& positionToRefer)
163 {
164  return offset_ + (rotation_ & positionToRefer);
165 }
166 
167 
168 vectorList referredCell::referPositions(const vectorList& positionsToRefer)
169 {
170  return offset_ + (rotation_ & positionsToRefer);
171 }
172 
173 
174 vector referredCell::rotateVector(const vector& vectorToRotate)
175 {
176  return rotation_ & vectorToRotate;
177 }
178 
179 
180 vectorList referredCell::rotateVectors(const vectorList& vectorsToRotate)
181 {
182  return rotation_ & vectorsToRotate;
183 }
184 
185 
186 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
187 
189 :
191  sourceProc_(-1),
192  sourceCell_(-1),
193  vertexPositions_(),
194  offset_(vector::zero),
195  rotation_(I)
196 {}
197 
198 
200 (
201  const polyMesh& mesh,
202  const label sourceProc,
203  const label sourceCell,
204  const vector& offset,
205  const tensor& rotation
206 )
207 :
209  sourceProc_(sourceProc),
210  sourceCell_(sourceCell),
211  offset_(offset),
212  rotation_(rotation)
213 {
214  setConstructionData(mesh, sourceCell);
215 }
216 
217 
219 (
220  const label sourceProc,
221  const label sourceCell,
222  const vectorList& vertexPositions,
223  const edgeList& localEdges,
224  const labelListList& localFaces,
225  const vectorList& faceCentres,
226  const vectorList& faceAreas,
227  const vector& offset,
228  const tensor& rotation
229 )
230 :
232  sourceProc_(sourceProc),
233  sourceCell_(sourceCell),
234  edges_(localEdges),
235  faces_(localFaces),
236  offset_(offset),
237  rotation_(rotation)
238 {
239  // Supplied vertexPositions, faceCentres and faceAreas are of the
240  // "original" cell, and need to be transformed to the referred
241  // locations on construction
242 
243  vertexPositions_ = referPositions(vertexPositions);
244 
245  faceCentres_ = referPositions(faceCentres);
246 
247  faceAreas_ = rotateVectors(faceAreas);
248 }
249 
250 
252 (
253  const polyMesh& mesh,
254  const label sourceProc,
255  const label sourceCell,
256  const vector& cS,
257  const vector& cD,
258  const vector& nS,
259  const vector& nD
260 )
261 :
263  sourceProc_(sourceProc),
264  sourceCell_(sourceCell)
265 {
266  // It is assumed that the vectors originating from the faces being referred
267  // here are correct periodic faces - i.e. they have the same area etc.
268 
269  vector nA = -nS/mag(nS);
270  vector nB = nD/mag(nD);
271 
272  rotation_ = rotationTensor(nA, nB);
273 
274  offset_ = cD - (rotation_ & cS);
275 
276  // Allow sourceCell = -1 to create a dummy referredCell
277  // to obtain the transformation
278 
279  if(sourceCell >= 0)
280  {
281  setConstructionData(mesh, sourceCell);
282  }
283 }
284 
285 
286 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
287 
289 {}
290 
291 
292 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
293 
295 (
296  const vector& cS,
297  const vector& cD,
298  const vector& nS,
299  const vector& nD
300 )
301 {
302  vector nA = -nS/mag(nS);
303  vector nB = nD/mag(nD);
304 
305  tensor newRotation = rotationTensor(nA, nB);
306 
307  vector newOffset = cD - (newRotation & cS);
308 
309  tensor reReferredRotation = newRotation & rotation_;
310 
311  vector reReferredOffset = newOffset + (newRotation & offset_);
312 
313  return referredCell
314  (
315  sourceProc_,
316  sourceCell_,
317  rotation_.T() & (vertexPositions_ - offset_),
318  edges_,
319  faces_,
320  rotation_.T() & (faceCentres_ - offset_),
321  rotation_.T() & (faceAreas_),
322  reReferredOffset,
323  reReferredRotation
324  );
325 }
326 
327 
328 vector referredCell::referPosition(const vector& positionToRefer) const
329 {
330  return offset_ + (rotation_ & positionToRefer);
331 }
332 
333 
334 vectorList referredCell::referPosition
335 (
336  const vectorList& positionsToRefer
337 ) const
338 {
339  return offset_ + (rotation_ & positionsToRefer);
340 }
341 
342 
343 vector referredCell::rotateVector(const vector& vectorToRotate) const
344 {
345  return rotation_ & vectorToRotate;
346 }
347 
348 
349 vectorList referredCell::rotateVectors(const vectorList& vectorsToRotate) const
350 {
351  return rotation_ & vectorsToRotate;
352 }
353 
354 
356 {
357  clear();
358 
359  forAll(incomingMols, iM)
360  {
361  append
362  (
364  (
365  incomingMols[iM].id(),
366  referPosition
367  (
368  incomingMols[iM].position()
369  ),
370  referPosition
371  (
372  incomingMols[iM].sitePositions()
373  )
374  )
375  );
376  }
377 
378  shrink();
379 }
380 
381 
382 bool referredCell::duplicate(const referredCell& refCellDupl) const
383 {
384  return
385  (
386  sourceProc_ == refCellDupl.sourceProc()
387  && sourceCell_ == refCellDupl.sourceCell()
388  && mag(offset_ - refCellDupl.offset()) < interactionLists::transTol
389  );
390 }
391 
392 
393 bool referredCell::duplicate(const label procNo,const label nCells) const
394 {
395  return
396  (
397  sourceProc_ == procNo
398  && sourceCell_ < nCells
399  && mag(offset_) < interactionLists::transTol
400  );
401 }
402 
403 
404 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
405 
407 {
408 
409  is >> rC.sourceProc_
410  >> rC.sourceCell_
411  >> rC.vertexPositions_
412  >> rC.edges_
413  >> rC.faces_
414  >> rC.faceCentres_
415  >> rC.faceAreas_
416  >> rC.offset_
417  >> rC.rotation_;
418 
419  is.check("Istream& operator<<(Istream& f, const referredCell& rC");
420 
421  return is;
422 }
423 
424 
426 {
427 
428  os << rC.sourceProc()
429  << token::SPACE << rC.sourceCell()
430  << token::SPACE << rC.vertexPositions()
431  << token::SPACE << rC.edges()
432  << token::SPACE << rC.faces()
433  << token::SPACE << rC.faceCentres()
434  << token::SPACE << rC.faceAreas()
435  << token::SPACE << rC.offset()
436  << token::SPACE << rC.rotation();
437 
438  os.check("Ostream& operator<<(Ostream& f, const referredCell& rC");
439 
440  return os;
441 }
442 
443 
444 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
445 
446 } // End namespace Foam
447 
448 // ************************ vim: set sw=4 sts=4 et: ************************ //