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 -------------------------------------------------------------------------------
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 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 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:63
Foam::word::lessExt
word lessExt() const
Definition: word.C:106
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:191
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:165
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:63
Foam::fileName
A class for handling file names.
Definition: fileName.H:71
setSystemRunTimeDictionaryIO.H
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryI.H:80
dictName
const word dictName("faMeshDefinition")
Foam::argList::addNote
static void addNote(const string &note)
Definition: argList.C:405
searchableSurfaceModifier.H
Foam::endl
Ostream & endl(Ostream &os)
Definition: Ostream.H:381
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:100
Foam::word::ext
word ext() const
Definition: word.C:119
triSurface.H
searchableSurfaces.H
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:66
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::regIOobject::write
virtual bool write(const bool valid=true) const
Definition: regIOobjectWrite.C:125
Foam::searchableSurface::regions
virtual const wordList & regions() const =0
Foam::Info
messageStream Info
argList.H
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:65
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionary.C:453
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
dictIO
IOobject dictIO
Definition: setConstantMeshDictionaryIO.H:1
Foam
Definition: atmBoundaryLayer.C:26
Foam::findStrings
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Definition: stringListOps.H:83
Foam::IOobject::name
const word & name() const noexcept
Definition: IOobjectI.H:58
Time.H
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:49
setRootCase.H
Foam::nl
constexpr char nl
Definition: Ostream.H:424
Foam::regIOobject::rename
virtual void rename(const word &newName)
Definition: regIOobject.C:408
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
Foam::searchableSurfaces
Container for searchableSurfaces. The collection is specified as a dictionary. For example,...
Definition: searchableSurfaces.H:88
Foam::triSurfaceMesh::meshSubDir
static word meshSubDir
Definition: triSurfaceMesh.H:170
Foam::constant::electromagnetic::e
const dimensionedScalar e
Definition: createFields.H:11
Foam::identity
labelList identity(const label len, label start=0)
Definition: labelList.C:31
createTime.H
Foam::name
word name(const expressions::valueTypeCode typeCode)
Definition: exprTraits.C:52
Foam::searchableSurfaceModifier::New
static autoPtr< searchableSurfaceModifier > New(const word &type, const searchableSurfaces &, const dictionary &dict)
Foam::argList::noParallel
static void noParallel()
Definition: argList.C:503
Foam::TimePaths::constant
const word & constant() const
Definition: TimePathsI.H:89
Foam::dictionary::getOrDefault
T getOrDefault(const word &keyword, const T &deflt, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:141
Foam::argList::addOption
static void addOption(const word &optName, const string &param="", const string &usage="", bool advanced=false)
Definition: argList.C:328
triSurfaceMesh.H
meshDict
const IOdictionary & meshDict
Definition: findBlockMeshDict.H:92
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:181