FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

BSpline.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 2009-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include <OpenFOAM/error.H>
00027 #include "BSpline.H"
00028 
00029 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00030 
00031 Foam::BSpline::BSpline
00032 (
00033     const pointField& knots,
00034     const bool closed
00035 )
00036 :
00037     polyLine(knots, closed)
00038 {}
00039 
00040 
00041 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00042 
00043 Foam::point Foam::BSpline::position(const scalar mu) const
00044 {
00045     // endpoints
00046     if (mu < SMALL)
00047     {
00048         return points_[0];
00049     }
00050     else if (mu > 1 - SMALL)
00051     {
00052         return points_[points_.size()-1];
00053     }
00054 
00055     scalar lambda = mu;
00056     label segment = localParameter(lambda);
00057     return position(segment, lambda);
00058 }
00059 
00060 
00061 Foam::point Foam::BSpline::position
00062 (
00063     const label segment,
00064     const scalar mu
00065 ) const
00066 {
00067     // out-of-bounds
00068     if (segment < 0)
00069     {
00070         return points_[0];
00071     }
00072     else if (segment > nSegments())
00073     {
00074         return points_[points_.size()-1];
00075     }
00076 
00077     const point& p0 = points()[segment];
00078     const point& p1 = points()[segment+1];
00079 
00080     // special cases - no calculation needed
00081     if (mu <= 0.0)
00082     {
00083         return p0;
00084     }
00085     else if (mu >= 1.0)
00086     {
00087         return p1;
00088     }
00089 
00090 
00091     // determine the end points
00092     point e0;
00093     point e1;
00094 
00095     if (segment == 0)
00096     {
00097         // end: simple reflection
00098         e0 = 2*p0 - p1;
00099     }
00100     else
00101     {
00102         e0 = points()[segment-1];
00103     }
00104 
00105     if (segment+1 == nSegments())
00106     {
00107         // end: simple reflection
00108         e1 = 2*p1 - p0;
00109     }
00110     else
00111     {
00112         e1 = points()[segment+2];
00113     }
00114 
00115 
00116     return 1.0/6.0 *
00117     (
00118         ( e0 + 4*p0 + p1 )
00119       + mu *
00120         (
00121             ( -3*e0 + 3*p1 )
00122           + mu *
00123             (
00124                 ( 3*e0 - 6*p0 + 3*p1 )
00125               + mu *
00126                 ( -e0 + 3*p0 - 3*p1 + e1 )
00127             )
00128         )
00129     );
00130 }
00131 
00132 
00133 Foam::scalar Foam::BSpline::length() const
00134 {
00135     notImplemented("BSpline::length() const");
00136     return 1.0;
00137 }
00138 
00139 
00140 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines