Function1.C 4.12 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
30
31

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

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


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


46
47
48
// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

template<class Type>
Henry Weller's avatar
Henry Weller committed
49
Foam::Function1<Type>::~Function1()
50
51
52
53
54
55
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

template<class Type>
Henry Weller's avatar
Henry Weller committed
56
const Foam::word& Foam::Function1<Type>::name() const
57
{
58
    return name_;
59
60
61
}


62
template<class Type>
Henry Weller's avatar
Henry Weller committed
63
void Foam::Function1<Type>::convertTimeBase(const Time&)
64
{}
65
66


67
template<class Type>
Henry Weller's avatar
Henry Weller committed
68
Type Foam::Function1<Type>::value(const scalar x) const
69
{
70
    NotImplemented;
71

72
    return Zero;
73
74
}

75
76
77
78
79
80
81
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value
(
    const scalarField& x
) const
{
    NotImplemented;
82
    return nullptr;
83
84
}

85

86
template<class Type>
Henry Weller's avatar
Henry Weller committed
87
Type Foam::Function1<Type>::integrate(const scalar x1, const scalar x2) const
88
{
89
    NotImplemented;
90

91
    return Zero;
92
93
94
}


95
96
97
98
99
100
101
102
template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::integrate
(
    const scalarField& x1,
    const scalarField& x2
) const
{
    NotImplemented;
103
    return nullptr;
104
105
106
}


107
108
109
template<class Function1Type>
Foam::tmp<Foam::Field<typename Function1Type::returnType>>
Foam::FieldFunction1<Function1Type>::value
110
111
112
113
(
    const scalarField& x
) const
{
114
    tmp<Field<Type>> tfld(new Field<Type>(x.size()));
115
    Field<Type>& fld = tfld.ref();
116
117
118

    forAll(x, i)
    {
119
        fld[i] = Function1Type::value(x[i]);
120
121
122
123
124
    }
    return tfld;
}


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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
150
151
152
153
154
(
    const scalarField& x1,
    const scalarField& x2
) const
{
155
    tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
156
    Field<Type>& fld = tfld.ref();
157
158
159

    forAll(x1, i)
    {
160
        fld[i] = Function1Type::integrate(x1[i], x2[i]);
161
    }
162

163
164
165
166
    return tfld;
}


Henry Weller's avatar
Henry Weller committed
167
168
169
170
171
172
173
template<class Type>
void Foam::Function1<Type>::writeData(Ostream& os) const
{
    os.writeKeyword(name_) << type();
}


174
175
// * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * * * //

Henry Weller's avatar
Henry Weller committed
176
177
178
179
180
181
182
template<class Type>
Foam::Ostream& Foam::operator<<
(
    Ostream& os,
    const Function1<Type>& f1
)
{
183
    os.check(FUNCTION_NAME);
Henry Weller's avatar
Henry Weller committed
184
185
186
187
188
189
190

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

    return os;
}

191

192
// ************************************************************************* //