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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
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 "midPointAndFaceSet.H"
29#include "polyMesh.H"
31
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
39}
40
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
44void Foam::midPointAndFaceSet::genSamples()
45{
46 // Generate midpoints and add to face points
47
48 List<point> mpfSamplePoints(3*size());
49 labelList mpfSampleCells(3*size());
50 labelList mpfSampleFaces(3*size());
51 labelList mpfSampleSegments(3*size());
52 scalarList mpfSampleCurveDist(3*size());
53
54 label mpfSamplei = 0;
55 label samplei = 0;
56
57 while (size() > 0)
58 {
59 // Add first face
60 mpfSamplePoints[mpfSamplei] = points()[samplei];
61 mpfSampleCells[mpfSamplei] = cells_[samplei];
62 mpfSampleFaces[mpfSamplei] = faces_[samplei];
63 mpfSampleSegments[mpfSamplei] = segments_[samplei];
64 mpfSampleCurveDist[mpfSamplei] = distance_[samplei];
65 ++mpfSamplei;
66
67 while
68 (
69 (samplei < size() - 1)
70 && (segments_[samplei] == segments_[samplei+1])
71 )
72 {
73 point midPoint(0.5*(points()[samplei] + points()[samplei+1]));
74 label cellm = pointInCell(midPoint, samplei);
75
76 if (cellm != -1)
77 {
78 mpfSamplePoints[mpfSamplei] = midPoint;
79 mpfSampleCells[mpfSamplei] = cellm;
80 mpfSampleFaces[mpfSamplei] = -1;
81 mpfSampleSegments[mpfSamplei] = segments_[samplei];
82 mpfSampleCurveDist[mpfSamplei] =
83 mag(mpfSamplePoints[mpfSamplei] - start());
84
85 ++mpfSamplei;
86 }
87
88 // Add second face
89 mpfSamplePoints[mpfSamplei] = operator[](samplei+1);
90 mpfSampleCells[mpfSamplei] = cells_[samplei+1];
91 mpfSampleFaces[mpfSamplei] = faces_[samplei+1];
92 mpfSampleSegments[mpfSamplei] = segments_[samplei+1];
93 mpfSampleCurveDist[mpfSamplei] =
94 mag(mpfSamplePoints[mpfSamplei] - start());
95
96 ++mpfSamplei;
97
98 ++samplei;
99 }
100
101 if (samplei == size() - 1)
102 {
103 break;
104 }
105 ++samplei;
106 }
107
108 mpfSamplePoints.setSize(mpfSamplei);
109 mpfSampleCells.setSize(mpfSamplei);
110 mpfSampleFaces.setSize(mpfSamplei);
111 mpfSampleSegments.setSize(mpfSamplei);
112 mpfSampleCurveDist.setSize(mpfSamplei);
113
114 // Move into *this
116 (
117 std::move(mpfSamplePoints),
118 std::move(mpfSampleCells),
119 std::move(mpfSampleFaces),
120 std::move(mpfSampleSegments),
121 std::move(mpfSampleCurveDist)
122 );
123
124 if (debug)
125 {
126 write(Info);
127 }
128}
129
130
131// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
132
134(
135 const word& name,
136 const polyMesh& mesh,
137 const meshSearch& searchEngine,
138 const word& axis,
139 const point& start,
140 const point& end
141)
142:
143 faceOnlySet(name, mesh, searchEngine, axis, start, end)
144{
145 genSamples();
146}
147
148
150(
151 const word& name,
152 const polyMesh& mesh,
153 const meshSearch& searchEngine,
154 const dictionary& dict
155)
156:
157 faceOnlySet(name, mesh, searchEngine, dict)
158{
159 genSamples();
160}
161
162
163// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
label size() const noexcept
The number of elements in the UList.
Definition: UListI.H:420
T & operator[](const label i)
Return element of UList.
Definition: UListI.H:299
scalarList distance_
Cumulative distance for "distance" write specifier.
Definition: coordSet.H:85
const pointField & points() const noexcept
Return the points.
Definition: coordSet.H:146
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
Sample on faces along a specified path.
Definition: faceOnlySet.H:89
const point & start() const
Definition: faceOnlySet.H:173
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:61
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:81
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:86
labelList faces_
Face numbers (-1 if not known)
Definition: sampledSet.H:107
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingDistance)
Set sample data. Copy list contents.
Definition: sampledSet.C:379
label pointInCell(const point &p, const label samplei) const
Return the cell in which the point on the sample line.
Definition: sampledSet.C:87
labelList segments_
Segment numbers.
Definition: sampledSet.H:101
labelList cells_
Cell numbers.
Definition: sampledSet.H:104
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
dynamicFvMesh & mesh
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
messageStream Info
Information stream (stdout output on master, null elsewhere)
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
vector point
Point is a vector.
Definition: point.H:43
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
runTime write()
dictionary dict