uniform.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) 2021 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 "uniform.H"
27 #include "volFields.H"
28 #include "surfaceFields.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37  defineTypeNameAndDebug(uniform, 0);
38  addToRunTimeSelectionTable(functionObject, uniform, dictionary);
39 }
40 }
41 
42 
43 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 
46 (
47  const word& name,
48  const Time& runTime,
49  const dictionary& dict
50 )
51 :
52  fvMeshFunctionObject(name, runTime, dict),
53  fieldType_(word::null),
54  name_(word::null),
55  dimensions_(dimless)
56 {
57  read(dict);
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
62 
64 {}
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
70 {
72 
73  fieldType_ = dict.lookup<word>("fieldType");
74  name_ = dict.lookup<word>("name");
75  dimensions_.reset(dict.lookup<dimensionSet>("dimensions"));
76 
77  bool ok = false;
78  #define readValueType(Type, GeoField) \
79  if (GeoField<Type>::typeName == fieldType_) \
80  { \
81  ok = true; \
82  Type##Value_ = dict.lookup<Type>("value"); \
83  }
86  #undef readValueType
87 
88  if (!ok)
89  {
91  << "Field type " << fieldType_ << " not recognised" << endl << endl;
92 
93  DynamicList<word> fieldTypes;
94  #define getFieldType(Type, GeoField) \
95  fieldTypes.append(GeoField<Type>::typeName);
98  #undef getFieldType
99 
101  << "Available field types are : " << endl
102  << fieldTypes
103  << exit(FatalError);
104  }
105 
106  return true;
107 }
108 
109 
111 {
112  #define calcType(Type, GeoField) \
113  if (GeoField<Type>::typeName == fieldType_) \
114  { \
115  store \
116  ( \
117  name_, \
118  GeoField<Type>::New \
119  ( \
120  name_, \
121  mesh_, \
122  dimensioned<Type>(dimensions_, Type##Value_) \
123  ) \
124  ); \
125  }
128  #undef calcType
129 
130  return true;
131 }
132 
133 
135 {
136  return writeObject(name_);
137 }
138 
139 
141 {
142  return clearObject(name_);
143 }
144 
145 
146 // ************************************************************************* //
Foam::surfaceFields.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
uniform(const word &name, const Time &, const dictionary &)
Construct from Time and dictionary.
Definition: uniform.C:46
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual bool write()
Write the field.
Definition: uniform.C:134
#define FOR_ALL_FIELD_TYPES(Macro,...)
Definition: fieldTypes.H:50
Generic GeometricField class.
const dimensionSet dimless
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &)
Read optional controls.
Dimension set for the base types.
Definition: dimensionSet.H:120
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
static const word null
An empty word.
Definition: word.H:77
#define calcType(Type, GeoField)
virtual ~uniform()
Destructor.
Definition: uniform.C:63
virtual bool execute()
Calculate the field.
Definition: uniform.C:110
#define getFieldType(Type, GeoField)
defineTypeNameAndDebug(Qdot, 0)
#define readValueType(Type, GeoField)
virtual bool read(const dictionary &)
Read the uniform data.
Definition: uniform.C:69
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool clear()
Clear the field from the objectRegistry.
Definition: uniform.C:140
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:844