Loading...
Searching...
No Matches
makeFaMesh.C
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) 2016-2017 Wikki Ltd
9 Copyright (C) 2021-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
27Application
28 makeFaMesh
29
30Description
31 A mesh generator for finiteArea mesh.
32 When called in parallel, it will also try to act like decomposePar,
33 create procAddressing and decompose serial finite-area fields.
34
35Original Authors
36 Zeljko Tukovic, FAMENA
37 Hrvoje Jasak, Wikki Ltd.
38
39\*---------------------------------------------------------------------------*/
40
41#include "Time.H"
42#include "argList.H"
43#include "faMesh.H"
44#include "faMeshTools.H"
45#include "IOdictionary.H"
46#include "IOobjectList.H"
47#include "areaFields.H"
48#include "edgeFields.H"
49#include "faFieldDecomposer.H"
50#include "faMeshReconstructor.H"
51#include "faMeshSubset.H"
52#include "PtrListOps.H"
53#include "foamVtkLineWriter.H"
55#include "regionProperties.H"
56#include "syncTools.H"
57#include "OBJstream.H"
58
59using namespace Foam;
60
61// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62
63int main(int argc, char *argv[])
64{
66 (
67 "A mesh generator for finiteArea mesh"
68 );
70 (
71 "empty-patch",
72 "name",
73 "Specify name for a default empty patch",
74 false // An advanced option, but not enough to worry about that
75 );
76 argList::addOption("dict", "file", "Alternative faMeshDefinition");
77
79 (
80 "Create but do not write"
81 );
83 (
84 "no-decompose",
85 "Suppress procAddressing creation and field decomposition"
86 " (parallel)"
87 );
89 (
90 "no-fields",
91 "Suppress field decomposition"
92 " (parallel)"
93 );
95 (
96 "write-vtk",
97 "Write mesh as a vtp (vtk) file for display or debugging"
98 );
100 (
101 "write-edges-obj",
102 "Write mesh edges as obj files (one per processor)",
103 true // advanced option (debugging only)
104 );
105
106 #include "addRegionOption.H"
107 #include "addAllFaRegionOptions.H"
108
109 #include "setRootCase.H"
110 #include "createTime.H"
111 #include "createNamedPolyMesh.H"
112
113 // Handle area region selections
114 #include "getAllFaRegionOptions.H"
115
116 const bool doDecompose = !args.found("no-decompose");
117 const bool doDecompFields = !args.found("no-fields");
118
119 if (!doDecompose)
120 {
121 Info<< "Skip decompose of finiteArea mesh/fields" << nl;
122 }
123 else if (!doDecompFields)
124 {
125 Info<< "Skip decompose of finiteArea fields" << nl;
126 }
127
128 // ------------------------------------------------------------------------
129
130 for (const word& areaRegionName : areaRegionNames)
131 {
132 // Reading faMeshDefinition dictionary
133 #include "findMeshDefinitionDict.H"
134
136 {
137 if (args.dryRun())
138 {
139 break;
140 }
141 else
142 {
144 << "Did not find area-mesh definition"<< nl
145 << exit(FatalError);
146 }
147 }
148
149 auto& meshDefDict = (*faMeshDefinitionPtr);
150
151
152 // Inject/overwrite name for optional 'empty' patch
153 if (word name; args.readIfPresent("empty-patch", name))
154 {
155 meshDefDict.add("emptyPatch", name, true);
156 }
157
158 // Preliminary checks
159 #include "checkPatchTopology.H"
160
161 Info<< "Create area-mesh";
163 {
164 Info<< " [" << areaRegionName << "]";
165 }
166 Info<< " with polyMesh at time = " << runTime.timeName() << nl;
167
168 // Create
169 faMesh aMesh(areaRegionName, mesh, meshDefDict);
170
171 // Mesh information (less verbose)
173
174 if (args.found("write-edges-obj"))
175 {
176 #include "faMeshWriteEdgesOBJ.H"
177 }
178
179 if (args.found("write-vtk"))
180 {
181 #include "faMeshWriteVTK.H"
182 }
183
184 if (args.dryRun())
185 {
186 Info<< "\ndry-run: not writing mesh or decomposing fields\n" << nl;
187 }
188 else
189 {
190 // More precision (for points data)
192
193 Info<< nl << "Write finite area mesh";
194 if (const word& name = aMesh.regionName(); !name.empty())
195 {
196 Info<< " [" << name << "]";
197 }
198 Info<< nl;
199
200 aMesh.write();
201
202 Info<< endl;
203 #include "decomposeFaFields.H"
204 }
205 }
206
207 Info<< "\nEnd\n" << endl;
208
209 return 0;
210}
211
212// ************************************************************************* //
Functions to operate on Pointer Lists.
Required Classes.
Required Classes.
static unsigned int minPrecision(unsigned int prec) noexcept
Set the minimum default precision.
Definition IOstream.H:459
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a 'dry-run' bool option, with usage information.
Definition argList.C:519
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition argList.C:389
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Add an option to validOptions with usage information.
Definition argList.C:400
static void addNote(const string &note)
Add extra notes for the usage information.
Definition argList.C:477
static void printMeshChecks(const faMesh &mesh, const int verbose=1)
Report mesh information.
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition faMesh.H:140
static const word & regionName(const word &region)
The mesh region name or word::null if polyMesh::defaultRegion.
Definition polyMesh.C:796
A class for handling words, derived from Foam::string.
Definition word.H:66
dynamicFvMesh & mesh
engineTime & runTime
Foam::word areaRegionName(args.getOrDefault< word >("area-region", Foam::polyMesh::defaultRegion))
Required Classes.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
Required Classes.
autoPtr< IOdictionary > faMeshDefinitionPtr
auto & name
wordList areaRegionNames
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)