diff --git a/applications/solvers/basic/potentialFoam/createFields.H b/applications/solvers/basic/potentialFoam/createFields.H index ef3b2202..2802cce3 100644 --- a/applications/solvers/basic/potentialFoam/createFields.H +++ b/applications/solvers/basic/potentialFoam/createFields.H @@ -1,21 +1,4 @@ - Info<< "Reading field p\n" << endl; - volScalarField p - ( - IOobject - ( - "p", - runTime.timeName(), - mesh, - IOobject::MUST_READ, - IOobject::NO_WRITE - ), - mesh - ); - - p = dimensionedScalar("zero", p.dimensions(), 0.0); - - - Info<< "Reading field U\n" << endl; + Info<< "Reading velocity field U\n" << endl; volVectorField U ( IOobject @@ -51,12 +34,65 @@ } - label pRefCell = 0; - scalar pRefValue = 0.0; + // Default name for the pressure field + word pName("p"); + + // Update name of the pressure field from the command-line option + args.optionReadIfPresent("pName", pName); + + // Infer the pressure BCs from the velocity BCs + wordList pBCTypes + ( + U.boundaryField().size(), + fixedValueFvPatchScalarField::typeName + ); + + forAll(U.boundaryField(), patchi) + { + if (U.boundaryField()[patchi].fixesValue()) + { + pBCTypes[patchi] = zeroGradientFvPatchScalarField::typeName; + } + } + + Info<< "Constructing pressure field " << pName << nl << endl; + volScalarField p + ( + IOobject + ( + pName, + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ), + mesh, + dimensionedScalar(pName, sqr(dimVelocity), 0), + pBCTypes + ); + + Info<< "Constructing velocity potential field Phi\n" << endl; + volScalarField Phi + ( + IOobject + ( + "Phi", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::NO_WRITE + ), + mesh, + dimensionedScalar("Phi", dimLength*dimVelocity, 0), + p.boundaryField().types() + ); + + label PhiRefCell = 0; + scalar PhiRefValue = 0; setRefCell ( - p, + Phi, potentialFlow, - pRefCell, - pRefValue + PhiRefCell, + PhiRefValue ); diff --git a/applications/solvers/basic/potentialFoam/potentialFoam.C b/applications/solvers/basic/potentialFoam/potentialFoam.C index b4951e5b..5e38befa 100644 --- a/applications/solvers/basic/potentialFoam/potentialFoam.C +++ b/applications/solvers/basic/potentialFoam/potentialFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,8 +25,12 @@ Application potentialFoam Description - Simple potential flow solver which can be used to generate starting fields - for full Navier-Stokes codes. + Potential flow solver which solves for the velocity potential + from which the flux-field is obtained and velocity field by reconstructing + the flux. + + This application is particularly useful to generate starting fields for + Navier-Stokes codes. \*---------------------------------------------------------------------------*/ @@ -37,11 +41,35 @@ Description int main(int argc, char *argv[]) { - argList::addBoolOption("writep", "write the final pressure field"); + argList::addOption + ( + "pName", + "pName", + "Name of the pressure field" + ); + argList::addBoolOption ( "initialiseUBCs", - "initialise U boundary conditions" + "Initialise U boundary conditions" + ); + + argList::addBoolOption + ( + "writePhi", + "Write the velocity potential field" + ); + + argList::addBoolOption + ( + "writep", + "Calculate and write the pressure field" + ); + + argList::addBoolOption + ( + "withFunctionObjects", + "execute functionObjects" ); #include "setRootCase.H" @@ -63,54 +91,93 @@ int main(int argc, char *argv[]) adjustPhi(phi, U, p); - + // Non-orthogonal velocity potential corrector loop for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) { - fvScalarMatrix pEqn + fvScalarMatrix PhiEqn ( - fvm::laplacian - ( - dimensionedScalar - ( - "1", - dimTime/p.dimensions()*dimensionSet(0, 2, -2, 0, 0), - 1 - ), - p - ) + fvm::laplacian(dimensionedScalar("1", dimless, 1), Phi) == fvc::div(phi) ); - pEqn.setReference(pRefCell, pRefValue); - pEqn.solve(); + PhiEqn.setReference(PhiRefCell, PhiRefValue); + PhiEqn.solve(); if (nonOrth == nNonOrthCorr) { - phi -= pEqn.flux(); + phi -= PhiEqn.flux(); } } fvOptions.makeAbsolute(phi); - Info<< "continuity error = " + Info<< "Continuity error = " << mag(fvc::div(phi))().weightedAverage(mesh.V()).value() << endl; U = fvc::reconstruct(phi); U.correctBoundaryConditions(); - Info<< "Interpolated U error = " + Info<< "Interpolated velocity error = " << (sqrt(sum(sqr((fvc::interpolate(U) & mesh.Sf()) - phi))) /sum(mesh.magSf())).value() << endl; - // Force the write + // Write U and phi U.write(); phi.write(); + // Optionally write Phi + if (args.optionFound("writePhi")) + { + Phi.write(); + } + + // Calculate the pressure field if (args.optionFound("writep")) { + Info<< nl << "Calculating approximate pressure field" << endl; + + label pRefCell = 0; + scalar pRefValue = 0.0; + setRefCell + ( + p, + potentialFlow, + pRefCell, + pRefValue + ); + + // Calculate the flow-direction filter tensor + volScalarField magSqrU(magSqr(U)); + volSymmTensorField F(sqr(U)/(magSqrU + SMALL*average(magSqrU))); + + // Calculate the divergence of the flow-direction filtered div(U*U) + // Filtering with the flow-direction generates a more reasonable + // pressure distribution in regions of high velocity gradient in the + // direction of the flow + volScalarField divDivUU + ( + fvc::div + ( + F & fvc::div(phi, U), + "div(div(phi,U))" + ) + ); + + // Solve a Poisson equation for the approximate pressure + for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) + { + fvScalarMatrix pEqn + ( + fvm::laplacian(p) + divDivUU + ); + + pEqn.setReference(pRefCell, pRefValue); + pEqn.solve(); + } + p.write(); } diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 94c8b9ca..0a075732 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -433,7 +433,13 @@ Foam::Time::Time graphFormat_("raw"), runTimeModifiable_(false), - functionObjects_(*this, !args.optionFound("noFunctionObjects")) + functionObjects_ + ( + *this, + argList::validOptions.found("withFunctionObjects") + ? args.optionFound("withFunctionObjects") + : !args.optionFound("noFunctionObjects") + ) { libs_.open(controlDict_, "libs"); diff --git a/tutorials/basic/potentialFoam/cylinder/Allrun b/tutorials/basic/potentialFoam/cylinder/Allrun index b9695da9..5f79f4c2 100755 --- a/tutorials/basic/potentialFoam/cylinder/Allrun +++ b/tutorials/basic/potentialFoam/cylinder/Allrun @@ -1,34 +1,14 @@ #!/bin/sh -cd ${0%/*} || exit 1 # run from this directory +cd ${0%/*} || exit 1 # Run from this directory # Source tutorial run functions . $WM_PROJECT_DIR/bin/tools/RunFunctions application=`getApplication` - -# This case uses the #codeStream which is disabled by default. Enable for -# just this case. -MAIN_CONTROL_DICT=`foamEtcFile controlDict` -if [ -f "$MAIN_CONTROL_DICT" ] -then - echo "Modifying ${MAIN_CONTROL_DICT} to enable allowSystemOperations" - - # Clean up on termination and on Ctrl-C - trap 'mv ${MAIN_CONTROL_DICT}.$$ ${MAIN_CONTROL_DICT} 2>/dev/null; exit 0' \ - EXIT TERM INT - cp ${MAIN_CONTROL_DICT} ${MAIN_CONTROL_DICT}.$$ - - echo "Enabling allowSystemOperations in ${MAIN_CONTROL_DICT}." - - sed \ - -e s/"\(allowSystemOperations[ \t]*\)\([0-9]\);"/"\1 1;"/g \ - ${MAIN_CONTROL_DICT}.$$ > ${MAIN_CONTROL_DICT} -fi - cp -r 0.org 0 > /dev/null 2>&1 runApplication blockMesh -runApplication $application +runApplication $application -withFunctionObjects -writePhi -writep runApplication streamFunction # ----------------------------------------------------------------- end-of-file diff --git a/tutorials/basic/potentialFoam/cylinder/system/fvSchemes b/tutorials/basic/potentialFoam/cylinder/system/fvSchemes index 361b8e6b..0c5eed42 100644 --- a/tutorials/basic/potentialFoam/cylinder/system/fvSchemes +++ b/tutorials/basic/potentialFoam/cylinder/system/fvSchemes @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: 2.3.0 | +| \\ / O peration | Version: 2.3.x | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -28,6 +28,8 @@ gradSchemes divSchemes { default none; + div(phi,U) bounded Gauss linear; + div(div(phi,U)) Gauss linear; } laplacianSchemes @@ -48,7 +50,7 @@ snGradSchemes fluxRequired { default no; - p ; + Phi ; } diff --git a/tutorials/basic/potentialFoam/cylinder/system/fvSolution b/tutorials/basic/potentialFoam/cylinder/system/fvSolution index be0c7797..69fa543c 100644 --- a/tutorials/basic/potentialFoam/cylinder/system/fvSolution +++ b/tutorials/basic/potentialFoam/cylinder/system/fvSolution @@ -1,7 +1,7 @@ /*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | -| \\ / O peration | Version: 2.3.0 | +| \\ / O peration | Version: 2.3.x | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ @@ -17,12 +17,22 @@ FoamFile solvers { + Phi + { + solver GAMG; + smoother DIC; + cacheAgglomeration on; + agglomerator faceAreaPair; + nCellsInCoarsestLevel 10; + mergeLevels 1; + + tolerance 1e-06; + relTol 0.01; + } + p { - solver PCG; - preconditioner DIC; - tolerance 1e-06; - relTol 0; + $Phi; } } diff --git a/tutorials/basic/potentialFoam/pitzDaily/Allrun b/tutorials/basic/potentialFoam/pitzDaily/Allrun index 219e4473..ea05ecad 100755 --- a/tutorials/basic/potentialFoam/pitzDaily/Allrun +++ b/tutorials/basic/potentialFoam/pitzDaily/Allrun @@ -1,5 +1,5 @@ #!/bin/sh -cd ${0%/*} || exit 1 # run from this directory +cd ${0%/*} || exit 1 # Run from this directory # Source tutorial run functions . $WM_PROJECT_DIR/bin/tools/RunFunctions @@ -8,7 +8,7 @@ application=`getApplication` cp -r 0.org 0 > /dev/null 2>&1 runApplication blockMesh -runApplication $application +runApplication $application -writePhi -writep runApplication streamFunction # ----------------------------------------------------------------- end-of-file diff --git a/tutorials/basic/potentialFoam/pitzDaily/system/fvSchemes b/tutorials/basic/potentialFoam/pitzDaily/system/fvSchemes index 7802d26d..41cedab7 100644 --- a/tutorials/basic/potentialFoam/pitzDaily/system/fvSchemes +++ b/tutorials/basic/potentialFoam/pitzDaily/system/fvSchemes @@ -28,6 +28,8 @@ gradSchemes divSchemes { default none; + div(phi,U) bounded Gauss linear; + div(div(phi,U)) Gauss linear; } laplacianSchemes @@ -48,7 +50,7 @@ snGradSchemes fluxRequired { default no; - p ; + Phi ; } diff --git a/tutorials/basic/potentialFoam/pitzDaily/system/fvSolution b/tutorials/basic/potentialFoam/pitzDaily/system/fvSolution index 93974cd8..35c33165 100644 --- a/tutorials/basic/potentialFoam/pitzDaily/system/fvSolution +++ b/tutorials/basic/potentialFoam/pitzDaily/system/fvSolution @@ -17,18 +17,28 @@ FoamFile solvers { + Phi + { + solver GAMG; + smoother DIC; + cacheAgglomeration on; + agglomerator faceAreaPair; + nCellsInCoarsestLevel 10; + mergeLevels 1; + + tolerance 1e-06; + relTol 0.01; + } + p { - solver PCG; - preconditioner DIC; - tolerance 1e-06; - relTol 0; + $Phi; } } potentialFlow { - nNonOrthogonalCorrectors 0; + nNonOrthogonalCorrectors 3; } diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun index 893aaac5..1711e339 100755 --- a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun +++ b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/Allrun @@ -23,7 +23,7 @@ ls -d processor* | xargs -I {} cp -r 0.org ./{}/0 $1 runParallel renumberMesh 8 -overwrite -runParallel potentialFoam 8 -initialiseUBCs -noFunctionObjects +runParallel potentialFoam 8 -initialiseUBCs runParallel `getApplication` 8 diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSchemes b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSchemes index f0d803b5..ebb8b088 100644 --- a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSchemes +++ b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSchemes @@ -55,7 +55,8 @@ snGradSchemes fluxRequired { default no; - p ; + p; + Phi; } diff --git a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSolution b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSolution index 77f9ed9d..f94faa3c 100644 --- a/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSolution +++ b/tutorials/incompressible/pisoFoam/les/motorBike/motorBike/system/fvSolution @@ -38,6 +38,11 @@ solvers relTol 0; }; + Phi + { + $p; + } + "(U|nuTilda)" { solver smoothSolver; diff --git a/tutorials/incompressible/simpleFoam/motorBike/Allrun b/tutorials/incompressible/simpleFoam/motorBike/Allrun index 74d70ca7..4af62e72 100755 --- a/tutorials/incompressible/simpleFoam/motorBike/Allrun +++ b/tutorials/incompressible/simpleFoam/motorBike/Allrun @@ -21,7 +21,7 @@ ls -d processor* | xargs -I {} rm -rf ./{}/0 ls -d processor* | xargs -I {} cp -r 0.org ./{}/0 runParallel patchSummary 6 -runParallel potentialFoam 6 -noFunctionObjects +runParallel potentialFoam 6 runParallel $(getApplication) 6 runApplication reconstructParMesh -constant diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/fvSchemes b/tutorials/incompressible/simpleFoam/motorBike/system/fvSchemes index 9d8ac207..fec61941 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/fvSchemes +++ b/tutorials/incompressible/simpleFoam/motorBike/system/fvSchemes @@ -53,6 +53,7 @@ fluxRequired { default no; p; + Phi; } // ************************************************************************* // diff --git a/tutorials/incompressible/simpleFoam/motorBike/system/fvSolution b/tutorials/incompressible/simpleFoam/motorBike/system/fvSolution index cdbefef9..0f59395f 100644 --- a/tutorials/incompressible/simpleFoam/motorBike/system/fvSolution +++ b/tutorials/incompressible/simpleFoam/motorBike/system/fvSolution @@ -30,6 +30,11 @@ solvers mergeLevels 1; } + Phi + { + $p; + } + U { solver smoothSolver; diff --git a/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSchemes b/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSchemes index 12cf2783..fff7574d 100644 --- a/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSchemes +++ b/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSchemes @@ -58,6 +58,7 @@ fluxRequired { default no; p; + Phi; } diff --git a/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSolution b/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSolution index 0261aef7..453d43eb 100644 --- a/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSolution +++ b/tutorials/lagrangian/reactingParcelFoam/verticalChannel/system/fvSolution @@ -68,6 +68,11 @@ solvers relTol 0; } + Phi + { + $p; + } + "(Yi|O2|N2|H2O)" { solver PBiCG; @@ -88,7 +93,7 @@ solvers potentialFlow { - // used for potentialFoam initialisation + // Used for potentialFoam initialisation nNonOrthogonalCorrectors 5; } diff --git a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSchemes b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSchemes index 6ddc1a4d..0b16bbca 100644 --- a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSchemes +++ b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSchemes @@ -23,7 +23,6 @@ ddtSchemes gradSchemes { default Gauss linear; - grad(p) Gauss linear; } divSchemes @@ -59,6 +58,7 @@ fluxRequired { default no; p; + Phi; } diff --git a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSolution b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSolution index 42cf7952..a134ea52 100644 --- a/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSolution +++ b/tutorials/lagrangian/simpleReactingParcelFoam/verticalChannel/system/fvSolution @@ -37,6 +37,11 @@ solvers maxIter 50; }; + Phi + { + $p; + } + "(U|Yi|h|k|omega)" { solver smoothSolver;