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-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 Application
28  makeFaMesh
29 
30 Description
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 
35 Original Authors
36  Zeljko Tukovic, FAMENA
37  Hrvoje Jasak, Wikki Ltd.
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #include "Time.H"
42 #include "argList.H"
43 #include "OSspecific.H"
44 #include "faMesh.H"
45 #include "faMeshTools.H"
46 #include "IOdictionary.H"
47 #include "IOobjectList.H"
48 #include "areaFields.H"
49 #include "edgeFields.H"
50 #include "faFieldDecomposer.H"
51 #include "faMeshReconstructor.H"
52 #include "faMeshSubset.H"
53 #include "PtrListOps.H"
54 #include "foamVtkLineWriter.H"
55 #include "foamVtkIndPatchWriter.H"
56 #include "syncTools.H"
57 #include "OBJstream.H"
58 
59 using namespace Foam;
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 int 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 "setRootCase.H"
108  #include "createTime.H"
109  #include "createNamedPolyMesh.H"
110 
111  const bool doDecompose = !args.found("no-decompose");
112  const bool doDecompFields = !args.found("no-fields");
113 
114  if (!doDecompose)
115  {
116  Info<< "Skip decompose of finiteArea mesh/fields" << nl;
117  }
118  else if (!doDecompFields)
119  {
120  Info<< "Skip decompose of finiteArea fields" << nl;
121  }
122 
123  // Reading faMeshDefinition dictionary
124  #include "findMeshDefinitionDict.H"
125 
126  // Inject/overwrite name for optional 'empty' patch
127  word patchName;
128  if (args.readIfPresent("empty-patch", patchName))
129  {
130  meshDefDict.add("emptyPatch", patchName, true);
131  }
132 
133  // Preliminary checks
134  #include "checkPatchTopology.H"
135 
136  // Create
137  faMesh aMesh(mesh, meshDefDict);
138 
139  // Mesh information (less verbose)
141 
142  if (args.found("write-edges-obj"))
143  {
144  #include "faMeshWriteEdgesOBJ.H"
145  }
146 
147  if (args.found("write-vtk"))
148  {
149  #include "faMeshWriteVTK.H"
150  }
151 
152  if (args.dryRun())
153  {
154  Info<< "\ndry-run: not writing mesh or decomposing fields\n" << nl;
155  }
156  else
157  {
158  // Set the precision of the points data to 10
160 
161  Info<< nl << "Write finite area mesh." << nl;
162  aMesh.write();
163 
164  Info<< endl;
165  #include "decomposeFaFields.H"
166  }
167 
168  Info<< "\nEnd\n" << endl;
169 
170  return 0;
171 }
172 
173 // ************************************************************************* //
Finite area mesh (used for 2-D non-Euclidian finite area method) defined using a patch of faces on a ...
Definition: faMesh.H:87
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
IOdictionary & meshDefDict
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static unsigned int defaultPrecision() noexcept
Return the default precision.
Definition: IOstream.H:423
static void addBoolOption(const word &optName, const string &usage="", bool advanced=false)
Add a bool option to validOptions with usage information.
Definition: argList.C:374
Functions to operate on Pointer Lists.
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition: dictionary.C:625
Required Classes.
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
Required Classes.
dynamicFvMesh & mesh
A class for handling words, derived from Foam::string.
Definition: word.H:63
static void addDryRunOption(const string &usage, bool advanced=false)
Enable a &#39;dry-run&#39; bool option, with usage information.
Definition: argList.C:504
int dryRun() const noexcept
Return the dry-run flag.
Definition: argListI.H:109
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:385
Required Classes.
static void printMeshChecks(const faMesh &mesh, const int verbose=1)
Report mesh information.
messageStream Info
Information stream (stdout output on master, null elsewhere)
bool readIfPresent(const word &optName, T &val) const
Read a value from the named option if present.
Definition: argListI.H:316
Foam::argList args(argc, argv)
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:171
Namespace for OpenFOAM.