From 6208a5ccd14f79679875d42e89f696559d6c51c8 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Fri, 27 May 2011 20:38:01 +0100 Subject: [PATCH] Engine updates: parallelisation of topo changes --- .../setEngineValveSlidingConstraint.H | 41 +-- .../addSimpleTwoStrokeModifiers.C | 2 - .../twoStrokeEngine/addPistonLayer.H | 60 ++++ .../addTwoStrokeEngineModifiers.C | 233 +++++++------ .../twoStrokeEngine/twoStrokeEngine.C | 10 +- .../twoStrokeEngineCalculate.C | 23 +- .../twoStrokeEngineInitialize.C | 36 +- .../twoStrokeEngine/twoStrokeEngineMove.C | 330 ++++++++++-------- ...ddPistonLayerAdditionRemovalMeshModifier.H | 14 +- src/engine/include/createEngineDynamicMesh.H | 3 +- .../simpleEngineTopoFvMesh.C | 7 +- .../simpleEngineTopoFvMesh.H | 18 +- 12 files changed, 436 insertions(+), 341 deletions(-) create mode 100644 src/engine/engineTopoChangerMesh/twoStrokeEngine/addPistonLayer.H diff --git a/src/engine/engineTopoChangerMesh/engineValveSliding/setEngineValveSlidingConstraint.H b/src/engine/engineTopoChangerMesh/engineValveSliding/setEngineValveSlidingConstraint.H index 8934b13fa..b436e5095 100644 --- a/src/engine/engineTopoChangerMesh/engineValveSliding/setEngineValveSlidingConstraint.H +++ b/src/engine/engineTopoChangerMesh/engineValveSliding/setEngineValveSlidingConstraint.H @@ -9,7 +9,6 @@ forAll(valves_, valveI) { - vector valveVel = valves_[valveI].curVelocity()*valves_[valveI].cs().axis(); @@ -17,10 +16,9 @@ { valveVel = vector::zero; } - - + { - + // label movingPtsIndex = pZones.findZoneID("movingPointsV"+Foam::name(valveI + 1)); // const labelList& movingPointsV = pZones[movingPtsIndex]; /* @@ -28,17 +26,17 @@ { constrainedPoints.append(movingPointsV[mpI]); constrainedVelocity.append(valveVel); - + constraintSize++; } */ - + label movingCellsIndex = cZones.findZoneID("movingCellsZoneV"+Foam::name(valveI + 1)); const labelList& movingCellsV = cZones[movingCellsIndex]; - + labelList movingPointsV; boolList count(newPoints.size(), false); - + forAll(movingCellsV, cellI) { const labelList& curCellPoints = cp[movingCellsV[cellI]]; @@ -76,17 +74,15 @@ { constrainedPoints.append(movingPointsV[mpI]); constrainedVelocity.append(valveVel); - + constraintSize++; } - } { - // label staticPtsIndex = pZones.findZoneID("staticPointsV"+Foam::name(valveI + 1)); // const labelList& staticPointsV = pZones[staticPtsIndex]; -/* +/* forAll(staticPointsV, spI) { constrainedPoints.append(staticPointsV[spI]); @@ -101,7 +97,7 @@ labelList staticPointsV; boolList count(newPoints.size(), false); - + forAll(staticCellsV, cellI) { const labelList& curCellPoints = cp[staticCellsV[cellI]]; @@ -134,7 +130,7 @@ nCounted++; } } - + forAll(staticPointsV, spI) { constrainedPoints.append(staticPointsV[spI]); @@ -145,16 +141,16 @@ } } - + if(piston().patchID().active()) { vector pistonVel = piston().cs().axis()*engineTime_.pistonSpeed().value(); -/* +/* label pistonPtsIndex = pZones.findZoneID("movingPistonPoints"); const labelList& movingPointsP = pZones[pistonPtsIndex]; - + forAll(movingPointsP, mpI) { constrainedPoints.append(movingPointsP[mpI]); @@ -165,11 +161,11 @@ label pistonCellsIndex = cZones.findZoneID("movingPistonCells"); const labelList& movingCellsP = cZones[pistonCellsIndex]; - + labelList movingPointsP; - + boolList count(newPoints.size(), false); - + forAll(movingCellsP, cellI) { const labelList& curCellPoints = cp[movingCellsP[cellI]]; @@ -202,8 +198,7 @@ nCounted++; } } - - + forAll(movingPointsP, mpI) { constrainedPoints.append(movingPointsP[mpI]); @@ -213,6 +208,4 @@ } - - } diff --git a/src/engine/engineTopoChangerMesh/simpleTwoStroke/addSimpleTwoStrokeModifiers.C b/src/engine/engineTopoChangerMesh/simpleTwoStroke/addSimpleTwoStrokeModifiers.C index c7d3c1e3b..7dd2d9209 100644 --- a/src/engine/engineTopoChangerMesh/simpleTwoStroke/addSimpleTwoStrokeModifiers.C +++ b/src/engine/engineTopoChangerMesh/simpleTwoStroke/addSimpleTwoStrokeModifiers.C @@ -301,8 +301,6 @@ void Foam::simpleTwoStroke::addZonesAndModifiers() nFaceZones++; - Info << "cut p" << endl; - pz[nPointZones] = new pointZone ( "cutPointZone", diff --git a/src/engine/engineTopoChangerMesh/twoStrokeEngine/addPistonLayer.H b/src/engine/engineTopoChangerMesh/twoStrokeEngine/addPistonLayer.H new file mode 100644 index 000000000..7e33995b4 --- /dev/null +++ b/src/engine/engineTopoChangerMesh/twoStrokeEngine/addPistonLayer.H @@ -0,0 +1,60 @@ +if (piston().patchID().active()) +{ + // Add faces for piston layering + // Note: because of operation of layer addition/removal + // (reduce function in layer addition/removal thickness) + // the layering modifier needs to be present on all processors + // even if the patch size is zero + // HJ, 7/Mar/2011 + + faceSet pistonFaceSet(*this, piston().pistonFaceSetName()); + + boolList flipPistonFaces(pistonFaceSet.toc().size(), false); + label nSet = pistonFaceSet.toc().size(); + label nFlip = 0; + + forAll (flipPistonFaces, facei) + { + scalar scalProd = + (faceAreas()[pistonFaceSet.toc()[facei]] & vector(0, 0, 1)); + + if (scalProd < 0) + { + flipPistonFaces[facei] = true; + nFlip++; + } + } + + Info << "nSet = " << nSet << endl; + Info << "nFlip = " << nFlip << endl; + + fz[nFaceZones] = + ( + new faceZone + ( + "pistonLayerFaces", + pistonFaceSet.toc(), + flipPistonFaces, + nFaceZones, + faceZones() + ) + ); + + nFaceZones++; + + cellSet movingPistonCells(*this, piston().pistonCellSetName()); + + Info<< "Adding piston cell set" << endl; + cz[nCellZones] = + ( + new cellZone + ( + "pistonCells", + movingPistonCells.toc(), + nCellZones, + cellZones() + ) + ); + + nCellZones++; +} diff --git a/src/engine/engineTopoChangerMesh/twoStrokeEngine/addTwoStrokeEngineModifiers.C b/src/engine/engineTopoChangerMesh/twoStrokeEngine/addTwoStrokeEngineModifiers.C index 183d37b10..1d14e6d86 100644 --- a/src/engine/engineTopoChangerMesh/twoStrokeEngine/addTwoStrokeEngineModifiers.C +++ b/src/engine/engineTopoChangerMesh/twoStrokeEngine/addTwoStrokeEngineModifiers.C @@ -62,25 +62,24 @@ void Foam::twoStrokeEngine::addZonesAndModifiers() return; } - Info << "checkAndCalculate()" << endl; checkAndCalculate(); Info<< "Time = " << engTime().theta() << endl << "Adding zones to the engine mesh" << endl; - - //fz = 4: virtual piston, outSidePort, insidePort, cutFaceZone - //pz = 2: piston points, cutPointZone - //cz = 1: moving mask + // Zones to add + // fz = 4: virtual piston, outSidePort, insidePort, cutFaceZone + // pz = 2: piston points, cutPointZone + // cz = 1: moving mask label nPorts = scavInCylPatches_.size(); - DynamicList pz(2 + nPorts); - DynamicList fz(3*nPorts + 1); + List pz(nPorts + 2); + List fz(3*nPorts + 1); // Added piston cells and head cells - DynamicList cz(3); + List cz(3); label nPointZones = 0; label nFaceZones = 0; @@ -88,24 +87,11 @@ void Foam::twoStrokeEngine::addZonesAndModifiers() Info << "Adding piston layer faces" << endl; -# include "addPistonLayerHrv.H" +# include "addPistonLayer.H" -// adding head points (does not move) + // Add head points that do not move { -// pointSet headPointSet(*this, headPointsSetName_); - -// pz[nPointZones] = -// new pointZone -// ( -// "headPoints", -// headPointSet.toc(), -// nPointZones, -// pointZones() -// ); - -// nPointZones++; - cellSet headCellSet(*this, headCellsSetName_); cz[nCellZones] = @@ -120,9 +106,9 @@ void Foam::twoStrokeEngine::addZonesAndModifiers() nCellZones++; } -// Sliding interface for scavenging ports + // Sliding interface for scavenging ports - if(nPorts > 0) + if (nPorts > 0) { forAll(scavInCylPatches_, patchi) { @@ -133,76 +119,85 @@ void Foam::twoStrokeEngine::addZonesAndModifiers() boundaryMesh().findPatchID(scavInCylPatches_[patchi]) ]; - labelList isf(innerScav.size()); - - forAll (isf, i) - { - isf[i] = innerScav.start() + i; - } - - fz[nFaceZones] = new faceZone - ( - scavInCylPatches_[patchi] + "Zone" + Foam::name(patchi + 1), - isf, - boolList(innerScav.size(), false), - nFaceZones, - faceZones() - ); - - nFaceZones++; - // Outer slider - const polyPatch& outerScav = boundaryMesh() [ boundaryMesh().findPatchID(scavInPortPatches_[patchi]) ]; - labelList osf(outerScav.size()); - - forAll (osf, i) + Pout<< "A: " << innerScav.size() << " " << outerScav.size() + << endl; + // Add zone if both patches has got faces + if (!innerScav.empty() && !outerScav.empty()) { - osf[i] = outerScav.start() + i; + // Inner + labelList isf(innerScav.size()); + + forAll (isf, i) + { + isf[i] = innerScav.start() + i; + } + + fz[nFaceZones] = new faceZone + ( + scavInCylPatches_[patchi] + "Zone" + + Foam::name(patchi + 1), + isf, + boolList(innerScav.size(), false), + nFaceZones, + faceZones() + ); + + nFaceZones++; + + // Outer + labelList osf(outerScav.size()); + + forAll (osf, i) + { + osf[i] = outerScav.start() + i; + } + + fz[nFaceZones] = new faceZone + ( + scavInPortPatches_[patchi] + "Zone" + + Foam::name(patchi + 1), + osf, + boolList(outerScav.size(), false), + nFaceZones, + faceZones() + ); + + nFaceZones++; + + // Cut faces + fz[nFaceZones] = new faceZone + ( + "cutFaceZone" + Foam::name(patchi + 1), + labelList(0), + boolList(0, false), + nFaceZones, + faceZones() + ); + + nFaceZones++; + + // Cut points + pz[nPointZones] = new pointZone + ( + "cutPointZone" + Foam::name(patchi + 1), + labelList(0), + nPointZones, + pointZones() + ); + + nPointZones++; } - - fz[nFaceZones] = new faceZone - ( - scavInPortPatches_[patchi] + "Zone" + Foam::name(patchi + 1), - osf, - boolList(outerScav.size(), false), - nFaceZones, - faceZones() - ); - - nFaceZones++; - - fz[nFaceZones] = new faceZone - ( - "cutFaceZone" + Foam::name(patchi + 1), - labelList(0), - boolList(0, false), - nFaceZones, - faceZones() - ); - - nFaceZones++; - - Info << "cut p" << endl; - - pz[nPointZones] = new pointZone - ( - "cutPointZone" + Foam::name(patchi + 1), - labelList(0), - nPointZones, - pointZones() - ); - - nPointZones++; } } - Info << "moving cells" << endl; + Info << "Adding moving cells zone" << endl; { cellSet movingCells(*this, movingCellSetName_); @@ -218,9 +213,7 @@ void Foam::twoStrokeEngine::addZonesAndModifiers() nCellZones++; } - Info << "moving cells added" << endl; - - Info<< "Adding " << nPointZones << " point, " + Pout<< "Adding " << nPointZones << " point, " << nFaceZones << " face zones and " << nCellZones << " cell zones" << endl; @@ -229,40 +222,64 @@ void Foam::twoStrokeEngine::addZonesAndModifiers() cz.setSize(nCellZones); addZones(pz, fz, cz); - List tm(1 + nPorts); + List tm(nPorts + 1); label nMods = 0; // Add piston layer addition # include "addPistonLayerAdditionRemovalMeshModifier.H" - if(nPorts > 0) + if (nPorts > 0) { - forAll(scavInPortPatches_, i) + forAll (scavInPortPatches_, i) { - topoChanger_.setSize(topoChanger_.size() + 1); + // Check if patches are present on local processor + const label sipID = + boundaryMesh().findPatchID(scavInPortPatches_[i]); - topoChanger_.set - ( - nMods, - new slidingInterface + const label sicID = + boundaryMesh().findPatchID(scavInCylPatches_[i]); + + if (sipID > -1 && sicID > -1) + { + if ( - "portCylinderInterface" + Foam::name(i + 1), - nMods, - topoChanger_, - scavInPortPatches_[i] + "Zone" + Foam::name(i + 1), - scavInCylPatches_[i] + "Zone" + Foam::name(i + 1), - "cutPointZone" + Foam::name(i + 1), - "cutFaceZone" + Foam::name(i + 1), - scavInPortPatches_[i], - scavInCylPatches_[i], - slidingInterface::INTEGRAL, - true, // Attach-detach action - intersection::VISIBLE // Projection algorithm + boundaryMesh()[sipID].size() > 0 + && boundaryMesh()[sicID].size() > 0 ) - ); + { + Pout<< "Adding slider for pair " << scavInPortPatches_[i] + << " and " << scavInCylPatches_[i] + << " with sizes " + << boundaryMesh()[sipID].size() << " " + << boundaryMesh()[sicID].size() << endl; - nMods++; + // Patches present. Add modifier + topoChanger_.setSize(topoChanger_.size() + 1); + + topoChanger_.set + ( + nMods, + new slidingInterface + ( + "portCylinderInterface" + Foam::name(i + 1), + nMods, + topoChanger_, + scavInPortPatches_[i] + "Zone" + Foam::name(i + 1), + scavInCylPatches_[i] + "Zone" + Foam::name(i + 1), + "cutPointZone" + Foam::name(i + 1), + "cutFaceZone" + Foam::name(i + 1), + scavInPortPatches_[i], + scavInCylPatches_[i], + slidingInterface::INTEGRAL, + true, // Attach-detach action + intersection::VISIBLE // Projection algorithm + ) + ); + + nMods++; + } + } } } diff --git a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngine.C b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngine.C index e82612044..c47d64eb9 100644 --- a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngine.C +++ b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngine.C @@ -152,13 +152,13 @@ void Foam::twoStrokeEngine::setBoundaryVelocity(volVectorField& U) // On the piston movingWallVelocity is used. // There is no need to update the piston velocity -// U.boundaryField()[piston().patchID().index()] = pistonVel; - forAll(scavInPortPatches_, patchi) + forAll (scavInPortPatches_, patchi) { - U.boundaryField() - [boundaryMesh().findPatchID(scavInPortPatches_[patchi])] == - pistonVel; + const label curPatchID = + boundaryMesh().findPatchID(scavInPortPatches_[patchi]); + + U.boundaryField()[curPatchID] == pistonVel; } } diff --git a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineCalculate.C b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineCalculate.C index b8fb6fd87..4aa486d79 100644 --- a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineCalculate.C +++ b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineCalculate.C @@ -61,21 +61,26 @@ void Foam::twoStrokeEngine::calcMovingMasks() const const cellList& c = cells(); const faceList& f = allFaces(); - const labelList& cellAddr = - cellZones()[cellZones().findZoneID("movingCells")]; + const label movingCellsID = cellZones().findZoneID("movingCells"); - forAll (cellAddr, cellI) + // If moving cell zone is found, mark the vertices + if (movingCellsID > -1) { - const cell& curCell = c[cellAddr[cellI]]; + const labelList& cellAddr = cellZones()[movingCellsID]; - forAll (curCell, faceI) + forAll (cellAddr, cellI) { - // Mark all the points as moving - const face& curFace = f[curCell[faceI]]; + const cell& curCell = c[cellAddr[cellI]]; - forAll (curFace, pointI) + forAll (curCell, faceI) { - movingPointsMask[curFace[pointI]] = 1; + // Mark all the points as moving + const face& curFace = f[curCell[faceI]]; + + forAll (curFace, pointI) + { + movingPointsMask[curFace[pointI]] = 1; + } } } } diff --git a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineInitialize.C b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineInitialize.C index fa7883736..835c1ae77 100644 --- a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineInitialize.C +++ b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineInitialize.C @@ -44,9 +44,8 @@ void Foam::twoStrokeEngine::checkAndCalculate() label cylinderHeadIndex = -1; bool foundCylinderHead = false; - forAll(boundary(), i) + forAll (boundary(), i) { - Info << boundary()[i].name() << endl; if (boundary()[i].name() == "piston") { pistonIndex = i; @@ -111,34 +110,31 @@ void Foam::twoStrokeEngine::checkAndCalculate() } } + void Foam::twoStrokeEngine::setVirtualPistonPosition() { - label pistonFaceIndex = faceZones().findZoneID("pistonLayerFaces"); - bool foundPistonFace = (pistonFaceIndex != -1); - - Info << "piston face index = " << pistonFaceIndex << endl; - - if(!foundPistonFace) + if(pistonFaceIndex == -1) { FatalErrorIn("Foam::twoStrokeEngine::setVirtualPistonPosition()") - << " : cannot find the pistonLayerFaces" - << exit(FatalError); + << "Cannot find the pistonLayerFaces" + << abort(FatalError); } - const labelList& pistonFaces = faceZones()[pistonFaceIndex]; - forAll(pistonFaces, i) - { - const face& f = faces()[pistonFaces[i]]; + const labelList& pistonPoints = + faceZones()[pistonFaceIndex]().meshPoints(); - // should loop over facepoints... - forAll(f, j) - { - virtualPistonPosition() = - Foam::max(virtualPistonPosition(), points()[f[j]].z()); - } + const pointField& p = points(); + + forAll (pistonPoints, i) + { + virtualPistonPosition() = + Foam::max(virtualPistonPosition_, p[pistonPoints[i]].z()); } reduce(virtualPistonPosition(), maxOp()); } + + +// ************************************************************************* // diff --git a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineMove.C b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineMove.C index d7efb65e1..d9f8871fc 100644 --- a/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineMove.C +++ b/src/engine/engineTopoChangerMesh/twoStrokeEngine/twoStrokeEngineMove.C @@ -41,11 +41,11 @@ void Foam::twoStrokeEngine::makeLayersLive() // Enable layering forAll (morphs, modI) { - if (typeid(morphs[modI]) == typeid(layerAdditionRemoval)) + if (isA(morphs[modI])) { morphs[modI].enable(); } - else if (typeid(morphs[modI]) == typeid(slidingInterface)) + else if (isA(morphs[modI])) { morphs[modI].disable(); } @@ -59,6 +59,7 @@ void Foam::twoStrokeEngine::makeLayersLive() } } + void Foam::twoStrokeEngine::makeSlidersLive() { const polyTopoChanger& morphs = topoChanger_; @@ -66,11 +67,11 @@ void Foam::twoStrokeEngine::makeSlidersLive() // Enable sliding interface forAll (morphs, modI) { - if (typeid(morphs[modI]) == typeid(layerAdditionRemoval)) + if (isA(morphs[modI])) { morphs[modI].disable(); } - else if (typeid(morphs[modI]) == typeid(slidingInterface)) + else if (isA(morphs[modI])) { morphs[modI].enable(); } @@ -93,10 +94,9 @@ bool Foam::twoStrokeEngine::attached() const forAll (morphs, modI) { - if (typeid(morphs[modI]) == typeid(slidingInterface)) + if (isA(morphs[modI])) { - result = - result + result = result || refCast(morphs[modI]).attached(); } } @@ -104,7 +104,7 @@ bool Foam::twoStrokeEngine::attached() const // Check thal all sliders are in sync (debug only) forAll (morphs, modI) { - if (typeid(morphs[modI]) == typeid(slidingInterface)) + if (isA(morphs[modI])) { if ( @@ -120,6 +120,9 @@ bool Foam::twoStrokeEngine::attached() const } } + // Sync across processors + reduce(result, orOp()); + return result; } @@ -133,13 +136,25 @@ bool Foam::twoStrokeEngine::update() makeSlidersLive(); // Changing topology by hand - autoPtr topoChangeMap5 = topoChanger_.changeMesh(); + autoPtr topoChangeMap1 = topoChanger_.changeMesh(); - if (topoChangeMap5->hasMotionPoints() && topoChangeMap5->morphing()) + bool localMorphing1 = topoChangeMap1->morphing(); + + // Note: Since we are detaching, global morphing is always true + // HJ, 7/Mar/2011 + + if (localMorphing1) { Info << "Topology change; executing pre-motion after " << "sliding detach" << endl; - movePoints(topoChangeMap5->preMotionPoints()); + movePoints(topoChangeMap1->preMotionPoints()); + } + else + { + pointField newPoints = allPoints(); + + // Dummy motion + movePoints(newPoints); } Info << "sliding interfaces successfully decoupled!!!" << endl; @@ -154,25 +169,14 @@ bool Foam::twoStrokeEngine::update() // Piston Layering makeLayersLive(); - // Changing topology by hand - -// /* Tommaso, 23/5/2008 - - // Find piston mesh modifier + // Find piston mesh modifier if present on processor const label pistonLayerID = topoChanger_.findModifierID("pistonLayer"); - if (pistonLayerID < 0) - { - FatalErrorIn("void engineFvMesh::moveAndMorph()") - << "Piston modifier not found." - << abort(FatalError); - } - scalar minLayerThickness = piston().minLayer(); scalar deltaZ = engTime().pistonDisplacement().value(); - virtualPistonPosition() += deltaZ; + virtualPistonPosition_ += deltaZ; Info << "virtualPistonPosition = " << virtualPistonPosition() << ", deckHeight = " << deckHeight() @@ -181,32 +185,45 @@ bool Foam::twoStrokeEngine::update() if (realDeformation()) { // Dectivate piston layer - Info << "Mesh deformation mode" << endl; - topoChanger_[pistonLayerID].disable(); + if (pistonLayerID > -1) + { + Info << "Mesh deformation mode" << endl; + topoChanger_[pistonLayerID].disable(); + } } else { // Activate piston layer - Info << "Piston layering mode" << endl; - topoChanger_[pistonLayerID].enable(); + if (pistonLayerID > -1) + { + Info << "Piston layering mode" << endl; + topoChanger_[pistonLayerID].enable(); + } } // Changing topology by hand - autoPtr topoChangeMap = topoChanger_.changeMesh(); + autoPtr topoChangeMap2 = topoChanger_.changeMesh(); + + bool localMorphing2 = topoChangeMap2->morphing(); + bool globalMorphing2 = localMorphing2; // Work array for new points position. pointField newPoints = allPoints(); - const pointField& refPoints = allPoints(); - if (topoChangeMap->morphing()) + if (globalMorphing2) { - if (topoChangeMap->hasMotionPoints()) + Info<< "Topology change; executing pre-motion after " + << "dynamic layering" << endl; + + if (localMorphing2) { - Info<< "Topology change; executing pre-motion after " - << "dynamic layering" << endl; - movePoints(topoChangeMap->preMotionPoints()); - newPoints = topoChangeMap->preMotionPoints(); + movePoints(topoChangeMap2->preMotionPoints()); + newPoints = topoChangeMap2->preMotionPoints(); + } + else + { + movePoints(newPoints); } setV0(); @@ -225,99 +242,92 @@ bool Foam::twoStrokeEngine::update() labelList pistonPoints; labelList headPoints; { - label pistonCellIndex = cellZones().findZoneID("pistonCells"); - - if (pistonCellIndex < 0) - { - FatalErrorIn("bool twoStrokeEngine::update()") - << "Cannot find cell zone pistonCells" - << abort(FatalError); - } - - - const labelList& pistonCells = cellZones()[pistonCellIndex]; - - label headCellIndex = cellZones().findZoneID("headCells"); - - if (headCellIndex < 0) - { - FatalErrorIn("bool twoStrokeEngine::update()") - << "Cannot find cell zone headCells" - << abort(FatalError); - } - - const labelList& headCells = cellZones()[headCellIndex]; - + // Get cell-point addressing const labelListList& cp = cellPoints(); boolList count(newPoints.size(), false); - forAll (pistonCells, cellI) - { - const labelList& curCellPoints = cp[pistonCells[cellI]]; + // Piston points + label pistonCellID = cellZones().findZoneID("pistonCells"); - forAll (curCellPoints, i) + if (pistonCellID > -1) + { + const labelList& pistonCells = cellZones()[pistonCellID]; + + forAll (pistonCells, cellI) { - count[curCellPoints[i]] = true; + const labelList& curCellPoints = cp[pistonCells[cellI]]; + + forAll (curCellPoints, i) + { + count[curCellPoints[i]] = true; + } } - } - // Count the points - label nCounted = 0; - forAll (count, pointI) - { - if (count[pointI] == true) + // Count the points + label nCounted = 0; + forAll (count, pointI) { - nCounted++; + if (count[pointI] == true) + { + nCounted++; + } } - } - pistonPoints.setSize(nCounted); + pistonPoints.setSize(nCounted); - // Collect the points - nCounted = 0; - forAll (count, pointI) - { - if (count[pointI] == true) + // Collect the points + nCounted = 0; + forAll (count, pointI) { - pistonPoints[nCounted] = pointI; - nCounted++; + if (count[pointI] == true) + { + pistonPoints[nCounted] = pointI; + nCounted++; + } } } // Repeat for head points count = false; - forAll (headCells, cellI) - { - const labelList& curCellPoints = cp[pistonCells[cellI]]; + const label headCellID = cellZones().findZoneID("headCells"); - forAll (curCellPoints, i) + if (headCellID > -1) + { + const labelList& headCells = cellZones()[headCellID]; + + forAll (headCells, cellI) { - count[curCellPoints[i]] = true; + const labelList& curCellPoints = cp[headCells[cellI]]; + + forAll (curCellPoints, i) + { + count[curCellPoints[i]] = true; + } } - } - // Count the points - nCounted = 0; - forAll (count, pointI) - { - if (count[pointI] == true) + // Count the points + label nCounted = 0; + forAll (count, pointI) { - nCounted++; + if (count[pointI] == true) + { + nCounted++; + } } - } - headPoints.setSize(nCounted); + headPoints.setSize(nCounted); - // Collect the points - nCounted = 0; - forAll (count, pointI) - { - if (count[pointI] == true) + // Collect the points + nCounted = 0; + forAll (count, pointI) { - headPoints[nCounted] = pointI; - nCounted++; + if (count[pointI] == true) + { + headPoints[nCounted] = pointI; + nCounted++; + } } } } @@ -325,12 +335,6 @@ bool Foam::twoStrokeEngine::update() label nScaled = nPoints(); -// label pistonPtsIndex = pointZones().findZoneID("pistonPoints"); -// const labelList& pistonPoints = pointZones()[pistonPtsIndex]; - -// label headPtsIndex = pointZones().findZoneID("headPoints"); -// const labelList& headPoints = pointZones()[headPtsIndex]; - const scalarField& movingPointsM = movingPointsMask(); forAll(pistonPoints, i) @@ -377,6 +381,7 @@ bool Foam::twoStrokeEngine::update() { // Always move piston scalar pistonTopZ = -GREAT; + forAll(pistonPoints, i) { point& p = newPoints[pistonPoints[i]]; @@ -406,15 +411,11 @@ bool Foam::twoStrokeEngine::update() } } - - movePoints(newPoints); deleteDemandDrivenData(movingPointsMaskPtr_); pistonPosition() += deltaZ; -//*/ //Tommaso, 23/5/2008 - { // Grab old points to correct the motion pointField oldPointsNew = oldAllPoints(); @@ -424,73 +425,98 @@ bool Foam::twoStrokeEngine::update() makeSlidersLive(); // Changing topology by hand - autoPtr topoChangeMap4 = topoChanger_.changeMesh(); + autoPtr topoChangeMap3 = topoChanger_.changeMesh(); - if (topoChangeMap4->morphing()) + bool localMorphing3 = topoChangeMap3->morphing(); + bool globalMorphing3 = localMorphing3; + + reduce(globalMorphing3, orOp()); + + if (globalMorphing3) { - if (topoChangeMap4->hasMotionPoints()) + Info<< "Topology change; executing pre-motion after " + << "sliding attach" << endl; + + // Grab points + newPoints = allPoints(); + + if (localMorphing3) { - Info<< "Topology change; executing pre-motion after " - << "sliding attach" << endl; + // If there is layering, pick up correct points + if (topoChangeMap3->hasMotionPoints()) + { + newPoints = topoChangeMap3->preMotionPoints(); + } -// Info<< "topoChangeMap4->preMotionPoints().size() = " -// << topoChangeMap4->preMotionPoints().size() << nl -// << "allPoints.size() = " << allPoints().size() << nl -// << "points.size() = " << points().size() << endl; - - movePoints(topoChangeMap4->preMotionPoints()); - newPoints = points(); - } - - { + // Prepare old points for the move pointField mappedOldPointsNew(allPoints().size()); mappedOldPointsNew.map ( - oldPointsNew, topoChangeMap4->pointMap() + oldPointsNew, topoChangeMap3->pointMap() ); forAll(scavInPortPatches_, patchi) { - const labelList& cutPointsAddressing = - pointZones() - [ - pointZones().findZoneID - ( - "cutPointZone" + Foam::name(patchi + 1) - ) - ]; + // Find cut point zone ID + const label cutPointZoneID = pointZones().findZoneID + ( + "cutPointZone" + Foam::name(patchi + 1) + ); - forAll(cutPointsAddressing, i) + if (cutPointZoneID > -1) { - mappedOldPointsNew[cutPointsAddressing[i]] = - newPoints[cutPointsAddressing[i]]; - } + const labelList& cutPointsAddressing = + pointZones()[cutPointZoneID]; - forAll(cutPointsAddressing, i) - { - if - ( - newPoints[cutPointsAddressing[i]].z() - > virtualPistonPosition() - ) + forAll(cutPointsAddressing, i) { - mappedOldPointsNew[cutPointsAddressing[i]].z() = - newPoints[cutPointsAddressing[i]].z(); + mappedOldPointsNew[cutPointsAddressing[i]] = + newPoints[cutPointsAddressing[i]]; } - else + + forAll(cutPointsAddressing, i) { - mappedOldPointsNew[cutPointsAddressing[i]].z() = - newPoints[cutPointsAddressing[i]].z() - deltaZ; + if + ( + newPoints[cutPointsAddressing[i]].z() + > virtualPistonPosition() + ) + { + mappedOldPointsNew + [cutPointsAddressing[i]].z() = + newPoints[cutPointsAddressing[i]].z(); + } + else + { + mappedOldPointsNew + [cutPointsAddressing[i]].z() = + newPoints[cutPointsAddressing[i]].z() + - deltaZ; + } } } } - pointField newPoints = allPoints(); + // Move mesh into correct old configuration movePoints(mappedOldPointsNew); resetMotion(); setV0(); + + // Set new point motion + movePoints(newPoints); + } + else + { + // No local topological change. Execute double motion for + // sync with topological changes + movePoints(oldPointsNew); + + resetMotion(); + setV0(); + + // Set new point motion movePoints(newPoints); } } diff --git a/src/engine/include/addPistonLayerAdditionRemovalMeshModifier.H b/src/engine/include/addPistonLayerAdditionRemovalMeshModifier.H index 9457a5972..80c8dfa29 100644 --- a/src/engine/include/addPistonLayerAdditionRemovalMeshModifier.H +++ b/src/engine/include/addPistonLayerAdditionRemovalMeshModifier.H @@ -1,11 +1,11 @@ // Add piston layer addition/removal if (piston().patchID().active()) { + Info<< "Adding a layer addition/removal mesh modifier to the piston" + << endl; + + topoChanger_.setSize(nMods + 1); - Info << "Adding a layer addition/removal mesh modifier to the piston" << endl; - - topoChanger_.setSize(nMods+1); - topoChanger_.set ( nMods, @@ -17,9 +17,9 @@ "pistonLayerFaces", piston().minLayer(), piston().maxLayer() - ) + ) ); nMods++; - Info << "pistonLayer" << endl; - Info << nMods << endl; + + Info << "pistonLayer modifier number " << nMods << endl; } diff --git a/src/engine/include/createEngineDynamicMesh.H b/src/engine/include/createEngineDynamicMesh.H index 9ac091818..e73a61729 100644 --- a/src/engine/include/createEngineDynamicMesh.H +++ b/src/engine/include/createEngineDynamicMesh.H @@ -7,7 +7,8 @@ ( engineTopoChangerMesh::defaultRegion, runTime.timeName(), - runTime + runTime, + IOobject::MUST_READ ) ) ); diff --git a/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.C b/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.C index b27451fe8..7deb0c485 100644 --- a/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.C +++ b/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.C @@ -43,7 +43,7 @@ namespace Foam addToRunTimeSelectionTable ( - topoChangerFvMesh, + engineTopoChangerMesh, simpleEngineTopoFvMesh, IOobject ); @@ -211,7 +211,7 @@ bool Foam::simpleEngineTopoFvMesh::attached() const { if ( - result + result != refCast(topoChanger_[modI]).attached() ) { @@ -458,8 +458,7 @@ Foam::simpleEngineTopoFvMesh::simpleEngineTopoFvMesh const IOobject& io ) : - topoChangerFvMesh(io), - engineTime_(refCast(time())), + engineTopoChangerMesh(io), valves_(*this, engineTime_.engineDict().lookup("valves")), piston_(*this, engineTime_.engineDict().subDict("piston")), msPtr_(motionSolver::New(*this)), diff --git a/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.H b/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.H index f6439d8b9..1bbc51d19 100644 --- a/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.H +++ b/src/engine/simpleEngineTopoFvMesh/simpleEngineTopoFvMesh.H @@ -27,8 +27,7 @@ License #ifndef simpleEngineTopoFvMesh_H #define simpleEngineTopoFvMesh_H -#include "topoChangerFvMesh.H" -#include "engineTime.H" +#include "engineTopoChangerMesh.H" #include "valveBank.H" #include "simpleEnginePiston.H" #include "motionSolver.H" @@ -44,13 +43,10 @@ namespace Foam class simpleEngineTopoFvMesh : - public topoChangerFvMesh + public engineTopoChangerMesh { // Private data - //- Engine database - const engineTime& engineTime_; - //- Engine valves valveBank valves_; @@ -76,6 +72,9 @@ class simpleEngineTopoFvMesh void operator=(const simpleEngineTopoFvMesh&); + //- Add valve and piston zones and modifiers + void addZonesAndModifiers(); + //- Make layering modifiers live void makeLayersLive(); @@ -140,11 +139,12 @@ public: && engineTime_.thetaRevolution() < deformSwitch_; } - //- Add valve and piston zones and modifiers - void addZonesAndModifiers(); - //- Update the mesh for both mesh motion and topology change virtual bool update(); + + //- Set boundary velocities + virtual void setBoundaryVelocity(volVectorField& U) + {} };