Add a componentsTurbo option to foamCalc. Will compute radial, tangential and z components from a vector/velocity field
This commit is contained in:
parent
c5956411d5
commit
a96fb65963
4 changed files with 390 additions and 0 deletions
|
@ -2,6 +2,7 @@ calcType/calcType.C
|
||||||
calcType/newCalcType.C
|
calcType/newCalcType.C
|
||||||
|
|
||||||
field/components/components.C
|
field/components/components.C
|
||||||
|
field/componentsTurbo/componentsTurbo.C
|
||||||
field/mag/mag.C
|
field/mag/mag.C
|
||||||
field/magSqr/magSqr.C
|
field/magSqr/magSqr.C
|
||||||
field/magGrad/magGrad.C
|
field/magGrad/magGrad.C
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright held by original author
|
||||||
|
\\/ 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 2 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, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Author
|
||||||
|
Martin Beaudoin, Hydro-Quebec, 2012. All rights reserved
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#include "componentsTurbo.H"
|
||||||
|
#include "addToRunTimeSelectionTable.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
namespace calcTypes
|
||||||
|
{
|
||||||
|
defineTypeNameAndDebug(componentsTurbo, 0);
|
||||||
|
addToRunTimeSelectionTable(calcType, componentsTurbo, dictionary);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::calcTypes::componentsTurbo::componentsTurbo()
|
||||||
|
:
|
||||||
|
calcType()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
Foam::calcTypes::componentsTurbo::~componentsTurbo()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
void Foam::calcTypes::componentsTurbo::init()
|
||||||
|
{
|
||||||
|
argList::validArgs.append("componentsTurbo");
|
||||||
|
argList::validArgs.append("fieldName");
|
||||||
|
//argList::validOptions.insert("rotationAxis", "rotation axis");
|
||||||
|
//argList::validOptions.insert("rotationAxisOrigin", "rotation axis origin");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::calcTypes::componentsTurbo::preCalc
|
||||||
|
(
|
||||||
|
const argList& args,
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh
|
||||||
|
)
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
void Foam::calcTypes::componentsTurbo::calc
|
||||||
|
(
|
||||||
|
const argList& args,
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh
|
||||||
|
)
|
||||||
|
{
|
||||||
|
const word& fieldName = args.additionalArgs()[1];
|
||||||
|
|
||||||
|
IOobject fieldHeader
|
||||||
|
(
|
||||||
|
fieldName,
|
||||||
|
runTime.timeName(),
|
||||||
|
mesh,
|
||||||
|
IOobject::MUST_READ
|
||||||
|
);
|
||||||
|
|
||||||
|
// Check field exists
|
||||||
|
if (fieldHeader.headerOk())
|
||||||
|
{
|
||||||
|
bool processed = false;
|
||||||
|
|
||||||
|
writeComponentFields<vector>(fieldHeader, mesh, processed);
|
||||||
|
//writeComponentFields<sphericalTensor>(fieldHeader, mesh, processed);
|
||||||
|
//writeComponentFields<symmTensor>(fieldHeader, mesh, processed);
|
||||||
|
//writeComponentFields<tensor>(fieldHeader, mesh, processed);
|
||||||
|
|
||||||
|
if (!processed)
|
||||||
|
{
|
||||||
|
FatalError
|
||||||
|
<< "Unable to process " << fieldName << nl
|
||||||
|
<< "No call to componentsTurbo for fields of type "
|
||||||
|
<< fieldHeader.headerClassName() << nl << nl
|
||||||
|
<< exit(FatalError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Info<< " No " << fieldName << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
|
@ -0,0 +1,146 @@
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright held by original author
|
||||||
|
\\/ 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 2 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, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
Class
|
||||||
|
Foam::calcTypes::componentsTurbo
|
||||||
|
|
||||||
|
Description
|
||||||
|
Writes turbo scalar fields corresponding to radial, tangential and z
|
||||||
|
components of the supplied vector field (name) (usually a velocity field)
|
||||||
|
for each time.
|
||||||
|
|
||||||
|
Caveat: the current implementation expect the vector field to be centered
|
||||||
|
around the z-axis.
|
||||||
|
|
||||||
|
Author
|
||||||
|
Martin Beaudoin, Hydro-Quebec, 2012. All rights reserved
|
||||||
|
|
||||||
|
SourceFiles
|
||||||
|
componentsTurbo.C
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
#ifndef componentsTurbo_H
|
||||||
|
#define componentsTurbo_H
|
||||||
|
|
||||||
|
#include "calcType.H"
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
namespace Foam
|
||||||
|
{
|
||||||
|
|
||||||
|
namespace calcTypes
|
||||||
|
{
|
||||||
|
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
Class componentsTurbo Declaration
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
class componentsTurbo
|
||||||
|
:
|
||||||
|
public calcType
|
||||||
|
{
|
||||||
|
// Private Member Functions
|
||||||
|
|
||||||
|
//- Disallow default bitwise copy construct
|
||||||
|
componentsTurbo(const componentsTurbo&);
|
||||||
|
|
||||||
|
//- Disallow default bitwise assignment
|
||||||
|
void operator=(const componentsTurbo&);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Member Functions
|
||||||
|
|
||||||
|
// Calculation routines
|
||||||
|
|
||||||
|
//- Initialise - typically setting static variables,
|
||||||
|
// e.g. command line arguments
|
||||||
|
virtual void init();
|
||||||
|
|
||||||
|
//- Pre-time loop calculations
|
||||||
|
virtual void preCalc
|
||||||
|
(
|
||||||
|
const argList& args,
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh
|
||||||
|
);
|
||||||
|
|
||||||
|
//- Time loop calculations
|
||||||
|
virtual void calc
|
||||||
|
(
|
||||||
|
const argList& args,
|
||||||
|
const Time& runTime,
|
||||||
|
const fvMesh& mesh
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
// I-O
|
||||||
|
|
||||||
|
//- Write component fields
|
||||||
|
template<class Type>
|
||||||
|
void writeComponentFields
|
||||||
|
(
|
||||||
|
const IOobject& header,
|
||||||
|
const fvMesh& mesh,
|
||||||
|
bool& processed
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//- Runtime type information
|
||||||
|
TypeName("componentsTurbo");
|
||||||
|
|
||||||
|
|
||||||
|
// Constructors
|
||||||
|
|
||||||
|
//- Construct null
|
||||||
|
componentsTurbo();
|
||||||
|
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
|
||||||
|
virtual ~componentsTurbo();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
} // End namespace calcTypes
|
||||||
|
} // End namespace Foam
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#ifdef NoRepository
|
||||||
|
# include "writeComponentTurboFields.C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// ************************************************************************* //
|
|
@ -0,0 +1,121 @@
|
||||||
|
/*---------------------------------------------------------------------------*\
|
||||||
|
========= |
|
||||||
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
|
\\ / O peration |
|
||||||
|
\\ / A nd | Copyright held by original author
|
||||||
|
\\/ 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 2 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, write to the Free Software Foundation,
|
||||||
|
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
|
\*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
template <class Type>
|
||||||
|
void Foam::calcTypes::componentsTurbo::writeComponentFields
|
||||||
|
(
|
||||||
|
const IOobject& header,
|
||||||
|
const fvMesh& mesh,
|
||||||
|
bool& processed
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
|
||||||
|
|
||||||
|
if (header.headerClassName() == fieldType::typeName)
|
||||||
|
{
|
||||||
|
const char* turboComponentNames[] = {"radial", "tangential", "z"};
|
||||||
|
|
||||||
|
Info<< " Reading " << header.name() << endl;
|
||||||
|
fieldType field(header, mesh);
|
||||||
|
fieldType turboField(field);
|
||||||
|
|
||||||
|
vectorField cellCentres(mesh.cellCentres());
|
||||||
|
cellCentres.replace(vector::Z, scalar(0));
|
||||||
|
|
||||||
|
const scalarField r = mag(cellCentres);
|
||||||
|
|
||||||
|
forAll(turboField, fI)
|
||||||
|
{
|
||||||
|
turboField[fI].replace(vector::X,
|
||||||
|
(
|
||||||
|
cellCentres[fI].component(vector::X)*field[fI].component(vector::X) +
|
||||||
|
cellCentres[fI].component(vector::Y)*field[fI].component(vector::Y)
|
||||||
|
) / r[fI]
|
||||||
|
);
|
||||||
|
|
||||||
|
turboField[fI].replace(vector::Y,
|
||||||
|
(
|
||||||
|
-cellCentres[fI].component(vector::Y)*field[fI].component(vector::X) +
|
||||||
|
cellCentres[fI].component(vector::X)*field[fI].component(vector::Y)
|
||||||
|
) / r[fI]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert boundary fields
|
||||||
|
forAll(turboField.boundaryField(), patchI)
|
||||||
|
{
|
||||||
|
fvPatchField<Type>& bf = field.boundaryField()[patchI];
|
||||||
|
fvPatchField<Type>& tbf = turboField.boundaryField()[patchI];
|
||||||
|
|
||||||
|
vectorField faceCentres(tbf.patch().Cf());
|
||||||
|
|
||||||
|
faceCentres.replace(vector::Z, scalar(0));
|
||||||
|
|
||||||
|
const scalarField r = mag(faceCentres);
|
||||||
|
|
||||||
|
forAll(tbf, tbfI)
|
||||||
|
{
|
||||||
|
tbf[tbfI].replace(vector::X,
|
||||||
|
(
|
||||||
|
faceCentres[tbfI].component(vector::X)*bf[tbfI].component(vector::X) +
|
||||||
|
faceCentres[tbfI].component(vector::Y)*bf[tbfI].component(vector::Y)
|
||||||
|
) / r[tbfI]
|
||||||
|
);
|
||||||
|
|
||||||
|
tbf[tbfI].replace(vector::Y,
|
||||||
|
(
|
||||||
|
-faceCentres[tbfI].component(vector::Y)*bf[tbfI].component(vector::X) +
|
||||||
|
faceCentres[tbfI].component(vector::X)*bf[tbfI].component(vector::Y)
|
||||||
|
) / r[tbfI]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (direction i=0; i<Type::nComponents; i++)
|
||||||
|
{
|
||||||
|
Info<< " Calculating " << header.name()
|
||||||
|
<< turboComponentNames[i] << endl;
|
||||||
|
|
||||||
|
volScalarField componentField
|
||||||
|
(
|
||||||
|
IOobject
|
||||||
|
(
|
||||||
|
header.name() + word(turboComponentNames[i]),
|
||||||
|
mesh.time().timeName(),
|
||||||
|
mesh,
|
||||||
|
IOobject::NO_READ
|
||||||
|
),
|
||||||
|
turboField.component(i)
|
||||||
|
);
|
||||||
|
componentField.write();
|
||||||
|
}
|
||||||
|
|
||||||
|
processed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
Reference in a new issue