From a0b0e23cff2cf36353ff7bc66c2e89a37abf3a4c Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 13 Aug 2009 15:27:48 +0100 Subject: [PATCH 01/12] proper error handling --- src/OpenFOAM/db/Time/Time.C | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index fa9b3e6a91..f0976a77b5 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -127,11 +127,11 @@ void Foam::Time::setControls() } else { - WarningIn("Time::setControls()") - << " expected startTime, firstTime or latestTime" - << " found '" << startFrom - << "' in dictionary " << controlDict_.name() << nl - << " Setting time to " << startTime_ << endl; + FatalIOErrorIn("Time::setControls()", controlDict_) + << "expected startTime, firstTime or latestTime" + << " found '" << startFrom << "'" + //<< "' in dictionary " << controlDict_.name() + << exit(FatalIOError); } } @@ -151,10 +151,10 @@ void Foam::Time::setControls() > Pstream::nProcs()*deltaT_/10.0 ) { - FatalErrorIn("Time::setControls()") + FatalIOErrorIn("Time::setControls()", controlDict_) << "Start time is not the same for all processors" << nl << "processor " << Pstream::myProcNo() << " has startTime " - << startTime_ << exit(FatalError); + << startTime_ << exit(FatalIOError); } } From 87b8f862556354c8dc07dbb637d665abb31f2a1d Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 13 Aug 2009 15:28:13 +0100 Subject: [PATCH 02/12] illegal use of List_ELEM macro --- src/OpenFOAM/containers/Lists/List/List.C | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/OpenFOAM/containers/Lists/List/List.C b/src/OpenFOAM/containers/Lists/List/List.C index 08422fd9ba..fb6d9a0678 100644 --- a/src/OpenFOAM/containers/Lists/List/List.C +++ b/src/OpenFOAM/containers/Lists/List/List.C @@ -162,13 +162,14 @@ Foam::List::List(const UList& a, const unallocLabelList& map) { if (this->size_) { + // Note:cannot use List_ELEM since third argument has to be index. + this->v_ = new T[this->size_]; - List_ACCESS(T, (*this), vp); - List_CONST_ACCESS(T, a, ap); - List_FOR_ALL(map, i) - List_ELEM((*this), vp, i) = List_ELEM(a, ap, (map[i])); - List_END_FOR_ALL + forAll(*this, i) + { + this->v_[i] = a[map[i]]; + } } } From 5c90c347f9687d116134f43fa2966ad642180397 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 13 Aug 2009 17:28:33 +0100 Subject: [PATCH 03/12] mapDistribute non-blocking of non-contiguous data --- .../extendedStencil/testExtendedStencil.C | 2 +- applications/test/parallel/parallelTest.C | 109 ++- .../mapPolyMesh/mapDistribute/mapDistribute.C | 20 +- .../mapPolyMesh/mapDistribute/mapDistribute.H | 41 +- .../mapDistribute/mapDistributeLagrangian.H | 26 +- .../mapDistribute/mapDistributePolyMesh.C | 60 +- .../mapDistribute/mapDistributePolyMesh.H | 42 +- .../mapDistribute/mapDistributeTemplates.C | 716 ++++++++++++------ .../autoHexMeshDriver/autoHexMeshDriver.C | 3 - .../autoHexMeshDriver/autoRefineDriver.C | 2 - .../fvMeshDistribute/fvMeshDistribute.C | 41 +- .../cellToFace/extendedCellToFaceStencil.C | 5 +- .../distributedTriSurfaceMesh.C | 25 +- 13 files changed, 674 insertions(+), 418 deletions(-) diff --git a/applications/test/extendedStencil/testExtendedStencil.C b/applications/test/extendedStencil/testExtendedStencil.C index b8db2b89bf..876576b29e 100644 --- a/applications/test/extendedStencil/testExtendedStencil.C +++ b/applications/test/extendedStencil/testExtendedStencil.C @@ -34,7 +34,7 @@ Description #include "fvMesh.H" #include "volFields.H" #include "Time.H" -#include "mapDistribute.H" +//#include "mapDistribute.H" #include "OFstream.H" #include "meshTools.H" //#include "FECCellToFaceStencil.H" diff --git a/applications/test/parallel/parallelTest.C b/applications/test/parallel/parallelTest.C index bf8440ece6..6120de31a5 100644 --- a/applications/test/parallel/parallelTest.C +++ b/applications/test/parallel/parallelTest.C @@ -23,19 +23,23 @@ License Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Application - icoFoam + parallelTest Description - Incompressible laminar CFD code. + Test for various parallel routines. \*---------------------------------------------------------------------------*/ +#include "List.H" +#include "mapDistribute.H" #include "argList.H" #include "Time.H" #include "IPstream.H" #include "OPstream.H" #include "vector.H" #include "IOstreams.H" +#include "Random.H" +#include "Tuple2.H" using namespace Foam; @@ -47,6 +51,99 @@ int main(int argc, char *argv[]) # include "setRootCase.H" # include "createTime.H" + + // Test mapDistribute + // ~~~~~~~~~~~~~~~~~~ + + if (false) + { + Random rndGen(43544*Pstream::myProcNo()); + + // Generate random data. + List > > complexData(100); + forAll(complexData, i) + { + complexData[i].first() = rndGen.integer(0, Pstream::nProcs()-1); + complexData[i].second().setSize(3); + complexData[i].second()[0] = 1; + complexData[i].second()[1] = 2; + complexData[i].second()[2] = 3; + } + + // Send all ones to processor indicated by .first() + + + // Count how many to send + labelList nSend(Pstream::nProcs(), 0); + forAll(complexData, i) + { + label procI = complexData[i].first(); + nSend[procI]++; + } + + // Sync how many to send + labelListList allNTrans(Pstream::nProcs()); + allNTrans[Pstream::myProcNo()] = nSend; + combineReduce(allNTrans, mapDistribute::listEq()); + + // Collect items to be sent + labelListList sendMap(Pstream::nProcs()); + forAll(sendMap, procI) + { + sendMap[procI].setSize(nSend[procI]); + } + nSend = 0; + forAll(complexData, i) + { + label procI = complexData[i].first(); + sendMap[procI][nSend[procI]++] = i; + } + + // Collect items to be received + labelListList recvMap(Pstream::nProcs()); + forAll(recvMap, procI) + { + recvMap[procI].setSize(allNTrans[procI][Pstream::myProcNo()]); + } + + label constructSize = 0; + // Construct with my own elements first + forAll(recvMap[Pstream::myProcNo()], i) + { + recvMap[Pstream::myProcNo()][i] = constructSize++; + } + // Construct from other processors + forAll(recvMap, procI) + { + if (procI != Pstream::myProcNo()) + { + forAll(recvMap[procI], i) + { + recvMap[procI][i] = constructSize++; + } + } + } + + + + // Construct distribute map (destructively) + mapDistribute map(constructSize, sendMap.xfer(), recvMap.xfer()); + + // Distribute complexData + mapDistribute::distribute + ( + Pstream::nonBlocking, + List(), + map.constructSize(), + map.subMap(), + map.constructMap(), + complexData + ); + + Pout<< "complexData:" << complexData << endl; + } + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // Perr<< "\nStarting transfers\n" << endl; @@ -60,13 +157,13 @@ int main(int argc, char *argv[]) { Perr<< "slave sending to master " << Pstream::masterNo() << endl; - OPstream toMaster(Pstream::masterNo()); + OPstream toMaster(Pstream::blocking, Pstream::masterNo()); toMaster << data; } Perr<< "slave receiving from master " << Pstream::masterNo() << endl; - IPstream fromMaster(Pstream::masterNo()); + IPstream fromMaster(Pstream::blocking, Pstream::masterNo()); fromMaster >> data; Perr<< data << endl; @@ -81,7 +178,7 @@ int main(int argc, char *argv[]) ) { Perr << "master receiving from slave " << slave << endl; - IPstream fromSlave(slave); + IPstream fromSlave(Pstream::blocking, slave); fromSlave >> data; Perr<< data << endl; @@ -95,7 +192,7 @@ int main(int argc, char *argv[]) ) { Perr << "master sending to slave " << slave << endl; - OPstream toSlave(slave); + OPstream toSlave(Pstream::blocking, slave); toSlave << data; } } diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C index 1bbeb3d077..e2c2dbf773 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.C @@ -172,8 +172,8 @@ const Foam::List& Foam::mapDistribute::schedule() const Foam::mapDistribute::mapDistribute ( const label constructSize, - const labelListList& subMap, - const labelListList& constructMap + const Xfer& subMap, + const Xfer& constructMap ) : constructSize_(constructSize), @@ -183,22 +183,6 @@ Foam::mapDistribute::mapDistribute {} -//- (optionally destructively) construct from components -Foam::mapDistribute::mapDistribute -( - const label constructSize, - labelListList& subMap, - labelListList& constructMap, - const bool reUse // clone or reuse -) -: - constructSize_(constructSize), - subMap_(subMap, reUse), - constructMap_(constructMap, reUse), - schedulePtr_() -{} - - Foam::mapDistribute::mapDistribute ( const labelList& sendProcs, diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H index d2cfe64ca5..c6962355fd 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistribute.H @@ -83,23 +83,36 @@ class mapDistribute public: + // Public classes + + //- combineReduce operator for lists. Used for counting. + class listEq + { + + public: + + template + void operator()(T& x, const T& y) const + { + forAll(y, i) + { + if (y[i].size()) + { + x[i] = y[i]; + } + } + } + }; + + // Constructors //- Construct from components mapDistribute ( const label constructSize, - const labelListList& subMap, - const labelListList& constructMap - ); - - //- (optionally destructively) construct from components - mapDistribute - ( - const label constructSize, - labelListList& subMap, - labelListList& constructMap, - const bool reUse // clone or reuse + const Xfer& subMap, + const Xfer& constructMap ); //- Construct from reverse addressing: per data item the send @@ -205,11 +218,7 @@ public: template void distribute(List& fld) const { - if - ( - Pstream::defaultCommsType == Pstream::nonBlocking - && contiguous() - ) + if (Pstream::defaultCommsType == Pstream::nonBlocking) { distribute ( diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeLagrangian.H b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeLagrangian.H index 5782308d19..ce05673908 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeLagrangian.H +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeLagrangian.H @@ -68,35 +68,15 @@ public: mapDistributeLagrangian ( const label nNewParticles, - const labelListList& subParticleMap, - const labelListList& constructParticleMap, - const labelListList& constructCellLabels + const Xfer& subParticleMap, + const Xfer& constructParticleMap, + const Xfer& constructCellLabels ) : particleMap_(nNewParticles, subParticleMap, constructParticleMap), constructCellLabels_(constructCellLabels) {} - //- Construct from components and steal storage - mapDistributeLagrangian - ( - const label nNewParticles, - labelListList& subParticleMap, - labelListList& constructParticleMap, - labelListList& constructCellLabels, - const bool reUse - ) - : - particleMap_ - ( - nNewParticles, - subParticleMap, - constructParticleMap, - reUse - ), - constructCellLabels_(constructCellLabels, reUse) - {} - // Member Functions diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.C index a5e4f16341..29649665b4 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.C @@ -66,27 +66,27 @@ Foam::mapDistributePolyMesh::mapDistributePolyMesh const label nOldPoints, const label nOldFaces, const label nOldCells, - const labelList& oldPatchStarts, - const labelList& oldPatchNMeshPoints, + const Xfer& oldPatchStarts, + const Xfer& oldPatchNMeshPoints, // how to subset pieces of mesh to send across - const labelListList& subPointMap, - const labelListList& subFaceMap, - const labelListList& subCellMap, - const labelListList& subPatchMap, + const Xfer& subPointMap, + const Xfer& subFaceMap, + const Xfer& subCellMap, + const Xfer& subPatchMap, // how to reconstruct received mesh - const labelListList& constructPointMap, - const labelListList& constructFaceMap, - const labelListList& constructCellMap, - const labelListList& constructPatchMap + const Xfer& constructPointMap, + const Xfer& constructFaceMap, + const Xfer& constructCellMap, + const Xfer& constructPatchMap ) : mesh_(mesh), nOldPoints_(nOldPoints), nOldFaces_(nOldFaces), nOldCells_(nOldCells), - oldPatchSizes_(oldPatchStarts.size()), + oldPatchSizes_(oldPatchStarts().size()), oldPatchStarts_(oldPatchStarts), oldPatchNMeshPoints_(oldPatchNMeshPoints), pointMap_(mesh.nPoints(), subPointMap, constructPointMap), @@ -98,44 +98,6 @@ Foam::mapDistributePolyMesh::mapDistributePolyMesh } -//- (optionally destructively) construct from components -Foam::mapDistributePolyMesh::mapDistributePolyMesh -( - const polyMesh& mesh, - const label nOldPoints, - const label nOldFaces, - const label nOldCells, - labelList& oldPatchStarts, - labelList& oldPatchNMeshPoints, - - labelListList& subPointMap, - labelListList& subFaceMap, - labelListList& subCellMap, - labelListList& subPatchMap, - labelListList& constructPointMap, - labelListList& constructFaceMap, - labelListList& constructCellMap, - labelListList& constructPatchMap, - const bool reUse // clone or reuse -) -: - mesh_(mesh), - nOldPoints_(nOldPoints), - nOldFaces_(nOldFaces), - nOldCells_(nOldCells), - oldPatchSizes_(oldPatchStarts.size()), - oldPatchStarts_(oldPatchStarts, reUse), - oldPatchNMeshPoints_(oldPatchNMeshPoints, reUse), - - pointMap_(mesh.nPoints(), subPointMap, constructPointMap, reUse), - faceMap_(mesh.nFaces(), subFaceMap, constructFaceMap, reUse), - cellMap_(mesh.nCells(), subCellMap, constructCellMap, reUse), - patchMap_(mesh.boundaryMesh().size(), subPatchMap, constructPatchMap, reUse) -{ - calcPatchSizes(); -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // void Foam::mapDistributePolyMesh::distributePointIndices(labelList& lst) const diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.H b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.H index bf5857170b..8fdfe7e8fb 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributePolyMesh.H @@ -120,42 +120,20 @@ public: const label nOldPoints, const label nOldFaces, const label nOldCells, - const labelList& oldPatchStarts, - const labelList& oldPatchNMeshPoints, + const Xfer& oldPatchStarts, + const Xfer& oldPatchNMeshPoints, // how to subset pieces of mesh to send across - const labelListList& subPointMap, - const labelListList& subFaceMap, - const labelListList& subCellMap, - const labelListList& subPatchMap, + const Xfer& subPointMap, + const Xfer& subFaceMap, + const Xfer& subCellMap, + const Xfer& subPatchMap, // how to reconstruct received mesh - const labelListList& constructPointMap, - const labelListList& constructFaceMap, - const labelListList& constructCellMap, - const labelListList& constructPatchMap - ); - - //- (optionally destructively) construct from components - // Note that mesh has to be changed already! - mapDistributePolyMesh - ( - const polyMesh& mesh, - const label nOldPoints, - const label nOldFaces, - const label nOldCells, - labelList& oldPatchStarts, - labelList& oldPatchNMeshPoints, - - labelListList& subPointMap, - labelListList& subFaceMap, - labelListList& subCellMap, - labelListList& subPatchMap, - labelListList& constructPointMap, - labelListList& constructFaceMap, - labelListList& constructCellMap, - labelListList& constructPatchMap, - const bool reUse // clone or reuse + const Xfer& constructPointMap, + const Xfer& constructFaceMap, + const Xfer& constructCellMap, + const Xfer& constructPatchMap ); diff --git a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C index 5f5d7a9fcf..da1ed19d1e 100644 --- a/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C +++ b/src/OpenFOAM/meshes/polyMesh/mapPolyMesh/mapDistribute/mapDistributeTemplates.C @@ -25,6 +25,7 @@ License \*---------------------------------------------------------------------------*/ #include "Pstream.H" +#include "PstreamCombineReduceOps.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -184,138 +185,269 @@ void Foam::mapDistribute::distribute { if (!contiguous()) { - FatalErrorIn - ( - "template\n" - "void mapDistribute::distribute\n" - "(\n" - " const Pstream::commsTypes commsType,\n" - " const List& schedule,\n" - " const label constructSize,\n" - " const labelListList& subMap,\n" - " const labelListList& constructMap,\n" - " List& field\n" - ")\n" - ) << "Non-blocking only supported for contiguous data." - << exit(FatalError); - } + // 1. convert to contiguous buffer + // 2. send buffer + // 3. receive buffer + // 4. read from buffer into List - // Set up sends to neighbours + List > sendFields(Pstream::nProcs()); + labelListList allNTrans(Pstream::nProcs()); + labelList& nsTransPs = allNTrans[Pstream::myProcNo()]; + nsTransPs.setSize(Pstream::nProcs(), 0); - List > sendFields(Pstream::nProcs()); - - for (label domain = 0; domain < Pstream::nProcs(); domain++) - { - const labelList& map = subMap[domain]; - - if (domain != Pstream::myProcNo() && map.size()) + // Stream data into sendField buffers + for (label domain = 0; domain < Pstream::nProcs(); domain++) { - List& subField = sendFields[domain]; + const labelList& map = subMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + // Put data into send buffer + OPstream toDomain(Pstream::nonBlocking, domain); + toDomain << UIndirectList(field, map); + + // Store the size + nsTransPs[domain] = toDomain.bufPosition(); + + // Transfer buffer out + sendFields[domain].transfer(toDomain.buf()); + toDomain.bufPosition() = 0; + + } + } + + // Send sizes across + combineReduce(allNTrans, listEq()); + + // Start sending buffers + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = subMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + OPstream::write + ( + Pstream::nonBlocking, + domain, + reinterpret_cast + ( + sendFields[domain].begin() + ), + nsTransPs[domain] + ); + } + } + + // Set up receives from neighbours + + PtrList fromSlave(Pstream::nProcs()); + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + // Start receiving + fromSlave.set + ( + domain, + new IPstream + ( + Pstream::nonBlocking, + domain, + allNTrans[domain][Pstream::myProcNo()] + ) + ); + } + } + + + { + // Set up 'send' to myself + const labelList& mySubMap = subMap[Pstream::myProcNo()]; + List mySubField(mySubMap.size()); + forAll(mySubMap, i) + { + mySubField[i] = field[mySubMap[i]]; + } + // Combine bits. Note that can reuse field storage + field.setSize(constructSize); + // Receive sub field from myself + { + const labelList& map = constructMap[Pstream::myProcNo()]; + + forAll(map, i) + { + field[map[i]] = mySubField[i]; + } + } + } + + + // Wait till all finished + IPstream::waitRequests(); + OPstream::waitRequests(); + + // Consume + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + List recvField(fromSlave[domain]); + + if (recvField.size() != map.size()) + { + FatalErrorIn + ( + "template\n" + "void mapDistribute::distribute\n" + "(\n" + " const Pstream::commsTypes commsType,\n" + " const List& schedule,\n" + " const label constructSize,\n" + " const labelListList& subMap,\n" + " const labelListList& constructMap,\n" + " List& field\n" + ")\n" + ) << "Expected from processor " << domain + << " " << map.size() << " but received " + << recvField.size() << " elements." + << abort(FatalError); + } + + forAll(map, i) + { + field[map[i]] = recvField[i]; + } + + // Delete receive buffer + fromSlave.set(domain, NULL); + } + } + } + else + { + // Set up sends to neighbours + + List > sendFields(Pstream::nProcs()); + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = subMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + List& subField = sendFields[domain]; + subField.setSize(map.size()); + forAll(map, i) + { + subField[i] = field[map[i]]; + } + + OPstream::write + ( + Pstream::nonBlocking, + domain, + reinterpret_cast(subField.begin()), + subField.byteSize() + ); + } + } + + // Set up receives from neighbours + + List > recvFields(Pstream::nProcs()); + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + recvFields[domain].setSize(map.size()); + IPstream::read + ( + Pstream::nonBlocking, + domain, + reinterpret_cast(recvFields[domain].begin()), + recvFields[domain].byteSize() + ); + } + } + + + // Set up 'send' to myself + + { + const labelList& map = subMap[Pstream::myProcNo()]; + + List& subField = sendFields[Pstream::myProcNo()]; subField.setSize(map.size()); forAll(map, i) { subField[i] = field[map[i]]; } - - OPstream::write - ( - Pstream::nonBlocking, - domain, - reinterpret_cast(subField.begin()), - subField.size()*sizeof(T) - ); } - } - // Set up receives from neighbours - List > recvFields(Pstream::nProcs()); + // Combine bits. Note that can reuse field storage - for (label domain = 0; domain < Pstream::nProcs(); domain++) - { - const labelList& map = constructMap[domain]; + field.setSize(constructSize); - if (domain != Pstream::myProcNo() && map.size()) + + // Receive sub field from myself (sendFields[Pstream::myProcNo()]) { - recvFields[domain].setSize(map.size()); - IPstream::read - ( - Pstream::nonBlocking, - domain, - reinterpret_cast(recvFields[domain].begin()), - recvFields[domain].size()*sizeof(T) - ); - } - } - - - // Set up 'send' to myself - - { - const labelList& map = subMap[Pstream::myProcNo()]; - - List& subField = sendFields[Pstream::myProcNo()]; - subField.setSize(map.size()); - forAll(map, i) - { - subField[i] = field[map[i]]; - } - } - - - // Combine bits. Note that can reuse field storage - - field.setSize(constructSize); - - - // Receive sub field from myself (sendFields[Pstream::myProcNo()]) - { - const labelList& map = constructMap[Pstream::myProcNo()]; - const List& subField = sendFields[Pstream::myProcNo()]; - - forAll(map, i) - { - field[map[i]] = subField[i]; - } - } - - - // Wait for all to finish - - OPstream::waitRequests(); - IPstream::waitRequests(); - - // Collect neighbour fields - - for (label domain = 0; domain < Pstream::nProcs(); domain++) - { - const labelList& map = constructMap[domain]; - - if (domain != Pstream::myProcNo() && map.size()) - { - if (recvFields[domain].size() != map.size()) - { - FatalErrorIn - ( - "template\n" - "void mapDistribute::distribute\n" - "(\n" - " const Pstream::commsTypes commsType,\n" - " const List& schedule,\n" - " const label constructSize,\n" - " const labelListList& subMap,\n" - " const labelListList& constructMap,\n" - " List& field\n" - ")\n" - ) << "Expected from processor " << domain - << " " << map.size() << " but received " - << recvFields[domain].size() << " elements." - << abort(FatalError); - } + const labelList& map = constructMap[Pstream::myProcNo()]; + const List& subField = sendFields[Pstream::myProcNo()]; forAll(map, i) { - field[map[i]] = recvFields[domain][i]; + field[map[i]] = subField[i]; + } + } + + + // Wait for all to finish + + OPstream::waitRequests(); + IPstream::waitRequests(); + + // Collect neighbour fields + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + if (recvFields[domain].size() != map.size()) + { + FatalErrorIn + ( + "template\n" + "void mapDistribute::distribute\n" + "(\n" + " const Pstream::commsTypes commsType,\n" + " const List& schedule,\n" + " const label constructSize,\n" + " const labelListList& subMap,\n" + " const labelListList& constructMap,\n" + " List& field\n" + ")\n" + ) << "Expected from processor " << domain + << " " << map.size() << " but received " + << recvFields[domain].size() << " elements." + << abort(FatalError); + } + + forAll(map, i) + { + field[map[i]] = recvFields[domain][i]; + } } } } @@ -488,137 +620,263 @@ void Foam::mapDistribute::distribute { if (!contiguous()) { - FatalErrorIn - ( - "template\n" - "void mapDistribute::distribute\n" - "(\n" - " const Pstream::commsTypes commsType,\n" - " const List& schedule,\n" - " const label constructSize,\n" - " const labelListList& subMap,\n" - " const labelListList& constructMap,\n" - " List& field\n" - ")\n" - ) << "Non-blocking only supported for contiguous data." - << exit(FatalError); - } + // 1. convert to contiguous buffer + // 2. send buffer + // 3. receive buffer + // 4. read from buffer into List - // Set up sends to neighbours + List > sendFields(Pstream::nProcs()); + labelListList allNTrans(Pstream::nProcs()); + labelList& nsTransPs = allNTrans[Pstream::myProcNo()]; + nsTransPs.setSize(Pstream::nProcs()); - List > sendFields(Pstream::nProcs()); - - for (label domain = 0; domain < Pstream::nProcs(); domain++) - { - const labelList& map = subMap[domain]; - - if (domain != Pstream::myProcNo() && map.size()) + // Stream data into sendField buffers + for (label domain = 0; domain < Pstream::nProcs(); domain++) { - List& subField = sendFields[domain]; + const labelList& map = subMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + // Put data into send buffer + OPstream toDomain(Pstream::nonBlocking, domain); + toDomain << UIndirectList(field, map); + + // Store the size + nsTransPs[domain] = toDomain.bufPosition(); + + // Transfer buffer out + sendFields[domain].transfer(toDomain.buf()); + toDomain.bufPosition() = 0; + } + } + + // Send sizes across + combineReduce(allNTrans, listEq()); + + // Start sending buffers + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = subMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + OPstream::write + ( + Pstream::nonBlocking, + domain, + reinterpret_cast + ( + sendFields[domain].begin() + ), + nsTransPs[domain] + ); + } + } + + // Set up receives from neighbours + + PtrList fromSlave(Pstream::nProcs()); + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + // Start receiving + fromSlave.set + ( + domain, + new IPstream + ( + Pstream::nonBlocking, + domain, + allNTrans[domain][Pstream::myProcNo()] + ) + ); + } + } + + + { + // Set up 'send' to myself + List mySubField(field, subMap[Pstream::myProcNo()]); + // Combine bits. Note that can reuse field storage + field.setSize(constructSize); + field = nullValue; + // Receive sub field from myself + { + const labelList& map = constructMap[Pstream::myProcNo()]; + + forAll(map, i) + { + cop(field[map[i]], mySubField[i]); + } + } + } + + + // Wait till all finished + IPstream::waitRequests(); + OPstream::waitRequests(); + + // Consume + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + List recvField(fromSlave[domain]); + + if (recvField.size() != map.size()) + { + FatalErrorIn + ( + "template\n" + "void mapDistribute::distribute\n" + "(\n" + " const Pstream::commsTypes commsType,\n" + " const List& schedule,\n" + " const label constructSize,\n" + " const labelListList& subMap,\n" + " const labelListList& constructMap,\n" + " List& field\n" + ")\n" + ) << "Expected from processor " << domain + << " " << map.size() << " but received " + << recvField.size() << " elements." + << abort(FatalError); + } + + forAll(map, i) + { + cop(field[map[i]], recvField[i]); + } + + // Delete receive buffer + fromSlave.set(domain, NULL); + } + } + } + else + { + // Set up sends to neighbours + + List > sendFields(Pstream::nProcs()); + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = subMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + List& subField = sendFields[domain]; + subField.setSize(map.size()); + forAll(map, i) + { + subField[i] = field[map[i]]; + } + + OPstream::write + ( + Pstream::nonBlocking, + domain, + reinterpret_cast(subField.begin()), + subField.size()*sizeof(T) + ); + } + } + + // Set up receives from neighbours + + List > recvFields(Pstream::nProcs()); + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + recvFields[domain].setSize(map.size()); + IPstream::read + ( + Pstream::nonBlocking, + domain, + reinterpret_cast(recvFields[domain].begin()), + recvFields[domain].size()*sizeof(T) + ); + } + } + + // Set up 'send' to myself + + { + const labelList& map = subMap[Pstream::myProcNo()]; + + List& subField = sendFields[Pstream::myProcNo()]; subField.setSize(map.size()); forAll(map, i) { subField[i] = field[map[i]]; } - - OPstream::write - ( - Pstream::nonBlocking, - domain, - reinterpret_cast(subField.begin()), - subField.size()*sizeof(T) - ); } - } - // Set up receives from neighbours - List > recvFields(Pstream::nProcs()); + // Combine bits. Note that can reuse field storage - for (label domain = 0; domain < Pstream::nProcs(); domain++) - { - const labelList& map = constructMap[domain]; + field.setSize(constructSize); + field = nullValue; - if (domain != Pstream::myProcNo() && map.size()) + // Receive sub field from myself (subField) { - recvFields[domain].setSize(map.size()); - IPstream::read - ( - Pstream::nonBlocking, - domain, - reinterpret_cast(recvFields[domain].begin()), - recvFields[domain].size()*sizeof(T) - ); - } - } - - // Set up 'send' to myself - - { - const labelList& map = subMap[Pstream::myProcNo()]; - - List& subField = sendFields[Pstream::myProcNo()]; - subField.setSize(map.size()); - forAll(map, i) - { - subField[i] = field[map[i]]; - } - } - - - // Combine bits. Note that can reuse field storage - - field.setSize(constructSize); - field = nullValue; - - // Receive sub field from myself (subField) - { - const labelList& map = constructMap[Pstream::myProcNo()]; - const List& subField = sendFields[Pstream::myProcNo()]; - - forAll(map, i) - { - cop(field[map[i]], subField[i]); - } - } - - - // Wait for all to finish - - OPstream::waitRequests(); - IPstream::waitRequests(); - - // Collect neighbour fields - - for (label domain = 0; domain < Pstream::nProcs(); domain++) - { - const labelList& map = constructMap[domain]; - - if (domain != Pstream::myProcNo() && map.size()) - { - if (recvFields[domain].size() != map.size()) - { - FatalErrorIn - ( - "template\n" - "void mapDistribute::distribute\n" - "(\n" - " const Pstream::commsTypes commsType,\n" - " const List& schedule,\n" - " const label constructSize,\n" - " const labelListList& subMap,\n" - " const labelListList& constructMap,\n" - " List& field\n" - ")\n" - ) << "Expected from processor " << domain - << " " << map.size() << " but received " - << recvFields[domain].size() << " elements." - << abort(FatalError); - } + const labelList& map = constructMap[Pstream::myProcNo()]; + const List& subField = sendFields[Pstream::myProcNo()]; forAll(map, i) { - cop(field[map[i]], recvFields[domain][i]); + cop(field[map[i]], subField[i]); + } + } + + + // Wait for all to finish + + OPstream::waitRequests(); + IPstream::waitRequests(); + + // Collect neighbour fields + + for (label domain = 0; domain < Pstream::nProcs(); domain++) + { + const labelList& map = constructMap[domain]; + + if (domain != Pstream::myProcNo() && map.size()) + { + if (recvFields[domain].size() != map.size()) + { + FatalErrorIn + ( + "template\n" + "void mapDistribute::distribute\n" + "(\n" + " const Pstream::commsTypes commsType,\n" + " const List& schedule,\n" + " const label constructSize,\n" + " const labelListList& subMap,\n" + " const labelListList& constructMap,\n" + " List& field\n" + ")\n" + ) << "Expected from processor " << domain + << " " << map.size() << " but received " + << recvFields[domain].size() << " elements." + << abort(FatalError); + } + + forAll(map, i) + { + cop(field[map[i]], recvFields[domain][i]); + } } } } diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C index 1612a23dea..cc110c1d40 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoHexMeshDriver.C @@ -28,12 +28,9 @@ License #include "fvMesh.H" #include "Time.H" #include "boundBox.H" -#include "globalIndex.H" #include "wallPolyPatch.H" -#include "mapDistributePolyMesh.H" #include "cellSet.H" #include "syncTools.H" -#include "motionSmoother.H" #include "refinementParameters.H" #include "snapParameters.H" #include "layerParameters.H" diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C index a9b31b9bd1..68d4b3b1e6 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C @@ -28,8 +28,6 @@ License #include "meshRefinement.H" #include "fvMesh.H" #include "Time.H" -#include "boundBox.H" -#include "mapDistributePolyMesh.H" #include "cellSet.H" #include "syncTools.H" #include "refinementParameters.H" diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 633c39f478..f815b46d71 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -1418,18 +1418,18 @@ Foam::autoPtr Foam::fvMeshDistribute::distribute nOldPoints, nOldFaces, nOldCells, - oldPatchStarts, - oldPatchNMeshPoints, + oldPatchStarts.xfer(), + oldPatchNMeshPoints.xfer(), - labelListList(1, identity(mesh_.nPoints())),//subPointMap - labelListList(1, identity(mesh_.nFaces())), //subFaceMap - labelListList(1, identity(mesh_.nCells())), //subCellMap - labelListList(1, identity(patches.size())), //subPatchMap + labelListList(1, identity(mesh_.nPoints())).xfer(),//subPointMap + labelListList(1, identity(mesh_.nFaces())).xfer(), //subFaceMap + labelListList(1, identity(mesh_.nCells())).xfer(), //subCellMap + labelListList(1, identity(patches.size())).xfer(), //subPatchMap - labelListList(1, identity(mesh_.nPoints())),//constructPointMap - labelListList(1, identity(mesh_.nFaces())), //constructFaceMap - labelListList(1, identity(mesh_.nCells())), //constructCellMap - labelListList(1, identity(patches.size())) //constructPatchMap + labelListList(1, identity(mesh_.nPoints())).xfer(),//pointMap + labelListList(1, identity(mesh_.nFaces())).xfer(), //faceMap + labelListList(1, identity(mesh_.nCells())).xfer(), //cellMap + labelListList(1, identity(patches.size())).xfer() //patchMap ) ); } @@ -2207,19 +2207,18 @@ Foam::autoPtr Foam::fvMeshDistribute::distribute nOldPoints, nOldFaces, nOldCells, - oldPatchStarts, - oldPatchNMeshPoints, + oldPatchStarts.xfer(), + oldPatchNMeshPoints.xfer(), - subPointMap, - subFaceMap, - subCellMap, - subPatchMap, + subPointMap.xfer(), + subFaceMap.xfer(), + subCellMap.xfer(), + subPatchMap.xfer(), - constructPointMap, - constructFaceMap, - constructCellMap, - constructPatchMap, - true // reuse storage + constructPointMap.xfer(), + constructFaceMap.xfer(), + constructCellMap.xfer(), + constructPatchMap.xfer() ) ); } diff --git a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedCellToFaceStencil.C b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedCellToFaceStencil.C index 5b1cb12e34..8a7224288c 100644 --- a/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedCellToFaceStencil.C +++ b/src/finiteVolume/fvMesh/extendedStencil/cellToFace/extendedCellToFaceStencil.C @@ -280,9 +280,8 @@ Foam::extendedCellToFaceStencil::calcDistributeMap new mapDistribute ( nCompact, - sendCompact, - recvCompact, - true // reuse send/recv maps. + sendCompact.xfer(), + recvCompact.xfer() ) ); diff --git a/src/meshTools/searchableSurface/distributedTriSurfaceMesh.C b/src/meshTools/searchableSurface/distributedTriSurfaceMesh.C index 7f86c0f658..33b6b6f1f5 100644 --- a/src/meshTools/searchableSurface/distributedTriSurfaceMesh.C +++ b/src/meshTools/searchableSurface/distributedTriSurfaceMesh.C @@ -340,9 +340,8 @@ Foam::distributedTriSurfaceMesh::distributeSegments new mapDistribute ( segmentI, // size after construction - sendMap, - constructMap, - true // reuse storage + sendMap.xfer(), + constructMap.xfer() ) ); } @@ -642,9 +641,8 @@ Foam::distributedTriSurfaceMesh::calcLocalQueries new mapDistribute ( segmentI, // size after construction - sendMap, - constructMap, - true // reuse storage + sendMap.xfer(), + constructMap.xfer() ) ); const mapDistribute& map = mapPtr(); @@ -806,9 +804,8 @@ Foam::distributedTriSurfaceMesh::calcLocalQueries new mapDistribute ( segmentI, // size after construction - sendMap, - constructMap, - true // reuse storage + sendMap.xfer(), + constructMap.xfer() ) ); return mapPtr; @@ -2399,9 +2396,8 @@ void Foam::distributedTriSurfaceMesh::distribute new mapDistribute ( allTris.size(), - faceSendMap, - faceConstructMap, - true + faceSendMap.xfer(), + faceConstructMap.xfer() ) ); pointMap.reset @@ -2409,9 +2405,8 @@ void Foam::distributedTriSurfaceMesh::distribute new mapDistribute ( allPoints.size(), - pointSendMap, - pointConstructMap, - true + pointSendMap.xfer(), + pointConstructMap.xfer() ) ); From c03788a9d33f0d35ab1e77f2aef09b105bd028a2 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 14 Aug 2009 13:17:33 +0100 Subject: [PATCH 04/12] tidying - using rasModel to provide fields instead of db lookup, and cache yPlusLam_ --- .../omegaWallFunctionFvPatchScalarField.C | 105 ++++++++++-------- .../omegaWallFunctionFvPatchScalarField.H | 29 +++-- 2 files changed, 71 insertions(+), 63 deletions(-) diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C index 105ee1de71..c39b20bf0c 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C @@ -40,7 +40,7 @@ namespace incompressible namespace RASModels { -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void omegaWallFunctionFvPatchScalarField::checkType() { @@ -56,6 +56,32 @@ void omegaWallFunctionFvPatchScalarField::checkType() } +scalar omegaWallFunctionFvPatchScalarField::calcYPlusLam +( + const scalar kappa, + const scalar E +) const +{ + scalar ypl = 11.0; + + for (int i=0; i<10; i++) + { + ypl = log(E*ypl)/kappa; + } + + return ypl; +} + + +void omegaWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const +{ + writeEntryIfDifferent(os, "G", "RASModel::G", GName_); + os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; + os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; + os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField @@ -65,14 +91,11 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF), - UName_("U"), - kName_("k"), GName_("RASModel::G"), - nuName_("nu"), - nutName_("nut"), Cmu_(0.09), kappa_(0.41), - E_(9.8) + E_(9.8), + yPlusLam_(calcYPlusLam(kappa_, E_)) { checkType(); } @@ -87,14 +110,11 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ptf, p, iF, mapper), - UName_(ptf.UName_), - kName_(ptf.kName_), GName_(ptf.GName_), - nuName_(ptf.nuName_), - nutName_(ptf.nutName_), Cmu_(ptf.Cmu_), kappa_(ptf.kappa_), - E_(ptf.E_) + E_(ptf.E_), + yPlusLam_(ptf.yPlusLam_) { checkType(); } @@ -108,14 +128,11 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF, dict), - UName_(dict.lookupOrDefault("U", "U")), - kName_(dict.lookupOrDefault("k", "k")), GName_(dict.lookupOrDefault("G", "RASModel::G")), - nuName_(dict.lookupOrDefault("nu", "nu")), - nutName_(dict.lookupOrDefault("nut", "nut")), Cmu_(dict.lookupOrDefault("Cmu", 0.09)), kappa_(dict.lookupOrDefault("kappa", 0.41)), - E_(dict.lookupOrDefault("E", 9.8)) + E_(dict.lookupOrDefault("E", 9.8)), + yPlusLam_(calcYPlusLam(kappa_, E_)) { checkType(); } @@ -127,14 +144,11 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(owfpsf), - UName_(owfpsf.UName_), - kName_(owfpsf.kName_), GName_(owfpsf.GName_), - nuName_(owfpsf.nuName_), - nutName_(owfpsf.nutName_), Cmu_(owfpsf.Cmu_), kappa_(owfpsf.kappa_), - E_(owfpsf.E_) + E_(owfpsf.E_), + yPlusLam_(owfpsf.yPlusLam_) { checkType(); } @@ -147,14 +161,12 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(owfpsf, iF), - UName_(owfpsf.UName_), - kName_(owfpsf.kName_), GName_(owfpsf.GName_), - nuName_(owfpsf.nuName_), - nutName_(owfpsf.nutName_), Cmu_(owfpsf.Cmu_), kappa_(owfpsf.kappa_), - E_(owfpsf.E_) + E_(owfpsf.E_), + yPlusLam_(owfpsf.yPlusLam_) + { checkType(); } @@ -169,28 +181,32 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs() return; } + const label patchI = patch().index(); + const RASModel& rasModel = db().lookupObject("RASProperties"); - const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_); - const scalarField& y = rasModel.y()[patch().index()]; + const scalarField& y = rasModel.y()[patchI]; const scalar Cmu25 = pow(Cmu_, 0.25); - volScalarField& G = const_cast - (db().lookupObject(GName_)); + volScalarField& G = + const_cast(db().lookupObject(GName_)); - volScalarField& omega = const_cast - (db().lookupObject(dimensionedInternalField().name())); + DimensionedField& omega = + const_cast&> + ( + dimensionedInternalField() + ); - const scalarField& k = db().lookupObject(kName_); + const tmp tk = rasModel.k(); + const volScalarField& k = tk(); - const scalarField& nuw = - patch().lookupPatchField(nuName_); + const scalarField& nuw = rasModel.nu().boundaryField()[patchI]; - const scalarField& nutw = - patch().lookupPatchField(nutName_); + const tmp tnut = rasModel.nut(); + const volScalarField& nut = tnut(); + const scalarField& nutw = nut.boundaryField()[patchI]; - const fvPatchVectorField& Uw = - patch().lookupPatchField(UName_); + const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; const scalarField magGradUw = mag(Uw.snGrad()); @@ -203,7 +219,7 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs() omega[faceCellI] = sqrt(k[faceCellI])/(Cmu25*kappa_*y[faceI]); - if (yPlus > yPlusLam) + if (yPlus > yPlusLam_) { G[faceCellI] = (nutw[faceI] + nuw[faceI]) @@ -226,14 +242,7 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs() void omegaWallFunctionFvPatchScalarField::write(Ostream& os) const { fixedInternalValueFvPatchField::write(os); - writeEntryIfDifferent(os, "U", "U", UName_); - writeEntryIfDifferent(os, "k", "k", kName_); - writeEntryIfDifferent(os, "G", "RASModel::G", GName_); - writeEntryIfDifferent(os, "nu", "nu", nuName_); - writeEntryIfDifferent(os, "nut", "nut", nutName_); - os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; - os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; - os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; + writeLocalEntries(os); writeEntry("value", os); } diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H index ce9060de8a..1b3915b575 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H @@ -55,23 +55,13 @@ class omegaWallFunctionFvPatchScalarField : public fixedInternalValueFvPatchField { - // Private data +protected: - //- Name of velocity field - word UName_; - - //- Name of turbulence kinetic energy field - word kName_; + // Protected data //- Name of turbulence generation field word GName_; - //- Name of laminar viscosity field - word nuName_; - - //- Name of turbulent viscosity field - word nutName_; - //- Cmu coefficient scalar Cmu_; @@ -81,11 +71,20 @@ class omegaWallFunctionFvPatchScalarField //- E coefficient scalar E_; + //- Y+ at the edge of the laminar sublayer + scalar yPlusLam_; - // Private member functions + + // Protected member functions //- Check the type of the patch - void checkType(); + virtual void checkType(); + + //- Calculate the Y+ at the edge of the laminar sublayer + virtual scalar calcYPlusLam(const scalar kappa, const scalar E) const; + + //- Write local wall function variables + virtual void writeLocalEntries(Ostream&) const; public: @@ -168,7 +167,7 @@ public: // I-O //- Write - void write(Ostream&) const; + virtual void write(Ostream&) const; }; From fcf14db03d928e1b3ee587bfbc8587aa8111607d Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 14 Aug 2009 13:26:45 +0100 Subject: [PATCH 05/12] tidying epsilon wf - using rasModel to provide fields instead of db lookup, and cache yPlusLam_ --- .../epsilonWallFunctionFvPatchScalarField.C | 102 ++++++++++-------- .../epsilonWallFunctionFvPatchScalarField.H | 30 +++--- 2 files changed, 70 insertions(+), 62 deletions(-) diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C index 96815c3931..5f771ec663 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C @@ -56,6 +56,32 @@ void epsilonWallFunctionFvPatchScalarField::checkType() } +scalar epsilonWallFunctionFvPatchScalarField::calcYPlusLam +( + const scalar kappa, + const scalar E +) const +{ + scalar ypl = 11.0; + + for (int i=0; i<10; i++) + { + ypl = log(E*ypl)/kappa; + } + + return ypl; +} + + +void epsilonWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const +{ + writeEntryIfDifferent(os, "G", "RASModel::G", GName_); + os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; + os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; + os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField @@ -65,14 +91,11 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF), - UName_("U"), - kName_("k"), GName_("RASModel::G"), - nuName_("nu"), - nutName_("nut"), Cmu_(0.09), kappa_(0.41), - E_(9.8) + E_(9.8), + yPlusLam_(calcYPlusLam(kappa_, E_)) { checkType(); } @@ -87,14 +110,11 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ptf, p, iF, mapper), - UName_(ptf.UName_), - kName_(ptf.kName_), GName_(ptf.GName_), - nuName_(ptf.nuName_), - nutName_(ptf.nutName_), Cmu_(ptf.Cmu_), kappa_(ptf.kappa_), - E_(ptf.E_) + E_(ptf.E_), + yPlusLam_(ptf.yPlusLam_) { checkType(); } @@ -108,14 +128,11 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF, dict), - UName_(dict.lookupOrDefault("U", "U")), - kName_(dict.lookupOrDefault("k", "k")), GName_(dict.lookupOrDefault("G", "RASModel::G")), - nuName_(dict.lookupOrDefault("nu", "nu")), - nutName_(dict.lookupOrDefault("nut", "nut")), Cmu_(dict.lookupOrDefault("Cmu", 0.09)), kappa_(dict.lookupOrDefault("kappa", 0.41)), - E_(dict.lookupOrDefault("E", 9.8)) + E_(dict.lookupOrDefault("E", 9.8)), + yPlusLam_(calcYPlusLam(kappa_, E_)) { checkType(); } @@ -127,14 +144,11 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ewfpsf), - UName_(ewfpsf.UName_), - kName_(ewfpsf.kName_), GName_(ewfpsf.GName_), - nuName_(ewfpsf.nuName_), - nutName_(ewfpsf.nutName_), Cmu_(ewfpsf.Cmu_), kappa_(ewfpsf.kappa_), - E_(ewfpsf.E_) + E_(ewfpsf.E_), + yPlusLam_(ewfpsf.yPlusLam_) { checkType(); } @@ -147,14 +161,11 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ewfpsf, iF), - UName_(ewfpsf.UName_), - kName_(ewfpsf.kName_), GName_(ewfpsf.GName_), - nuName_(ewfpsf.nuName_), - nutName_(ewfpsf.nutName_), Cmu_(ewfpsf.Cmu_), kappa_(ewfpsf.kappa_), - E_(ewfpsf.E_) + E_(ewfpsf.E_), + yPlusLam_(ewfpsf.yPlusLam_) { checkType(); } @@ -169,29 +180,33 @@ void epsilonWallFunctionFvPatchScalarField::updateCoeffs() return; } + const label patchI = patch().index(); + const RASModel& rasModel = db().lookupObject("RASProperties"); - const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_); - const scalarField& y = rasModel.y()[patch().index()]; + const scalarField& y = rasModel.y()[patchI]; const scalar Cmu25 = pow(Cmu_, 0.25); const scalar Cmu75 = pow(Cmu_, 0.75); - volScalarField& G = const_cast - (db().lookupObject(GName_)); + volScalarField& G = + const_cast(db().lookupObject(GName_)); - volScalarField& epsilon = const_cast - (db().lookupObject(dimensionedInternalField().name())); + DimensionedField& epsilon = + const_cast&> + ( + dimensionedInternalField() + ); - const volScalarField& k = db().lookupObject(kName_); + const tmp tk = rasModel.k(); + const volScalarField& k = tk(); - const scalarField& nuw = - patch().lookupPatchField(nuName_); + const scalarField& nuw = rasModel.nu().boundaryField()[patchI]; - const scalarField& nutw = - patch().lookupPatchField(nutName_); + const tmp tnut = rasModel.nut(); + const volScalarField& nut = tnut(); + const scalarField& nutw = nut.boundaryField()[patchI]; - const fvPatchVectorField& Uw = - patch().lookupPatchField(UName_); + const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; const scalarField magGradUw = mag(Uw.snGrad()); @@ -204,7 +219,7 @@ void epsilonWallFunctionFvPatchScalarField::updateCoeffs() epsilon[faceCellI] = Cmu75*pow(k[faceCellI], 1.5)/(kappa_*y[faceI]); - if (yPlus > yPlusLam) + if (yPlus > yPlusLam_) { G[faceCellI] = (nutw[faceI] + nuw[faceI]) @@ -236,14 +251,7 @@ void epsilonWallFunctionFvPatchScalarField::evaluate void epsilonWallFunctionFvPatchScalarField::write(Ostream& os) const { fixedInternalValueFvPatchField::write(os); - writeEntryIfDifferent(os, "U", "U", UName_); - writeEntryIfDifferent(os, "k", "k", kName_); - writeEntryIfDifferent(os, "G", "RASModel::G", GName_); - writeEntryIfDifferent(os, "nu", "nu", nuName_); - writeEntryIfDifferent(os, "nut", "nut", nutName_); - os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; - os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; - os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; + writeLocalEntries(os); writeEntry("value", os); } diff --git a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H index bd98cced76..805daeb503 100644 --- a/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H +++ b/src/turbulenceModels/incompressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H @@ -57,23 +57,13 @@ class epsilonWallFunctionFvPatchScalarField : public fixedInternalValueFvPatchField { - // Private data +protected: - //- Name of velocity field - word UName_; - - //- Name of turbulence kinetic energy field - word kName_; + // Protected data //- Name of turbulence generation field word GName_; - //- Name of laminar viscosity field - word nuName_; - - //- Name of turbulent viscosity field - word nutName_; - //- Cmu coefficient scalar Cmu_; @@ -84,10 +74,20 @@ class epsilonWallFunctionFvPatchScalarField scalar E_; - // Private member functions + //- Y+ at the edge of the laminar sublayer + scalar yPlusLam_; + + + // Protected member functions //- Check the type of the patch - void checkType(); + virtual void checkType(); + + //- Calculate the Y+ at the edge of the laminar sublayer + virtual scalar calcYPlusLam(const scalar kappa, const scalar E) const; + + //- Write local wall function variables + virtual void writeLocalEntries(Ostream&) const; public: @@ -173,7 +173,7 @@ public: // I-O //- Write - void write(Ostream&) const; + virtual void write(Ostream&) const; }; From 7e2b27751e893c82c5a455c38a360919cbfe64c5 Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 14 Aug 2009 14:45:09 +0100 Subject: [PATCH 06/12] tidying compressible wfs - using rasModel to provide fields instead of db lookup, and cache yPlusLam_ --- .../epsilonWallFunctionFvPatchScalarField.C | 115 +++++++++--------- .../epsilonWallFunctionFvPatchScalarField.H | 32 +++-- .../omegaWallFunctionFvPatchScalarField.C | 109 +++++++++-------- .../omegaWallFunctionFvPatchScalarField.H | 32 +++-- 4 files changed, 144 insertions(+), 144 deletions(-) diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C index 4a2b5b6d31..07382bad52 100644 --- a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.C @@ -56,6 +56,32 @@ void epsilonWallFunctionFvPatchScalarField::checkType() } +scalar epsilonWallFunctionFvPatchScalarField::calcYPlusLam +( + const scalar kappa, + const scalar E +) const +{ + scalar ypl = 11.0; + + for (int i=0; i<10; i++) + { + ypl = log(E*ypl)/kappa; + } + + return ypl; +} + + +void epsilonWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const +{ + writeEntryIfDifferent(os, "G", "RASModel::G", GName_); + os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; + os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; + os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField @@ -65,15 +91,13 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF), - UName_("U"), - kName_("k"), GName_("RASModel::G"), - rhoName_("rho"), - muName_("mu"), - mutName_("mut"), Cmu_(0.09), kappa_(0.41), - E_(9.8) + E_(9.8), + yPlusLam_(calcYPlusLam(kappa_, E_)) + + { checkType(); } @@ -88,15 +112,12 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ptf, p, iF, mapper), - UName_(ptf.UName_), - kName_(ptf.kName_), GName_(ptf.GName_), - rhoName_(ptf.rhoName_), - muName_(ptf.muName_), - mutName_(ptf.mutName_), Cmu_(ptf.Cmu_), kappa_(ptf.kappa_), - E_(ptf.E_) + E_(ptf.E_), + yPlusLam_(ptf.yPlusLam_) + { checkType(); } @@ -110,15 +131,12 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF, dict), - UName_(dict.lookupOrDefault("U", "U")), - kName_(dict.lookupOrDefault("k", "k")), GName_(dict.lookupOrDefault("G", "RASModel::G")), - rhoName_(dict.lookupOrDefault("rho", "rho")), - muName_(dict.lookupOrDefault("mu", "mu")), - mutName_(dict.lookupOrDefault("mut", "mut")), Cmu_(dict.lookupOrDefault("Cmu", 0.09)), kappa_(dict.lookupOrDefault("kappa", 0.41)), - E_(dict.lookupOrDefault("E", 9.8)) + E_(dict.lookupOrDefault("E", 9.8)), + yPlusLam_(calcYPlusLam(kappa_, E_)) + { checkType(); } @@ -130,15 +148,11 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ewfpsf), - UName_(ewfpsf.UName_), - kName_(ewfpsf.kName_), GName_(ewfpsf.GName_), - rhoName_(ewfpsf.rhoName_), - muName_(ewfpsf.muName_), - mutName_(ewfpsf.mutName_), Cmu_(ewfpsf.Cmu_), kappa_(ewfpsf.kappa_), - E_(ewfpsf.E_) + E_(ewfpsf.E_), + yPlusLam_(ewfpsf.yPlusLam_) { checkType(); } @@ -151,15 +165,11 @@ epsilonWallFunctionFvPatchScalarField::epsilonWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ewfpsf, iF), - UName_(ewfpsf.UName_), - kName_(ewfpsf.kName_), GName_(ewfpsf.GName_), - rhoName_(ewfpsf.rhoName_), - muName_(ewfpsf.muName_), - mutName_(ewfpsf.mutName_), Cmu_(ewfpsf.Cmu_), kappa_(ewfpsf.kappa_), - E_(ewfpsf.E_) + E_(ewfpsf.E_), + yPlusLam_(ewfpsf.yPlusLam_) { checkType(); } @@ -174,33 +184,36 @@ void epsilonWallFunctionFvPatchScalarField::updateCoeffs() return; } + const label patchI = patch().index(); + const RASModel& rasModel = db().lookupObject("RASProperties"); const scalar Cmu25 = pow(Cmu_, 0.25); const scalar Cmu75 = pow(Cmu_, 0.75); - const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_); - const scalarField& y = rasModel.y()[patch().index()]; + const scalarField& y = rasModel.y()[patchI]; - volScalarField& G = const_cast - (db().lookupObject(GName_)); + volScalarField& G = + const_cast(db().lookupObject(GName_)); - volScalarField& epsilon = const_cast - (db().lookupObject(dimensionedInternalField().name())); + DimensionedField& epsilon = + const_cast&> + ( + dimensionedInternalField() + ); - const volScalarField& k = db().lookupObject(kName_); + const tmp tk = rasModel.k(); + const volScalarField& k = tk(); - const scalarField& rhow = - patch().lookupPatchField(rhoName_); + const scalarField& rhow = rasModel.rho().boundaryField()[patchI]; - const scalarField& muw = - patch().lookupPatchField(muName_); + const scalarField& muw = rasModel.mu().boundaryField()[patchI]; - const scalarField& mutw = - patch().lookupPatchField(mutName_); + const tmp tmut = rasModel.mut(); + const volScalarField& mut = tmut(); + const scalarField& mutw = mut.boundaryField()[patchI]; - const fvPatchVectorField& Uw = - patch().lookupPatchField(UName_); + const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; const scalarField magGradUw = mag(Uw.snGrad()); @@ -215,7 +228,7 @@ void epsilonWallFunctionFvPatchScalarField::updateCoeffs() epsilon[faceCellI] = Cmu75*pow(k[faceCellI], 1.5)/(kappa_*y[faceI]); - if (yPlus > yPlusLam) + if (yPlus > yPlusLam_) { G[faceCellI] = (mutw[faceI] + muw[faceI]) @@ -247,15 +260,7 @@ void epsilonWallFunctionFvPatchScalarField::evaluate void epsilonWallFunctionFvPatchScalarField::write(Ostream& os) const { fixedInternalValueFvPatchField::write(os); - writeEntryIfDifferent(os, "U", "U", UName_); - writeEntryIfDifferent(os, "k", "k", kName_); - writeEntryIfDifferent(os, "G", "RASModel::G", GName_); - writeEntryIfDifferent(os, "rho", "rho", rhoName_); - writeEntryIfDifferent(os, "mu", "mu", muName_); - writeEntryIfDifferent(os, "mut", "mut", mutName_); - os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; - os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; - os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; + writeLocalEntries(os); writeEntry("value", os); } diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H index 5d5865e11e..1d4c64fb41 100644 --- a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/epsilonWallFunctions/epsilonWallFunction/epsilonWallFunctionFvPatchScalarField.H @@ -57,26 +57,13 @@ class epsilonWallFunctionFvPatchScalarField : public fixedInternalValueFvPatchField { - // Private data +protected: - //- Name of velocity field - word UName_; - - //- Name of turbulence kinetic energy field - word kName_; + // Protected data //- Name of turbulence generation field word GName_; - //- Name of density field - word rhoName_; - - //- Name of laminar viscosity field - word muName_; - - //- Name of turbulent viscosity field - word mutName_; - //- Cmu coefficient scalar Cmu_; @@ -86,11 +73,20 @@ class epsilonWallFunctionFvPatchScalarField //- E coefficient scalar E_; + //- Y+ at the edge of the laminar sublayer + scalar yPlusLam_; - // Private member functions + + // Protected member functions //- Check the type of the patch - void checkType(); + virtual void checkType(); + + //- Calculate the Y+ at the edge of the laminar sublayer + virtual scalar calcYPlusLam(const scalar kappa, const scalar E) const; + + //- Write local wall function variables + virtual void writeLocalEntries(Ostream&) const; public: @@ -176,7 +172,7 @@ public: // I-O //- Write - void write(Ostream&) const; + virtual void write(Ostream&) const; }; diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C index 84ac6ba060..6e475094ec 100644 --- a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.C @@ -40,7 +40,7 @@ namespace compressible namespace RASModels { -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void omegaWallFunctionFvPatchScalarField::checkType() { @@ -56,6 +56,32 @@ void omegaWallFunctionFvPatchScalarField::checkType() } +scalar omegaWallFunctionFvPatchScalarField::calcYPlusLam +( + const scalar kappa, + const scalar E +) const +{ + scalar ypl = 11.0; + + for (int i=0; i<10; i++) + { + ypl = log(E*ypl)/kappa; + } + + return ypl; +} + + +void omegaWallFunctionFvPatchScalarField::writeLocalEntries(Ostream& os) const +{ + writeEntryIfDifferent(os, "G", "RASModel::G", GName_); + os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; + os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; + os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; +} + + // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField @@ -65,15 +91,12 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF), - UName_("U"), - rhoName_("rho"), - kName_("k"), GName_("RASModel::G"), - muName_("mu"), - mutName_("mut"), Cmu_(0.09), kappa_(0.41), - E_(9.8) + E_(9.8), + yPlusLam_(calcYPlusLam(kappa_, E_)) + { checkType(); } @@ -88,15 +111,11 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(ptf, p, iF, mapper), - UName_(ptf.UName_), - rhoName_(ptf.rhoName_), - kName_(ptf.kName_), GName_(ptf.GName_), - muName_(ptf.muName_), - mutName_(ptf.mutName_), Cmu_(ptf.Cmu_), kappa_(ptf.kappa_), - E_(ptf.E_) + E_(ptf.E_), + yPlusLam_(ptf.yPlusLam_) { checkType(); } @@ -110,15 +129,11 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(p, iF, dict), - UName_(dict.lookupOrDefault("U", "U")), - rhoName_(dict.lookupOrDefault("rho", "rho")), - kName_(dict.lookupOrDefault("k", "k")), GName_(dict.lookupOrDefault("G", "RASModel::G")), - muName_(dict.lookupOrDefault("mu", "mu")), - mutName_(dict.lookupOrDefault("mut", "mut")), Cmu_(dict.lookupOrDefault("Cmu", 0.09)), kappa_(dict.lookupOrDefault("kappa", 0.41)), - E_(dict.lookupOrDefault("E", 9.8)) + E_(dict.lookupOrDefault("E", 9.8)), + yPlusLam_(calcYPlusLam(kappa_, E_)) { checkType(); } @@ -130,15 +145,11 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(owfpsf), - UName_(owfpsf.UName_), - rhoName_(owfpsf.rhoName_), - kName_(owfpsf.kName_), GName_(owfpsf.GName_), - muName_(owfpsf.muName_), - mutName_(owfpsf.mutName_), Cmu_(owfpsf.Cmu_), kappa_(owfpsf.kappa_), - E_(owfpsf.E_) + E_(owfpsf.E_), + yPlusLam_(owfpsf.yPlusLam_) { checkType(); } @@ -151,15 +162,12 @@ omegaWallFunctionFvPatchScalarField::omegaWallFunctionFvPatchScalarField ) : fixedInternalValueFvPatchField(owfpsf, iF), - UName_(owfpsf.UName_), - rhoName_(owfpsf.rhoName_), - kName_(owfpsf.kName_), GName_(owfpsf.GName_), - muName_(owfpsf.muName_), - mutName_(owfpsf.mutName_), Cmu_(owfpsf.Cmu_), kappa_(owfpsf.kappa_), - E_(owfpsf.E_) + E_(owfpsf.E_), + yPlusLam_(owfpsf.yPlusLam_) + { checkType(); } @@ -174,8 +182,9 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs() return; } + const label patchI = patch().index(); + const RASModel& rasModel = db().lookupObject("RASProperties"); - const scalar yPlusLam = rasModel.yPlusLam(kappa_, E_); const scalarField& y = rasModel.y()[patch().index()]; const scalar Cmu25 = pow(Cmu_, 0.25); @@ -183,22 +192,24 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs() volScalarField& G = const_cast (db().lookupObject(GName_)); - volScalarField& omega = const_cast - (db().lookupObject(dimensionedInternalField().name())); + DimensionedField& omega = + const_cast&> + ( + dimensionedInternalField() + ); - const scalarField& k = db().lookupObject(kName_); + const tmp tk = rasModel.k(); + const volScalarField& k = tk(); - const scalarField& rhow = - patch().lookupPatchField(rhoName_); + const scalarField& rhow = rasModel.rho().boundaryField()[patchI]; - const scalarField& muw = - patch().lookupPatchField(muName_); + const scalarField& muw = rasModel.mu().boundaryField()[patchI]; - const scalarField& mutw = - patch().lookupPatchField(mutName_); + const tmp tmut = rasModel.mut(); + const volScalarField& mut = tmut(); + const scalarField& mutw = mut.boundaryField()[patchI]; - const fvPatchVectorField& Uw = - patch().lookupPatchField(UName_); + const fvPatchVectorField& Uw = rasModel.U().boundaryField()[patchI]; const scalarField magGradUw = mag(Uw.snGrad()); @@ -213,7 +224,7 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs() omega[faceCellI] = sqrt(k[faceCellI])/(Cmu25*kappa_*y[faceI]); - if (yPlus > yPlusLam) + if (yPlus > yPlusLam_) { G[faceCellI] = (mutw[faceI] + muw[faceI]) @@ -236,15 +247,7 @@ void omegaWallFunctionFvPatchScalarField::updateCoeffs() void omegaWallFunctionFvPatchScalarField::write(Ostream& os) const { fixedInternalValueFvPatchField::write(os); - writeEntryIfDifferent(os, "U", "U", UName_); - writeEntryIfDifferent(os, "rho", "rho", rhoName_); - writeEntryIfDifferent(os, "k", "k", kName_); - writeEntryIfDifferent(os, "G", "RASModel::G", GName_); - writeEntryIfDifferent(os, "mu", "mu", muName_); - writeEntryIfDifferent(os, "mut", "mut", mutName_); - os.writeKeyword("Cmu") << Cmu_ << token::END_STATEMENT << nl; - os.writeKeyword("kappa") << kappa_ << token::END_STATEMENT << nl; - os.writeKeyword("E") << E_ << token::END_STATEMENT << nl; + writeLocalEntries(os); writeEntry("value", os); } diff --git a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H index 2eb4779279..2efcc1e191 100644 --- a/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H +++ b/src/turbulenceModels/compressible/RAS/derivedFvPatchFields/wallFunctions/omegaWallFunctions/omegaWallFunction/omegaWallFunctionFvPatchScalarField.H @@ -55,26 +55,13 @@ class omegaWallFunctionFvPatchScalarField : public fixedInternalValueFvPatchField { - // Private data +protected: - //- Name of velocity field - word UName_; - - //- Name of density field - word rhoName_; - - //- Name of turbulence kinetic energy field - word kName_; + // Protected data //- Name of turbulence generation field word GName_; - //- Name of laminar viscosity field - word muName_; - - //- Name of turbulent viscosity field - word mutName_; - //- Cmu coefficient scalar Cmu_; @@ -84,11 +71,20 @@ class omegaWallFunctionFvPatchScalarField //- E coefficient scalar E_; + //- Y+ at the edge of the laminar sublayer + scalar yPlusLam_; - // Private member functions + + // Protected member functions //- Check the type of the patch - void checkType(); + virtual void checkType(); + + //- Calculate the Y+ at the edge of the laminar sublayer + virtual scalar calcYPlusLam(const scalar kappa, const scalar E) const; + + //- Write local wall function variables + virtual void writeLocalEntries(Ostream&) const; public: @@ -171,7 +167,7 @@ public: // I-O //- Write - void write(Ostream&) const; + virtual void write(Ostream&) const; }; From adf3e4b7e15783ff112a186393b83a09008a412c Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 17 Aug 2009 17:05:38 +0100 Subject: [PATCH 07/12] clever usage of #include --- applications/utilities/surface/surfaceSubset/surfaceSubsetDict | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/utilities/surface/surfaceSubset/surfaceSubsetDict b/applications/utilities/surface/surfaceSubset/surfaceSubsetDict index ed06d0a39c..3a8db2cffd 100644 --- a/applications/utilities/surface/surfaceSubset/surfaceSubsetDict +++ b/applications/utilities/surface/surfaceSubset/surfaceSubsetDict @@ -16,7 +16,7 @@ FoamFile // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Select triangles by label -faces (); +faces #include "badFaces"; // Select triangles using given points (local point numbering) localPoints ( ); From 42001c007af059d474ee3bec90194b4f477da1a9 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 17 Aug 2009 17:05:57 +0100 Subject: [PATCH 08/12] extraneous printing --- .../utilities/mesh/generation/blockMesh/createMergeList.C | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/utilities/mesh/generation/blockMesh/createMergeList.C b/applications/utilities/mesh/generation/blockMesh/createMergeList.C index 551b9eec67..b46317652d 100644 --- a/applications/utilities/mesh/generation/blockMesh/createMergeList.C +++ b/applications/utilities/mesh/generation/blockMesh/createMergeList.C @@ -30,7 +30,7 @@ License Foam::labelList Foam::blockMesh::createMergeList() { - Info<< nl << "Creating merge list " << flush; + Info<< nl << "Creating merge list" << flush; labelList MergeList(nPoints_, -1); From 5896bd04f75a71de9564ec366fa9ba86fee730fa Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 17 Aug 2009 17:06:45 +0100 Subject: [PATCH 09/12] remove commented out code --- src/OpenFOAM/db/Time/Time.C | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index f0976a77b5..f0c67306be 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -130,7 +130,6 @@ void Foam::Time::setControls() FatalIOErrorIn("Time::setControls()", controlDict_) << "expected startTime, firstTime or latestTime" << " found '" << startFrom << "'" - //<< "' in dictionary " << controlDict_.name() << exit(FatalIOError); } } From 47066c7e512d9be6c03cc8d9bc31ad5127e31e44 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 17 Aug 2009 22:03:53 +0100 Subject: [PATCH 10/12] cgal compilation --- wmake/rules/General/CGAL | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/wmake/rules/General/CGAL b/wmake/rules/General/CGAL index 4e7e3b4ef9..b31cd53a7f 100644 --- a/wmake/rules/General/CGAL +++ b/wmake/rules/General/CGAL @@ -1,7 +1,4 @@ -CGAL_PATH = ${WM_THIRD_PARTY_DIR}/CGAL-${CGAL_VERSION} - CGAL_INC = \ -Wno-old-style-cast \ -I${CGAL_SRC}/include \ - -I${CGAL_PATH} \ - -I${BOOST_SRC} + -I${BOOST_ROOT}/include/boost-${BOOST_LIB_VERSION} From 064892f3f8fc6a828537ad5d734b0c9160689c0e Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 17 Aug 2009 22:04:14 +0100 Subject: [PATCH 11/12] surface patch handling improvements --- .../utilities/surface/surfaceAdd/surfaceAdd.C | 30 ++++++------------- .../geometricSurfacePatch.H | 6 ++++ src/triSurface/triSurface/triSurface.C | 3 ++ 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/applications/utilities/surface/surfaceAdd/surfaceAdd.C b/applications/utilities/surface/surfaceAdd/surfaceAdd.C index 6441486cd1..587461d403 100644 --- a/applications/utilities/surface/surfaceAdd/surfaceAdd.C +++ b/applications/utilities/surface/surfaceAdd/surfaceAdd.C @@ -158,45 +158,33 @@ int main(int argc, char *argv[]) label trianglei = 0; - label maxRegion1 = labelMin; // Copy triangles1 into trianglesAll - // Determine max region. - forAll(surface1, faceI) { - facesAll[trianglei] = surface1[faceI]; - - maxRegion1 = max(maxRegion1, facesAll[trianglei].region()); - - trianglei++; + facesAll[trianglei++] = surface1[faceI]; } + label nRegions1 = surface1.patches().size(); - label nRegions1 = maxRegion1 + 1; if (!mergeRegions) { - Info<< "Surface " << inFileName1 << " has " << nRegions1 << " regions" + Info<< "Surface " << inFileName1 << " has " << nRegions1 + << " regions" << nl << "All region numbers in " << inFileName2 << " will be offset" << " by this amount" << nl << endl; } // Add (renumbered) surface2 triangles - label maxRegion2 = labelMin; - forAll(surface2, faceI) { const labelledTri& tri = surface2[faceI]; labelledTri& destTri = facesAll[trianglei++]; - destTri[0] = tri[0] + points1.size(); destTri[1] = tri[1] + points1.size(); destTri[2] = tri[2] + points1.size(); - - maxRegion2 = max(maxRegion2, tri.region()); - if (mergeRegions) { destTri.region() = tri.region(); @@ -207,7 +195,7 @@ int main(int argc, char *argv[]) } } - label nRegions2 = maxRegion2 + 1; + label nRegions2 = surface2.patches().size(); geometricSurfacePatchList newPatches; @@ -218,11 +206,11 @@ int main(int argc, char *argv[]) forAll(surface1.patches(), patchI) { - newPatches[patchI] = surface1.patches()[ patchI]; + newPatches[patchI] = surface1.patches()[patchI]; } forAll(surface2.patches(), patchI) { - newPatches[patchI] = surface2.patches()[ patchI]; + newPatches[patchI] = surface2.patches()[patchI]; } } else @@ -244,12 +232,12 @@ int main(int argc, char *argv[]) forAll(surface1.patches(), patchI) { - newPatches[newPatchI++] = surface1.patches()[ patchI]; + newPatches[newPatchI++] = surface1.patches()[patchI]; } forAll(surface2.patches(), patchI) { - newPatches[newPatchI++] = surface2.patches()[ patchI]; + newPatches[newPatchI++] = surface2.patches()[patchI]; } } diff --git a/src/triSurface/triSurface/geometricSurfacePatch/geometricSurfacePatch.H b/src/triSurface/triSurface/geometricSurfacePatch/geometricSurfacePatch.H index 7db3f27bd9..a641924684 100644 --- a/src/triSurface/triSurface/geometricSurfacePatch/geometricSurfacePatch.H +++ b/src/triSurface/triSurface/geometricSurfacePatch/geometricSurfacePatch.H @@ -128,6 +128,12 @@ public: return index_; } + //- Return the index of this patch in the boundaryMesh + label& index() + { + return index_; + } + //- Write void write(Ostream&) const; diff --git a/src/triSurface/triSurface/triSurface.C b/src/triSurface/triSurface/triSurface.C index b17aa88bb5..3b8d2f9d5f 100644 --- a/src/triSurface/triSurface/triSurface.C +++ b/src/triSurface/triSurface/triSurface.C @@ -544,6 +544,8 @@ Foam::surfacePatchList Foam::triSurface::calcPatches(labelList& faceMap) const { surfacePatch& newPatch = newPatches[newPatchI]; + newPatch.index() = newPatchI; + label oldPatchI = newPatchI; // start of patch @@ -592,6 +594,7 @@ void Foam::triSurface::setDefaultPatches() forAll(newPatches, patchI) { + patches_[patchI].index() = patchI; patches_[patchI].name() = newPatches[patchI].name(); patches_[patchI].geometricType() = newPatches[patchI].geometricType(); } From 252023468328878a40647f594d2164554439c9af Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 17 Aug 2009 22:08:49 +0100 Subject: [PATCH 12/12] missing include file --- src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C | 1 + 1 file changed, 1 insertion(+) diff --git a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C index 68d4b3b1e6..1ba66fffe9 100644 --- a/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C +++ b/src/autoMesh/autoHexMesh/autoHexMeshDriver/autoRefineDriver.C @@ -34,6 +34,7 @@ License #include "featureEdgeMesh.H" #include "refinementSurfaces.H" #include "shellSurfaces.H" +#include "mapDistributePolyMesh.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //