Loading...
Searching...
No Matches
surfacePatch.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-2013 OpenFOAM Foundation
9 Copyright (C) 2015-2024 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 surfacePatch
29
30Group
31 grpSurfaceUtilities
32
33Description
34 Patches (regionises) a surface using a user-selectable method.
35
36 The current methods are either based on a geometric feature angle
37 (a replacement for the surfaceAutoPatch functionality) or on intersecting
38 a set of searchableSurfaces - this will re-triangulate the intersecting
39 triangles and regonise the resulting triangles according to being
40 inside/outside the surface.
41
42\*---------------------------------------------------------------------------*/
43
44#include "triSurface.H"
45#include "argList.H"
46#include "Time.H"
47#include "triSurfaceMesh.H"
48#include "searchableSurfaces.H"
50
51using namespace Foam;
52
53// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54// Main program:
55
56int main(int argc, char *argv[])
57{
59 (
60 "Add patches (regions) to a surface with a user-selectable method"
61 );
63 argList::addOption("dict", "file", "Alternative surfacePatchDict");
64
65 #include "setRootCase.H"
66 #include "createTime.H"
67
68 const word dictName("surfacePatchDict");
71
72
73 // Read geometry
74 // ~~~~~~~~~~~~~
75
76 searchableSurfaces allGeometry
77 (
79 (
80 "abc", // dummy name
81 runTime.constant(), // instance
83 runTime, // registry
86 ),
87 meshDict.subDict("geometry"),
88 meshDict.getOrDefault("singleRegionName", true)
89 );
90
91
92 const dictionary& surfacesDict = meshDict.subDict("surfaces");
93
94 for (const entry& dEntry : surfacesDict)
95 {
96 if (dEntry.isDict())
97 {
98 const word& surfName = dEntry.keyword();
99 const dictionary& surfDict = dEntry.dict();
100
101 // Look up surface
102 searchableSurface& surf = allGeometry[surfName];
103
104
105 bool changed = false;
106
107 // Check for modifier on global level
108 if (surfDict.found("type"))
109 {
111 (
113 (
114 surfDict.get<word>("type"),
115 allGeometry,
116 surfDict
117 )
118 );
119
120 if (modifier().modify(identity(surf.regions().size()), surf))
121 {
122 changed = true;
123 }
124 }
125
126 // Check for modifier on a per-region level
127 if (surfDict.found("regions"))
128 {
129 const dictionary& regionsDict = surfDict.subDict("regions");
130
131 for (const entry& e : regionsDict)
132 {
133 const wordRe regionName(e.keyword());
134 const dictionary& regionDict = e.dict();
135
136 labelList regionIDs
137 (
139 );
140
142 (
144 (
145 regionDict.get<word>("type"),
146 allGeometry,
147 regionDict
148 )
149 );
150
151 if (modifier().modify(regionIDs, surf))
152 {
153 changed = true;
154 }
155 }
156 }
157
158
159 if (changed)
160 {
161 const word oldName(surf.name());
162 surf.rename(oldName.lessExt() + "_patched." + oldName.ext());
163
164 Info<< "Writing repatched surface " << oldName << " to "
165 << surf.name() << nl << endl;
166
167 surf.write();
168 }
169 else
170 {
171 Info<< "Surface " << surf.name() << " unchanged" << nl << endl;
172 }
173 }
174 }
175
176 Info<< "End\n" << endl;
177
178 return 0;
179}
180
181
182// ************************************************************************* //
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
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
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
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T. FatalIOError if not found, or if the number of tokens is incorrect.
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
virtual void rename(const word &newName)
Rename.
static autoPtr< searchableSurfaceModifier > New(const word &type, const searchableSurfaces &, const dictionary &dict)
Return a reference to the selected searchableSurfaceModifier.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
virtual const wordList & regions() const =0
Names of regions.
Container for searchableSurfaces. The collection is specified as a dictionary. For example,...
static word meshSubDir
Return the mesh sub-directory name (usually "triSurface").
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
static labelList matching(const wordRe &select, const UList< StringType > &input, const bool invert=false)
Determine the list indices for all matches.
A class for handling words, derived from Foam::string.
Definition word.H:66
engineTime & runTime
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
const IOdictionary & meshDict
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
IOobject dictIO
volScalarField & e