lineCell.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) 2011-2018 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 "lineCell.H"
27 #include "meshSearch.H"
28 #include "DynamicList.H"
29 #include "polyMesh.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace sampledSets
37 {
38  defineTypeNameAndDebug(lineCell, 0);
39  addToRunTimeSelectionTable(sampledSet, lineCell, word);
40 }
41 }
42 
43 
44 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
45 
47 (
48  const polyMesh& mesh,
49  const point& prevPt,
50  const label prevFace,
51  const label prevSegment,
52  const scalar prevCurveDist,
53  const point& nextPt,
54  const label nextFace,
55  const label nextSegment,
56  DynamicList<point>& samplingPts,
57  DynamicList<label>& samplingCells,
58  DynamicList<label>& samplingFaces,
59  DynamicList<label>& samplingSegments,
60  DynamicList<scalar>& samplingCurveDist
61 )
62 {
63  if (prevSegment == nextSegment)
64  {
65  const point pt = (prevPt + nextPt)/2;
66  const vector delta = nextPt - prevPt;
67 
68  const label prevOwner = mesh.faceOwner()[prevFace];
69  const label prevNeighbour =
70  prevFace < mesh.faceNeighbour().size()
71  ? mesh.faceNeighbour()[prevFace]
72  : -1;
73  const label nextOwner = mesh.faceOwner()[nextFace];
74  const label nextNeighbour =
75  nextFace < mesh.faceNeighbour().size()
76  ? mesh.faceNeighbour()[nextFace]
77  : -2;
78 
79  label celli = -1;
80  if (prevOwner == nextOwner || prevOwner == nextNeighbour)
81  {
82  celli = prevOwner;
83  }
84  else if (prevNeighbour == nextOwner || prevNeighbour == nextNeighbour)
85  {
86  celli = prevNeighbour;
87  }
88  else
89  {
91  << "Adjacent faces in the same segment do not share a cell. "
92  << "This is a bug." << exit(FatalError);
93  }
94 
95  samplingPts.append(pt);
96  samplingCells.append(celli);
97  samplingFaces.append(-1);
98  samplingCurveDist.append(prevCurveDist + mag(delta)/2);
99  samplingSegments.append(prevSegment);
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
105 
106 void Foam::sampledSets::lineCell::calcSamples
107 (
108  DynamicList<point>& samplingPts,
109  DynamicList<label>& samplingCells,
110  DynamicList<label>& samplingFaces,
111  DynamicList<label>& samplingSegments,
112  DynamicList<scalar>& samplingCurveDist
113 ) const
114 {
115  // Run the algorithm from lineFaceSet to get all the face intersections
116  DynamicList<point> facePts;
117  DynamicList<label> faceCells;
118  DynamicList<label> faceFaces;
119  DynamicList<label> faceSegments;
120  DynamicList<scalar> faceCurveDist;
121  lineFace::calcSamples
122  (
123  mesh(),
124  searchEngine(),
125  start_,
126  end_,
127  facePts,
128  faceCells,
129  faceFaces,
130  faceSegments,
131  faceCurveDist
132  );
133 
134  // Append all mid points to the set
135  for (label facei = 1; facei < facePts.size(); ++ facei)
136  {
137  calcMidPointSample
138  (
139  mesh(),
140  facePts[facei - 1],
141  faceFaces[facei - 1],
142  faceSegments[facei - 1],
143  faceCurveDist[facei - 1],
144  facePts[facei],
145  faceFaces[facei],
146  faceSegments[facei],
147  samplingPts,
148  samplingCells,
149  samplingFaces,
150  samplingSegments,
151  samplingCurveDist
152  );
153  }
154 }
155 
156 
157 void Foam::sampledSets::lineCell::genSamples()
158 {
159  DynamicList<point> samplingPts;
160  DynamicList<label> samplingCells;
161  DynamicList<label> samplingFaces;
162  DynamicList<label> samplingSegments;
163  DynamicList<scalar> samplingCurveDist;
164 
165  calcSamples
166  (
167  samplingPts,
168  samplingCells,
169  samplingFaces,
170  samplingSegments,
171  samplingCurveDist
172  );
173 
174  samplingPts.shrink();
175  samplingCells.shrink();
176  samplingFaces.shrink();
177  samplingSegments.shrink();
178  samplingCurveDist.shrink();
179 
180  setSamples
181  (
182  samplingPts,
183  samplingCells,
184  samplingFaces,
185  samplingSegments,
186  samplingCurveDist
187  );
188 }
189 
190 
191 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
192 
194 (
195  const word& name,
196  const polyMesh& mesh,
197  const meshSearch& searchEngine,
198  const dictionary& dict
199 )
200 :
201  sampledSet(name, mesh, searchEngine, dict),
202  start_(dict.lookup("start")),
203  end_(dict.lookup("end"))
204 {
205  genSamples();
206 
207  if (debug)
208  {
209  write(Info);
210  }
211 }
212 
213 
214 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
215 
217 {}
218 
219 
220 // ************************************************************************* //
scalar delta
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search...
Definition: meshSearch.H:57
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1047
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Macros for easy insertion into run-time selection tables.
dynamicFvMesh & mesh
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:61
A class for handling words, derived from string.
Definition: word.H:59
lineCell(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const dictionary &dict)
Construct from dictionary.
Definition: lineCell.C:194
static void calcMidPointSample(const polyMesh &mesh, const point &prevPt, const label prevFace, const label prevSegment, const scalar prevCurveDist, const point &nextPt, const label nextFace, const label nextSegment, DynamicList< point > &samplingPts, DynamicList< label > &samplingCells, DynamicList< label > &samplingFaces, DynamicList< label > &samplingSegments, DynamicList< scalar > &samplingCurveDist)
Calculate the next mid point sample.
Definition: lineCell.C:47
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1041
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:292
virtual ~lineCell()
Destructor.
Definition: lineCell.C:216
addToRunTimeSelectionTable(sampledSet, arcUniform, word)
DynamicList< T, SizeInc, SizeMult, SizeDiv > & shrink()
Shrink the allocated space to the number of elements used.
Definition: DynamicListI.H:240
virtual bool write()
Sample and write.
Definition: sampledSets.C:241
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
defineTypeNameAndDebug(arcUniform, 0)
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576