regionProperties.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) 2012 OpenFOAM Foundation
9  Copyright (C) 2018-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 \*---------------------------------------------------------------------------*/
28 
29 #include "regionProperties.H"
30 #include "IOdictionary.H"
31 #include "Time.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 :
37  regionProperties(runTime, IOobject::MUST_READ_IF_MODIFIED)
38 {}
39 
40 
42 (
43  const Time& runTime,
45 )
46 {
47  HashTable<wordList>& props = *this;
48 
49  IOdictionary iodict
50  (
51  IOobject
52  (
53  "regionProperties",
54  runTime.time().constant(),
55  runTime.db(),
56  rOpt,
58  )
59  );
60 
61  if (IOobjectOption::isReadRequired(rOpt) || iodict.size())
62  {
63  iodict.readEntry("regions", props);
64  }
65 }
66 
67 
68 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
69 
70 Foam::label Foam::regionProperties::count() const
71 {
72  label n = 0;
73 
74  const HashTable<wordList>& props = *this;
75 
76  forAllConstIters(props, iter)
77  {
78  n += iter.val().size();
79  }
80 
81  return n;
82 }
83 
84 
86 {
87  wordList list(this->count());
88 
89  label n = 0;
90 
91  const HashTable<wordList>& props = *this;
92 
93  for (const word& grp : props.sortedToc())
94  {
95  for (const word& name : props[grp])
96  {
97  list[n] = name;
98  ++n;
99  }
100  }
101 
102  return list;
103 }
104 
105 
107 {
108  wordList list(this->count());
109 
110  label n = 0;
111 
112  const HashTable<wordList>& props = *this;
113 
114  forAllConstIters(props, iter)
115  {
116  for (const word& name : iter.val())
117  {
118  list[n] = name;
119  ++n;
120  }
121  }
122 
123  Foam::sort(list);
124 
125  return list;
126 }
127 
128 
129 // ************************************************************************* //
engineTime & runTime
Simple class to hold region information for coupled region simulations.
Ignore writing from objectRegistry::writeObject()
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const Time & time() const noexcept
Return time registry.
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:296
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:450
label count() const
Total count of all region names.
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
wordList sortedNames() const
The region names in sorted order.
bool isReadRequired() const noexcept
True if (MUST_READ | READ_MODIFIED) bits are set.
regionProperties(const Time &runTime)
Construct from Time.
List< word > wordList
List of word.
Definition: fileName.H:59
label n
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
forAllConstIters(mixture.phases(), phase)
Definition: pEqn.H:28
wordList names() const
The region names. Sorted by region type.
readOption
Enumeration defining read preferences.