Loading...
Searching...
No Matches
internalFieldProbe.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-2017 OpenFOAM Foundation
9 Copyright (C) 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
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
37}
38
39// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
40
42{
43 DebugInfo<< "internalFieldProbe: resetting sample locations" << endl;
44
46
47 cellIds_.resize_nocopy(probeLocations.size());
50 procIds_ = -1;
51
52
53 forAll(probeLocations, probei)
54 {
55 const point& location = probeLocations[probei];
56
57 const label celli = mesh.findCell(location);
58
59 cellIds_[probei] = celli;
60
61 if (celli != -1)
62 {
63 const labelList& cellFaces = mesh.cells()[celli];
64 const vector& cellCentre = mesh.cellCentres()[celli];
65 scalar minDistance = GREAT;
66 label minFaceID = -1;
67 forAll(cellFaces, i)
68 {
69 label facei = cellFaces[i];
70 vector dist = mesh.faceCentres()[facei] - cellCentre;
71 if (mag(dist) < minDistance)
72 {
73 minDistance = mag(dist);
74 minFaceID = facei;
75 }
76 }
77 faceIds_[probei] = minFaceID;
78 }
79 else
80 {
81 faceIds_[probei] = -1;
82 }
83
84 if (debug && (cellIds_[probei] != -1 || faceIds_[probei] != -1))
85 {
86 Pout<< "internalFieldProbe : found point " << location
87 << " in cell " << cellIds_[probei]
88 << " and face " << faceIds_[probei] << endl;
89 }
90 }
91
92
93 // Check if all probes have been found.
94 forAll(cellIds_, probei)
95 {
96 const point& location = probeLocations[probei];
97 label celli = cellIds_[probei];
98 label facei = faceIds_[probei];
99
100 procIds_[probei] = (celli != -1 ? Pstream::myProcNo() : -1);
101
102 // Check at least one processor with cell.
103 reduce(celli, maxOp<label>());
104 reduce(facei, maxOp<label>());
105 reduce(procIds_[probei], maxOp<label>());
106
107 if (celli == -1)
108 {
109 if (Pstream::master())
110 {
112 << "Did not find location " << location
113 << " in any cell. Skipping location." << endl;
114 }
115 }
116 else if (facei == -1)
117 {
118 if (Pstream::master())
119 {
121 << "Did not find location " << location
122 << " in any face. Skipping location." << endl;
123 }
124 }
125 else
126 {
127 // Make sure location not on two domains.
128 if (cellIds_[probei] != -1 && cellIds_[probei] != celli)
129 {
131 << "Location " << location
132 << " seems to be on multiple domains:"
133 << " cell " << cellIds_[probei]
134 << " on my domain " << Pstream::myProcNo()
135 << " and cell " << celli << " on some other domain."
136 << nl
137 << "This might happen if the probe location is on"
138 << " a processor patch. Change the location slightly"
139 << " to prevent this." << endl;
140 }
141
142 if (faceIds_[probei] != -1 && faceIds_[probei] != facei)
143 {
145 << "Location " << location
146 << " seems to be on multiple domains:"
147 << " cell " << faceIds_[probei]
148 << " on my domain " << Pstream::myProcNo()
149 << " and face " << facei << " on some other domain."
150 << nl
151 << "This might happen if the probe location is on"
152 << " a processor patch. Change the location slightly"
153 << " to prevent this." << endl;
154 }
156 }
157}
158
159
160// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
161
163(
164 const fvMesh& mesh,
165 const dictionary& dict
166)
167:
170 read(dict);
171}
172
173
174// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
175
177{
179 {
180 return false;
181 }
182
183 // Initialise cells to sample from supplied locations
184 findElements(thisMesh_);
185
186 return true;
187}
188
189
190// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
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
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition UPstream.H:1714
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
A utility class for probing field values at specified point locations within an fvMesh.
virtual void findElements(const fvMesh &mesh)
Find cells and faces containing probes.
internalFieldProbe(const fvMesh &mesh, const dictionary &dict)
Construct from Time and dictionary.
virtual bool read(const dictionary &)
Read the settings dictionary.
Base class for sampling fields at specified internal and boundary locations.
Definition probeModel.H:49
labelList cellIds_
Cells to be probed (obtained from the locations).
Definition probeModel.H:113
labelList faceIds_
Faces to be probed.
Definition probeModel.H:118
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
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.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
dynamicFvMesh & mesh
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
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
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
vectorField pointField
pointField is a vectorField.
Vector< scalar > vector
Definition vector.H:57
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299