regionProperties.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
6  \\/ M anipulation |
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 \*---------------------------------------------------------------------------*/
25 
26 #include "regionProperties.H"
27 #include "IOdictionary.H"
28 #include "argList.H"
29 #include "polyMesh.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 Foam::regionProperties::regionProperties(const Time& runTime)
34 :
36  (
38  (
39  IOobject
40  (
41  "regionProperties",
42  runTime.time().constant(),
43  runTime.db(),
44  IOobject::MUST_READ_IF_MODIFIED,
45  IOobject::NO_WRITE
46  )
47  ).lookup("regions")
48  )
49 {}
50 
51 
52 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
53 
55 {}
56 
57 
58 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
59 
61 {
62  return
63  regionName == polyMesh::defaultRegion
64  ? word::null
65  : regionName;
66 }
67 
68 
70 {
71  const bool allRegions = args.optionFound("allRegions");
72 
73  wordList regionNames;
74 
75  if (allRegions)
76  {
77  const regionProperties rp(runTime);
79  {
80  const wordList& regions = iter();
81  forAll(regions, i)
82  {
83  if (findIndex(regionNames, regions[i]) == -1)
84  {
85  regionNames.append(regions[i]);
86  }
87  }
88  }
89  }
90  else
91  {
93  if (args.optionReadIfPresent("region", regionName))
94  {
95  regionNames = wordList(1, regionName);
96  }
97  else
98  {
99  regionNames = wordList(1, polyMesh::defaultRegion);
100  }
101  }
102 
103  return regionNames;
104 }
105 
106 
107 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
Foam::word regionName
engineTime & runTime
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:309
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:108
Simple class to hold region information for coupled region simulations.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:198
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
const word & regionDir(const word &regionName)
stressControl lookup("compactNormalStress") >> compactNormalStress
A class for handling words, derived from string.
Definition: word.H:59
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
void append(const T &)
Append an element at the end of the list.
Definition: ListI.H:184
regionProperties rp(runTime)
static const word null
An empty word.
Definition: word.H:77
An STL-conforming hash table.
Definition: HashTable.H:62
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
List< word > wordList
A List of words.
Definition: fileName.H:54
~regionProperties()
Destructor.
Foam::argList args(argc, argv)
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
wordList selectRegionNames(const argList &args, const Time &runTime)