From 8ceec6456a57f93ab76f2e25608be8c07b2a922f Mon Sep 17 00:00:00 2001 From: Mattijs Janssens Date: Thu, 15 Nov 2018 14:58:56 +0000 Subject: [PATCH] Mapping injected faces through interpolation --- README.txt | 47 + src/dynamicFvMesh/Make/files | 1 + src/dynamicFvMesh/Make/options | 3 + .../balanceParDict | 29 + .../dynamicMeshDict | 125 +++ .../dynamicRefineBalancedFvMesh.C | 843 ++++++++++++++++++ .../dynamicRefineBalancedFvMesh.H | 206 +++++ .../dynamicRefineBalancedFvMeshTemplates.C | 217 +++++ .../dynamicRefineFvMesh/dynamicRefineFvMesh.C | 309 ++++--- .../dynamicRefineFvMesh/dynamicRefineFvMesh.H | 44 +- .../dynamicRefineFvMeshTemplates.C | 196 ++++ .../polyTopoChange/hexRef8/hexRef8.C | 2 +- src/finiteVolume/fvMesh/fvMesh.C | 10 + .../constant/dynamicMeshDict | 1 + 14 files changed, 1906 insertions(+), 127 deletions(-) create mode 100644 README.txt create mode 100644 src/dynamicFvMesh/dynamicRefineBalancedFvMesh/balanceParDict create mode 100644 src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicMeshDict create mode 100644 src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicRefineBalancedFvMesh.C create mode 100644 src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicRefineBalancedFvMesh.H create mode 100644 src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicRefineBalancedFvMeshTemplates.C create mode 100644 src/dynamicFvMesh/dynamicRefineFvMesh/dynamicRefineFvMeshTemplates.C diff --git a/README.txt b/README.txt new file mode 100644 index 0000000000..273b4dad20 --- /dev/null +++ b/README.txt @@ -0,0 +1,47 @@ +Notes from merging Integration-TUD-addOns and plus. + +0) +- Changed +dynamicMesh/polyTopoChange/polyTopoChange/hexRef8/hexRef8.C +to created internal faces out-of-nothing. +- Added the mapNewInternalFaces to dynamicRefineFvMesh +- unset FOAM_SETNAN, FOAM_SIGFPE and run + + testCases/testAMRandLoadBalancing/damBreakWithObstacle + +- However when writing V0 we noticed a nan in the V0 field. + (this doesn't get written anymore but it might indicate a bug) + + +1) Tried moving additional mapping of surface fields to + + virtual dynamicRefineFvMesh::mapFields(const mapPolyMesh&); + +so it would get called from the fvMesh::updateMesh. However +this mapping (explicitly) gets done using unadapted addressing +and it causes the cell addressing to be wrong: + + +[1] --> FOAM FATAL ERROR: +[1] index 826015320 out of range 0 ... 71079 +[1] +[1] From function void Foam::UList::checkIndex(Foam::label) const [with T = Foam::cell; Foam::label = int] +[1] in file /home/preston2/mattijs/OpenFOAM/work/OpenFOAM-plus.integration-TUD/src/OpenFOAM/lnInclude/UListI.H at line 106. + + +From dynamicRefineFvMesh::mapNewInternalFaces : (I think) + + cell faceOwner = this->cells()[owner[facei]]; + +So this adaptation should be done in a separate pass + + +2) Mapping new internal faces: +- currently done by averaging the values of 'properly' mapped + faces from owner and neighbour. +- this would not work if a cell gets split into 3x3x3 +- instead this should be done by some geometric interpolation + from point values? +- have selection mechanism instead or use oriented flag on surfaceFields + +3) Current averaging is valid only for internal faces & only scalar/vector diff --git a/src/dynamicFvMesh/Make/files b/src/dynamicFvMesh/Make/files index b8432c07c9..bb04e8ac64 100644 --- a/src/dynamicFvMesh/Make/files +++ b/src/dynamicFvMesh/Make/files @@ -5,6 +5,7 @@ dynamicMotionSolverFvMesh/dynamicMotionSolverFvMesh.C dynamicMultiMotionSolverFvMesh/dynamicMultiMotionSolverFvMesh.C dynamicInkJetFvMesh/dynamicInkJetFvMesh.C dynamicRefineFvMesh/dynamicRefineFvMesh.C +dynamicRefineBalancedFvMesh/dynamicRefineBalancedFvMesh.C dynamicMotionSolverListFvMesh/dynamicMotionSolverListFvMesh.C simplifiedDynamicFvMesh/simplifiedDynamicFvMeshes.C diff --git a/src/dynamicFvMesh/Make/options b/src/dynamicFvMesh/Make/options index 3540c13bfc..718fde7d5c 100644 --- a/src/dynamicFvMesh/Make/options +++ b/src/dynamicFvMesh/Make/options @@ -1,10 +1,13 @@ EXE_INC = \ + -g -DFULLDEBUG -O0 -g \ + -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude LIB_LIBS = \ + -ldecompositionMethods \ -lmeshTools \ -ldynamicMesh \ -lfiniteVolume diff --git a/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/balanceParDict b/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/balanceParDict new file mode 100644 index 0000000000..08d1ef6538 --- /dev/null +++ b/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/balanceParDict @@ -0,0 +1,29 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 2.1.1 | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object balanceParDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +numberOfSubdomains 2; + +method ptscotch; + +constraints +{ + refinementHistory + { + type refinementHistory; + } +} +// ************************************************************************* // diff --git a/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicMeshDict b/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicMeshDict new file mode 100644 index 0000000000..a8df1cb7ef --- /dev/null +++ b/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicMeshDict @@ -0,0 +1,125 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: dev | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object dynamicMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dynamicFvMesh dynamicRefineBalancedFvMesh; + +refinementControls +{ + enableRefinementControl true; + + fields // must be scalarFields + ( + //alpha (min max refineLevel) + alpha (0.01 0.99 2) // refine cells where alpha in [0.01:0.99] with maximal 2 refinement layers + ); + + interface // must be a scalarField (only one dictionary!) + ( + alpha // refine interface (found based on snGrad of alpha > 0.1) + { + innerRefLayers 2; // describes how many cell layers inside phase alpha are to be refined + outerRefLayers 5; // describes how many cell layers outside phase alpha are to be refined + + // optional settings: + maxRefineLevel 4; // max refinement layers; Default: maxRefinement from dynamicRefineFvMeshCoeffs is used + // to get slower than 2:1 refinement; add #nAddLayers between each refinement level at the interface + nAddLayers 1; //Default: 0 + } + ); + + gradients // must be scalars + ( + // arguments as in 'fields' + // min/max values are based on mag(fvc::grad(volScalarField)) * cellVolume + T (0.01 10 1) + ); + + curls // must be vectors + ( + // arguments as in 'fields' + // min/max values are based on mag(fvc::curl(volVectorField)) + U (0.5 1 2) + ); + + regions + ( + boxToCell + { + minLevel 1; + + box (-1 0.001 0.002)(1 0.005 0.003); + } + + ); +} + +dynamicRefineFvMeshCoeffs +{ + // Extra entries for balancing + enableBalancing true; + allowableImbalance 0.15; + + // How often to refine + refineInterval 10; + + // Field to be refinement on (set it to 'internalRefinementField' to use the + // refinementControls dictionary entries above) + field internalRefinementField; + + // Refine field inbetween lower..upper + lowerRefineLevel 0.5; // do not change + upperRefineLevel 3.5; // maxRefinement+0.5 + + // If value < unrefineLevel unrefine + unrefineLevel -0.5; // do not change + + // Have slower than 2:1 refinement + nBufferLayers 4; + + // Refine cells only up to maxRefinement levels + maxRefinement 3; + + // Stop refinement if maxCells reached + maxCells 200000; + + // Flux field and corresponding velocity field. Fluxes on changed + // faces get recalculated by interpolating the velocity. Use 'none' + // on surfaceScalarFields that do not need to be reinterpolated. + correctFluxes + ( + (phi Urel) + (phiAbs U) + (phiAbs_0 U_0) + (nHatf none) + (rho*phi none) + (ghf none) + ); + + // List of non-flux surfaceFields to be mapped + // only for new internal faces (AMR refine) + mapSurfaceFields + ( + Uf + Uf_0 + ); + + // Write the refinement level as a volScalarField + dumpLevel true; +} + + +// ************************************************************************* // diff --git a/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicRefineBalancedFvMesh.C b/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicRefineBalancedFvMesh.C new file mode 100644 index 0000000000..d5098ffe68 --- /dev/null +++ b/src/dynamicFvMesh/dynamicRefineBalancedFvMesh/dynamicRefineBalancedFvMesh.C @@ -0,0 +1,843 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2014 Tyler Voskuilen + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is a derivative work 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 "dynamicRefineBalancedFvMesh.H" +#include "addToRunTimeSelectionTable.H" +#include "surfaceInterpolate.H" +#include "volFields.H" +#include "polyTopoChange.H" +#include "surfaceFields.H" +#include "syncTools.H" +#include "pointFields.H" +#include "fvCFD.H" +#include "volPointInterpolation.H" +#include "pointMesh.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ + defineTypeNameAndDebug(dynamicRefineBalancedFvMesh, 0); + addToRunTimeSelectionTable(dynamicFvMesh, dynamicRefineBalancedFvMesh, IOobject); +} + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // +Foam::label Foam::dynamicRefineBalancedFvMesh::topParentID(label p) +{ + label nextP = meshCutter().history().splitCells()[p].parent_; + if( nextP < 0 ) + { + return p; + } + else + { + return topParentID(nextP); + } +} + +Foam::List Foam::dynamicRefineBalancedFvMesh::readRefinementPoints() +{ + dictionary refineDict + ( + IOdictionary + ( + IOobject + ( + "dynamicMeshDict", + time().constant(), + *this, + IOobject::MUST_READ_IF_MODIFIED, + IOobject::NO_WRITE, + false + ) + ).subDict("dynamicRefineFvMeshCoeffs") + ); + + List refData(4, scalar(0)); + + refData[0] = readScalar(refineDict.lookup("unrefineLevel")); + refData[1] = readScalar(refineDict.lookup("lowerRefineLevel")); + refData[2] = readScalar(refineDict.lookup("refineInterval")); + refData[3] = readScalar(refineDict.lookup("maxRefinement")); + + return refData; +} + +void Foam::dynamicRefineBalancedFvMesh::updateRefinementField() +{ + Info<< "Calculating internal refinement field" << endl; + + volScalarField& intRefFld = *internalRefinementFieldPtr_; + volScalarField& targetFld = *targetLevelPtr_; + volScalarField& currFld = *isLevelPtr_; + + // Set the internal refinement field to zero to start with + intRefFld = dimensionedScalar("zero",dimless,0.0); + + // Get the cell level field from dynamicRefineFvMesh + const labelList& cellLevel = meshCutter().cellLevel(); + + // Read the points at which refinement and unrefinement occur from the + // dynamicMeshDict entries + List refinePoints = readRefinementPoints(); + + // init list for refine/unrefine field (-1=unrefine, 1=refine, 0=do nothing) + labelList markRefineCells (this->nCells(), 0); + + // init list for target refinement level per cell + labelList targetLevel (this->nCells(), 0); + + // First fields + List fieldNames = fields_.toc(); + Field refFld(nCells(),0.0); + + forAll(fieldNames, i) + { + word fldName = fieldNames[i]; + scalar minValue = fields_[fldName][0]; + scalar maxValue = fields_[fldName][1]; + label refineLevel = static_cast