From 9a534cf76db82dd6ff428a458796234ae6f9e21c Mon Sep 17 00:00:00 2001 From: mattijs Date: Wed, 18 Sep 2013 17:24:57 +0100 Subject: [PATCH] ENH: fieldMapping: new test app --- applications/test/fieldMapping/Make/files | 7 + applications/test/fieldMapping/Make/options | 9 + applications/test/fieldMapping/README.txt | 8 + .../test/fieldMapping/Test-fieldMapping.C | 334 ++++++++++++++ applications/test/fieldMapping/pipe1D/Allrun | 23 + .../pipe1D/constant/manualDecomposition | 424 ++++++++++++++++++ .../pipe1D/constant/polyMesh/blockMeshDict | 61 +++ .../pipe1D/constant/polyMesh/boundary | 41 ++ .../pipe1D/constant/transportProperties | 21 + .../fieldMapping/pipe1D/system/controlDict | 56 +++ .../test/fieldMapping/pipe1D/system/fvSchemes | 57 +++ .../fieldMapping/pipe1D/system/fvSolution | 46 ++ 12 files changed, 1087 insertions(+) create mode 100644 applications/test/fieldMapping/Make/files create mode 100644 applications/test/fieldMapping/Make/options create mode 100644 applications/test/fieldMapping/README.txt create mode 100644 applications/test/fieldMapping/Test-fieldMapping.C create mode 100755 applications/test/fieldMapping/pipe1D/Allrun create mode 100644 applications/test/fieldMapping/pipe1D/constant/manualDecomposition create mode 100644 applications/test/fieldMapping/pipe1D/constant/polyMesh/blockMeshDict create mode 100644 applications/test/fieldMapping/pipe1D/constant/polyMesh/boundary create mode 100644 applications/test/fieldMapping/pipe1D/constant/transportProperties create mode 100644 applications/test/fieldMapping/pipe1D/system/controlDict create mode 100644 applications/test/fieldMapping/pipe1D/system/fvSchemes create mode 100644 applications/test/fieldMapping/pipe1D/system/fvSolution diff --git a/applications/test/fieldMapping/Make/files b/applications/test/fieldMapping/Make/files new file mode 100644 index 0000000000..6e0b3b5164 --- /dev/null +++ b/applications/test/fieldMapping/Make/files @@ -0,0 +1,7 @@ +/* +fvMeshGeometry.C +fvMesh.C +*/ +Test-fieldMapping.C + +EXE = $(FOAM_USER_APPBIN)/Test-fieldMapping diff --git a/applications/test/fieldMapping/Make/options b/applications/test/fieldMapping/Make/options new file mode 100644 index 0000000000..8c55d77648 --- /dev/null +++ b/applications/test/fieldMapping/Make/options @@ -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 diff --git a/applications/test/fieldMapping/README.txt b/applications/test/fieldMapping/README.txt new file mode 100644 index 0000000000..2c2ad0222e --- /dev/null +++ b/applications/test/fieldMapping/README.txt @@ -0,0 +1,8 @@ +Test application for volField and surfaceField mapping with topology +changes. + +Run + + pipe1D/Allrun + +to compile and map a few fields diff --git a/applications/test/fieldMapping/Test-fieldMapping.C b/applications/test/fieldMapping/Test-fieldMapping.C new file mode 100644 index 0000000000..1dae32069e --- /dev/null +++ b/applications/test/fieldMapping/Test-fieldMapping.C @@ -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 . + +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 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; +} + + +// ************************************************************************* // diff --git a/applications/test/fieldMapping/pipe1D/Allrun b/applications/test/fieldMapping/pipe1D/Allrun new file mode 100755 index 0000000000..ba5421e60c --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/Allrun @@ -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 diff --git a/applications/test/fieldMapping/pipe1D/constant/manualDecomposition b/applications/test/fieldMapping/pipe1D/constant/manualDecomposition new file mode 100644 index 0000000000..8f08c2826f --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/constant/manualDecomposition @@ -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 +) + + +// ************************************************************************* // diff --git a/applications/test/fieldMapping/pipe1D/constant/polyMesh/blockMeshDict b/applications/test/fieldMapping/pipe1D/constant/polyMesh/blockMeshDict new file mode 100644 index 0000000000..14bfd1bc80 --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/constant/polyMesh/blockMeshDict @@ -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) + ); + } +); + +// ************************************************************************* // diff --git a/applications/test/fieldMapping/pipe1D/constant/polyMesh/boundary b/applications/test/fieldMapping/pipe1D/constant/polyMesh/boundary new file mode 100644 index 0000000000..a284128db2 --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/constant/polyMesh/boundary @@ -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; + } +) + +// ************************************************************************* // diff --git a/applications/test/fieldMapping/pipe1D/constant/transportProperties b/applications/test/fieldMapping/pipe1D/constant/transportProperties new file mode 100644 index 0000000000..fa1c1ca0b1 --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/constant/transportProperties @@ -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; + + +// ************************************************************************* // diff --git a/applications/test/fieldMapping/pipe1D/system/controlDict b/applications/test/fieldMapping/pipe1D/system/controlDict new file mode 100644 index 0000000000..ff7a82a791 --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/system/controlDict @@ -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; + + +// ************************************************************************* // diff --git a/applications/test/fieldMapping/pipe1D/system/fvSchemes b/applications/test/fieldMapping/pipe1D/system/fvSchemes new file mode 100644 index 0000000000..dede0a6cba --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/system/fvSchemes @@ -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 ; +} + + +// ************************************************************************* // diff --git a/applications/test/fieldMapping/pipe1D/system/fvSolution b/applications/test/fieldMapping/pipe1D/system/fvSolution new file mode 100644 index 0000000000..cc4750f16c --- /dev/null +++ b/applications/test/fieldMapping/pipe1D/system/fvSolution @@ -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; +} + + +// ************************************************************************* //