diff --git a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C index 4abdc6c607..b57e181a03 100644 --- a/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C +++ b/applications/utilities/mesh/manipulation/splitMeshRegions/splitMeshRegions.C @@ -101,296 +101,13 @@ Description #include "syncTools.H" #include "ReadFields.H" #include "mappedWallPolyPatch.H" +#include "fvMeshTools.H" #include "zeroGradientFvPatchFields.H" using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -template -void addPatchFields(fvMesh& mesh, const word& patchFieldType) -{ - HashTable flds - ( - mesh.objectRegistry::lookupClass() - ); - - forAllConstIter(typename HashTable, flds, iter) - { - const GeoField& fld = *iter(); - - typename GeoField::GeometricBoundaryField& bfld = - const_cast - ( - fld.boundaryField() - ); - - label sz = bfld.size(); - bfld.setSize(sz+1); - bfld.set - ( - sz, - GeoField::PatchFieldType::New - ( - patchFieldType, - mesh.boundary()[sz], - fld.dimensionedInternalField() - ) - ); - } -} - - -// Remove last patch field -template -void trimPatchFields(fvMesh& mesh, const label nPatches) -{ - HashTable flds - ( - mesh.objectRegistry::lookupClass() - ); - - forAllConstIter(typename HashTable, flds, iter) - { - const GeoField& fld = *iter(); - - const_cast - ( - fld.boundaryField() - ).setSize(nPatches); - } -} - - -// Reorder patch field -template -void reorderPatchFields(fvMesh& mesh, const labelList& oldToNew) -{ - HashTable flds - ( - mesh.objectRegistry::lookupClass() - ); - - forAllConstIter(typename HashTable, flds, iter) - { - const GeoField& fld = *iter(); - - typename GeoField::GeometricBoundaryField& bfld = - const_cast - ( - fld.boundaryField() - ); - - bfld.reorder(oldToNew); - } -} - - -// Adds patch if not yet there. Returns patchID. -label addPatch(fvMesh& mesh, const polyPatch& patch) -{ - polyBoundaryMesh& polyPatches = - const_cast(mesh.boundaryMesh()); - - label patchI = polyPatches.findPatchID(patch.name()); - if (patchI != -1) - { - if (polyPatches[patchI].type() == patch.type()) - { - // Already there - return patchI; - } - else - { - FatalErrorIn("addPatch(fvMesh&, const polyPatch*)") - << "Already have patch " << patch.name() - << " but of type " << patch.type() - << exit(FatalError); - } - } - - - label insertPatchI = polyPatches.size(); - label startFaceI = mesh.nFaces(); - - forAll(polyPatches, patchI) - { - const polyPatch& pp = polyPatches[patchI]; - - if (isA(pp)) - { - insertPatchI = patchI; - startFaceI = pp.start(); - break; - } - } - - - // Below is all quite a hack. Feel free to change once there is a better - // mechanism to insert and reorder patches. - - // Clear local fields and e.g. polyMesh parallelInfo. - mesh.clearOut(); - - label sz = polyPatches.size(); - - fvBoundaryMesh& fvPatches = const_cast(mesh.boundary()); - - // Add polyPatch at the end - polyPatches.setSize(sz+1); - polyPatches.set - ( - sz, - patch.clone - ( - polyPatches, - insertPatchI, //index - 0, //size - startFaceI //start - ) - ); - fvPatches.setSize(sz+1); - fvPatches.set - ( - sz, - fvPatch::New - ( - polyPatches[sz], // point to newly added polyPatch - mesh.boundary() - ) - ); - - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - - // Surface fields - - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - addPatchFields - ( - mesh, - calculatedFvPatchField::typeName - ); - - // Create reordering list - // patches before insert position stay as is - labelList oldToNew(sz+1); - for (label i = 0; i < insertPatchI; i++) - { - oldToNew[i] = i; - } - // patches after insert position move one up - for (label i = insertPatchI; i < sz; i++) - { - oldToNew[i] = i+1; - } - // appended patch gets moved to insert position - oldToNew[sz] = insertPatchI; - - // Shuffle into place - polyPatches.reorder(oldToNew); - fvPatches.reorder(oldToNew); - - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - - return insertPatchI; -} - - -// Reorder and delete patches. -void reorderPatches -( - fvMesh& mesh, - const labelList& oldToNew, - const label nNewPatches -) -{ - polyBoundaryMesh& polyPatches = - const_cast(mesh.boundaryMesh()); - fvBoundaryMesh& fvPatches = const_cast(mesh.boundary()); - - // Shuffle into place - polyPatches.reorder(oldToNew); - fvPatches.reorder(oldToNew); - - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - reorderPatchFields(mesh, oldToNew); - - // Remove last. - polyPatches.setSize(nNewPatches); - fvPatches.setSize(nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); - trimPatchFields(mesh, nNewPatches); -} - - // Prepend prefix to selected patches. void renamePatches ( @@ -1193,8 +910,8 @@ void createAndWriteRegion } } - reorderPatches(newMesh(), oldToNew, nNewPatches); - + //reorderPatches(newMesh(), oldToNew, nNewPatches); + fvMeshTools::reorderPatches(newMesh(), oldToNew, nNewPatches, true); // Rename shared patches with region name if (prefixRegion) @@ -1360,7 +1077,15 @@ labelList addRegionPatches mesh.boundaryMesh() ); - interfacePatches[interI] = addPatch(mesh, patch1); + //interfacePatches[interI] = addPatch(mesh, patch1); + interfacePatches[interI] = fvMeshTools::addPatch + ( + mesh, + patch1, + dictionary(), //optional per field value + calculatedFvPatchField::typeName, + true //validBoundary + ); mappedWallPolyPatch patch2 ( @@ -1374,7 +1099,15 @@ labelList addRegionPatches point::zero, // offset mesh.boundaryMesh() ); - addPatch(mesh, patch2); + //addPatch(mesh, patch2); + fvMeshTools::addPatch + ( + mesh, + patch2, + dictionary(), //optional per field value + calculatedFvPatchField::typeName, + true //validBoundary + ); Info<< "For interface between region " << regionNames[e[0]] << " and " << regionNames[e[1]] << " added patches" << endl diff --git a/applications/utilities/mesh/manipulation/topoSet/topoSetDict b/applications/utilities/mesh/manipulation/topoSet/topoSetDict index 31fa348e97..00720d2382 100644 --- a/applications/utilities/mesh/manipulation/topoSet/topoSetDict +++ b/applications/utilities/mesh/manipulation/topoSet/topoSetDict @@ -226,6 +226,12 @@ FoamFile // // (regular expressions allowed) // } // +// // All boundary faces +// source boundaryToFace; +// sourceInfo +// { +// } +// // // All faces of faceZone // source zoneToFace; // sourceInfo @@ -359,6 +365,21 @@ FoamFile // cellSet c0; // name of cellSet of slave side // } // +// // Select based on surface. Orientation from normals on surface +// { +// name fz0; +// type faceZoneSet; +// action new; +// source searchableSurfaceToFaceZone; +// sourceInfo +// { +// surface searchableSphere; +// centre (0.05 0.05 0.005); +// radius 0.025; +// } +// } +// +// // // pointZoneSet // ~~~~~~~~~~~~ diff --git a/src/OpenFOAM/db/dictionary/dictionary.C b/src/OpenFOAM/db/dictionary/dictionary.C index 295749ea4c..2a2ae85253 100644 --- a/src/OpenFOAM/db/dictionary/dictionary.C +++ b/src/OpenFOAM/db/dictionary/dictionary.C @@ -424,38 +424,87 @@ const Foam::entry* Foam::dictionary::lookupScopedEntryPtr bool patternMatch ) const { - string::size_type dotPos = keyword.find('.'); - - if (dotPos == string::npos) + if (keyword[0] == ':') { - return lookupEntryPtr(keyword, recursive, patternMatch); + // Go up to top level + const dictionary* dictPtr = this; + while (&dictPtr->parent_ != &dictionary::null) + { + dictPtr = &dictPtr->parent_; + } + + // At top. Recurse to find entries + return dictPtr->lookupScopedEntryPtr + ( + keyword.substr(1, keyword.size()-1), + false, + patternMatch + ); } else { - if (dotPos == 0) - { - const dictionary* dictPtr = this; - while (&dictPtr->parent_ != &dictionary::null) - { - dictPtr = &dictPtr->parent_; - } + string::size_type dotPos = keyword.find('.'); - // At top - return dictPtr->lookupScopedEntryPtr - ( - keyword.substr(1, keyword.size()-1), - false, - patternMatch - ); + if (dotPos == string::npos) + { + // Non-scoped lookup + return lookupEntryPtr(keyword, recursive, patternMatch); } else { - wordList entryNames(fileName(keyword).components('.')); - - const entry* entPtr = lookupEntryPtr(entryNames[0], false, true); - - for (int i=1; iparent_ == &dictionary::null) + { + FatalIOErrorIn + ( + "dictionary::lookupScopedEntryPtr" + "(const word&, bool, bool)", + *this + ) << "No parent of current dictionary" + << " when searching for " + << keyword.substr(begVar, keyword.size()-begVar) + << exit(FatalIOError); + } + dictPtr = &dictPtr->parent_; + } + + return dictPtr->lookupScopedEntryPtr + ( + keyword.substr(endVar), + false, + patternMatch + ); + } + else + { + // Extract the first word + word firstWord = keyword.substr(0, dotPos); + + const entry* entPtr = lookupScopedEntryPtr + ( + firstWord, + false, //recursive + patternMatch + ); + if (!entPtr) { FatalIOErrorIn @@ -463,46 +512,27 @@ const Foam::entry* Foam::dictionary::lookupScopedEntryPtr "dictionary::lookupScopedEntryPtr" "(const word&, bool, bool)", *this - ) << "keyword " << keyword + ) << "keyword " << firstWord << " is undefined in dictionary " << name() << endl << "Valid keywords are " << keys() << exit(FatalIOError); } - if (!entPtr->isDict()) + + if (entPtr->isDict()) { - FatalIOErrorIn + return entPtr->dict().lookupScopedEntryPtr ( - "dictionary::lookupScopedEntryPtr" - "(const word&, bool, bool)", - *this - ) << "Entry " << entPtr->name() - << " is not a dictionary so cannot lookup sub entry " - << entryNames[i] - << exit(FatalIOError); + keyword.substr(dotPos, keyword.size()-dotPos), + false, + patternMatch + ); + } + else + { + return NULL; } - - entPtr = entPtr->dict().lookupEntryPtr - ( - entryNames[i], - false, - true - ); } - - if (!entPtr) - { - FatalIOErrorIn - ( - "dictionary::lookupScopedEntryPtr" - "(const word&, bool, bool)", - *this - ) << "keyword " << keyword - << " is not a valid scoped entry in dictionary " - << name() - << exit(FatalIOError); - } - return entPtr; } } } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C index a54438f105..b4148405cf 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.C @@ -1078,7 +1078,11 @@ void Foam::polyBoundaryMesh::updateMesh() } -void Foam::polyBoundaryMesh::reorder(const labelUList& oldToNew) +void Foam::polyBoundaryMesh::reorder +( + const labelUList& oldToNew, + const bool validBoundary +) { // Change order of patches polyPatchList::reorder(oldToNew); @@ -1091,7 +1095,10 @@ void Foam::polyBoundaryMesh::reorder(const labelUList& oldToNew) patches[patchI].index() = patchI; } - updateMesh(); + if (validBoundary) + { + updateMesh(); + } } diff --git a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H index 34f0a6d409..ad937a86fd 100644 --- a/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H +++ b/src/OpenFOAM/meshes/polyMesh/polyBoundaryMesh/polyBoundaryMesh.H @@ -219,9 +219,10 @@ public: //- Reorders patches. Ordering does not have to be done in // ascending or descending order. Reordering has to be unique. - // (is shuffle) Calls updateMesh() after reordering to recalculate - // data. - void reorder(const labelUList&); + // (is shuffle) If validBoundary calls updateMesh() + // after reordering to recalculate data (so call needs to be parallel + // sync in that case) + void reorder(const labelUList&, const bool validBoundary); //- writeData member function required by regIOobject bool writeData(Ostream&) const; diff --git a/src/dynamicMesh/Make/files b/src/dynamicMesh/Make/files index 21dcc72398..bb0ec3ddef 100644 --- a/src/dynamicMesh/Make/files +++ b/src/dynamicMesh/Make/files @@ -81,6 +81,8 @@ fvMeshDistribute/fvMeshDistribute.C polyMeshAdder/faceCoupleInfo.C polyMeshAdder/polyMeshAdder.C +fvMeshTools/fvMeshTools.C + motionSmoother/motionSmoother.C motionSmoother/motionSmootherCheck.C motionSmoother/polyMeshGeometry/polyMeshGeometry.C diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C index 33058afaf4..7fe993522a 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.C @@ -31,7 +31,6 @@ License #include "processorFvsPatchField.H" #include "processorCyclicPolyPatch.H" #include "processorCyclicFvPatchField.H" -#include "processorCyclicFvsPatchField.H" #include "polyTopoChange.H" #include "removeCells.H" #include "polyModifyFace.H" @@ -40,6 +39,7 @@ License #include "surfaceFields.H" #include "syncTools.H" #include "CompactListList.H" +#include "fvMeshTools.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -274,156 +274,6 @@ Foam::label Foam::fvMeshDistribute::findNonEmptyPatch() const } -//// Appends processorPolyPatch. Returns patchID. -//Foam::label Foam::fvMeshDistribute::addProcPatch -//( -// const word& patchName, -// const label nbrProc -//) -//{ -// // Clear local fields and e.g. polyMesh globalMeshData. -// mesh_.clearOut(); -// -// -// polyBoundaryMesh& polyPatches = -// const_cast(mesh_.boundaryMesh()); -// fvBoundaryMesh& fvPatches = const_cast(mesh_.boundary()); -// -// if (polyPatches.findPatchID(patchName) != -1) -// { -// FatalErrorIn -// ( -// "fvMeshDistribute::addProcPatch(const word&, const label)" -// ) -// << "Cannot create patch " << patchName << " since already exists." -// << nl -// << "Current patch names:" << polyPatches.names() -// << exit(FatalError); -// } -// -// -// -// // Add the patch -// // ~~~~~~~~~~~~~ -// -// label sz = polyPatches.size(); -// -// // Add polyPatch -// polyPatches.setSize(sz+1); -// polyPatches.set -// ( -// sz, -// new processorPolyPatch -// ( -// patchName, -// 0, // size -// mesh_.nFaces(), -// sz, -// mesh_.boundaryMesh(), -// Pstream::myProcNo(), -// nbrProc -// ) -// ); -// fvPatches.setSize(sz+1); -// fvPatches.set -// ( -// sz, -// fvPatch::New -// ( -// polyPatches[sz], // point to newly added polyPatch -// mesh_.boundary() -// ) -// ); -// -// return sz; -//} - - -// Appends polyPatch. Returns patchID. -Foam::label Foam::fvMeshDistribute::addPatch(polyPatch* patchPtr) -{ - // Clear local fields and e.g. polyMesh globalMeshData. - mesh_.clearOut(); - - polyBoundaryMesh& polyPatches = - const_cast(mesh_.boundaryMesh()); - fvBoundaryMesh& fvPatches = const_cast(mesh_.boundary()); - - if (polyPatches.findPatchID(patchPtr->name()) != -1) - { - FatalErrorIn("fvMeshDistribute::addPatch(polyPatch*)") - << "Cannot create patch " << patchPtr->name() - << " since already exists." << nl - << "Current patch names:" << polyPatches.names() - << exit(FatalError); - } - - - // Add the patch - // ~~~~~~~~~~~~~ - - label sz = polyPatches.size(); - - // Add polyPatch - polyPatches.setSize(sz+1); - polyPatches.set(sz, patchPtr); - fvPatches.setSize(sz+1); - fvPatches.set - ( - sz, - fvPatch::New - ( - polyPatches[sz], // point to newly added polyPatch - mesh_.boundary() - ) - ); - - return sz; -} - - -// Deletes last patch -void Foam::fvMeshDistribute::deleteTrailingPatch() -{ - // Clear local fields and e.g. polyMesh globalMeshData. - mesh_.clearOut(); - - polyBoundaryMesh& polyPatches = - const_cast(mesh_.boundaryMesh()); - fvBoundaryMesh& fvPatches = const_cast(mesh_.boundary()); - - if (polyPatches.empty()) - { - FatalErrorIn("fvMeshDistribute::deleteTrailingPatch(fvMesh&)") - << "No patches in mesh" - << abort(FatalError); - } - - label sz = polyPatches.size(); - - label nFaces = polyPatches[sz-1].size(); - - // Remove last polyPatch - if (debug) - { - Pout<< "deleteTrailingPatch : Removing patch " << sz-1 - << " : " << polyPatches[sz-1].name() << " size:" << nFaces << endl; - } - - if (nFaces) - { - FatalErrorIn("fvMeshDistribute::deleteTrailingPatch()") - << "There are still " << nFaces << " faces in patch to be deleted " - << sz-1 << ' ' << polyPatches[sz-1].name() - << abort(FatalError); - } - - // Remove actual patch - polyPatches.setSize(sz-1); - fvPatches.setSize(sz-1); -} - - // Delete all processor patches. Move any processor faces into the last // non-processor patch. Foam::autoPtr Foam::fvMeshDistribute::deleteProcPatches @@ -469,25 +319,28 @@ Foam::autoPtr Foam::fvMeshDistribute::deleteProcPatches // Delete (now empty) processor patches. - forAllReverse(mesh_.boundaryMesh(), patchI) { - const polyPatch& pp = mesh_.boundaryMesh()[patchI]; - - if (isA(pp)) + labelList oldToNew(identity(mesh_.boundaryMesh().size())); + label newI = 0; + // Non processor patches first + forAll(mesh_.boundaryMesh(), patchI) { - deleteTrailingPatch(); - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); - - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); - deleteTrailingPatchFields(); + if (!isA(mesh_.boundaryMesh()[patchI])) + { + oldToNew[patchI] = newI++; + } } + label nNonProcPatches = newI; + + // Processor patches as last + forAll(mesh_.boundaryMesh(), patchI) + { + if (isA(mesh_.boundaryMesh()[patchI])) + { + oldToNew[patchI] = newI++; + } + } + fvMeshTools::reorderPatches(mesh_, oldToNew, nNonProcPatches, false); } return map; @@ -1082,65 +935,28 @@ void Foam::fvMeshDistribute::addProcPatches + "to" + name(procI); + processorPolyPatch pp + ( + patchName, + 0, // size + mesh_.nFaces(), + mesh_.boundaryMesh().size(), + mesh_.boundaryMesh(), + Pstream::myProcNo(), + nbrProc[bFaceI] + ); procPatchID[procI].insert ( referPatchID[bFaceI], - addPatch + fvMeshTools::addPatch ( - new processorPolyPatch - ( - patchName, - 0, // size - mesh_.nFaces(), - mesh_.boundaryMesh().size(), - mesh_.boundaryMesh(), - Pstream::myProcNo(), - nbrProc[bFaceI] - ) + mesh_, + pp, + dictionary(), + processorFvPatchField::typeName, + false // not parallel sync ) ); - - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); - - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); - addPatchFields - ( - processorFvPatchField::typeName - ); } else { @@ -1158,66 +974,29 @@ void Foam::fvMeshDistribute::addProcPatches + "through" + cycName; + processorCyclicPolyPatch pp + ( + patchName, + 0, // size + mesh_.nFaces(), + mesh_.boundaryMesh().size(), + mesh_.boundaryMesh(), + Pstream::myProcNo(), + nbrProc[bFaceI], + cycName + ); procPatchID[procI].insert ( referPatchID[bFaceI], - addPatch + fvMeshTools::addPatch ( - new processorCyclicPolyPatch - ( - patchName, - 0, // size - mesh_.nFaces(), - mesh_.boundaryMesh().size(), - mesh_.boundaryMesh(), - Pstream::myProcNo(), - nbrProc[bFaceI], - cycName - ) + mesh_, + pp, + dictionary(), // optional per field patchField + processorCyclicFvPatchField::typeName, + false // not parallel sync ) ); - - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); - addPatchFields - ( - processorCyclicFvPatchField::typeName - ); } } } @@ -2445,68 +2224,32 @@ Foam::autoPtr Foam::fvMeshDistribute::distribute // parallel comms. After this points and edges should again be consistent. mergeSharedPoints(constructPointMap); -// // Bit of hack: processorFvPatchField does not get reset since created -// // from nothing so explicitly reset. -// initPatchFields > -// ( -// pTraits::zero -// ); -// initPatchFields > -// ( -// pTraits::zero -// ); -// initPatchFields -// < -// volSphericalTensorField, -// processorFvPatchField -// > -// ( -// pTraits::zero -// ); -// initPatchFields > -// ( -// pTraits::zero -// ); -// initPatchFields > -// ( -// pTraits::zero -// ); -// initPatchFields > -// ( -// pTraits::zero -// ); -// initPatchFields > -// ( -// pTraits::zero -// ); -// initPatchFields -// < -// surfaceSphericalTensorField, -// processorFvsPatchField -// > -// ( -// pTraits::zero -// ); -// initPatchFields -// < -// surfaceSymmTensorField, -// processorFvsPatchField -// > -// ( -// pTraits::zero -// ); -// initPatchFields > -// ( -// pTraits::zero -// ); -//XXXXX // Bit of hack: processorFvPatchField does not get reset since created // from nothing so explicitly reset. - correctBoundaryConditions(); - correctBoundaryConditions(); - correctBoundaryConditions(); - correctBoundaryConditions(); - correctBoundaryConditions(); + initPatchFields > + ( + pTraits::zero + ); + initPatchFields > + ( + pTraits::zero + ); + initPatchFields + < + volSphericalTensorField, + processorFvPatchField + > + ( + pTraits::zero + ); + initPatchFields > + ( + pTraits::zero + ); + initPatchFields > + ( + pTraits::zero + ); initPatchFields > ( @@ -2536,7 +2279,7 @@ Foam::autoPtr Foam::fvMeshDistribute::distribute ( pTraits::zero ); -//XXXXX + mesh_.setInstance(mesh_.time().timeName()); diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.H b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.H index eb771003a0..0aa64bf447 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.H +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistribute.H @@ -102,20 +102,6 @@ class fvMeshDistribute //- Find patch to put exposed faces into. label findNonEmptyPatch() const; - //- Appends polyPatch. Returns patchID. - label addPatch(polyPatch*); - - //- Add patch field - template - void addPatchFields(const word& patchFieldType); - - //- Deletes last patch. - void deleteTrailingPatch(); - - // Delete trailing patch fields - template - void deleteTrailingPatchFields(); - //- Save boundary fields template void saveBoundaryFields diff --git a/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C b/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C index 00364a81ad..a09d538083 100644 --- a/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C +++ b/src/dynamicMesh/fvMeshDistribute/fvMeshDistributeTemplates.C @@ -55,65 +55,6 @@ void Foam::fvMeshDistribute::printFieldInfo(const fvMesh& mesh) } -template -void Foam::fvMeshDistribute::addPatchFields(const word& patchFieldType) -{ - HashTable flds - ( - mesh_.objectRegistry::lookupClass() - ); - - forAllConstIter(typename HashTable, flds, iter) - { - const GeoField& fld = *iter(); - - typename GeoField::GeometricBoundaryField& bfld = - const_cast - ( - fld.boundaryField() - ); - - label sz = bfld.size(); - bfld.setSize(sz + 1); - bfld.set - ( - sz, - GeoField::PatchFieldType::New - ( - patchFieldType, - mesh_.boundary()[sz], - fld.dimensionedInternalField() - ) - ); - } -} - - -// Delete trailing patch fields -template -void Foam::fvMeshDistribute::deleteTrailingPatchFields() -{ - HashTable flds - ( - mesh_.objectRegistry::lookupClass() - ); - - forAllConstIter(typename HashTable, flds, iter) - { - const GeoField& fld = *iter(); - - typename GeoField::GeometricBoundaryField& bfld = - const_cast - ( - fld.boundaryField() - ); - - // Shrink patchFields - bfld.setSize(bfld.size() - 1); - } -} - - // Save whole boundary field template void Foam::fvMeshDistribute::saveBoundaryFields diff --git a/src/dynamicMesh/fvMeshTools/fvMeshTools.C b/src/dynamicMesh/fvMeshTools/fvMeshTools.C new file mode 100644 index 0000000000..08d3cdc014 --- /dev/null +++ b/src/dynamicMesh/fvMeshTools/fvMeshTools.C @@ -0,0 +1,351 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2012 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "fvMeshTools.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Adds patch if not yet there. Returns patchID. +Foam::label Foam::fvMeshTools::addPatch +( + fvMesh& mesh, + const polyPatch& patch, + const dictionary& patchFieldDict, + const word& defaultPatchFieldType, + const bool validBoundary +) +{ + polyBoundaryMesh& polyPatches = + const_cast(mesh.boundaryMesh()); + + label patchI = polyPatches.findPatchID(patch.name()); + if (patchI != -1) + { + // Already there + return patchI; + } + + + label insertPatchI = polyPatches.size(); + label startFaceI = mesh.nFaces(); + + forAll(polyPatches, patchI) + { + const polyPatch& pp = polyPatches[patchI]; + + if (isA(pp)) + { + insertPatchI = patchI; + startFaceI = pp.start(); + break; + } + } + + + // Below is all quite a hack. Feel free to change once there is a better + // mechanism to insert and reorder patches. + + // Clear local fields and e.g. polyMesh parallelInfo. + mesh.clearOut(); + + label sz = polyPatches.size(); + + fvBoundaryMesh& fvPatches = const_cast(mesh.boundary()); + + // Add polyPatch at the end + polyPatches.setSize(sz+1); + polyPatches.set + ( + sz, + patch.clone + ( + polyPatches, + insertPatchI, //index + 0, //size + startFaceI //start + ) + ); + fvPatches.setSize(sz+1); + fvPatches.set + ( + sz, + fvPatch::New + ( + polyPatches[sz], // point to newly added polyPatch + mesh.boundary() + ) + ); + + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + + // Surface fields + + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + addPatchFields + ( + mesh, + patchFieldDict, + defaultPatchFieldType, + pTraits::zero + ); + + // Create reordering list + // patches before insert position stay as is + labelList oldToNew(sz+1); + for (label i = 0; i < insertPatchI; i++) + { + oldToNew[i] = i; + } + // patches after insert position move one up + for (label i = insertPatchI; i < sz; i++) + { + oldToNew[i] = i+1; + } + // appended patch gets moved to insert position + oldToNew[sz] = insertPatchI; + + // Shuffle into place + polyPatches.reorder(oldToNew, validBoundary); + fvPatches.reorder(oldToNew); + + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + reorderPatchFields(mesh, oldToNew); + + return insertPatchI; +} + + +void Foam::fvMeshTools::setPatchFields +( + fvMesh& mesh, + const label patchI, + const dictionary& patchFieldDict +) +{ + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields + ( + mesh, + patchI, + patchFieldDict + ); + setPatchFields(mesh, patchI, patchFieldDict); + setPatchFields(mesh, patchI, patchFieldDict); +} + + +void Foam::fvMeshTools::zeroPatchFields(fvMesh& mesh, const label patchI) +{ + setPatchFields(mesh, patchI, pTraits::zero); + setPatchFields(mesh, patchI, pTraits::zero); + setPatchFields + ( + mesh, + patchI, + pTraits::zero + ); + setPatchFields + ( + mesh, + patchI, + pTraits::zero + ); + setPatchFields(mesh, patchI, pTraits::zero); + setPatchFields(mesh, patchI, pTraits::zero); + setPatchFields(mesh, patchI, pTraits::zero); + setPatchFields + ( + mesh, + patchI, + pTraits::zero + ); + setPatchFields + ( + mesh, + patchI, + pTraits::zero + ); + setPatchFields(mesh, patchI, pTraits::zero); +} + + +// Deletes last patch +void Foam::fvMeshTools::trimPatches(fvMesh& mesh, const label nPatches) +{ + // Clear local fields and e.g. polyMesh globalMeshData. + mesh.clearOut(); + + polyBoundaryMesh& polyPatches = + const_cast(mesh.boundaryMesh()); + fvBoundaryMesh& fvPatches = const_cast(mesh.boundary()); + + if (polyPatches.empty()) + { + FatalErrorIn("fvMeshTools::trimPatches(fvMesh&, const label)") + << "No patches in mesh" + << abort(FatalError); + } + + label nFaces = 0; + for (label patchI = nPatches; patchI < polyPatches.size(); patchI++) + { + nFaces += polyPatches[patchI].size(); + } + reduce(nFaces, sumOp