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 | Copyright (C) 2011-2013 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  surfacePatch
26 
27 Description
28  Patches (regionises) a surface using a user-selectable method.
29 
30  The current methods are either based on a geometric feature angle
31  (a replacement for the surfaceAutoPatch functionality) or on intersecting
32  a set of searchableSurfaces - this will re-triangulate the intersecting
33  triangles and regonise the resulting triangles according to being
34  inside/outside the surface.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "triSurface.H"
39 #include "argList.H"
40 #include "Time.H"
41 #include "triSurfaceMesh.H"
42 #include "searchableSurfaces.H"
44 
45 using namespace Foam;
46 
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
48 // Main program:
49 
50 int main(int argc, char *argv[])
51 {
52  argList::validArgs.clear();
54  #include "addDictOption.H"
55 
56  #include "setRootCase.H"
57  #include "createTime.H"
58 
59  const word dictName("surfacePatchDict");
61  const IOdictionary meshDict(dictIO);
62 
63 
64  // Read geometry
65  // ~~~~~~~~~~~~~
66 
67  searchableSurfaces allGeometry
68  (
69  IOobject
70  (
71  "abc", // dummy name
72  runTime.constant(), // instance
74  runTime, // registry
77  ),
78  meshDict.subDict("geometry"),
79  meshDict.lookupOrDefault("singleRegionName", true)
80  );
81 
82 
83  const dictionary& surfacesDict = meshDict.subDict("surfaces");
84 
85  forAllConstIter(dictionary, surfacesDict, surfacesIter)
86  {
87  if (surfacesIter().isDict())
88  {
89  const word& surfName = surfacesIter().keyword();
90  const dictionary& surfDict = surfacesIter().dict();
91 
92  // Look up surface
93  searchableSurface& surf = allGeometry[surfName];
94 
95 
96  bool changed = false;
97 
98  // Check for modifier on global level
99  if (surfDict.found("type"))
100  {
102  (
104  (
105  surfDict.lookup("type"),
106  allGeometry,
107  surfDict
108  )
109  );
110 
111  if (modifier().modify(identity(surf.regions().size()), surf))
112  {
113  changed = true;
114  }
115  }
116 
117  // Check for modifier on a per-region level
118  if (surfDict.found("regions"))
119  {
120  const dictionary& regionsDict = surfDict.subDict("regions");
121  forAllConstIter(dictionary, regionsDict, regionsIter)
122  {
123  const dictionary& regionDict = regionsIter().dict();
124  const keyType& regionName = regionsIter().keyword();
125 
127  (
129  (
130  regionDict.lookup("type"),
131  allGeometry,
132  regionDict
133  )
134  );
135 
136  labelList regionIDs =
137  findStrings(regionName, surf.regions());
138  if (modifier().modify(regionIDs, surf))
139  {
140  changed = true;
141  }
142  }
143  }
144 
145 
146  if (changed)
147  {
148  const fileName name(surf.name());
149  surf.rename(name.lessExt() + "_patched." + name.ext());
150 
151  Info<< "Writing repatched surface " << name << " to "
152  << surf.name() << nl << endl;
153 
154  surf.write();
155  }
156  else
157  {
158  Info<< "Surface " << surf.name() << " unchanged" << nl << endl;
159  }
160  }
161  }
162 
163  Info<< "End\n" << endl;
164 
165  return 0;
166 }
167 
168 
169 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
setSystemRunTimeDictionaryIO.H
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
searchableSurfaceModifier.H
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::triSurfaceMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "triSurface")
Definition: triSurfaceMesh.H:143
forAllConstIter
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:39
addDictOption.H
dictName
const word dictName("particleTrackDict")
searchableSurfaces.H
Foam::keyType
A class for handling keywords in dictionaries.
Definition: keyType.H:56
regionName
Foam::word regionName
Definition: createNamedDynamicFvMesh.H:1
Foam::dictionary::found
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:304
Foam::searchableSurface::regions
virtual const wordList & regions() const =0
Names of regions.
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:66
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
setRootCase.H
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Foam::regIOobject::rename
virtual void rename(const word &newName)
Rename.
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: HashTable.H:59
Foam::searchableSurfaces
Container for searchableSurfaces.
Definition: searchableSurfaces.H:53
createTime.H
Foam::searchableSurfaceModifier::New
static autoPtr< searchableSurfaceModifier > New(const word &type, const searchableSurfaces &, const dictionary &dict)
Return a reference to the selected searchableSurfaceModifier.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
Foam::dictionary::subDict
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:631
triSurfaceMesh.H
dictIO
IOobject dictIO(dictName, runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47