Loading...
Searching...
No Matches
blockMeshTools.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) 2016 OpenFOAM Foundation
9 Copyright (C) 2021 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
30
31// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
32
33namespace Foam
34{
35
36static inline const Foam::entry* resolveLabel(const entry& e, const label val)
37{
38 return
39 (
40 (e.isStream() && e.stream().front().isLabel(val))
41 ? &e : nullptr
42 );
44
45} // End namespace Foam
46
47
48// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49
51(
52 Istream& is,
53 label& val,
54 const dictionary& dict
55)
56{
57 token t(is);
58 if (t.isLabel())
59 {
60 val = t.labelToken();
61 }
62 else if (t.isWord())
63 {
64 const word& varName = t.wordToken();
65 const entry* eptr =
66 dict.findScoped(varName, keyType::REGEX_RECURSIVE);
67
68 if (eptr)
69 {
70 // Read as label
71 val = Foam::readLabel(eptr->stream());
72 }
73 else
74 {
76 << "Undefined variable "
77 << varName << ". Valid variables are " << dict
78 << exit(FatalIOError);
79 }
80 }
81 else
82 {
84 << "Illegal token " << t.info()
85 << " when trying to read label"
87 }
88
89 is.fatalCheck(FUNCTION_NAME);
90}
91
92
94(
95 Istream& is,
96 const dictionary& dict
97)
99 label val(0);
100 read(is, val, dict);
101 return val;
102}
103
104
106(
107 Ostream& os,
108 const label val,
109 const dictionary& dict
110)
111{
112 for (const entry& e : dict)
113 {
114 const entry* eptr = resolveLabel(e, val);
115 if (eptr)
116 {
117 os << eptr->keyword();
118 return;
119 }
120 }
121 os << val;
122}
123
124
126(
127 const dictionary& dict,
128 const label val
129)
130{
131 for (const entry& e : dict)
132 {
133 const entry* eptr = resolveLabel(e, val);
134 if (eptr)
135 {
136 return eptr;
137 }
138 }
139
140 return nullptr;
141}
142
143
144// ************************************************************************* //
bool fatalCheck(const char *operation) const
Check IOstream status for given operation.
Definition IOstream.C:51
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
virtual ITstream & stream() const =0
Return token stream, if entry is a primitive entry.
const keyType & keyword() const noexcept
Return keyword.
Definition entry.H:231
@ REGEX_RECURSIVE
Definition keyType.H:88
A token holds an item read from Istream.
Definition token.H:70
bool isLabel() const noexcept
Integral token is convertible to Foam::label.
Definition tokenI.H:843
label labelToken() const
Return integer type as label value or Error.
Definition tokenI.H:869
const word & wordToken() const
Return const reference to the word contents.
Definition tokenI.H:1022
bool isWord() const noexcept
Token is word-variant (WORD, DIRECTIVE).
Definition tokenI.H:1004
InfoProxy< token > info() const noexcept
Return info proxy, for printing token information to a stream.
Definition token.H:1253
A class for handling words, derived from Foam::string.
Definition word.H:66
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
#define FUNCTION_NAME
void write(Ostream &, const label val, const dictionary &)
Write with dictionary lookup.
void read(Istream &, label &val, const dictionary &)
In-place read with dictionary lookup.
const entry * findEntry(const dictionary &dict, const label val)
Linear search for labelled entry, nullptr if not found.
Namespace for OpenFOAM.
label readLabel(const char *buf)
Parse entire buffer as a label, skipping leading/trailing whitespace.
Definition label.H:63
static const Foam::entry * resolveLabel(const entry &e, const label val)
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
dictionary dict
volScalarField & e