trisurfaceMeshes superceded by searchableSurfaces

This commit is contained in:
mattijs
2008-07-07 18:40:05 +01:00
parent e3ee5fcf37
commit b7bb04e81b
2 changed files with 177 additions and 126 deletions

View File

@ -62,7 +62,6 @@ surfaceSlipDisplacementPointPatchVectorField
) )
: :
pointPatchVectorField(p, iF), pointPatchVectorField(p, iF),
surfaceNames_(),
projectMode_(NEAREST), projectMode_(NEAREST),
projectDir_(vector::zero), projectDir_(vector::zero),
wedgePlane_(-1) wedgePlane_(-1)
@ -78,7 +77,7 @@ surfaceSlipDisplacementPointPatchVectorField
) )
: :
pointPatchVectorField(p, iF, dict), pointPatchVectorField(p, iF, dict),
surfaceNames_(dict.lookup("projectSurfaces")), surfacesDict_(dict.subDict("geometry")),
projectMode_(followModeNames_.read(dict.lookup("followMode"))), projectMode_(followModeNames_.read(dict.lookup("followMode"))),
projectDir_(dict.lookup("projectDirection")), projectDir_(dict.lookup("projectDirection")),
wedgePlane_(readLabel(dict.lookup("wedgePlane"))), wedgePlane_(readLabel(dict.lookup("wedgePlane"))),
@ -96,7 +95,7 @@ surfaceSlipDisplacementPointPatchVectorField
) )
: :
pointPatchVectorField(p, iF), pointPatchVectorField(p, iF),
surfaceNames_(ppf.surfaceNames()), surfacesDict_(ppf.surfacesDict()),
projectMode_(ppf.projectMode()), projectMode_(ppf.projectMode()),
projectDir_(ppf.projectDir()), projectDir_(ppf.projectDir()),
wedgePlane_(ppf.wedgePlane()), wedgePlane_(ppf.wedgePlane()),
@ -111,7 +110,7 @@ surfaceSlipDisplacementPointPatchVectorField
) )
: :
pointPatchVectorField(ppf), pointPatchVectorField(ppf),
surfaceNames_(ppf.surfaceNames()), surfacesDict_(ppf.surfacesDict()),
projectMode_(ppf.projectMode()), projectMode_(ppf.projectMode()),
projectDir_(ppf.projectDir()), projectDir_(ppf.projectDir()),
wedgePlane_(ppf.wedgePlane()), wedgePlane_(ppf.wedgePlane()),
@ -127,7 +126,7 @@ surfaceSlipDisplacementPointPatchVectorField
) )
: :
pointPatchVectorField(ppf, iF), pointPatchVectorField(ppf, iF),
surfaceNames_(ppf.surfaceNames()), surfacesDict_(ppf.surfacesDict()),
projectMode_(ppf.projectMode()), projectMode_(ppf.projectMode()),
projectDir_(ppf.projectDir()), projectDir_(ppf.projectDir()),
wedgePlane_(ppf.wedgePlane()), wedgePlane_(ppf.wedgePlane()),
@ -137,14 +136,14 @@ surfaceSlipDisplacementPointPatchVectorField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const triSurfaceMeshes& surfaceSlipDisplacementPointPatchVectorField:: const searchableSurfaces& surfaceSlipDisplacementPointPatchVectorField::
surfaces() const surfaces() const
{ {
if (!surfacesPtr_.valid()) if (!surfacesPtr_.valid())
{ {
surfacesPtr_.reset surfacesPtr_.reset
( (
new triSurfaceMeshes new searchableSurfaces
( (
IOobject IOobject
( (
@ -155,7 +154,7 @@ surfaces() const
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
), ),
surfaceNames_ surfacesDict_
) )
); );
} }
@ -215,130 +214,182 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate
); );
const pointField& points0 = motionSolver.points0(); const pointField& points0 = motionSolver.points0();
forAll(localPoints, i)
//XXXXXX
pointField start(meshPoints.size());
forAll(start, i)
{ {
if (zonePtr && (zonePtr->whichPoint(meshPoints[i]) >= 0)) start[i] = points0[meshPoints[i]] + displacement[i];
}
if (projectMode_ == NEAREST)
{
List<pointIndexHit> nearest;
labelList hitSurfaces;
surfaces().findNearest
(
start,
scalarField(start.size(), sqr(projectLen)),
hitSurfaces,
nearest
);
forAll(nearest, i)
{ {
// Fixed point. Reset to point0 location. if (zonePtr && (zonePtr->whichPoint(meshPoints[i]) >= 0))
//Pout<< " Fixed point:" << meshPoints[i]
// << " coord:" << localPoints[i]
// << " should be at:" << points0[meshPoints[i]]
// << endl;
displacement[i] = points0[meshPoints[i]] - localPoints[i];
}
else
{
point start(points0[meshPoints[i]] + displacement[i]);
scalar offset = 0;
pointIndexHit intersection;
if (projectMode_ == NEAREST)
{ {
surfaces().findNearest(start, sqr(projectLen), intersection); // Fixed point. Reset to point0 location.
displacement[i] = points0[meshPoints[i]] - localPoints[i];
} }
else else if (nearest[i].hit())
{ {
// Check if already on surface displacement[i] =
surfaces().findNearest(start, sqr(SMALL), intersection); nearest[i].hitPoint()
- points0[meshPoints[i]];
if (!intersection.hit())
{
// No nearest found. Do intersection
if (projectMode_ == POINTNORMAL)
{
projectVec = projectLen*patch().pointNormals()[i];
}
// Knock out any wedge component
if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
{
offset = start[wedgePlane_];
start[wedgePlane_] = 0;
projectVec[wedgePlane_] = 0;
}
label rightSurf0, rightSurf1;
pointIndexHit rightHit0, rightHit1;
surfaces().findNearestIntersection
(
start,
start+projectVec,
rightSurf0,
rightHit0,
rightSurf1,
rightHit1
);
// Do intersection
label leftSurf0, leftSurf1;
pointIndexHit leftHit0, leftHit1;
surfaces().findNearestIntersection
(
start,
start-projectVec,
leftSurf0,
leftHit0,
leftSurf1,
leftHit1
);
if (rightHit0.hit())
{
if (leftHit0.hit())
{
if
(
magSqr(rightHit0.hitPoint()-start)
< magSqr(leftHit0.hitPoint()-start)
)
{
intersection = rightHit0;
}
else
{
intersection = leftHit0;
}
}
else
{
intersection = rightHit0;
}
}
else
{
if (leftHit0.hit())
{
intersection = leftHit0;
}
}
}
}
// Update *this from intersection point
if (intersection.hit())
{
point interPt = intersection.hitPoint();
if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
{
interPt[wedgePlane_] += offset;
}
displacement[i] = interPt-points0[meshPoints[i]];
} }
else else
{ {
Pout<< " point:" << meshPoints[i] Pout<< " point:" << meshPoints[i]
<< " coord:" << localPoints[i] << " coord:" << localPoints[i]
<< " did not find any intersection between ray from " << " did not find any surface within " << projectLen
<< start-projectVec << " to " << start+projectVec
<< endl; << endl;
} }
} }
} }
else
{
// Do tests on all points. Combine later on.
// 1. Check if already on surface
List<pointIndexHit> nearest;
{
labelList nearestSurface;
surfaces().findNearest
(
start,
scalarField(start.size(), sqr(SMALL)),
nearestSurface,
nearest
);
}
// 2. intersection. (combined later on with information from nearest
// above)
vectorField projectVecs(start.size(), projectVec);
if (projectMode_ == POINTNORMAL)
{
projectVecs = projectLen*patch().pointNormals();
}
// Knock out any wedge component
scalarField offset(start.size(), 0.0);
if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
{
forAll(offset, i)
{
offset[i] = start[i][wedgePlane_];
start[i][wedgePlane_] = 0;
projectVecs[i][wedgePlane_] = 0;
}
}
List<pointIndexHit> rightHit;
{
labelList rightSurf;
surfaces().findAnyIntersection
(
start,
start+projectVecs,
rightSurf,
rightHit
);
}
List<pointIndexHit> leftHit;
{
labelList leftSurf;
surfaces().findAnyIntersection
(
start,
start-projectVecs,
leftSurf,
leftHit
);
}
// 3. Choose either -fixed, nearest, right, left.
forAll(displacement, i)
{
if (zonePtr && (zonePtr->whichPoint(meshPoints[i]) >= 0))
{
// Fixed point. Reset to point0 location.
displacement[i] = points0[meshPoints[i]] - localPoints[i];
}
else if (nearest[i].hit())
{
// Found nearest.
displacement[i] =
nearest[i].hitPoint()
- points0[meshPoints[i]];
}
else
{
pointIndexHit interPt;
if (rightHit[i].hit())
{
if (leftHit[i].hit())
{
if
(
magSqr(rightHit[i].hitPoint()-start[i])
< magSqr(leftHit[i].hitPoint()-start[i])
)
{
interPt = rightHit[i];
}
else
{
interPt = leftHit[i];
}
}
else
{
interPt = rightHit[i];
}
}
else
{
if (leftHit[i].hit())
{
interPt = leftHit[i];
}
}
if (interPt.hit())
{
if (wedgePlane_ >= 0 && wedgePlane_ <= vector::nComponents)
{
interPt.rawPoint()[wedgePlane_] += offset[i];
}
displacement[i] = interPt.rawPoint()-points0[meshPoints[i]];
}
else
{
Pout<< " point:" << meshPoints[i]
<< " coord:" << localPoints[i]
<< " did not find any intersection between ray from "
<< start[i]-projectVecs[i]
<< " to " << start[i]+projectVecs[i]
<< endl;
}
}
}
}
// Get internal field to insert values into // Get internal field to insert values into
Field<vector>& iF = const_cast<Field<vector>&>(this->internalField()); Field<vector>& iF = const_cast<Field<vector>&>(this->internalField());
@ -353,7 +404,7 @@ void surfaceSlipDisplacementPointPatchVectorField::evaluate
void surfaceSlipDisplacementPointPatchVectorField::write(Ostream& os) const void surfaceSlipDisplacementPointPatchVectorField::write(Ostream& os) const
{ {
pointPatchVectorField::write(os); pointPatchVectorField::write(os);
os.writeKeyword("projectSurfaces") << surfaceNames_ os.writeKeyword("geometry") << surfacesDict_
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;
os.writeKeyword("followMode") << followModeNames_[projectMode_] os.writeKeyword("followMode") << followModeNames_[projectMode_]
<< token::END_STATEMENT << nl; << token::END_STATEMENT << nl;

View File

@ -52,7 +52,7 @@ SourceFiles
#define surfaceSlipDisplacementPointPatchVectorField_H #define surfaceSlipDisplacementPointPatchVectorField_H
#include "pointPatchFields.H" #include "pointPatchFields.H"
#include "triSurfaceMeshes.H" #include "searchableSurfaces.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -87,7 +87,7 @@ private:
static const NamedEnum<followMode, 3> followModeNames_; static const NamedEnum<followMode, 3> followModeNames_;
//- names of surfaces //- names of surfaces
const fileNameList surfaceNames_; const dictionary surfacesDict_;
//- How to follow/project onto surface //- How to follow/project onto surface
const followMode projectMode_; const followMode projectMode_;
@ -102,7 +102,7 @@ private:
const word frozenPointsZone_; const word frozenPointsZone_;
//- Demand driven: surface to follow //- Demand driven: surface to follow
mutable autoPtr<triSurfaceMeshes> surfacesPtr_; mutable autoPtr<searchableSurfaces> surfacesPtr_;
// Private Member Functions // Private Member Functions
@ -187,13 +187,13 @@ public:
// Member Functions // Member Functions
//- Surfaces to follow //- Surfaces to follow
const fileNameList& surfaceNames() const const dictionary& surfacesDict() const
{ {
return surfaceNames_; return surfacesDict_;
} }
//- Surface to follow. Demand loads surfaceNames. //- Surface to follow. Demand loads surfaceNames.
const triSurfaceMeshes& surfaces() const; const searchableSurfaces& surfaces() const;
//- Mode of projection/following //- Mode of projection/following
followMode projectMode() const followMode projectMode() const