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-2015 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"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(midPointSet, 0);
35  addToRunTimeSelectionTable(sampledSet, midPointSet, word);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
42 {
43  // Generate midpoints.
44 
45  List<point> midPoints(2*size());
46  labelList midCells(2*size());
47  labelList midSegments(2*size());
48  scalarList midCurveDist(2*size());
49 
50  label midI = 0;
51 
52  label sampleI = 0;
53 
54  while(true && 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  midPoints[midI] =
64  0.5*(operator[](sampleI) + operator[](sampleI+1));
65 
66  label cell1 = getCell(faces_[sampleI], midPoints[midI]);
67  label cell2 = getCell(faces_[sampleI+1], midPoints[midI]);
68 
69  if (cell1 != cell2)
70  {
72  << " midI:" << midI
73  << " sampleI:" << sampleI
74  << " pts[sampleI]:" << operator[](sampleI)
75  << " face[sampleI]:" << faces_[sampleI]
76  << " pts[sampleI+1]:" << operator[](sampleI+1)
77  << " face[sampleI+1]:" << faces_[sampleI+1]
78  << " cell1:" << cell1
79  << " cell2:" << cell2
80  << abort(FatalError);
81  }
82 
83  midCells[midI] = cell1;
84  midSegments[midI] = segments_[sampleI];
85  midCurveDist[midI] = mag(midPoints[midI] - start());
86 
87  midI++;
88  sampleI++;
89  }
90 
91  if (sampleI == size() - 1)
92  {
93  break;
94  }
95  sampleI++;
96  }
97 
98  midPoints.setSize(midI);
99  midCells.setSize(midI);
100  midSegments.setSize(midI);
101  midCurveDist.setSize(midI);
102  setSamples
103  (
104  midPoints,
105  midCells,
106  labelList(midCells.size(), -1),
107  midSegments,
108  midCurveDist
109  );
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
114 
116 (
117  const word& name,
118  const polyMesh& mesh,
119  const meshSearch& searchEngine,
120  const word& axis,
121  const point& start,
122  const point& end
123 )
124 :
125  faceOnlySet(name, mesh, searchEngine, axis, start, end)
126 {
127  genSamples();
128 
129  if (debug)
130  {
131  write(Info);
132  }
133 }
134 
135 
137 (
138  const word& name,
139  const polyMesh& mesh,
140  const meshSearch& searchEngine,
141  const dictionary& dict
142 )
143 :
144  faceOnlySet(name, mesh, searchEngine, dict)
145 {
146  genSamples();
147 
148  if (debug)
149  {
150  write(Info);
151  }
152 }
153 
154 
155 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
156 
158 {}
159 
160 
161 // ************************************************************************* //
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::sampledSet::getCell
label getCell(const label faceI, const point &sample) const
Returns cell using face and containing sample.
Definition: sampledSet.C:53
Foam::meshSearch
Various (local, not parallel) searches on polyMesh; uses (demand driven) octree to search.
Definition: meshSearch.H:57
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::midPointSet::~midPointSet
virtual ~midPointSet()
Destructor.
Definition: midPointSet.C:157
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(ensightPart, ensightPartCells, istream)
Foam::faceOnlySet::start
const point & start() const
Definition: faceOnlySet.H:127
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
midPointSet.H
Foam::label
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
Foam::Info
messageStream Info
Foam::faceOnlySet
Definition: faceOnlySet.H:49
Foam::sampledSet::segments_
labelList segments_
Segment numbers.
Definition: sampledSet.H:80
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::List::setSize
void setSize(const label)
Reset size of List.
Foam::midPointSet::genSamples
void genSamples()
Definition: midPointSet.C:41
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::sampledSet::setSamples
void setSamples(const List< point > &samplingPts, const labelList &samplingCells, const labelList &samplingFaces, const labelList &samplingSegments, const scalarList &samplingCurveDist)
Sets sample data.
Definition: sampledSet.C:351
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
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:116
Foam::sampledSet::faces_
labelList faces_
Face numbers (-1 if not known)
Definition: sampledSet.H:86
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
write
Tcoeff write()
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47