BSpline.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "error.H"
00031
00032 #include "BSpline.H"
00033 #include "simpleMatrix.H"
00034
00035
00036
00037 namespace Foam
00038 {
00039
00040 pointField BSpline::findKnots
00041 (
00042 const pointField& allknots,
00043 const vector& fstend,
00044 const vector& sndend
00045 )
00046 {
00047 label newnKnots(allknots.size() + 2);
00048 label NKnots(allknots.size());
00049 pointField newknots(newnKnots);
00050
00051
00052
00053
00054 register scalar oneSixth = 1.0/6.0;
00055 register scalar twoThird = 2.0/3.0;
00056
00057 simpleMatrix<vector> M(newnKnots);
00058
00059
00060
00061 M[0][0] = -0.5*scalar(NKnots - 1);
00062 M[0][2] = 0.5*scalar(NKnots - 1);
00063
00064 for (register label i=1; i<newnKnots-1; i++)
00065 {
00066 M[i][i-1] = oneSixth;
00067 M[i][i] = twoThird;
00068 M[i][i+1] = oneSixth;
00069 }
00070
00071 M[newnKnots - 1][newnKnots - 3] = -0.5*scalar(NKnots - 1);
00072 M[newnKnots - 1][newnKnots - 1] = 0.5*scalar(NKnots - 1);
00073
00074
00075
00076 for (label i=1; i<=NKnots; i++)
00077 {
00078 M.source()[i] = allknots[i-1];
00079 }
00080
00081
00082
00083 if (mag(fstend)<1e-8)
00084 {
00085
00086 M.source()[0] = allknots[1] - allknots[0];
00087 M.source()[0] /= mag(M.source()[0]);
00088
00089 M.source()[NKnots+1] = M.source()[NKnots-1] - M.source()[NKnots];
00090 M.source()[NKnots+1] /= mag(M.source()[NKnots+1]);
00091 }
00092 else
00093 {
00094
00095 M.source()[0] = fstend/mag(fstend);
00096 M.source()[NKnots+1] = sndend/mag(sndend);
00097 }
00098
00099
00100
00101 newknots = M.solve();
00102
00103 return newknots;
00104 }
00105
00106
00107
00108
00109
00110 BSpline::BSpline(const pointField& Knots)
00111 :
00112 spline(findKnots(Knots))
00113 {}
00114
00115
00116
00117 BSpline::BSpline
00118 (
00119 const pointField& Knots,
00120 const vector& fstend,
00121 const vector& sndend
00122 )
00123 :
00124 spline(findKnots(Knots, fstend, sndend))
00125 {}
00126
00127
00128
00129
00130
00131
00132 vector BSpline::realPosition(scalar mu)
00133 {
00134 return spline::position(mu);
00135 }
00136
00137
00138
00139
00140 vector BSpline::position(const scalar mu) const
00141 {
00142 return spline::position((1.0/(nKnots() - 1))*(1.0 + mu*(nKnots() - 3)));
00143 }
00144
00145
00146
00147 scalar BSpline::length() const
00148 {
00149 notImplemented("BSpline::length() const");
00150 return 1.0;
00151 }
00152
00153
00154
00155
00156 }
00157
00158
Copyright © 2000-2009 OpenCFD Ltd