Loading...
Searching...
No Matches
patchFieldProbe.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-2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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 "patchFieldProbe.H"
30#include "mappedPatchBase.H"
31#include "treeBoundBox.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
40}
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
45{
46 (void)mesh.tetBasePtIs();
47
48 const polyBoundaryMesh& bm = mesh.boundaryMesh();
49
50 // All the info for nearest. Construct to miss
52
54
55 label nFaces = 0;
57 {
58 nFaces += bm[patchIDs_[i]].size();
59 }
60
61 if (nFaces > 0)
62 {
63 // Collect mesh faces and bounding box
64 labelList bndFaces(nFaces);
65 treeBoundBox overallBb;
66
67 nFaces = 0;
69 {
70 const polyPatch& pp = bm[patchIDs_[i]];
71 forAll(pp, i)
72 {
73 bndFaces[nFaces++] = pp.start()+i;
74 const face& f = pp[i];
75
76 // Without reduction.
77 overallBb.add(pp.points(), f);
78 }
79 }
80
81 Random rndGen(123456);
82 overallBb.inflate(rndGen, 1e-4, ROOTVSMALL);
83
84
85 const indexedOctree<treeDataFace> boundaryTree
86 (
87 treeDataFace(mesh, bndFaces), // patch faces only
88
89 overallBb, // overall search domain
90 8, // maxLevel
91 10, // leafsize
92 3.0 // duplicity
93 );
94
95 forAll(probeLocations(), probei)
96 {
97 const auto& treeData = boundaryTree.shapes();
98 const point sample = probeLocations()[probei];
99
100 pointIndexHit info = boundaryTree.findNearest
101 (
102 sample,
103 Foam::sqr(boundaryTree.bb().mag())
104 );
105
106 if (!info.hit())
107 {
108 info = boundaryTree.findNearest(sample, Foam::sqr(GREAT));
109 }
110
111 const label facei = treeData.objectIndex(info.index());
112
113 const label patchi = bm.whichPatch(facei);
114
115 if (isA<emptyPolyPatch>(bm[patchi]))
116 {
118 << " The sample point: " << sample
119 << " belongs to " << patchi
120 << " which is an empty patch. This is not permitted. "
121 << " This sample will not be included "
122 << endl;
123 }
124 else if (info.hit())
125 {
126 // Note: do we store the face centre or the actual nearest?
127 // We interpolate using the faceI only though (no
128 // interpolation) so it does not actually matter much, just for
129 // the location written to the header.
130
131 //const point& facePt = mesh.faceCentres()[faceI];
132 const point& facePt = info.point();
133
134 mappedPatchBase::nearInfo sampleInfo;
135
136 sampleInfo.first() = pointIndexHit(true, facePt, facei);
137
138 sampleInfo.second().first() = facePt.distSqr(sample);
139 sampleInfo.second().second() = Pstream::myProcNo();
140
141 nearest[probei] = sampleInfo;
142 }
143 }
144 }
145
146
147 // Find nearest - globally consistent
148 Pstream::listCombineReduce(nearest, mappedPatchBase::nearestEqOp());
149
150 oldPoints_.resize(this->size());
151
153 // Update actual probe locations and store old ones
154 forAll(nearest, samplei)
155 {
156 oldPoints_[samplei] = probeLocations[samplei];
157 probeLocations[samplei] = nearest[samplei].first().point();
158 }
159
160 if (debug)
161 {
163 forAll(nearest, samplei)
164 {
165 label proci = nearest[samplei].second().second();
166 label locali = nearest[samplei].first().index();
167
168 Info<< " " << samplei << " coord:"<< probeLocations[samplei]
169 << " found on processor:" << proci
170 << " in local face:" << locali
171 << " with location:" << nearest[samplei].first().point()
172 << endl;
173 }
174 }
175
176 // Extract any local faces to sample:
177 // - operator[] : actual point to sample (=nearest point on patch)
178 // - oldPoints_ : original provided point (might be anywhere in the mesh)
179 // - cellIds_ : cells, not used
180 // - faceIds_ : faces (now patch faces)
181 // - patchIds_ : patch corresponding to faceList
182 // - procIds_ : processor
183 cellIds_.resize_nocopy(nearest.size());
184 cellIds_ = -1;
185
186 faceIds_.resize_nocopy(nearest.size());
187 faceIds_ = -1;
188
189 procIds_.resize_nocopy(nearest.size());
190 procIds_ = -1;
191
192 patchIds_.resize_nocopy(nearest.size());
193 patchIds_ = -1;
194
195 forAll(nearest, sampleI)
196 {
197 procIds_[sampleI] = nearest[sampleI].second().second();
198
199 if (nearest[sampleI].second().second() == Pstream::myProcNo())
200 {
201 // Store the face to sample
202 faceIds_[sampleI] = nearest[sampleI].first().index();
203 const label facei = faceIds_[sampleI];
204 if (facei != -1)
205 {
206 procIds_[sampleI] = Pstream::myProcNo();
207 patchIds_[sampleI] = bm.whichPatch(facei);
208 }
209 }
210 reduce(procIds_[sampleI], maxOp<label>());
212 }
213}
214
215
216// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
217
219(
220 const fvMesh& mesh,
221 const dictionary& dict
222)
223:
224 probeModel(mesh, dict)
226 read(dict);
227}
228
229
230// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
231
233{
235 {
236 return false;
237 }
238
239 if (!dict.readIfPresent("patches", patchNames_))
240 {
241 patchNames_.resize(1);
242 patchNames_.first() = dict.get<word>("patch");
243 }
244
245 // Initialise cells to sample from supplied locations
246 findElements(thisMesh_);
247
248 return true;
249}
250
251
252// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
List< Key > sortedToc() const
The table of contents (the keys) in sorted order.
Definition HashTable.C:156
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
label index() const noexcept
Return the hit index.
bool hit() const noexcept
Is there a hit?
const point_type & point() const noexcept
Return point, no checks.
static void listCombineReduce(UList< T > &values, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Forwards to Pstream::listReduce with an in-place cop.
Random number generator.
Definition Random.H:56
const T1 & first() const noexcept
Access the first element.
Definition Tuple2.H:132
const T2 & second() const noexcept
Access the second element.
Definition Tuple2.H:142
T & first()
Access first element of the list, position [0].
Definition UList.H:957
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
Definition UPstream.H:1706
label size() const noexcept
The number of entries in the list.
Definition UPtrListI.H:106
scalar distSqr(const Vector< Cmpt > &v2) const
The L2-norm distance squared from another vector. The magSqr() of the difference.
Definition VectorI.H:95
void add(const boundBox &bb)
Extend to include the second box.
Definition boundBoxI.H:323
scalar mag() const
The magnitude/length of the bounding box diagonal.
Definition boundBoxI.H:198
void inflate(const scalar factor)
Expand box by factor*mag(span) in all dimensions.
Definition boundBoxI.H:381
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Non-pointer based hierarchical recursive searching.
const Type & shapes() const noexcept
Reference to shape.
const treeBoundBox & bb() const
Top bounding box.
Tuple2< pointIndexHit, Tuple2< scalar, label > > nearInfo
Helper class for finding nearest.
Utility class for probing specified points on user-selected boundary patches. The input points are pr...
virtual void findElements(const fvMesh &mesh)
Find elements containing patchFieldProbe.
patchFieldProbe(const fvMesh &mesh, const dictionary &dict)
Construct from Time and dictionary.
wordRes patchNames_
Names of the patches to sample.
tmp< Field< Type > > sample(const VolumeField< Type > &) const
Sample a volume field at all locations.
labelList patchIDs_
Index of the patches to sample.
virtual bool read(const dictionary &)
Read the settings dictionary.
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
label whichPatch(const label meshFacei) const
Return patch index for a given mesh face index. Uses binary search.
labelHashSet patchSet(const UList< wordRe > &select, const bool warnNotFound=true, const bool useGroups=true) const
Return the set of patch IDs corresponding to the given names.
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
labelList cellIds_
Cells to be probed (obtained from the locations).
Definition probeModel.H:113
labelList patchIds_
Patch IDs on which the new probes are located.
Definition probeModel.H:129
labelList faceIds_
Faces to be probed.
Definition probeModel.H:118
pointField oldPoints_
Original probes location.
Definition probeModel.H:134
labelList procIds_
Processor holding the cell or face (-1 if point not found on any processor).
Definition probeModel.H:124
const fvMesh & thisMesh_
Const reference to the mesh.
Definition probeModel.H:80
label size() const
Return number of probe locations.
Definition probeModel.H:196
const pointField & probeLocations() const
Return const reference to the probe locations.
Definition probeModel.H:218
virtual bool read(const dictionary &)
Read the settings dictionary.
Definition probeModel.C:50
probeModel(const probeModel &)=delete
No copy construct.
Standard boundBox with extra functionality for use in octree.
Encapsulation of data for searching on faces.
A class for handling words, derived from Foam::string.
Definition word.H:66
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define WarningInFunction
Report a warning using Foam::Warning.
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Definition debug.C:45
Namespace for OpenFOAM.
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition int32.H:127
List< label > labelList
A List of labels.
Definition List.H:62
dimensionedSymmTensor sqr(const dimensionedVector &dv)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
vector point
Point is a vector.
Definition point.H:37
vectorField pointField
pointField is a vectorField.
PointIndexHit< point > pointIndexHit
A PointIndexHit with a 3D point.
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
labelList f(nPoints)
dictionary dict
volScalarField & e
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299
Random rndGen