midPointAndFaceSet.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) 2011-2016 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 "midPointAndFaceSet.H"
27 #include "polyMesh.H"
29 
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(midPointAndFaceSet, 0);
36  addToRunTimeSelectionTable(sampledSet, midPointAndFaceSet, word);
37 }
38 
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 void Foam::midPointAndFaceSet::genSamples()
43 {
44  // Generate midpoints and add to face points
45 
46  List<point> mpfSamplePoints(3*size());
47  labelList mpfSampleCells(3*size());
48  labelList mpfSampleFaces(3*size());
49  labelList mpfSampleSegments(3*size());
50  scalarList mpfSampleCurveDist(3*size());
51 
52  label mpfSamplei = 0;
53  label samplei = 0;
54 
55  while (size() > 0)
56  {
57  // Add first face
58  mpfSamplePoints[mpfSamplei] = operator[](samplei);
59  mpfSampleCells[mpfSamplei] = cells_[samplei];
60  mpfSampleFaces[mpfSamplei] = faces_[samplei];
61  mpfSampleSegments[mpfSamplei] = segments_[samplei];
62  mpfSampleCurveDist[mpfSamplei] = curveDist_[samplei];
63  mpfSamplei++;
64 
65  while
66  (
67  (samplei < size() - 1)
68  && (segments_[samplei] == segments_[samplei+1])
69  )
70  {
71  point midPoint(0.5*(operator[](samplei) + operator[](samplei+1)));
72  label cellm = pointInCell(midPoint, samplei);
73 
74  if (cellm != -1)
75  {
76  mpfSamplePoints[mpfSamplei] = midPoint;
77  mpfSampleCells[mpfSamplei] = cellm;
78  mpfSampleFaces[mpfSamplei] = -1;
79  mpfSampleSegments[mpfSamplei] = segments_[samplei];
80  mpfSampleCurveDist[mpfSamplei] =
81  mag(mpfSamplePoints[mpfSamplei] - start());
82 
83  mpfSamplei++;
84  }
85 
86  // Add second face
87  mpfSamplePoints[mpfSamplei] = operator[](samplei+1);
88  mpfSampleCells[mpfSamplei] = cells_[samplei+1];
89  mpfSampleFaces[mpfSamplei] = faces_[samplei+1];
90  mpfSampleSegments[mpfSamplei] = segments_[samplei+1];
91  mpfSampleCurveDist[mpfSamplei] =
92  mag(mpfSamplePoints[mpfSamplei] - start());
93 
94  mpfSamplei++;
95 
96  samplei++;
97  }
98 
99  if (samplei == size() - 1)
100  {
101  break;
102  }
103  samplei++;
104  }
105 
106  mpfSamplePoints.setSize(mpfSamplei);
107  mpfSampleCells.setSize(mpfSamplei);
108  mpfSampleFaces.setSize(mpfSamplei);
109  mpfSampleSegments.setSize(mpfSamplei);
110  mpfSampleCurveDist.setSize(mpfSamplei);
111 
112  setSamples
113  (
114  mpfSamplePoints,
115  mpfSampleCells,
116  mpfSampleFaces,
117  mpfSampleSegments,
118  mpfSampleCurveDist
119  );
120 }
121 
122 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 
125 (
126  const word& name,
127  const polyMesh& mesh,
128  const meshSearch& searchEngine,
129  const word& axis,
130  const point& start,
131  const point& end
132 )
133 :
134  faceOnlySet(name, mesh, searchEngine, axis, start, end)
135 {
136  genSamples();
137 
138  if (debug)
139  {
140  write(Info);
141  }
142 }
143 
144 
146 (
147  const word& name,
148  const polyMesh& mesh,
149  const meshSearch& searchEngine,
150  const dictionary& dict
151 )
152 :
153  faceOnlySet(name, mesh, searchEngine, dict)
154 {
155  genSamples();
156 
157  if (debug)
158  {
159  write(Info);
160  }
161 }
162 
163 
164 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
165 
167 {}
168 
169 
170 // ************************************************************************* //
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
Macros for easy insertion into run-time selection tables.
void write(Ostream &, const label, const dictionary &)
Write with dictionary lookup.
virtual ~midPointAndFaceSet()
Destructor.
A class for handling words, derived from string.
Definition: word.H:59
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:50
List< label > labelList
A List of labels.
Definition: labelList.H:56
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
defineTypeNameAndDebug(combustionModel, 0)
vector point
Point is a vector.
Definition: point.H:41
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
midPointAndFaceSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis, const point &start, const point &end)
Construct from components.
Namespace for OpenFOAM.