From b4f78778d2c2786d38915f29c6e4642205a8644c Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 13 Oct 2015 16:20:40 +0100 Subject: [PATCH] ENH: fvMeshAdd: support dimensionedFields --- src/dynamicMesh/fvMeshAdder/fvMeshAdder.C | 18 ++- src/dynamicMesh/fvMeshAdder/fvMeshAdder.H | 28 ++++- .../fvMeshAdder/fvMeshAdderTemplates.C | 105 +++++++++++++++++- 3 files changed, 144 insertions(+), 7 deletions(-) diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C index 915173a142..6e1febbcd9 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.C @@ -2,8 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation - \\/ M anipulation | + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,6 +28,14 @@ License #include "faceCoupleInfo.H" #include "fvMesh.H" +/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */ + +namespace Foam +{ +defineTypeNameAndDebug(fvMeshAdder, 0); +} + + // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // //- Calculate map from new patch faces to old patch faces. -1 where @@ -108,6 +116,12 @@ Foam::autoPtr Foam::fvMeshAdder::add fvMeshAdder::MapSurfaceFields(mapPtr, mesh0, mesh1); fvMeshAdder::MapSurfaceFields(mapPtr, mesh0, mesh1); + fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); + fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); + fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); + fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); + fvMeshAdder::MapDimFields(mapPtr, mesh0, mesh1); + return mapPtr; } diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H index cc4240c77e..ccd869296c 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdder.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,7 +26,7 @@ Class Description Adds two fvMeshes without using any polyMesh morphing. - Uses fvMeshAdder. + Uses polyMeshAdder. SourceFiles fvMeshAdder.C @@ -42,6 +42,7 @@ SourceFiles #include "fvPatchFieldsFwd.H" #include "fvsPatchFieldsFwd.H" #include "fvPatchFieldMapper.H" +#include "DimensionedField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -101,8 +102,22 @@ private: const GeometricField& fldToAdd ); + //- Update single dimensionedField. + template + static void MapDimField + ( + const mapAddedPolyMesh& meshMap, + + DimensionedField& fld, + const DimensionedField& fldToAdd + ); + public: + // Declare name of the class and its debug switch + ClassName("fvMeshAdder"); + + // Member Functions //- Inplace add mesh to fvMesh. Maps all stored fields. Returns map. @@ -131,6 +146,15 @@ public: const fvMesh& mesh, const fvMesh& meshToAdd ); + + //- Map all DimensionedFields of Type + template + static void MapDimFields + ( + const mapAddedPolyMesh&, + const fvMesh& mesh, + const fvMesh& meshToAdd + ); }; diff --git a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C index 296bb3c513..41ae1918cb 100644 --- a/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C +++ b/src/dynamicMesh/fvMeshAdder/fvMeshAdderTemplates.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -280,6 +280,12 @@ void Foam::fvMeshAdder::MapVolFields ++fieldIter ) { + if (debug) + { + Pout<< "MapVolFields : Storing old time for " << fieldIter()->name() + << endl; + } + const_cast*>(fieldIter()) ->storeOldTimes(); } @@ -304,6 +310,12 @@ void Foam::fvMeshAdder::MapVolFields const GeometricField& fldToAdd = *fieldsToAdd[fld.name()]; + if (debug) + { + Pout<< "MapVolFields : mapping " << fld.name() + << " and " << fldToAdd.name() << endl; + } + MapVolField(meshMap, fld, fldToAdd); } else @@ -585,8 +597,13 @@ void Foam::fvMeshAdder::MapSurfaceFields ++fieldIter ) { - const_cast(fieldIter()) - ->storeOldTimes(); + if (debug) + { + Pout<< "MapSurfaceFields : Storing old time for " + << fieldIter()->name() << endl; + } + + const_cast(fieldIter())->storeOldTimes(); } @@ -604,6 +621,12 @@ void Foam::fvMeshAdder::MapSurfaceFields { const fldType& fldToAdd = *fieldsToAdd[fld.name()]; + if (debug) + { + Pout<< "MapSurfaceFields : mapping " << fld.name() + << " and " << fldToAdd.name() << endl; + } + MapSurfaceField(meshMap, fld, fldToAdd); } else @@ -617,4 +640,80 @@ void Foam::fvMeshAdder::MapSurfaceFields } +template +void Foam::fvMeshAdder::MapDimField +( + const mapAddedPolyMesh& meshMap, + + DimensionedField& fld, + const DimensionedField& fldToAdd +) +{ + const fvMesh& mesh = fld.mesh(); + + // Store old field + Field oldField(fld); + + fld.setSize(mesh.nCells()); + + fld.rmap(oldField, meshMap.oldCellMap()); + fld.rmap(fldToAdd, meshMap.addedCellMap()); +} + + +template +void Foam::fvMeshAdder::MapDimFields +( + const mapAddedPolyMesh& meshMap, + const fvMesh& mesh, + const fvMesh& meshToAdd +) +{ + typedef DimensionedField fldType; + + // Note: use strict flag on lookupClass to avoid picking up + // volFields + HashTable fields + ( + mesh.objectRegistry::lookupClass(true) + ); + + HashTable fieldsToAdd + ( + meshToAdd.objectRegistry::lookupClass(true) + ); + + for + ( + typename HashTable:: + iterator fieldIter = fields.begin(); + fieldIter != fields.end(); + ++fieldIter + ) + { + fldType& fld = const_cast(*fieldIter()); + + if (fieldsToAdd.found(fld.name())) + { + const fldType& fldToAdd = *fieldsToAdd[fld.name()]; + + if (debug) + { + Pout<< "MapDimFields : mapping " << fld.name() + << " and " << fldToAdd.name() << endl; + } + + MapDimField(meshMap, fld, fldToAdd); + } + else + { + WarningIn("fvMeshAdder::MapDimFields(..)") + << "Not mapping field " << fld.name() + << " since not present on mesh to add" + << endl; + } + } +} + + // ************************************************************************* //