objectFunction1Templates.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) 2020 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 "objectFunction1.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template <class PrimitiveType>
31 Foam::objectFunction1::objectFunction1
32 (
33  const word& entryName,
34  const dictionary& dict,
35  const type<PrimitiveType>&
36 )
37 :
38  autoPtr<Function1<PrimitiveType>>
39  (
40  Function1<PrimitiveType>::New(entryName, dict).ptr()
41  )
42 {}
43 
44 
45 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
46 
47 template <template <class> class ObjectType>
49 (
50  const word& entryName,
51  const dictionary& dict,
52  const word& objectName,
53  const objectRegistry& db
54 )
55 {
57  (
58  db.foundObject<ObjectType<scalar>>(objectName)
59  ? new objectFunction1(entryName, dict, type<scalar>())
60  : db.foundObject<ObjectType<vector>>(objectName)
61  ? new objectFunction1(entryName, dict, type<vector>())
62  : db.foundObject<ObjectType<symmTensor>>(objectName)
63  ? new objectFunction1(entryName, dict, type<symmTensor>())
64  : db.foundObject<ObjectType<sphericalTensor>>(objectName)
65  ? new objectFunction1(entryName, dict, type<sphericalTensor>())
66  : db.foundObject<ObjectType<tensor>>(objectName)
67  ? new objectFunction1(entryName, dict, type<tensor>())
68  : nullptr
69  );
70 
71  if (!ptr.valid())
72  {
73  // Spit lookup error
74  db.lookupObject<regIOobject>(objectName);
75  }
76 
77  return ptr;
78 }
79 
80 
81 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
82 
84 {}
85 
86 
87 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
88 
89 template <class PrimitiveType>
90 PrimitiveType Foam::objectFunction1::value
91 (
92  const scalar x
93 ) const
94 {
95  return autoPtr<Function1<PrimitiveType>>::operator*().value(x);
96 }
97 
98 
99 template <class PrimitiveType>
101 (
102  const scalarField& x
103 ) const
104 {
105  return autoPtr<Function1<PrimitiveType>>::operator*().value(x);
106 }
107 
108 
109 template <class PrimitiveType>
111 (
112  const scalar x1,
113  const scalar x2
114 ) const
115 {
116  return autoPtr<Function1<PrimitiveType>>::operator*().integrate(x1, x2);
117 }
118 
119 
120 template <class PrimitiveType>
122 (
123  const scalarField& x1,
124  const scalarField& x2
125 ) const
126 {
127  return autoPtr<Function1<PrimitiveType>>::operator*().integrate(x1, x2);
128 }
129 
130 
131 // ************************************************************************* //
Wrapper around Function1 that constructs a function of type associated with an object found in the da...
PrimitiveType value(const scalar x) const
Return value as a function of (scalar) independent variable.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
bool foundObject(const word &name) const
Is the named Type found?
Function1< sphericalTensor > * ptr()
Return object pointer for reuse.
Definition: autoPtrI.H:90
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
PrimitiveType integrate(const scalar x1, const scalar x2) const
Integrate between two (scalar) values.
autoPtr< BasicCompressibleMomentumTransportModel > New(const volScalarField &rho, const volVectorField &U, const surfaceScalarField &phi, const typename BasicCompressibleMomentumTransportModel::transportModel &transport)
A class for handling words, derived from string.
Definition: word.H:59
bool valid() const
Return true if the autoPtr valid (ie, the pointer is set)
Definition: autoPtrI.H:83
static autoPtr< objectFunction1 > New(const word &entryName, const dictionary &dict, const word &objectName, const objectRegistry &db)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:55
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
A class for managing temporary objects.
Definition: PtrList.H:53
Registry of regIOobjects.