UniformDimensionedField.H
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) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 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 Class
28  Foam::UniformDimensionedField
29 
30 Description
31  Dimensioned<Type> registered with the database as a registered IOobject
32  which has the functionality of a uniform field and allows values from the
33  top-level code to be passed to boundary conditions etc.
34 
35  Is a 'global' field, same on all processors
36 
37 SourceFiles
38  UniformDimensionedField.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef Foam_UniformDimensionedField_H
43 #define Foam_UniformDimensionedField_H
44 
45 #include "regIOobject.H"
46 #include "dimensionedType.H"
47 
48 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
49 
50 namespace Foam
51 {
52 
53 /*---------------------------------------------------------------------------*\
54  Class UniformDimensionedField Declaration
55 \*---------------------------------------------------------------------------*/
56 
57 template<class Type>
59 :
60  public regIOobject,
61  public dimensioned<Type>
62 {
63 public:
64 
65  //- Runtime type information
66  TypeName("UniformDimensionedField");
67 
68 
69  // Constructors
70 
71  //- Construct from components. Either reads or uses supplied value.
72  // The name of the dimensioned<Type> defines the name of the
73  // field (if non-empty)
75  (
76  const IOobject& io,
77  const dimensioned<Type>& dt
78  );
79 
80  //- Construct from components. Either reads or uses supplied value.
81  // The name of the IOobject defines the name of the field.
82  // Parameter ordering as per dimensioned<Type>
84  (
85  const IOobject& io,
86  const dimensionSet& dims,
87  const Type& val
88  );
89 
90  //- Construct from components. Either reads or uses supplied value.
91  // The name of the IOobject defines the name of the field.
92  // Parameter ordering as per DimensionedField<Type>
94  (
95  const IOobject& io,
96  const Type& val,
97  const dimensionSet& dims
98  );
99 
100  //- Construct as copy
102 
103  //- Construct from Istream
105 
106 
107  //- Destructor
108  virtual ~UniformDimensionedField() = default;
109 
110 
111  // Member Functions
112 
113  //- Use name from dimensioned<Type>, not from regIOobject
114  virtual const word& name() const
115  {
116  return dimensioned<Type>::name();
117  }
118 
119  //- The readData method required for regIOobject read operation
120  virtual bool readData(Istream&);
121 
122  //- The writeData method required for regIOobject write operation
123  bool writeData(Ostream&) const;
124 
125  //- Is object global
126  virtual bool global() const
127  {
128  return true;
129  }
130 
131  //- Return complete path + object name if the file exists
132  // either in the case/processor or case otherwise null
133  virtual fileName filePath() const
134  {
135  return globalFilePath(type());
136  }
137 
138 
139  // Member Operators
140 
141  //- Assign name, dimensions and value of the dimensioned<Type>
142  void operator=(const UniformDimensionedField<Type>& rhs);
143 
144  //- Assign name, dimensions and value to the dimensioned<Type>
145  void operator=(const dimensioned<Type>& rhs);
147  //- Return value
148  const Type& operator[](const label) const noexcept
149  {
150  return dimensioned<Type>::value();
151  }
152 };
153 
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 //- Global file type for UniformDimensionedField
158 template<class Type>
159 struct is_globalIOobject<UniformDimensionedField<Type>> : std::true_type {};
160 
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 } // End namespace Foam
165 
166 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
167 
168 #ifdef NoRepository
169  #include "UniformDimensionedField.C"
170 #endif
171 
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
173 
174 #endif
175 
176 // ************************************************************************* //
const Type & value() const noexcept
Return const reference to value.
A class for handling file names.
Definition: fileName.H:72
fileName globalFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching up if in parallel.
Definition: IOobject.C:547
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual ~UniformDimensionedField()=default
Destructor.
Trait for specifying global vs. local file types.
Definition: IOobject.H:981
Generic dimensioned Type class.
bool writeData(Ostream &) const
The writeData method required for regIOobject write operation.
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
Dimension set for the base types, which can be used to implement rigorous dimension checking for alge...
Definition: dimensionSet.H:105
virtual bool global() const
Is object global.
A class for handling words, derived from Foam::string.
Definition: word.H:63
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
virtual fileName filePath() const
Return complete path + object name if the file exists.
virtual bool readData(Istream &)
The readData method required for regIOobject read operation.
Dimensioned<Type> registered with the database as a registered IOobject which has the functionality o...
const word & name() const noexcept
Return const reference to name.
TypeName("UniformDimensionedField")
Runtime type information.
const Type & operator[](const label) const noexcept
Return value.
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:66
void operator=(const UniformDimensionedField< Type > &rhs)
Assign name, dimensions and value of the dimensioned<Type>
virtual const word & name() const
Use name from dimensioned<Type>, not from regIOobject.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
UniformDimensionedField(const IOobject &io, const dimensioned< Type > &dt)
Construct from components. Either reads or uses supplied value.
Namespace for OpenFOAM.