Function1.C 4.02 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2017 OpenFOAM Foundation
6
7
8
9
10
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

11
12
13
14
    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
15
16
17
18
19
20
21

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    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

\*---------------------------------------------------------------------------*/

Henry Weller's avatar
Henry Weller committed
26
#include "Function1.H"
27
#include "Time.H"
28
29
// Required by clang 5 for correct instantiation of Function1::New
#include "Constant.H"
30
31
32
33

// * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * //

template<class Type>
Henry Weller's avatar
Henry Weller committed
34
Foam::Function1<Type>::Function1(const word& entryName)
35
:
36
    name_(entryName)
37
38
39
{}


40
template<class Type>
Henry Weller's avatar
Henry Weller committed
41
Foam::Function1<Type>::Function1(const Function1<Type>& de)
42
:
43
    refCount(),
44
45
46
47
    name_(de.name_)
{}


48
49
50
// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

template<class Type>
Henry Weller's avatar
Henry Weller committed
51
const Foam::word& Foam::Function1<Type>::name() const
52
{
53
    return name_;
54
55
56
}


57
template<class Type>
Henry Weller's avatar
Henry Weller committed
58
void Foam::Function1<Type>::convertTimeBase(const Time&)
59
{}
60
61


62
template<class Type>
Henry Weller's avatar
Henry Weller committed
63
Type Foam::Function1<Type>::value(const scalar x) const
64
{
65
    NotImplemented;
66

67
    return Zero;
68
69
}

70
71
72
73
74
75
76
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value
(
    const scalarField& x
) const
{
    NotImplemented;
77
    return nullptr;
78
79
}

80

81
template<class Type>
Henry Weller's avatar
Henry Weller committed
82
Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
83
{
84
    NotImplemented;
85

86
    return Zero;
87
88
89
}


90
91
92
93
94
95
96
97
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::integrate
(
    const scalarField& x1,
    const scalarField& x2
) const
{
    NotImplemented;
98
    return nullptr;
99
100
101
}


102
103
104
template<class Function1Type>
Foam::tmp<Foam::Field<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::value
105
106
107
108
(
    const scalarField& x
) const
{
109
110
    auto tfld = tmp<Field<Type>>::New(x.size());
    auto& fld = tfld.ref();
111
112
113

    forAll(x, i)
    {
114
        fld[i] = Function1Type::value(x[i]);
115
116
117
118
119
    }
    return tfld;
}


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
template<class Function1Type>
Foam::FieldFunction1<Function1Type>::FieldFunction1
(
    const word& entryName,
    const dictionary& dict
)
:
    Function1Type(entryName, dict)
{}


template<class Function1Type>
Foam::tmp<Foam::Function1<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::clone() const
{
    return tmp<Function1<Type>>
    (
        new FieldFunction1<Function1Type>(*this)
    );
}


template<class Function1Type>
Foam::tmp<Foam::Field<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::integrate
145
146
147
148
149
(
    const scalarField& x1,
    const scalarField& x2
) const
{
150
151
    auto tfld = tmp<Field<Type>>::New(x1.size());
    auto& fld = tfld.ref();
152
153
154

    forAll(x1, i)
    {
155
        fld[i] = Function1Type::integrate(x1[i], x2[i]);
156
    }
157

158
159
160
161
    return tfld;
}


Henry Weller's avatar
Henry Weller committed
162
163
164
165
166
167
168
template<class Type>
void Foam::Function1<Type>::writeData(Ostream& os) const
{
    os.writeKeyword(name_) << type();
}


169
170
// * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * * * //

Henry Weller's avatar
Henry Weller committed
171
172
173
174
175
176
177
template<class Type>
Foam::Ostream& Foam::operator<<
(
    Ostream& os,
    const Function1<Type>& f1
)
{
178
    os.check(FUNCTION_NAME);
Henry Weller's avatar
Henry Weller committed
179
180
181
182
183
184
185

    os  << f1.name_;
    f1.writeData(os);

    return os;
}

186

187
// ************************************************************************* //