midPointSet.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 "midPointSet.H"
29#include "polyMesh.H"
30#include "meshSearch.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
39}
40
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
44void Foam::midPointSet::genSamples()
45{
46 // Generate midpoints.
47
48 List<point> midPoints(2*size());
49 labelList midCells(2*size());
50 labelList midSegments(2*size());
51 scalarList midCurveDist(2*size());
52
53 label mSamplei = 0;
54 label samplei = 0;
55
56 while (size() > 0)
57 {
58 // Calculate midpoint between samplei and samplei+1 (if in same segment)
59 while
60 (
61 (samplei < size() - 1)
62 && (segments_[samplei] == segments_[samplei+1])
63 )
64 {
65 point midPoint(0.5*(operator[](samplei) + operator[](samplei+1)));
66 label cellm = pointInCell(midPoint, samplei);
67
68 if (cellm != -1)
69 {
70 midPoints[mSamplei] = midPoint;
71 midCells[mSamplei] = cellm;
72 midSegments[mSamplei] = segments_[samplei];
73 midCurveDist[mSamplei] = mag(midPoints[mSamplei] - start());
74 ++mSamplei;
75 }
76
77 ++samplei;
78 }
79
80 if (samplei == size() - 1)
81 {
82 break;
83 }
84
85 ++samplei;
86 }
87
88 midPoints.setSize(mSamplei);
89 midCells.setSize(mSamplei);
90 midSegments.setSize(mSamplei);
91 midCurveDist.setSize(mSamplei);
92
93 labelList midFaces(midCells.size(), -1);
94
95 // Move into *this
97 (
98 std::move(midPoints),
99 std::move(midCells),
100 std::move(midFaces),
101 std::move(midSegments),
102 std::move(midCurveDist)
103 );
104
105 if (debug)
106 {
107 write(Info);
108 }
109}
110
111
112// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
113
115(
116 const word& name,
117 const polyMesh& mesh,
118 const meshSearch& searchEngine,
119 const word& axis,
120 const point& start,
121 const point& end
122)
123:
124 faceOnlySet(name, mesh, searchEngine, axis, start, end)
125{
126 genSamples();
127}
128
129
131(
132 const word& name,
133 const polyMesh& mesh,
134 const meshSearch& searchEngine,
135 const dictionary& dict
136)
137:
138 faceOnlySet(name, mesh, searchEngine, dict)
139{
140 genSamples();
141}
142
143
144// ************************************************************************* //
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
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
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
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