cloudSet.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  Copyright (C) 2016 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "cloudSet.H"
30 #include "sampledSet.H"
31 #include "meshSearch.H"
32 #include "DynamicList.H"
33 #include "polyMesh.H"
35 #include "word.H"
36 #include "DynamicField.H"
37 
38 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42  defineTypeNameAndDebug(cloudSet, 0);
43  addToRunTimeSelectionTable(sampledSet, cloudSet, word);
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
49 void Foam::cloudSet::calcSamples
50 (
51  DynamicList<point>& samplingPts,
52  DynamicList<label>& samplingCells,
53  DynamicList<label>& samplingFaces,
54  DynamicList<label>& samplingSegments,
55  DynamicList<scalar>& samplingCurveDist
56 ) const
57 {
58  const meshSearch& queryMesh = searchEngine();
59 
60  labelList foundProc(sampleCoords_.size(), -1);
61  forAll(sampleCoords_, sampleI)
62  {
63  label celli = queryMesh.findCell(sampleCoords_[sampleI]);
64 
65  if (celli != -1)
66  {
67  samplingPts.append(sampleCoords_[sampleI]);
68  samplingCells.append(celli);
69  samplingFaces.append(-1);
70  samplingSegments.append(0);
71  samplingCurveDist.append(1.0 * sampleI);
72 
73  foundProc[sampleI] = Pstream::myProcNo();
74  }
75  }
76 
77  // Check that all have been found
78  labelList maxFoundProc(foundProc);
79  Pstream::listCombineGather(maxFoundProc, maxEqOp<label>());
80  Pstream::listCombineScatter(maxFoundProc);
81 
82  labelList minFoundProc(foundProc.size(), labelMax);
83  forAll(foundProc, i)
84  {
85  if (foundProc[i] != -1)
86  {
87  minFoundProc[i] = foundProc[i];
88  }
89  }
90  Pstream::listCombineGather(minFoundProc, minEqOp<label>());
91  Pstream::listCombineScatter(minFoundProc);
92 
93 
94  DynamicField<point> missingPoints(sampleCoords_.size());
95 
96  forAll(sampleCoords_, sampleI)
97  {
98  if (maxFoundProc[sampleI] == -1)
99  {
100  // No processor has found the location.
101  missingPoints.append(sampleCoords_[sampleI]);
102  }
103  else if (minFoundProc[sampleI] != maxFoundProc[sampleI])
104  {
106  << "For sample set " << name()
107  << " location " << sampleCoords_[sampleI]
108  << " seems to be on multiple domains: "
109  << minFoundProc[sampleI] << " and " << maxFoundProc[sampleI]
110  << nl
111  << "This might happen if the location is on"
112  << " a processor patch. Change the location slightly"
113  << " to prevent this." << endl;
114  }
115  }
116 
117 
118  if (missingPoints.size() > 0)
119  {
120  if (missingPoints.size() < 100 || debug)
121  {
123  << "For sample set " << name()
124  << " did not found " << missingPoints.size()
125  << " points out of " << sampleCoords_.size()
126  << nl
127  << "Missing points:" << missingPoints << endl;
128  }
129  else
130  {
132  << "For sample set " << name()
133  << " did not found " << missingPoints.size()
134  << " points out of " << sampleCoords_.size()
135  << nl
136  << "Print missing points by setting the debug flag"
137  << " for " << cloudSet::typeName << endl;
138  }
139  }
140 }
141 
142 
143 void Foam::cloudSet::genSamples()
144 {
145  // Storage for sample points
146  DynamicList<point> samplingPts;
147  DynamicList<label> samplingCells;
148  DynamicList<label> samplingFaces;
149  DynamicList<label> samplingSegments;
150  DynamicList<scalar> samplingCurveDist;
151 
152  calcSamples
153  (
154  samplingPts,
155  samplingCells,
156  samplingFaces,
157  samplingSegments,
158  samplingCurveDist
159  );
160 
161  samplingPts.shrink();
162  samplingCells.shrink();
163  samplingFaces.shrink();
164  samplingSegments.shrink();
165  samplingCurveDist.shrink();
166 
167  // Move into *this
168  setSamples
169  (
170  std::move(samplingPts),
171  std::move(samplingCells),
172  std::move(samplingFaces),
173  std::move(samplingSegments),
174  std::move(samplingCurveDist)
175  );
176 
177  if (debug)
178  {
179  write(Info);
180  }
181 }
182 
183 
184 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
185 
187 (
188  const word& name,
189  const polyMesh& mesh,
190  const meshSearch& searchEngine,
191  const word& axis,
192  const List<point>& sampleCoords
193 )
194 :
195  sampledSet(name, mesh, searchEngine, axis),
196  sampleCoords_(sampleCoords)
197 {
198  genSamples();
199 }
200 
201 
203 (
204  const word& name,
205  const polyMesh& mesh,
206  const meshSearch& searchEngine,
207  const dictionary& dict
208 )
209 :
210  sampledSet(name, mesh, searchEngine, dict),
211  sampleCoords_(dict.get<pointField>("points"))
212 {
213  genSamples();
214 }
215 
216 
217 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::sampledSet
Holds list of sampling points which is filled at construction time. Various implementations of this b...
Definition: sampledSet.H:83
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::coordSet::name
const word & name() const
Definition: coordSet.H:125
Foam::labelMax
constexpr label labelMax
Definition: label.H:61
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::sampledSet::searchEngine
const meshSearch & searchEngine() const
Definition: sampledSet.H:286
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
sampledSet.H
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::cloudSet::cloudSet
cloudSet(const word &name, const polyMesh &mesh, const meshSearch &searchEngine, const word &axis, const List< point > &sampleCoords)
Construct from components.
Definition: cloudSet.C:187
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.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Pstream::listCombineGather
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
Definition: combineGatherScatter.C:290
DynamicField.H
meshSearch.H
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:463
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:36
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
DynamicList.H
word.H
Foam::Pstream::listCombineScatter
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
Definition: combineGatherScatter.C:432
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
cloudSet.H