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