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-2023 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 {
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  fieldName_(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  fieldName_ = dict.lookupBackwardsCompatible<word>({"field", "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  }
87  #undef readValueType
88 
89  if (!ok)
90  {
92  << "Field type " << fieldType_ << " not recognised" << endl << endl;
93 
94  DynamicList<word> fieldTypes;
95  #define getFieldType(Type, GeoField) \
96  fieldTypes.append(GeoField<Type>::typeName);
100  #undef getFieldType
101 
103  << "Available field types are : " << endl
104  << fieldTypes
105  << exit(FatalError);
106  }
107 
108  return true;
109 }
110 
111 
113 {
114  #define calcType(Type, GeoField) \
115  if (GeoField<Type>::typeName == fieldType_) \
116  { \
117  store \
118  ( \
119  fieldName_, \
120  GeoField<Type>::New \
121  ( \
122  fieldName_, \
123  mesh_, \
124  dimensioned<Type>(dimensions_, Type##Value_) \
125  ) \
126  ); \
127  }
131  #undef calcType
132 
133  return true;
134 }
135 
136 
138 {
139  return writeObject(fieldName_);
140 }
141 
142 
144 {
145  return clearObject(fieldName_);
146 }
147 
148 
149 // ************************************************************************* //
Macros for easy insertion into run-time selection tables.
Generic GeometricField class.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Dimension set for the base types.
Definition: dimensionSet.H:125
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
virtual bool read(const dictionary &)
Read optional controls.
Generate a uniform field.
Definition: uniform.H:58
virtual bool clear()
Clear the field from the objectRegistry.
Definition: uniform.C:143
virtual ~uniform()
Destructor.
Definition: uniform.C:63
virtual bool execute()
Calculate the field.
Definition: uniform.C:112
virtual bool write()
Write the field.
Definition: uniform.C:137
uniform(const word &name, const Time &, const dictionary &)
Construct from Time and dictionary.
Definition: uniform.C:46
virtual bool read(const dictionary &)
Read the uniform data.
Definition: uniform.C:69
A class for handling words, derived from string.
Definition: word.H:62
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
#define readValueType(Type, GeoField)
#define getFieldType(Type, GeoField)
#define calcType(Type, GeoField)
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
const dimensionSet dimless
typename VolField< Type >::Internal VolInternalField
Definition: volFieldsFwd.H:61
error FatalError
FOR_ALL_FIELD_TYPES(makeFieldSourceTypedef)
dictionary dict
Foam::surfaceFields.