From fca33d213e5e634f2331eabc420cc619ccecb113 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 24 Nov 2015 12:52:01 +0000 Subject: [PATCH] ENH: bezier: added bezier curves in blockMesh edges --- src/mesh/blockMesh/Make/files | 1 + src/mesh/blockMesh/curvedEdges/bezier.C | 97 +++++++++++++++++++ src/mesh/blockMesh/curvedEdges/bezier.H | 121 ++++++++++++++++++++++++ 3 files changed, 219 insertions(+) create mode 100644 src/mesh/blockMesh/curvedEdges/bezier.C create mode 100644 src/mesh/blockMesh/curvedEdges/bezier.H diff --git a/src/mesh/blockMesh/Make/files b/src/mesh/blockMesh/Make/files index 37bbe7ba17..584db6cf61 100644 --- a/src/mesh/blockMesh/Make/files +++ b/src/mesh/blockMesh/Make/files @@ -3,6 +3,7 @@ curvedEdges/CatmullRomSpline.C curvedEdges/polyLine.C curvedEdges/arcEdge.C +curvedEdges/bezier.C curvedEdges/curvedEdge.C curvedEdges/lineEdge.C curvedEdges/polyLineEdge.C diff --git a/src/mesh/blockMesh/curvedEdges/bezier.C b/src/mesh/blockMesh/curvedEdges/bezier.C new file mode 100644 index 0000000000..1d590457b9 --- /dev/null +++ b/src/mesh/blockMesh/curvedEdges/bezier.C @@ -0,0 +1,97 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenCFD Ltd. + \\/ 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 3 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, see . + +\*---------------------------------------------------------------------------*/ + +#include "bezier.H" +#include "SubList.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(bezier, 0); + addToRunTimeSelectionTable(curvedEdge, bezier, Istream); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::bezier::bezier +( + const pointField& ps, + const label start, + const label end, + const pointField& control +) +: + curvedEdge(ps, start, end), + control_(control) +{} + + +Foam::bezier::bezier(const pointField& ps, Istream& is) +: + curvedEdge(ps, is), + control_(appendEndPoints(ps, start_, end_, pointField(is))) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::bezier::~bezier() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +Foam::point Foam::bezier::position(const scalar lambda) const +{ + pointField working(control_); + + label nWorking(working.size()); + + forAll(working, workingI) + { + -- nWorking; + + SubList(working, nWorking).assign + ( + (1 - lambda)*SubList(working, nWorking) + + lambda*SubList(working, nWorking, 1) + ); + } + + return working[0]; +} + + +Foam::scalar Foam::bezier::length() const +{ + notImplemented("bezier::length() const"); + return 1.0; +} + + +// ************************************************************************* // diff --git a/src/mesh/blockMesh/curvedEdges/bezier.H b/src/mesh/blockMesh/curvedEdges/bezier.H new file mode 100644 index 0000000000..2f231c754f --- /dev/null +++ b/src/mesh/blockMesh/curvedEdges/bezier.H @@ -0,0 +1,121 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2015 OpenCFD Ltd. + \\/ 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 3 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, see . + +Class + Foam::bezier + +Description + Nth order bezier curve edge. Only interior control points should be + specified. The outer points are taken as start and end. Note that the + calculation of each point takes 0(N^2) time, where N is the number of + control points. This edge type shouldn't therefore be used for finely + discretised line data; polyLine or similar will be more appropriate for + such cases. Beziers are useful for simple curved shapes such as aerofoils, + or when you want an edge to match a specific direction at one, or both, or + its endpoints. In comparison with BSplines, the grading of bezier edges + should be smoother, and the code is much simpler. The algorithmic order is + worse, however, and the edge will not follow the control points as closely. + +SourceFiles + bezier.C + +\*---------------------------------------------------------------------------*/ + +#ifndef bezier_H +#define bezier_H + +#include "curvedEdge.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class bezier Declaration +\*---------------------------------------------------------------------------*/ + +class bezier +: + public curvedEdge +{ +private: + + //- Control points + pointField control_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + bezier(const bezier&); + + //- Disallow default bitwise assignment + void operator=(const bezier&); + + +public: + + // Static data members + TypeName("bezier"); + + + // Constructors + + //- Construct from components + bezier + ( + const pointField&, + const label start, + const label end, + const pointField& control + ); + + //- Construct from Istream + bezier(const pointField&, Istream&); + + + //- Destructor + virtual ~bezier(); + + + // Member Functions + + //- Return the point position corresponding to the curve parameter + // 0 <= lambda <= 1 + point position(const scalar lambda) const; + + //- Return the length of the curve + scalar length() const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //