Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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
27Class
28 Foam::fvMeshTools
29
30Description
31 A collection of tools for operating on an fvMesh.
32
33SourceFiles
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
47namespace Foam
48{
49
50// Forward Declarations
51class fileOperation;
54/*---------------------------------------------------------------------------*\
55 Class fvMeshTools Declaration
56\*---------------------------------------------------------------------------*/
57
58class 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
115public:
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
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,
204 refPtr<fileOperation>& readHandler,
205 const bool verbose = true
206 );
207
208 //- Create additional fvSchemes/fvSolution files
209 static void createDummyFvMeshFiles
210 (
211 const objectRegistry& parent,
212 const word& regionName,
213 const bool verbose = false
214 );
215
216
217 //- Read procAddressing components (reconstructing)
219 (
220 const fvMesh& procMesh,
221 const fvMesh* baseMeshPtr
222 );
223
224 //- Write addressing if decomposing (1 to many) or reconstructing
225 //- (many to 1)
226 static void writeProcAddressing
227 (
228 const fvMesh& procMesh,
229 const mapDistributePolyMesh& map,
231 const bool decompose,
233 const fileName& writeInstance,
235 refPtr<fileOperation>& writeHandler
236 );
237
238
239 // Housekeeping
240
241 //- Read procAddressing components (reconstructing)
243 (
244 const fvMesh& procMesh,
245 const autoPtr<fvMesh>& baseMeshPtr
246 );
247};
248
249
250// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251
252} // End namespace Foam
253
254// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
255
256#ifdef NoRepository
257 #include "fvMeshToolsTemplates.C"
258#endif
259
260// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
261
262#endif
263
264// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A class for handling file names.
Definition fileName.H:75
An encapsulation of filesystem-related operations.
A collection of tools for operating on an fvMesh.
Definition fvMeshTools.H:54
static void reorderPatches(fvMesh &, const labelList &oldToNew, const label nPatches, const bool validBoundary)
Reorder and remove trailing patches.
static labelList removeEmptyPatches(fvMesh &, const bool validBoundary)
Remove zero sized patches. All but processor patches are.
static void createDummyFvMeshFiles(const objectRegistry &parent, const word &regionName, const bool verbose=false)
Create additional fvSchemes/fvSolution files.
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).
static autoPtr< mapDistributePolyMesh > readProcAddressing(const fvMesh &procMesh, const fvMesh *baseMeshPtr)
Read procAddressing components (reconstructing).
static void setBasicGeometry(fvMesh &mesh)
Set the fvGeometryScheme to basic (to avoid parallel communication).
static void writeProcAddressing(const fvMesh &procMesh, const mapDistributePolyMesh &map, const bool decompose, const fileName &writeInstance, refPtr< fileOperation > &writeHandler)
Write addressing if decomposing (1 to many) or reconstructing (many to 1).
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.
static void zeroPatchFields(fvMesh &mesh, const label patchi)
Change patchField to zero on registered fields.
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Registry of regIOobjects.
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
A class for managing references or pointers (no reference counting).
Definition refPtr.H:54
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
const auto & io
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62
label nPatches