ENH: offsetSurface: new extrusion model to extrude inbetween two surfaces

This commit is contained in:
mattijs
2015-11-24 13:46:48 +00:00
parent b6f350f6f7
commit f3787e5722
3 changed files with 293 additions and 0 deletions

View File

@ -63,6 +63,10 @@ extrudeModel wedge;
//- Extrudes into sphere with grading according to pressure (atmospherics)
//extrudeModel sigmaRadial;
//- Extrudes by interpolating along path inbetween two (topologically identical)
// surfaces (e.g. one is an offsetted version of the other)
//extrudeModel offsetSurface;
nLayers 10;
expansionRatio 1.0;
@ -105,6 +109,16 @@ sigmaRadialCoeffs
pStrat 1;
}
offsetSurfaceCoeffs
{
// Surface that mesh has been meshed to
baseSurface "$FOAM_CASE/constant/triSurface/DTC-scaled-inflated.obj";
// Surface to fill in to
offsetSurface "$FOAM_CASE/constant/triSurface/DTC-scaled.obj";
}
// Do front and back need to be merged? Usually only makes sense for 360
// degree wedges.
mergeFaces false;

View File

@ -0,0 +1,165 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 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 "offsetSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "triSurface.H"
#include "triSurfaceSearch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace extrudeModels
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(offsetSurface, 0);
addToRunTimeSelectionTable(extrudeModel, offsetSurface, dictionary);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
offsetSurface::offsetSurface(const dictionary& dict)
:
extrudeModel(typeName, dict),
project_(coeffDict_.lookupOrDefault("project", false))
{
// Read surface
fileName baseName(coeffDict_.lookup("baseSurface"));
baseName.expand();
baseSurfPtr_.reset(new triSurface(baseName));
// Construct search engine
baseSearchPtr_.reset(new triSurfaceSearch(baseSurfPtr_()));
// Read offsetted surface
fileName offsetName(coeffDict_.lookup("offsetSurface"));
offsetName.expand();
offsetSurfPtr_.reset(new triSurface(offsetName));
// Construct search engine
offsetSearchPtr_.reset(new triSurfaceSearch(offsetSurfPtr_()));
const triSurface& b = baseSurfPtr_();
const triSurface& o = offsetSurfPtr_();
if
(
b.size() != o.size()
|| b.nPoints() != o.nPoints()
|| b.nEdges() != o.nEdges()
)
{
FatalIOErrorIn("offsetSurface::offsetSurface(const dictionary&)", dict)
<< "offsetSurface " << offsetName
<< " should have exactly the same topology as the baseSurface "
<< baseName << exit(FatalIOError);
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
offsetSurface::~offsetSurface()
{}
// * * * * * * * * * * * * * * * * Operators * * * * * * * * * * * * * * * * //
point offsetSurface::operator()
(
const point& surfacePoint,
const vector& surfaceNormal,
const label layer
) const
{
if (layer == 0)
{
return surfacePoint;
}
else
{
pointField samples(1, surfacePoint);
scalarField nearestDistSqr(1, GREAT);
List<pointIndexHit> info;
baseSearchPtr_().findNearest(samples, nearestDistSqr, info);
label triI = info[0].index();
const triSurface& base = baseSurfPtr_();
const triPointRef baseTri(base[triI].tri(base.points()));
List<scalar> bary;
baseTri.barycentric(surfacePoint, bary);
const triSurface& offset = offsetSurfPtr_();
const triPointRef offsetTri(offset[triI].tri(offset.points()));
const point offsetPoint
(
bary[0]*offsetTri.a()
+bary[1]*offsetTri.b()
+bary[2]*offsetTri.c()
);
point interpolatedPoint
(
surfacePoint + sumThickness(layer)*(offsetPoint-surfacePoint)
);
//- Either return interpolatedPoint or re-project onto surface (since
// snapping might not have do so exactly)
if (project_)
{
// Re-project onto surface
offsetSearchPtr_().findNearest
(
pointField(1, interpolatedPoint),
scalarField(1, GREAT),
info
);
return info[0].hitPoint();
}
else
{
return interpolatedPoint;
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace extrudeModels
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014 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::extrudeModels::offsetSurface
Description
Extrudes by interpolating points from one surface to the other. Surfaces
have to be topologically identical i.e. one has to be an offsetted version
of the other.
\*---------------------------------------------------------------------------*/
#ifndef offsetSurface_H
#define offsetSurface_H
#include "point.H"
#include "extrudeModel.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class triSurface;
class triSurfaceSearch;
namespace extrudeModels
{
/*---------------------------------------------------------------------------*\
Class offsetSurface Declaration
\*---------------------------------------------------------------------------*/
class offsetSurface
:
public extrudeModel
{
// Private data
//- surface
autoPtr<triSurface> baseSurfPtr_;
//- search engine
autoPtr<triSurfaceSearch> baseSearchPtr_;
//- offsets
autoPtr<triSurface> offsetSurfPtr_;
//- search engine
autoPtr<triSurfaceSearch> offsetSearchPtr_;
// Whether to re-project onto offsetted surface
const Switch project_;
public:
//- Runtime type information
TypeName("offsetSurface");
// Constructors
//- Construct from dictionary
offsetSurface(const dictionary& dict);
//- Destructor
virtual ~offsetSurface();
// Member Operators
//- Return point
point operator()
(
const point& surfacePoint,
const vector& surfaceNormal,
const label layer
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace extrudeModels
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //