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-2021 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& name,
34  const dictionary& dict,
35  const type<PrimitiveType>&
36 )
37 :
38  autoPtr<Function1<PrimitiveType>>
39  (
40  Function1<PrimitiveType>::New(name, dict).ptr()
41  )
42 {}
43 
44 
45 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
46 
47 template<template<class> class ObjectType>
49 (
50  const word& name,
51  const dictionary& dict,
52  const word& objectName,
53  const objectRegistry& db,
54  const bool error
55 )
56 {
58  (
59  db.foundObject<ObjectType<scalar>>(objectName)
60  ? new objectFunction1(name, dict, type<scalar>())
61  : db.foundObject<ObjectType<vector>>(objectName)
62  ? new objectFunction1(name, dict, type<vector>())
63  : db.foundObject<ObjectType<symmTensor>>(objectName)
64  ? new objectFunction1(name, dict, type<symmTensor>())
65  : db.foundObject<ObjectType<sphericalTensor>>(objectName)
66  ? new objectFunction1(name, dict, type<sphericalTensor>())
67  : db.foundObject<ObjectType<tensor>>(objectName)
68  ? new objectFunction1(name, dict, type<tensor>())
69  : nullptr
70  );
71 
72  if (error && !ptr.valid())
73  {
74  // Spit lookup error
75  db.lookupObject<regIOobject>(objectName);
76  }
77 
78  return ptr;
79 }
80 
81 
82 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
83 
84 template<class PrimitiveType>
85 PrimitiveType Foam::objectFunction1::value
86 (
87  const scalar x
88 ) const
89 {
90  return autoPtr<Function1<PrimitiveType>>::operator*().value(x);
91 }
92 
93 
94 template<class PrimitiveType>
96 (
97  const scalarField& x
98 ) const
99 {
100  return autoPtr<Function1<PrimitiveType>>::operator*().value(x);
101 }
102 
103 
104 template<class PrimitiveType>
106 (
107  const scalar x1,
108  const scalar x2
109 ) const
110 {
111  return autoPtr<Function1<PrimitiveType>>::operator*().integral(x1, x2);
112 }
113 
114 
115 template<class PrimitiveType>
117 (
118  const scalarField& x1,
119  const scalarField& x2
120 ) const
121 {
122  return autoPtr<Function1<PrimitiveType>>::operator*().integral(x1, x2);
123 }
124 
125 
126 // ************************************************************************* //
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 x.
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
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.
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 &name, const dictionary &dict, const word &objectName, const objectRegistry &db, const bool error=true)
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:52
PrimitiveType integral(const scalar x1, const scalar x2) const
Integrate between two scalars.
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.