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-2023 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  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 
160  //- Set the fvGeometryScheme to basic (to avoid parallel communication)
161  static void setBasicGeometry(fvMesh& mesh);
162 
163  //- Read mesh or create dummy mesh (0 cells, >0 patches).
164  //
165  // Works in two modes according to masterOnlyReading:
166  // true : create dummy mesh on all procs
167  // false: checks locally for mesh directories and only creates dummy mesh
168  // if not present
169  static autoPtr<fvMesh> newMesh
170  (
171  const IOobject& io,
172  const bool masterOnlyReading,
173  const bool verbose = false
174  );
175 
176  //- Read mesh if available, or create empty mesh with non-proc as per
177  //- proc0 mesh.
178  // Requires:
179  // - all processors to have all patches (and in same order).
180  // - io.instance() set to facesInstance
182  (
183  const IOobject& io,
184  const bool decompose,
185  const bool verbose = false
186  );
187 
188  //- Read mesh if available, or create empty mesh with non-proc as per
189  //- proc0 mesh.
190  // The fileHandler is specified on processors that have a processor mesh.
191  // Generates empty mesh on other processors.
193  (
194  const IOobject& io,
196  refPtr<fileOperation>& readHandler,
197  const bool verbose = true
198  );
199 
200  //- Create additional fvSchemes/fvSolution files
201  static void createDummyFvMeshFiles
202  (
203  const objectRegistry& parent,
204  const word& regionName,
205  const bool verbose = false
206  );
207 
208 
209  //- Read procAddressing components (reconstructing)
211  (
212  const fvMesh& procMesh,
213  const autoPtr<fvMesh>& baseMeshPtr
214  );
215 
216  //- Write addressing if decomposing (1 to many) or reconstructing
217  //- (many to 1)
218  static void writeProcAddressing
219  (
220  const fvMesh& procMesh,
221  const mapDistributePolyMesh& map,
222  const bool decompose,
223  refPtr<fileOperation>& writeHandler
224  );
225 };
226 
227 
228 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
229 
230 } // End namespace Foam
231 
232 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
233 
234 #ifdef NoRepository
235  #include "fvMeshToolsTemplates.C"
236 #endif
237 
238 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
239 
240 #endif
241 
242 // ************************************************************************* //
label nPatches
Definition: readKivaGrid.H:396
static void reorderPatches(fvMesh &, const labelList &oldToNew, const label nPatches, const bool validBoundary)
Reorder and remove trailing patches.
Definition: fvMeshTools.C:317
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
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
Foam::word regionName(Foam::polyMesh::defaultRegion)
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
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:446
static void createDummyFvMeshFiles(const objectRegistry &parent, const word &regionName, const bool verbose=false)
Create additional fvSchemes/fvSolution files.
Definition: fvMeshTools.C:1218
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:1183
A collection of tools for operating on an fvMesh.
Definition: fvMeshTools.H:53
static void writeProcAddressing(const fvMesh &procMesh, const mapDistributePolyMesh &map, const bool decompose, refPtr< fileOperation > &writeHandler)
Write addressing if decomposing (1 to many) or reconstructing (many to 1)
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:79
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
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
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:171
static autoPtr< mapDistributePolyMesh > readProcAddressing(const fvMesh &procMesh, const autoPtr< fvMesh > &baseMeshPtr)
Read procAddressing components (reconstructing)
static void setBasicGeometry(fvMesh &mesh)
Set the fvGeometryScheme to basic (to avoid parallel communication)
Definition: fvMeshTools.C:425
static labelList removeEmptyPatches(fvMesh &, const bool validBoundary)
Remove zero sized patches. All but processor patches are.
Definition: fvMeshTools.C:363
Namespace for OpenFOAM.