parPointFieldDistributor.H
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) 2022-2026 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::parPointFieldDistributor
28 
29 Description
30  Distributor/redistributor for point fields,
31  uses a two (or three) stage construction.
32 
33  The inconvenient multi-stage construction is needed since the
34  pointMesh is directly associated with a polyMesh, which will probably
35  have changed while creating the target mesh. This means that it is
36  necessary to save the size of the source mesh and all of its
37  patch meshPoints prior to making any changes (eg, creating the target
38  mesh).
39 
40  -# Create with specified source mesh
41  -# Save the meshPoints (per boundary) for the source mesh
42  -# Attach a target mesh and mesh distribution
43  -# Map the point fields
44  .
45 
46  Runs in parallel. Redistributes from srcMesh to tgtMesh.
47 
48 SourceFiles
49  parPointFieldDistributor.cxx
50  parPointFieldDistributor.txx
51 
52 \*---------------------------------------------------------------------------*/
53 
54 #ifndef Foam_parPointFieldDistributor_H
55 #define Foam_parPointFieldDistributor_H
56 
57 #include "pointMesh.H"
58 #include "pointFieldsFwd.H"
59 #include "PtrList.H"
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 
66 // Forward Declarations
67 class mapDistributePolyMesh;
68 class mapDistributeBase;
69 class IOobjectList;
70 
71 /*---------------------------------------------------------------------------*\
72  Class parPointFieldDistributor Declaration
73 \*---------------------------------------------------------------------------*/
74 
76 {
77  // Private Data
78 
79  //- The source mesh reference
80  const pointMesh& srcMesh_;
81 
82  //- Number of points in the old (source) mesh
83  const label nOldPoints_;
84 
85  //- The pointPatch mesh points
86  PtrList<labelList> patchMeshPoints_;
87 
88  //- The target (destination) mesh reference
89  refPtr<pointMesh> tgtMeshRef_;
90 
91  //- Distribution map reference
93 
94  //- Point patch mappers
95  PtrList<mapDistributeBase> patchPointMaps_;
96 
97  //- Storage for unused handler (when using bool control)
98  const refPtr<fileOperation> noHandler_;
99 
100  //- Write control via a file handler
101  const refPtr<fileOperation>& writeHandler_;
102 
103  //- Write control as a bool (instead of via file handler)
104  bool isWriteProc_;
105 
106 
107  // Private Member Functions
108 
109  //- Write using writeHandler_ or isWriteProc_ to guide the output
110  template<class FieldType>
111  void writeField(const FieldType& fld) const;
112 
113 
114 public:
115 
116  //- Output verbosity when writing
117  static int verbose_;
118 
119 
120  // Generated Methods
121 
122  //- No copy construct
124 
125  //- No copy assignment
126  void operator=(const parPointFieldDistributor&) = delete;
127 
128 
129  // Constructors
130 
131  //- Basic construction
132  explicit parPointFieldDistributor
133  (
135  const pointMesh& srcMesh,
137  const bool isWriteProc = true
138  );
139 
140  //- Basic construction
142  (
144  const pointMesh& srcMesh,
146  const refPtr<fileOperation>& writeHandler
147  );
148 
149  //- Full construction of source/target
151  (
153  const pointMesh& srcMesh,
155  const pointMesh& tgtMesh,
157  const mapDistributePolyMesh& distMap,
159  const bool isWriteProc = true
160  );
161 
162  //- Full construction of source/target
164  (
166  const pointMesh& srcMesh,
168  const pointMesh& tgtMesh,
170  const mapDistributePolyMesh& distMap,
172  const refPtr<fileOperation>& writeHandler
173  );
174 
175 
176  // Member Functions
177 
178  //- The source mesh
179  const pointMesh& sourceMesh() const noexcept { return srcMesh_; }
180 
181  //- True if meshPoints (per boundary) for the source mesh
182  //- have been saved
183  bool hasMeshPoints() const noexcept;
184 
185  //- True if patch maps (per boundary) exist
186  bool hasPatchPointMaps() const noexcept;
187 
188  //- True if a target mesh/distribution map has been attached
189  bool hasTarget() const noexcept;
190 
191  //- Clear out meshPoints (per boundary) for the source mesh
192  void clearMeshPoints();
193 
194  //- Clear out patch maps (per boundary)
195  void clearPatchPointMaps();
196 
197  //- Create/recreate meshPoints (per boundary) for the source mesh
198  void saveMeshPoints();
199 
200  //- Construct per-patch addressing
201  void createPatchPointMaps();
202 
203  //- Clear target mesh / distribution map
204  void resetTarget();
205 
206  //- Reset target mesh / distribution map
207  void resetTarget
208  (
209  const pointMesh& tgtMesh,
210  const mapDistributePolyMesh& distMap
211  );
212 
213 
214  // Field Mapping
215 
216  //- Read, distribute and write all/selected point field types
217  //- (scalar, vector, ... types)
218  label distributeAllFields
219  (
220  const IOobjectList& objects,
221  const wordRes& selectedFields = wordRes()
222  ) const;
223 
224 
225  //- Distribute point field
226  template<class Type>
229  (
231  ) const;
232 
233  //- Read and distribute point field
234  template<class Type>
237  (
238  const IOobject& fieldObject
239  ) const;
240 
241  //- Read, distribute and write all/selected point fields
242  template<class Type>
244  (
245  const IOobjectList& objects,
246  const wordRes& selectedFields = wordRes()
247  ) const;
248 
249  //- Distributed each (unregistered!) point field
250  //- and store the result on its objectRegistry
251  template<class Type>
252  void distributeAndStore
253  (
255  ) const;
256 };
257 
258 
259 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
260 
261 } // End namespace Foam
262 
263 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
264 
265 #ifdef NoRepository
266 # include "parPointFieldDistributor.txx"
267 #endif
268 
269 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 
271 #endif
272 
273 // ************************************************************************* //
void clearMeshPoints()
Clear out meshPoints (per boundary) for the source mesh.
void clearPatchPointMaps()
Clear out patch maps (per boundary)
void operator=(const parPointFieldDistributor &)=delete
No copy assignment.
void saveMeshPoints()
Create/recreate meshPoints (per boundary) for the source mesh.
List of IOobjects with searching and retrieving facilities. Implemented as a HashTable, so the various sorted methods should be used if traversing in parallel.
Definition: IOobjectList.H:55
void createPatchPointMaps()
Construct per-patch addressing.
bool hasTarget() const noexcept
True if a target mesh/distribution map has been attached.
label distributeAllFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected point field types (scalar, vector, ... types) ...
void resetTarget()
Clear target mesh / distribution map.
tmp< GeometricField< Type, pointPatchField, pointMesh > > distributePointField(const IOobject &fieldObject) const
Read and distribute point field.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Forwards and collection of common point field types.
Distributor/redistributor for point fields, uses a two (or three) stage construction.
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:45
static int verbose_
Output verbosity when writing.
label distributePointFields(const IOobjectList &objects, const wordRes &selectedFields=wordRes()) const
Read, distribute and write all/selected point fields.
tmp< GeometricField< Type, pointPatchField, pointMesh > > distributeField(const GeometricField< Type, pointPatchField, pointMesh > &fld) const
Distribute point field.
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:53
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
const direction noexcept
Definition: scalarImpl.H:265
void distributeAndStore(const UPtrList< GeometricField< Type, pointPatchField, pointMesh >> &) const
Distributed each (unregistered!) point field and store the result on its objectRegistry.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const pointMesh & sourceMesh() const noexcept
The source mesh.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: PtrList.H:56
A class for managing temporary objects.
Definition: HashPtrTable.H:50
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:188
bool hasMeshPoints() const noexcept
True if meshPoints (per boundary) for the source mesh have been saved.
parPointFieldDistributor(const parPointFieldDistributor &)=delete
No copy construct.
Namespace for OpenFOAM.
bool hasPatchPointMaps() const noexcept
True if patch maps (per boundary) exist.