Loading...
Searching...
No Matches
surfaceSplitByPatch.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2020-2023 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 surfaceSplitByPatch
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Writes surface regions to separate files.
35
36Usage
37 \b surfaceSplitByPatch [OPTION]
38
39 Options:
40 - \par -patches NAME | LIST
41 Specify single patch or multiple patches (name or regex) to extract
42 For example,
43 \verbatim
44 -patches top
45 -patches '( front \".*back\" )'
46 \endverbatim
47
48 - \par -exclude-patches NAME | LIST
49 Exclude single or multiple patches (name or regex) from extracting.
50 For example,
51 \verbatim
52 -exclude-patches '( inlet_1 inlet_2 "proc.*" )'
53 \endverbatim
54
55\*---------------------------------------------------------------------------*/
56
57#include "argList.H"
58#include "MeshedSurfaces.H"
59#include "stringListOps.H" // For stringListOps::findMatching()
61
62using namespace Foam;
63
64// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65
66int main(int argc, char *argv[])
67{
69 (
70 "Write surface mesh regions to separate files"
71 );
74 (
75 "patches",
76 "wordRes",
77 "Specify single patch or multiple patches to extract\n"
78 "Eg, 'top' or '( front \".*back\" )'"
79 );
81 (
82 "exclude-patches",
83 "wordRes",
84 "Exclude single or multiple patches (name or regex) from extracting.\n"
85 "Eg, 'outlet' or '( inlet \".*Wall\" )'"
86 );
87 argList::addOptionCompat("exclude-patches", {"excludePatches", 2306});
88
89 argList::addArgument("input", "The input surface file");
90
91 argList args(argc, argv);
92
93 const auto surfName = args.get<fileName>(1);
94
95 const fileName surfBase(surfName.lessExt());
96
97 const word extension(surfName.ext());
98
99
100 Info<< nl
101 << "Read surface from " << surfName << " ..." << nl << endl;
102
103 meshedSurface surf(surfName);
104
105 const surfZoneList& zones = surf.surfZones();
106
107 Info<< " " << surf.size() << " faces with "
108 << zones.size() << " zones" << nl << nl;
109
110
111 wordRes includePatches, excludePatches;
112
113 if (args.readListIfPresent<wordRe>("patches", includePatches))
114 {
115 Info<< "Including patches " << flatOutput(includePatches)
116 << nl << endl;
117 }
118 if (args.readListIfPresent<wordRe>("exclude-patches", excludePatches))
119 {
120 Info<< "Excluding patches " << flatOutput(excludePatches)
121 << nl << endl;
122 }
123
124 // Identity if both include/exclude lists are empty
125 const labelList zoneIndices
126 (
128 (
129 zones,
130 includePatches,
131 excludePatches,
133 )
134 );
135
136
137 Info<< "Writing regions to "
138 << zoneIndices.size() << " separate files ..." << nl << endl;
139
140
141 // Faces to subset
142 bitSet includeMap(surf.size());
143
144 for (const label zonei : zoneIndices)
145 {
146 const surfZone& zn = zones[zonei];
147
148 includeMap.reset();
149 includeMap.set(zn.range());
150
151 word patchName(zn.name());
152
153 if (patchName.empty())
154 {
155 // In case people expect the same names as with triSurface
156 patchName = geometricSurfacePatch::defaultName(zonei);
157 }
158
159 fileName outFile(surfBase + '_' + patchName + '.' + extension);
160
161 Info<< " Zone " << zonei << " (" << zn.size() << " faces) "
162 << patchName
163 << " to file " << outFile << nl;
164
165 // Subset and write
166 surf.subsetMesh(includeMap).write(outFile);
167 }
168
169 Info<< "\nEnd\n" << endl;
170
171 return 0;
172}
173
174
175// ************************************************************************* //
bool set(const label i, bool val=true)
A bitSet::set() method for a list of bool.
Definition List.H:469
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
Extract command arguments and options from the supplied argc and argv parameters.
Definition argList.H:119
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition argList.C:366
static void noParallel()
Remove the parallel options.
Definition argList.C:599
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 addOptionCompat(const word &optName, std::pair< const char *, int > compat)
Specify an alias for the option name.
Definition argList.C:433
A class for handling file names.
Definition fileName.H:75
static word defaultName(const label n=-1)
Default patch name: "patch" or "patchN".
const word & name() const noexcept
The patch/zone name.
A surface zone on a MeshedSurface.
Definition surfZone.H:55
label size() const
The size of this zone in the face list.
Definition surfZone.H:162
labelRange range() const
The start/size range of this zone.
Definition surfZone.H:178
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
A class for handling words, derived from Foam::string.
Definition word.H:66
labelList findMatching(const StringListType &input, const wordRes::filter &pred, AccessOp aop=identityOp())
Return ids for items with matching names.
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
List< surfZone > surfZoneList
List of surfZone.
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
MeshedSurface< face > meshedSurface
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
Foam::argList args(argc, argv)
Operations on lists of strings.
Extract name (as a word) from an object, typically using its name() method.
Definition word.H:341