fvMeshTools.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) 2012-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2025 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 Class
28  Foam::fvMeshTools
29 
30 Description
31  A collection of tools for operating on an fvMesh.
32 
33 SourceFiles
34  fvMeshTools.C
35  fvMeshToolsProcAddr.C
36  fvMeshToolsTemplates.C
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #ifndef Foam_fvMeshTools_H
41 #define Foam_fvMeshTools_H
42 
43 #include "fvMesh.H"
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 namespace Foam
48 {
49 
50 // Forward Declarations
51 class fileOperation;
52 class mapDistributePolyMesh;
53 
54 /*---------------------------------------------------------------------------*\
55  Class fvMeshTools Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class fvMeshTools
59 {
60  // Private Member Functions
61 
62  template<class GeoField>
63  static void addPatchFields
64  (
65  fvMesh&,
66  const dictionary& patchFieldDict,
67  const word& defaultPatchFieldType,
68  const typename GeoField::value_type& defaultPatchValue
69  );
70 
71  //- Set patchFields according to dictionary
72  template<class GeoField>
73  static void setPatchFields
74  (
75  fvMesh& mesh,
76  const label patchi,
77  const dictionary& patchFieldDict
78  );
79 
80  //- Set patchFields to value
81  template<class GeoField>
82  static void setPatchFields
83  (
84  fvMesh& mesh,
85  const label patchi,
86  const typename GeoField::value_type& value
87  );
88 
89  // Remove last patch fields
90  template<class GeoField>
91  static void trimPatchFields(fvMesh&, const label nPatches);
92 
93  template<class GeoField>
94  static void reorderPatchFields(fvMesh&, const labelList& oldToNew);
95 
96  // Remove trailing patches
97  static void trimPatches(fvMesh&, const label nPatches);
98 
99  //- Read mesh if available, or create empty mesh with non-proc as per
100  //- proc0 mesh.
101  // Has two modes of operation.
102  // If the readHandler is non-nullptr, use it to decide on availability.
103  // Requires:
104  // - all processors to have all patches (and in same order).
105  // - io.instance() set to facesInstance
106  static autoPtr<fvMesh> loadOrCreateMeshImpl
107  (
108  const IOobject& io,
109  const refPtr<fileOperation>* readHandlerPtr, // Can be nullptr
110  const bool decompose, // Only used if readHandlerPtr == nullptr
111  const bool verbose = false
112  );
113 
114 
115 public:
116 
117  // Member Functions
118 
119  //- Add patch. Inserts patch before all processor patches.
120  // Supply per field the new patchField per field as a
121  // subdictionary or a default type. If validBoundary call is parallel
122  // synced and all add the same patch with same settings.
123  static label addPatch
124  (
125  fvMesh& mesh,
126  const polyPatch& patch,
127  const dictionary& patchFieldDict,
128  const word& defaultPatchFieldType,
129  const bool validBoundary
130  );
131 
132  //- Change patchField on registered fields according to dictionary
133  static void setPatchFields
134  (
135  fvMesh& mesh,
136  const label patchi,
137  const dictionary& patchFieldDict
138  );
139 
140  //- Change patchField to zero on registered fields
141  static void zeroPatchFields(fvMesh& mesh, const label patchi);
142 
143  //- Reorder and remove trailing patches.
144  // Is parallel synced when validBoundary is true
145  static void reorderPatches
146  (
147  fvMesh&,
148  const labelList& oldToNew,
149  const label nPatches,
150  const bool validBoundary
151  );
152 
153  //- Remove zero sized patches. All but processor patches are
154  // assumed to be present on all processors (so size will be reduced
155  // if validBoundary). Return map from new
156  // to old patches
157  static labelList removeEmptyPatches(fvMesh&, const bool validBoundary);
158 
159  //- Remove zero sized patches unless explicitly forced to preserve.
160  // See above.
162  (
163  fvMesh&,
164  const wordList& keepPatches,
165  const bool validBoundary
166  );
167 
168  //- Set the fvGeometryScheme to basic (to avoid parallel communication)
169  static void setBasicGeometry(fvMesh& mesh);
170 
171  //- Read mesh or create dummy mesh (0 cells, >0 patches).
172  //
173  // Works in two modes according to masterOnlyReading:
174  // true : create dummy mesh on all procs
175  // false: checks locally for mesh directories and only creates dummy mesh
176  // if not present
177  static autoPtr<fvMesh> newMesh
178  (
179  const IOobject& io,
180  const bool masterOnlyReading,
181  const bool verbose = false
182  );
183 
184  //- Read mesh if available, or create empty mesh with non-proc as per
185  //- proc0 mesh.
186  // Requires:
187  // - all processors to have all patches (and in same order).
188  // - io.instance() set to facesInstance
190  (
191  const IOobject& io,
192  const bool decompose,
193  const bool verbose = false
194  );
195 
196  //- Read mesh if available, or create empty mesh with non-proc as per
197  //- proc0 mesh.
198  // The fileHandler is specified on processors that have a processor mesh.
199  // Generates empty mesh on other processors.
201  (
202  const IOobject& io,
205  const refPtr<fileOperation>& readHandler,
206  const bool verbose = true
207  );
208 
209  //- Create additional fvSchemes/fvSolution files
210  static void createDummyFvMeshFiles
211  (
212  const objectRegistry& parent,
213  const word& regionName,
214  const bool verbose = false
215  );
216 
217 
218  //- Read procAddressing components (reconstructing)
220  (
221  const fvMesh& procMesh,
222  const fvMesh* baseMeshPtr
223  );
224 
225  //- Write addressing if decomposing (1 to many) or reconstructing
226  //- (many to 1)
227  static void writeProcAddressing
228  (
229  const fvMesh& procMesh,
230  const mapDistributePolyMesh& map,
232  const bool decompose,
234  const fileName& writeInstance,
236  const refPtr<fileOperation>& writeHandler
237  );
238 
239 
240  // Housekeeping
241 
242  //- Read procAddressing components (reconstructing)
244  (
245  const fvMesh& procMesh,
246  const autoPtr<fvMesh>& baseMeshPtr
247  );
248 };
249 
250 
251 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 
253 } // End namespace Foam
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #ifdef NoRepository
258  #include "fvMeshToolsTemplates.C"
259 #endif
260 
261 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 
263 #endif
264 
265 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:394
static void reorderPatches(fvMesh &, const labelList &oldToNew, const label nPatches, const bool validBoundary)
Reorder and remove trailing patches.
Definition: fvMeshTools.C:317
A class for handling file names.
Definition: fileName.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:130
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
static autoPtr< mapDistributePolyMesh > readProcAddressing(const fvMesh &procMesh, const fvMesh *baseMeshPtr)
Read procAddressing components (reconstructing)
A class for managing references or pointers (no reference counting)
Definition: HashPtrTable.H:49
static void zeroPatchFields(fvMesh &mesh, const label patchi)
Change patchField to zero on registered fields.
Definition: fvMeshTools.C:223
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
static label addPatch(fvMesh &mesh, const polyPatch &patch, const dictionary &patchFieldDict, const word &defaultPatchFieldType, const bool validBoundary)
Add patch. Inserts patch before all processor patches.
Definition: fvMeshTools.C:38
const auto & io
static autoPtr< fvMesh > newMesh(const IOobject &io, const bool masterOnlyReading, const bool verbose=false)
Read mesh or create dummy mesh (0 cells, >0 patches).
Definition: fvMeshTools.C:472
static void createDummyFvMeshFiles(const objectRegistry &parent, const word &regionName, const bool verbose=false)
Create additional fvSchemes/fvSolution files.
Definition: fvMeshTools.C:1228
static autoPtr< fvMesh > loadOrCreateMesh(const IOobject &io, const bool decompose, const bool verbose=false)
Read mesh if available, or create empty mesh with non-proc as per proc0 mesh.
Definition: fvMeshTools.C:1193
A collection of tools for operating on an fvMesh.
Definition: fvMeshTools.H:53
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const std::string patch
OpenFOAM patch number as a std::string.
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
Registry of regIOobjects.
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:69
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:188
static void setBasicGeometry(fvMesh &mesh)
Set the fvGeometryScheme to basic (to avoid parallel communication)
Definition: fvMeshTools.C:451
static void writeProcAddressing(const fvMesh &procMesh, const mapDistributePolyMesh &map, const bool decompose, const fileName &writeInstance, const refPtr< fileOperation > &writeHandler)
Write addressing if decomposing (1 to many) or reconstructing (many to 1)
static labelList removeEmptyPatches(fvMesh &, const bool validBoundary)
Remove zero sized patches. All but processor patches are.
Definition: fvMeshTools.C:442
Namespace for OpenFOAM.