/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2021 OpenCFD Ltd.
Copyright (C) YEAR AUTHOR, AFFILIATION
-------------------------------------------------------------------------------
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 .
\*---------------------------------------------------------------------------*/
#include "functionObjectTemplate.H"
#define namespaceFoam // Suppress
#include "fvCFD.H"
#include "unitConversion.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(errorFunctionObject, 0);
addRemovableToRunTimeSelectionTable
(
functionObject,
errorFunctionObject,
dictionary
);
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
// dynamicCode:
// SHA1 = 58a951483d4c198c74a673fad22549aa08dd009e
//
// unique function name that can be checked if the correct library version
// has been loaded
extern "C" void error_58a951483d4c198c74a673fad22549aa08dd009e(bool load)
{
if (load)
{
// Code that can be explicitly executed after loading
}
else
{
// Code that can be explicitly executed before unloading
}
}
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
//{{{ begin localCode
//}}} end localCode
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
const Foam::fvMesh&
Foam::errorFunctionObject::mesh() const
{
return refCast(obr_);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::
errorFunctionObject::
errorFunctionObject
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
functionObjects::regionFunctionObject(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::
errorFunctionObject::
~errorFunctionObject()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool
Foam::
errorFunctionObject::read(const dictionary& dict)
{
if (false)
{
printMessage("read error");
}
//{{{ begin code
//}}} end code
return true;
}
bool
Foam::
errorFunctionObject::execute()
{
if (false)
{
printMessage("execute error");
}
//{{{ begin code
//}}} end code
return true;
}
bool
Foam::
errorFunctionObject::write()
{
if (false)
{
printMessage("write error");
}
//{{{ begin code
//}}} end code
return true;
}
bool
Foam::
errorFunctionObject::end()
{
if (false)
{
printMessage("end error");
}
//{{{ begin code
#line 56 "/mnt/fivehundred/cylinder/system/controlDict/functions/error"
// Lookup U
Info<< "Looking up field U\n" << endl;
const auto& U = mesh().lookupObject("U");
Info<< "Reading inlet velocity uInfX\n" << endl;
scalar ULeft = 0.0;
label leftI = mesh().boundaryMesh().findPatchID("left");
const auto& fvp = U.boundaryField()[leftI];
if (fvp.size())
{
ULeft = fvp[0].x();
}
reduce(ULeft, maxOp());
dimensionedScalar uInfX("uInfx", dimVelocity, ULeft);
Info<< "U at inlet = " << uInfX.value() << " m/s" << endl;
scalar magCylinder = 0.0;
label cylI = mesh().boundaryMesh().findPatchID("cylinder");
const auto& cylFvp = mesh().C().boundaryField()[cylI];
if (cylFvp.size())
{
magCylinder = mag(cylFvp[0]);
}
reduce(magCylinder, maxOp());
dimensionedScalar radius("radius", dimLength, magCylinder);
Info<< "Cylinder radius = " << radius.value() << " m" << endl;
volVectorField UA
(
IOobject
(
"UA",
mesh().time().timeName(),
U.mesh(),
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
U
);
Info<< "\nEvaluating analytical solution" << endl;
const volVectorField& centres = UA.mesh().C();
volScalarField magCentres(mag(centres));
volScalarField theta(acos((centres & vector(1,0,0))/magCentres));
volVectorField cs2theta
(
cos(2*theta)*vector(1,0,0)
+ sin(2*theta)*vector(0,1,0)
);
UA = uInfX*(dimensionedVector(vector(1,0,0))
- pow((radius/magCentres),2)*cs2theta);
// Force writing of UA (since time has not changed)
UA.write();
volScalarField error("error", mag(U-UA)/mag(UA));
Info<<"Writing relative error in U to " << error.objectPath()
<< endl;
error.write();
//}}} end code
return true;
}
// ************************************************************************* //