FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/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 
41 // Rework faceOnlySet samples.
42 // Take two consecutive samples
43 void Foam::midPointSet::genSamples()
44 {
45  // Generate midpoints.
46 
47  List<point> midPoints(2*size());
48  labelList midCells(2*size());
49  labelList midSegments(2*size());
50  scalarList midCurveDist(2*size());
51 
52  label midI = 0;
53 
54  label sampleI = 0;
55 
56  while(true && 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  midPoints[midI] =
66  0.5*(operator[](sampleI) + operator[](sampleI+1));
67 
68  label cell1 = getCell(faces_[sampleI], midPoints[midI]);
69  label cell2 = getCell(faces_[sampleI+1], midPoints[midI]);
70 
71  if (cell1 != cell2)
72  {
73  FatalErrorIn("midPointSet::genSamples()")
74  << " sampleI:" << sampleI
75  << " midI:" << midI
76  << " sampleI:" << sampleI
77  << " pts[sampleI]:" << operator[](sampleI)
78  << " face[sampleI]:" << faces_[sampleI]
79  << " pts[sampleI+1]:" << operator[](sampleI+1)
80  << " face[sampleI+1]:" << faces_[sampleI+1]
81  << " cell1:" << cell1
82  << " cell2:" << cell2
83  << abort(FatalError);
84  }
85 
86  midCells[midI] = cell1;
87  midSegments[midI] = segments_[sampleI];
88  midCurveDist[midI] = mag(midPoints[midI] - start());
89 
90  midI++;
91  sampleI++;
92  }
93 
94  if (sampleI == size() - 1)
95  {
96  break;
97  }
98  sampleI++;
99  }
100 
101  midPoints.setSize(midI);
102  midCells.setSize(midI);
103  midSegments.setSize(midI);
104  midCurveDist.setSize(midI);
105  setSamples
106  (
107  midPoints,
108  midCells,
109  labelList(midCells.size(), -1),
110  midSegments,
111  midCurveDist
112  );
113 }
114 
115 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
116 
118 (
119  const word& name,
120  const polyMesh& mesh,
121  meshSearch& searchEngine,
122  const word& axis,
123  const point& start,
124  const point& end
125 )
126 :
127  faceOnlySet(name, mesh, searchEngine, axis, start, end)
128 {
129  genSamples();
130 
131  if (debug)
132  {
133  write(Info);
134  }
135 }
136 
137 
139 (
140  const word& name,
141  const polyMesh& mesh,
142  meshSearch& searchEngine,
143  const dictionary& dict
144 )
145 :
146  faceOnlySet(name, mesh, searchEngine, dict)
147 {
148  genSamples();
149 
150  if (debug)
151  {
152  write(Info);
153  }
154 }
155 
156 
157 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
158 
160 {}
161 
162 
163 // ************************ vim: set sw=4 sts=4 et: ************************ //