From 52418e859bfa0f3324e7d91200a6ba70a458a796 Mon Sep 17 00:00:00 2001 From: mattijs Date: Fri, 23 Nov 2012 15:14:03 +0000 Subject: [PATCH 01/29] STYLE: addPatchCellLayer: improved comment --- .../polyTopoChange/polyTopoChange/addPatchCellLayer.H | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H b/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H index bc3624548e..9e8269df93 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H +++ b/src/dynamicMesh/polyTopoChange/polyTopoChange/addPatchCellLayer.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -66,8 +66,8 @@ Description - added faces get same patchID as face they are extruded from - - 'side' faces (i.e. on the edge of pp) get the patchID of the - other patch they are connected to. + - 'side' faces (i.e. on the edge of pp) get the patchID/zoneID of the + other patch/zone they are connected to (hopefully only 1) E.g. 3 boundary faces on patches a,b. b gets extruded, a doesn't. From c93a2a2ac41abad810a09da4a4b6240b1df01390 Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 29 Nov 2012 15:41:38 +0000 Subject: [PATCH 02/29] ENH: fvMeshTools: utility functions for fvPatch, fvMesh --- src/dynamicMesh/Make/files | 2 + src/dynamicMesh/fvMeshTools/fvMeshTools.C | 351 ++++++++++++++++++ src/dynamicMesh/fvMeshTools/fvMeshTools.H | 142 +++++++ .../fvMeshTools/fvMeshToolsTemplates.C | 208 +++++++++++ 4 files changed, 703 insertions(+) create mode 100644 src/dynamicMesh/fvMeshTools/fvMeshTools.C create mode 100644 src/dynamicMesh/fvMeshTools/fvMeshTools.H create mode 100644 src/dynamicMesh/fvMeshTools/fvMeshToolsTemplates.C 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/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