Commit 71addd7b authored by Henry Weller's avatar Henry Weller
Browse files

functionObjects::magSqr, components: New functionObjects to calculate the...

functionObjects::magSqr, components: New functionObjects to calculate the 'magSqr' and 'components' of a field
parent b50e2146
......@@ -33,9 +33,11 @@ regionSizeDistribution/regionSizeDistribution.C
histogram/histogram.C
fieldExpression/fieldExpression.C
components/components.C
div/div.C
grad/grad.C
mag/mag.C
magSqr/magSqr.C
vorticity/vorticity.C
enstrophy/enstrophy.C
Q/Q.C
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "components.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(components, 0);
addToRunTimeSelectionTable(functionObject, components, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::components::calc()
{
bool processed = false;
processed = processed || calcComponents<vector>();
processed = processed || calcComponents<sphericalTensor>();
processed = processed || calcComponents<symmTensor>();
processed = processed || calcComponents<tensor>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::components::components
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::components::~components()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::components::write(const bool postProcess)
{
bool written = true;
forAll(resultNames_, i)
{
written = written && writeObject(resultNames_[i]);
}
return written;
}
bool Foam::functionObjects::components::clear()
{
bool cleared = true;
forAll(resultNames_, i)
{
cleared = cleared && clearObject(resultNames_[i]);
}
return cleared;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::components
Group
grpFieldFunctionObjects
Description
This function object calculates the components of a field.
The operation can be applied to any volume or surface fields generating a
volume or surface scalar fields for each component.
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
components.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_components_H
#define functionObjects_components_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class components Declaration
\*---------------------------------------------------------------------------*/
class components
:
public fieldExpression
{
// Private member data
//- List of the component field names
wordList resultNames_;
// Private Member Functions
//- Calculate the components of the field with the specified type
// and register the result
template<class GeoFieldType>
bool calcFieldComponents();
//- Calculate the components of the field with the specified
// element type and register the result
template<class Type>
bool calcComponents();
//- Calculate the components of the field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("components");
// Constructors
//- Construct from Time and dictionary
components
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~components();
// Member Functions
//- Write the component fields
virtual bool write(const bool postProcess = false);
//- Clear the component fields from the objectRegistry
virtual bool clear();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "componentsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class GeoFieldType>
bool Foam::functionObjects::components::calcFieldComponents()
{
typedef typename GeoFieldType::value_type Type;
const GeoFieldType& field(lookupObject<GeoFieldType>(fieldName_));
resultNames_.setSize(Type::nComponents);
bool stored = true;
for (direction i=0; i<Type::nComponents; i++)
{
resultName_ = fieldName_ + word(Type::componentNames[i]);
resultNames_[i] = resultName_;
stored = stored && store(resultName_, field.component(i));
}
return stored;
}
template<class Type>
bool Foam::functionObjects::components::calcComponents()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (foundObject<VolFieldType>(fieldName_))
{
return calcFieldComponents<VolFieldType>();
}
else if (foundObject<SurfaceFieldType>(fieldName_))
{
return calcFieldComponents<SurfaceFieldType>();
}
else
{
return false;
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "magSqr.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(magSqr, 0);
addToRunTimeSelectionTable(functionObject, magSqr, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::magSqr::calc()
{
bool processed = false;
processed = processed || calcMagSqr<scalar>();
processed = processed || calcMagSqr<vector>();
processed = processed || calcMagSqr<sphericalTensor>();
processed = processed || calcMagSqr<symmTensor>();
processed = processed || calcMagSqr<tensor>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::magSqr::magSqr
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::magSqr::~magSqr()
{}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::magSqr
Group
grpFieldFunctionObjects
Description
This function object calculates the magnitude of the sqr of a field.
The operation can be applied to any volume or surface field generating a
volume or surface scalar field.
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
magSqr.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_magSqr_H
#define functionObjects_magSqr_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class magSqr Declaration
\*---------------------------------------------------------------------------*/
class magSqr
:
public fieldExpression
{
// Private Member Functions
//- Calculate the magnitude of the sqr of the field
// and register the result
template<class Type>
bool calcMagSqr();
//- Calculate the magnitude of the sqr of the field
// and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("magSqr");
// Constructors
//- Construct from Time and dictionary
magSqr
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~magSqr();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "magSqrTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "volFields.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::magSqr::calcMagSqr()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (foundObject<VolFieldType>(fieldName_))
{
return store
(
resultName_,
Foam::magSqr(lookupObject<VolFieldType>(fieldName_))
);
}
else if (foundObject<SurfaceFieldType>(fieldName_))
{
return store
(
resultName_,
Foam::magSqr(lookupObject<SurfaceFieldType>(fieldName_))
);
}
else
{
return false;
}
}
// ************************************************************************* //
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment