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-2020 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{
58 argList::addNote
59 (
60 "Add patches (regions) to a surface with a user-selectable method"
61 );
62 argList::noParallel();
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
82 triSurfaceMesh::meshSubDir, // local
83 runTime, // registry
84 IOobject::MUST_READ,
85 IOobject::NO_WRITE
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 (
112 searchableSurfaceModifier::New
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 keyType& regionName = e.keyword();
134 const dictionary& regionDict = e.dict();
135
137 (
138 searchableSurfaceModifier::New
139 (
140 regionDict.get<word>("type"),
141 allGeometry,
142 regionDict
143 )
144 );
145
146 labelList regionIDs =
148
149 if (modifier().modify(regionIDs, surf))
150 {
151 changed = true;
152 }
153 }
154 }
155
156
157 if (changed)
158 {
159 const fileName name(surf.name());
160 surf.rename(name.lessExt() + "_patched." + name.ext());
161
162 Info<< "Writing repatched surface " << name << " to "
163 << surf.name() << nl << endl;
164
165 surf.write();
166 }
167 else
168 {
169 Info<< "Surface " << surf.name() << " unchanged" << nl << endl;
170 }
171 }
172 }
173
174 Info<< "End\n" << endl;
175
176 return 0;
177}
178
179
180// ************************************************************************* //
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:57
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
A class for handling file names.
Definition: fileName.H:76
A class for handling keywords in dictionaries.
Definition: keyType.H:71
virtual bool write(const bool valid=true) const
Write using setting from DB.
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:417
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,...
A class for handling words, derived from Foam::string.
Definition: word.H:68
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
word lessExt() const
Return word without extension (part before last .)
Definition: word.C:113
engineTime & runTime
Foam::word regionName(Foam::polyMesh::defaultRegion)
const IOdictionary & meshDict
const word dictName("faMeshDefinition")
Namespace for OpenFOAM.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
Definition: labelList.C:38
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
Definition: stringListOps.H:87
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
IOobject dictIO
volScalarField & e
Definition: createFields.H:11