spline.C 2.58 KB
Newer Older
1
2
3
4
/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
Mark Olesen's avatar
Mark Olesen committed
5
    \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    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 2 of the License, or (at your
    option) any later version.

    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
    along with OpenFOAM; if not, write to the Free Software Foundation,
    Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

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

#include "spline.H"

29
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
30

31
Foam::scalar Foam::spline::B(const scalar tau)
32
{
33
    if (tau <= -2.0 || tau >= 2.0)
34
    {
35
        return 0.0;
36
    }
37
    else if (tau <= -1.0)
38
    {
39
        return pow((2.0 + tau), 3.0)/6.0;
40
    }
41
    else if (tau <= 0.0)
42
    {
43
        return (4.0 - 6.0*tau*tau - 3.0*tau*tau*tau)/6.0;
44
    }
45
    else if (tau <= 1.0)
46
    {
47
        return (4.0 - 6.0*tau*tau + 3.0*tau*tau*tau)/6.0;
48
    }
49
    else if (tau <= 2.0)
50
    {
51
        return pow((2.0 - tau), 3.0)/6.0;
52
53
54
    }
    else
    {
55
        FatalErrorIn("spline::B(const scalar)")
56
            << "Programming error???, "
57
58
59
60
            << "tau = " << tau
            << abort(FatalError);
    }

61
    return 0.0;
62
63
64
}


65
66
67
68
69
70
71
72
73
74
// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::spline::spline(const pointField& knotPoints)
:
    knots_(knotPoints)
{}


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

75
Foam::point Foam::spline::position(const scalar mu) const
76
{
77
    point loc(point::zero);
78

79
    for (register label i=0; i < knots_.size(); i++)
80
    {
81
        loc += B((knots_.size() - 1)*mu - i)*knots_[i];
82
83
    }

84
    return loc;
85
86
87
}


88
Foam::scalar Foam::spline::length() const
89
90
91
92
93
94
95
{
    notImplemented("spline::length() const");
    return 1.0;
}


// ************************************************************************* //