Loading...
Searching...
No Matches
probeModel.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
29#include "probeModel.H"
30#include "mapPolyMesh.H"
32
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38}
39
40// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41
43(
44 const fvMesh& mesh,
45 const dictionary& dict
46)
47:
48 thisMesh_(mesh),
49 samplePointScheme_("cell")
51 read(dict);
52}
53
54
55// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
56
58{
59 dict.readEntry("probeLocations", probes_);
60
61 if (probes_.empty())
62 {
64 << "Empty 'probeLocations' list."
66 }
67
68 fixedLocations_ = dict.getOrDefault<bool>("fixedLocations", true);
69 includeOutOfBounds_ = dict.getOrDefault<bool>("includeOutOfBounds", true);
70
71 if (dict.readIfPresent("interpolationScheme", samplePointScheme_))
72 {
73 if (!fixedLocations_ && samplePointScheme_ != "cell")
74 {
76 << "Only cell interpolation can be applied when "
77 << "not using fixedLocations. InterpolationScheme "
78 << "entry will be ignored"
79 << endl;
80 }
81 }
82
83 return true;
84}
85
86
88{
89 DebugInfo<< "probes: updateMesh" << endl;
90
91 if (&mpm.mesh() != &thisMesh_)
92 {
93 return;
94 }
95
96 if (fixedLocations_)
97 {
98 this->findElements(thisMesh_);
99 }
100 else
101 {
102 DebugInfo<< "probes: remapping sample locations" << endl;
103
104 // 1. Update cells
105 {
106 DynamicList<label> elems(cellIds_.size());
107
108 const labelList& reverseMap = mpm.reverseCellMap();
109 forAll(cellIds_, i)
110 {
111 label celli = cellIds_[i];
112 if (celli != -1)
113 {
114 label newCelli = reverseMap[celli];
115 if (newCelli == -1)
116 {
117 // cell removed
118 }
119 else if (newCelli < -1)
120 {
121 // cell merged
122 elems.append(-newCelli - 2);
123 }
124 else
125 {
126 // valid new cell
127 elems.append(newCelli);
128 }
129 }
130 else
131 {
132 // Keep -1 elements so the size stays the same
133 elems.append(-1);
134 }
135 }
136
137 cellIds_.transfer(elems);
138 }
139
140 // 2. Update faces
141 {
142 DynamicList<label> elems(faceIds_.size());
143
144 const labelList& reverseMap = mpm.reverseFaceMap();
145 for (const label facei : faceIds_)
146 {
147 if (facei != -1)
148 {
149 label newFacei = reverseMap[facei];
150 if (newFacei == -1)
151 {
152 // face removed
153 }
154 else if (newFacei < -1)
155 {
156 // face merged
157 elems.append(-newFacei - 2);
158 }
159 else
160 {
161 // valid new face
162 elems.append(newFacei);
163 }
164 }
165 else
166 {
167 // Keep -1 elements
168 elems.append(-1);
169 }
170 }
172 faceIds_.transfer(elems);
173 }
174 }
175}
176
177
179{
180 DebugInfo<< "probes: movePoints" << endl;
181
182 if (fixedLocations_ && &mesh == &thisMesh_)
183 {
184 this->findElements(thisMesh_);
185 }
186}
187
188
189// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition DynamicList.H:68
void append(const T &val)
Copy append an element to the end of this list.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
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
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
const labelList & reverseCellMap() const noexcept
Reverse cell map.
const labelList & reverseFaceMap() const noexcept
Reverse face map.
const polyMesh & mesh() const noexcept
Return polyMesh.
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Base class for sampling fields at specified internal and boundary locations.
Definition probeModel.H:49
word samplePointScheme_
Interpolation/sample scheme to obtain values at the points.
Definition probeModel.H:100
bool includeOutOfBounds_
Include probes that were not found (default: true).
Definition probeModel.H:93
labelList cellIds_
Cells to be probed (obtained from the locations).
Definition probeModel.H:113
labelList faceIds_
Faces to be probed.
Definition probeModel.H:118
pointField probes_
Probe locations.
Definition probeModel.H:108
virtual void findElements(const fvMesh &mesh)=0
Find cells and faces containing probes.
const fvMesh & thisMesh_
Const reference to the mesh.
Definition probeModel.H:80
bool fixedLocations_
Fixed locations (default: true).
Definition probeModel.H:88
virtual void movePoints(const polyMesh &)
Update for changes of mesh.
Definition probeModel.C:171
virtual void updateMesh(const mapPolyMesh &)
Update for changes of mesh.
Definition probeModel.C:80
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 FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
#define DebugInfo
Report an information message using Foam::Info.
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299