diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index cef09c6e94..0f94506d17 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -306,6 +306,35 @@ castellatedMeshControls // // - cellLevel will include any directional refinement // // (i.e. it will be the maximum of all three directions) //} + + //wakeBox + //{ + // mode inside; + // // Dummy base level + // levels ((10000 0)); + // + // // Optional directional refinement (after all other refinement) + // // Directional refinement + // // for all cells according to 'mode' ('inside' or 'outside'; + // // 'distance' not supported) and within certain range. E.g. + // // - for all cells with level 2-5 + // // - do one split in x direction + // levelIncrement (2 5 (1 0 0)); + // + // // Note + // // - ignores 'levels' and gap* settings. + // // - the cellLevel/pointLevels files are no longer consistent + // // with the mesh, the resulting mesh is no longer compatible + // // with e.g. dynamic refinement/unrefinement. + // // - cellLevel will include any directional refinement + // // (i.e. it will be the maximum of all three directions) + // + // // Optional directional expansion-ratio smoothing (after all + // // refinement). This will try to smooth out edge/cell size jumps + // // Specify smoothing direction and number of iterations + // nSmoothExpansion 100; + // smoothDirection (1 0 0); + //} } diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C index fa3797e2f7..0c0a5e2480 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C @@ -3148,7 +3148,6 @@ Foam::labelList Foam::hexRef8::consistentSlowRefinement2 bitSet refineCell(mesh_.nCells(), newCellsToRefine); const bitSet savedRefineCell(refineCell); - label nChanged = faceConsistentRefinement(true, cellLevel_, refineCell); { diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H index b1ff027f7c..24e9a4c9ff 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.H @@ -1053,7 +1053,6 @@ public: const scalar maxLoadUnbalance ); - //- Calculate list of cells to directionally refine labelList directionalRefineCandidates ( diff --git a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C index 6713ba2d83..dfa08a65c8 100644 --- a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C +++ b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.C @@ -595,6 +595,9 @@ Foam::shellSurfaces::shellSurfaces distances_.setSize(shellI); levels_.setSize(shellI); dirLevels_.setSize(shellI); + smoothDirection_.setSize(shellI); + nSmoothExpansion_.setSize(shellI); + nSmoothPosition_.setSize(shellI); extendedGapLevel_.setSize(shellI); extendedGapMode_.setSize(shellI); @@ -671,6 +674,19 @@ Foam::shellSurfaces::shellSurfaces } } + // Directional smoothing + // ~~~~~~~~~~~~~~~~~~~~~ + + nSmoothExpansion_[shellI] = 0; + nSmoothPosition_[shellI] = 0; + smoothDirection_[shellI] = + dict.lookupOrDefault("smoothDirection", vector::zero); + + if (smoothDirection_[shellI] != vector::zero) + { + dict.lookup("nSmoothExpansion") >> nSmoothExpansion_[shellI]; + dict.lookup("nSmoothPosition") >> nSmoothPosition_[shellI]; + } // Gap specification @@ -797,6 +813,24 @@ Foam::labelPairList Foam::shellSurfaces::directionalSelectLevel() const } +const Foam::labelList& Foam::shellSurfaces::nSmoothExpansion() const +{ + return nSmoothExpansion_; +} + + +const Foam::vectorField& Foam::shellSurfaces::smoothDirection() const +{ + return smoothDirection_; +} + + +const Foam::labelList& Foam::shellSurfaces::nSmoothPosition() const +{ + return nSmoothPosition_; +} + + void Foam::shellSurfaces::findHigherLevel ( const pointField& pt, diff --git a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H index de3edb7c02..2390a98e95 100644 --- a/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H +++ b/src/mesh/snappyHexMesh/shellSurfaces/shellSurfaces.H @@ -86,8 +86,20 @@ private: //- Per shell per distance the refinement level labelListList levels_; - //- Per shell any additional directional refinement - List> dirLevels_; + + // Directional + + //- Per shell any additional directional refinement + List> dirLevels_; + + //- Per shell the smoothing direction + vectorField smoothDirection_; + + //- Per shell the directional smoothing iterations + labelList nSmoothExpansion_; + + //- Per shell the positional smoothing iterations + labelList nSmoothPosition_; // Gap level refinement @@ -231,6 +243,15 @@ public: const direction dir, labelList& shell ) const; + + //- Per shell the smoothing direction + const vectorField& smoothDirection() const; + + //- Per shell the directional smoothing iterations + const labelList& nSmoothExpansion() const; + + //- Per shell the positional smoothing iterations + const labelList& nSmoothPosition() const; }; diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/PointIntegrateData/PointIntegrateData.H b/src/mesh/snappyHexMesh/snappyHexMeshDriver/PointIntegrateData/PointIntegrateData.H new file mode 100644 index 0000000000..a2d32ba9ed --- /dev/null +++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/PointIntegrateData/PointIntegrateData.H @@ -0,0 +1,258 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 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 . + +Class + Foam::PointIntegrateData + +Description + Integrate along selected edges using PointEdgeWave. + +SourceFiles + PointIntegrateDataI.H + +\*---------------------------------------------------------------------------*/ + +#ifndef PointIntegrateData_H +#define PointIntegrateData_H + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Forward declaration of classes +class Istream; +class Ostream; +template +class PointIntegrateData; + +// Forward declaration of friend functions and operators +template +Ostream& operator<<(Ostream&, const PointIntegrateData&); +template +Istream& operator>>(Istream&, PointIntegrateData&); + +/*---------------------------------------------------------------------------*\ + Class PointIntegrateData declaration +\*---------------------------------------------------------------------------*/ + +template +class PointIntegrateData +{ +private: + + // Private data + + //- Valid flag + bool valid_; + + //- Integrated data + DataType data_; + + +public: + + //- Class used to pass extra data + class trackingData + { + public: + + UList& edgeData_; + + trackingData(UList& edgeData) + : + edgeData_(edgeData) + {} + }; + + + + // Constructors + + //- Construct null + inline PointIntegrateData(); + + //- Construct from data + inline PointIntegrateData(const DataType& data); + + + // Member Functions + + // Access + + //- Const access the data + inline const DataType& data() const + { + return data_; + }; + + + // Needed by PointEdgeWave + + //- Check whether original (invalid) value. + template + inline bool valid(TrackingData& td) const; + + //- Check for identical geometrical data. Used for cyclics checking. + template + inline bool sameGeometry + ( + const PointIntegrateData&, + const scalar tol, + TrackingData& td + ) const; + + //- Convert origin to relative vector to leaving point + // (= point coordinate) + template + inline void leaveDomain + ( + const polyPatch& patch, + const label patchPointi, + const point& pos, + TrackingData& td + ); + + //- Convert relative origin to absolute by adding entering point + template + inline void enterDomain + ( + const polyPatch& patch, + const label patchPointi, + const point& pos, + TrackingData& td + ); + + //- Apply rotation matrix to the data + template + inline void transform + ( + const tensor& rotTensor, + TrackingData& td + ); + + //- Influence of edge on point + template + inline bool updatePoint + ( + const polyMesh& mesh, + const label pointI, + const label edgeI, + const PointIntegrateData& edgeInfo, + const scalar tol, + TrackingData& td + ); + + //- Influence of different value on same point. + // Merge new and old info. + template + inline bool updatePoint + ( + const polyMesh& mesh, + const label pointI, + const PointIntegrateData& newPointInfo, + const scalar tol, + TrackingData& td + ); + + //- Influence of different value on same point. + // No information about current position whatsoever. + template + inline bool updatePoint + ( + const PointIntegrateData& newPointInfo, + const scalar tol, + TrackingData& td + ); + + //- Influence of point on edge. + template + inline bool updateEdge + ( + const polyMesh& mesh, + const label edgeI, + const label pointI, + const PointIntegrateData& pointInfo, + const scalar tol, + TrackingData& td + ); + + //- Same (like operator==) + template + inline bool equal + ( + const PointIntegrateData&, + TrackingData& td + ) const; + + + // Member Operators + + // Needed for List IO + inline bool operator==(const PointIntegrateData&) const; + inline bool operator!=(const PointIntegrateData&) const; + + + // IOstream Operators + + friend Ostream& operator<< + ( + Ostream&, + const PointIntegrateData& + ); + friend Istream& operator>> + ( + Istream&, + PointIntegrateData& + ); +}; + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +//- Data associated with PointIntegrateData types is contiguous + +template<> +inline bool contiguous>() +{ + return true; +} + +template<> +inline bool contiguous>() +{ + return true; +} + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#include "PointIntegrateDataI.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/PointIntegrateData/PointIntegrateDataI.H b/src/mesh/snappyHexMesh/snappyHexMeshDriver/PointIntegrateData/PointIntegrateDataI.H new file mode 100644 index 0000000000..c22cdac898 --- /dev/null +++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/PointIntegrateData/PointIntegrateDataI.H @@ -0,0 +1,304 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 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 . + +\*---------------------------------------------------------------------------*/ + +#include "polyMesh.H" +#include "transform.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +inline Foam::PointIntegrateData::PointIntegrateData() +: + valid_(false) +{} + + +template +inline Foam::PointIntegrateData::PointIntegrateData +( + const DataType& data +) +: + valid_(true), + data_(data) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +template +inline bool Foam::PointIntegrateData::valid(TrackingData& td) const +{ + return valid_; +} + + +template +template +inline bool Foam::PointIntegrateData::sameGeometry +( + const PointIntegrateData&, + const scalar tol, + TrackingData& td +) const +{ + return true; +} + + +template +template +inline void Foam::PointIntegrateData::leaveDomain +( + const polyPatch& patch, + const label patchPointi, + const point& pos, + TrackingData& td +) +{} + + +template +template +inline void Foam::PointIntegrateData::enterDomain +( + const polyPatch& patch, + const label patchPointi, + const point& pos, + TrackingData& td +) +{} + + +template +template +inline void Foam::PointIntegrateData::transform +( + const tensor& rotTensor, + TrackingData& td +) +{ + this->data_ = Foam::transform(rotTensor, this->data_); +} + + +template +template +inline bool Foam::PointIntegrateData::updatePoint +( + const polyMesh& mesh, + const label pointI, + const label edgeI, + const PointIntegrateData& edgeInfo, + const scalar tol, + TrackingData& td +) +{ + // Update point from an edge + if (!valid_) + { + if (!edgeInfo.valid_) + { + FatalErrorInFunction<< "edgeInfo:" << edgeInfo << exit(FatalError); + } + this->operator=(edgeInfo); + return true; + } + else + { + return false; + } +} + + +template +template +inline bool Foam::PointIntegrateData::updatePoint +( + const polyMesh& mesh, + const label pointI, + const PointIntegrateData& newPointInfo, + const scalar tol, + TrackingData& td +) +{ + // Update point from coupled point + if (!valid_) + { + if (!newPointInfo.valid_) + { + FatalErrorInFunction<< "newPointInfo:" << newPointInfo + << exit(FatalError); + } + this->operator=(newPointInfo); + return true; + } + else + { + return false; + } +} + + +template +template +inline bool Foam::PointIntegrateData::updatePoint +( + const PointIntegrateData& newPointInfo, + const scalar tol, + TrackingData& td +) +{ + if (!valid_) + { + if (!newPointInfo.valid_) + { + FatalErrorInFunction<< "newPointInfo:" << newPointInfo + << exit(FatalError); + } + this->operator=(newPointInfo); + return true; + } + else + { + return false; + } +} + + +template +template +inline bool Foam::PointIntegrateData::updateEdge +( + const polyMesh& mesh, + const label edgeI, + const label pointI, + const PointIntegrateData& pointInfo, + const scalar tol, + TrackingData& td +) +{ + if (!valid_) + { + if (!pointInfo.valid(td)) + { + FatalErrorInFunction<< "problem: invalid point:" + << mesh.points()[pointI] + << " data:" << pointInfo + << exit(FatalError); + } + this->data_ = pointInfo.data_ + td.edgeData_[edgeI]; + this->valid_ = true; + return true; + } + else + { + return false; + } +} + +//- Same (like operator==) +template +template +inline bool Foam::PointIntegrateData::equal +( + const PointIntegrateData& pi, + TrackingData& td +) const +{ + if (!valid_) + { + return false; + } + else if (!pi.valid_) + { + FatalErrorInFunction << "pi:" << pi + << exit(FatalError); + return false; + } + else + { + return this->data_ == pi.data_; + } +} + + +// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // + +template +inline bool Foam::PointIntegrateData::operator== +( + const Foam::PointIntegrateData& rhs +) +const +{ + return this->data_ == rhs.data_; +} + + +template +inline bool Foam::PointIntegrateData::operator!= +( + const Foam::PointIntegrateData& rhs +) +const +{ + return !(*this == rhs); +} + + +// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // + +template +inline Foam::Ostream& Foam::operator<< +( + Ostream& os, + const PointIntegrateData& pd +) +{ + if (os.format() == IOstream::ASCII) + { + return os << pd.valid_ << token::SPACE << pd.data(); + } + else + { + return os << pd.valid_ << pd.data(); + } +} + + +template +inline Foam::Istream& Foam::operator>> +( + Istream& is, + PointIntegrateData& pd +) +{ + return is >> pd.valid_ >> pd.data_; +} + + +// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointData.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointData.C deleted file mode 100644 index e3d36bfcb3..0000000000 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointData.C +++ /dev/null @@ -1,53 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 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 . - -\*---------------------------------------------------------------------------*/ - -#include "pointData.H" - -// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // - -Foam::Ostream& Foam::operator<<(Ostream& os, const pointData& wDist) -{ - if (os.format() == IOstream::ASCII) - { - return os - << static_cast(wDist) - << token::SPACE << wDist.s() << token::SPACE << wDist.v(); - } - else - { - return os - << static_cast(wDist) - << wDist.s() << wDist.v(); - } -} - - -Foam::Istream& Foam::operator>>(Istream& is, pointData& wDist) -{ - return is >> static_cast(wDist) >> wDist.s_ >> wDist.v_; -} - - -// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointData.H b/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointData.H deleted file mode 100644 index 86f615b343..0000000000 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointData.H +++ /dev/null @@ -1,193 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2015 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 . - -Class - Foam::pointData - -Description - Variant of pointEdgePoint with some transported additional data. - WIP - should be templated on data like wallDistData. - Passive vector v_ is not a coordinate (so no enterDomain/leaveDomain - transformation needed) - -SourceFiles - pointDataI.H - pointData.C - -\*---------------------------------------------------------------------------*/ - -#ifndef pointData_H -#define pointData_H - -#include "pointEdgePoint.H" - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -// Forward declaration of friend functions and operators - -class pointData; - -Istream& operator>>(Istream&, pointData&); -Ostream& operator<<(Ostream&, const pointData&); - - -/*---------------------------------------------------------------------------*\ - Class pointData Declaration -\*---------------------------------------------------------------------------*/ - -class pointData -: - public pointEdgePoint -{ - // Private data - - //- Additional information. - scalar s_; - - //- Additional information. - vector v_; - -public: - - // Constructors - - //- Construct null - inline pointData(); - - //- Construct from origin, distance - inline pointData - ( - const point& origin, - const scalar distSqr, - const scalar s, - const vector& v - ); - - //- Construct as copy - inline pointData(const pointData&); - - - // Member Functions - - // Access - - inline scalar s() const; - - inline const vector& v() const; - - - // Needed by meshWave - - //- Apply rotation matrix to origin - template - inline void transform - ( - const tensor& rotTensor, - TrackingData& td - ); - - //- Influence of edge on point - template - inline bool updatePoint - ( - const polyMesh& mesh, - const label pointi, - const label edgeI, - const pointData& edgeInfo, - const scalar tol, - TrackingData& td - ); - - //- Influence of different value on same point. - // Merge new and old info. - template - inline bool updatePoint - ( - const polyMesh& mesh, - const label pointi, - const pointData& newPointInfo, - const scalar tol, - TrackingData& td - ); - - //- Influence of different value on same point. - // No information about current position whatsoever. - template - inline bool updatePoint - ( - const pointData& newPointInfo, - const scalar tol, - TrackingData& td - ); - - //- Influence of point on edge. - template - inline bool updateEdge - ( - const polyMesh& mesh, - const label edgeI, - const label pointi, - const pointData& pointInfo, - const scalar tol, - TrackingData& td - ); - - // Member Operators - - // Needed for List IO - inline bool operator==(const pointData&) const; - inline bool operator!=(const pointData&) const; - - - // IOstream Operators - - friend Ostream& operator<<(Ostream&, const pointData&); - friend Istream& operator>>(Istream&, pointData&); -}; - - -//- Data associated with pointData as contiguous as pointEdgePoint -template<> -inline bool contiguous() -{ - return contiguous(); -} - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#include "pointDataI.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointDataI.H b/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointDataI.H deleted file mode 100644 index cc95cca046..0000000000 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/pointData/pointDataI.H +++ /dev/null @@ -1,237 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 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 . - -\*---------------------------------------------------------------------------*/ - -#include "polyMesh.H" -#include "transform.H" - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -// Null constructor -inline Foam::pointData::pointData() -: - pointEdgePoint(), - s_(GREAT), - v_(point::max) -{} - - -// Construct from origin, distance -inline Foam::pointData::pointData -( - const point& origin, - const scalar distSqr, - const scalar s, - const vector& v -) -: - pointEdgePoint(origin, distSqr), - s_(s), - v_(v) -{} - - -// Construct as copy -inline Foam::pointData::pointData(const pointData& wpt) -: - pointEdgePoint(wpt), - s_(wpt.s()), - v_(wpt.v()) -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -inline Foam::scalar Foam::pointData::s() const -{ - return s_; -} - - -inline const Foam::vector& Foam::pointData::v() const -{ - return v_; -} - - -template -inline void Foam::pointData::transform -( - const tensor& rotTensor, - TrackingData& td -) -{ - pointEdgePoint::transform(rotTensor, td); - v_ = Foam::transform(rotTensor, v_); -} - - -// Update this with information from connected edge -template -inline bool Foam::pointData::updatePoint -( - const polyMesh& mesh, - const label pointi, - const label edgeI, - const pointData& edgeInfo, - const scalar tol, - TrackingData& td -) -{ - if - ( - pointEdgePoint::updatePoint - ( - mesh, - pointi, - edgeI, - edgeInfo, - tol, - td - ) - ) - { - s_ = edgeInfo.s_; - v_ = edgeInfo.v_; - return true; - } - else - { - return false; - } -} - -// Update this with new information on same point -template -inline bool Foam::pointData::updatePoint -( - const polyMesh& mesh, - const label pointi, - const pointData& newPointInfo, - const scalar tol, - TrackingData& td -) -{ - if - ( - pointEdgePoint::updatePoint - ( - mesh, - pointi, - newPointInfo, - tol, - td - ) - ) - { - s_ = newPointInfo.s_; - v_ = newPointInfo.v_; - return true; - } - else - { - return false; - } -} - - -// Update this with new information on same point. No extra information. -template -inline bool Foam::pointData::updatePoint -( - const pointData& newPointInfo, - const scalar tol, - TrackingData& td -) -{ - if (pointEdgePoint::updatePoint(newPointInfo, tol, td)) - { - s_ = newPointInfo.s_; - v_ = newPointInfo.v_; - return true; - } - else - { - return false; - } -} - - -// Update this with information from connected point -template -inline bool Foam::pointData::updateEdge -( - const polyMesh& mesh, - const label edgeI, - const label pointi, - const pointData& pointInfo, - const scalar tol, - TrackingData& td - -) -{ - if - ( - pointEdgePoint::updateEdge - ( - mesh, - edgeI, - pointi, - pointInfo, - tol, - td - ) - ) - { - s_ = pointInfo.s_; - v_ = pointInfo.v_; - return true; - } - else - { - return false; - } -} - - -// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // - -inline bool Foam::pointData::operator==(const Foam::pointData& rhs) -const -{ - return - pointEdgePoint::operator==(rhs) - && (s() == rhs.s()) - && (v() == rhs.v()); -} - - -inline bool Foam::pointData::operator!=(const Foam::pointData& rhs) -const -{ - return !(*this == rhs); -} - - -// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C index 7a20491291..9a9d11047f 100644 --- a/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C +++ b/src/mesh/snappyHexMesh/snappyHexMeshDriver/snappyRefineDriver.C @@ -41,6 +41,8 @@ License #include "labelVector.H" #include "profiling.H" #include "searchableSurfaces.H" +#include "fvMeshSubset.H" +#include "interpolationTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -1642,7 +1644,6 @@ Foam::label Foam::snappyRefineDriver::directionalShellRefine for (direction dir = 0; dir < vector::nComponents; dir++) { // Select the cells that need to be refined in certain direction: - // // - cell inside/outside shell // - original cellLevel (using mapping) mentioned in levelIncrement // - dirCellLevel not yet up to cellLevel+levelIncrement @@ -1800,6 +1801,517 @@ Foam::label Foam::snappyRefineDriver::directionalShellRefine } +void Foam::snappyRefineDriver::mergeAndSmoothRatio +( + const scalarList& allSeedPointDist, + const label nSmoothExpansion, + List>& keyAndValue +) +{ + // Merge duplicate distance from coupled locations to get unique + // distances to operate on, do on master + SortableList unmergedDist(allSeedPointDist); + DynamicList mergedDist; + + scalar prevDist = GREAT; + forAll(unmergedDist, i) + { + scalar curDist = unmergedDist[i]; + scalar difference = mag(curDist - prevDist); + if (difference > meshRefiner_.mergeDistance()) + //if (difference > 0.01) + { + mergedDist.append(curDist); + prevDist = curDist; + } + } + + // Sort the unique distances + SortableList sortedDist(mergedDist); + labelList indexSet = sortedDist.indices(); + + // Get updated position starting from original (undistorted) mesh + scalarList seedPointsNewLocation = sortedDist; + + scalar initResidual = 0.0; + scalar prevIterResidual = GREAT; + + for (label iter = 0; iter < nSmoothExpansion; iter++) + { + + // Position based edge averaging algorithm operated on + // all seed plane locations in normalized form. + // + // 0 1 2 3 4 5 6 (edge numbers) + // ---x---x---x---x---x---x--- + // 0 1 2 3 4 5 (point numbers) + // + // Average of edge 1-3 in terms of position + // = (point3 - point0)/3 + // Keeping points 0-1 frozen, new position of point 2 + // = position2 + (average of edge 1-3 as above) + for(label i = 2; i 0 + || shells.nSmoothPosition()[shellI] > 0 + ) + { + label surfi = shells.shells()[shellI]; + const vector& userDirection = shells.smoothDirection()[shellI]; + + + // Extract inside points + labelList pointLabels; + { + // Get inside points + List volType; + geometry[surfi].getVolumeType(baseMesh.points(), volType); + + label nInside = 0; + forAll(volType, pointi) + { + if (volType[pointi] == volumeType::INSIDE) + { + nInside++; + } + } + pointLabels.setSize(nInside); + nInside = 0; + forAll(volType, pointi) + { + if (volType[pointi] == volumeType::INSIDE) + { + pointLabels[nInside++] = pointi; + } + } + + //bitSet isInsidePoint(baseMesh.nPoints()); + //forAll(volType, pointi) + //{ + // if (volType[pointi] == volumeType::INSIDE) + // { + // isInsidePoint.set(pointi); + // } + //} + //pointLabels = isInsidePoint.used(); + } + + // Mark all directed edges + bitSet isXEdge(baseMesh.edges().size()); + { + const edgeList& edges = baseMesh.edges(); + forAll(edges, edgei) + { + const edge& e = edges[edgei]; + vector eVec(e.vec(baseMesh.points())); + eVec /= mag(eVec); + if (mag(eVec&userDirection) > 0.9) + { + isXEdge.set(edgei); + } + } + } + + // Get the extreme of smoothing region and + // normalize all points within + const scalar totalLength = + geometry[surfi].bounds().span() + & userDirection; + const scalar startPosition = + geometry[surfi].bounds().min() + & userDirection; + + scalarField normalizedPosition(pointLabels.size(), 0); + forAll(pointLabels, i) + { + label pointi = pointLabels[i]; + normalizedPosition[i] = + ( + ((baseMesh.points()[pointi]&userDirection) - startPosition) + / totalLength + ); + } + + // Sort the normalized position + labelList order; + sortedOrder(normalizedPosition, order); + + DynamicList seedPointDist; + + // Select points from finest refinement (one point-per plane) + scalar prevDist = GREAT; + forAll(order, i) + { + label pointi = order[i]; + scalar curDist = normalizedPosition[pointi]; + if (mag(curDist - prevDist) > meshRefiner_.mergeDistance()) + { + seedPointDist.append(curDist); + prevDist = curDist; + } + } + + // Collect data from all processors + scalarList allSeedPointDist; + { + List gatheredDist(Pstream::nProcs()); + gatheredDist[Pstream::myProcNo()] = seedPointDist; + Pstream::gatherList(gatheredDist); + + // Combine processor lists into one big list. + allSeedPointDist = + ListListOps::combine + ( + gatheredDist, accessOp() + ); + } + + // Pre-set the points not to smooth (after expansion) + bitSet isFrozenPoint(baseMesh.nPoints(), true); + + { + scalar minSeed = min(allSeedPointDist); + Pstream::scatter(minSeed); + scalar maxSeed = max(allSeedPointDist); + Pstream::scatter(maxSeed); + + forAll(normalizedPosition, posI) + { + const scalar pos = normalizedPosition[posI]; + if + ( + (mag(pos-minSeed) < meshRefiner_.mergeDistance()) + || (mag(pos-maxSeed) < meshRefiner_.mergeDistance()) + ) + { + // Boundary point: freeze + isFrozenPoint.set(pointLabels[posI]); + } + else + { + // Internal to moving region + isFrozenPoint.unset(pointLabels[posI]); + } + } + } + + Info<< "Smoothing " << geometry[surfi].name() << ':' << nl + << " Direction : " << userDirection << nl + << " Number of points : " + << returnReduce(pointLabels.size(), sumOp