diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C index a83154ad56..886281274b 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/arcEdge.C @@ -30,8 +30,7 @@ Description #include "arcEdge.H" #include "mathematicalConstants.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -40,8 +39,7 @@ namespace Foam defineTypeNameAndDebug(arcEdge, 0); // Add the curvedEdge constructor functions to the hash tables - curvedEdge::addIstreamConstructorToTable - addArcEdgeIstreamConstructorToTable_; + addToRunTimeSelectionTable(curvedEdge, arcEdge, Istream); } diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C index c9d31ef6a1..6a2d41a83e 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.C @@ -41,26 +41,7 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(curvedEdge, 0); - -// Define the constructor function hash tables -HashTable* - curvedEdge::IstreamConstructorTablePtr_; - - -// Hash table Constructor called from the table add functions. - -void curvedEdge::constructTables() -{ - static bool constructed = false; - - if (!constructed) - { - curvedEdge::IstreamConstructorTablePtr_ - = new HashTable; - - constructed = true; - } -} +defineRunTimeSelectionTable(curvedEdge, Istream); // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // @@ -117,10 +98,11 @@ autoPtr curvedEdge::New(const pointField& points, Istream& is) word curvedEdgeType(is); - HashTable::iterator curvedEdgeConstructorIter = - IstreamConstructorTablePtr_->find(curvedEdgeType); + IstreamConstructorTable::iterator cstrIter = + IstreamConstructorTablePtr_ + ->find(curvedEdgeType); - if (curvedEdgeConstructorIter == IstreamConstructorTablePtr_->end()) + if (cstrIter == IstreamConstructorTablePtr_->end()) { FatalErrorIn("curvedEdge::New(const pointField&, Istream&)") << "Unknown curvedEdge type " << curvedEdgeType << endl << endl @@ -129,7 +111,7 @@ autoPtr curvedEdge::New(const pointField& points, Istream& is) << abort(FatalError); } - return autoPtr(curvedEdgeConstructorIter()(points, is)); + return autoPtr(cstrIter()(points, is)); } @@ -177,7 +159,6 @@ Ostream& operator<<(Ostream& os, const curvedEdge& p) } - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H index c568180d73..5ecf489d38 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/curvedEdge.H @@ -63,51 +63,23 @@ protected: public: - // Constructor Hash tables - - //- Construct from Istream function pointer type - typedef autoPtr (*IstreamConstructorPtr_) - (const pointField&, Istream&); - - //- Construct from Istream function pointer table pointer - static HashTable* - IstreamConstructorTablePtr_; + //- Runtime type information + TypeName("curvedEdge"); - // Hash table constructor classes and functions + // Declare run-time constructor selection tables - //- Hash table Constructor. - // Must be called from the table add functions below. - static void constructTables(); - - - //- Class to add constructor from Istream to Hash table - template - class addIstreamConstructorToTable - { - public: - - static autoPtr New + declareRunTimeSelectionTable + ( + autoPtr, + curvedEdge, + Istream, ( const pointField& points, Istream& is - ) - { - return autoPtr(new curvedEdgeType(points, is)); - } - - addIstreamConstructorToTable() - { - curvedEdge::constructTables(); - - curvedEdge::IstreamConstructorTablePtr_ - ->insert(curvedEdgeType::typeName, New); - } - }; - - - //- Runtime type information - TypeName("curvedEdge"); + ), + (points, is) + ); // Constructors diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C index f4581ed338..7263f71843 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.C @@ -26,6 +26,7 @@ License #include "polySplineEdge.H" #include "BSpline.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -34,8 +35,7 @@ namespace Foam defineTypeNameAndDebug(polySplineEdge, 0); // Add the curvedEdge constructor functions to the hash tables - curvedEdge::addIstreamConstructorToTable - addPolySplineEdgeIstreamConstructorToTable_; + addToRunTimeSelectionTable(curvedEdge, polySplineEdge, Istream); } diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H index d71685782d..1f59d5bf8e 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/polySplineEdge.H @@ -92,7 +92,7 @@ public: ); //- Construct from Istream setting pointsList - polySplineEdge(const pointField& points,Istream& is); + polySplineEdge(const pointField& points, Istream& is); // Destructor diff --git a/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C b/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C index 8fe13aefe0..b45f0ea3c2 100644 --- a/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C +++ b/applications/utilities/mesh/generation/blockMesh/curvedEdges/simpleSplineEdge.C @@ -27,9 +27,8 @@ Description \*---------------------------------------------------------------------------*/ -#include "error.H" - #include "simpleSplineEdge.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -39,10 +38,8 @@ namespace Foam // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // defineTypeNameAndDebug(simpleSplineEdge, 0); +addToRunTimeSelectionTable(curvedEdge, simpleSplineEdge, Istream); -// Add the curvedEdge constructor functions to the hash tables -curvedEdge::addIstreamConstructorToTable - addSimpleSplineEdgeIstreamConstructorToTable_; // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // diff --git a/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C b/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C index 6e9ee2f228..18ba96c4f1 100644 --- a/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C +++ b/applications/utilities/postProcessing/sampling/probeLocations/probeLocations.C @@ -39,10 +39,12 @@ using namespace Foam; int main(int argc, char *argv[]) { timeSelector::addOptions(); +# include "addRegionOption.H" + # include "setRootCase.H" # include "createTime.H" instantList timeDirs = timeSelector::select0(runTime, args); -# include "createMesh.H" +# include "createNamedMesh.H" IOprobes sniff ( diff --git a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C index 00091293fa..70eafc70a8 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C +++ b/src/OpenFOAM/meshes/polyMesh/polyPatches/constraint/processor/processorPolyPatch.C @@ -143,7 +143,7 @@ void Foam::processorPolyPatch::initGeometry() ( Pstream::blocking, neighbProcNo(), - 3*(sizeof(label) + size()*sizeof(vector) + sizeof(float)) + 3*(sizeof(label) + size()*sizeof(vector) + sizeof(scalar)) ); toNeighbProc @@ -163,7 +163,7 @@ void Foam::processorPolyPatch::calcGeometry() ( Pstream::blocking, neighbProcNo(), - 3*(sizeof(label) + size()*sizeof(vector) + sizeof(float)) + 3*(sizeof(label) + size()*sizeof(vector) + sizeof(scalar)) ); fromNeighbProc >> neighbFaceCentres_ diff --git a/src/fvMotionSolver/Make/files b/src/fvMotionSolver/Make/files index a49366e8ad..41f31c0ecc 100644 --- a/src/fvMotionSolver/Make/files +++ b/src/fvMotionSolver/Make/files @@ -1,5 +1,6 @@ fvMotionSolvers/fvMotionSolver/fvMotionSolver.C fvMotionSolvers/velocity/laplacian/velocityLaplacianFvMotionSolver.C +fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C index 68f7280c19..8c53669181 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.C @@ -55,25 +55,10 @@ namespace Foam Foam::displacementSBRStressFvMotionSolver::displacementSBRStressFvMotionSolver ( const polyMesh& mesh, - Istream& + Istream& is ) : - fvMotionSolver(mesh), - points0_ - ( - pointIOField - ( - IOobject - ( - "points", - time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE - ) - ) - ), + displacementFvMotionSolver(mesh, is), pointDisplacement_ ( IOobject @@ -132,7 +117,7 @@ Foam::displacementSBRStressFvMotionSolver::curPoints() const tmp tcurPoints ( - points0_ + pointDisplacement_.internalField() + points0() + pointDisplacement_.internalField() ); twoDCorrectPoints(tcurPoints()); @@ -208,63 +193,7 @@ void Foam::displacementSBRStressFvMotionSolver::updateMesh const mapPolyMesh& mpm ) { - fvMotionSolver::updateMesh(mpm); - - // Map points0_ - // Map points0_. Bit special since we somehow have to come up with - // a sensible points0 position for introduced points. - // Find out scaling between points0 and current points - - // Get the new points either from the map or the mesh - const pointField& points = - ( - mpm.hasMotionPoints() - ? mpm.preMotionPoints() - : fvMesh_.points() - ); - - // Note: boundBox does reduce - const vector span0 = boundBox(points0_).span(); - const vector span = boundBox(points).span(); - - vector scaleFactors(cmptDivide(span0, span)); - - pointField newPoints0(mpm.pointMap().size()); - - forAll(newPoints0, pointI) - { - label oldPointI = mpm.pointMap()[pointI]; - - if (oldPointI >= 0) - { - label masterPointI = mpm.reversePointMap()[oldPointI]; - - if (masterPointI == pointI) - { - newPoints0[pointI] = points0_[oldPointI]; - } - else - { - // New point. Assume motion is scaling. - newPoints0[pointI] = points0_[oldPointI] + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); - } - } - else - { - FatalErrorIn - ( - "displacementSBRStressFvMotionSolver::updateMesh" - "(const mapPolyMesh& mpm)" - ) << "Cannot work out coordinates of introduced vertices." - << " New vertex " << pointI << " at coordinate " - << points[pointI] << exit(FatalError); - } - } - points0_.transfer(newPoints0); + displacementFvMotionSolver::updateMesh(mpm); // Update diffusivity. Note two stage to make sure old one is de-registered // before creating/registering new one. diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H index 740fed7e7b..766025cf86 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/SBRStress/displacementSBRStressFvMotionSolver.H @@ -37,7 +37,7 @@ SourceFiles #ifndef displacementSBRStressFvMotionSolver_H #define displacementSBRStressFvMotionSolver_H -#include "fvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -53,13 +53,10 @@ class motionDiffusivity; class displacementSBRStressFvMotionSolver : - public fvMotionSolver + public displacementFvMotionSolver { // Private data - //- Reference point field - pointField points0_; - //- Point motion field mutable pointVectorField pointDisplacement_; @@ -105,12 +102,6 @@ public: // Member Functions - //- Return reference to the reference field - const pointField& points0() const - { - return points0_; - } - //- Return reference to the point motion displacement field pointVectorField& pointDisplacement() { diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C new file mode 100644 index 0000000000..aee52c717c --- /dev/null +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.C @@ -0,0 +1,146 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +\*---------------------------------------------------------------------------*/ + +#include "displacementFvMotionSolver.H" +#include "addToRunTimeSelectionTable.H" +#include "mapPolyMesh.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +// defineTypeNameAndDebug(displacementFvMotionSolver, 0); +// +// addToRunTimeSelectionTable +// ( +// fvMotionSolver, +// displacementFvMotionSolver, +// dictionary +// ); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::displacementFvMotionSolver:: +displacementFvMotionSolver +( + const polyMesh& mesh, + Istream& +) +: + fvMotionSolver(mesh), + points0_ + ( + pointIOField + ( + IOobject + ( + "points", + mesh.time().constant(), + polyMesh::meshSubDir, + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE, + false + ) + ) + ) +{} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::displacementFvMotionSolver::~displacementFvMotionSolver() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +void Foam::displacementFvMotionSolver::updateMesh(const mapPolyMesh& mpm) +{ + fvMotionSolver::updateMesh(mpm); + + // Map points0_. Bit special since we somehow have to come up with + // a sensible points0 position for introduced points. + // Find out scaling between points0 and current points + + // Get the new points either from the map or the mesh + const pointField& points = + ( + mpm.hasMotionPoints() + ? mpm.preMotionPoints() + : fvMesh_.points() + ); + + // Note: boundBox does reduce + const vector span0 = boundBox(points0_).span(); + const vector span = boundBox(points).span(); + + vector scaleFactors(cmptDivide(span0, span)); + + pointField newPoints0(mpm.pointMap().size()); + + forAll(newPoints0, pointI) + { + label oldPointI = mpm.pointMap()[pointI]; + + if (oldPointI >= 0) + { + label masterPointI = mpm.reversePointMap()[oldPointI]; + + if (masterPointI == pointI) + { + newPoints0[pointI] = points0_[oldPointI]; + } + else + { + // New point. Assume motion is scaling. + newPoints0[pointI] = points0_[oldPointI] + cmptMultiply + ( + scaleFactors, + points[pointI]-points[masterPointI] + ); + } + } + else + { + FatalErrorIn + ( + "displacementLaplacianFvMotionSolver::updateMesh" + "(const mapPolyMesh& mpm)" + ) << "Cannot work out coordinates of introduced vertices." + << " New vertex " << pointI << " at coordinate " + << points[pointI] << exit(FatalError); + } + } + points0_.transfer(newPoints0); +} + + +// ************************************************************************* // diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.H new file mode 100644 index 0000000000..aedd15f704 --- /dev/null +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/displacementFvMotionSolver/displacementFvMotionSolver.H @@ -0,0 +1,114 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +Class + Foam::displacementFvMotionSolver.H + +Description + Base class for fvMotionSolvers which calculate displacement. + +SourceFiles + displacementFvMotionSolver.C + +\*---------------------------------------------------------------------------*/ + +#ifndef displacementFvMotionSolver_H +#define displacementFvMotionSolver_H + +#include "fvMotionSolver.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class displacementFvMotionSolver Declaration +\*---------------------------------------------------------------------------*/ + +class displacementFvMotionSolver +: + public fvMotionSolver +{ + // Private data + + //- Reference point field + pointField points0_; + + + // Private Member Functions + + //- Disallow default bitwise copy construct + displacementFvMotionSolver + ( + const displacementFvMotionSolver& + ); + + //- Disallow default bitwise assignment + void operator=(const displacementFvMotionSolver&); + + +public: + + //- Runtime type information + TypeName("displacementInterpolation"); + + + // Constructors + + //- Construct from polyMesh and data stream + displacementFvMotionSolver + ( + const polyMesh&, + Istream& msDataUnused + ); + + + // Destructor + + ~displacementFvMotionSolver(); + + + // Member Functions + + //- Return reference to the reference field + const pointField& points0() const + { + return points0_; + } + + //- Update topology + virtual void updateMesh(const mapPolyMesh&); +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C index 178d1d1b2a..cdd5a999ec 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.C @@ -58,26 +58,10 @@ Foam::displacementInterpolationFvMotionSolver:: displacementInterpolationFvMotionSolver ( const polyMesh& mesh, - Istream& + Istream& is ) : - fvMotionSolver(mesh), - points0_ - ( - pointIOField - ( - IOobject - ( - "points", - mesh.time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ) - ), + displacementFvMotionSolver(mesh, is), dynamicMeshCoeffs_ ( IOdictionary @@ -174,7 +158,7 @@ displacementInterpolationFvMotionSolver forAll(fz().meshPoints(), localI) { label pointI = fz().meshPoints()[localI]; - const scalar coord = points0_[pointI][dir]; + const scalar coord = points0()[pointI][dir]; minCoord = min(minCoord, coord); maxCoord = max(maxCoord, coord); } @@ -198,7 +182,7 @@ displacementInterpolationFvMotionSolver zoneCoordinates[zoneCoordinates.size()-1] += SMALL; // Check if we have static min and max mesh bounds - const scalarField meshCoords = points0_.component(dir); + const scalarField meshCoords = points0().component(dir); scalar minCoord = gMin(meshCoords); scalar maxCoord = gMax(meshCoords); @@ -288,7 +272,7 @@ displacementInterpolationFvMotionSolver "displacementInterpolationFvMotionSolver::" "displacementInterpolationFvMotionSolver" "(const polyMesh&, Istream&)" - ) << "Did not find point " << points0_[pointI] + ) << "Did not find point " << points0()[pointI] << " coordinate " << meshCoords[pointI] << " in ranges " << rangeToCoord << abort(FatalError); @@ -344,18 +328,18 @@ Foam::displacementInterpolationFvMotionSolver:: Foam::tmp Foam::displacementInterpolationFvMotionSolver::curPoints() const { - if (mesh().nPoints() != points0_.size()) + if (mesh().nPoints() != points0().size()) { FatalErrorIn ( "displacementInterpolationFvMotionSolver::curPoints() const" ) << "The number of points in the mesh seems to have changed." << endl - << "In constant/polyMesh there are " << points0_.size() + << "In constant/polyMesh there are " << points0().size() << " points; in the current mesh there are " << mesh().nPoints() << " points." << exit(FatalError); } - tmp tcurPoints(new pointField(points0_)); + tmp tcurPoints(new pointField(points0())); pointField& curPoints = tcurPoints(); // Interpolate the diplacement of the face zones. @@ -413,68 +397,4 @@ Foam::displacementInterpolationFvMotionSolver::curPoints() const } -void Foam::displacementInterpolationFvMotionSolver::updateMesh -( - const mapPolyMesh& mpm -) -{ - fvMotionSolver::updateMesh(mpm); - - // Map points0_. Bit special since we somehow have to come up with - // a sensible points0 position for introduced points. - // Find out scaling between points0 and current points - - // Get the new points either from the map or the mesh - const pointField& points = - ( - mpm.hasMotionPoints() - ? mpm.preMotionPoints() - : fvMesh_.points() - ); - - // Note: boundBox does reduce - const vector span0 = boundBox(points0_).span(); - const vector span = boundBox(points).span(); - - vector scaleFactors(cmptDivide(span0, span)); - - pointField newPoints0(mpm.pointMap().size()); - - forAll(newPoints0, pointI) - { - label oldPointI = mpm.pointMap()[pointI]; - - if (oldPointI >= 0) - { - label masterPointI = mpm.reversePointMap()[oldPointI]; - - if (masterPointI == pointI) - { - newPoints0[pointI] = points0_[oldPointI]; - } - else - { - // New point. Assume motion is scaling. - newPoints0[pointI] = points0_[oldPointI] + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); - } - } - else - { - FatalErrorIn - ( - "displacementLaplacianFvMotionSolver::updateMesh" - "(const mapPolyMesh& mpm)" - ) << "Cannot work out coordinates of introduced vertices." - << " New vertex " << pointI << " at coordinate " - << points[pointI] << exit(FatalError); - } - } - points0_.transfer(newPoints0); -} - - // ************************************************************************* // diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H index cd7438df06..d67886ac3c 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/interpolation/displacementInterpolationFvMotionSolver.H @@ -48,7 +48,7 @@ SourceFiles #ifndef displacementInterpolationFvMotionSolver_H #define displacementInterpolationFvMotionSolver_H -#include "fvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -61,13 +61,10 @@ namespace Foam class displacementInterpolationFvMotionSolver : - public fvMotionSolver + public displacementFvMotionSolver { // Private data - //- Reference point field - pointField points0_; - //- Additional settings for motion solver dictionary dynamicMeshCoeffs_; @@ -130,21 +127,12 @@ public: // Member Functions - //- Return reference to the reference field - const pointField& points0() const - { - return points0_; - } - //- Return point location obtained from the current motion field virtual tmp curPoints() const; //- Solve for motion virtual void solve() {} - - //- Update topology - virtual void updateMesh(const mapPolyMesh&); }; diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C index a979feebb3..e57a17cce9 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.C @@ -53,26 +53,10 @@ namespace Foam Foam::displacementLaplacianFvMotionSolver::displacementLaplacianFvMotionSolver ( const polyMesh& mesh, - Istream& + Istream& is ) : - fvMotionSolver(mesh), - points0_ - ( - pointIOField - ( - IOobject - ( - "points", - time().constant(), - polyMesh::meshSubDir, - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE, - false - ) - ) - ), + displacementFvMotionSolver(mesh, is), pointDisplacement_ ( IOobject @@ -186,7 +170,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const } pointLocation_().internalField() = - points0_ + points0() + pointDisplacement_.internalField(); pointLocation_().correctBoundaryConditions(); @@ -198,7 +182,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const forAll(pz, i) { - pointLocation_()[pz[i]] = points0_[pz[i]]; + pointLocation_()[pz[i]] = points0()[pz[i]]; } } @@ -210,7 +194,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const { tmp tcurPoints ( - points0_ + pointDisplacement_.internalField() + points0() + pointDisplacement_.internalField() ); // Implement frozen points @@ -220,7 +204,7 @@ Foam::displacementLaplacianFvMotionSolver::curPoints() const forAll(pz, i) { - tcurPoints()[pz[i]] = points0_[pz[i]]; + tcurPoints()[pz[i]] = points0()[pz[i]]; } } @@ -257,74 +241,7 @@ void Foam::displacementLaplacianFvMotionSolver::updateMesh const mapPolyMesh& mpm ) { - fvMotionSolver::updateMesh(mpm); - - // Map points0_. Bit special since we somehow have to come up with - // a sensible points0 position for introduced points. - // Find out scaling between points0 and current points - - // Get the new points either from the map or the mesh - const pointField& points = - ( - mpm.hasMotionPoints() - ? mpm.preMotionPoints() - : fvMesh_.points() - ); - - // Note: boundBox does reduce - const vector span0 = boundBox(points0_).span(); - const vector span = boundBox(points).span(); - - vector scaleFactors(cmptDivide(span0, span)); - - pointField newPoints0(mpm.pointMap().size()); - - forAll(newPoints0, pointI) - { - label oldPointI = mpm.pointMap()[pointI]; - - if (oldPointI >= 0) - { - label masterPointI = mpm.reversePointMap()[oldPointI]; - - if (masterPointI == pointI) - { - newPoints0[pointI] = points0_[oldPointI]; - } - else - { - // New point. Assume motion is scaling. - newPoints0[pointI] = points0_[oldPointI] + cmptMultiply - ( - scaleFactors, - points[pointI]-points[masterPointI] - ); - } - } - else - { - FatalErrorIn - ( - "displacementLaplacianFvMotionSolver::updateMesh" - "(const mapPolyMesh& mpm)" - ) << "Cannot work out coordinates of introduced vertices." - << " New vertex " << pointI << " at coordinate " - << points[pointI] << exit(FatalError); - } - } - points0_.transfer(newPoints0); - - if (debug & 2) - { - OFstream str(time().timePath()/"points0.obj"); - Pout<< "displacementLaplacianFvMotionSolver :" - << " Writing points0_ to " << str.name() << endl; - - forAll(points0_, pointI) - { - meshTools::writeOBJ(str, points0_[pointI]); - } - } + displacementFvMotionSolver::updateMesh(mpm); // Update diffusivity. Note two stage to make sure old one is de-registered // before creating/registering new one. diff --git a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H index 67ed89c40f..6ba0c01e32 100644 --- a/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H +++ b/src/fvMotionSolver/fvMotionSolvers/displacement/laplacian/displacementLaplacianFvMotionSolver.H @@ -37,7 +37,7 @@ SourceFiles #ifndef displacementLaplacianFvMotionSolver_H #define displacementLaplacianFvMotionSolver_H -#include "fvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -53,13 +53,10 @@ class motionDiffusivity; class displacementLaplacianFvMotionSolver : - public fvMotionSolver + public displacementFvMotionSolver { // Private data - //- Reference point field - pointField points0_; - //- Point motion field mutable pointVectorField pointDisplacement_; @@ -113,13 +110,6 @@ public: // Member Functions - - //- Return reference to the reference field - const pointField& points0() const - { - return points0_; - } - //- Return reference to the point motion displacement field pointVectorField& pointDisplacement() { diff --git a/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C b/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C index 68e0151f85..8c310481d7 100644 --- a/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C +++ b/src/fvMotionSolver/pointPatchFields/derived/surfaceSlipDisplacement/surfaceSlipDisplacementPointPatchVectorField.C @@ -29,7 +29,7 @@ License #include "Time.H" #include "transformField.H" #include "fvMesh.H" -#include "displacementLaplacianFvMotionSolver.H" +#include "displacementFvMotionSolver.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -52,6 +52,254 @@ const NamedEnum surfaceSlipDisplacementPointPatchVectorField::followModeNames_; +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void surfaceSlipDisplacementPointPatchVectorField::calcProjection +( + vectorField& displacement +) const +{ + const polyMesh& mesh = patch().boundaryMesh().mesh()(); + const pointField& localPoints = patch().localPoints(); + const labelList& meshPoints = patch().meshPoints(); + + //const scalar deltaT = mesh.time().deltaT().value(); + + // Construct large enough vector in direction of projectDir so + // we're guaranteed to hit something. + + //- Per point projection vector: + const scalar projectLen = mag(mesh.bounds().max()-mesh.bounds().min()); + + // For case of fixed projection vector: + vector projectVec; + if (projectMode_ == FIXEDNORMAL) + { + vector n = projectDir_/mag(projectDir_); + projectVec = projectLen*n; + } + + + // Get fixed points (bit of a hack) + const pointZone* zonePtr = NULL; + + if (frozenPointsZone_.size() > 0) + { + const pointZoneMesh& pZones = mesh.pointZones(); + + zonePtr = &pZones[pZones.findZoneID(frozenPointsZone_)]; + + Pout<< "surfaceSlipDisplacementPointPatchVectorField : Fixing all " + << zonePtr->size() << " points in pointZone " << zonePtr->name() + << endl; + } + + // Get the starting locations from the motionSolver + const displacementFvMotionSolver& motionSolver = + mesh.lookupObject + ( + "dynamicMeshDict" + ); + const pointField& points0 = motionSolver.points0(); + + + pointField start(meshPoints.size()); + forAll(start, i) + { + start[i] = points0[meshPoints[i]] + displacement[i]; + } + + label nNotProjected = 0; + + if (projectMode_ == NEAREST) + { + List nearest; + labelList hitSurfaces; + surfaces().findNearest + ( + start, + scalarField(start.size(), sqr(projectLen)), + hitSurfaces, + nearest + ); + + forAll(nearest, 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()) + { + displacement[i] = + nearest[i].hitPoint() + - points0[meshPoints[i]]; + } + else + { + nNotProjected++; + + if (debug) + { + Pout<< " point:" << meshPoints[i] + << " coord:" << localPoints[i] + << " did not find any surface within " << projectLen + << endl; + } + } + } + } + else + { + // Do tests on all points. Combine later on. + + // 1. Check if already on surface + List 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 rightHit; + { + labelList rightSurf; + surfaces().findAnyIntersection + ( + start, + start+projectVecs, + rightSurf, + rightHit + ); + } + + List 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 + { + nNotProjected++; + + if (debug) + { + 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; + } + } + } + } + } + + reduce(nNotProjected, sumOp