stitchMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2023-2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  stitchMesh
26 
27 Description
28  Utility to stitch or conform pairs of patches,
29  converting the patch faces either into internal faces
30  or conformal faces or another patch.
31 
32 Usage
33  \b stitchMesh (<list of patch pairs>)
34 
35  E.g. to stitch patches \c top1 to \c top2 and \c bottom1 to \c bottom2
36  stitchMesh "((top1 top2) (bottom1 bottom2))"
37 
38  Options:
39  - \par -overwrite \n
40  Replace the old mesh with the new one, rather than writing the new one
41  into a separate time directory
42 
43  - \par -region <name>
44  Specify an alternative mesh region.
45 
46  - \par -fields
47  Update vol and point fields
48 
49  - \par -tol
50  Merge tolerance relative to local edge length (default 1e-4)
51 
52 See also
53  Foam::mergePatchPairs
54 
55 \*---------------------------------------------------------------------------*/
56 
57 #include "argList.H"
58 #include "fvMesh.H"
59 #include "timeSelector.H"
60 #include "ReadFields.H"
61 #include "volFields.H"
62 #include "pointFields.H"
63 #include "mergePatchPairs.H"
64 
65 using namespace Foam;
66 
67 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
68 
69 int main(int argc, char *argv[])
70 {
71  timeSelector::addOptions(true, false);
72 
74  (
75  "Stitch the faces on the specified patch pairs\n"
76  "converting the overlapping patch faces into internal faces.\n"
77  );
78 
80  #include "addOverwriteOption.H"
81  #include "addRegionOption.H"
83  (
84  "fields",
85  "update fields"
86  );
88  (
89  "tol",
90  "scalar",
91  "merge tolerance relative to local edge length (default 1e-4)"
92  );
93 
94  argList::validArgs.append("patchPairs");
95 
96  #include "setRootCase.H"
98 
99  // Select time if specified
101 
103 
104  const scalar snapTol = args.optionLookupOrDefault("tol", 1e-4);
105  const bool overwrite = args.optionFound("overwrite");
106  const bool fields = args.optionFound("fields");
107 
108  const List<Pair<word>> patchPairNames((IStringStream(args[1])()));
109 
110  const word oldInstance = mesh.pointsInstance();
111 
112  // Search for list of objects for this time
113  IOobjectList objects(mesh, runTime.name());
114 
115  if (fields) Info<< "Reading geometric fields" << nl << endl;
116 
117  #include "readVolFields.H"
118  #include "readPointFields.H"
119 
120  Info<< endl;
121 
122  if (!overwrite)
123  {
124  runTime++;
125  }
126 
127  // Stitch all the patch-pairs
128  mergePatchPairs(mesh, patchPairNames, snapTol);
129 
130  if (overwrite)
131  {
132  mesh.setInstance(oldInstance);
133  }
134 
135  Info<< "Writing mesh to " << mesh.facesInstance() << endl;
136  mesh.write();
137 
138  Info<< "End\n" << endl;
139 
140  return 0;
141 }
142 
143 
144 // ************************************************************************* //
Field reading functions for post-processing utilities.
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:53
Input from memory buffer stream.
Definition: IStringStream.H:52
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
virtual Ostream & write(const char)=0
Write character.
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static void noParallel()
Remove the parallel options.
Definition: argList.C:175
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
T optionLookupOrDefault(const word &opt, const T &deflt) const
Read a value from the named option if present.
Definition: argListI.H:243
Class to stitch mesh by merging patch-pairs.
static void addOptions(const bool constant=true, const bool withZero=false)
Add the options handled by timeSelector to argList::validOptions.
Definition: timeSelector.C:114
static instantList selectIfPresent(Time &runTime, const argList &args)
If any time option provided return the set of times (as select0)
Definition: timeSelector.C:283
A class for handling words, derived from string.
Definition: word.H:62
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:228
Namespace for OpenFOAM.
const doubleScalar e
Definition: doubleScalar.H:106
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
static const char nl
Definition: Ostream.H:266
objects
Foam::argList args(argc, argv)