nearWallFields.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 "nearWallFields.H"
27 #include "wordReList.H"
28 #include "findCellParticle.H"
29 #include "OBJstream.H"
30 #include "globalIndex.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
46 
48 {
49  // Count number of faces
50  label nPatchFaces = 0;
52  {
53  label patchi = iter.key();
54  nPatchFaces += mesh_.boundary()[patchi].size();
55  }
56 
57  // Global indexing
58  globalIndex globalWalls(nPatchFaces);
59 
60  DebugInFunction << "nPatchFaces: " << globalWalls.size() << endl;
61 
62  // Get the mesh searching engine
63  const meshSearch& searchEngine = meshSearch::New(mesh_);
64 
65  // Construct cloud
67  (
68  mesh_,
71  );
72 
73  // Add particles to track to sample locations
74  nPatchFaces = 0;
75 
76  label nLocateBoundaryHits = 0;
77 
79  {
80  label patchi = iter.key();
81  const fvPatch& patch = mesh_.boundary()[patchi];
82 
83  vectorField nf(patch.nf());
84 
85  forAll(patch, patchFacei)
86  {
87  cloud.addParticle
88  (
90  (
91  searchEngine,
92  patch.Cf()[patchFacei],
93  patch.faceCells()[patchFacei],
94  nLocateBoundaryHits,
95  - distance_*nf[patchFacei],
96  globalWalls.toGlobal(nPatchFaces) // passive data
97  )
98  );
99 
100  nPatchFaces++;
101  }
102  }
103 
104 
105 
106  if (debug)
107  {
108  // Dump particles
109  OBJstream str
110  (
111  time_.path()
112  /"wantedTracks_" + time_.name() + ".obj"
113  );
114  InfoInFunction << "Dumping tracks to " << str.name() << endl;
115 
117  {
118  const vector p = iter().position(mesh_);
119  str.write(linePointRef(p, p + iter().displacement()));
120  }
121  }
122 
123 
124 
125  // Per cell: empty or global wall index and end location
127  cellToSamples_.setSize(mesh_.nCells());
128 
129  // Database to pass into findCellParticle::move
131 
132  // Debug: collect start points
133  pointField start;
134  if (debug)
135  {
136  start.setSize(nPatchFaces);
137  nPatchFaces = 0;
139  {
140  const findCellParticle& tp = iter();
141  start[nPatchFaces++] = tp.position(mesh_);
142  }
143  }
144 
145 
146  // Track
147  cloud.move(cloud, td);
148 
149 
150  // Rework cell-to-globalpatchface into a map
151  List<Map<label>> compactMap;
152  getPatchDataMapPtr_.reset
153  (
154  new distributionMap
155  (
156  globalWalls,
157  cellToWalls_,
158  compactMap
159  )
160  );
161 
162 
163  // Debug: dump resulting tracks
164  if (debug)
165  {
166  getPatchDataMapPtr_().distribute(start);
167  {
168  OBJstream str
169  (
170  time_.path()
171  /"obtainedTracks_" + time_.name() + ".obj"
172  );
173  InfoInFunction << "Dumping obtained to " << str.name() << endl;
174 
175  forAll(cellToWalls_, celli)
176  {
177  const List<point>& ends = cellToSamples_[celli];
178  const labelList& cData = cellToWalls_[celli];
179  forAll(cData, i)
180  {
181  str.write(linePointRef(ends[i], start[cData[i]]));
182  }
183  }
184  }
185  }
186 }
187 
188 
189 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
190 
192 (
193  const word& name,
194  const Time& runTime,
195  const dictionary& dict
196 )
197 :
198  fvMeshFunctionObject(name, runTime, dict),
199  fieldSet_()
200 {
201  read(dict);
202 }
203 
204 
205 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
206 
208 {
210 }
211 
212 
213 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
214 
216 {
218 
219  dict.lookup("fields") >> fieldSet_;
220  patchSet_ = mesh_.poly().boundary().patchSet(dict);
221  distance_ = dict.lookup<scalar>("distance");
222 
223 
224  // Clear out any previously loaded fields
225  vsf_.clear();
226  vvf_.clear();
227  vSpheretf_.clear();
228  vSymmtf_.clear();
229  vtf_.clear();
230  fieldMap_.clear();
231  reverseFieldMap_.clear();
232 
233 
234  // Generate fields with mappedField boundary condition
235 
236  // Convert field to map
237  fieldMap_.resize(2*fieldSet_.size());
238  reverseFieldMap_.resize(2*fieldSet_.size());
239  forAll(fieldSet_, seti)
240  {
241  const word& fieldName = fieldSet_[seti].first();
242  const word& sampleFieldName = fieldSet_[seti].second();
243 
244  fieldMap_.insert(fieldName, sampleFieldName);
245  reverseFieldMap_.insert(sampleFieldName, fieldName);
246  }
247 
248  Log << type() << " " << name()
249  << ": Sampling " << fieldMap_.size() << " fields" << endl;
250 
251  // Do analysis
252  calcAddressing();
253 
254  return true;
255 }
256 
257 
259 {
260  wordList fields(fieldSet_.size());
261 
262  forAll(fieldSet_, fieldi)
263  {
264  fields[fieldi] = fieldSet_[fieldi].first();
265  }
266 
267  return fields;
268 }
269 
270 
272 {
274 
275  if
276  (
277  fieldMap_.size()
278  && vsf_.empty()
279  && vvf_.empty()
280  && vSpheretf_.empty()
281  && vSymmtf_.empty()
282  && vtf_.empty()
283  )
284  {
285  Log << type() << " " << name()
286  << ": Creating " << fieldMap_.size() << " fields" << endl;
287 
288  createFields(vsf_);
289  createFields(vvf_);
290  createFields(vSpheretf_);
291  createFields(vSymmtf_);
292  createFields(vtf_);
293 
294  Log << endl;
295  }
296 
297  Log << type() << " " << name()
298  << " write:" << nl
299  << " Sampling fields to " << time_.name()
300  << endl;
301 
302  sampleFields(vsf_);
303  sampleFields(vvf_);
304  sampleFields(vSpheretf_);
305  sampleFields(vSymmtf_);
306  sampleFields(vtf_);
307 
308  return true;
309 }
310 
311 
313 {
315 
316  Log << " Writing sampled fields to " << time_.name()
317  << endl;
318 
319  forAll(vsf_, i)
320  {
321  vsf_[i].write();
322  }
323  forAll(vvf_, i)
324  {
325  vvf_[i].write();
326  }
327  forAll(vSpheretf_, i)
328  {
329  vSpheretf_[i].write();
330  }
331  forAll(vSymmtf_, i)
332  {
333  vSymmtf_[i].write();
334  }
335  forAll(vtf_, i)
336  {
337  vtf_[i].write();
338  }
339 
340  return true;
341 }
342 
343 
344 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:492
Macros for easy insertion into run-time selection tables.
Template class for intrusive linked lists.
Definition: ILList.H:67
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void setSize(const label)
Reset size of List.
Definition: List.C:281
OFstream which keeps track of vertices.
Definition: OBJstream.H:56
virtual Ostream & write(const char)
Write character.
Definition: OBJstream.C:81
const fileName & name() const
Return the name of the stream.
Definition: OFstream.H:121
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
fileName path() const
Explicitly inherit path from TimePaths to disambiguate from.
Definition: TimePaths.H:138
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
const word & name() const
Return const reference to name.
Class containing processor-to-processor mapping information.
Class used to pass tracking data to the trackToFace function.
Particle class that finds cells by tracking.
Abstract base-class for Time/database functionObjects.
const Time & time_
Reference to time.
Function object that solves for the evolution of a cloud. Only provides one-way coupling with a finit...
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
Samples near-patch volume fields.
scalar distance_
Distance away from wall.
virtual wordList fields() const
Return the list of fields required.
List< List< point > > cellToSamples_
From cell to tracked end point.
labelListList cellToWalls_
From cell to seed patch faces.
void calcAddressing()
Calculate addressing from cells back to patch faces.
labelHashSet patchSet_
Patches to sample.
nearWallFields(const word &name, const Time &runTime, const dictionary &dict)
Construct for given objectRegistry and dictionary.
autoPtr< distributionMap > getPatchDataMapPtr_
Map from cell based data back to patch based data.
virtual bool execute()
Calculate the near-wall fields.
virtual bool write()
Write the near-wall fields.
virtual bool read(const dictionary &)
Read the controls.
virtual bool read(const dictionary &)
Read optional controls.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:932
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:58
tmp< vectorField > nf() const
Return face normals.
Definition: fvPatch.C:141
const vectorField & Cf() const
Return face centres.
Definition: fvPatch.C:85
virtual const labelUList & faceCells() const
Return faceCells.
Definition: fvPatch.C:79
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:64
label size() const
Global sum of localSizes.
Definition: globalIndexI.H:66
label toGlobal(const label i) const
From local to global.
Definition: globalIndexI.H:82
static const word defaultName
The default cloud name: defaultCloud.
Definition: cloud.H:72
Mesh object that implements searches within the local cells and faces.
Definition: meshSearch.H:59
static const meshSearch & New(const polyMesh &mesh, const pointInCellShapes=pointInCellShapes::tets)
Lookup or construct from mesh and cell decomposition option.
Definition: meshSearch.C:61
vector position(const polyMesh &mesh) const
Return current particle position.
Definition: particleI.H:159
label nCells() const
A class for handling words, derived from string.
Definition: word.H:63
label patchi
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:234
#define Log
Report write to Foam::Info if the local log switch is true.
#define DebugInFunction
Report an information message using Foam::Info.
#define InfoInFunction
Report an information message using Foam::Info.
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
addToRunTimeSelectionTable(functionObject, fvModel, dictionary)
Namespace for OpenFOAM.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
line< point, const point & > linePointRef
Line using referred points.
Definition: linePointRef.H:45
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
dictionary dict
volScalarField & p