Function1.C 3.37 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
5
    \\  /    A nd           | Copyright (C) 2011-2016 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
    refCount(),
35
    name_(entryName)
36
37
38
{}


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


47
48
49
// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

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


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

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


63
template<class Type>
Henry Weller's avatar
Henry Weller committed
64
void Foam::Function1<Type>::convertTimeBase(const Time&)
65
66
67
68
69
{
    // do nothing
}


70
template<class Type>
Henry Weller's avatar
Henry Weller committed
71
Type Foam::Function1<Type>::value(const scalar x) const
72
{
73
    NotImplemented;
74
75
76
77
78

    return pTraits<Type>::zero;
}


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

    return pTraits<Type>::zero;
}


88
template<class Type>
Henry Weller's avatar
Henry Weller committed
89
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::value
90
91
92
93
(
    const scalarField& x
) const
{
94
    tmp<Field<Type>> tfld(new Field<Type>(x.size()));
95
    Field<Type>& fld = tfld.ref();
96
97
98
99
100
101
102
103
104

    forAll(x, i)
    {
        fld[i] = this->value(x[i]);
    }
    return tfld;
}


105
template<class Type>
Henry Weller's avatar
Henry Weller committed
106
Foam::tmp<Foam::Field<Type>> Foam::Function1<Type>::integrate
107
108
109
110
111
(
    const scalarField& x1,
    const scalarField& x2
) const
{
112
    tmp<Field<Type>> tfld(new Field<Type>(x1.size()));
113
    Field<Type>& fld = tfld.ref();
114
115
116
117
118
119
120
121
122

    forAll(x1, i)
    {
        fld[i] = this->integrate(x1[i], x2[i]);
    }
    return tfld;
}


Henry Weller's avatar
Henry Weller committed
123
124
125
126
127
128
129
template<class Type>
void Foam::Function1<Type>::writeData(Ostream& os) const
{
    os.writeKeyword(name_) << type();
}


130
131
// * * * * * * * * * * * * * *  IOStream operators * * * * * * * * * * * * * //

Henry Weller's avatar
Henry Weller committed
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
template<class Type>
Foam::Ostream& Foam::operator<<
(
    Ostream& os,
    const Function1<Type>& f1
)
{
    // Check state of Ostream
    os.check
    (
        "Ostream& operator<<(Ostream&, const Function1<Type>&)"
    );

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

    return os;
}

151

152
// ************************************************************************* //