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-2022 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  surfacePatch
29 
30 Group
31  grpSurfaceUtilities
32 
33 Description
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 
51 using namespace Foam;
52 
53 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
54 // Main program:
55 
56 int 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  (
78  IOobject
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 keyType& regionName = e.keyword();
134  const dictionary& regionDict = e.dict();
135 
137  (
139  (
140  regionDict.get<word>("type"),
141  allGeometry,
142  regionDict
143  )
144  );
145 
146  labelList regionIDs =
147  findStrings(regionName, surf.regions());
148 
149  if (modifier().modify(regionIDs, surf))
150  {
151  changed = true;
152  }
153  }
154  }
155 
156 
157  if (changed)
158  {
159  const word oldName(surf.name());
160  surf.rename(oldName.lessExt() + "_patched." + oldName.ext());
161 
162  Info<< "Writing repatched surface " << oldName << " 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 // ************************************************************************* //
const IOdictionary & meshDict
A class for handling keywords in dictionaries.
Definition: keyType.H:66
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:462
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
virtual const wordList & regions() const =0
Names of regions.
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
const word dictName("faMeshDefinition")
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
static void noParallel()
Remove the parallel options.
Definition: argList.C:584
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
Ignore writing from objectRegistry::writeObject()
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
static word meshSubDir
Return the mesh sub-directory name (usually "triSurface")
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:104
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
static autoPtr< searchableSurfaceModifier > New(const word &type, const searchableSurfaces &, const dictionary &dict)
Return a reference to the selected searchableSurfaceModifier.
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
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...
Definition: labelLists.C:44
A class for handling words, derived from Foam::string.
Definition: word.H:63
virtual bool write(const bool writeOnProc=true) const
Write using setting from DB.
Container for searchableSurfaces. The collection is specified as a dictionary. For example...
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
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
virtual void rename(const word &newName)
Rename.
Definition: regIOobject.C:484
Foam::word regionName(args.getOrDefault< word >("region", Foam::polyMesh::defaultRegion))
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject dictIO
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T, or return the given default value. FatalIOError if it is found and the number of...
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
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:92
Namespace for OpenFOAM.
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63