Commit 3773db53 authored by Henry Weller's avatar Henry Weller
Browse files

blockMesh: Added projected vertices and edges

Patch contributed by Mattijs Janssens

    - Added projected vertices
    - Added projected edges
    - Change of blockEdges API (operate on list lambdas)
    - Change of blockFaces API (pass in blockDescriptor and blockFacei)
    - Added sphere7ProjectedEdges tutorial to demonstrate vertex and edge projection
parent b84618a3
blockVertices/blockVertex/blockVertex.C
blockVertices/pointVertex/pointVertex.C
blockVertices/projectVertex/projectVertex.C
blockEdges/blockEdge/blockEdge.C
blockEdges/lineDivide/lineDivide.C
......@@ -11,6 +12,7 @@ blockEdges/BSplineEdge/BSpline.C
blockEdges/BSplineEdge/BSplineEdge.C
blockEdges/splineEdge/CatmullRomSpline.C
blockEdges/splineEdge/splineEdge.C
blockEdges/projectEdge/projectEdge.C
blockFaces/blockFace/blockFace.C
blockFaces/projectFace/projectFace.C
......
......@@ -336,7 +336,12 @@ void Foam::blockDescriptor::correctFacePoints
{
if (curvedFaces_[blockFacei] != -1)
{
faces_[curvedFaces_[blockFacei]].project(facePoints[blockFacei]);
faces_[curvedFaces_[blockFacei]].project
(
*this,
blockFacei,
facePoints[blockFacei]
);
}
}
}
......
......@@ -125,6 +125,20 @@ Foam::pointField Foam::blockEdge::appendEndPoints
}
Foam::tmp<Foam::pointField>
Foam::blockEdge::position(const scalarList& lambdas) const
{
tmp<pointField> tpoints(new pointField(lambdas.size()));
pointField& points = tpoints.ref();
forAll(lambdas, i)
{
points[i] = position(lambdas[i]);
}
return tpoints;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const blockEdge& p)
......
......@@ -188,6 +188,10 @@ public:
// 0 <= lambda <= 1
virtual point position(const scalar) const = 0;
//- Return the point positions corresponding to the curve parameters
// 0 <= lambda <= 1
virtual tmp<pointField> position(const scalarList&) const;
//- Return the length of the curve
virtual scalar length() const = 0;
......
......@@ -131,10 +131,7 @@ Foam::lineDivide::lineDivide
}
// Calculate the points
for (label i = 0; i <= nDiv; i++)
{
points_[i] = cedge.position(divisions_[i]);
}
points_ = cedge.position(divisions_);
}
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "searchableSurfacesQueries.H"
#include "projectEdge.H"
#include "unitConversion.H"
#include "addToRunTimeSelectionTable.H"
#include "pointConstraint.H"
#include "plane.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(projectEdge, 0);
addToRunTimeSelectionTable(blockEdge, projectEdge, Istream);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::projectEdge::findNearest
(
const point& pt,
point& near,
pointConstraint& constraint
) const
{
if (surfaces_.size())
{
const scalar distSqr = magSqr(points_[end_]-points_[start_]);
pointField boundaryNear(1);
List<pointConstraint> boundaryConstraint(1);
searchableSurfacesQueries::findNearest
(
geometry_,
surfaces_,
pointField(1, pt),
scalarField(1, distSqr),
boundaryNear,
boundaryConstraint
);
near = boundaryNear[0];
constraint = boundaryConstraint[0];
}
else
{
near = pt;
constraint = pointConstraint();
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::projectEdge::projectEdge
(
const searchableSurfaces& geometry,
const pointField& points,
Istream& is
)
:
blockEdge(points, is),
geometry_(geometry)
{
wordList names(is);
surfaces_.setSize(names.size());
forAll(names, i)
{
surfaces_[i] = geometry_.findSurfaceID(names[i]);
if (surfaces_[i] == -1)
{
FatalIOErrorInFunction(is)
<< "Cannot find surface " << names[i] << " in geometry"
<< exit(FatalIOError);
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::point Foam::projectEdge::position(const scalar lambda) const
{
// Initial guess
const point start(points_[start_]+lambda*(points_[end_]-points_[start_]));
point near(start);
if (lambda >= SMALL && lambda < 1.0-SMALL)
{
pointConstraint constraint;
findNearest(start, near, constraint);
}
return near;
}
Foam::tmp<Foam::pointField>
Foam::projectEdge::position(const scalarList& lambdas) const
{
tmp<pointField> tpoints(new pointField(lambdas.size()));
pointField& points = tpoints.ref();
const point& startPt = points_[start_];
const point& endPt = points_[end_];
const vector d = endPt-startPt;
forAll(lambdas, i)
{
points[i] = startPt+lambdas[i]*d;
}
forAll(lambdas, i)
{
if (lambdas[i] >= SMALL && lambdas[i] < 1.0-SMALL)
{
pointConstraint constraint;
findNearest(points[i], points[i], constraint);
}
}
return tpoints;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ 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 <http://www.gnu.org/licenses/>.
Class
Foam::projectEdge
Description
Defines the edge from the projection onto a surface (single surface)
or intersection of two surfaces.
SourceFiles
projectEdge.C
\*---------------------------------------------------------------------------*/
#ifndef projectEdge_H
#define projectEdge_H
#include "blockEdge.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class pointConstraint;
/*---------------------------------------------------------------------------*\
Class projectEdge Declaration
\*---------------------------------------------------------------------------*/
class projectEdge
:
public blockEdge
{
// Private data
const searchableSurfaces& geometry_;
//- The indices of surfaces onto which the points are projected
labelList surfaces_;
// Private Member Functions
//- Single point find nearest
void findNearest(const point&, point& near, pointConstraint&) const;
//- Disallow default bitwise copy construct
projectEdge(const projectEdge&);
//- Disallow default bitwise assignment
void operator=(const projectEdge&);
public:
//- Runtime type information
TypeName("project");
// Constructors
//- Construct from Istream setting pointsList
projectEdge
(
const searchableSurfaces& geometry,
const pointField& points,
Istream&
);
//- Destructor
virtual ~projectEdge()
{}
// Member Functions
//- Return the point positions corresponding to the curve parameters
// 0 <= lambda <= 1
virtual point position(const scalar) const;
//- Return the point positions corresponding to the curve parameters
// 0 <= lambda <= 1
virtual tmp<pointField> position(const scalarList&) const;
//- Return the length of the curve
virtual scalar length() const
{
NotImplemented;
return 1;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -44,11 +44,11 @@ namespace Foam
// Forward declaration of friend functions and operators
class blockDescriptor;
class blockFace;
Ostream& operator<<(Ostream&, const blockFace&);
/*---------------------------------------------------------------------------*\
Class blockFace Declaration
\*---------------------------------------------------------------------------*/
......@@ -138,7 +138,12 @@ public:
//- Compare with the given block and block face
inline bool compare(const face& vertices) const;
virtual void project(pointField& points) const = 0;
virtual void project
(
const blockDescriptor&,
const label blockFacei,
pointField& points
) const = 0;
// Ostream operator
......
......@@ -26,6 +26,7 @@ License
#include "projectFace.H"
#include "unitConversion.H"
#include "addToRunTimeSelectionTable.H"
#include "blockDescriptor.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -80,7 +81,12 @@ Foam::blockFaces::projectFace::projectFace
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::blockFaces::projectFace::project(pointField& points) const
void Foam::blockFaces::projectFace::project
(
const blockDescriptor& desc,
const label blockFacei,
pointField& points
) const
{
List<pointIndexHit> hits;
scalarField nearestDistSqr
......
......@@ -98,7 +98,12 @@ public:
// Member Functions
//- Project the given points onto the surface
virtual void project(pointField& points) const;
virtual void project
(
const blockDescriptor&,
const label blockFacei,
pointField& points
) const;
};
......
......@@ -51,7 +51,9 @@ class pointVertex
:
public blockVertex
{
// Private member data
protected:
// Protected member data
//- The vertex location
point vertex_;
......
......@@ -23,77 +23,76 @@ License
\*---------------------------------------------------------------------------*/
#include "projectFace.H"
#include "projectVertex.H"
#include "unitConversion.H"
#include "addToRunTimeSelectionTable.H"
#include "searchableSurfacesQueries.H"
#include "pointConstraint.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(projectFace, 0);
addToRunTimeSelectionTable(blockVertex, projectFace, Istream);
namespace blockVertices
{
defineTypeNameAndDebug(projectVertex, 0);
addToRunTimeSelectionTable(blockVertex, projectVertex, Istream);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
const Foam::searchableSurface& Foam::projectFace::lookupSurface
Foam::blockVertices::projectVertex::projectVertex
(
const searchableSurfaces& geometry,
Istream& is
) const
)
:
pointVertex(geometry, is),
geometry_(geometry)
{
word name(is);
forAll(geometry, i)
wordList names(is);
surfaces_.setSize(names.size());
forAll(names, i)
{
if (geometry[i].name() == name)
surfaces_[i] = geometry_.findSurfaceID(names[i]);
if (surfaces_[i] == -1)
{
return geometry[i];
FatalIOErrorInFunction(is)
<< "Cannot find surface " << names[i] << " in geometry"
<< exit(FatalIOError);
}
}
FatalIOErrorInFunction(is)
<< "Cannot find surface " << name << " in geometry"
<< exit(FatalIOError);
return geometry[0];
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::projectFace::projectFace
(
const searchableSurfaces& geometry,
Istream& is
)
:
blockVertex(is),
surface_(lookupSurface(geometry, is))
{}
Foam::blockVertices::projectVertex::operator point() const
{
pointField start(1, pointVertex::operator point());
pointField boundaryNear(start);
List<pointConstraint> boundaryConstraint;
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::projectFace::project(pointField& points) const
{
List<pointIndexHit> hits;
scalarField nearestDistSqr
// Note: how far do we need to search? Probably not further than
// span of surfaces themselves.
boundBox bb(searchableSurfacesQueries::bounds(geometry_, surfaces_));
searchableSurfacesQueries::findNearest
(
points.size(),
magSqr(points[0] - points[points.size()-1])
geometry_,
surfaces_,
start,
scalarField(start.size(), magSqr(bb.span())),
boundaryNear,
boundaryConstraint
);
surface_.findNearest(points, nearestDistSqr, hits);
forAll(hits, i)
{
if (hits[i].hit())
{
points[i] = hits[i].hitPoint();
}
}
return boundaryNear[0];
}
......
......@@ -22,54 +22,52 @@ License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::projectFace
Foam::blockVertices::projectVertex
Description
Projects the given set of face points onto the selected surface of the
Projects the vertex onto the selected surfacees of the
geometry provided as a searchableSurfaces object.
SourceFiles
projectFace.C
projectVertex.C
\*---------------------------------------------------------------------------*/
#ifndef projectFace_H
#define projectFace_H
#ifndef blockVertices_projectVertex_H
#define blockVertices_projectVertex_H
#include "blockVertex.H"
#include "pointVertex.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace blockVertices
{
/*---------------------------------------------------------------------------*\
Class projectFace Declaration
Class projectVertex Declaration
\*---------------------------------------------------------------------------*/
class projectFace
class projectVertex
:
public blockVertex
public pointVertex
{
// Private data
//- The surface onto which the points are projected
const searchableSurface& surface_;
const searchableSurfaces& geometry_;
//- The indices of surfaces onto which the points are projected
labelList surfaces_;
// Private Member Functions