ENH: interFoam: added mesh motion. Fixes #2395.

This commit is contained in:
mattijs
2022-03-07 15:24:34 +00:00
parent 83628e9298
commit fcd5373a7f
23 changed files with 806 additions and 10 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenFOAM Foundation
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) 2019-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -139,6 +139,22 @@ Foam::dynamicMotionSolverListFvMesh::~dynamicMotionSolverListFvMesh()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::dynamicMotionSolverListFvMesh::mapFields
(
const mapPolyMesh& mpm
)
{
dynamicFvMesh::mapFields(mpm);
// Update the motionSolvers for any topo change ...
for (auto& ms : motionSolvers_)
{
ms.updateMesh(mpm);
}
}
bool Foam::dynamicMotionSolverListFvMesh::update()
{
if (motionSolvers_.size())

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020,2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -99,8 +99,11 @@ public:
//- Initialise all non-demand-driven data
virtual bool init(const bool doInit);
//- Dummy update function which does not change the mesh
//- Update the mesh for both mesh motion and topology change
virtual bool update();
//- Map all fields in time using given map. Triggered by topo change
virtual void mapFields(const mapPolyMesh& mpm);
};

View File

@ -196,7 +196,63 @@ void Foam::dynamicRefineFvMesh::readDict()
void Foam::dynamicRefineFvMesh::mapFields(const mapPolyMesh& mpm)
{
dynamicFvMesh::mapFields(mpm);
//dynamicFvMesh::mapFields(mpm);
dynamicMotionSolverListFvMesh::mapFields(mpm);
// Correct old-time volumes for refined/unrefined cells. We know at this
// point that the points have not moved and the cells have only been split
// or merged. We hope that dynamicMotionSolverListFvMesh::mapFields
// does not use old-time volumes ...
{
const labelList& cellMap = mpm.cellMap();
const labelList& reverseCellMap = mpm.reverseCellMap();
// Each split cell becomes original + 7 additional
labelList nSubCells(mpm.nOldCells(), 0);
forAll(cellMap, celli)
{
const label oldCelli = cellMap[celli];
if (oldCelli >= 0 && reverseCellMap[oldCelli] >= 0)
{
// Found master cell.
nSubCells[oldCelli]++;
}
}
// Start off from mapped old volumes
scalarField correctedV0(this->V0());
// Correct any split cells
const auto& V = this->V();
forAll(cellMap, celli)
{
const label oldCelli = cellMap[celli];
if (oldCelli >= 0 && nSubCells[oldCelli] == 8)
{
// Found split cell. Use current volume instead of mapped
// old one
correctedV0[celli] = V[celli];
}
}
const auto& cellsFromCells = mpm.cellsFromCellsMap();
for (const auto& s : cellsFromCells)
{
// Reset unsplit cell
const label celli = s.index();
correctedV0[celli] = V[celli];
//? Or sum up old volumes?
//const labelList& oldCells = s.masterObjects();
//for (const label oldCelli : oldCells)
//{
//}
}
setV0().field() = correctedV0;
}
// Correct the flux for modified/added faces. All the faces which only
// have been renumbered will already have been handled by the mapping.
@ -1027,7 +1083,8 @@ Foam::dynamicRefineFvMesh::dynamicRefineFvMesh
const bool doInit
)
:
dynamicFvMesh(io, doInit),
//dynamicFvMesh(io, doInit),
dynamicMotionSolverListFvMesh(io, doInit),
meshCutter_(*this)
{
if (doInit)
@ -1041,7 +1098,8 @@ bool Foam::dynamicRefineFvMesh::init(const bool doInit)
{
if (doInit)
{
dynamicFvMesh::init(doInit);
//dynamicFvMesh::init(doInit);
dynamicMotionSolverListFvMesh::init(doInit);
}
protectedCell_.setSize(nCells());
@ -1208,7 +1266,7 @@ bool Foam::dynamicRefineFvMesh::init(const bool doInit)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::dynamicRefineFvMesh::update()
bool Foam::dynamicRefineFvMesh::updateTopology()
{
// Re-read dictionary. Chosen since usually -small so trivial amount
// of time compared to actual refinement. Also very useful to be able
@ -1413,6 +1471,15 @@ bool Foam::dynamicRefineFvMesh::update()
}
bool Foam::dynamicRefineFvMesh::update()
{
bool hasChanged = updateTopology();
hasChanged = dynamicMotionSolverListFvMesh::update() && hasChanged;
return hasChanged;
}
bool Foam::dynamicRefineFvMesh::writeObject
(
IOstreamOption streamOpt,
@ -1424,7 +1491,8 @@ bool Foam::dynamicRefineFvMesh::writeObject
bool writeOk =
(
dynamicFvMesh::writeObject(streamOpt, valid)
//dynamicFvMesh::writeObject(streamOpt, valid)
dynamicMotionSolverListFvMesh::writeObject(streamOpt, valid)
&& meshCutter_.write(valid)
);

View File

@ -75,7 +75,8 @@ SourceFiles
#ifndef dynamicRefineFvMesh_H
#define dynamicRefineFvMesh_H
#include "dynamicFvMesh.H"
//#include "dynamicFvMesh.H"
#include "dynamicMotionSolverListFvMesh.H"
#include "hexRef8.H"
#include "bitSet.H"
@ -90,7 +91,8 @@ namespace Foam
class dynamicRefineFvMesh
:
public dynamicFvMesh
//public dynamicFvMesh
public dynamicMotionSolverListFvMesh
{
protected:
@ -210,6 +212,9 @@ protected:
const labelList& faceMap
);
//- Update topology (refinement, unrefinement)
bool updateTopology();
private:

View File

@ -0,0 +1,37 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volVectorField;
object U;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -1 0 0 0 0];
internalField uniform (0 0 0);
boundaryField
{
atmosphere
{
type pressureInletOutletVelocity;
value uniform (0 0 0);
}
"(obstacle|walls)"
{
type movingWallVelocity;
value uniform (0 0 0);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,42 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object alpha.water;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 0 0 0 0 0 0];
internalField uniform 0;
boundaryField
{
walls
{
type zeroGradient;
}
obstacle
{
type zeroGradient;
}
atmosphere
{
type inletOutlet;
inletValue uniform 0;
value uniform 0;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,38 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object nut;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 2 -1 0 0 0 0];
internalField uniform 5e-07;
boundaryField
{
atmosphere
{
type zeroGradient;
}
"(obstacle|walls)"
{
type nutkRoughWallFunction;
Ks uniform 100e-6;
Cs uniform 0.5;
value $internalField;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,45 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class volScalarField;
object p_rgh;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [1 -1 -2 0 0 0 0];
internalField uniform 0;
boundaryField
{
walls
{
type fixedFluxPressure;
phi phiAbs;
value uniform 0;
}
obstacle
{
type fixedFluxPressure;
phi phiAbs;
value uniform 0;
}
atmosphere
{
type totalPressure;
p0 uniform 0;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,8 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
#------------------------------------------------------------------------------
cleanCase0
#------------------------------------------------------------------------------

View File

@ -0,0 +1,13 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
./Allrun.pre
#runApplication $(getApplication)
runApplication decomposePar
runParallel $(getApplication)
#------------------------------------------------------------------------------

View File

@ -0,0 +1,12 @@
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/bin/tools/RunFunctions # Tutorial run functions
#------------------------------------------------------------------------------
restore0Dir
runApplication blockMesh
runApplication setFields
#------------------------------------------------------------------------------

View File

@ -0,0 +1,6 @@
(
(0 ((0 0 0) (0 0 0)))
//(1 ((1 1 0) (0 0 0)))
(10 ((1 1 0) (0 0 0)))
//(100 ((0 0 0) (0 0 0)))
)

View File

@ -0,0 +1,73 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object dynamicMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dynamicFvMesh dynamicRefineFvMesh;
solvers
{
VF
{
motionSolverLibs (fvMotionSolvers);
motionSolver solidBody;
solidBodyMotionFunction oscillatingLinearMotion;
amplitude (0.1 0 0);
omega #eval "2*pi()";
}
}
// How often to refine
refineInterval 1;
// Field to be refinement on
field alpha.water;
// Refine field inbetween lower..upper
lowerRefineLevel 0.001;
upperRefineLevel 0.999;
// If value < unrefineLevel unrefine
unrefineLevel 10;
// Have slower than 2:1 refinement
nBufferLayers 1;
// Refine cells only up to maxRefinement levels
maxRefinement 2;
// 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 none)
(nHatf none)
(rhoPhi none)
(alphaPhi0.water none)
(ghf none)
(alphaPhiUn none)
);
// Write the refinement level as a volScalarField
dumpLevel true;
// ************************************************************************* //

View File

@ -0,0 +1,21 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class uniformDimensionedVectorField;
object g;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
dimensions [0 1 -2 0 0 0 0];
value (0 -9.81 0);
// ************************************************************************* //

View File

@ -0,0 +1,36 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
phases (water air);
water
{
transportModel Newtonian;
nu 1e-06;
rho 1000;
}
air
{
transportModel Newtonian;
nu 1.48e-05;
rho 1;
}
sigma 0.07;
// ************************************************************************* //

View File

@ -0,0 +1,20 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object turbulenceProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
simulationType laminar;
// ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
scale 1;
vertices
(
(0 0 0)
(1 0 0)
(1 1 0)
(0 1 0)
(0 0 1)
(1 0 1)
(1 1 1)
(0 1 1)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (10 10 10) simpleGrading (1 1 1)
);
edges
(
);
boundary
(
atmosphere
{
type patch;
faces
(
(3 7 6 2)
);
}
walls
{
type wall;
faces
(
(0 4 7 3)
(2 6 5 1)
(1 5 4 0)
(0 3 2 1)
(4 5 6 7)
);
}
);
// ************************************************************************* //

View File

@ -0,0 +1,57 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application interFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 1;
deltaT 0.00001;
writeControl adjustable;
writeInterval 0.02;
//writeControl timeStep;
//writeInterval 1;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable yes;
adjustTimeStep yes;
maxCo 0.1;
maxAlphaCo 0.1;
maxDeltaT 1;
// ************************************************************************* //

View File

@ -0,0 +1,22 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
numberOfSubdomains 6;
method scotch;
// ************************************************************************* //

View File

@ -0,0 +1,58 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSchemes;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
ddtSchemes
{
default Euler;
}
gradSchemes
{
default Gauss linear;
}
divSchemes
{
div(rhoPhi,U) Gauss upwind;
div(phi,alpha) Gauss vanLeer;
div(phirb,alpha) Gauss linear;
div(phi,k) Gauss upwind;
div(phi,omega) Gauss upwind;
div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear;
}
laplacianSchemes
{
default Gauss linear corrected;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default corrected;
}
wallDist
{
method meshWave;
}
// ************************************************************************* //

View File

@ -0,0 +1,78 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
solvers
{
"alpha.water.*"
{
nAlphaCorr 1;
nAlphaSubCycles 3;
cAlpha 1;
}
p_rgh
{
solver GAMG;
tolerance 1e-10;
relTol 0.01;
smoother DIC;
}
p_rghFinal
{
$p_rgh;
relTol 0;
}
"pcorr.*"
{
$p_rghFinal;
tolerance 1e-10;
}
"(U|UFinal)"
{
solver smoothSolver;
smoother GaussSeidel;
tolerance 1e-08;
relTol 0;
nSweeps 1;
}
"(k|omega|B|nuTilda).*"
{
solver smoothSolver;
smoother symGaussSeidel;
tolerance 1e-08;
relTol 0;
}
}
PIMPLE
{
//- Solid body motion - no cell volume change
//correctPhi false;
momentumPredictor yes;
nCorrectors 3;
nNonOrthogonalCorrectors 0;
pRefPoint (0.51 0.51 0.51);
pRefValue 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,35 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object setFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
defaultFieldValues
(
volScalarFieldValue alpha.water 0
);
regions
(
boxToCell
{
box (0 0 0) (1.0 0.2 1.0);
fieldValues
(
volScalarFieldValue alpha.water 1
);
}
);
// ************************************************************************* //

View File

@ -0,0 +1,39 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2112 |
| \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object topoSetDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
actions
(
{
name c0;
type cellSet;
action clear;
}
{
name c0;
type cellSet;
action invert;
}
{
name c0;
type cellSet;
action subtract;
source boxToCell;
box (0.8 0 0.8) (1.0 0.2 1.0);
}
);
// ************************************************************************* //