SampleFunction1.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) 2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Class
27  Foam::Function1Types::sample
28 
29 Description
30  Minimal example by using \c system/controlDict.functions:
31  \verbatim
32 
33  \verbatim
34  <entryName> sample;
35  <entryName>Coeffs
36  {
37  field <field name>;
38  position (0 0 0);
39  interpolationScheme cell;
40  }
41  \endverbatim
42 
43 SourceFiles
44  sampleFunction1.C
45 
46 \*---------------------------------------------------------------------------*/
47 
48 #ifndef Function1Types_Sample_H
49 #define Function1Types_Sample_H
50 
51 #include "Function1.H"
52 #include "point.H"
53 
54 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
55 
56 namespace Foam
57 {
58 namespace Function1Types
59 {
60 
61 /*---------------------------------------------------------------------------*\
62  Class Sample Declaration
63 \*---------------------------------------------------------------------------*/
64 
65 template<class Type>
66 class Sample
67 :
68  public Function1<Type>
69 {
70  // Private Data
71 
72  //- Name of field to sample
73  const word fieldName_;
74 
75  //- Sample position
76  const point position_;
77 
78  //- Interpolation scheme name; default = "cell"
79  const word interpolationScheme_;
80 
81  //- Sample cell
82  mutable label celli_;
83 
84  //- Points event number used to determine if celli should be updated
85  mutable label pointEventNo_;
86 
87 
88  // Private Member Functions
89 
90  //- Set the sample celli; error on not found
91  void setSampleCell() const;
92 
93  //- No copy assignment
94  void operator=(const Sample<Type>&) = delete;
95 
96 
97 public:
98 
99  //- Runtime type information
100  TypeName("sample");
101 
102 
103  // Constructors
104 
105  //- Construct from entry name, dictionary and optional registry
106  Sample
107  (
108  const word& entryName,
109  const dictionary& dict,
110  const objectRegistry* obrPtr = nullptr
111  );
112 
113  //- Construct from components
114  Sample
115  (
116  const word& entryName,
117  const List<Tuple2<Type, Type>>& coeffs,
118  const objectRegistry* obrPtr = nullptr
119  );
120 
121  //- Copy constructor
122  explicit Sample(const Sample& poly);
123 
124  //- Construct and return a clone
125  virtual tmp<Function1<Type>> clone() const
126  {
127  return tmp<Function1<Type>>(new Sample<Type>(*this));
128  }
129 
130 
131  //- Destructor
132  virtual ~Sample() = default;
133 
134 
135  // Member Functions
136 
137  //- Return Sample value
138  virtual Type value(const scalar x) const;
139 
140  //- Integrate between two (scalar) values
141  virtual Type integrate(const scalar x1, const scalar x2) const;
142 
143  //- Write as primitive (inline) format
144  virtual void writeData(Ostream& os) const;
145 
146  //- Write coefficient entries in dictionary format
147  void writeEntries(Ostream& os) const;
148 };
149 
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 } // End namespace Function1Types
154 } // End namespace Foam
155 
156 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
157 
158 #ifdef NoRepository
159  #include "SampleFunction1.C"
160 #endif
161 
162 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
163 
164 #endif
165 
166 // ************************************************************************* //
Foam::Function1Types::Sample::clone
virtual tmp< Function1< Type > > clone() const
Construct and return a clone.
Definition: SampleFunction1.H:124
Foam::Function1Types::Sample::Sample
Sample(const word &entryName, const dictionary &dict, const objectRegistry *obrPtr=nullptr)
Construct from entry name, dictionary and optional registry.
Definition: SampleFunction1.C:72
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Function1::entryName
const word & entryName
Definition: Function1.H:133
point.H
Function1.H
Foam::Function1Types::Sample::integrate
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
Definition: SampleFunction1.C:149
Foam::Function1Types::Sample::~Sample
virtual ~Sample()=default
Destructor.
Foam::Function1::dict
const word const dictionary & dict
Definition: Function1.H:134
SampleFunction1.C
Foam::Function1
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition: propellerInfo.H:291
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:60
Foam::Function1::obrPtr
const word const dictionary const objectRegistry * obrPtr
Definition: Function1.H:136
Foam::Function1Types::Sample::TypeName
TypeName("sample")
Runtime type information.
Foam::Function1Types::Sample::value
virtual Type value(const scalar x) const
Return Sample value.
Definition: SampleFunction1.C:105
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::Function1Types::Sample::writeEntries
void writeEntries(Ostream &os) const
Write coefficient entries in dictionary format.
Definition: SampleFunction1.C:161
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::Vector< scalar >
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::Function1Types::Sample::writeData
virtual void writeData(Ostream &os) const
Write as primitive (inline) format.
Definition: SampleFunction1.C:174
x
x
Definition: LISASMDCalcMethod2.H:52
Foam::Function1Types::Sample
Definition: SampleFunction1.H:65
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::Tuple2
A 2-tuple for storing two objects of dissimilar types. The container is similar in purpose to std::pa...
Definition: stringOps.H:60