DimensionedFieldFunction.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) 2026 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 
27 #include "DimensionedField.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class DimensionedFieldType>
33 (
34  const dictionary& dict,
35  DimensionedFieldType& field
36 )
37 :
38  field_(field)
39 {}
40 
41 
42 template<class DimensionedFieldType>
44 (
45  const DimensionedFieldFunction& dff,
46  DimensionedFieldType& field
47 )
48 :
49  field_(field)
50 {}
51 
52 
53 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
54 
55 template<class DimensionedFieldType>
58 (
59  const dictionary& dict,
60  DimensionedFieldType& field
61 )
62 {
63  const word type(dict.lookup("type"));
64 
65  libs.open
66  (
67  dict,
68  "libs",
69  dictionaryConstructorTablePtr_
70  );
71 
72  typename dictionaryConstructorTable::iterator cstrIter =
73  dictionaryConstructorTablePtr_->find(type);
74 
75  if (cstrIter == dictionaryConstructorTablePtr_->end())
76  {
78  << "Unknown DimensionedFieldFunction type " << type
79  << " for field " << field.name() << nl << nl
80  << "Valid DimensionedFieldFunction types are:" << nl
81  << dictionaryConstructorTablePtr_->sortedToc() << nl
82  << exit(FatalIOError);
83  }
84 
85  return cstrIter()(dict, field);
86 }
87 
88 
89 // * * * * * * * * * * * * * * * IOstream Functions * * * * * * * * * * * * //
90 
91 template<class DimensionedFieldType>
93 (
94  Ostream& os,
95  const word& key,
97 )
98 {
99  writeKeyword(os, key)
100  << nl << indent << token::BEGIN_BLOCK << nl << incrIndent;
101 
102  writeEntry(os, "type", f.type());
103  f.write(os);
104 
105  os << decrIndent << indent << token::END_BLOCK << endl;
106 }
107 
108 
109 // ************************************************************************* //
Base class for run-time selectable internal and patch field initialisation evaluation and update with...
DimensionedFieldFunction(const dictionary &dict, DimensionedFieldType &field)
Construct with dictionary to initialise given field.
static autoPtr< DimensionedFieldFunction< DimensionedFieldType > > New(const dictionary &dict, DimensionedFieldType &field)
Select null constructed.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
bool open(const fileName &libName, const bool verbose=true)
Open the named library, optionally with warnings if problems occur.
@ BEGIN_BLOCK
Definition: token.H:114
@ END_BLOCK
Definition: token.H:115
A class for handling words, derived from string.
Definition: word.H:63
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dlLibraryTable libs
Table of loaded dynamic libraries.
Ostream & decrIndent(Ostream &os)
Decrement the indent level.
Definition: Ostream.H:272
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
Ostream & incrIndent(Ostream &os)
Increment the indent level.
Definition: Ostream.H:265
IOerror FatalIOError
Ostream & writeKeyword(Foam::Ostream &os, const keyType &kw)
Write the keyword to the Ostream with the current level of indentation.
Definition: keyType.C:155
Ostream & indent(Ostream &os)
Indent stream.
Definition: Ostream.H:243
void writeEntry(Ostream &os, const word &key, const DimensionedFieldFunction< DimensionedFieldType > &f)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
labelList f(nPoints)
dictionary dict