patchProbes.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 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 "patchProbes.H"
27 #include "volFields.H"
28 #include "IOmanip.H"
29 #include "RemoteData.H"
30 #include "treeBoundBox.H"
31 #include "treeDataFace.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
39 
41  (
45  );
46 }
47 
48 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
49 
50 void Foam::patchProbes::findElements(const fvMesh& mesh)
51 {
52  (void)mesh.tetBasePtIs();
53 
54  const polyBoundaryMesh& bm = mesh.poly().boundary();
55 
56  label patchi = bm.findIndex(patchName_);
57 
58  if (patchi == -1)
59  {
61  << " Unknown patch name "
62  << patchName_ << endl
63  << exit(FatalError);
64  }
65 
66  // All the info for nearest. Construct to miss
68 
69  const polyPatch& pp = bm[patchi];
70 
71  if (pp.size() > 0)
72  {
73  labelList bndFaces(pp.size());
74  forAll(bndFaces, i)
75  {
76  bndFaces[i] = pp.start() + i;
77  }
78 
79  treeBoundBox overallBb(pp.points());
80  overallBb = overallBb.extend(1e-4);
81 
82  const indexedOctree<treeDataFace> boundaryTree
83  (
84  treeDataFace // all information needed to search faces
85  (
86  false, // do not cache bb
87  mesh,
88  bndFaces // patch faces only
89  ),
90  overallBb, // overall search domain
91  8, // maxLevel
92  10, // leafsize
93  3.0 // duplicity
94  );
95 
96  forAll(locations_, probei)
97  {
98  const point sample = locations_[probei];
99 
100  scalar span = boundaryTree.bb().mag();
101 
102  pointIndexHit info = boundaryTree.findNearest
103  (
104  sample,
105  Foam::sqr(span)
106  );
107 
108  if (!info.hit())
109  {
110  info = boundaryTree.findNearest
111  (
112  sample,
113  Foam::sqr(great)
114  );
115  }
116 
117  label facei = boundaryTree.shapes().faceLabels()[info.index()];
118 
119  const label patchi = bm.whichPatch(facei);
120 
121  if (isA<emptyPolyPatch>(bm[patchi]))
122  {
124  << " The sample point: " << sample
125  << " belongs to " << patchi
126  << " which is an empty patch. This is not permitted. "
127  << " This sample will not be included "
128  << endl;
129  }
130  else
131  {
132  const point& fc = mesh.faceCentres()[facei];
133 
134  nearest[probei].proci = Pstream::myProcNo();
135  nearest[probei].elementi = facei;
136  nearest[probei].data = magSqr(fc-sample);
137  }
138  }
139  }
140 
141  // Find nearest.
143  (
144  nearest,
145  RemoteData<scalar>::smallestEqOp()
146  );
148 
149  if (debug)
150  {
151  InfoInFunction << endl;
152  forAll(nearest, sampleI)
153  {
154  Info<< " " << sampleI << " coord:" << locations_[sampleI]
155  << " found on processor:" << nearest[sampleI].proci
156  << " in local cell/face:" << nearest[sampleI].elementi
157  << endl;
158  }
159  }
160 
161  // Extract any local faces to sample
162  cellList_.setSize(nearest.size());
163  cellList_ = -1;
164  faceList_.setSize(nearest.size());
165  faceList_ = -1;
166  forAll(nearest, sampleI)
167  {
168  if (nearest[sampleI].proci == Pstream::myProcNo())
169  {
170  cellList_[sampleI] = mesh.faceOwner()[nearest[sampleI].elementi];
171  faceList_[sampleI] = nearest[sampleI].elementi;
172  }
173  }
174 }
175 
176 
177 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
178 
180 (
181  const word& name,
182  const Time& t,
183  const dictionary& dict
184 )
185 :
186  probes(name, t, dict, false)
187 {
188  read(dict);
189 }
190 
191 
192 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
193 
195 {}
196 
197 
198 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
199 
201 {
202  const bool result = probes::read(dict, false);
203 
204  dict.lookup("patchName") >> patchName_;
205 
206  {
207  // Initialise cells to sample from supplied locations
208  findElements(mesh_);
209 
210  prepare();
211  }
212 
213  return result;
214 }
215 
216 
218 {
219  if (locations_.size() && prepare())
220  {
221  sampleAndWrite(scalarFields_);
222  sampleAndWrite(vectorFields_);
223  sampleAndWrite(sphericalTensorFields_);
224  sampleAndWrite(symmTensorFields_);
225  sampleAndWrite(tensorFields_);
226 
227  sampleAndWriteSurfaceFields(surfaceScalarFields_);
228  sampleAndWriteSurfaceFields(surfaceVectorFields_);
229  sampleAndWriteSurfaceFields(surfaceSphericalTensorFields_);
230  sampleAndWriteSurfaceFields(surfaceSymmTensorFields_);
231  sampleAndWriteSurfaceFields(surfaceTensorFields_);
232  }
233 
234  return true;
235 }
236 
237 
238 // ************************************************************************* //
Istream and Ostream manipulators taking arguments.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Macros for easy insertion into run-time selection tables.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
void setSize(const label)
Reset size of List.
Definition: List.C:281
static void listCombineGather(const List< commsStruct > &comms, List< T > &Value, const CombineOp &cop, const int tag, const label comm)
static void listCombineScatter(const List< commsStruct > &comms, List< T > &Value, const int tag, const label comm)
Scatter data. Reverse of combineGather.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:429
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
Abstract base-class for Time/database functionObjects.
const polyMesh & poly() const
Return reference to polyMesh.
Definition: fvMesh.H:456
Set of locations to sample.at patches.
Definition: patchProbes.H:59
patchProbes(const word &name, const Time &time, const dictionary &dict)
Construct from Time and dictionary.
Definition: patchProbes.C:180
virtual bool write()
Sample and write.
Definition: patchProbes.C:217
virtual ~patchProbes()
Destructor.
Definition: patchProbes.C:194
virtual bool read(const dictionary &)
Read.
Definition: patchProbes.C:200
Motion of the mesh specified as a list of pointMeshMovers.
const polyBoundaryMesh & boundary() const
Return boundary mesh.
Definition: polyMesh.H:393
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1321
const labelIOList & tetBasePtIs() const
Return the tetBasePtIs.
Definition: polyMesh.C:1064
const vectorField & faceCentres() const
Set of locations to sample.
Definition: probes.H:66
labelList cellList_
Definition: probes.H:128
pointField locations_
Probe locations.
Definition: probes.H:96
bool read(const dictionary &, const bool initialise)
Read the probes.
Definition: probes.C:296
labelList faceList_
Definition: probes.H:131
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
#define WarningInFunction
Report a warning using Foam::Warning.
#define InfoInFunction
Report an information message using Foam::Info.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const doubleScalar e
Definition: doubleScalar.H:106
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
addToRunTimeSelectionTable(polyPatch, mergedCyclicPolyPatch, word)
PointIndexHit< point > pointIndexHit
Definition: pointIndexHit.H:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
messageStream Info
vector point
Point is a vector.
Definition: point.H:41
tmp< DimensionedField< typename outerProduct< Type, Type >::type, GeoMesh, Field >> sqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
tmp< DimensionedField< scalar, GeoMesh, Field > > magSqr(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)
defineTypeNameAndDebug(atmosphericBoundaryLayer, 0)
dictionary dict