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.
83  (
84  const IOobject& io,
85  const dimensionSet& dims,
86  const Type& val
87  );
88 
89  //- Construct as copy
91 
92  //- Construct from Istream
94 
95 
96  //- Destructor
97  virtual ~UniformDimensionedField() = default;
98 
99 
100  // Member Functions
101 
102  //- Name function provided to resolve the ambiguity between the
103  //- name functions in regIOobject and dimensioned<Type>
104  virtual const word& name() const
105  {
106  return dimensioned<Type>::name();
107  }
108 
109  //- ReadData function required for regIOobject read operation
110  virtual bool readData(Istream&);
111 
112  //- WriteData function required for regIOobject write operation
113  bool writeData(Ostream&) const;
114 
115  //- Is object global
116  virtual bool global() const
117  {
118  return true;
119  }
120 
121  //- Return complete path + object name if the file exists
122  // either in the case/processor or case otherwise null
123  virtual fileName filePath() const
124  {
125  return globalFilePath(type());
126  }
127 
128 
129  // Member Operators
130 
131  //- Assign name, dimensions and value.
132  void operator=(const UniformDimensionedField<Type>& rhs);
134  //- Assign name, dimensions and value.
135  void operator=(const dimensioned<Type>& rhs);
136 
137  //- Return value
138  const Type& operator[](const label) const noexcept
139  {
140  return dimensioned<Type>::value();
141  }
142 };
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 } // End namespace Foam
148 
149 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150 
151 #ifdef NoRepository
152  #include "UniformDimensionedField.C"
153 #endif
154 
155 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156 
157 #endif
158 
159 // ************************************************************************* //
const Type & value() const noexcept
Return const reference to value.
A class for handling file names.
Definition: fileName.H:71
fileName globalFilePath(const word &typeName, const bool search=true) const
Redirect to fileHandler filePath, searching up if in parallel.
Definition: IOobject.C:534
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
virtual ~UniformDimensionedField()=default
Destructor.
Generic dimensioned Type class.
bool writeData(Ostream &) const
WriteData function 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:752
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.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
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:55
const direction noexcept
Definition: Scalar.H:258
virtual fileName filePath() const
Return complete path + object name if the file exists.
virtual bool readData(Istream &)
ReadData function 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:69
void operator=(const UniformDimensionedField< Type > &rhs)
Assign name, dimensions and value.
virtual const word & name() const
Name function provided to resolve the ambiguity between the name functions in regIOobject and dimensi...
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:166
UniformDimensionedField(const IOobject &io, const dimensioned< Type > &dt)
Construct from components. Either reads or uses supplied value.
Namespace for OpenFOAM.