From 05a22e53074d1ca040259bf488bea73dce93a93d Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Wed, 24 Aug 2011 23:37:36 +0100 Subject: [PATCH] Hot-fix: moving cone topo --- src/dynamicMesh/topoChangerFvMesh/Make/files | 2 +- .../topoChangerFvMesh/Make/options | 2 + .../mixerFvMesh/mixerFvMesh.C | 310 +++++++------ .../movingBodyTopoFvMesh.C | 306 +++++++++++++ .../movingBodyTopoFvMesh.H} | 71 ++- .../movingConeTopoFvMesh.C | 429 ------------------ .../multiMixerFvMesh/mixerRotor.C | 76 +--- 7 files changed, 531 insertions(+), 665 deletions(-) create mode 100644 src/dynamicMesh/topoChangerFvMesh/movingBodyTopoFvMesh/movingBodyTopoFvMesh.C rename src/dynamicMesh/topoChangerFvMesh/{movingConeTopoFvMesh/movingConeTopoFvMesh.H => movingBodyTopoFvMesh/movingBodyTopoFvMesh.H} (63%) delete mode 100644 src/dynamicMesh/topoChangerFvMesh/movingConeTopoFvMesh/movingConeTopoFvMesh.C diff --git a/src/dynamicMesh/topoChangerFvMesh/Make/files b/src/dynamicMesh/topoChangerFvMesh/Make/files index 810d69c28..4aa6df5bf 100644 --- a/src/dynamicMesh/topoChangerFvMesh/Make/files +++ b/src/dynamicMesh/topoChangerFvMesh/Make/files @@ -3,7 +3,7 @@ topoChangerFvMesh/topoChangerFvMesh.C linearValveFvMesh/linearValveFvMesh.C attachDetachFvMesh/attachDetachFvMesh.C linearValveLayersFvMesh/linearValveLayersFvMesh.C -movingConeTopoFvMesh/movingConeTopoFvMesh.C +movingBodyTopoFvMesh/movingBodyTopoFvMesh.C mixerFvMesh/mixerFvMesh.C multiMixerFvMesh/mixerRotor.C multiMixerFvMesh/multiMixerFvMesh.C diff --git a/src/dynamicMesh/topoChangerFvMesh/Make/options b/src/dynamicMesh/topoChangerFvMesh/Make/options index 5e46ce41d..0b21616b7 100644 --- a/src/dynamicMesh/topoChangerFvMesh/Make/options +++ b/src/dynamicMesh/topoChangerFvMesh/Make/options @@ -3,6 +3,7 @@ EXE_INC = \ -I$(LIB_SRC)/dynamicMesh/dynamicFvMesh/lnInclude \ -I$(LIB_SRC)/dynamicMesh/dynamicMesh/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/dynamicMesh/meshMotion/solidBodyMotion/lnInclude \ -I$(LIB_SRC)/dynamicMesh/meshMotion/tetDecompositionMotionSolver/lnInclude \ -I$(LIB_SRC)/tetDecompositionFiniteElement/lnInclude \ $(WM_DECOMP_INC) @@ -12,4 +13,5 @@ LIB_LIBS = \ -ldynamicFvMesh \ -ldynamicMesh \ -lmeshTools \ + -lsolidBodyMotion \ $(WM_DECOMP_LIBS) diff --git a/src/dynamicMesh/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C b/src/dynamicMesh/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C index eda0674b7..6c7b60b3a 100644 --- a/src/dynamicMesh/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C +++ b/src/dynamicMesh/topoChangerFvMesh/mixerFvMesh/mixerFvMesh.C @@ -46,50 +46,35 @@ namespace Foam void Foam::mixerFvMesh::addZonesAndModifiers() { // Add zones and modifiers for motion action - - if - ( - pointZones().size() > 0 - || faceZones().size() > 0 - || cellZones().size() > 0 - ) + if (cellZones().size() > 0) { Info<< "void mixerFvMesh::addZonesAndModifiers() : " << "Zones and modifiers already present. Skipping." << endl; - if (topoChanger_.size() == 0) + // Check definition of the modifier + if + ( + pointZones().size() > 0 + || faceZones().size() > 0 + ) { - FatalErrorIn - ( - "void mixerFvMesh::addZonesAndModifiers()" - ) << "Mesh modifiers not read properly" - << abort(FatalError); + if (topoChanger_.size() == 0) + { + FatalErrorIn + ( + "void mixerFvMesh::addZonesAndModifiers()" + ) << "Mesh modifiers not read properly. " + << "pointZones = " << pointZones().size() + << " faceZones = " << faceZones().size() + << abort(FatalError); + } } return; } - Info<< "Time = " << time().timeName() << endl - << "Adding zones and modifiers to the mesh" << endl; - - // Add zones - List pz(1); - - // Add an empty zone for cut points - - pz[0] = new pointZone - ( - "cutPointZone", - labelList(0), - 0, - pointZones() - ); - - - // Do face zones for slider - - List fz(3); + // Find patches and check sizes // Moving slider const word movingSliderName(dict_.subDict("slider").lookup("moving")); @@ -114,51 +99,84 @@ void Foam::mixerFvMesh::addZonesAndModifiers() } const polyPatch& movingSlider = boundaryMesh()[movingSliderIndex]; - - labelList isf(movingSlider.size()); - - forAll (isf, i) - { - isf[i] = movingSlider.start() + i; - } - - fz[0] = new faceZone - ( - movingSliderName + "Zone", - isf, - boolList(movingSlider.size(), false), - 0, - faceZones() - ); - - // Static slider const polyPatch& staticSlider = boundaryMesh()[staticSliderIndex]; - labelList osf(staticSlider.size()); + List pz; + List fz; - forAll (osf, i) + bool addSlider = false; + + if (movingSlider.size() > 0 && staticSlider.size() > 0) { - osf[i] = staticSlider.start() + i; + addSlider = true; + + pz.setSize(1); + fz.setSize(3); + + Info<< "Time = " << time().timeName() << endl + << "Adding zones and modifiers to the mesh" << endl; + + // Add zones + + // Add an empty zone for cut points + + pz[0] = new pointZone + ( + "cutPointZone", + labelList(0), + 0, + pointZones() + ); + + + // Do face zones for slider + + // Moving slider + labelList isf(movingSlider.size()); + + forAll (isf, i) + { + isf[i] = movingSlider.start() + i; + } + + fz[0] = new faceZone + ( + movingSliderName + "Zone", + isf, + boolList(movingSlider.size(), false), + 0, + faceZones() + ); + + // Static slider + labelList osf(staticSlider.size()); + + forAll (osf, i) + { + osf[i] = staticSlider.start() + i; + } + + fz[1] = new faceZone + ( + staticSliderName + "Zone", + osf, + boolList(staticSlider.size(), false), + 1, + faceZones() + ); + + // Add empty zone for cut faces + fz[2] = new faceZone + ( + "cutFaceZone", + labelList(0), + boolList(0, false), + 2, + faceZones() + ); } - fz[1] = new faceZone - ( - staticSliderName + "Zone", - osf, - boolList(staticSlider.size(), false), - 1, - faceZones() - ); - - // Add empty zone for cut faces - fz[2] = new faceZone - ( - "cutFaceZone", - labelList(0), - boolList(0, false), - 2, - faceZones() - ); + // Add cell zone even if slider does not exist List cz(1); @@ -194,28 +212,32 @@ void Foam::mixerFvMesh::addZonesAndModifiers() Info << "Adding point, face and cell zones" << endl; addZones(pz, fz, cz); - // Add a topology modifier - Info << "Adding topology modifiers" << endl; - topoChanger_.setSize(1); - topoChanger_.set - ( - 0, - new slidingInterface + if (addSlider) + { + // Add a topology modifier + Info << "Adding topology modifiers" << endl; + topoChanger_.setSize(1); + + topoChanger_.set ( - "mixerSlider", 0, - topoChanger_, - staticSliderName + "Zone", - movingSliderName + "Zone", - "cutPointZone", - "cutFaceZone", - staticSliderName, - movingSliderName, - slidingInterface::INTEGRAL, // Edge matching algorithm - attachDetach_, // Attach-detach action - intersection::VISIBLE // Projection algorithm - ) - ); + new slidingInterface + ( + "mixerSlider", + 0, + topoChanger_, + staticSliderName + "Zone", + movingSliderName + "Zone", + "cutPointZone", + "cutFaceZone", + staticSliderName, + movingSliderName, + slidingInterface::INTEGRAL, // Edge matching algorithm + attachDetach_, // Attach-detach action + intersection::VISIBLE // Projection algorithm + ) + ); + } // Write mesh and modifiers topoChanger_.writeOpt() = IOobject::AUTO_WRITE; @@ -226,7 +248,16 @@ void Foam::mixerFvMesh::addZonesAndModifiers() bool Foam::mixerFvMesh::attached() const { - return refCast(topoChanger_[0]).attached(); + bool result = false; + + if (topoChanger_.size() > 0) + { + result = refCast(topoChanger_[0]).attached(); + } + + reduce(result, orOp()); + + return result; } @@ -272,41 +303,43 @@ void Foam::mixerFvMesh::calcMovingMask() const } } - const word movingSliderZoneName - ( - word(dict_.subDict("slider").lookup("moving")) - + "Zone" - ); - - const labelList& movingSliderAddr = - faceZones()[faceZones().findZoneID(movingSliderZoneName)]; - - forAll (movingSliderAddr, faceI) + if (topoChanger_.size() > 0) { - const face& curFace = f[movingSliderAddr[faceI]]; + // Topo changer present. Use zones for motion + const word movingSliderZoneName + ( + word(dict_.subDict("slider").lookup("moving")) + "Zone" + ); - forAll (curFace, pointI) + const labelList& movingSliderAddr = + faceZones()[faceZones().findZoneID(movingSliderZoneName)]; + + forAll (movingSliderAddr, faceI) { - movingPointsMask[curFace[pointI]] = 1; + const face& curFace = f[movingSliderAddr[faceI]]; + + forAll (curFace, pointI) + { + movingPointsMask[curFace[pointI]] = 1; + } } - } - const word staticSliderZoneName - ( - word(dict_.subDict("slider").lookup("static")) - + "Zone" - ); + const word staticSliderZoneName + ( + word(dict_.subDict("slider").lookup("static")) + "Zone" + ); - const labelList& staticSliderAddr = - faceZones()[faceZones().findZoneID(staticSliderZoneName)]; + const labelList& staticSliderAddr = + faceZones()[faceZones().findZoneID(staticSliderZoneName)]; - forAll (staticSliderAddr, faceI) - { - const face& curFace = f[staticSliderAddr[faceI]]; - - forAll (curFace, pointI) + forAll (staticSliderAddr, faceI) { - movingPointsMask[curFace[pointI]] = 0; + const face& curFace = f[staticSliderAddr[faceI]]; + + forAll (curFace, pointI) + { + movingPointsMask[curFace[pointI]] = 0; + } } } } @@ -415,22 +448,43 @@ bool Foam::mixerFvMesh::update() autoPtr topoChangeMap = topoChanger_.changeMesh(); - if (topoChangeMap->morphing()) + bool localMorphing = topoChangeMap->morphing(); + bool globalMorphing = localMorphing; + + reduce(globalMorphing, orOp()); + + if (globalMorphing) { Info << "Attaching rotors" << endl; deleteDemandDrivenData(movingPointsMaskPtr_); // Move the sliding interface points to correct position - pointField mappedOldPointsNew(allPoints().size()); - mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap()); + if (localMorphing) + { + pointField mappedOldPointsNew(allPoints().size()); + mappedOldPointsNew.map(oldPointsNew, topoChangeMap->pointMap()); - movePoints(mappedOldPointsNew); - resetMotion(); - setV0(); + movePoints(mappedOldPointsNew); + + resetMotion(); + setV0(); + + // Move the sliding interface points to correct position + movePoints(topoChangeMap->preMotionPoints()); + } + else + { + pointField newPoints = allPoints(); + movePoints(oldPointsNew); + + resetMotion(); + setV0(); + + // Move the sliding interface points to correct position + movePoints(newPoints); + } - // Move the sliding interface points to correct position - movePoints(topoChangeMap->preMotionPoints()); } return topoChangeMap->morphing(); diff --git a/src/dynamicMesh/topoChangerFvMesh/movingBodyTopoFvMesh/movingBodyTopoFvMesh.C b/src/dynamicMesh/topoChangerFvMesh/movingBodyTopoFvMesh/movingBodyTopoFvMesh.C new file mode 100644 index 000000000..b9f4cdb58 --- /dev/null +++ b/src/dynamicMesh/topoChangerFvMesh/movingBodyTopoFvMesh/movingBodyTopoFvMesh.C @@ -0,0 +1,306 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright held by original author + \\/ 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 "movingBodyTopoFvMesh.H" +#include "Time.H" +#include "mapPolyMesh.H" +#include "layerAdditionRemoval.H" +#include "volMesh.H" +#include "transformField.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(movingBodyTopoFvMesh, 0); + + addToRunTimeSelectionTable + ( + topoChangerFvMesh, + movingBodyTopoFvMesh, + IOobject + ); +} + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +Foam::tmp +Foam::movingBodyTopoFvMesh::calcMotionMask() const +{ + Info<< "Updating vertex markup" << endl; + + tmp tvertexMarkup(new scalarField(allPoints().size(), 0)); + scalarField& vertexMarkup = tvertexMarkup(); + + cellZoneID movingCellsID(movingCellsName_, cellZones()); + + // In order to do a correct update on a mask on processor boundaries, + // Detection of moving cells should use patchNeighbourField for + // processor (not coupled!) boundaries. This is done by expanding + // a moving cell set into a field and making sure that processor patch + // points move in sync. Not done at the moment, probably best to do + // using parallel update of pointFields. HJ, 19/Feb/2011 + + // If moving cells are found, perform mark-up + if (movingCellsID.active()) + { + // Get cell-point addressing + const labelListList& cp = cellPoints(); + + // Get labels of all moving cells + const labelList& movingCells = cellZones()[movingCellsID.index()]; + + forAll (movingCells, cellI) + { + const labelList& curCp = cp[movingCells[cellI]]; + + forAll (curCp, pointI) + { + vertexMarkup[curCp[pointI]] = 1; + } + } + } + + faceZoneID frontFacesID(frontFacesName_, faceZones()); + + if (frontFacesID.active()) + { + const faceZone& frontFaces = faceZones()[frontFacesID.index()]; + + const labelList& mp = frontFaces().meshPoints(); + + forAll (mp, mpI) + { + vertexMarkup[mp[mpI]] = 1; + } + } + + faceZoneID backFacesID(backFacesName_, faceZones()); + + if (backFacesID.active()) + { + const faceZone& backFaces = faceZones()[backFacesID.index()]; + + const labelList& mp = backFaces().meshPoints(); + + forAll (mp, mpI) + { + vertexMarkup[mp[mpI]] = 1; + } + } + + return tvertexMarkup; +} + + +void Foam::movingBodyTopoFvMesh::addZonesAndModifiers() +{ + // Add zones and modifiers for motion action + + if (topoChanger_.size() > 0) + { + Info<< "void movingBodyTopoFvMesh::addZonesAndModifiers() : " + << "Zones and modifiers already present. Skipping." + << endl; + + return; + } + + // Add layer addition/removal interfaces + topoChanger_.setSize(2); + label nMods = 0; + + + faceZoneID frontFacesID(frontFacesName_, faceZones()); + faceZoneID backFacesID(backFacesName_, faceZones()); + + if (frontFacesID.active()) + { + const faceZone& frontFaces = faceZones()[frontFacesID.index()]; + + if (!frontFaces.empty()) + { + topoChanger_.set + ( + nMods, + new layerAdditionRemoval + ( + frontFacesName_ + "Layer", + nMods, + topoChanger_, + frontFacesName_, + readScalar + ( + dict_.subDict("front").lookup("minThickness") + ), + readScalar + ( + dict_.subDict("front").lookup("maxThickness") + ) + ) + ); + + nMods++; + } + } + + if (backFacesID.active()) + { + const faceZone& backFaces = faceZones()[backFacesID.index()]; + + if (!backFaces.empty()) + { + topoChanger_.set + ( + nMods, + new layerAdditionRemoval + ( + backFacesName_ + "Layer", + nMods, + topoChanger_, + backFacesName_, + readScalar + ( + dict_.subDict("back").lookup("minThickness") + ), + readScalar + ( + dict_.subDict("back").lookup("maxThickness") + ) + ) + ); + + nMods++; + } + } + + topoChanger_.setSize(nMods); + + reduce(nMods, sumOp