Commit 55c04d30 authored by Mark Olesen's avatar Mark Olesen
Browse files

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.
parent 81891675
...@@ -120,8 +120,8 @@ void Foam::blockDescriptor::setEdge ...@@ -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());
......
...@@ -115,13 +115,13 @@ Foam::BSpline::BSpline ...@@ -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)));
} }
......
...@@ -82,13 +82,13 @@ public: ...@@ -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;
......
...@@ -61,7 +61,7 @@ Foam::cylindricalCS Foam::arcEdge::calcAngle() ...@@ -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() ...@@ -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) ...@@ -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 ...@@ -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_;
} }
......
...@@ -54,7 +54,7 @@ class arcEdge ...@@ -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: ...@@ -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;
......
...@@ -108,27 +108,27 @@ Foam::autoPtr<Foam::curvedEdge> Foam::curvedEdge::New ...@@ -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;
} }
......
...@@ -26,8 +26,8 @@ Class ...@@ -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: ...@@ -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: ...@@ -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
......
...@@ -67,7 +67,4 @@ inline int Foam::curvedEdge::compare(const edge& e) const ...@@ -67,7 +67,4 @@ inline int Foam::curvedEdge::compare(const edge& e) const
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* // // ************************************************************************* //
...@@ -55,14 +55,14 @@ class lineDivide ...@@ -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&,
......
...@@ -46,23 +46,19 @@ Foam::lineEdge::lineEdge ...@@ -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 ...@@ -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_]);
} }
......
...@@ -52,14 +52,6 @@ class lineEdge ...@@ -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 ...@@ -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: ...@@ -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;
......
...@@ -40,18 +40,19 @@ void Foam::polyLine::calcDistances() ...@@ -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) ...@@ -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
{ {
// check range of lambda return controlPoints_;
}
Foam::point Foam::polyLine::position(const scalar lambda) const
{
// 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 ...@@ -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 ...@@ -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
scalar offsetDist =
(lambda - distances_[i])
/(distances_[i+1] - distances_[i]);
vector offsetV = controlPoints_[i+1] - controlPoints_[i];
return controlPoints_[i] + offsetDist*offsetV; // linear interpolation
return
(
controlPoints_[i]
+ ( controlPoints_[i+1] - controlPoints_[i] )
* ( lambda - distances_[i] ) / ( distances_[i+1] - distances_[i] )
);
} }
......
...@@ -26,7 +26,8 @@ Class ...@@ -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: ...@@ -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: ...@@ -85,9 +91,12 @@ public:
// Member Functions