ENH: correct suspicious coordinate system conversions (issue #1027)

- arraySet :
     was translate + transform
     now use globalPosition (== transform + translate).

     Explicitly limit to Cartesian coordinate system for clarity.
This commit is contained in:
Mark Olesen
2018-10-01 17:10:35 +02:00
parent 6697bb4735
commit b17bcd67b7
2 changed files with 30 additions and 54 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,7 +30,6 @@ License
#include "polyMesh.H" #include "polyMesh.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "word.H" #include "word.H"
#include "transform.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -54,57 +53,37 @@ void Foam::arraySet::calcSamples
{ {
const meshSearch& queryMesh = searchEngine(); const meshSearch& queryMesh = searchEngine();
label nTotalSamples const scalar dx = spanBox_.x()/(pointsDensity_.x() + 1);
( const scalar dy = spanBox_.y()/(pointsDensity_.y() + 1);
pointsDensity_.x() const scalar dz = spanBox_.z()/(pointsDensity_.z() + 1);
*pointsDensity_.y()
*pointsDensity_.z()
);
List<point> sampleCoords(nTotalSamples); label sampleI(0);
const scalar deltax = spanBox_.x()/(pointsDensity_.x() + 1);
const scalar deltay = spanBox_.y()/(pointsDensity_.y() + 1);
const scalar deltaz = spanBox_.z()/(pointsDensity_.z() + 1);
label p(0);
for (label k=1; k<=pointsDensity_.z(); ++k) for (label k=1; k<=pointsDensity_.z(); ++k)
{ {
for (label j=1; j<=pointsDensity_.y(); ++j) for (label j=1; j<=pointsDensity_.y(); ++j)
{ {
for (label i=1; i<=pointsDensity_.x(); ++i) for (label i=1; i<=pointsDensity_.x(); ++i)
{ {
vector t(deltax*i , deltay*j, deltaz*k); // Local Cartesian
sampleCoords[p] = coordSys_.origin() + t; point pt(i*dx*i , j*dy, k*dz);
++p;
// Global Cartesian
pt = csys_.globalPosition(pt);
const label celli = queryMesh.findCell(pt);
if (celli != -1)
{
samplingPts.append(pt);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingSegments.append(0);
samplingCurveDist.append(1.0 * sampleI);
}
} }
} }
} }
// Local to global (Cartesian)
{
const tensor& rotTensor = coordSys_.R();
forAll(sampleCoords, i)
{
sampleCoords[i] = Foam::transform(rotTensor, sampleCoords[i]);
}
}
forAll(sampleCoords, sampleI)
{
label celli = queryMesh.findCell(sampleCoords[sampleI]);
if (celli != -1)
{
samplingPts.append(sampleCoords[sampleI]);
samplingCells.append(celli);
samplingFaces.append(-1);
samplingSegments.append(0);
samplingCurveDist.append(1.0 * sampleI);
}
}
} }
@ -157,13 +136,13 @@ Foam::arraySet::arraySet
const polyMesh& mesh, const polyMesh& mesh,
const meshSearch& searchEngine, const meshSearch& searchEngine,
const word& axis, const word& axis,
const coordinateSystem& origin, const coordSystem::cartesian& csys,
const Vector<label>& pointsDensity, const Vector<label>& pointsDensity,
const Vector<scalar>& spanBox const Vector<scalar>& spanBox
) )
: :
sampledSet(name, mesh, searchEngine, axis), sampledSet(name, mesh, searchEngine, axis),
coordSys_(origin), csys_(csys),
pointsDensity_(pointsDensity), pointsDensity_(pointsDensity),
spanBox_(spanBox) spanBox_(spanBox)
{ {
@ -180,7 +159,7 @@ Foam::arraySet::arraySet
) )
: :
sampledSet(name, mesh, searchEngine, dict), sampledSet(name, mesh, searchEngine, dict),
coordSys_(dict), csys_(dict), // Note: no indirect cs with this constructor
pointsDensity_(dict.get<labelVector>("pointsDensity")), pointsDensity_(dict.get<labelVector>("pointsDensity")),
spanBox_(dict.get<vector>("spanBox")) spanBox_(dict.get<vector>("spanBox"))
{ {

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -49,17 +49,14 @@ SourceFiles
#include "sampledSet.H" #include "sampledSet.H"
#include "labelVector.H" #include "labelVector.H"
#include "DynamicList.H" #include "DynamicList.H"
#include "coordinateSystem.H" #include "cartesianCS.H"
#include "cylindricalCS.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
// Forward declarations
class passiveParticle;
template<class Type> class particle;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class arraySet Declaration Class arraySet Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -70,8 +67,8 @@ class arraySet
{ {
// Private data // Private data
//- Coordinate system //- Local Cartesian coordinate system
coordinateSystem coordSys_; coordSystem::cartesian csys_;
//- Point density vector //- Point density vector
labelVector pointsDensity_; labelVector pointsDensity_;
@ -111,7 +108,7 @@ public:
const polyMesh& mesh, const polyMesh& mesh,
const meshSearch& searchEngine, const meshSearch& searchEngine,
const word& axis, const word& axis,
const coordinateSystem& coordSys, const coordSystem::cartesian& csys,
const Vector<label>& pointsDensity, const Vector<label>& pointsDensity,
const Vector<scalar>& spanBox const Vector<scalar>& spanBox
); );