2010-05-12 13:27:55 +00:00
|
|
|
/*---------------------------------------------------------------------------*\
|
|
|
|
========= |
|
2013-12-11 16:09:41 +00:00
|
|
|
\\ / F ield | foam-extend: Open Source CFD
|
2015-05-17 13:32:07 +00:00
|
|
|
\\ / O peration | Version: 3.2
|
|
|
|
\\ / A nd | Web: http://www.foam-extend.org
|
|
|
|
\\/ M anipulation | For copyright notice see file Copyright
|
2010-05-12 13:27:55 +00:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
License
|
2013-12-11 16:09:41 +00:00
|
|
|
This file is part of foam-extend.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend is free software: you can redistribute it and/or modify it
|
2010-05-12 13:27:55 +00:00
|
|
|
under the terms of the GNU General Public License as published by the
|
2013-12-11 16:09:41 +00:00
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
2010-05-12 13:27:55 +00:00
|
|
|
option) any later version.
|
|
|
|
|
2013-12-11 16:09:41 +00:00
|
|
|
foam-extend 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.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2013-12-11 16:09:41 +00:00
|
|
|
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
Application
|
|
|
|
potentialFoam
|
|
|
|
|
|
|
|
Description
|
|
|
|
Simple potential flow solver which can be used to generate starting fields
|
|
|
|
for full Navier-Stokes codes.
|
|
|
|
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "fvCFD.H"
|
2016-05-07 07:34:33 +00:00
|
|
|
#include "simpleControl.H"
|
2010-05-12 13:27:55 +00:00
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2013-06-27 12:05:12 +00:00
|
|
|
argList::validOptions.insert("resetU", "");
|
2010-05-12 13:27:55 +00:00
|
|
|
argList::validOptions.insert("writep", "");
|
|
|
|
|
|
|
|
# include "setRootCase.H"
|
|
|
|
|
|
|
|
# include "createTime.H"
|
|
|
|
# include "createMesh.H"
|
2016-05-07 07:34:33 +00:00
|
|
|
|
|
|
|
simpleControl simple(mesh);
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
# include "createFields.H"
|
|
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
|
|
|
|
|
|
|
Info<< nl << "Calculating potential flow" << endl;
|
|
|
|
|
|
|
|
adjustPhi(phi, U, p);
|
|
|
|
|
2016-05-07 07:34:33 +00:00
|
|
|
while (simple.correctNonOrthogonal())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
p.storePrevIter();
|
|
|
|
|
|
|
|
fvScalarMatrix pEqn
|
|
|
|
(
|
|
|
|
fvm::laplacian
|
|
|
|
(
|
|
|
|
dimensionedScalar
|
|
|
|
(
|
|
|
|
"1",
|
|
|
|
dimTime/p.dimensions()*dimensionSet(0, 2, -2, 0, 0),
|
|
|
|
1
|
|
|
|
),
|
|
|
|
p
|
|
|
|
)
|
|
|
|
==
|
|
|
|
fvc::div(phi)
|
|
|
|
);
|
|
|
|
|
|
|
|
pEqn.setReference(pRefCell, pRefValue);
|
|
|
|
pEqn.solve();
|
|
|
|
|
2016-05-07 07:34:33 +00:00
|
|
|
if (simple.finalNonOrthogonalIter())
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
|
|
|
phi -= pEqn.flux();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
p.relax();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Info<< "continuity error = "
|
|
|
|
<< mag(fvc::div(phi))().weightedAverage(mesh.V()).value()
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
U = fvc::reconstruct(phi);
|
|
|
|
U.correctBoundaryConditions();
|
|
|
|
|
|
|
|
Info<< "Interpolated U error = "
|
|
|
|
<< (sqrt(sum(sqr((fvc::interpolate(U) & mesh.Sf()) - phi)))
|
|
|
|
/sum(mesh.magSf())).value()
|
|
|
|
<< endl;
|
|
|
|
|
|
|
|
// Calculate velocity magnitude
|
|
|
|
{
|
|
|
|
volScalarField magU = mag(U);
|
|
|
|
|
2014-08-19 14:42:49 +00:00
|
|
|
Info<< "mag(U): max: " << gMax(magU.internalField())
|
2010-05-12 13:27:55 +00:00
|
|
|
<< " min: " << gMin(magU.internalField()) << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force the write
|
|
|
|
U.write();
|
|
|
|
phi.write();
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
if (args.optionFound("writep"))
|
2010-05-12 13:27:55 +00:00
|
|
|
{
|
2011-05-27 16:17:25 +00:00
|
|
|
// Find reference patch
|
|
|
|
label refPatch = -1;
|
|
|
|
scalar maxMagU = 0;
|
|
|
|
|
|
|
|
// Go through all velocity patches and find the one that fixes
|
|
|
|
// velocity to the largest value
|
|
|
|
|
|
|
|
forAll (U.boundaryField(), patchI)
|
|
|
|
{
|
|
|
|
const fvPatchVectorField& Upatch = U.boundaryField()[patchI];
|
|
|
|
|
|
|
|
if (Upatch.fixesValue())
|
|
|
|
{
|
|
|
|
// Calculate mean velocity
|
|
|
|
scalar u = sum(mag(Upatch));
|
|
|
|
label patchSize = Upatch.size();
|
|
|
|
|
|
|
|
reduce(u, sumOp<scalar>());
|
|
|
|
reduce(patchSize, sumOp<label>());
|
|
|
|
|
|
|
|
if (patchSize > 0)
|
|
|
|
{
|
|
|
|
scalar curMag = u/patchSize;
|
|
|
|
|
|
|
|
if (curMag > maxMagU)
|
|
|
|
{
|
|
|
|
refPatch = patchI;
|
|
|
|
|
|
|
|
maxMagU = curMag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refPatch > -1)
|
|
|
|
{
|
|
|
|
// Calculate reference pressure
|
|
|
|
const fvPatchVectorField& Upatch = U.boundaryField()[refPatch];
|
|
|
|
const fvPatchScalarField& pPatch = p.boundaryField()[refPatch];
|
|
|
|
|
|
|
|
scalar patchE = sum(mag(pPatch + 0.5*magSqr(Upatch)));
|
|
|
|
label patchSize = Upatch.size();
|
|
|
|
|
|
|
|
reduce(patchE, sumOp<scalar>());
|
|
|
|
reduce(patchSize, sumOp<label>());
|
|
|
|
|
|
|
|
scalar e = patchE/patchSize;
|
|
|
|
|
|
|
|
|
|
|
|
Info<< "Using reference patch " << refPatch
|
|
|
|
<< " with mag(U) = " << maxMagU
|
|
|
|
<< " p + 0.5*U^2 = " << e << endl;
|
|
|
|
|
|
|
|
p.internalField() = e - 0.5*magSqr(U.internalField());
|
|
|
|
p.correctBoundaryConditions();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Info<< "No reference patch found. Writing potential function"
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
|
2010-05-12 13:27:55 +00:00
|
|
|
p.write();
|
|
|
|
}
|
|
|
|
|
|
|
|
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
|
|
|
|
<< " ClockTime = " << runTime.elapsedClockTime() << " s"
|
|
|
|
<< nl << endl;
|
|
|
|
|
|
|
|
Info<< "End\n" << endl;
|
|
|
|
|
2010-08-26 14:22:03 +00:00
|
|
|
return 0;
|
2010-05-12 13:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ************************************************************************* //
|