ENH: fieldMapping: new test app

This commit is contained in:
mattijs 2013-09-18 17:24:57 +01:00
parent 5612b439bc
commit 9a534cf76d
12 changed files with 1087 additions and 0 deletions

View File

@ -0,0 +1,7 @@
/*
fvMeshGeometry.C
fvMesh.C
*/
Test-fieldMapping.C
EXE = $(FOAM_USER_APPBIN)/Test-fieldMapping

View File

@ -0,0 +1,9 @@
EXE_INC = \
-DFULLDEBUG -g -O0 \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/dynamicMesh/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-ldynamicMesh

View File

@ -0,0 +1,8 @@
Test application for volField and surfaceField mapping with topology
changes.
Run
pipe1D/Allrun
to compile and map a few fields

View File

@ -0,0 +1,334 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 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 <http://www.gnu.org/licenses/>.
Application
Test-fieldMapping
Description
Test app for mapping of fields.
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "fvMesh.H"
#include "volFields.H"
#include "Time.H"
#include "OFstream.H"
#include "meshTools.H"
#include "removeFaces.H"
#include "mapPolyMesh.H"
#include "polyTopoChange.H"
#include "fvcDiv.H"
#include "Random.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
bool notEqual(const scalar s1, const scalar s2, const scalar tol)
{
return mag(s1-s2) > tol;
}
// Main program:
int main(int argc, char *argv[])
{
# include "addTimeOptions.H"
argList::validArgs.append("inflate (true|false)");
# include "setRootCase.H"
# include "createTime.H"
# include "createMesh.H"
const Switch inflate(args.args()[1]);
if (inflate)
{
Info<< "Deleting cells using inflation/deflation" << nl << endl;
}
else
{
Info<< "Deleting cells, introducing points at new position" << nl
<< endl;
}
Random rndGen(0);
// Test mapping
// ------------
// Mapping is volume averaged
// 1. uniform field stays uniform
volScalarField one
(
IOobject
(
"one",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("one", dimless, 1.0),
zeroGradientFvPatchScalarField::typeName
);
Info<< "Writing one field "
<< one.name() << " in " << runTime.timeName() << endl;
one.write();
// 2. linear profile gets preserved
volScalarField ccX
(
IOobject
(
"ccX",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh.C().component(0)
);
Info<< "Writing x component of cell centres to "
<< ccX.name()
<< " in " << runTime.timeName() << endl;
ccX.write();
// Uniform surface field
surfaceScalarField surfaceOne
(
IOobject
(
"surfaceOne",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar("one", dimless, 1.0),
calculatedFvsPatchScalarField::typeName
);
Info<< "Writing surface one field "
<< surfaceOne.name() << " in " << runTime.timeName() << endl;
surfaceOne.write();
// Force allocation of V. Important for any mesh changes since otherwise
// old time volumes cannot
const scalar totalVol = gSum(mesh.V());
// Face removal engine. No checking for not merging boundary faces.
removeFaces faceRemover(mesh, GREAT);
while (runTime.loop())
{
Info<< "Time = " << runTime.timeName() << nl << endl;
if (!mesh.nInternalFaces())
{
break;
}
// Remove face
label candidateFaceI = rndGen.integer(0, mesh.nInternalFaces()-1);
Info<< "Wanting to delete face " << mesh.faceCentres()[candidateFaceI]
<< endl;
labelList candidates(1, candidateFaceI);
// Get compatible set of faces and connected sets of cells.
labelList cellRegion;
labelList cellRegionMaster;
labelList facesToRemove;
faceRemover.compatibleRemoves
(
candidates,
cellRegion,
cellRegionMaster,
facesToRemove
);
// Topo changes container
polyTopoChange meshMod(mesh);
// Insert mesh refinement into polyTopoChange.
faceRemover.setRefinement
(
facesToRemove,
cellRegion,
cellRegionMaster,
meshMod
);
// Change mesh and inflate
Info<< "Actually changing mesh" << endl;
autoPtr<mapPolyMesh> morphMap = meshMod.changeMesh(mesh, inflate);
Info<< "Mapping fields" << endl;
mesh.updateMesh(morphMap);
// Move mesh (since morphing does not do this)
if (morphMap().hasMotionPoints())
{
Info<< "Moving mesh" << endl;
mesh.movePoints(morphMap().preMotionPoints());
}
// Update numbering of cells/vertices.
faceRemover.updateMesh(morphMap);
Info<< "Writing fields" << endl;
runTime.write();
// Check mesh volume conservation
if (mesh.moving())
{
#include "volContinuity.H"
}
else
{
if (mesh.V().size() != mesh.nCells())
{
FatalErrorIn(args.executable())
<< "Volume not mapped. V:" << mesh.V().size()
<< " nCells:" << mesh.nCells()
<< exit(FatalError);
}
const scalar newVol = gSum(mesh.V());
Info<< "Initial volume = " << totalVol
<< " New volume = " << newVol
<< endl;
if (mag(newVol-totalVol)/totalVol > 1e-10)
{
FatalErrorIn(args.executable())
<< "Volume loss: old volume:" << totalVol
<< " new volume:" << newVol
<< exit(FatalError);
}
else
{
Info<< "Volume check OK" << endl;
}
}
// Check constant profile
{
const scalar max = gMax(one);
const scalar min = gMin(one);
Info<< "Uniform one field min = " << min
<< " max = " << max << endl;
if (notEqual(max, 1.0, 1e-10) || notEqual(min, 1.0, 1e-10))
{
FatalErrorIn(args.executable())
<< "Uniform volVectorField not preserved."
<< " Min and max should both be 1.0. min:" << min
<< " max:" << max
<< exit(FatalError);
}
else
{
Info<< "Uniform field mapping check OK" << endl;
}
}
// Check linear profile
{
const scalarField diff = ccX-mesh.C().component(0);
const scalar max = gMax(diff);
const scalar min = gMin(diff);
Info<< "Linear profile field min = " << min
<< " max = " << max << endl;
if (notEqual(max, 0.0, 1e-10) || notEqual(min, 0.0, 1e-10))
{
FatalErrorIn(args.executable())
<< "Uniform field not preserved."
<< " Min and max should both be 0.0. min:" << min
<< " max:" << max
<< exit(FatalError);
}
else
{
Info<< "Linear profile mapping check OK" << endl;
}
}
// Check face field mapping
if (surfaceOne.size())
{
const scalar max = gMax(surfaceOne.internalField());
const scalar min = gMin(surfaceOne.internalField());
Info<< "Uniform surface field min = " << min
<< " max = " << max << endl;
if (notEqual(max, 1.0, 1e-10) || notEqual(min, 1.0, 1e-10))
{
FatalErrorIn(args.executable())
<< "Uniform surfaceScalarField not preserved."
<< " Min and max should both be 1.0. min:" << min
<< " max:" << max
<< exit(FatalError);
}
else
{
Info<< "Uniform surfaceScalarField mapping check OK" << endl;
}
}
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
<< nl << endl;
}
Info<< "End\n" << endl;
return 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,23 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions
# Get application name
application=Test-fieldMapping
# Compile
wmake ..
runApplication blockMesh
# Run with inflation
runApplication $application true
mv "log.$application" "log.$application-inflate"
# Run without inflation
runApplication $application true
# ----------------------------------------------------------------- end-of-file

View File

@ -0,0 +1,424 @@
/*--------------------------------*- 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 labelList;
location "constant";
object cellDecomposition;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
400
(
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
)
// ************************************************************************* //

View File

@ -0,0 +1,61 @@
/*--------------------------------*- 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;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
convertToMeters 1;
vertices
(
(0 0 0)
(1 0 0)
(1 0.1 0)
(0 0.1 0)
(0 0 0.1)
(1 0 0.1)
(1 0.1 0.1)
(0 0.1 0.1)
);
blocks
(
hex (0 1 2 3 4 5 6 7) (20 1 1) simpleGrading (10 1 1)
);
edges
(
);
boundary
(
inlet
{
type patch;
faces
(
(0 4 7 3)
);
}
outlet
{
type patch;
faces
(
(2 6 5 1)
);
}
);
// ************************************************************************* //

View File

@ -0,0 +1,41 @@
/*--------------------------------*- 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 polyBoundaryMesh;
location "constant/polyMesh";
object boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
3
(
inlet
{
type patch;
nFaces 1;
startFace 19;
}
outlet
{
type patch;
nFaces 1;
startFace 20;
}
defaultFaces
{
type empty;
inGroups 1(empty);
nFaces 80;
startFace 21;
}
)
// ************************************************************************* //

View File

@ -0,0 +1,21 @@
/*--------------------------------*- 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 transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
nu nu [ 0 2 -1 0 0 0 0 ] 0.01;
// ************************************************************************* //

View File

@ -0,0 +1,56 @@
/*--------------------------------*- 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 "system";
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
DebugSwitches
{
// primitiveMesh 1;
// polyMesh 1;
// fvMesh 1;
}
application Test-fieldMapping;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 100;
deltaT 1;
writeControl timeStep;
writeInterval 1;
purgeWrite 0;
writeFormat ascii;
writePrecision 10;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
// ************************************************************************* //

View File

@ -0,0 +1,57 @@
/*--------------------------------*- 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 "system";
object fvSchemes;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
ddtSchemes
{
default Euler;
}
gradSchemes
{
default Gauss linear;
grad(p) Gauss linear;
}
divSchemes
{
default none;
div(phi,U) Gauss linear;
}
laplacianSchemes
{
default Gauss linear orthogonal;
}
interpolationSchemes
{
default linear;
}
snGradSchemes
{
default orthogonal;
}
fluxRequired
{
default no;
p ;
}
// ************************************************************************* //

View File

@ -0,0 +1,46 @@
/*--------------------------------*- 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 "system";
object fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
solvers
{
p
{
solver PCG;
preconditioner DIC;
tolerance 1e-06;
relTol 0;
}
U
{
solver PBiCG;
preconditioner DILU;
tolerance 1e-05;
relTol 0;
}
}
PISO
{
nCorrectors 2;
nNonOrthogonalCorrectors 0;
pRefCell 0;
pRefValue 0;
}
// ************************************************************************* //