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 -------------------------------------------------------------------------------
10 License
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 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(midPointSet, 0);
38  addToRunTimeSelectionTable(sampledSet, midPointSet, word);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void 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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::scalarList
List< scalar > scalarList
A List of scalars.
Definition: scalarList.H:64
Foam::sampledSet::write
Ostream & write(Ostream &) const
Output for debugging.
Definition: sampledSet.C:554
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:60
Foam::faceOnlySet::start
const point & start() const
Definition: faceOnlySet.H:173
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
midPointSet.H
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::faceOnlySet
Sample on faces along a specified path.
Definition: faceOnlySet.H:86
Foam::sampledSet::segments_
labelList segments_
Segment numbers.
Definition: sampledSet.H:99
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
meshSearch.H
Foam::sampledSet::setSamples
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingCurveDist)
Set sample data. Copy list contents.
Definition: sampledSet.C:382
Foam::Vector< scalar >
Foam::midPointSet::midPointSet
midPointSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis, const point &start, const point &end)
Construct from components.
Definition: midPointSet.C:115
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::point
vector point
Point is a vector.
Definition: point.H:43
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::sampledSet::pointInCell
label pointInCell(const point &p, const label samplei) const
Return the cell in which the point on the sample line.
Definition: sampledSet.C:90