finally commited pending (cosmetic) code cleanup for blockMesh/curvedEdges

- slightly better code isolation, dropped unneed variables, changed
  vector -> point in the appropriate places

- the spline stuff is still horribly broken.
  Needs a complete rewrite or needs to get chucked.
This commit is contained in:
Mark Olesen
2009-11-24 00:34:37 +01:00
parent 81891675ea
commit 55c04d307e
21 changed files with 131 additions and 125 deletions

View File

@ -120,8 +120,8 @@ void Foam::blockDescriptor::setEdge
// divide the line // divide the line
lineDivide divEdge(cedge, dim, 1.0/(gExp+SMALL)); lineDivide divEdge(cedge, dim, 1.0/(gExp+SMALL));
pointField p = divEdge.points(); const pointField& p = divEdge.points();
scalarList d = divEdge.lambdaDivisions(); const scalarList& d = divEdge.lambdaDivisions();
edgePoints_[edgeI].setSize(p.size()); edgePoints_[edgeI].setSize(p.size());
edgeWeights_[edgeI].setSize(d.size()); edgeWeights_[edgeI].setSize(d.size());

View File

@ -115,13 +115,13 @@ Foam::BSpline::BSpline
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::BSpline::realPosition(const scalar mu) const Foam::point Foam::BSpline::realPosition(const scalar mu) const
{ {
return spline::position(mu); return spline::position(mu);
} }
Foam::vector Foam::BSpline::position(const scalar mu) const Foam::point Foam::BSpline::position(const scalar mu) const
{ {
return spline::position((1.0/(nKnots() - 1))*(1.0 + mu*(nKnots() - 3))); return spline::position((1.0/(nKnots() - 1))*(1.0 + mu*(nKnots() - 3)));
} }

View File

@ -82,13 +82,13 @@ public:
// Member Functions // Member Functions
//- Return the real position of a point on the curve given by //- Return the real point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector realPosition(const scalar lambda) const; point realPosition(const scalar lambda) const;
//- Return the position of a point on the curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector position(const scalar lambda) const; point position(const scalar lambda) const;
//- Return the length of the curve //- Return the length of the curve
scalar length() const; scalar length() const;

View File

@ -61,7 +61,7 @@ Foam::cylindricalCS Foam::arcEdge::calcAngle()
scalar fact = 0.5*(bsqr - adotb)/denom; scalar fact = 0.5*(bsqr - adotb)/denom;
vector centre = 0.5*a + fact*((a ^ b) ^ a); point centre = 0.5*a + fact*((a ^ b) ^ a);
centre += p1_; centre += p1_;
@ -75,7 +75,7 @@ Foam::cylindricalCS Foam::arcEdge::calcAngle()
angle_ = radToDeg(acos(tmp)); angle_ = radToDeg(acos(tmp));
// check if the vectors define an exterior or an interior arcEdge // check if the vectors define an exterior or an interior arcEdge
if (((r1 ^ r2)&(r1 ^ r3)) < 0.0) if (((r1 ^ r2) & (r1 ^ r3)) < 0.0)
{ {
angle_ = 360.0 - angle_; angle_ = 360.0 - angle_;
} }
@ -133,7 +133,7 @@ Foam::arcEdge::arcEdge(const pointField& points, Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::arcEdge::position(const scalar lambda) const Foam::point Foam::arcEdge::position(const scalar lambda) const
{ {
if (lambda < 0 || lambda > 1) if (lambda < 0 || lambda > 1)
{ {
@ -146,7 +146,7 @@ Foam::vector Foam::arcEdge::position(const scalar lambda) const
{ {
return p1_; return p1_;
} }
else if (lambda > 1-SMALL) else if (lambda > 1 - SMALL)
{ {
return p3_; return p3_;
} }

View File

@ -54,7 +54,7 @@ class arcEdge
{ {
// Private data // Private data
vector p1_, p2_, p3_; point p1_, p2_, p3_;
scalar angle_; scalar angle_;
scalar radius_; scalar radius_;
cylindricalCS cs_; cylindricalCS cs_;
@ -96,9 +96,9 @@ public:
// Member Functions // Member Functions
//- Return the position of a point on the curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector position(const scalar) const; point position(const scalar) const;
//- Return the length of the curve //- Return the length of the curve
scalar length() const; scalar length() const;

View File

@ -108,27 +108,27 @@ Foam::autoPtr<Foam::curvedEdge> Foam::curvedEdge::New
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::pointField Foam::curvedEdge::knotlist Foam::pointField Foam::curvedEdge::fullKnotList
( (
const pointField& points, const pointField& points,
const label start, const label start,
const label end, const label end,
const pointField& otherknots const pointField& otherKnots
) )
{ {
pointField newPoints(otherknots.size() + 2); pointField allKnots(otherKnots.size() + 2);
// start/end knots // start/end knots
newPoints[0] = points[start]; allKnots[0] = points[start];
newPoints[otherknots.size() + 1] = points[end]; allKnots[otherKnots.size() + 1] = points[end];
// intermediate knots // intermediate knots
forAll(otherknots, knotI) forAll(otherKnots, knotI)
{ {
newPoints[knotI+1] = otherknots[knotI]; allKnots[knotI+1] = otherKnots[knotI];
} }
return newPoints; return allKnots;
} }

View File

@ -26,8 +26,8 @@ Class
Foam::curvedEdge Foam::curvedEdge
Description Description
Define a curved edge in space that is parameterised for Define a curved edge that is parameterized for 0<lambda<1
0<lambda<1 from the beginning to the end point. between the start and end point.
SourceFiles SourceFiles
curvedEdge.C curvedEdge.C
@ -62,6 +62,19 @@ protected:
const label start_; const label start_;
const label end_; const label end_;
// Protected Member Functions
//- Return a complete knotList by adding the start/end points
// to the given list
static pointField fullKnotList
(
const pointField&,
const label start,
const label end,
const pointField& otherKnots
);
public: public:
//- Runtime type information //- Runtime type information
@ -136,23 +149,13 @@ public:
// - -1: same edge, but different orientation // - -1: same edge, but different orientation
inline int compare(const label start, const label end) const; inline int compare(const label start, const label end) const;
//- Return the position of a point on the curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
virtual vector position(const scalar) const = 0; virtual point position(const scalar) const = 0;
//- Return the length of the curve //- Return the length of the curve
virtual scalar length() const = 0; virtual scalar length() const = 0;
//- Return a complete knotList by adding the start/end points
// to the given list
static pointField knotlist
(
const pointField&,
const label start,
const label end,
const pointField& otherknots
);
// Member operators // Member operators

View File

@ -67,7 +67,4 @@ inline int Foam::curvedEdge::compare(const edge& e) const
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* // // ************************************************************************* //

View File

@ -55,14 +55,14 @@ class lineDivide
// Private data // Private data
pointField points_; pointField points_;
scalarList divisions_; scalarList divisions_;
public: public:
// Constructors // Constructors
//- Construct from components //- Construct from components with discretization and expansion ratio
// discretization and expansion ration
lineDivide lineDivide
( (
const curvedEdge&, const curvedEdge&,

View File

@ -46,23 +46,19 @@ Foam::lineEdge::lineEdge
const label end const label end
) )
: :
curvedEdge(points, start, end), curvedEdge(points, start, end)
startPoint_(points_[start_]),
direction_(points_[end_] - points_[start_])
{} {}
Foam::lineEdge::lineEdge(const pointField& points, Istream& is) Foam::lineEdge::lineEdge(const pointField& points, Istream& is)
: :
curvedEdge(points, is), curvedEdge(points, is)
startPoint_(points_[start_]),
direction_(points_[end_] - points_[start_])
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::lineEdge::position(const scalar lambda) const Foam::point Foam::lineEdge::position(const scalar lambda) const
{ {
if (lambda < 0 || lambda > 1) if (lambda < 0 || lambda > 1)
{ {
@ -71,13 +67,13 @@ Foam::vector Foam::lineEdge::position(const scalar lambda) const
<< abort(FatalError); << abort(FatalError);
} }
return startPoint_ + lambda*direction_; return points_[start_] + lambda * (points_[end_] - points_[start_]);
} }
Foam::scalar Foam::lineEdge::length() const Foam::scalar Foam::lineEdge::length() const
{ {
return mag(direction_); return mag(points_[end_] - points_[start_]);
} }

View File

@ -52,14 +52,6 @@ class lineEdge
: :
public curvedEdge public curvedEdge
{ {
// Private data
//- Avoid repetitive calculation of the start point
const vector startPoint_;
//- Avoid repetitive calculation of the direction (end - start)
const vector direction_;
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
@ -68,7 +60,6 @@ class lineEdge
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const lineEdge&); void operator=(const lineEdge&);
public: public:
//- Runtime type information //- Runtime type information
@ -83,16 +74,16 @@ public:
lineEdge(const pointField&, Istream&); lineEdge(const pointField&, Istream&);
// Destructor //- Destructor
virtual ~lineEdge()
virtual ~lineEdge(){} {}
// Member Functions // Member Functions
//- Return the position of a point on the curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector position(const scalar) const; point position(const scalar) const;
//- Return the length of the curve //- Return the length of the curve
scalar length() const; scalar length() const;

View File

@ -40,18 +40,19 @@ void Foam::polyLine::calcDistances()
{ {
distances_[0] = 0.0; distances_[0] = 0.0;
for (label i=1; i<distances_.size(); i++) for (label i=1; i < distances_.size(); i++)
{ {
distances_[i] = distances_[i-1] + distances_[i] = distances_[i-1] +
mag(controlPoints_[i] - controlPoints_[i-1]); mag(controlPoints_[i] - controlPoints_[i-1]);
} }
// normalize // normalize on the interval 0-1
lineLength_ = distances_[distances_.size()-1]; lineLength_ = distances_[distances_.size()-1];
for (label i=1; i<distances_.size(); i++) for (label i=1; i < distances_.size() - 1; i++)
{ {
distances_[i] /= lineLength_; distances_[i] /= lineLength_;
} }
distances_[distances_.size()-1] = 1.0;
} }
else else
{ {
@ -75,10 +76,15 @@ Foam::polyLine::polyLine(const pointField& ps)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::polyLine::position(const scalar lambda) const const Foam::pointField& Foam::polyLine::controlPoints() const
{
return controlPoints_;
}
Foam::point Foam::polyLine::position(const scalar lambda) const
{ {
// check range of lambda // check range of lambda
if (lambda < 0 || lambda > 1) if (lambda < 0 || lambda > 1)
{ {
FatalErrorIn("polyLine::position(const scalar)") FatalErrorIn("polyLine::position(const scalar)")
@ -87,8 +93,7 @@ Foam::vector Foam::polyLine::position(const scalar lambda) const
<< abort(FatalError); << abort(FatalError);
} }
// Quick calc of endpoints // check endpoints
if (lambda < SMALL) if (lambda < SMALL)
{ {
return controlPoints_[0]; return controlPoints_[0];
@ -99,25 +104,24 @@ Foam::vector Foam::polyLine::position(const scalar lambda) const
} }
// search table of cumulative distance to find which linesegment we // search table of cumulative distances to find which line-segment
// are on // we are on. Check the upper bound.
label i(0); label i = 1;
do while (distances_[i] < lambda)
{ {
i++; i++;
} while (distances_[i] < lambda); }
i--; // we now want the lower bound
i--; // we overshot!
// construct position vector // linear interpolation
scalar offsetDist = return
(lambda - distances_[i]) (
/(distances_[i+1] - distances_[i]); controlPoints_[i]
+ ( controlPoints_[i+1] - controlPoints_[i] )
vector offsetV = controlPoints_[i+1] - controlPoints_[i]; * ( lambda - distances_[i] ) / ( distances_[i+1] - distances_[i] )
);
return controlPoints_[i] + offsetDist*offsetV;
} }

View File

@ -26,7 +26,8 @@ Class
Foam::polyLine Foam::polyLine
Description Description
Defines a curvedEdge in terms of a series of straight line segments. Define a series of control points, which can also be interpreted as a
series of straight line segments.
This is the basic polyLine class which implements just the line This is the basic polyLine class which implements just the line
(no topology - it is not derived from curvedEdge) (no topology - it is not derived from curvedEdge)
@ -66,15 +67,20 @@ protected:
// Protected data // Protected data
//- The control points or ends of each segmen
pointField controlPoints_; pointField controlPoints_;
//- The rational (0-1) cumulative distance for each control-point
scalarList distances_; scalarList distances_;
//- The real line length
scalar lineLength_; scalar lineLength_;
// Protected member functions // Protected member functions
//- Precalculate the rational cumulative distances and the line-length
void calcDistances(); void calcDistances();
public: public:
// Constructors // Constructors
@ -85,9 +91,12 @@ public:
// Member Functions // Member Functions
//- Return the position of a point on the curve given by //- Return const-access to the control-points
// the parameter 0 <= lambda <= 1 const pointField& controlPoints() const;
vector position(const scalar) const;
//- Return the point position corresponding to the curve parameter
// 0 <= lambda <= 1
point position(const scalar) const;
//- Return the length of the curve //- Return the length of the curve
scalar length() const; scalar length() const;

View File

@ -44,24 +44,24 @@ Foam::polyLineEdge::polyLineEdge
const pointField& ps, const pointField& ps,
const label start, const label start,
const label end, const label end,
const pointField& otherpoints const pointField& otherPoints
) )
: :
curvedEdge(ps, start, end), curvedEdge(ps, start, end),
polyLine(knotlist(ps, start, end, otherpoints)) polyLine(fullKnotList(ps, start_, end_, otherPoints))
{} {}
Foam::polyLineEdge::polyLineEdge(const pointField& ps, Istream& is) Foam::polyLineEdge::polyLineEdge(const pointField& ps, Istream& is)
: :
curvedEdge(ps, is), curvedEdge(ps, is),
polyLine(knotlist(ps, start_, end_, pointField(is))) polyLine(fullKnotList(ps, start_, end_, pointField(is)))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::polyLineEdge::position(const scalar lambda) const Foam::point Foam::polyLineEdge::position(const scalar lambda) const
{ {
return polyLine::position(lambda); return polyLine::position(lambda);
} }

View File

@ -26,8 +26,7 @@ Class
Foam::polyLineEdge Foam::polyLineEdge
Description Description
Defines a curvedEdge in terms of a series of straight line segments. A curvedEdge defined in terms of a series of straight line segments.
This is the public face of polyLine
SourceFiles SourceFiles
polyLineEdge.C polyLineEdge.C
@ -91,9 +90,9 @@ public:
// Member Functions // Member Functions
//- Return the position of a point on the curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector position(const scalar lambda) const; point position(const scalar lambda) const;
//- Return the length of the curve //- Return the length of the curve
scalar length() const; scalar length() const;

View File

@ -56,7 +56,7 @@ Foam::pointField Foam::polySplineEdge::intervening
{ {
BSpline spl BSpline spl
( (
knotlist(points_, start_, end_, otherknots), fullKnotList(points_, start_, end_, otherknots),
fstend, fstend,
sndend sndend
); );
@ -135,7 +135,7 @@ Foam::polySplineEdge::polySplineEdge
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::polySplineEdge::position(const scalar mu) const Foam::point Foam::polySplineEdge::position(const scalar mu) const
{ {
return polyLine::position(mu); return polyLine::position(mu);
} }

View File

@ -90,16 +90,16 @@ public:
polySplineEdge(const pointField&, Istream&); polySplineEdge(const pointField&, Istream&);
// Destructor //- Destructor
virtual ~polySplineEdge()
virtual ~polySplineEdge(){} {}
// Member Functions // Member Functions
//- Return the position of a point on the curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector position(const scalar mu) const; point position(const scalar mu) const;
//- Return the length of the curve //- Return the length of the curve
scalar length() const; scalar length() const;

View File

@ -48,7 +48,7 @@ Foam::simpleSplineEdge::simpleSplineEdge
) )
: :
curvedEdge(points, start, end), curvedEdge(points, start, end),
BSpline(knotlist(points, start, end, otherknots)) BSpline(fullKnotList(points, start, end, otherknots))
{} {}
@ -63,20 +63,20 @@ Foam::simpleSplineEdge::simpleSplineEdge
) )
: :
curvedEdge(points, start, end), curvedEdge(points, start, end),
BSpline(knotlist(points, start, end, otherknots), fstend, sndend) BSpline(fullKnotList(points, start, end, otherknots), fstend, sndend)
{} {}
Foam::simpleSplineEdge::simpleSplineEdge(const pointField& points, Istream& is) Foam::simpleSplineEdge::simpleSplineEdge(const pointField& points, Istream& is)
: :
curvedEdge(points, is), curvedEdge(points, is),
BSpline(knotlist(points, start_, end_, pointField(is))) BSpline(fullKnotList(points, start_, end_, pointField(is)))
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::simpleSplineEdge::position(const scalar mu) const Foam::point Foam::simpleSplineEdge::position(const scalar mu) const
{ {
return BSpline::position(mu); return BSpline::position(mu);
} }

View File

@ -102,9 +102,9 @@ public:
// Member Functions // Member Functions
//- Return the position of a point on the simple spline curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector position(const scalar mu) const; point position(const scalar) const;
//- Return the length of the simple spline curve //- Return the length of the simple spline curve
scalar length() const; scalar length() const;

View File

@ -72,9 +72,9 @@ Foam::spline::spline(const pointField& knotPoints)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::vector Foam::spline::position(const scalar mu) const Foam::point Foam::spline::position(const scalar mu) const
{ {
vector loc(vector::zero); point loc(point::zero);
for (register label i=0; i < knots_.size(); i++) for (register label i=0; i < knots_.size(); i++)
{ {

View File

@ -81,6 +81,13 @@ public:
// Access // Access
//- Return the knot points in the spline
const pointField& knotPoints() const
{
return knots_;
}
//- Return the number of knots in the spline //- Return the number of knots in the spline
label nKnots() const label nKnots() const
{ {
@ -88,9 +95,9 @@ public:
} }
//- Return the position of a point on the curve given by //- Return the point position corresponding to the curve parameter
// the parameter 0 <= lambda <= 1 // 0 <= lambda <= 1
vector position(const scalar) const; point position(const scalar) const;
//- Return the length of the spline curve //- Return the length of the spline curve
scalar length() const; scalar length() const;