MRG: Resolve conflict when merging branch merge-foundation

This commit is contained in:
Andrew Heather
2016-10-26 15:48:39 +01:00
6041 changed files with 171402 additions and 121858 deletions

16
src/functionObjects/Allwmake Executable file
View File

@ -0,0 +1,16 @@
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
# Parse arguments for library compilation
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
set -x
wmake $targetType field
wmake $targetType forces
wmake $targetType lagrangian
wmake $targetType utilities
wmake $targetType solvers
./graphics/Allwmake
#------------------------------------------------------------------------------

View File

@ -0,0 +1,167 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "CourantNo.H"
#include "surfaceFields.H"
#include "fvcSurfaceIntegrate.H"
#include "zeroGradientFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(CourantNo, 0);
addToRunTimeSelectionTable
(
functionObject,
CourantNo,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField::Internal>
Foam::functionObjects::CourantNo::byRho
(
const tmp<volScalarField::Internal>& Co
) const
{
if (Co().dimensions() == dimDensity)
{
return Co/obr_.lookupObject<volScalarField>(rhoName_);
}
else
{
return Co;
}
}
bool Foam::functionObjects::CourantNo::calc()
{
if (foundObject<surfaceScalarField>(fieldName_))
{
const surfaceScalarField& phi =
lookupObject<surfaceScalarField>(fieldName_);
tmp<volScalarField::Internal> Coi
(
byRho
(
(0.5*mesh_.time().deltaT())
*fvc::surfaceSum(mag(phi))()()
/mesh_.V()
)
);
if (foundObject<volScalarField>(resultName_))
{
volScalarField& Co
(
const_cast<volScalarField&>
(
lookupObject<volScalarField>(resultName_)
)
);
Co.ref() = Coi();
Co.correctBoundaryConditions();
}
else
{
tmp<volScalarField> tCo
(
new volScalarField
(
IOobject
(
resultName_,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
)
);
tCo.ref().ref() = Coi();
tCo.ref().correctBoundaryConditions();
mesh_.objectRegistry::store(tCo.ptr());
}
return true;
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::CourantNo::CourantNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "phi"),
rhoName_("rho")
{
setResultName("Co", "phi");
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::CourantNo::~CourantNo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::CourantNo::read(const dictionary& dict)
{
fieldExpression::read(dict);
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,141 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::CourantNo
Group
grpFieldFunctionObjects
Description
This function object calculates and outputs the Courant number as a
volScalarField. The field is stored on the mesh database so that it can
be retrieved and used for other applications.
Usage
Example of function object specification to calculate the Courant number:
\verbatim
CourantNo1
{
type CourantNo;
libs ("libfieldFunctionObjects.so");
...
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | Type name: CourantNo | yes |
rho | Name of density field | no | rho
field | Name of flux field | no | phi
result | Name of Courant number field | no | <function name>
log | Log to standard output | no | yes
\endtable
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
CourantNo.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_CourantNo_H
#define functionObjects_CourantNo_H
#include "fieldExpression.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class CourantNo Declaration
\*---------------------------------------------------------------------------*/
class CourantNo
:
public fieldExpression
{
// Private data
//- Name of density field (optional)
word rhoName_;
// Private Member Functions
//- Divide the Courant number by rho if required
tmp<volScalarField::Internal> byRho
(
const tmp<volScalarField::Internal>& Co
) const;
//- Calculate the Courant number field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("CourantNo");
// Constructors
//- Construct from Time and dictionary
CourantNo
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~CourantNo();
// Member Functions
//- Read the CourantNo data
virtual bool read(const dictionary&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,179 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "DESModelRegions.H"
#include "volFields.H"
#include "DESModelBase.H"
#include "turbulenceModel.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(DESModelRegions, 0);
addToRunTimeSelectionTable
(
functionObject,
DESModelRegions,
dictionary
);
}
}
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::functionObjects::DESModelRegions::writeFileHeader(Ostream& os) const
{
writeHeader(os, "DES model region coverage (% volume)");
writeCommented(os, "Time");
writeTabbed(os, "LES");
writeTabbed(os, "RAS");
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::DESModelRegions::DESModelRegions
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name, typeName, dict),
resultName_(name)
{
read(dict);
tmp<volScalarField> tDESModelRegions
(
(
new volScalarField
(
IOobject
(
resultName_,
time_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0)
)
)
);
store(resultName_, tDESModelRegions);
writeFileHeader(file());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::DESModelRegions::~DESModelRegions()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::DESModelRegions::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
writeFile::read(dict);
dict.readIfPresent("resultName", resultName_);
return true;
}
bool Foam::functionObjects::DESModelRegions::execute()
{
Log << type() << " " << name() << " execute:" << nl;
volScalarField& DESModelRegions =
const_cast<volScalarField&>
(
lookupObject<volScalarField>(resultName_)
);
if (foundObject<DESModelBase>(turbulenceModel::propertiesName))
{
const DESModelBase& model =
lookupObject<DESModelBase>
(
turbulenceModel::propertiesName
);
DESModelRegions == model.LESRegion();
scalar prc =
gSum(DESModelRegions.primitiveField()*mesh_.V())
/gSum(mesh_.V())*100.0;
file() << time_.value()
<< token::TAB << prc
<< token::TAB << 100.0 - prc
<< endl;
Log << " LES = " << prc << " % (volume)" << nl
<< " RAS = " << 100.0 - prc << " % (volume)" << nl
<< endl;
}
else
{
Log << " No DES turbulence model found in database" << nl
<< endl;
}
return true;
}
bool Foam::functionObjects::DESModelRegions::write()
{
const volScalarField& DESModelRegions =
lookupObject<volScalarField>(resultName_);
Log << type() << " " << name() << " output:" << nl
<< " writing field " << DESModelRegions.name() << nl
<< endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,149 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::DESModelRegions
Group
grpFieldFunctionObjects
Description
This function object writes out an indicator field for DES turbulence
calculations, that is:
- 0 for RAS regions
- 1 for LES regions
The field is stored on the mesh database so that it can be retrieved and
used for other applications.
Usage
Example of function object specification to generate DES indicator field:
\verbatim
DESModelRegions1
{
type DESModelRegions;
libs ("libutilityFunctionObjects.so");
...
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: DESModelRegions| yes |
resultName | Name of DES indicator field | no | <function name>
log | log to standard output | no | yes
\endtable
SourceFiles
DESModelRegions.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_DESModelRegions_H
#define functionObjects_DESModelRegions_H
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "volFieldsFwd.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class DESModelRegions Declaration
\*---------------------------------------------------------------------------*/
class DESModelRegions
:
public fvMeshFunctionObject,
public writeFile
{
protected:
// Protected data
//- Result name
word resultName_;
// Protected Member Functions
//- File header information
virtual void writeFileHeader(Ostream& os) const;
//- Disallow default bitwise copy construct
DESModelRegions(const DESModelRegions&) = delete;
//- Disallow default bitwise assignment
void operator=(const DESModelRegions&) = delete;
public:
//- Runtime type information
TypeName("DESModelRegions");
// Constructors
//- Construct from Time and dictionary
DESModelRegions
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~DESModelRegions();
// Member Functions
//- Read the DESModelRegions data
virtual bool read(const dictionary&);
//- Execute
virtual bool execute();
//- Calculate the DESModelRegions and write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,98 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "Lambda2.H"
#include "fvcGrad.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(Lambda2, 0);
addToRunTimeSelectionTable
(
functionObject,
Lambda2,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::Lambda2::calc()
{
if (foundObject<volVectorField>(fieldName_))
{
const volVectorField& U = lookupObject<volVectorField>(fieldName_);
const tmp<volTensorField> tgradU(fvc::grad(U));
const volTensorField& gradU = tgradU();
const volTensorField SSplusWW
(
(symm(gradU) & symm(gradU))
+ (skew(gradU) & skew(gradU))
);
return store
(
resultName_,
-eigenValues(SSplusWW)().component(vector::Y)
);
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::Lambda2::Lambda2
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U")
{
setResultName(typeName, "U");
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::Lambda2::~Lambda2()
{}
// ************************************************************************* //

View File

@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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::Lambda2
Group
grpFieldFunctionObjects
Description
Calculates and outputs the second largest eigenvalue of the sum of the
square of the symmetrical and anti-symmetrical parts of the velocity
gradient tensor.
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
Lambda2.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_Lambda2_H
#define functionObjects_Lambda2_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class Lambda2 Declaration
\*---------------------------------------------------------------------------*/
class Lambda2
:
public fieldExpression
{
// Private Member Functions
//- Calculate the Lambda2 field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("Lambda2");
// Constructors
//- Construct from Time and dictionary
Lambda2
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~Lambda2();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "MachNo.H"
#include "fluidThermo.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(MachNo, 0);
addToRunTimeSelectionTable
(
functionObject,
MachNo,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::MachNo::calc()
{
if
(
foundObject<volVectorField>(fieldName_)
&& mesh_.foundObject<fluidThermo>(fluidThermo::dictName)
)
{
const fluidThermo& thermo =
mesh_.lookupObject<fluidThermo>(fluidThermo::dictName);
const volVectorField& U = lookupObject<volVectorField>(fieldName_);
return store
(
resultName_,
mag(U)/sqrt(thermo.gamma()*thermo.p()/thermo.rho())
);
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::MachNo::MachNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U")
{
setResultName("Ma", "U");
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::MachNo::~MachNo()
{}
// ************************************************************************* //

View File

@ -0,0 +1,100 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::MachNo
Group
grpFieldFunctionObjects
Description
Calculates and writes the Mach number as a volScalarField.
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
MachNo.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_MachNo_H
#define functionObjects_MachNo_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class MachNo Declaration
\*---------------------------------------------------------------------------*/
class MachNo
:
public fieldExpression
{
// Private Member Functions
//- Calculate the Mach number field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("MachNo");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
MachNo
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~MachNo();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,78 @@
fieldAverage/fieldAverage.C
fieldAverage/fieldAverageItem/fieldAverageItem.C
fieldAverage/fieldAverageItem/fieldAverageItemIO.C
fieldCoordinateSystemTransform/fieldCoordinateSystemTransform.C
fieldMinMax/fieldMinMax.C
fieldValues/fieldValue/fieldValue.C
fieldValues/fieldValue/fieldValueNew.C
fieldValues/fieldValueDelta/fieldValueDelta.C
fieldValues/volFieldValue/volFieldValue.C
fieldValues/surfaceFieldValue/surfaceFieldValue.C
nearWallFields/nearWallFields.C
nearWallFields/findCellParticle.C
nearWallFields/findCellParticleCloud.C
processorField/processorField.C
readFields/readFields.C
streamLine/streamLine.C
streamLine/streamLineBase.C
streamLine/streamLineParticle.C
streamLine/streamLineParticleCloud.C
wallBoundedStreamLine/wallBoundedStreamLine.C
wallBoundedStreamLine/wallBoundedStreamLineParticle.C
wallBoundedStreamLine/wallBoundedStreamLineParticleCloud.C
wallBoundedStreamLine/wallBoundedParticle.C
surfaceInterpolate/surfaceInterpolate.C
regionSizeDistribution/regionSizeDistribution.C
histogram/histogram.C
fieldExpression/fieldExpression.C
components/components.C
randomise/randomise.C
div/div.C
grad/grad.C
mag/mag.C
magSqr/magSqr.C
vorticity/vorticity.C
enstrophy/enstrophy.C
Q/Q.C
Lambda2/Lambda2.C
flowType/flowType.C
CourantNo/CourantNo.C
PecletNo/PecletNo.C
blendingFactor/blendingFactor.C
pressure/pressure.C
MachNo/MachNo.C
turbulenceFields/turbulenceFields.C
yPlus/yPlus.C
wallShearStress/wallShearStress.C
wallHeatFlux/wallHeatFlux.C
writeCellCentres/writeCellCentres.C
writeCellVolumes/writeCellVolumes.C
XiReactionRate/XiReactionRate.C
streamFunction/streamFunction.C
valueAverage/valueAverage.C
fluxSummary/fluxSummary.C
mapFields/mapFields.C
reactionSensitivityAnalysis/reactionsSensitivityAnalysisObjects.C
DESModelRegions/DESModelRegions.C
externalCoupled/externalCoupled.C
externalCoupled/externalCoupledMixed/externalCoupledMixedFvPatchFields.C
externalCoupled/externalCoupledTemperatureMixed/externalCoupledTemperatureMixedFvPatchScalarField.C
ddt2/ddt2.C
zeroGradient/zeroGradient.C
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects

View File

@ -0,0 +1,36 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/transportModels \
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/turbulenceModels/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/incompressible/lnInclude \
-I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \
-I$(LIB_SRC)/transportModels/compressible/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/chemistryModel/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/reactionThermo/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude
LIB_LIBS = \
-lfiniteVolume \
-lfluidThermophysicalModels \
-lincompressibleTransportModels \
-lturbulenceModels \
-lcompressibleTransportModels \
-lincompressibleTurbulenceModels \
-lcompressibleTurbulenceModels \
-lmeshTools \
-lsampling \
-lsurfMesh \
-lchemistryModel \
-lreactionThermophysicalModels

View File

@ -0,0 +1,166 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "PecletNo.H"
#include "turbulenceModel.H"
#include "surfaceInterpolate.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(PecletNo, 0);
addToRunTimeSelectionTable
(
functionObject,
PecletNo,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::tmp<Foam::surfaceScalarField> Foam::functionObjects::PecletNo::rhoScale
(
const surfaceScalarField& phi
) const
{
if (phi.dimensions() == dimMass/dimTime)
{
return phi/fvc::interpolate(lookupObject<volScalarField>(rhoName_));
}
else
{
return phi;
}
}
bool Foam::functionObjects::PecletNo::calc()
{
if (foundObject<surfaceScalarField>(fieldName_))
{
tmp<volScalarField> nuEff;
if (mesh_.foundObject<turbulenceModel>(turbulenceModel::propertiesName))
{
const turbulenceModel& model =
lookupObject<turbulenceModel>
(
turbulenceModel::propertiesName
);
nuEff = model.nuEff();
}
else if (mesh_.foundObject<dictionary>("transportProperties"))
{
const dictionary& model =
mesh_.lookupObject<dictionary>("transportProperties");
nuEff =
tmp<volScalarField>
(
new volScalarField
(
IOobject
(
"nuEff",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar(model.lookup("nu"))
)
);
}
else
{
FatalErrorInFunction
<< "Unable to determine the viscosity"
<< exit(FatalError);
}
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(fieldName_);
return store
(
resultName_,
mag(rhoScale(phi))
/(
mesh_.magSf()
*mesh_.surfaceInterpolation::deltaCoeffs()
*fvc::interpolate(nuEff)
)
);
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::PecletNo::PecletNo
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "phi"),
rhoName_("rho")
{
setResultName("Pe", "phi");
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::PecletNo::~PecletNo()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::PecletNo::read(const dictionary& dict)
{
dict.readIfPresent("rho", rhoName_);
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,132 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::PecletNo
Group
grpFieldFunctionObjects
Description
Calculates and outputs the Peclet number as a surfaceScalarField.
Usage
Example of function object specification to calculate the Peclet number:
\verbatim
PecletNo1
{
type PecletNo;
libs ("libutilityFunctionObjects.so");
...
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: Peclet | yes |
phi | Name of flux field | no | phi
rho | Name of density field | no | rho
result | Name of Peclet field | no | <function name>
log | Log to standard output | no | yes
\endtable
SourceFiles
PecletNo.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_PecletNo_H
#define functionObjects_PecletNo_H
#include "fieldExpression.H"
#include "surfaceFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class PecletNo Declaration
\*---------------------------------------------------------------------------*/
class PecletNo
:
public fieldExpression
{
// Private data
//- Name of density field, default is "rho"
word rhoName_;
// Private Member Functions
//- Optionally scale the flux for compressible cases
tmp<surfaceScalarField> rhoScale(const surfaceScalarField& phi) const;
//- Calculate the Peclet number field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("PecletNo");
// Constructors
//- Construct from Time and dictionary
PecletNo
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~PecletNo();
// Member Functions
//- Read the PecletNo data
virtual bool read(const dictionary&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,92 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "Q.H"
#include "fvcGrad.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(Q, 0);
addToRunTimeSelectionTable
(
functionObject,
Q,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::Q::calc()
{
if (foundObject<volVectorField>(fieldName_))
{
const volVectorField& U = lookupObject<volVectorField>(fieldName_);
const tmp<volTensorField> tgradU(fvc::grad(U));
const volTensorField& gradU = tgradU();
return store
(
resultName_,
0.5*(sqr(tr(gradU)) - tr(((gradU) & (gradU))))
);
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::Q::Q
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U")
{
setResultName(typeName, "U");
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::Q::~Q()
{}
// ************************************************************************* //

View File

@ -0,0 +1,129 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::Q
Group
grpFieldFunctionObjects
Description
Calculates and outputs the second invariant of the velocity gradient tensor
[1/s^2].
\f[
Q = 0.5(sqr(tr(\nabla U)) - tr(((\nabla U) \cdot (\nabla U))))
\f]
where
\vartable
U | velocity [m/s]
\endvartable
Usage
Example of function object specification to calculate Q:
\verbatim
Q1
{
type Q;
libs ("libutilityFunctionObjects.so");
...
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: Q | yes |
U | Name of velocity field | no | U
result | Name of Q field | no | <function name>
log | Log to standard output | no | yes
\endtable
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
Q.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_Q_H
#define functionObjects_Q_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class Q Declaration
\*---------------------------------------------------------------------------*/
class Q
:
public fieldExpression
{
// Private Member Functions
//- Calculate the Q field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("Q");
// Constructors
//- Construct from Time and dictionary
Q
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~Q();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "XiReactionRate.H"
#include "volFields.H"
#include "fvcGrad.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(XiReactionRate, 0);
addToRunTimeSelectionTable(functionObject, XiReactionRate, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::XiReactionRate::XiReactionRate
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::XiReactionRate::~XiReactionRate()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::XiReactionRate::read(const dictionary& dict)
{
return fvMeshFunctionObject::read(dict);
}
bool Foam::functionObjects::XiReactionRate::execute()
{
return true;
}
bool Foam::functionObjects::XiReactionRate::write()
{
const volScalarField& b =
mesh_.lookupObject<volScalarField>("b");
const volScalarField& Su =
mesh_.lookupObject<volScalarField>("Su");
const volScalarField& Xi =
mesh_.lookupObject<volScalarField>("Xi");
volScalarField St
(
IOobject
(
"St",
time_.timeName(),
mesh_
),
Xi*Su
);
Log << " Writing turbulent flame-speed field " << St.name()
<< " to " << time_.timeName() << endl;
St.write();
volScalarField wdot
(
IOobject
(
"wdot",
time_.timeName(),
mesh_
),
St*mag(fvc::grad(b))
);
Log << " Writing reaction-rate field " << wdot.name()
<< " to " << time_.timeName() << endl;
wdot.write();
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::XiReactionRate
Group
grpFieldFunctionObjects
Description
Writes the turbulent flame-speed and reaction-rate volScalarFields for the
Xi-based combustion models.
Usage
Example of function object specification:
\verbatim
XiReactionRate
{
type XiReactionRate;
libs ("libfieldFunctionObjects.so");
...
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: XiReactionRate | yes |
\endtable
See also
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
XiReactionRate.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_XiReactionRate_H
#define functionObjects_XiReactionRate_H
#include "fvMeshFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class XiReactionRate Declaration
\*---------------------------------------------------------------------------*/
class XiReactionRate
:
public fvMeshFunctionObject
{
// Private member functions
//- Disallow default bitwise copy construct
XiReactionRate(const XiReactionRate&);
//- Disallow default bitwise assignment
void operator=(const XiReactionRate&);
public:
//- Runtime type information
TypeName("XiReactionRate");
// Constructors
//- Construct from Time and dictionary
XiReactionRate
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~XiReactionRate();
// Member Functions
//- Read the reaction rate data
virtual bool read(const dictionary&);
//- Do nothing
virtual bool execute();
//- Write the reaction rate fields
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,182 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "blendingFactor.H"
#include "addToRunTimeSelectionTable.H"
#include "zeroGradientFvPatchFields.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(blendingFactor, 0);
addToRunTimeSelectionTable(functionObject, blendingFactor, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::blendingFactor::writeFileHeader(Ostream& os) const
{
writeHeader(os, "Blending factor");
writeCommented(os, "Time");
writeTabbed(os, "Scheme1");
writeTabbed(os, "Scheme2");
writeTabbed(os, "Blended");
os << endl;
}
bool Foam::functionObjects::blendingFactor::calc()
{
bool processed = false;
processed = processed || calcScheme<scalar>();
processed = processed || calcScheme<vector>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::blendingFactor::blendingFactor
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict),
writeFile(obr_, name, typeName, dict),
phiName_("phi"),
tolerance_(0.001)
{
read(dict);
writeFileHeader(file());
setResultName(typeName, fieldName_);
tmp<volScalarField> indicatorPtr
(
new volScalarField
(
IOobject
(
resultName_,
time_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0),
zeroGradientFvPatchScalarField::typeName
)
);
store(resultName_, indicatorPtr);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::blendingFactor::~blendingFactor()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::blendingFactor::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
dict.readIfPresent("tolerance", tolerance_);
if ((tolerance_ < 0) || (tolerance_ > 1))
{
FatalErrorInFunction
<< "tolerance must be in the range 0 to 1. Supplied value: "
<< tolerance_ << exit(FatalError);
}
return true;
}
bool Foam::functionObjects::blendingFactor::write()
{
if (fieldExpression::write())
{
const volScalarField& indicator =
lookupObject<volScalarField>(resultName_);
// Generate scheme statistics
label nCellsScheme1 = 0;
label nCellsScheme2 = 0;
label nCellsBlended = 0;
forAll(indicator, celli)
{
scalar i = indicator[celli];
if (i < tolerance_)
{
nCellsScheme1++;
}
else if (i > (1 - tolerance_))
{
nCellsScheme2++;
}
else
{
nCellsBlended++;
}
}
reduce(nCellsScheme1, sumOp<label>());
reduce(nCellsScheme2, sumOp<label>());
reduce(nCellsBlended, sumOp<label>());
Log << type() << " " << name() << " write:" << nl
<< " scheme 1 cells : " << nCellsScheme1 << nl
<< " scheme 2 cells : " << nCellsScheme2 << nl
<< " blended cells : " << nCellsBlended << nl
<< endl;
file()
<< time_.time().value()
<< token::TAB << nCellsScheme1
<< token::TAB << nCellsScheme2
<< token::TAB << nCellsBlended
<< endl;
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,191 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::blendingFactor
Group
grpFieldFunctionObjects
Description
Calculates and outputs the blendingFactor as used by the bended convection
schemes. The output is a volume field (cells) whose value is calculated via
the maximum blending factor for any cell face.
The weight of a blended scheme is given by a function of the blending
factor, f:
weight = f*scheme1 + (1 - f)*scheme2
The factor is a face-based quantity, which is converted to a cell-based
quantity by assigning the minimum blending factor for any cell face.
An indicator (volume) field, named <functionObjectName>:<fieldName>, is
generated that is set to (1 - f), i.e. values of:
- 0 represent scheme1 as active, and
- 1 represent scheme2 as active.
- intermediate values show the contribution to scheme2
Additional reporting is written to the standard output, providing
statistics as to the number of cells used by each scheme.
Usage
Example of function object specification to calculate the blending factor:
\verbatim
blendingFactor1
{
type blendingFactor;
libs ("libfieldFunctionObjects.so");
...
// Name of field
fieldName U;
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | Type name: blendingFactor | yes |
phi | Name of flux field | no | phi
field | Name of field to evaluate | yes |
tolerance | Tolerance for number of blended cells | no | 0.001
log | Log to standard output | no | yes
\endtable
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
SourceFiles
blendingFactor.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_blendingFactor_H
#define functionObjects_blendingFactor_H
#include "fieldExpression.H"
#include "writeFile.H"
#include "convectionScheme.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class blendingFactor Declaration
\*---------------------------------------------------------------------------*/
class blendingFactor
:
public fieldExpression,
public writeFile
{
// Private member data
//- Name of flux field, default is "phi"
word phiName_;
//- Tolerance used when calculating the number of blended cells
scalar tolerance_;
// Private Member Functions
//- Calculate the blending factor field
template<class Type>
void calcBlendingFactor
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const typename fv::convectionScheme<Type>& cs
);
//- Calculate the blending factor field
template<class Type>
bool calcScheme();
//- Calculate the blending factor field and return true if successful
virtual bool calc();
protected:
// Protected Member Functions
//- Write the file header
virtual void writeFileHeader(Ostream& os) const;
public:
//- Runtime type information
TypeName("blendingFactor");
// Constructors
//- Construct from Time and dictionary
blendingFactor
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~blendingFactor();
// Member Functions
//- Read the blendingFactor data
virtual bool read(const dictionary&);
//- Write the blendingFactor
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "blendingFactorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,123 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "gaussConvectionScheme.H"
#include "boundedConvectionScheme.H"
#include "blendedSchemeBase.H"
#include "fvcCellReduce.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::blendingFactor::calcBlendingFactor
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const typename fv::convectionScheme<Type>& cs
)
{
if (!isA<fv::gaussConvectionScheme<Type>>(cs))
{
WarningInFunction
<< "Scheme for field " << field.name() << " is not a "
<< fv::gaussConvectionScheme<Type>::typeName
<< " scheme. Not calculating " << resultName_ << endl;
return;
}
const fv::gaussConvectionScheme<Type>& gcs =
refCast<const fv::gaussConvectionScheme<Type>>(cs);
const surfaceInterpolationScheme<Type>& interpScheme = gcs.interpScheme();
if (!isA<blendedSchemeBase<Type>>(interpScheme))
{
WarningInFunction
<< interpScheme.type() << " is not a blended scheme"
<< ". Not calculating " << resultName_ << endl;
return;
}
// Retrieve the face-based blending factor
const blendedSchemeBase<Type>& blendedScheme =
refCast<const blendedSchemeBase<Type>>(interpScheme);
const surfaceScalarField factorf(blendedScheme.blendingFactor(field));
// Convert into vol field whose values represent the local face minima
// Note:
// - factor applied to 1st scheme, and (1-factor) to 2nd scheme
// - not using the store(...) mechanism due to need to correct BCs
volScalarField& indicator =
const_cast<volScalarField&>
(
lookupObject<volScalarField>(resultName_)
);
indicator = 1 - fvc::cellReduce(factorf, minEqOp<scalar>(), GREAT);
indicator.correctBoundaryConditions();
}
template<class Type>
bool Foam::functionObjects::blendingFactor::calcScheme()
{
typedef GeometricField<Type, fvPatchField, volMesh> FieldType;
if (!foundObject<FieldType>(fieldName_))
{
return false;
}
const FieldType& field = lookupObject<FieldType>(fieldName_);
const word divScheme("div(" + phiName_ + ',' + fieldName_ + ')');
ITstream& its = mesh_.divScheme(divScheme);
const surfaceScalarField& phi = lookupObject<surfaceScalarField>(phiName_);
tmp<fv::convectionScheme<Type>> tcs =
fv::convectionScheme<Type>::New(mesh_, phi, its);
if (isA<fv::boundedConvectionScheme<Type>>(tcs()))
{
const fv::boundedConvectionScheme<Type>& bcs =
refCast<const fv::boundedConvectionScheme<Type>>(tcs());
calcBlendingFactor(field, bcs.scheme());
}
else
{
const fv::gaussConvectionScheme<Type>& gcs =
refCast<const fv::gaussConvectionScheme<Type>>(tcs());
calcBlendingFactor(field, gcs);
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,103 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::components::~components()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::components::write()
{
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;
}
// ************************************************************************* //

View File

@ -0,0 +1,132 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
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.
See also
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();
//- Clear the component fields from the objectRegistry
virtual bool clear();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "componentsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,75 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,268 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ 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 "ddt2.H"
#include "volFields.H"
#include "dictionary.H"
#include "steadyStateDdtScheme.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(ddt2, 0);
addToRunTimeSelectionTable
(
functionObject,
ddt2,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::ddt2::checkFormatName(const word& str)
{
if (str.find("@@") == string::npos)
{
WarningInFunction
<< "Bad result naming "
<< "(no '@@' token found), deactivating."
<< nl << endl;
return false;
}
else if (str == "@@")
{
WarningInFunction
<< "Bad result naming "
<< "(only a '@@' token found), deactivating."
<< nl
<< endl;
return false;
}
else
{
return true;
}
}
void Foam::functionObjects::ddt2::uniqWords(wordReList& lst)
{
boolList retain(lst.size());
wordHashSet uniq;
forAll(lst, i)
{
const wordRe& select = lst[i];
retain[i] =
(
select.isPattern()
|| uniq.insert(static_cast<const word&>(select))
);
}
inplaceSubset(retain, lst);
}
bool Foam::functionObjects::ddt2::accept(const word& fieldName) const
{
// check input vs possible result names
// to avoid circular calculations
return !blacklist_.match(fieldName);
}
int Foam::functionObjects::ddt2::process(const word& fieldName)
{
if (!accept(fieldName))
{
return -1;
}
int state = 0;
apply<volScalarField>(fieldName, state);
apply<volVectorField>(fieldName, state);
return state;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::ddt2::ddt2
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
selectFields_(),
resultName_(word::null),
blacklist_(),
results_(),
mag_(dict.lookupOrDefault<Switch>("mag", false))
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::ddt2::~ddt2()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::ddt2::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
if (word(mesh_.ddtScheme("default")) == "steadyState")
{
WarningInFunction
<< typeName << " function object not appropriate for steady-state"
<< endl;
return false;
}
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> selectFields_;
uniqWords(selectFields_);
resultName_ = dict.lookupOrDefault<word>
(
"result",
( mag_ ? "mag(ddt(@@))" : "magSqr(ddt(@@))" )
);
if (checkFormatName(resultName_))
{
blacklist_.set
(
string::quotemeta<regExp>
(
resultName_
).replace("@@", "(.+)")
);
return true;
}
else
{
blacklist_.clear();
return false;
}
}
bool Foam::functionObjects::ddt2::execute()
{
results_.clear();
wordHashSet candidates = subsetStrings(selectFields_, mesh_.names());
DynamicList<word> missing(selectFields_.size());
DynamicList<word> ignored(selectFields_.size());
// check exact matches first
forAll(selectFields_, i)
{
const wordRe& select = selectFields_[i];
if (!select.isPattern())
{
const word& fieldName = static_cast<const word&>(select);
if (!candidates.erase(fieldName))
{
missing.append(fieldName);
}
else if (process(fieldName) < 1)
{
ignored.append(fieldName);
}
}
}
forAllConstIter(wordHashSet, candidates, iter)
{
process(iter.key());
}
if (missing.size())
{
WarningInFunction
<< "Missing field " << missing << endl;
}
if (ignored.size())
{
WarningInFunction
<< "Unprocessed field " << ignored << endl;
}
return true;
}
bool Foam::functionObjects::ddt2::write()
{
if (results_.size())
{
Log << type() << ' ' << name() << " write:" << endl;
}
// Consistent output order
const wordList outputList = results_.sortedToc();
forAll(outputList, i)
{
const word& fieldName = outputList[i];
if (foundObject<regIOobject>(fieldName))
{
const regIOobject& io = lookupObject<regIOobject>(fieldName);
Log << " " << fieldName << endl;
io.write();
}
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,198 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ 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::ddt2
Group
grpFieldFunctionObjects
Description
This function object calculates the magnitude squared
of d(scalarField)/dt.
The result can be used further for determining variance or RMS values
(for example).
Usage
Example of function object specification:
\verbatim
dpdt2
{
type ddt2;
libs ("libfieldFunctionObjects.so");
fields (p);
result d@@dt2;
...
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: ddt2 | yes |
fields | Name of fields to process | yes |
result | Name of results | no | magSqr(ddt(@@))
log | Log to standard output | no | yes
mag | Use 'mag' instead of 'magSqr' | no | false
\endtable
Note that the optional 'mag' entry cannot be changed during the simulation
since it alters the dimensions of the output field.
A list of fields can contain exact names or regular expressions.
The token '\@\@' in the result name is replaced by the name of the source
field.
The function object will skip over fields that appear to have
already been processed (ie, their names are similar to the output names).
SourceFiles
ddt2.C
ddt2Templates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_ddt2_H
#define functionObjects_ddt2_H
#include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
#include "OFstream.H"
#include "wordReList.H"
#include "regExp.H"
#include "HashSet.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class ddt2 Declaration
\*---------------------------------------------------------------------------*/
class ddt2
:
public fvMeshFunctionObject
{
// Private data
//- Name of fields to process
wordReList selectFields_;
//- Formatting for the result fields.
word resultName_;
//- Avoid processing the same field twice.
mutable regExp blacklist_;
//- Hashed names of result fields.
wordHashSet results_;
//- Use 'mag' instead of 'magSqr'.
// Cannot be adjusted during the simulation since it alters the
// dimensions of the output field.
const Switch mag_;
// Private Member Functions
//- Check that the word contains the appropriate substitution token(s).
static bool checkFormatName(const word&);
//- Eliminate duplicate 'word' entries
static void uniqWords(wordReList&);
//- Accept unless field name appears to have already been processed
bool accept(const word& fieldName) const;
//- Apply for the volume field type
template<class FieldType>
int apply(const word& inputName, int& state);
//- Process by trying to apply for various volume field types.
int process(const word& inputName);
//- Disallow default bitwise copy construct
ddt2(const ddt2&) = delete;
//- Disallow default bitwise assignment
void operator=(const ddt2&) = delete;
public:
//- Runtime type information
TypeName("ddt2");
// Constructors
//- Construct from Time and dictionary
ddt2
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~ddt2();
// Member Functions
//- Read the ddt2 specification
virtual bool read(const dictionary&);
//- Calculate the ddt2 fields
virtual bool execute();
//- Write the ddt fields
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "ddt2Templates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,103 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ 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 "Time.H"
#include "dimensionedType.H"
#include "fvcDdt.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class FieldType>
int Foam::functionObjects::ddt2::apply(const word& inputName, int& state)
{
// State: return 0 (not-processed), -1 (skip), +1 ok
// Already done, or not available
if (state || !foundObject<FieldType>(inputName))
{
return state;
}
const FieldType& input = lookupObject<FieldType>(inputName);
word outputName(resultName_);
outputName.replace("@@", inputName);
results_.set(outputName);
if (!foundObject<volScalarField>(outputName))
{
tmp<volScalarField> tddt2
(
new volScalarField
(
IOobject
(
outputName,
time_.timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar
(
"0",
(
mag_
? mag(input.dimensions()/dimTime)
: magSqr(input.dimensions()/dimTime)
),
Zero
)
)
);
store(outputName, tddt2);
}
volScalarField& output =
const_cast<volScalarField&>(lookupObject<volScalarField>(outputName));
if (mag_)
{
output = mag(fvc::ddt(input));
}
else
{
output = magSqr(fvc::ddt(input));
}
// Could add additional statistics here
Log << type() << ' ' << name()
<< " field " << outputName
<< " average: " << gAverage(output) << endl;
state = +1;
return state;
}
// ************************************************************************* //

View File

@ -0,0 +1,75 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "div.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(div, 0);
addToRunTimeSelectionTable(functionObject, div, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::div::calc()
{
bool processed = false;
processed = processed || calcDiv<surfaceScalarField>();
processed = processed || calcDiv<volVectorField>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::div::div
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::div::~div()
{}
// ************************************************************************* //

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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::div
Group
grpFieldFunctionObjects
Description
Calculates the divergence of a field. The operation is limited to
surfaceScalarFields and volVectorFields, and the output is a volScalarField.
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
div.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_div_H
#define functionObjects_div_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class div Declaration
\*---------------------------------------------------------------------------*/
class div
:
public fieldExpression
{
// Private Member Functions
//- Calculate the divergence of either a
// volScalarField or a surfaceScalarField and register the result
template<class FieldType>
bool calcDiv();
//- Calculate the divergence field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("div");
// Constructors
//- Construct from Time and dictionary
div
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~div();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "divTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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 "fvcDiv.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class FieldType>
bool Foam::functionObjects::div::calcDiv()
{
if (foundObject<FieldType>(fieldName_))
{
return store
(
resultName_,
fvc::div(lookupObject<FieldType>(fieldName_))
);
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,33 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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/>.
\defgroup grpFieldFunctionObjects Field function objects
@{
\ingroup grpFunctionObjects
This group contains field-based function objects
Function objects in this group are packaged into the
libfieldFunctionObjects.so library.
@}
\*---------------------------------------------------------------------------*/

View File

@ -0,0 +1,90 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "enstrophy.H"
#include "fvcCurl.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(enstrophy, 0);
addToRunTimeSelectionTable
(
functionObject,
enstrophy,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::enstrophy::calc()
{
if (foundObject<volVectorField>(fieldName_))
{
return store
(
resultName_,
0.5*magSqr(fvc::curl(lookupObject<volVectorField>(fieldName_)))
);
}
else
{
return false;
}
return true;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::enstrophy::enstrophy
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U")
{
setResultName(typeName, "U");
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::enstrophy::~enstrophy()
{}
// ************************************************************************* //

View File

@ -0,0 +1,99 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::enstrophy
Group
grpFieldFunctionObjects
Description
Calculates the enstrophy of the velocity.
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
enstrophy.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_enstrophy_H
#define functionObjects_enstrophy_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class enstrophy Declaration
\*---------------------------------------------------------------------------*/
class enstrophy
:
public fieldExpression
{
// Private Member Functions
//- Calculate the enstrophy field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("enstrophy");
// Constructors
//- Construct from Time and dictionary
enstrophy
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~enstrophy();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,363 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify i
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::externalCoupled
Group
grpFieldFunctionObjects
Description
This functionObject provides a simple interface for explicit coupling with
an external application. The coupling is through plain text files
where OpenFOAM boundary data is read/written as one line per face
(data from all processors collated):
# Patch: <patch name>
<fld1> <fld2> .. <fldn> //face0
<fld1> <fld2> .. <fldn> //face1
..
<fld1> <fld2> .. <fldn> //faceN
where the actual entries depend on the bc type:
- mixed: value, snGrad, refValue, refGrad, valueFraction
- externalCoupledMixed: output of writeData
- other: value, snGrad
These text files are located in a user specified communications directory
which gets read/written on the master processor only. In the
communications directory the structure will be
<regionsName>/<patchGroup>/<fieldName>.[in|out]
(where regionsName is either the name of a single region or a composite
of multiple region names)
At start-up, the boundary creates a lock file, i.e..
OpenFOAM.lock
... to signal the external source to wait. During the functionObject
execution the boundary values are written to files (one per region,
per patch(group), per field), e.g.
<regionsName>/<patchGroup>/<fieldName>.out
The lock file is then removed, instructing the external source to take
control of the program execution. When ready, the external program
should create the return values, e.g. to files
<regionsName>/<patchGroup>/<fieldName>.in
... and then re-instate the lock file. The functionObject will then
read these values, apply them to the boundary conditions and pass
program execution back to OpenFOAM.
Usage
\verbatim
externalCoupled
{
type externalCoupled;
...
log yes;
commsDir "${FOAM_CASE}/comms";
initByExternal yes;
regions
{
"(region1|region0)" // Name of region(s)
{
TPatchGroup // Name of patch(group)
{
readFields (p); // List of fields to read
writeFields (T); // List of fields to write
}
}
}
}
\endverbatim
This reads/writes (on the master processor) the directory:
comms/region0_region1/TPatchGroup/
with contents:
patchPoints (collected points)
patchFaces (collected faces)
p.in (input file of p, written by external application)
T.out (output file of T, written by OpenFOAM)
The patchPoints/patchFaces files denote the (collated) geometry
which will be written if it does not exist yet or can be written as
a preprocessing step using the createExternalCoupledPatchGeometry
application.
SourceFiles
externalCoupledTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_externalCoupled_H
#define functionObjects_externalCoupled_H
#include "functionObject.H"
#include "DynamicList.H"
#include "wordReList.H"
#include "scalarField.H"
#include "Switch.H"
#include "UPtrList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class fvMesh;
class IFstream;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class externalCoupled Declaration
\*---------------------------------------------------------------------------*/
class externalCoupled
:
public functionObject
{
// Private data
//- Reference to the time database
const Time& time_;
//- Switch for the execution - defaults to 'yes/on'
Switch enabled_;
//- Path to communications directory
fileName commsDir_;
//- Interval time between checking for return data [s]
label waitInterval_;
//- Time out time [s]
label timeOut_;
//- Calculation frequency
label calcFrequency_;
//- Flag to indicate values are initialised by external application
bool initByExternal_;
//- Names of (composite) regions
DynamicList<word> regionGroupNames_;
// Per (composite) region the names of the regions
DynamicList<wordList> regionGroupRegions_;
// Per (composite) region the indices of the group information
HashTable<labelList> regionToGroups_;
// Per group the names of the patches/patchGroups
DynamicList<wordRe> groupNames_;
// Per group the names of the fields to read
DynamicList<wordList> groupReadFields_;
// Per group the names of the fields to write
DynamicList<wordList> groupWriteFields_;
//- Initialised flag
bool initialised_;
// Private Member Functions
//- Return the file path to the communications directory for the region
static fileName groupDir
(
const fileName& commsDir,
const word& regionsName,
const wordRe& groupName
);
//- Return the file path to the base communications directory
fileName baseDir() const;
//- Return the file path to the lock file
fileName lockFile() const;
//- Create lock file
void createLockFile() const;
//- Remove lock file
void removeLockFile() const;
//- Remove files written by OpenFOAM
void removeWriteFiles() const;
//- Remove files written by external code
void removeReadFiles() const;
//- Wait for response from external source
void wait() const;
//- Read data for a single region, single field
template<class Type>
bool readData
(
const UPtrList<const fvMesh>& meshes,
const wordRe& groupName,
const word& fieldName
);
//- Read data for all regions, all fields
void readData();
//- Write data for a single region, single field
template<class Type>
bool writeData
(
const UPtrList<const fvMesh>& meshes,
const wordRe& groupName,
const word& fieldName
) const;
//- Write data for all regions, all fields
void writeData() const;
void initialise();
//- Read (and distribute) scalar columns from stream. Every processor
// gets nRows (= patch size) of these. Note: could make its argument
// ISstream& but then would need additional logic to construct valid
// stream on all processors.
void readColumns
(
const label nRows,
const label nColumns,
autoPtr<IFstream>& masterFilePtr,
List<scalarField>& data
) const;
//- Read (and distribute) lines from stream. Every processor
// gets nRows (= patch size) of these. Data kept as stream (instead
// of strings) for ease of interfacing to readData routines that take
// an Istream.
void readLines
(
const label nRows,
autoPtr<IFstream>& masterFilePtr,
OStringStream& data
) const;
//- Helper: append data from all processors onto master
template<class Type>
static tmp<Field<Type>> gatherAndCombine(const Field<Type>& fld);
static void checkOrder(const wordList&);
//- Disallow default bitwise copy constructor
externalCoupled(const externalCoupled&) = delete;
//- Disallow default bitwise assignment
void operator=(const externalCoupled&) = delete;
public:
//- Runtime type information
TypeName("externalCoupled");
//- Name of lock file
static word lockName;
//- Name of patch key, e.g. '# Patch:' when looking for start of patch data
static string patchKey;
// Constructors
//- Construct given time and dictionary
externalCoupled
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~externalCoupled();
// Member Functions
// Function object control
//- Called at each ++ or += of the time-loop
virtual bool execute();
//- Called when Time::run() determines that the time-loop exits
virtual bool end();
//- Read and set the function object if its data have changed
virtual bool read(const dictionary&);
//- Write
virtual bool write();
// Other
//- Create single name by appending words (in sorted order),
// separated by '_'
static word compositeName(const wordList&);
//- Write geometry for the group/patch
static void writeGeometry
(
const UPtrList<const fvMesh>& meshes,
const fileName& commsDir,
const wordRe& groupName
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "externalCoupledTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,168 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 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 "externalCoupledMixedFvPatchField.H"
#include "fvPatchFieldMapper.H"
#include "ISstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::externalCoupledMixedFvPatchField<Type>::
externalCoupledMixedFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF
)
:
mixedFvPatchField<Type>(p, iF)
{
this->refValue() = Type(Zero);
this->refGrad() = Type(Zero);
this->valueFraction() = 0.0;
}
template<class Type>
Foam::externalCoupledMixedFvPatchField<Type>::
externalCoupledMixedFvPatchField
(
const externalCoupledMixedFvPatchField& ptf,
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
mixedFvPatchField<Type>(ptf, p, iF, mapper)
{}
template<class Type>
Foam::externalCoupledMixedFvPatchField<Type>::
externalCoupledMixedFvPatchField
(
const fvPatch& p,
const DimensionedField<Type, volMesh>& iF,
const dictionary& dict
)
:
mixedFvPatchField<Type>(p, iF, dict)
{}
template<class Type>
Foam::externalCoupledMixedFvPatchField<Type>::
externalCoupledMixedFvPatchField
(
const externalCoupledMixedFvPatchField& ecmpf
)
:
mixedFvPatchField<Type>(ecmpf)
{}
template<class Type>
Foam::externalCoupledMixedFvPatchField<Type>::
externalCoupledMixedFvPatchField
(
const externalCoupledMixedFvPatchField& ecmpf,
const DimensionedField<Type, volMesh>& iF
)
:
mixedFvPatchField<Type>(ecmpf, iF)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::externalCoupledMixedFvPatchField<Type>::
~externalCoupledMixedFvPatchField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::externalCoupledMixedFvPatchField<Type>::writeHeader
(
Ostream& os
) const
{
os << "# Values: value snGrad refValue refGrad valueFraction" << endl;
}
template<class Type>
void Foam::externalCoupledMixedFvPatchField<Type>::writeData
(
Ostream& os
) const
{
const Field<Type> snGrad(this->snGrad());
const Field<Type>& refValue(this->refValue());
const Field<Type>& refGrad(this->refGrad());
const scalarField& valueFraction(this->valueFraction());
forAll(refValue, facei)
{
os << this->operator[](facei) << token::SPACE
<< snGrad[facei] << token::SPACE
<< refValue[facei] << token::SPACE
<< refGrad[facei] << token::SPACE
<< valueFraction[facei] << nl;
}
}
template<class Type>
void Foam::externalCoupledMixedFvPatchField<Type>::readData(Istream& is)
{
// Assume generic input stream so we can do line-based format and skip
// unused columns
ISstream& iss = dynamic_cast<ISstream&>(is);
string line;
forAll(*this, facei)
{
iss.getLine(line);
IStringStream lineStr(line);
// For symmetry with writing ignore value, snGrad columns
Type value, snGrad;
lineStr
>> value
>> snGrad
>> this->refValue()[facei]
>> this->refGrad()[facei]
>> this->valueFraction()[facei];
}
}
// ************************************************************************* //

View File

@ -0,0 +1,174 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 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::externalCoupledMixedFvPatchField
Group
grpGenericBoundaryConditions grpCoupledBoundaryConditions
Description
This boundary condition extends the mixed boundary condition with
serialisation through
- writeHeader
- writeData
- readData
functions. It is used for coupling to external applications in combination
with the externalCoupled functionObject. The default output is one
line per face, with columns
<value> <snGrad> <refValue> <refGrad> <valueFraction>
Notes
readData,writeData are not callbacks for regIOobject (since fvPatchField
not derived from it). They do however do exactly the same - streaming of
data.
SeeAlso
mixedFvPatchField
externalCoupledFunctionObject
SourceFiles
externalCoupledMixedFvPatchField.C
\*---------------------------------------------------------------------------*/
#ifndef externalCoupledMixedFvPatchField_H
#define externalCoupledMixedFvPatchField_H
#include "mixedFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class externalCoupledMixedFvPatchField Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class externalCoupledMixedFvPatchField
:
public mixedFvPatchField<Type>
{
public:
//- Runtime type information
TypeName("externalCoupled");
// Constructors
//- Construct from patch and internal field
externalCoupledMixedFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&
);
//- Construct from patch, internal field and dictionary
externalCoupledMixedFvPatchField
(
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const dictionary&
);
//- Construct by mapping given externalCoupledMixedFvPatchField
// onto a new patch
externalCoupledMixedFvPatchField
(
const externalCoupledMixedFvPatchField<Type>&,
const fvPatch&,
const DimensionedField<Type, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
externalCoupledMixedFvPatchField
(
const externalCoupledMixedFvPatchField&
);
//- Construct and return a clone
virtual tmp<fvPatchField<Type>> clone() const
{
return tmp<fvPatchField<Type>>
(
new externalCoupledMixedFvPatchField<Type>(*this)
);
}
//- Construct as copy setting internal field reference
externalCoupledMixedFvPatchField
(
const externalCoupledMixedFvPatchField&,
const DimensionedField<Type, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchField<Type>> clone
(
const DimensionedField<Type, volMesh>& iF
) const
{
return tmp<fvPatchField<Type>>
(
new externalCoupledMixedFvPatchField<Type>(*this, iF)
);
}
//- Destructor
virtual ~externalCoupledMixedFvPatchField();
// Member functions
//- Write header
virtual void writeHeader(Ostream&) const;
//- Write data
virtual void writeData(Ostream&) const;
//- Read data
virtual void readData(Istream&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "externalCoupledMixedFvPatchField.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 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 "externalCoupledMixedFvPatchFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makePatchFields(externalCoupledMixed);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 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/>.
\*---------------------------------------------------------------------------*/
#ifndef externalCoupledMixedFvPatchFields_H
#define externalCoupledMixedFvPatchFields_H
#include "externalCoupledMixedFvPatchField.H"
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
makePatchTypeFieldTypedefs(externalCoupledMixed);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2015 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/>.
\*---------------------------------------------------------------------------*/
#ifndef externalCoupledMixedFvPatchFieldsFwd_H
#define externalCoupledMixedFvPatchFieldsFwd_H
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> class externalCoupledMixedFvPatchField;
makePatchTypeFieldTypedefs(externalCoupledMixed);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,250 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "externalCoupledTemperatureMixedFvPatchScalarField.H"
#include "turbulentFluidThermoModel.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "volFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeHeader
(
Ostream& os
) const
{
os << "# Values: magSf T qDot htc" << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF
)
:
externalCoupledMixedFvPatchField<scalar>(p, iF)
{}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField& ptf,
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const fvPatchFieldMapper& mapper
)
:
externalCoupledMixedFvPatchField<scalar>(ptf, p, iF, mapper)
{}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch& p,
const DimensionedField<scalar, volMesh>& iF,
const dictionary& dict
)
:
//externalCoupledMixedFvPatchField<scalar>(p, iF, dict)
externalCoupledMixedFvPatchField<scalar>(p, iF)
{
if (dict.found("refValue"))
{
// Initialise same way as mixed
this->refValue() = scalarField("refValue", dict, p.size());
this->refGrad() = scalarField("refGradient", dict, p.size());
this->valueFraction() = scalarField("valueFraction", dict, p.size());
evaluate();
}
else
{
// For convenience: initialise as fixedValue with either read value
// or extrapolated value
if (dict.found("value"))
{
fvPatchField<scalar>::operator=
(
scalarField("value", dict, p.size())
);
}
else
{
fvPatchField<scalar>::operator=(this->patchInternalField());
}
// Initialise as a fixed value
this->refValue() = *this;
this->refGrad() = Zero;
this->valueFraction() = 1.0;
}
}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField& ecmpf
)
:
externalCoupledMixedFvPatchField<scalar>(ecmpf)
{}
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField& ecmpf,
const DimensionedField<scalar, volMesh>& iF
)
:
externalCoupledMixedFvPatchField<scalar>(ecmpf, iF)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::externalCoupledTemperatureMixedFvPatchScalarField::
~externalCoupledTemperatureMixedFvPatchScalarField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::writeData
(
Ostream& os
) const
{
const label patchi = patch().index();
// Heat flux [W/m2]
scalarField qDot(this->patch().size(), 0.0);
typedef compressible::turbulenceModel cmpTurbModelType;
static word turbName
(
IOobject::groupName
(
turbulenceModel::propertiesName,
internalField().group()
)
);
static word thermoName("thermophysicalProperties");
if (db().foundObject<cmpTurbModelType>(turbName))
{
const cmpTurbModelType& turbModel =
db().lookupObject<cmpTurbModelType>(turbName);
const basicThermo& thermo = turbModel.transport();
const fvPatchScalarField& hep = thermo.he().boundaryField()[patchi];
qDot = turbModel.alphaEff(patchi)*hep.snGrad();
}
else if (db().foundObject<basicThermo>(thermoName))
{
const basicThermo& thermo = db().lookupObject<basicThermo>(thermoName);
const fvPatchScalarField& hep = thermo.he().boundaryField()[patchi];
qDot = thermo.alpha().boundaryField()[patchi]*hep.snGrad();
}
else
{
FatalErrorInFunction
<< "Condition requires either compressible turbulence and/or "
<< "thermo model to be available" << exit(FatalError);
}
// Patch temperature [K]
const scalarField& Tp(*this);
// Near wall cell temperature [K]
const scalarField Tc(patchInternalField());
// Heat transfer coefficient [W/m2/K]
const scalarField htc(qDot/(Tp - Tc + ROOTVSMALL));
const Field<scalar>& magSf(this->patch().magSf());
forAll(patch(), facei)
{
os << magSf[facei] << token::SPACE
<< Tp[facei] << token::SPACE
<< qDot[facei] << token::SPACE
<< htc[facei] << token::SPACE
<< nl;
}
}
void Foam::externalCoupledTemperatureMixedFvPatchScalarField::readData
(
Istream& is
)
{
// Assume generic input stream so we can do line-based format and skip
// unused columns
ISstream& iss = dynamic_cast<ISstream&>(is);
string line;
forAll(*this, facei)
{
iss.getLine(line);
IStringStream lineStr(line);
lineStr
>> this->refValue()[facei]
>> this->refGrad()[facei]
>> this->valueFraction()[facei];
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchScalarField,
externalCoupledTemperatureMixedFvPatchScalarField
);
}
// ************************************************************************* //

View File

@ -0,0 +1,201 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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::externalCoupledTemperatureMixedFvPatchScalarField
Group
grpCoupledBoundaryConditions
Description
This boundary condition provides a temperatue interface to an external
application. Values are transferred as plain text files, where OpenFOAM
data is written as:
# Patch: \<patch name\>
\<magSf1\> \<value1\> \<qDot1\> \<htc1\>
\<magSf2\> \<value2\> \<qDot2\> \<htc2\>
\<magSf3\> \<value3\> \<qDot3\> \<htc2\>
...
\<magSfN\> \<valueN\> \<qDotN\> \<htcN\>
and received as the constituent pieces of the `mixed' condition, i.e.
# Patch: \<patch name\>
\<value1\> \<gradient1\> \<valueFracion1\>
\<value2\> \<gradient2\> \<valueFracion2\>
\<value3\> \<gradient3\> \<valueFracion3\>
...
\<valueN\> \<gradientN\> \<valueFracionN\>
Data is sent/received as a single file for all patches from the directory
$FOAM_CASE/\<commsDir\>
At start-up, the boundary creates a lock file, i.e..
OpenFOAM.lock
... to signal the external source to wait. During the boundary condition
update, boundary values are written to file, e.g.
\<fileName\>.out
The lock file is then removed, instructing the external source to take
control of the program execution. When ready, the external program
should create the return values, e.g. to file
\<fileName\>.in
... and then re-instate the lock file. The boundary condition will then
read the return values, and pass program execution back to OpenFOAM.
To be used in combination with the externalCoupled functionObject.
SeeAlso
externalCoupledFunctionObject
mixedFvPatchField
externalCoupledMixedFvPatchField
SourceFiles
externalCoupledTemperatureMixedFvPatchScalarField.C
\*---------------------------------------------------------------------------*/
#ifndef externalCoupledTemperatureMixedFvPatchScalarField_H
#define externalCoupledTemperatureMixedFvPatchScalarField_H
#include "externalCoupledMixedFvPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class externalCoupledTemperatureMixedFvPatchScalarField Declaration
\*---------------------------------------------------------------------------*/
class externalCoupledTemperatureMixedFvPatchScalarField
:
public externalCoupledMixedFvPatchField<scalar>
{
public:
//- Runtime type information
TypeName("externalCoupledTemperature");
// Constructors
//- Construct from patch and internal field
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&
);
//- Construct from patch, internal field and dictionary
externalCoupledTemperatureMixedFvPatchScalarField
(
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const dictionary&
);
//- Construct by mapping given
// externalCoupledTemperatureMixedFvPatchScalarField onto a new patch
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField&,
const fvPatch&,
const DimensionedField<scalar, volMesh>&,
const fvPatchFieldMapper&
);
//- Construct as copy
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField&
);
//- Construct and return a clone
virtual tmp<fvPatchField<scalar>> clone() const
{
return tmp<fvPatchField<scalar>>
(
new externalCoupledTemperatureMixedFvPatchScalarField(*this)
);
}
//- Construct as copy setting internal field reference
externalCoupledTemperatureMixedFvPatchScalarField
(
const externalCoupledTemperatureMixedFvPatchScalarField&,
const DimensionedField<scalar, volMesh>&
);
//- Construct and return a clone setting internal field reference
virtual tmp<fvPatchField<scalar>> clone
(
const DimensionedField<scalar, volMesh>& iF
) const
{
return tmp<fvPatchField<scalar>>
(
new externalCoupledTemperatureMixedFvPatchScalarField
(
*this,
iF
)
);
}
//- Destructor
virtual ~externalCoupledTemperatureMixedFvPatchScalarField();
// Member functions
//- Write header
virtual void writeHeader(Ostream&) const;
//- Write data
virtual void writeData(Ostream&) const;
//- Read data
virtual void readData(Istream&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,500 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify i
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 "externalCoupled.H"
//#include "fvMesh.H"
#include "OSspecific.H"
#include "IFstream.H"
#include "OFstream.H"
#include "volFields.H"
#include "externalCoupledMixedFvPatchFields.H"
#include "mixedFvPatchFields.H"
#include "fixedGradientFvPatchFields.H"
#include "fixedValueFvPatchFields.H"
#include "OStringStream.H"
#include "globalIndex.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::externalCoupled::readData
(
const UPtrList<const fvMesh>& meshes,
const wordRe& groupName,
const word& fieldName
)
{
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
wordList regionNames(meshes.size());
forAll(meshes, i)
{
regionNames[i] = meshes[i].dbDir();
}
// File only opened on master; contains data for all processors, for all
// patchIDs.
autoPtr<IFstream> masterFilePtr;
if (Pstream::master())
{
const fileName transferFile
(
groupDir(commsDir_, compositeName(regionNames), groupName)
/ fieldName + ".in"
);
Log << type() << ": reading data from " << transferFile << endl;
masterFilePtr.reset(new IFstream(transferFile));
if (!masterFilePtr().good())
{
FatalIOErrorInFunction(masterFilePtr())
<< "Cannot open file for region " << compositeName(regionNames)
<< ", field " << fieldName
<< exit(FatalIOError);
}
}
label nFound = 0;
forAll(meshes, i)
{
const fvMesh& mesh = meshes[i];
if (!mesh.foundObject<volFieldType>(fieldName))
{
continue;
}
nFound++;
const volFieldType& cvf = mesh.lookupObject<volFieldType>(fieldName);
const typename volFieldType::Boundary& bf = cvf.boundaryField();
// Get the patches
const labelList patchIDs
(
mesh.boundaryMesh().patchSet
(
List<wordRe>(1, groupName)
).sortedToc()
);
// Handle column-wise reading of patch data. Supports most easy types
forAll(patchIDs, i)
{
label patchi = patchIDs[i];
if (isA<patchFieldType>(bf[patchi]))
{
// Explicit handling of externalCoupledMixed bcs - they
// have specialised reading routines.
patchFieldType& pf = const_cast<patchFieldType&>
(
refCast<const patchFieldType>
(
bf[patchi]
)
);
// Read from master into local stream
OStringStream os;
readLines
(
bf[patchi].size(), // number of lines to read
masterFilePtr,
os
);
// Pass responsability for all reading over to bc
pf.readData(IStringStream(os.str())());
// Update the value from the read coefficicient. Bypass any
// additional processing by derived type.
pf.patchFieldType::evaluate();
}
else if (isA<mixedFvPatchField<Type>>(bf[patchi]))
{
// Read columns from file for
// value, snGrad, refValue, refGrad, valueFraction
List<scalarField> data;
readColumns
(
bf[patchi].size(), // number of lines to read
4*pTraits<Type>::nComponents+1, // nColumns: 4*Type+1*scalar
masterFilePtr,
data
);
mixedFvPatchField<Type>& pf =
const_cast<mixedFvPatchField<Type>&>
(
refCast<const mixedFvPatchField<Type>>
(
bf[patchi]
)
);
// Transfer read data to bc.
// Skip value, snGrad
direction columni = 2*pTraits<Type>::nComponents;
Field<Type>& refValue = pf.refValue();
for
(
direction cmpt = 0;
cmpt < pTraits<Type>::nComponents;
cmpt++
)
{
refValue.replace(cmpt, data[columni++]);
}
Field<Type>& refGrad = pf.refGrad();
for
(
direction cmpt = 0;
cmpt < pTraits<Type>::nComponents;
cmpt++
)
{
refGrad.replace(cmpt, data[columni++]);
}
pf.valueFraction() = data[columni];
// Update the value from the read coefficicient. Bypass any
// additional processing by derived type.
pf.mixedFvPatchField<Type>::evaluate();
}
else if (isA<fixedGradientFvPatchField<Type>>(bf[patchi]))
{
// Read columns for value and gradient
List<scalarField> data;
readColumns
(
bf[patchi].size(), // number of lines to read
2*pTraits<Type>::nComponents, // nColumns: Type
masterFilePtr,
data
);
fixedGradientFvPatchField<Type>& pf =
const_cast<fixedGradientFvPatchField<Type>&>
(
refCast<const fixedGradientFvPatchField<Type>>
(
bf[patchi]
)
);
// Transfer gradient to bc
Field<Type>& gradient = pf.gradient();
for
(
direction cmpt = 0;
cmpt < pTraits<Type>::nComponents;
cmpt++
)
{
gradient.replace
(
cmpt,
data[pTraits<Type>::nComponents+cmpt]
);
}
// Update the value from the read coefficicient. Bypass any
// additional processing by derived type.
pf.fixedGradientFvPatchField<Type>::evaluate();
}
else if (isA<fixedValueFvPatchField<Type>>(bf[patchi]))
{
// Read columns for value only
List<scalarField> data;
readColumns
(
bf[patchi].size(), // number of lines to read
pTraits<Type>::nComponents, // number of columns to read
masterFilePtr,
data
);
// Transfer read value to bc
Field<Type> value(bf[patchi].size());
for
(
direction cmpt = 0;
cmpt < pTraits<Type>::nComponents;
cmpt++
)
{
value.replace(cmpt, data[cmpt]);
}
fixedValueFvPatchField<Type>& pf =
const_cast<fixedValueFvPatchField<Type>&>
(
refCast<const fixedValueFvPatchField<Type>>
(
bf[patchi]
)
);
pf == value;
// Update the value from the read coefficicient. Bypass any
// additional processing by derived type.
pf.fixedValueFvPatchField<Type>::evaluate();
}
else
{
FatalErrorInFunction
<< "Unsupported boundary condition " << bf[patchi].type()
<< " for patch " << bf[patchi].patch().name()
<< " in region " << mesh.name()
<< exit(FatalError);
}
initialised_ = true;
}
}
return nFound > 0;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::externalCoupled::gatherAndCombine
(
const Field<Type>& fld
)
{
// Collect values from all processors
List<Field<Type>> gatheredValues(Pstream::nProcs());
gatheredValues[Pstream::myProcNo()] = fld;
Pstream::gatherList(gatheredValues);
tmp<Field<Type>> tresult(new Field<Type>(0));
Field<Type>& result = tresult.ref();
if (Pstream::master())
{
// Combine values into single field
label globalElemi = 0;
forAll(gatheredValues, lsti)
{
globalElemi += gatheredValues[lsti].size();
}
result.setSize(globalElemi);
globalElemi = 0;
forAll(gatheredValues, lsti)
{
const Field<Type>& sub = gatheredValues[lsti];
forAll(sub, elemi)
{
result[globalElemi++] = sub[elemi];
}
}
}
return tresult;
}
template<class Type>
bool Foam::functionObjects::externalCoupled::writeData
(
const UPtrList<const fvMesh>& meshes,
const wordRe& groupName,
const word& fieldName
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> volFieldType;
typedef externalCoupledMixedFvPatchField<Type> patchFieldType;
wordList regionNames(meshes.size());
forAll(meshes, i)
{
regionNames[i] = meshes[i].dbDir();
}
// File only opened on master; contains data for all processors, for all
// patchIDs
autoPtr<OFstream> masterFilePtr;
if (Pstream::master())
{
const fileName transferFile
(
groupDir(commsDir_, compositeName(regionNames), groupName)
/ fieldName + ".out"
);
Log << type() << ": writing data to " << transferFile << endl;
masterFilePtr.reset(new OFstream(transferFile));
if (!masterFilePtr().good())
{
FatalIOErrorInFunction(masterFilePtr())
<< "Cannot open file for region " << compositeName(regionNames)
<< ", field " << fieldName
<< exit(FatalIOError);
}
}
bool headerDone = false;
label nFound = 0;
forAll(meshes, i)
{
const fvMesh& mesh = meshes[i];
if (!mesh.foundObject<volFieldType>(fieldName))
{
continue;
}
nFound++;
const volFieldType& cvf = mesh.lookupObject<volFieldType>(fieldName);
const typename volFieldType::Boundary& bf = cvf.boundaryField();
// Get the patches
const labelList patchIDs
(
mesh.boundaryMesh().patchSet
(
List<wordRe>(1, groupName)
).sortedToc()
);
// Handle column-wise writing of patch data. Supports most easy types
forAll(patchIDs, i)
{
label patchi = patchIDs[i];
const globalIndex globalFaces(bf[patchi].size());
if (isA<patchFieldType>(bf[patchi]))
{
// Explicit handling of externalCoupledMixed bcs - they
// have specialised writing routines
const patchFieldType& pf = refCast<const patchFieldType>
(
bf[patchi]
);
OStringStream os;
// Pass responsibility for all writing over to bc
pf.writeData(os);
// Collect contributions from all processors and output them on
// master
if (Pstream::master())
{
// Output master data first
if (!headerDone)
{
pf.writeHeader(masterFilePtr());
headerDone = true;
}
masterFilePtr() << os.str().c_str();
for (label proci = 1; proci < Pstream::nProcs(); proci++)
{
IPstream fromSlave(Pstream::scheduled, proci);
string str(fromSlave);
masterFilePtr() << str.c_str();
}
}
else
{
OPstream toMaster(Pstream::scheduled, Pstream::masterNo());
toMaster << os.str();
}
}
else if (isA<mixedFvPatchField<Type>>(bf[patchi]))
{
const mixedFvPatchField<Type>& pf =
refCast<const mixedFvPatchField<Type>>(bf[patchi]);
Field<Type> value(gatherAndCombine(pf));
Field<Type> snGrad(gatherAndCombine(pf.snGrad()()));
Field<Type> refValue(gatherAndCombine(pf.refValue()));
Field<Type> refGrad(gatherAndCombine(pf.refGrad()));
scalarField valueFraction(gatherAndCombine(pf.valueFraction()));
if (Pstream::master())
{
forAll(refValue, facei)
{
masterFilePtr()
<< value[facei] << token::SPACE
<< snGrad[facei] << token::SPACE
<< refValue[facei] << token::SPACE
<< refGrad[facei] << token::SPACE
<< valueFraction[facei] << nl;
}
}
}
else
{
// Output the value and snGrad
Field<Type> value(gatherAndCombine(bf[patchi]));
Field<Type> snGrad(gatherAndCombine(bf[patchi].snGrad()()));
if (Pstream::master())
{
forAll(value, facei)
{
masterFilePtr()
<< value[facei] << token::SPACE
<< snGrad[facei] << nl;
}
}
}
}
}
return nFound > 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,331 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldAverage.H"
#include "volFields.H"
#include "fieldAverageItem.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fieldAverage, 0);
addToRunTimeSelectionTable(functionObject, fieldAverage, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldAverage::resetFields()
{
forAll(faItems_, i)
{
if (faItems_[i].mean())
{
if (obr_.found(faItems_[i].meanFieldName()))
{
obr_.checkOut(*obr_[faItems_[i].meanFieldName()]);
}
}
if (faItems_[i].prime2Mean())
{
if (obr_.found(faItems_[i].prime2MeanFieldName()))
{
obr_.checkOut(*obr_[faItems_[i].prime2MeanFieldName()]);
}
}
}
}
void Foam::functionObjects::fieldAverage::initialize()
{
resetFields();
Log << type() << " " << name() << ":" << nl;
// Add mean fields to the field lists
forAll(faItems_, fieldi)
{
addMeanField<scalar>(fieldi);
addMeanField<vector>(fieldi);
addMeanField<sphericalTensor>(fieldi);
addMeanField<symmTensor>(fieldi);
addMeanField<tensor>(fieldi);
}
// Add prime-squared mean fields to the field lists
forAll(faItems_, fieldi)
{
addPrime2MeanField<scalar, scalar>(fieldi);
addPrime2MeanField<vector, symmTensor>(fieldi);
}
forAll(faItems_, fieldi)
{
if (!faItems_[fieldi].active())
{
WarningInFunction
<< "Field " << faItems_[fieldi].fieldName()
<< " not found in database for averaging";
}
}
// ensure first averaging works unconditionally
prevTimeIndex_ = -1;
Log << endl;
initialised_ = true;
}
void Foam::functionObjects::fieldAverage::restart()
{
Log
<< " Restarting averaging at time " << obr_.time().timeName()
<< nl << endl;
totalIter_.clear();
totalIter_.setSize(faItems_.size(), 1);
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
initialize();
}
void Foam::functionObjects::fieldAverage::calcAverages()
{
if (!initialised_)
{
initialize();
}
const label currentTimeIndex = obr_.time().timeIndex();
const scalar currentTime = obr_.time().value();
if (prevTimeIndex_ == currentTimeIndex)
{
return;
}
else
{
prevTimeIndex_ = currentTimeIndex;
}
if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_)
{
restart();
periodIndex_++;
}
Log
<< type() << " " << name() << " write:" << nl
<< " Calculating averages" << nl;
addMeanSqrToPrime2Mean<scalar, scalar>();
addMeanSqrToPrime2Mean<vector, symmTensor>();
calculateMeanFields<scalar>();
calculateMeanFields<vector>();
calculateMeanFields<sphericalTensor>();
calculateMeanFields<symmTensor>();
calculateMeanFields<tensor>();
calculatePrime2MeanFields<scalar, scalar>();
calculatePrime2MeanFields<vector, symmTensor>();
forAll(faItems_, fieldi)
{
totalIter_[fieldi]++;
totalTime_[fieldi] += obr_.time().deltaTValue();
}
Log << endl;
}
void Foam::functionObjects::fieldAverage::writeAverages() const
{
Log << " Writing average fields" << endl;
writeFields<scalar>();
writeFields<vector>();
writeFields<sphericalTensor>();
writeFields<symmTensor>();
writeFields<tensor>();
Log << endl;
}
void Foam::functionObjects::fieldAverage::writeAveragingProperties()
{
forAll(faItems_, fieldi)
{
const word& fieldName = faItems_[fieldi].fieldName();
dictionary propsDict;
propsDict.add("totalIter", totalIter_[fieldi]);
propsDict.add("totalTime", totalTime_[fieldi]);
setProperty(fieldName, propsDict);
}
}
void Foam::functionObjects::fieldAverage::readAveragingProperties()
{
totalIter_.clear();
totalIter_.setSize(faItems_.size(), 1);
totalTime_.clear();
totalTime_.setSize(faItems_.size(), obr_.time().deltaTValue());
if ((restartOnRestart_ || restartOnOutput_) && log)
{
Info<< " Starting averaging at time " << obr_.time().timeName()
<< nl;
}
else
{
Log << " Restarting averaging for fields:" << nl;
forAll(faItems_, fieldi)
{
const word& fieldName = faItems_[fieldi].fieldName();
if (foundProperty(fieldName))
{
dictionary fieldDict;
getProperty(fieldName, fieldDict);
totalIter_[fieldi] = readLabel(fieldDict.lookup("totalIter"));
totalTime_[fieldi] = readScalar(fieldDict.lookup("totalTime"));
Log
<< " " << fieldName
<< " iters = " << totalIter_[fieldi]
<< " time = " << totalTime_[fieldi] << nl;
}
else
{
Log
<< " " << fieldName
<< ": starting averaging at time "
<< obr_.time().timeName() << endl;
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldAverage::fieldAverage
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
prevTimeIndex_(-1),
restartOnRestart_(false),
restartOnOutput_(false),
periodicRestart_(false),
restartPeriod_(GREAT),
initialised_(false),
faItems_(),
totalIter_(),
totalTime_(),
periodIndex_(1)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldAverage::~fieldAverage()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldAverage::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
initialised_ = false;
Log << type() << " " << name() << ":" << nl;
dict.readIfPresent("restartOnRestart", restartOnRestart_);
dict.readIfPresent("restartOnOutput", restartOnOutput_);
dict.readIfPresent("periodicRestart", periodicRestart_);
dict.lookup("fields") >> faItems_;
if (periodicRestart_)
{
dict.lookup("restartPeriod") >> restartPeriod_;
}
readAveragingProperties();
Log << endl;
return true;
}
bool Foam::functionObjects::fieldAverage::execute()
{
calcAverages();
return true;
}
bool Foam::functionObjects::fieldAverage::write()
{
writeAverages();
writeAveragingProperties();
if (restartOnOutput_)
{
restart();
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,326 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fieldAverage
Group
grpFieldFunctionObjects
Description
Calculates average quantities for a user-specified selection of volumetric
and surface fields.
Fields are entered as a list of sub-dictionaries, which indicate the type of
averages to perform, and can be updated during the calculation. The current
options include:
- \c mean: arithmetic mean:
\f[
\overline{x} = \frac{1}{N}\displaystyle\sum\limits_{i=0}^N x_i
\f]
- \c prime2Mean: prime-squared mean
\f[
\overline{x'}^2 = \frac{1}{N}\displaystyle\sum\limits_{i=0}^N
(x_i - \overline{x})^2
\f]
- base: average over 'time', or 'iteration' (\f$N\f$ in the above)
- window: optional averaging window, specified in 'base' units
Average field names are constructed by concatenating the base field with
the averaging type, e.g. when averaging field 'U', the resultant fields
are:
- arithmetic mean field, UMean
- prime-squared field, UPrime2Mean
Information regarding the number of averaging steps, and total averaging
time are written on a per-field basis to the
\c "<functionObject name>Properties" dictionary, located in \<time\>/uniform
When restarting form a previous calculation, the averaging is continuous or
may be restarted using the \c restartOnRestart option.
The averaging process may be restarted after each calculation output time
using the \c restartOnOutput option or restarted periodically using the \c
periodicRestart option and setting \c restartPeriod to the required
averaging period.
Usage
\verbatim
fieldAverage1
{
type fieldAverage;
libs ("libfieldFunctionObjects.so");
writeControl writeTime;
restartOnRestart false;
restartOnOutput false;
periodicRestart false;
restartPeriod 0.002;
fields
(
U
{
mean on;
prime2Mean on;
base time;
window 10.0;
windowName w1;
}
p
{
mean on;
prime2Mean on;
base time;
}
);
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: fieldAverage | yes |
restartOnRestart| Restart the averaging on restart | no | no
restartOnOutput | Restart the averaging on output | no | no
periodicRestart | Periodically restart the averaging | no | no
restartPeriod | Periodic restart period | conditional |
fields | list of fields and averaging options | yes |
\endtable
Note
To employ the \c prime2Mean option, the \c mean option must be selecetd.
See also
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObject
SourceFiles
fieldAverage.C
fieldAverageTemplates.C
fieldAverageItem.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldAverage_H
#define functionObjects_fieldAverage_H
#include "fvMeshFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
// Forward declaration of classes
class fieldAverageItem;
/*---------------------------------------------------------------------------*\
Class fieldAverage Declaration
\*---------------------------------------------------------------------------*/
class fieldAverage
:
public fvMeshFunctionObject
{
protected:
// Protected data
//- Time at last call, prevents repeated averaging
label prevTimeIndex_;
//- Restart the averaging process on restart
Switch restartOnRestart_;
//- Restart the averaging process on output
Switch restartOnOutput_;
//- Periodically restart the averaging process
Switch periodicRestart_;
//- Restart period
scalar restartPeriod_;
//- Initialised flag
bool initialised_;
//- List of field average items, describing what averages to be
// calculated and output
List<fieldAverageItem> faItems_;
// Counters
//- Iteration steps counter
List<label> totalIter_;
//- Total time counter
List<scalar> totalTime_;
//- Index for periodic restart
label periodIndex_;
// Private Member Functions
// Initialisation routines
//- Checkout fields (causes deletion) from the database
// and reset lists
void resetFields();
//- Reset lists (clear existing values) and initialize averaging.
// Check requested field averages are valid, populate field lists
void initialize();
//- Restart averaging for restartOnOutput
void restart();
//- Add mean average field to database
template<class Type>
void addMeanFieldType(const label fieldi);
//- Add mean average field to database
template<class Type>
void addMeanField(const label fieldi);
//- Add prime-squared average field to database
template<class Type1, class Type2>
void addPrime2MeanFieldType(const label fieldi);
//- Add prime-squared average field to database
template<class Type1, class Type2>
void addPrime2MeanField(const label fieldi);
// Calculation functions
//- Main calculation routine
virtual void calcAverages();
//- Calculate mean average fields
template<class Type>
void calculateMeanFieldType(const label fieldi) const;
//- Calculate mean average fields
template<class Type>
void calculateMeanFields() const;
//- Calculate prime-squared average fields
template<class Type1, class Type2>
void calculatePrime2MeanFieldType(const label fieldi) const;
//- Calculate prime-squared average fields
template<class Type1, class Type2>
void calculatePrime2MeanFields() const;
//- Add mean-squared field value to prime-squared mean field
template<class Type1, class Type2>
void addMeanSqrToPrime2MeanType(const label fieldi) const;
//- Add mean-squared field value to prime-squared mean field
template<class Type1, class Type2>
void addMeanSqrToPrime2Mean() const;
// I-O
//- Write averages
virtual void writeAverages() const;
//- Write fields
template<class Type>
void writeFieldType(const word& fieldName) const;
//- Write fields
template<class Type>
void writeFields() const;
//- Write averaging properties - steps and time
void writeAveragingProperties();
//- Read averaging properties - steps and time
void readAveragingProperties();
//- Disallow default bitwise copy construct
fieldAverage(const fieldAverage&);
//- Disallow default bitwise assignment
void operator=(const fieldAverage&);
public:
//- Runtime type information
TypeName("fieldAverage");
// Constructors
//- Construct from Time and dictionary
fieldAverage
(
const word& name,
const Time& runTime,
const dictionary&
);
//- Destructor
virtual ~fieldAverage();
// Member Functions
//- Read the field average data
virtual bool read(const dictionary&);
//- Calculate the field averages
virtual bool execute();
//- Write the field averages
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldAverageTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,121 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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 "fieldAverageItem.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::word Foam::functionObjects::fieldAverageItem::EXT_MEAN
(
"Mean"
);
const Foam::word Foam::functionObjects::fieldAverageItem::EXT_PRIME2MEAN
(
"Prime2Mean"
);
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldAverageItem::baseType,
2
>::names[] = { "iteration", "time"};
const Foam::NamedEnum
<
Foam::functionObjects::fieldAverageItem::baseType,
2
> Foam::functionObjects::fieldAverageItem::baseTypeNames_;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldAverageItem::fieldAverageItem()
:
active_(false),
fieldName_("unknown"),
mean_(0),
meanFieldName_("unknown"),
prime2Mean_(0),
prime2MeanFieldName_("unknown"),
base_(ITER),
window_(-1.0),
windowName_("")
{}
Foam::functionObjects::fieldAverageItem::fieldAverageItem
(
const fieldAverageItem& faItem
)
:
active_(faItem.active_),
fieldName_(faItem.fieldName_),
mean_(faItem.mean_),
meanFieldName_(faItem.meanFieldName_),
prime2Mean_(faItem.prime2Mean_),
prime2MeanFieldName_(faItem.prime2MeanFieldName_),
base_(faItem.base_),
window_(faItem.window_),
windowName_(faItem.windowName_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldAverageItem::~fieldAverageItem()
{}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::functionObjects::fieldAverageItem::operator=
(
const fieldAverageItem& rhs
)
{
// Check for assignment to self
if (this == &rhs)
{
FatalErrorInFunction
<< "Attempted assignment to self" << nl
<< abort(FatalError);
}
// Set updated values
active_ = rhs.active_;
fieldName_ = rhs.fieldName_;
mean_ = rhs.mean_;
meanFieldName_ = rhs.meanFieldName_;
prime2Mean_ = rhs.prime2Mean_;
prime2MeanFieldName_ = rhs.prime2MeanFieldName_;
base_ = rhs.base_;
window_ = rhs.window_;
windowName_ = rhs.windowName_;
}
// ************************************************************************* //

View File

@ -0,0 +1,290 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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::fieldAverageItem
Description
Helper class to describe what form of averaging to apply. A set will be
applied to each base field in Foam::fieldAverage, of the form:
\verbatim
{
mean on;
prime2Mean on;
base time; // iteration
window 200; // optional averaging window
windowName w1; // optional window name (default = "")
}
\endverbatim
The averaging window corresponds to the averaging interval (iters or time)
If not specified, the averaging is over 'all iters/time'
SourceFiles
fieldAverageItem.C
fieldAverageItemIO.C
\*---------------------------------------------------------------------------*/
#ifndef fieldAverageItem_H
#define fieldAverageItem_H
#include "NamedEnum.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class Istream;
class Ostream;
namespace functionObjects
{
// Forward declaration of friend functions and operators
class fieldAverageItem;
Istream& operator>>(Istream&, fieldAverageItem&);
Ostream& operator<<(Ostream&, const fieldAverageItem&);
/*---------------------------------------------------------------------------*\
Class fieldAverageItem Declaration
\*---------------------------------------------------------------------------*/
class fieldAverageItem
{
public:
// Public data
// File and field name extensions
//- Mean average
static const word EXT_MEAN;
//- Prime-squared average
static const word EXT_PRIME2MEAN;
//- Enumeration defining the averaging base type
enum baseType
{
ITER,
TIME
};
private:
// Private data
//- Active flag
bool active_;
//- Field name
word fieldName_;
//- Compute mean flag
bool mean_;
//- Name of mean field
word meanFieldName_;
//- Compute prime-squared mean flag
bool prime2Mean_;
//- Name of prime-squared mean field
word prime2MeanFieldName_;
//- Averaging base type names
static const NamedEnum<baseType, 2> baseTypeNames_;
//- Averaging base type
baseType base_;
//- Averaging window - defaults to -1 for 'all iters/time'
scalar window_;
//- Averaging window name - defaults to 'window'
word windowName_;
public:
// Constructors
//- Construct null
fieldAverageItem();
//- Construct from Istream
fieldAverageItem(Istream&);
//- Construct as copy
fieldAverageItem(const fieldAverageItem&);
//- Destructor
~fieldAverageItem();
// Member Functions
// Access
//- Return const access to the active flag
bool active() const
{
return active_;
}
//- Return non-const access to the active flag
bool& active()
{
return active_;
}
//- Return const access to the field name
const word& fieldName() const
{
return fieldName_;
}
//- Return const access to the mean flag
bool mean() const
{
return mean_;
}
//- Return non-const access to the mean flag
bool& mean()
{
return mean_;
}
//- Return const access to the mean field name
const word& meanFieldName() const
{
return meanFieldName_;
}
//- Return const access to the prime-squared mean flag
bool prime2Mean() const
{
return prime2Mean_;
}
//- Return non-const access to the prime-squared mean flag
bool& prime2Mean()
{
return prime2Mean_;
}
//- Return const access to the prime-squared mean field name
const word& prime2MeanFieldName() const
{
return prime2MeanFieldName_;
}
//- Return averaging base type name
const word base() const
{
return baseTypeNames_[base_];
}
//- Return true if base is ITER
bool iterBase() const
{
return base_ == ITER;
}
//- Return true if base is time
bool timeBase() const
{
return base_ == TIME;
}
scalar window() const
{
return window_;
}
const word& windowName() const
{
return windowName_;
}
// Member Operators
void operator=(const fieldAverageItem&);
// Friend Operators
friend bool operator==
(
const fieldAverageItem& a,
const fieldAverageItem& b
)
{
return
a.active_ == b.active_
&& a.fieldName_ == b.fieldName_
&& a.mean_ == b.mean_
&& a.meanFieldName_ == b.meanFieldName_
&& a.prime2Mean_ == b.prime2Mean_
&& a.prime2MeanFieldName_ == b.prime2MeanFieldName_
&& a.base_ == b.base_
&& a.window_ == b.window_
&& a.windowName_ == b.windowName_;
}
friend bool operator!=
(
const fieldAverageItem& a,
const fieldAverageItem& b
)
{
return !(a == b);
}
// IOstream Operators
friend Istream& operator>>(Istream&, fieldAverageItem&);
friend Ostream& operator<<(Ostream&, const fieldAverageItem&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldAverageItem.H"
#include "IOstreams.H"
#include "dictionaryEntry.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldAverageItem::fieldAverageItem(Istream& is)
:
active_(false),
fieldName_("unknown"),
mean_(0),
meanFieldName_("unknown"),
prime2Mean_(0),
prime2MeanFieldName_("unknown"),
base_(ITER),
window_(-1.0)
{
is.check
(
"Foam::functionObjects::fieldAverageItem::fieldAverageItem"
"(Foam::Istream&)"
);
const dictionaryEntry entry(dictionary::null, is);
fieldName_ = entry.keyword();
mean_ = readBool(entry.lookup("mean"));
prime2Mean_ = readBool(entry.lookup("prime2Mean"));
base_ = baseTypeNames_[entry.lookup("base")];
window_ = entry.lookupOrDefault<scalar>("window", -1.0);
windowName_ = entry.lookupOrDefault<word>("windowName", "");
meanFieldName_ = fieldName_ + EXT_MEAN;
prime2MeanFieldName_ = fieldName_ + EXT_PRIME2MEAN;
if ((window_ > 0) && (windowName_ != ""))
{
meanFieldName_ = meanFieldName_ + "_" + windowName_;
prime2MeanFieldName_ = prime2MeanFieldName_ + "_" + windowName_;
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Istream& Foam::functionObjects::operator>>
(
Istream& is,
fieldAverageItem& faItem
)
{
is.check
(
"Foam::Istream& Foam::operator>>"
"(Foam::Istream&, Foam::functionObjects::fieldAverageItem&)"
);
const dictionaryEntry entry(dictionary::null, is);
faItem.active_ = false;
faItem.fieldName_ = entry.keyword();
faItem.mean_ = readBool(entry.lookup("mean"));
faItem.prime2Mean_ = readBool(entry.lookup("prime2Mean"));
faItem.base_ = faItem.baseTypeNames_[entry.lookup("base")];
faItem.window_ = entry.lookupOrDefault<scalar>("window", -1.0);
faItem.windowName_ = entry.lookupOrDefault<word>("windowName", "");
faItem.meanFieldName_ = faItem.fieldName_ + fieldAverageItem::EXT_MEAN;
faItem.prime2MeanFieldName_ =
faItem.fieldName_ + fieldAverageItem::EXT_PRIME2MEAN;
if ((faItem.window_ > 0) && (faItem.windowName_ != ""))
{
faItem.meanFieldName_ =
faItem.meanFieldName_ + "_" + faItem.windowName_;
faItem.prime2MeanFieldName_ =
faItem.prime2MeanFieldName_ + "_" + faItem.windowName_;
}
return is;
}
Foam::Ostream& Foam::functionObjects::operator<<
(
Ostream& os,
const fieldAverageItem& faItem
)
{
os.check
(
"Foam::Ostream& Foam::operator<<"
"(Foam::Ostream&, const Foam::functionObjects::fieldAverageItem&)"
);
os << faItem.fieldName_ << nl << token::BEGIN_BLOCK << nl;
os.writeKeyword("mean") << faItem.mean_ << token::END_STATEMENT << nl;
os.writeKeyword("prime2Mean") << faItem.prime2Mean_
<< token::END_STATEMENT << nl;
os.writeKeyword("base") << faItem.baseTypeNames_[faItem.base_]
<< token::END_STATEMENT << nl;
if (faItem.window_ > 0)
{
os.writeKeyword("window") << faItem.window_
<< token::END_STATEMENT << nl;
if (faItem.windowName_ != "")
{
os.writeKeyword("windowName") << faItem.windowName_
<< token::END_STATEMENT << nl;
}
}
os << token::END_BLOCK << nl;
os.check
(
"Foam::Ostream& Foam::operator<<"
"(Foam::Ostream&, const Foam::functionObjects::fieldAverageItem&)"
);
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,414 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldAverageItem.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "OFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fieldAverage::addMeanFieldType(const label fieldi)
{
// Field has been found, so set active flag to true
faItems_[fieldi].active() = true;
const word& fieldName = faItems_[fieldi].fieldName();
const word& meanFieldName = faItems_[fieldi].meanFieldName();
Log << " Reading/initialising field " << meanFieldName << endl;
if (obr_.foundObject<Type>(meanFieldName))
{
// do nothing
}
else if (obr_.found(meanFieldName))
{
Log << " Cannot allocate average field " << meanFieldName
<< " since an object with that name already exists."
<< " Disabling averaging for field." << endl;
faItems_[fieldi].mean() = false;
}
else
{
const Type& baseField = obr_.lookupObject<Type>(fieldName);
// Store on registry
obr_.store
(
new Type
(
IOobject
(
meanFieldName,
obr_.time().timeName(obr_.time().startTime().value()),
obr_,
restartOnOutput_
? IOobject::NO_READ
: IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
1*baseField
)
);
}
}
template<class Type>
void Foam::functionObjects::fieldAverage::addMeanField(const label fieldi)
{
if (faItems_[fieldi].mean())
{
typedef GeometricField<Type, fvPatchField, volMesh>
VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh>
SurfaceFieldType;
const word& fieldName = faItems_[fieldi].fieldName();
if (obr_.foundObject<VolFieldType>(fieldName))
{
addMeanFieldType<VolFieldType>(fieldi);
}
else if (obr_.foundObject<SurfaceFieldType>(fieldName))
{
addMeanFieldType<SurfaceFieldType>(fieldi);
}
}
}
template<class Type1, class Type2>
void Foam::functionObjects::fieldAverage::addPrime2MeanFieldType
(
const label fieldi
)
{
const word& fieldName = faItems_[fieldi].fieldName();
const word& meanFieldName = faItems_[fieldi].meanFieldName();
const word& prime2MeanFieldName = faItems_[fieldi].prime2MeanFieldName();
Log << " Reading/initialising field " << prime2MeanFieldName << nl;
if (obr_.foundObject<Type2>(prime2MeanFieldName))
{
// do nothing
}
else if (obr_.found(prime2MeanFieldName))
{
Log << " Cannot allocate average field " << prime2MeanFieldName
<< " since an object with that name already exists."
<< " Disabling averaging for field." << endl;
faItems_[fieldi].prime2Mean() = false;
}
else
{
const Type1& baseField = obr_.lookupObject<Type1>(fieldName);
const Type1& meanField = obr_.lookupObject<Type1>(meanFieldName);
// Store on registry
obr_.store
(
new Type2
(
IOobject
(
prime2MeanFieldName,
obr_.time().timeName(obr_.time().startTime().value()),
obr_,
restartOnOutput_
? IOobject::NO_READ
: IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE
),
sqr(baseField) - sqr(meanField)
)
);
}
}
template<class Type1, class Type2>
void Foam::functionObjects::fieldAverage::addPrime2MeanField(const label fieldi)
{
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
if (faItems_[fieldi].prime2Mean())
{
const word& fieldName = faItems_[fieldi].fieldName();
if (!faItems_[fieldi].mean())
{
FatalErrorInFunction
<< "To calculate the prime-squared average, the "
<< "mean average must also be selected for field "
<< fieldName << nl << exit(FatalError);
}
if (obr_.foundObject<VolFieldType1>(fieldName))
{
addPrime2MeanFieldType<VolFieldType1, VolFieldType2>(fieldi);
}
else if (obr_.foundObject<SurfaceFieldType1>(fieldName))
{
addPrime2MeanFieldType<SurfaceFieldType1, SurfaceFieldType2>
(
fieldi
);
}
}
}
template<class Type>
void Foam::functionObjects::fieldAverage::calculateMeanFieldType
(
const label fieldi
) const
{
const word& fieldName = faItems_[fieldi].fieldName();
if (obr_.foundObject<Type>(fieldName))
{
const Type& baseField = obr_.lookupObject<Type>(fieldName);
Type& meanField = const_cast<Type&>
(
obr_.lookupObject<Type>(faItems_[fieldi].meanFieldName())
);
scalar dt = obr_.time().deltaTValue();
scalar Dt = totalTime_[fieldi];
if (faItems_[fieldi].iterBase())
{
dt = 1.0;
Dt = scalar(totalIter_[fieldi]);
}
scalar alpha = (Dt - dt)/Dt;
scalar beta = dt/Dt;
if (faItems_[fieldi].window() > 0)
{
const scalar w = faItems_[fieldi].window();
if (Dt - dt >= w)
{
alpha = (w - dt)/w;
beta = dt/w;
}
}
meanField = alpha*meanField + beta*baseField;
}
}
template<class Type>
void Foam::functionObjects::fieldAverage::calculateMeanFields() const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
forAll(faItems_, i)
{
if (faItems_[i].mean())
{
calculateMeanFieldType<VolFieldType>(i);
calculateMeanFieldType<SurfaceFieldType>(i);
}
}
}
template<class Type1, class Type2>
void Foam::functionObjects::fieldAverage::calculatePrime2MeanFieldType
(
const label fieldi
) const
{
const word& fieldName = faItems_[fieldi].fieldName();
if (obr_.foundObject<Type1>(fieldName))
{
const Type1& baseField = obr_.lookupObject<Type1>(fieldName);
const Type1& meanField =
obr_.lookupObject<Type1>(faItems_[fieldi].meanFieldName());
Type2& prime2MeanField = const_cast<Type2&>
(
obr_.lookupObject<Type2>(faItems_[fieldi].prime2MeanFieldName())
);
scalar dt = obr_.time().deltaTValue();
scalar Dt = totalTime_[fieldi];
if (faItems_[fieldi].iterBase())
{
dt = 1.0;
Dt = scalar(totalIter_[fieldi]);
}
scalar alpha = (Dt - dt)/Dt;
scalar beta = dt/Dt;
if (faItems_[fieldi].window() > 0)
{
const scalar w = faItems_[fieldi].window();
if (Dt - dt >= w)
{
alpha = (w - dt)/w;
beta = dt/w;
}
}
prime2MeanField =
alpha*prime2MeanField
+ beta*sqr(baseField)
- sqr(meanField);
}
}
template<class Type1, class Type2>
void Foam::functionObjects::fieldAverage::calculatePrime2MeanFields() const
{
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
forAll(faItems_, i)
{
if (faItems_[i].prime2Mean())
{
calculatePrime2MeanFieldType<VolFieldType1, VolFieldType2>
(
i
);
calculatePrime2MeanFieldType<SurfaceFieldType1, SurfaceFieldType2>
(
i
);
}
}
}
template<class Type1, class Type2>
void Foam::functionObjects::fieldAverage::addMeanSqrToPrime2MeanType
(
const label fieldi
) const
{
const word& fieldName = faItems_[fieldi].fieldName();
if (obr_.foundObject<Type1>(fieldName))
{
const Type1& meanField =
obr_.lookupObject<Type1>(faItems_[fieldi].meanFieldName());
Type2& prime2MeanField = const_cast<Type2&>
(
obr_.lookupObject<Type2>(faItems_[fieldi].prime2MeanFieldName())
);
prime2MeanField += sqr(meanField);
}
}
template<class Type1, class Type2>
void Foam::functionObjects::fieldAverage::addMeanSqrToPrime2Mean() const
{
typedef GeometricField<Type1, fvPatchField, volMesh> VolFieldType1;
typedef GeometricField<Type1, fvsPatchField, surfaceMesh> SurfaceFieldType1;
typedef GeometricField<Type2, fvPatchField, volMesh> VolFieldType2;
typedef GeometricField<Type2, fvsPatchField, surfaceMesh> SurfaceFieldType2;
forAll(faItems_, i)
{
if (faItems_[i].prime2Mean())
{
addMeanSqrToPrime2MeanType<VolFieldType1, VolFieldType2>(i);
addMeanSqrToPrime2MeanType<SurfaceFieldType1, SurfaceFieldType2>(i);
}
}
}
template<class Type>
void Foam::functionObjects::fieldAverage::writeFieldType
(
const word& fieldName
) const
{
if (obr_.foundObject<Type>(fieldName))
{
const Type& f = obr_.lookupObject<Type>(fieldName);
f.write();
}
}
template<class Type>
void Foam::functionObjects::fieldAverage::writeFields() const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
forAll(faItems_, i)
{
if (faItems_[i].mean())
{
const word& fieldName = faItems_[i].meanFieldName();
writeFieldType<VolFieldType>(fieldName);
writeFieldType<SurfaceFieldType>(fieldName);
}
if (faItems_[i].prime2Mean())
{
const word& fieldName = faItems_[i].prime2MeanFieldName();
writeFieldType<VolFieldType>(fieldName);
writeFieldType<SurfaceFieldType>(fieldName);
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,127 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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 "fieldCoordinateSystemTransform.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fieldCoordinateSystemTransform, 0);
addToRunTimeSelectionTable
(
functionObject,
fieldCoordinateSystemTransform,
dictionary
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldCoordinateSystemTransform::
fieldCoordinateSystemTransform
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
fieldSet_(),
coordSys_(mesh_, dict)
{
read(dict);
Log << type() << " " << name << ":" << nl
<< " Applying transformation from global Cartesian to local "
<< coordSys_ << nl << endl;
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldCoordinateSystemTransform::
~fieldCoordinateSystemTransform()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::word
Foam::functionObjects::fieldCoordinateSystemTransform::transformFieldName
(
const word& fieldName
) const
{
return fieldName + ":Transformed";
}
bool Foam::functionObjects::fieldCoordinateSystemTransform::read
(
const dictionary& dict
)
{
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> fieldSet_;
return true;
}
bool Foam::functionObjects::fieldCoordinateSystemTransform::execute()
{
forAll(fieldSet_, fieldi)
{
transform<scalar>(fieldSet_[fieldi]);
transform<vector>(fieldSet_[fieldi]);
transform<sphericalTensor>(fieldSet_[fieldi]);
transform<symmTensor>(fieldSet_[fieldi]);
transform<tensor>(fieldSet_[fieldi]);
}
return true;
}
bool Foam::functionObjects::fieldCoordinateSystemTransform::write()
{
forAll(fieldSet_, fieldi)
{
writeObject(transformFieldName(fieldSet_[fieldi]));
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,178 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fieldCoordinateSystemTransform
Group
grpFieldFunctionObjects
Description
Transforms a user-specified selection of fields from global Cartesian
co-ordinates to a local co-ordinate system. The fields are run-time
modifiable.
Usage
Example of function object specification:
\verbatim
fieldCoordinateSystemTransform1
{
type fieldCoordinateSystemTransform;
libs ("libfieldFunctionObjects.so");
...
fields
(
U
UMean
UPrime2Mean
);
origin (0.001 0 0);
coordinateRotation
{
type axesRotation;
e1 (1 0.15 0);
e3 (0 0 -1);
}
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: fieldCoordinateSystemTransform | yes |
fields | list of fields to be transformed |yes |
origin | origin of local co-ordinate system | yes |
coordinateRotation | orientation of local co-ordinate system | yes |
log | Log to standard output | no | yes
\endtable
See also
Foam::functionObjects::fvMeshFunctionObject
Foam::coordinateSystem
SourceFiles
fieldCoordinateSystemTransform.C
fieldCoordinateSystemTransformTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldCoordinateSystemTransform_H
#define functionObjects_fieldCoordinateSystemTransform_H
#include "fvMeshFunctionObject.H"
#include "coordinateSystem.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldCoordinateSystemTransform Declaration
\*---------------------------------------------------------------------------*/
class fieldCoordinateSystemTransform
:
public fvMeshFunctionObject
{
protected:
// Protected data
//- Fields to transform
wordList fieldSet_;
//- Co-ordinate system to transform to
coordinateSystem coordSys_;
//- Switch to send output to Info as well as to file
Switch log_;
// Protected Member Functions
//- Return the name of the transformed field
word transformFieldName(const word& fieldName) const;
//- Transform the given field
template<class FieldType>
void transformField(const FieldType& field);
//- Transform the given field if has the specified element type
template<class Type>
void transform(const word& fieldName);
public:
//- Runtime type information
TypeName("fieldCoordinateSystemTransform");
// Constructors
//- Construct from Time and dictionary
fieldCoordinateSystemTransform
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~fieldCoordinateSystemTransform();
// Member Functions
//- Read the input data
virtual bool read(const dictionary&);
//- Calculate the transformed fields
virtual bool execute();
//- Write the transformed fields
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldCoordinateSystemTransformTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldCoordinateSystemTransform.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "transformGeometricField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class FieldType>
void Foam::functionObjects::fieldCoordinateSystemTransform::transformField
(
const FieldType& field
)
{
word transFieldName(transformFieldName(field.name()));
store
(
transFieldName,
Foam::transform(dimensionedTensor(coordSys_.R().R()), field)
);
}
template<class Type>
void Foam::functionObjects::fieldCoordinateSystemTransform::transform
(
const word& fieldName
)
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (foundObject<VolFieldType>(fieldName))
{
DebugInfo
<< type() << ": Field " << fieldName << " already in database"
<< endl;
transformField<VolFieldType>(lookupObject<VolFieldType>(fieldName));
}
else if (foundObject<SurfaceFieldType>(fieldName))
{
DebugInfo
<< type() << ": Field " << fieldName << " already in database"
<< endl;
transformField<SurfaceFieldType>
(
lookupObject<SurfaceFieldType>(fieldName)
);
}
else
{
IOobject fieldHeader
(
fieldName,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if (fieldHeader.typeHeaderOk<VolFieldType>(true))
{
DebugInfo
<< type() << ": Field " << fieldName << " read from file"
<< endl;
transformField<VolFieldType>
(
lookupObject<VolFieldType>(fieldName)
);
}
else if (fieldHeader.typeHeaderOk<SurfaceFieldType>(true))
{
DebugInfo
<< type() << ": Field " << fieldName << " read from file"
<< endl;
transformField<SurfaceFieldType>
(
lookupObject<SurfaceFieldType>(fieldName)
);
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,52 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object postProcessingDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
functions
{
fieldCoordinateSystemTransform1
{
// Type of functionObject
type fieldCoordinateSystemTransform;
// Where to load it from (if not already in solver)
libs ("libfieldFunctionObjects.so");
// Function object enabled flag
enabled true;
// When to output the average fields
writeControl writeTime;
// Fields to be transformed - runTime modifiable
fields
(
U
UMean
UPrime2Mean
);
origin (0.001 0 0);
coordinateRotation
{
type axesRotation;
e1 (1 0.15 0);
e3 (0 0 -1);
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "fieldExpression.H"
#include "dictionary.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fieldExpression, 0);
}
}
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
bool Foam::functionObjects::fieldExpression::calc()
{
NotImplemented;
return false;
}
void Foam::functionObjects::fieldExpression::setResultName
(
const word& typeName,
const word& defaultArg
)
{
if (fieldName_.empty())
{
fieldName_ = defaultArg;
}
if (resultName_.empty())
{
if (fieldName_ != defaultArg)
{
resultName_ = typeName + '(' + fieldName_ + ')';
}
else
{
resultName_ = typeName;
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldExpression::fieldExpression
(
const word& name,
const Time& runTime,
const dictionary& dict,
const word& fieldName,
const word& resultName
)
:
fvMeshFunctionObject(name, runTime, dict),
fieldName_(fieldName),
resultName_(resultName)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldExpression::~fieldExpression()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldExpression::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
if (fieldName_.empty() || dict.found("field"))
{
dict.lookup("field") >> fieldName_;
}
if (dict.found("result"))
{
dict.lookup("result") >> resultName_;
}
return true;
}
bool Foam::functionObjects::fieldExpression::execute()
{
if (!calc())
{
Warning
<< " functionObjects::" << type() << " " << name()
<< " cannot find required field " << fieldName_ << endl;
// Clear the result field from the objectRegistry if present
clear();
return false;
}
else
{
return true;
}
}
bool Foam::functionObjects::fieldExpression::write()
{
return writeObject(resultName_);
}
bool Foam::functionObjects::fieldExpression::clear()
{
return clearObject(resultName_);
}
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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::fieldExpression
Group
grpFieldFunctionObjects
Description
Base class for field expression function objects
See also
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
fieldExpression.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldExpression_H
#define functionObjects_fieldExpression_H
#include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldExpression Declaration
\*---------------------------------------------------------------------------*/
class fieldExpression
:
public fvMeshFunctionObject
{
protected:
// Protected member data
//- Name of field to process
word fieldName_;
//- Name of result field
word resultName_;
// Protected member functions
virtual bool calc();
void setResultName(const word& typeName, const word& defaultArg);
private:
// Private Member Functions
//- Disallow default bitwise copy construct
fieldExpression(const fieldExpression&);
//- Disallow default bitwise assignment
void operator=(const fieldExpression&);
public:
//- Runtime type information
TypeName("fieldExpression");
// Constructors
//- Construct from Time and dictionary
fieldExpression
(
const word& name,
const Time& runTime,
const dictionary& dict,
const word& fieldName = word::null,
const word& resultName = word::null
);
//- Destructor
virtual ~fieldExpression();
// Member Functions
//- Read the fieldExpression data
virtual bool read(const dictionary&);
//- Calculate the result field
virtual bool execute();
//- Write the result field
virtual bool write();
//- Clear the result field from the objectRegistry
virtual bool clear();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,162 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldMinMax.H"
#include "fieldTypes.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fieldMinMax, 0);
addToRunTimeSelectionTable(functionObject, fieldMinMax, dictionary);
}
}
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldMinMax::modeType,
2
>::names[] = {"magnitude", "component"};
const Foam::NamedEnum
<
Foam::functionObjects::fieldMinMax::modeType,
2
> Foam::functionObjects::fieldMinMax::modeTypeNames_;
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::functionObjects::fieldMinMax::writeFileHeader(Ostream& os) const
{
writeHeader(os, "Field minima and maxima");
writeCommented(os, "Time");
if (location_)
{
writeTabbed(os, "field");
writeTabbed(os, "min");
writeTabbed(os, "location(min)");
if (Pstream::parRun())
{
writeTabbed(os, "processor");
}
writeTabbed(os, "max");
writeTabbed(os, "location(max)");
if (Pstream::parRun())
{
writeTabbed(os, "processor");
}
}
else
{
forAll(fieldSet_, fieldi)
{
writeTabbed(os, "min(" + fieldSet_[fieldi] + ')');
writeTabbed(os, "max(" + fieldSet_[fieldi] + ')');
}
}
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldMinMax::fieldMinMax
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(mesh_, name, typeName, dict),
location_(true),
mode_(mdMag),
fieldSet_()
{
read(dict);
writeFileHeader(file());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldMinMax::~fieldMinMax()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldMinMax::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
location_ = dict.lookupOrDefault<Switch>("location", true);
mode_ = modeTypeNames_[dict.lookupOrDefault<word>("mode", "magnitude")];
dict.lookup("fields") >> fieldSet_;
return true;
}
bool Foam::functionObjects::fieldMinMax::execute()
{
return true;
}
bool Foam::functionObjects::fieldMinMax::write()
{
if (!location_) writeTime(file());
Log << type() << " " << name() << " write:" << nl;
forAll(fieldSet_, fieldi)
{
calcMinMaxFields<scalar>(fieldSet_[fieldi], mdCmpt);
calcMinMaxFields<vector>(fieldSet_[fieldi], mode_);
calcMinMaxFields<sphericalTensor>(fieldSet_[fieldi], mode_);
calcMinMaxFields<symmTensor>(fieldSet_[fieldi], mode_);
calcMinMaxFields<tensor>(fieldSet_[fieldi], mode_);
}
if (!location_) file()<< endl;
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,214 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fieldMinMax
Group
grpFieldFunctionObjects
Description
Calculates the value and location of scalar minimim and maximum for a list
of user-specified fields.
For variables with a rank greater than zero, either the min/max of a
component value or the magnitude is reported. When operating in parallel,
the processor owning the value is also given.
Usage
Example of function object specification:
\verbatim
fieldMinMax1
{
type fieldMinMax;
libs ("libfieldFunctionObjects.so");
...
writeToFile yes;
log yes;
location yes;
mode magnitude;
fields (U p);
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: fieldMinMax | yes |
writeToFile | write min/max data to file | no | yes
log | write min/max data to standard output | no | yes
location | write location of the min/max value | no | yes
mode | calculation mode: magnitude or component | no | magnitude
fields | list of fields to process | yes |
\endtable
Output data is written to the file \<timeDir\>/fieldMinMax.dat
See also
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
SourceFiles
fieldMinMax.C
fieldMinMaxTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldMinMax_H
#define functionObjects_fieldMinMax_H
#include "Switch.H"
#include "NamedEnum.H"
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "vector.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldMinMax Declaration
\*---------------------------------------------------------------------------*/
class fieldMinMax
:
public fvMeshFunctionObject,
public writeFile
{
public:
// Public enumerations
enum modeType
{
mdMag, //!< magnitude
mdCmpt //!< component
};
protected:
// Protected data
//- Mode type names
static const NamedEnum<modeType, 2> modeTypeNames_;
//- Switch to write location of min/max values
Switch location_;
//- Mode for min/max - only applicable for ranks > 0
modeType mode_;
//- Fields to assess min/max
wordList fieldSet_;
// Private Member Functions
//- Helper function to write the output
template<class Type>
void output
(
const word& fieldName,
const word& outputName,
const vector& minC,
const vector& maxC,
const label minProci,
const label maxProci,
const Type& minValue,
const Type& maxValue
);
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
//- Disallow default bitwise copy construct
fieldMinMax(const fieldMinMax&) = delete;
//- Disallow default bitwise assignment
void operator=(const fieldMinMax&) = delete;
//- Calculate the field min/max
template<class Type>
void calcMinMaxFields
(
const word& fieldName,
const modeType& mode
);
public:
//- Runtime type information
TypeName("fieldMinMax");
// Constructors
//- Construct from Time and dictionary
fieldMinMax
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~fieldMinMax();
// Member Functions
//- Read the field min/max data
virtual bool read(const dictionary&);
//- Execute, currently does nothing
virtual bool execute();
//- Write the fieldMinMax
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldMinMaxTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,286 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldMinMax.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fieldMinMax::output
(
const word& fieldName,
const word& outputName,
const vector& minC,
const vector& maxC,
const label minProci,
const label maxProci,
const Type& minValue,
const Type& maxValue
)
{
OFstream& file = this->file();
if (location_)
{
writeTime(file());
writeTabbed(file, fieldName);
file<< token::TAB << minValue
<< token::TAB << minC;
if (Pstream::parRun())
{
file<< token::TAB << minProci;
}
file<< token::TAB << maxValue
<< token::TAB << maxC;
if (Pstream::parRun())
{
file<< token::TAB << maxProci;
}
file<< endl;
Log << " min(" << outputName << ") = " << minValue
<< " at location " << minC;
if (Pstream::parRun())
{
Log << " on processor " << minProci;
}
Log << nl << " max(" << outputName << ") = " << maxValue
<< " at location " << maxC;
if (Pstream::parRun())
{
Log << " on processor " << maxProci;
}
}
else
{
file<< token::TAB << minValue << token::TAB << maxValue;
Log << " min/max(" << outputName << ") = "
<< minValue << ' ' << maxValue;
}
Log << endl;
// Write state/results information
word nameStr('(' + outputName + ')');
this->setResult("min" + nameStr, minValue);
this->setResult("min" + nameStr + "_position", minC);
this->setResult("min" + nameStr + "_processor", minProci);
this->setResult("max" + nameStr, maxValue);
this->setResult("max" + nameStr + "_position", maxC);
this->setResult("max" + nameStr + "_processor", maxProci);
}
template<class Type>
void Foam::functionObjects::fieldMinMax::calcMinMaxFields
(
const word& fieldName,
const modeType& mode
)
{
typedef GeometricField<Type, fvPatchField, volMesh> fieldType;
if (obr_.foundObject<fieldType>(fieldName))
{
const label proci = Pstream::myProcNo();
const fieldType& field = lookupObject<fieldType>(fieldName);
const volVectorField::Boundary& CfBoundary =
mesh_.C().boundaryField();
switch (mode)
{
case mdMag:
{
const volScalarField magField(mag(field));
const volScalarField::Boundary& magFieldBoundary =
magField.boundaryField();
scalarList minVs(Pstream::nProcs());
List<vector> minCs(Pstream::nProcs());
label minProci = findMin(magField);
minVs[proci] = magField[minProci];
minCs[proci] = mesh_.C()[minProci];
labelList maxIs(Pstream::nProcs());
scalarList maxVs(Pstream::nProcs());
List<vector> maxCs(Pstream::nProcs());
label maxProci = findMax(magField);
maxVs[proci] = magField[maxProci];
maxCs[proci] = mesh_.C()[maxProci];
forAll(magFieldBoundary, patchi)
{
const scalarField& mfp = magFieldBoundary[patchi];
if (mfp.size())
{
const vectorField& Cfp = CfBoundary[patchi];
label minPi = findMin(mfp);
if (mfp[minPi] < minVs[proci])
{
minVs[proci] = mfp[minPi];
minCs[proci] = Cfp[minPi];
}
label maxPi = findMax(mfp);
if (mfp[maxPi] > maxVs[proci])
{
maxVs[proci] = mfp[maxPi];
maxCs[proci] = Cfp[maxPi];
}
}
}
Pstream::gatherList(minVs);
Pstream::scatterList(minVs);
Pstream::gatherList(minCs);
Pstream::scatterList(minCs);
Pstream::gatherList(maxVs);
Pstream::scatterList(maxVs);
Pstream::gatherList(maxCs);
Pstream::scatterList(maxCs);
label mini = findMin(minVs);
scalar minValue = minVs[mini];
const vector& minC = minCs[mini];
label maxi = findMax(maxVs);
scalar maxValue = maxVs[maxi];
const vector& maxC = maxCs[maxi];
output
(
fieldName,
word("mag(" + fieldName + ")"),
minC,
maxC,
mini,
maxi,
minValue,
maxValue
);
break;
}
case mdCmpt:
{
const typename fieldType::Boundary&
fieldBoundary = field.boundaryField();
List<Type> minVs(Pstream::nProcs());
List<vector> minCs(Pstream::nProcs());
label minProci = findMin(field);
minVs[proci] = field[minProci];
minCs[proci] = mesh_.C()[minProci];
Pstream::gatherList(minVs);
Pstream::gatherList(minCs);
List<Type> maxVs(Pstream::nProcs());
List<vector> maxCs(Pstream::nProcs());
label maxProci = findMax(field);
maxVs[proci] = field[maxProci];
maxCs[proci] = mesh_.C()[maxProci];
forAll(fieldBoundary, patchi)
{
const Field<Type>& fp = fieldBoundary[patchi];
if (fp.size())
{
const vectorField& Cfp = CfBoundary[patchi];
label minPi = findMin(fp);
if (fp[minPi] < minVs[proci])
{
minVs[proci] = fp[minPi];
minCs[proci] = Cfp[minPi];
}
label maxPi = findMax(fp);
if (fp[maxPi] > maxVs[proci])
{
maxVs[proci] = fp[maxPi];
maxCs[proci] = Cfp[maxPi];
}
}
}
Pstream::gatherList(minVs);
Pstream::scatterList(minVs);
Pstream::gatherList(minCs);
Pstream::scatterList(minCs);
Pstream::gatherList(maxVs);
Pstream::scatterList(maxVs);
Pstream::gatherList(maxCs);
Pstream::scatterList(maxCs);
label mini = findMin(minVs);
Type minValue = minVs[mini];
const vector& minC = minCs[mini];
label maxi = findMax(maxVs);
Type maxValue = maxVs[maxi];
const vector& maxC = maxCs[maxi];
output
(
fieldName,
fieldName,
minC,
maxC,
mini,
maxi,
minValue,
maxValue
);
break;
}
default:
{
FatalErrorInFunction
<< "Unknown min/max mode: " << modeTypeNames_[mode_]
<< exit(FatalError);
}
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,120 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldValue.H"
#include "Time.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fieldValue, 0);
defineRunTimeSelectionTable(fieldValue, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValue::fieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict,
const word& valueType
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name, valueType, dict),
scaleFactor_(1.0),
dict_(dict),
regionName_(word::null)
{
read(dict);
}
Foam::functionObjects::fieldValue::fieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& valueType
)
:
fvMeshFunctionObject(name, obr, dict),
writeFile(obr_, name, valueType, dict),
scaleFactor_(1.0),
dict_(dict),
regionName_(word::null)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValue::~fieldValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValue::read(const dictionary& dict)
{
if (dict != dict_)
{
dict_ = dict;
}
fvMeshFunctionObject::read(dict);
writeFile::read(dict);
dict.lookup("fields") >> fields_;
dict.lookup("writeFields") >> writeFields_;
dict.readIfPresent("scaleFactor", scaleFactor_);
return true;
}
bool Foam::functionObjects::fieldValue::execute()
{
return true;
}
bool Foam::functionObjects::fieldValue::write()
{
Log << type() << " " << name() << " write:" << nl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,199 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fieldValue
Group
grpFieldFunctionObjects
Description
Base class for field value-based function objects.
See also
Foam::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
SourceFiles
fieldValue.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldValue_H
#define functionObjects_fieldValue_H
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "Switch.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldValue Declaration
\*---------------------------------------------------------------------------*/
class fieldValue
:
public fvMeshFunctionObject,
public writeFile
{
protected:
// Protected data
//- Optional scale value
scalar scaleFactor_;
//- Construction dictionary
dictionary dict_;
//- Name of region (patch, zone, etc.)
word regionName_;
//- List of field names to operate on
wordList fields_;
//- Output field values flag
Switch writeFields_;
// Protected Member Functions
//- Combine fields from all processor domains into single field
template<class Type>
void combineFields(Field<Type>& field);
//- Combine fields from all processor domains into single field
template<class Type>
void combineFields(tmp<Field<Type>>&);
public:
//- Run-time type information
TypeName("fieldValue");
// Declare runtime constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
fieldValue,
dictionary,
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
),
(name, obr, dict)
);
// Constructors
//- Construct from Time and dictionary
fieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict,
const word& valueType
);
//- Construct from objectRegistry and dictionary
fieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& valueType
);
//- Return a reference to the selected fieldValue
static autoPtr<fieldValue> New
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool output = true
);
//- Destructor
virtual ~fieldValue();
// Member Functions
//- Return the reference to the construction dictionary
inline const dictionary& dict() const;
//- Return the region name
inline const word& regionName() const;
//- Return the list of field names
inline const wordList& fields() const;
//- Return the output field values flag
inline const Switch& writeFields() const;
//- Read from dictionary
virtual bool read(const dictionary& dict);
//- Execute
virtual bool execute();
//- Write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "fieldValueI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldValueTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,53 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::dictionary& Foam::functionObjects::fieldValue::dict() const
{
return dict_;
}
inline const Foam::word& Foam::functionObjects::fieldValue::regionName() const
{
return regionName_;
}
inline const Foam::wordList& Foam::functionObjects::fieldValue::fields() const
{
return fields_;
}
inline const Foam::Switch&
Foam::functionObjects::fieldValue::writeFields() const
{
return writeFields_;
}
// ************************************************************************* //

View File

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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 "fieldValue.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::functionObjects::fieldValue>
Foam::functionObjects::fieldValue::New
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool output
)
{
const word modelType(dict.lookup("type"));
if (output)
{
Info<< "Selecting " << typeName << " " << modelType << endl;
}
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(modelType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown " << typeName << " type "
<< modelType << nl << nl
<< "Valid " << typeName << " types are:" << nl
<< dictionaryConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<fieldValue>(cstrIter()(name, obr, dict));
}
// ************************************************************************* //

View File

@ -0,0 +1,58 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldValue.H"
#include "ListListOps.H"
#include "Pstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fieldValue::combineFields(Field<Type>& field)
{
List<Field<Type>> allValues(Pstream::nProcs());
allValues[Pstream::myProcNo()] = field;
Pstream::gatherList(allValues);
Pstream::scatterList(allValues);
field =
ListListOps::combine<Field<Type>>
(
allValues,
accessOp<Field<Type>>()
);
}
template<class Type>
void Foam::functionObjects::fieldValue::combineFields(tmp<Field<Type>>& field)
{
combineFields(field());
}
// ************************************************************************* //

View File

@ -0,0 +1,236 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fieldValueDelta.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(fieldValueDelta, 0);
addToRunTimeSelectionTable(functionObject, fieldValueDelta, dictionary);
}
}
}
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::fieldValueDelta::operationType,
5
>::names[] =
{
"add",
"subtract",
"min",
"max",
"average"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::fieldValueDelta::operationType,
5
> Foam::functionObjects::fieldValues::fieldValueDelta::operationTypeNames_;
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
void Foam::functionObjects::fieldValues::fieldValueDelta::writeFileHeader
(
Ostream& os
) const
{
const wordList& fields1 = region1Ptr_->fields();
const wordList& fields2 = region2Ptr_->fields();
DynamicList<word> commonFields(fields1.size());
forAll(fields1, fieldi)
{
label index = findIndex(fields2, fields1[fieldi]);
if (index != -1)
{
commonFields.append(fields1[fieldi]);
}
}
writeHeaderValue(os, "Source1", region1Ptr_->name());
writeHeaderValue(os, "Source2", region2Ptr_->name());
writeHeaderValue(os, "Operation", operationTypeNames_[operation_]);
writeCommented(os, "Time");
forAll(commonFields, i)
{
os << tab << commonFields[i];
}
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::fieldValueDelta::fieldValueDelta
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name, typeName, dict),
operation_(opSubtract),
region1Ptr_(nullptr),
region2Ptr_(nullptr)
{
read(dict);
writeFileHeader(file());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::fieldValueDelta::~fieldValueDelta()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::fieldValueDelta::read
(
const dictionary& dict
)
{
fvMeshFunctionObject::read(dict);
writeFile::read(dict);
region1Ptr_.reset
(
fieldValue::New
(
name() + ".region1",
obr_,
dict.subDict("region1"),
false
).ptr()
);
region2Ptr_.reset
(
fieldValue::New
(
name() + ".region2",
obr_,
dict.subDict("region2"),
false
).ptr()
);
operation_ = operationTypeNames_.read(dict.lookup("operation"));
return true;
}
bool Foam::functionObjects::fieldValues::fieldValueDelta::write()
{
region1Ptr_->write();
region2Ptr_->write();
writeTime(file());
Log << type() << " " << name() << " write:" << endl;
const word& name1 = region1Ptr_->name();
const word& name2 = region2Ptr_->name();
const wordList entries1 = objectResultEntries(name1);
const wordList entries2 = objectResultEntries(name2);
if (entries1.size() != entries2.size())
{
FatalErrorInFunction
<< name() << ": objects must generate the same number of results"
<< nl
<< " " << name1 << " objects: " << entries1 << nl
<< " " << name2 << " objects: " << entries2 << nl
<< exit(FatalError);
}
forAll(entries1, i)
{
const word& entry1(entries1[i]);
const word& entry2(entries2[i]);
const word type1 = objectResultType(name1, entry1);
const word type2 = objectResultType(name2, entry2);
if (type1 != type2)
{
FatalErrorInFunction
<< name()
<< ": input values for operation must be of the same type"
<< nl
<< " " << entry1 << ": " << type1 << nl
<< " " << entry2 << ": " << type2 << nl
<< exit(FatalError);
}
bool found = false;
applyOperation<scalar>(type1, name1, name2, entry1, entry2, found);
applyOperation<vector>(type1, name1, name2, entry1, entry2, found);
applyOperation<sphericalTensor>
(type1, name1, name2, entry1, entry2, found);
applyOperation<symmTensor>(type1, name1, name2, entry1, entry2, found);
applyOperation<tensor>(type1, name1, name2, entry1, entry2, found);
if (log && !found)
{
Info<< "Operation between "
<< name1 << " with result " << entry1 << " and "
<< name2 << " with result " << entry2 << " not applied"
<< endl;
}
}
Log << (entries1.empty() ? " none" : "") << endl;
file()<< endl;
return true;
}
bool Foam::functionObjects::fieldValues::fieldValueDelta::execute()
{
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,209 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fieldValues::fieldValueDelta
Group
grpFieldFunctionObjects
Description
Provides an operation between two 'field value' function objects.
The operation is applied to all results of each fieldValue object.
Accordingly, each object must generate the same number and type of results.
Usage
Example of function object specification:
\verbatim
fieldValueDelta1
{
type fieldValueDelta;
libs ("libfieldFunctionObjects.so");
operation subtract;
source1
{
...
}
source2
{
...
}
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: fieldValueDelta | yes |
\endtable
The \c operation is one of:
\plaintable
add | add
subtract | subtract
min | minimum
max | maximum
average | average
\endplaintable
See also
Foam::functionObject
Foam::functionObjects::fieldValue
Foam::functionObjects::regionFunctionObject
Foam::functionObjects::writeFile
SourceFiles
fieldValueDelta.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldValueDelta_H
#define functionObjects_fieldValueDelta_H
#include "stateFunctionObject.H"
#include "writeFile.H"
#include "fieldValue.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class fieldValueDelta Declaration
\*---------------------------------------------------------------------------*/
class fieldValueDelta
:
public fvMeshFunctionObject,
public writeFile
{
public:
//- Operation type enumeration
enum operationType
{
opAdd, //!< Add
opSubtract, //!< Subtract
opMin, //!< Minimum
opMax, //!< Maximum
opAverage //!< Average
};
//- Operation type names
static const NamedEnum<operationType, 5> operationTypeNames_;
private:
// Private data
//- Operation to apply to values
operationType operation_;
//- Field value region object 1
autoPtr<fieldValue> region1Ptr_;
//- Field value region object 2
autoPtr<fieldValue> region2Ptr_;
// Private Member Functions
//- Templated function to apply the operation
template<class Type>
void applyOperation
(
const word& resultType,
const word& name1,
const word& name2,
const word& entryName1,
const word& entryName2,
bool& found
);
protected:
// Protected Member Functions
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
public:
//- Run-time type information
TypeName("fieldValueDelta");
// Constructors
//- Construct from Time and dictionary
fieldValueDelta
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~fieldValueDelta();
// Public Member Functions
//- Read from dictionary
virtual bool read(const dictionary&);
//- Do nothing
virtual bool execute();
//- Calculate and write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldValueDeltaTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,100 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fieldValues::fieldValueDelta::applyOperation
(
const word& resultType,
const word& name1,
const word& name2,
const word& entryName1,
const word& entryName2,
bool& found
)
{
if (pTraits<Type>::typeName != resultType)
{
return;
}
Type result = Zero;
Type value1 = this->getObjectResult<Type>(name1, entryName1);
Type value2 = this->getObjectResult<Type>(name2, entryName2);
const word& opName = operationTypeNames_[operation_];
switch (operation_)
{
case opAdd:
{
result = value1 + value2;
break;
}
case opSubtract:
{
result = value1 - value2;
break;
}
case opMin:
{
result = min(value1, value2);
break;
}
case opMax:
{
result = max(value1, value2);
break;
}
case opAverage:
{
result = 0.5*(value1 + value2);
break;
}
default:
{
FatalErrorInFunction
<< "Unable to process operation "
<< operationTypeNames_[operation_]
<< abort(FatalError);
}
}
const word resultName(opName + '(' + entryName1 + ',' + entryName2 + ')');
Log << " " << resultName << " = " << result << endl;
this->file()<< tab << result;
// Write state/results information
this->setResult(resultName, result);
found = true;
}
// ************************************************************************* //

View File

@ -0,0 +1,785 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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 "surfaceFieldValue.H"
#include "fvMesh.H"
#include "emptyPolyPatch.H"
#include "coupledPolyPatch.H"
#include "sampledSurface.H"
#include "mergePoints.H"
#include "indirectPrimitivePatch.H"
#include "PatchTools.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(surfaceFieldValue, 0);
addToRunTimeSelectionTable(fieldValue, surfaceFieldValue, dictionary);
addToRunTimeSelectionTable(functionObject, surfaceFieldValue, dictionary);
}
}
}
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
3
>::names[] =
{
"faceZone",
"patch",
"sampledSurface"
};
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
15
>::names[] =
{
"none",
"sum",
"sumMag",
"sumDirection",
"sumDirectionBalance",
"average",
"weightedAverage",
"areaAverage",
"weightedAreaAverage",
"areaIntegrate",
"min",
"max",
"CoV",
"areaNormalAverage",
"areaNormalIntegrate"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes,
3
> Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypeNames_;
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::surfaceFieldValue::operationType,
15
> Foam::functionObjects::fieldValues::surfaceFieldValue::operationTypeNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::surfaceFieldValue::setFaceZoneFaces()
{
label zoneId = mesh_.faceZones().findZoneID(regionName_);
if (zoneId < 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Unknown face zone name: " << regionName_
<< ". Valid face zones are: " << mesh_.faceZones().names()
<< nl << exit(FatalError);
}
const faceZone& fZone = mesh_.faceZones()[zoneId];
DynamicList<label> faceIds(fZone.size());
DynamicList<label> facePatchIds(fZone.size());
DynamicList<label> faceSigns(fZone.size());
forAll(fZone, i)
{
label facei = fZone[i];
label faceId = -1;
label facePatchId = -1;
if (mesh_.isInternalFace(facei))
{
faceId = facei;
facePatchId = -1;
}
else
{
facePatchId = mesh_.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh_.boundaryMesh()[facePatchId];
if (isA<coupledPolyPatch>(pp))
{
if (refCast<const coupledPolyPatch>(pp).owner())
{
faceId = pp.whichFace(facei);
}
else
{
faceId = -1;
}
}
else if (!isA<emptyPolyPatch>(pp))
{
faceId = facei - pp.start();
}
else
{
faceId = -1;
facePatchId = -1;
}
}
if (faceId >= 0)
{
if (fZone.flipMap()[i])
{
faceSigns.append(-1);
}
else
{
faceSigns.append(1);
}
faceIds.append(faceId);
facePatchIds.append(facePatchId);
}
}
faceId_.transfer(faceIds);
facePatchId_.transfer(facePatchIds);
faceSign_.transfer(faceSigns);
nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
if (debug)
{
Pout<< "Original face zone size = " << fZone.size()
<< ", new size = " << faceId_.size() << endl;
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::setPatchFaces()
{
const label patchid = mesh_.boundaryMesh().findPatchID(regionName_);
if (patchid < 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Unknown patch name: " << regionName_
<< ". Valid patch names are: "
<< mesh_.boundaryMesh().names() << nl
<< exit(FatalError);
}
const polyPatch& pp = mesh_.boundaryMesh()[patchid];
label nFaces = pp.size();
if (isA<emptyPolyPatch>(pp))
{
nFaces = 0;
}
faceId_.setSize(nFaces);
facePatchId_.setSize(nFaces);
faceSign_.setSize(nFaces);
nFaces_ = returnReduce(faceId_.size(), sumOp<label>());
forAll(faceId_, facei)
{
faceId_[facei] = facei;
facePatchId_[facei] = patchid;
faceSign_[facei] = 1;
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::sampledSurfaceFaces
(
const dictionary& dict
)
{
surfacePtr_ = sampledSurface::New
(
name(),
mesh_,
dict.subDict("sampledSurfaceDict")
);
surfacePtr_().update();
nFaces_ = returnReduce(surfacePtr_().faces().size(), sumOp<label>());
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::combineMeshGeometry
(
faceList& faces,
pointField& points
) const
{
List<faceList> allFaces(Pstream::nProcs());
List<pointField> allPoints(Pstream::nProcs());
labelList globalFacesIs(faceId_);
forAll(globalFacesIs, i)
{
if (facePatchId_[i] != -1)
{
label patchi = facePatchId_[i];
globalFacesIs[i] += mesh_.boundaryMesh()[patchi].start();
}
}
// Add local faces and points to the all* lists
indirectPrimitivePatch pp
(
IndirectList<face>(mesh_.faces(), globalFacesIs),
mesh_.points()
);
allFaces[Pstream::myProcNo()] = pp.localFaces();
allPoints[Pstream::myProcNo()] = pp.localPoints();
Pstream::gatherList(allFaces);
Pstream::gatherList(allPoints);
// Renumber and flatten
label nFaces = 0;
label nPoints = 0;
forAll(allFaces, proci)
{
nFaces += allFaces[proci].size();
nPoints += allPoints[proci].size();
}
faces.setSize(nFaces);
points.setSize(nPoints);
nFaces = 0;
nPoints = 0;
// My own data first
{
const faceList& fcs = allFaces[Pstream::myProcNo()];
forAll(fcs, i)
{
const face& f = fcs[i];
face& newF = faces[nFaces++];
newF.setSize(f.size());
forAll(f, fp)
{
newF[fp] = f[fp] + nPoints;
}
}
const pointField& pts = allPoints[Pstream::myProcNo()];
forAll(pts, i)
{
points[nPoints++] = pts[i];
}
}
// Other proc data follows
forAll(allFaces, proci)
{
if (proci != Pstream::myProcNo())
{
const faceList& fcs = allFaces[proci];
forAll(fcs, i)
{
const face& f = fcs[i];
face& newF = faces[nFaces++];
newF.setSize(f.size());
forAll(f, fp)
{
newF[fp] = f[fp] + nPoints;
}
}
const pointField& pts = allPoints[proci];
forAll(pts, i)
{
points[nPoints++] = pts[i];
}
}
}
// Merge
labelList oldToNew;
pointField newPoints;
bool hasMerged = mergePoints
(
points,
SMALL,
false,
oldToNew,
newPoints
);
if (hasMerged)
{
if (debug)
{
Pout<< "Merged from " << points.size()
<< " down to " << newPoints.size() << " points" << endl;
}
points.transfer(newPoints);
forAll(faces, i)
{
inplaceRenumber(oldToNew, faces[i]);
}
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::
combineSurfaceGeometry
(
faceList& faces,
pointField& points
) const
{
if (surfacePtr_.valid())
{
const sampledSurface& s = surfacePtr_();
if (Pstream::parRun())
{
// Dimension as fraction of mesh bounding box
scalar mergeDim = 1e-10*mesh_.bounds().mag();
labelList pointsMap;
PatchTools::gatherAndMerge
(
mergeDim,
primitivePatch
(
SubList<face>(s.faces(), s.faces().size()),
s.points()
),
points,
faces,
pointsMap
);
}
else
{
faces = s.faces();
points = s.points();
}
}
}
Foam::scalar
Foam::functionObjects::fieldValues::surfaceFieldValue::totalArea() const
{
scalar totalArea;
if (surfacePtr_.valid())
{
totalArea = gSum(surfacePtr_().magSf());
}
else
{
totalArea = gSum(filterField(mesh_.magSf(), false));
}
return totalArea;
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::surfaceFieldValue::initialise
(
const dictionary& dict
)
{
dict.lookup("name") >> regionName_;
switch (regionType_)
{
case stFaceZone:
{
setFaceZoneFaces();
break;
}
case stPatch:
{
setPatchFaces();
break;
}
case stSampledSurface:
{
sampledSurfaceFaces(dict);
break;
}
default:
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):"
<< nl << " Unknown region type. Valid region types are:"
<< regionTypeNames_.sortedToc() << nl << exit(FatalError);
}
}
if (nFaces_ == 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):" << nl
<< " Region has no faces" << exit(FatalError);
}
if (surfacePtr_.valid())
{
surfacePtr_().update();
}
totalArea_ = totalArea();
Info<< type() << " " << name() << ":" << nl
<< " total faces = " << nFaces_ << nl
<< " total area = " << totalArea_ << nl;
if (dict.readIfPresent("weightField", weightFieldName_))
{
Info<< " weight field = " << weightFieldName_ << nl;
if (regionType_ == stSampledSurface)
{
FatalIOErrorInFunction(dict)
<< "Cannot use weightField for a sampledSurface"
<< exit(FatalIOError);
}
}
if (dict.found("orientedWeightField"))
{
if (weightFieldName_ == "none")
{
dict.lookup("orientedWeightField") >> weightFieldName_;
Log << " weight field = " << weightFieldName_ << nl;
orientWeightField_ = true;
}
else
{
FatalIOErrorInFunction(dict)
<< "Either weightField or orientedWeightField can be supplied, "
<< "but not both"
<< exit(FatalIOError);
}
}
List<word> orientedFields;
if (dict.readIfPresent("orientedFields", orientedFields))
{
orientedFieldsStart_ = fields_.size();
fields_.append(orientedFields);
}
Info<< nl << endl;
if (writeFields_)
{
const word surfaceFormat(dict.lookup("surfaceFormat"));
surfaceWriterPtr_.reset
(
surfaceWriter::New
(
surfaceFormat,
dict.subOrEmptyDict("formatOptions").
subOrEmptyDict(surfaceFormat)
).ptr()
);
}
}
void Foam::functionObjects::fieldValues::surfaceFieldValue::writeFileHeader
(
Ostream& os
) const
{
if (operation_ != opNone)
{
writeCommented(os, "Region type : ");
os << regionTypeNames_[regionType_] << " " << regionName_ << endl;
writeHeaderValue(os, "Faces", nFaces_);
writeHeaderValue(os, "Area", totalArea_);
writeHeaderValue(os, "Scale factor", scaleFactor_);
writeCommented(os, "Time");
if (writeArea_)
{
os << tab << "Area";
}
forAll(fields_, i)
{
os << tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
os << endl;
}
}
template<>
Foam::scalar Foam::functionObjects::fieldValues::surfaceFieldValue::
processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
switch (operation_)
{
case opSumDirection:
{
vector n(dict_.lookup("direction"));
return gSum(pos(values*(Sf & n))*mag(values));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
const scalarField nv(values*(Sf & n));
return gSum(pos(nv)*mag(values) - neg(nv)*mag(values));
}
default:
{
// Fall through to other operations
return processSameTypeValues(values, Sf, weightField);
}
}
}
template<>
Foam::vector Foam::functionObjects::fieldValues::surfaceFieldValue::
processValues
(
const Field<vector>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
switch (operation_)
{
case opSumDirection:
{
vector n(dict_.lookup("direction"));
n /= mag(n) + ROOTVSMALL;
const scalarField nv(n & values);
return gSum(pos(nv)*n*(nv));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
n /= mag(n) + ROOTVSMALL;
const scalarField nv(n & values);
return gSum(pos(nv)*n*(nv));
}
case opAreaNormalAverage:
{
scalar result = gSum(values & Sf)/gSum(mag(Sf));
return vector(result, 0.0, 0.0);
}
case opAreaNormalIntegrate:
{
scalar result = gSum(values & Sf);
return vector(result, 0.0, 0.0);
}
default:
{
// Fall through to other operations
return processSameTypeValues(values, Sf, weightField);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldValue(name, runTime, dict, typeName),
surfaceWriterPtr_(nullptr),
regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"),
orientWeightField_(false),
orientedFieldsStart_(labelMax),
writeArea_(dict.lookupOrDefault("writeArea", false)),
nFaces_(0),
faceId_(),
facePatchId_(),
faceSign_()
{
read(dict);
writeFileHeader(file());
}
Foam::functionObjects::fieldValues::surfaceFieldValue::surfaceFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName),
surfaceWriterPtr_(nullptr),
regionType_(regionTypeNames_.read(dict.lookup("regionType"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"),
orientWeightField_(false),
orientedFieldsStart_(labelMax),
writeArea_(dict.lookupOrDefault("writeArea", false)),
nFaces_(0),
faceId_(),
facePatchId_(),
faceSign_()
{
read(dict);
writeFileHeader(file());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::surfaceFieldValue::~surfaceFieldValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
(
const dictionary& dict
)
{
fieldValue::read(dict);
initialise(dict);
return true;
}
bool Foam::functionObjects::fieldValues::surfaceFieldValue::write()
{
if (operation_ != opNone)
{
fieldValue::write();
}
if (surfacePtr_.valid())
{
surfacePtr_().update();
}
if (operation_ != opNone && Pstream::master())
{
writeTime(file());
}
if (writeArea_)
{
totalArea_ = totalArea();
if (operation_ != opNone && Pstream::master())
{
file() << tab << totalArea_;
}
Log << " total area = " << totalArea_ << endl;
}
// Construct weight field. Note: zero size means weight = 1
scalarField weightField;
if (weightFieldName_ != "none")
{
weightField =
getFieldValues<scalar>
(
weightFieldName_,
true,
orientWeightField_
);
}
// Process the fields
forAll(fields_, i)
{
const word& fieldName = fields_[i];
bool ok = false;
bool orient = i >= orientedFieldsStart_;
ok = ok || writeValues<scalar>(fieldName, weightField, orient);
ok = ok || writeValues<vector>(fieldName, weightField, orient);
ok = ok
|| writeValues<sphericalTensor>(fieldName, weightField, orient);
ok = ok || writeValues<symmTensor>(fieldName, weightField, orient);
ok = ok || writeValues<tensor>(fieldName, weightField, orient);
if (!ok)
{
WarningInFunction
<< "Requested field " << fieldName
<< " not found in database and not processed"
<< endl;
}
}
if (operation_ != opNone && Pstream::master())
{
file() << endl;
}
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,467 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fieldValues::surfaceFieldValue
Group
grpFieldFunctionObjects
Description
Provides a 'face regionType' variant of the fieldValues function object.
Given a list of user-specified fields and a selection of mesh (or general
surface) faces, a number of operations can be performed, such as sums,
averages and integrations.
For example, to calculate the volumetric or mass flux across a patch,
apply the 'sum' operator to the flux field (typically \c phi)
Usage
Examples of function object specification:
\verbatim
movingWallPatch
{
type surfaceFieldValue;
libs ("libfieldFunctionObjects.so");
log true;
writeControl writeTime;
writeFields true;
regionType patch;
name movingWall;
operation areaAverage;
fields (p phi U);
}
surfaceFieldValue1
{
type surfaceFieldValue;
libs ("libfieldFunctionObjects.so");
log true;
writeControl writeTime;
writeFields true;
surfaceFormat none;
regionType faceZone;
name f0;
operation sum;
weightField alpha1;
fields (p phi U);
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: surfaceFieldValue | yes |
log | write data to standard output | no | no
writeFields | Write the region field values | yes |
writeArea | Write the area of the surfaceFieldValue | no |
surfaceFormat | output value format | no |
regionType | face regionType: see below | yes |
name | name of face regionType if required | no |
operation | operation to perform | yes |
weightField | name of field to apply weighting | no |
orientedWeightField | name of oriented field to apply weighting | no |
scaleFactor | scale factor | no | 1
fields | list of fields to operate on | yes |
orientedFields | list of oriented fields to operate on | no |
\endtable
Where \c regionType is defined by
\plaintable
faceZone | requires a 'name' entry to specify the faceZone
patch | requires a 'name' entry to specify the patch
sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
\endplaintable
The \c operation is one of:
\plaintable
none | no operation
sum | sum
sumMag | sum of component magnitudes
sumDirection | sum values which are positive in given direction
sumDirectionBalance | sum of balance of values in given direction
average | ensemble average
weightedAverage | weighted average
areaAverage | area weighted average
weightedAreaAverage | weighted area average
areaIntegrate | area integral
min | minimum
max | maximum
CoV | coefficient of variation: standard deviation/mean
areaNormalAverage| area weighted average in face normal direction
areaNormalIntegrate | area weighted integral in face normal directon
\endplaintable
Note
- The values reported by the areaNormalAverage and areaNormalIntegrate
operations are written as the first component of a field with the same
rank as the input field.
- faces on empty patches get ignored
- if the field is a volField the \c faceZone can only consist of boundary
faces
- the `oriented' entries relate to mesh-oriented fields, such as the
flux, phi. These fields will be oriented according to the face normals.
- using \c sampledSurface:
- not available for surface fields
- if interpolate=true they use \c interpolationCellPoint
otherwise they use cell values
- each triangle in \c sampledSurface is logically only in one cell
so interpolation will be wrong when triangles are larger than
cells. This can only happen for sampling on a \c triSurfaceMesh
- take care when using isoSurfaces - these might have duplicate
triangles and so integration might be wrong
See also
Foam::fieldValues
Foam::functionObject
SourceFiles
surfaceFieldValue.C
surfaceFieldValueTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_surfaceFieldValue_H
#define functionObjects_surfaceFieldValue_H
#include "fieldValue.H"
#include "NamedEnum.H"
#include "faceList.H"
#include "surfaceMesh.H"
#include "fvsPatchField.H"
#include "volFieldsFwd.H"
#include "surfFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class sampledSurface;
class surfaceWriter;
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class surfaceFieldValue Declaration
\*---------------------------------------------------------------------------*/
class surfaceFieldValue
:
public fieldValue
{
public:
// Public data types
//- region type enumeration
enum regionTypes
{
stFaceZone,
stPatch,
stSampledSurface
};
//- region type names
static const NamedEnum<regionTypes, 3> regionTypeNames_;
//- Operation type enumeration
enum operationType
{
opNone, //!< None
opSum, //!< Sum
opSumMag, //!< Magnitude of sum
opSumDirection, //!< Sum in a given direction
opSumDirectionBalance, //!< Sum in a given direction for multiple
opAverage, //!< Average
opWeightedAverage, //!< Weighted average
opAreaAverage, //!< Area average
opWeightedAreaAverage, //!< Weighted area average
opAreaIntegrate, //!< Area integral
opMin, //!< Minimum
opMax, //!< Maximum
opCoV, //!< Coefficient of variation
opAreaNormalAverage, //!< Area average in normal direction
opAreaNormalIntegrate //!< Area integral in normal direction
};
//- Operation type names
static const NamedEnum<operationType, 15> operationTypeNames_;
private:
// Private Member Functions
//- Set faces to evaluate based on a face zone
void setFaceZoneFaces();
//- Set faces to evaluate based on a patch
void setPatchFaces();
//- Set faces according to sampledSurface
void sampledSurfaceFaces(const dictionary&);
//- Combine mesh faces and points from multiple processors
void combineMeshGeometry
(
faceList& faces,
pointField& points
) const;
//- Combine surface faces and points from multiple processors
void combineSurfaceGeometry
(
faceList& faces,
pointField& points
) const;
//- Calculate and return total area of the surfaceFieldValue: sum(magSf)
scalar totalArea() const;
protected:
// Protected data
//- Surface writer
autoPtr<surfaceWriter> surfaceWriterPtr_;
//- region type
regionTypes regionType_;
//- Operation to apply to values
operationType operation_;
//- Weight field name - optional
word weightFieldName_;
//- Flag to indicate if flipMap should be applied to the weight field
bool orientWeightField_;
//- Start index of fields that require application of flipMap
label orientedFieldsStart_;
//- Total area of the surfaceFieldValue
scalar totalArea_;
//- Optionally write the area of the surfaceFieldValue
bool writeArea_;
//- Global number of faces
label nFaces_;
// If operating on mesh faces (faceZone, patch)
//- Local list of face IDs
labelList faceId_;
//- Local list of patch ID per face
labelList facePatchId_;
//- List of +1/-1 representing face flip map
// (1 use as is, -1 negate)
labelList faceSign_;
// If operating on sampledSurface
//- Underlying sampledSurface
autoPtr<sampledSurface> surfacePtr_;
// Protected Member Functions
//- Initialise, e.g. face addressing
void initialise(const dictionary& dict);
//- Return true if the field name is valid
template<class Type>
bool validField(const word& fieldName) const;
//- Return field values by looking up field name
template<class Type>
tmp<Field<Type>> getFieldValues
(
const word& fieldName,
const bool mustGet = false,
const bool applyOrientation = false
) const;
//- Apply the 'operation' to the values. Operation has to
// preserve Type.
template<class Type>
Type processSameTypeValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Apply the 'operation' to the values. Wrapper around
// processSameTypeValues. See also template specialisation below.
template<class Type>
Type processValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
public:
//- Run-time type information
TypeName("surfaceFieldValue");
// Constructors
//- Construct from name, Time and dictionary
surfaceFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from name, objectRegistry and dictionary
surfaceFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~surfaceFieldValue();
// Public Member Functions
//- Return the region type
inline const regionTypes& regionType() const;
//- Return the local list of face IDs
inline const labelList& faceId() const;
//- Return the local list of patch ID per face
inline const labelList& facePatch() const;
//- Return the list of +1/-1 representing face flip map
inline const labelList& faceSign() const;
//- Return the output directory
inline fileName outputDir() const;
//- Templated helper function to output field values
template<class Type>
bool writeValues
(
const word& fieldName,
const scalarField& weightField,
const bool orient
);
//- Filter a surface field according to faceIds
template<class Type>
tmp<Field<Type>> filterField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
const bool applyOrientation
) const;
//- Filter a volume field according to faceIds
template<class Type>
tmp<Field<Type>> filterField
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const bool applyOrientation
) const;
//- Read from dictionary
virtual bool read(const dictionary&);
//- Calculate and write
virtual bool write();
};
//- Specialisation for scalar
template<>
scalar surfaceFieldValue::processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Specialisation for vector
template<>
vector surfaceFieldValue::processValues
(
const Field<vector>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "surfaceFieldValueI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "surfaceFieldValueTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,66 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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 "surfaceFieldValue.H"
#include "Time.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::functionObjects::fieldValues::surfaceFieldValue::regionTypes&
Foam::functionObjects::fieldValues::surfaceFieldValue::regionType() const
{
return regionType_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::surfaceFieldValue::faceId() const
{
return faceId_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::surfaceFieldValue::facePatch() const
{
return facePatchId_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::surfaceFieldValue::faceSign() const
{
return faceSign_;
}
inline Foam::fileName
Foam::functionObjects::fieldValues::surfaceFieldValue::outputDir() const
{
return baseFileDir()/name()/"surface"/time_.timeName();
}
// ************************************************************************* //

View File

@ -0,0 +1,444 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "surfaceFieldValue.H"
#include "surfaceFields.H"
#include "volFields.H"
#include "sampledSurface.H"
#include "surfaceWriter.H"
#include "interpolationCellPoint.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::surfaceFieldValue::validField
(
const word& fieldName
) const
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (regionType_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
{
return true;
}
else if (obr_.foundObject<vf>(fieldName))
{
return true;
}
return false;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::surfaceFieldValue::getFieldValues
(
const word& fieldName,
const bool mustGet,
const bool applyOrientation
) const
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (regionType_ != stSampledSurface && obr_.foundObject<sf>(fieldName))
{
return filterField(obr_.lookupObject<sf>(fieldName), applyOrientation);
}
else if (obr_.foundObject<vf>(fieldName))
{
const vf& fld = obr_.lookupObject<vf>(fieldName);
if (surfacePtr_.valid())
{
if (surfacePtr_().interpolate())
{
const interpolationCellPoint<Type> interp(fld);
tmp<Field<Type>> tintFld(surfacePtr_().interpolate(interp));
const Field<Type>& intFld = tintFld();
// Average
const faceList& faces = surfacePtr_().faces();
tmp<Field<Type>> tavg
(
new Field<Type>(faces.size(), Zero)
);
Field<Type>& avg = tavg.ref();
forAll(faces, facei)
{
const face& f = faces[facei];
forAll(f, fp)
{
avg[facei] += intFld[f[fp]];
}
avg[facei] /= f.size();
}
return tavg;
}
else
{
return surfacePtr_().sample(fld);
}
}
else
{
return filterField(fld, applyOrientation);
}
}
if (mustGet)
{
FatalErrorInFunction
<< "Field " << fieldName << " not found in database"
<< abort(FatalError);
}
return tmp<Field<Type>>(new Field<Type>(0));
}
template<class Type>
Type Foam::functionObjects::fieldValues::surfaceFieldValue::
processSameTypeValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
Type result = Zero;
switch (operation_)
{
case opSum:
{
result = gSum(values);
break;
}
case opSumMag:
{
result = gSum(cmptMag(values));
break;
}
case opSumDirection:
{
FatalErrorInFunction
<< "Operation " << operationTypeNames_[operation_]
<< " not available for values of type "
<< pTraits<Type>::typeName
<< exit(FatalError);
result = Zero;
break;
}
case opSumDirectionBalance:
{
FatalErrorInFunction
<< "Operation " << operationTypeNames_[operation_]
<< " not available for values of type "
<< pTraits<Type>::typeName
<< exit(FatalError);
result = Zero;
break;
}
case opAverage:
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
break;
}
case opWeightedAverage:
{
label wSize = returnReduce(weightField.size(), sumOp<label>());
if (wSize > 0)
{
result =
gSum(weightField*values)/(gSum(weightField) + ROOTVSMALL);
}
else
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
}
break;
}
case opAreaAverage:
{
const scalarField magSf(mag(Sf));
result = gSum(magSf*values)/gSum(magSf);
break;
}
case opWeightedAreaAverage:
{
const scalarField magSf(mag(Sf));
label wSize = returnReduce(weightField.size(), sumOp<label>());
if (wSize > 0)
{
result = gSum(weightField*magSf*values)/gSum(magSf*weightField);
}
else
{
result = gSum(magSf*values)/gSum(magSf);
}
break;
}
case opAreaIntegrate:
{
const scalarField magSf(mag(Sf));
result = gSum(magSf*values);
break;
}
case opMin:
{
result = gMin(values);
break;
}
case opMax:
{
result = gMax(values);
break;
}
case opCoV:
{
const scalarField magSf(mag(Sf));
const scalar gSumMagSf = gSum(magSf);
Type meanValue = gSum(values*magSf)/gSumMagSf;
const label nComp = pTraits<Type>::nComponents;
for (direction d=0; d<nComp; ++d)
{
scalarField vals(values.component(d));
scalar mean = component(meanValue, d);
scalar& res = setComponent(result, d);
res =
sqrt(gSum(magSf*sqr(vals - mean))/gSumMagSf)
/(mean + ROOTVSMALL);
}
break;
}
case opAreaNormalAverage:
{}
case opAreaNormalIntegrate:
{}
case opNone:
{}
}
return result;
}
template<class Type>
Type Foam::functionObjects::fieldValues::surfaceFieldValue::processValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
return processSameTypeValues(values, Sf, weightField);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues
(
const word& fieldName,
const scalarField& weightField,
const bool orient
)
{
const bool ok = validField<Type>(fieldName);
if (ok)
{
Field<Type> values(getFieldValues<Type>(fieldName, true, orient));
vectorField Sf;
if (surfacePtr_.valid())
{
// Get oriented Sf
Sf = surfacePtr_().Sf();
}
else
{
// Get oriented Sf
Sf = filterField(mesh_.Sf(), true);
}
// Write raw values on surface if specified
if (surfaceWriterPtr_.valid())
{
Field<Type> allValues(values);
combineFields(allValues);
faceList faces;
pointField points;
if (surfacePtr_.valid())
{
combineSurfaceGeometry(faces, points);
}
else
{
combineMeshGeometry(faces, points);
}
if (Pstream::master())
{
surfaceWriterPtr_->write
(
outputDir(),
regionTypeNames_[regionType_] + ("_" + regionName_),
points,
faces,
fieldName,
allValues,
false
);
}
}
if (operation_ != opNone)
{
// Apply scale factor
values *= scaleFactor_;
Type result = processValues(values, Sf, weightField);
file()<< tab << result;
Log << " " << operationTypeNames_[operation_]
<< "(" << regionName_ << ") of " << fieldName
<< " = " << result << endl;
// Write state/results information
const word& opName = operationTypeNames_[operation_];
word resultName =
opName + '(' + regionName_ + ',' + fieldName + ')';
this->setResult(resultName, result);
}
}
return ok;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
(
const GeometricField<Type, fvPatchField, volMesh>& field,
const bool applyOrientation
) const
{
tmp<Field<Type>> tvalues(new Field<Type>(faceId_.size()));
Field<Type>& values = tvalues.ref();
forAll(values, i)
{
label facei = faceId_[i];
label patchi = facePatchId_[i];
if (patchi >= 0)
{
values[i] = field.boundaryField()[patchi][facei];
}
else
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< regionTypeNames_[regionType_] << "(" << regionName_ << "):"
<< nl
<< " Unable to process internal faces for volume field "
<< field.name() << nl << abort(FatalError);
}
}
if (applyOrientation)
{
forAll(values, i)
{
values[i] *= faceSign_[i];
}
}
return tvalues;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::surfaceFieldValue::filterField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& field,
const bool applyOrientation
) const
{
tmp<Field<Type>> tvalues(new Field<Type>(faceId_.size()));
Field<Type>& values = tvalues.ref();
forAll(values, i)
{
label facei = faceId_[i];
label patchi = facePatchId_[i];
if (patchi >= 0)
{
values[i] = field.boundaryField()[patchi][facei];
}
else
{
values[i] = field[facei];
}
}
if (applyOrientation)
{
forAll(values, i)
{
values[i] *= faceSign_[i];
}
}
return tvalues;
}
// ************************************************************************* //

View File

@ -0,0 +1,218 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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 "volFieldValue.H"
#include "fvMesh.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(volFieldValue, 0);
addToRunTimeSelectionTable(fieldValue, volFieldValue, dictionary);
addToRunTimeSelectionTable(functionObject, volFieldValue, dictionary);
}
}
}
template<>
const char*
Foam::NamedEnum
<
Foam::functionObjects::fieldValues::volFieldValue::operationType,
11
>::names[] =
{
"none",
"sum",
"sumMag",
"average",
"weightedAverage",
"volAverage",
"weightedVolAverage",
"volIntegrate",
"min",
"max",
"CoV"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::volFieldValue::operationType,
11
> Foam::functionObjects::fieldValues::volFieldValue::operationTypeNames_;
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::volFieldValue::initialise
(
const dictionary& dict
)
{
if (dict.readIfPresent("weightField", weightFieldName_))
{
Info<< " weight field = " << weightFieldName_;
}
Info<< nl << endl;
}
void Foam::functionObjects::fieldValues::volFieldValue::writeFileHeader
(
Ostream& os
) const
{
volRegion::writeFileHeader(*this, os);
writeCommented(os, "Time");
forAll(fields_, fieldi)
{
os << tab << operationTypeNames_[operation_]
<< "(" << fields_[fieldi] << ")";
}
os << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldValue(name, runTime, dict, typeName),
volRegion(fieldValue::mesh_, dict),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none")
{
read(dict);
writeFileHeader(file());
}
Foam::functionObjects::fieldValues::volFieldValue::volFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName),
volRegion(fieldValue::mesh_, dict),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none")
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::volFieldValue::~volFieldValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::volFieldValue::read
(
const dictionary& dict
)
{
fieldValue::read(dict);
// No additional info to read
initialise(dict);
return true;
}
bool Foam::functionObjects::fieldValues::volFieldValue::write()
{
fieldValue::write();
if (Pstream::master())
{
writeTime(file());
}
// Construct weight field. Note: zero size means weight = 1
scalarField weightField;
if (weightFieldName_ != "none")
{
weightField =
getFieldValues<scalar>
(
weightFieldName_,
true
);
}
forAll(fields_, i)
{
const word& fieldName = fields_[i];
bool ok = false;
ok = ok || writeValues<scalar>(fieldName, weightField);
ok = ok || writeValues<vector>(fieldName, weightField);
ok = ok || writeValues<sphericalTensor>(fieldName, weightField);
ok = ok || writeValues<symmTensor>(fieldName, weightField);
ok = ok || writeValues<tensor>(fieldName, weightField);
if (!ok)
{
WarningInFunction
<< "Requested field " << fieldName
<< " not found in database and not processed"
<< endl;
}
}
if (Pstream::master())
{
file()<< endl;
}
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,259 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fieldValues::volFieldValue
Group
grpFieldFunctionObjects
Description
Provides a 'volRegion' specialization of the fieldValue function object.
Given a list of user-specified fields and a 'volRegion', a number of
operations can be performed, such as sums, averages and integrations.
Usage
Example of function object specification:
\verbatim
volFieldValue1
{
type volFieldValue;
libs ("libfieldFunctionObjects.so");
log true;
writeControl writeTime;
writeFields true;
regionType cellZone;
name c0;
operation volAverage;
weightField alpha1;
fields
(
p
U
);
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | Type name: volFieldValue | yes |
log | Write data to standard output | no | no
writeFields | Write the region field values | yes |
regionType | volRegion type: see below | yes |
name | Name of volRegion if required | no |
operation | Operation to perform | yes |
weightField | Name of field to apply weighting | no |
fields | List of fields to operate on | yes |
\endtable
Where \c regionType is defined by
\plaintable
cellZone | requires a 'name' entry to specify the cellZone
all | all cells
\endplaintable
The \c operation is one of:
\plaintable
none | No operation
sum | Sum
sumMag | Sum of component magnitudes
average | Ensemble average
weightedAverage | Weighted average
volAverage | Volume weighted average
weightedVolAverage | Weighted volume average
volIntegrate | Volume integral
min | Minimum
max | Maximum
CoV | Coefficient of variation: standard deviation/mean
\endplaintable
See also
Foam::functionObjects::fieldValues::fieldValue
Foam::functionObjects::volRegion
Foam::functionObject
SourceFiles
volFieldValue.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_volFieldValue_H
#define functionObjects_volFieldValue_H
#include "fieldValue.H"
#include "volRegion.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class volFieldValue Declaration
\*---------------------------------------------------------------------------*/
class volFieldValue
:
public fieldValue,
public volRegion
{
public:
// Public data types
//- Operation type enumeration
enum operationType
{
opNone,
opSum,
opSumMag,
opAverage,
opWeightedAverage,
opVolAverage,
opWeightedVolAverage,
opVolIntegrate,
opMin,
opMax,
opCoV
};
//- Operation type names
static const NamedEnum<operationType, 11> operationTypeNames_;
protected:
// Protected data
//- Operation to apply to values
operationType operation_;
//- Weight field name - only used for opWeightedAverage mode
word weightFieldName_;
// Protected Member Functions
//- Initialise, e.g. cell addressing
void initialise(const dictionary& dict);
//- Return true if the field name is valid
template<class Type>
bool validField(const word& fieldName) const;
//- Insert field values into values list
template<class Type>
tmp<Field<Type>> getFieldValues
(
const word& fieldName,
const bool mustGet = false
) const;
//- Apply the 'operation' to the values
template<class Type>
Type processValues
(
const Field<Type>& values,
const scalarField& V,
const scalarField& weightField
) const;
//- Output file header information
virtual void writeFileHeader(Ostream& os) const;
public:
//- Run-time type information
TypeName("volFieldValue");
// Constructors
//- Construct from name, Time and dictionary
volFieldValue
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from name, objectRegistry and dictionary
volFieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~volFieldValue();
// Public Member Functions
//- Templated helper function to output field values
template<class Type>
bool writeValues(const word& fieldName, const scalarField& weightField);
//- Filter a field according to cellIds
template<class Type>
tmp<Field<Type>> filterField(const Field<Type>& field) const;
//- Read from dictionary
virtual bool read(const dictionary&);
//- Calculate and write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "volFieldValueTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,248 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "volFieldValue.H"
#include "volFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::volFieldValue::validField
(
const word& fieldName
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (obr_.foundObject<vf>(fieldName))
{
return true;
}
return false;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::volFieldValue::getFieldValues
(
const word& fieldName,
const bool mustGet
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (obr_.foundObject<vf>(fieldName))
{
return filterField(obr_.lookupObject<vf>(fieldName));
}
if (mustGet)
{
FatalErrorInFunction
<< "Field " << fieldName << " not found in database"
<< abort(FatalError);
}
return tmp<Field<Type>>(new Field<Type>(0.0));
}
template<class Type>
Type Foam::functionObjects::fieldValues::volFieldValue::processValues
(
const Field<Type>& values,
const scalarField& V,
const scalarField& weightField
) const
{
Type result = Zero;
switch (operation_)
{
case opSum:
{
result = gSum(values);
break;
}
case opSumMag:
{
result = gSum(cmptMag(values));
break;
}
case opAverage:
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
break;
}
case opWeightedAverage:
{
label wSize = returnReduce(weightField.size(), sumOp<label>());
if (wSize > 0)
{
result =
gSum(weightField*values)/(gSum(weightField) + ROOTVSMALL);
}
else
{
label n = returnReduce(values.size(), sumOp<label>());
result = gSum(values)/(scalar(n) + ROOTVSMALL);
}
break;
}
case opVolAverage:
{
result = gSum(values*V)/(gSum(V) + ROOTVSMALL);
break;
}
case opWeightedVolAverage:
{
result = gSum(weightField*V*values)/gSum(weightField*V);
break;
}
case opVolIntegrate:
{
result = gSum(V*values);
break;
}
case opMin:
{
result = gMin(values);
break;
}
case opMax:
{
result = gMax(values);
break;
}
case opCoV:
{
const scalar sumV = gSum(V);
Type meanValue = gSum(V*values)/sumV;
const label nComp = pTraits<Type>::nComponents;
for (direction d=0; d<nComp; ++d)
{
scalarField vals(values.component(d));
scalar mean = component(meanValue, d);
scalar& res = setComponent(result, d);
res = sqrt(gSum(V*sqr(vals - mean))/sumV)/(mean + ROOTVSMALL);
}
break;
}
case opNone:
{}
}
return result;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::volFieldValue::writeValues
(
const word& fieldName,
const scalarField& weightField
)
{
const bool ok = validField<Type>(fieldName);
if (ok)
{
Field<Type> values(getFieldValues<Type>(fieldName));
scalarField V(filterField(fieldValue::mesh_.V()));
if (writeFields_)
{
Field<Type> allValues(values);
combineFields(allValues);
if (Pstream::master())
{
IOField<Type>
(
IOobject
(
fieldName + '_' + regionTypeNames_[regionType_]
+ '-' + volRegion::regionName_,
obr_.time().timeName(),
obr_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
scaleFactor_*weightField*allValues
).write();
}
}
// Apply scale factor
values *= scaleFactor_;
Type result = processValues(values, V, weightField);
file()<< tab << result;
Log << " " << operationTypeNames_[operation_]
<< "(" << volRegion::regionName_ << ") of " << fieldName
<< " = " << result << endl;
// Write state/results information
const word& opName = operationTypeNames_[operation_];
word resultName =
opName + '(' + volRegion::regionName_ + ',' + fieldName + ')';
this->setResult(resultName, result);
}
return ok;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::volFieldValue::filterField
(
const Field<Type>& field
) const
{
if (isNull(cellIDs()))
{
return field;
}
else
{
return tmp<Field<Type>>(new Field<Type>(field, cellIDs()));
}
}
// ************************************************************************* //

View File

@ -0,0 +1,124 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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
flowType
Group
grpPostProcessingUtilities
Description
Calculates and writes the flowType of velocity field U.
The -noWrite option has no meaning.
The flow type parameter is obtained according to the following equation:
\verbatim
|D| - |Omega|
lambda = -------------
|D| + |Omega|
-1 = rotational flow
0 = simple shear flow
1 = planar extensional flow
\endverbatim
\*---------------------------------------------------------------------------*/
#include "flowType.H"
#include "fvcGrad.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(flowType, 0);
addToRunTimeSelectionTable
(
functionObject,
flowType,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::flowType::calc()
{
if (foundObject<volVectorField>(fieldName_))
{
const volVectorField& U = lookupObject<volVectorField>(fieldName_);
const tmp<volTensorField> tgradU(fvc::grad(U));
const volTensorField& gradU = tgradU();
volScalarField magD(mag(symm(gradU)));
volScalarField magOmega (mag(skew(gradU)));
dimensionedScalar smallMagD("smallMagD", magD.dimensions(), SMALL);
const volTensorField SSplusWW
(
(symm(gradU) & symm(gradU))
+ (skew(gradU) & skew(gradU))
);
return store
(
resultName_,
(magD - magOmega)/(magD + magOmega + smallMagD)
);
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::flowType::flowType
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "U")
{
setResultName(typeName, "U");
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::flowType::~flowType()
{}
// ************************************************************************* //

View File

@ -0,0 +1,110 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::flowType
Group
grpFieldFunctionObjects
Description
Calculates and writes the flowType of a velocity field.
The flow type parameter is obtained according to the following equation:
\verbatim
|D| - |Omega|
lambda = -------------
|D| + |Omega|
-1 = rotational flow
0 = simple shear flow
1 = planar extensional flow
\endverbatim
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
flowType.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_flowType_H
#define functionObjects_flowType_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class flowType Declaration
\*---------------------------------------------------------------------------*/
class flowType
:
public fieldExpression
{
// Private Member Functions
//- Calculate the flowType field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("flowType");
// Constructors
//- Construct from Time and dictionary
flowType
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~flowType();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,884 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "fluxSummary.H"
#include "surfaceFields.H"
#include "dictionary.H"
#include "Time.H"
#include "syncTools.H"
#include "meshTools.H"
#include "PatchEdgeFaceWave.H"
#include "patchEdgeFaceRegion.H"
#include "globalIndex.H"
#include "OBJstream.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(fluxSummary, 0);
addToRunTimeSelectionTable
(
functionObject,
fluxSummary,
dictionary
);
}
template<>
const char* NamedEnum
<
functionObjects::fluxSummary::modeType,
3
>::names[] =
{
"faceZone",
"faceZoneAndDirection",
"cellZoneAndDirection"
};
}
const Foam::NamedEnum<Foam::functionObjects::fluxSummary::modeType, 3>
Foam::functionObjects::fluxSummary::modeTypeNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fluxSummary::initialiseFaceZone
(
const word& faceZoneName,
DynamicList<word>& faceZoneNames,
DynamicList<List<label>>& faceID,
DynamicList<List<label>>& facePatchID,
DynamicList<List<scalar>>& faceSign
) const
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
label zonei = mesh.faceZones().findZoneID(faceZoneName);
if (zonei == -1)
{
FatalErrorInFunction
<< "Unable to find faceZone " << faceZoneName
<< ". Valid faceZones are: " << mesh.faceZones().names()
<< exit(FatalError);
}
faceZoneNames.append(faceZoneName);
const faceZone& fZone = mesh.faceZones()[zonei];
DynamicList<label> faceIDs(fZone.size());
DynamicList<label> facePatchIDs(fZone.size());
DynamicList<scalar> faceSigns(fZone.size());
forAll(fZone, i)
{
label facei = fZone[i];
label faceID = -1;
label facePatchID = -1;
if (mesh.isInternalFace(facei))
{
faceID = facei;
facePatchID = -1;
}
else
{
facePatchID = mesh.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh.boundaryMesh()[facePatchID];
if (isA<coupledPolyPatch>(pp))
{
if (refCast<const coupledPolyPatch>(pp).owner())
{
faceID = pp.whichFace(facei);
}
else
{
faceID = -1;
}
}
else if (!isA<emptyPolyPatch>(pp))
{
faceID = facei - pp.start();
}
else
{
faceID = -1;
facePatchID = -1;
}
}
if (faceID >= 0)
{
// Orientation set by faceZone flip map
if (fZone.flipMap()[facei])
{
faceSigns.append(-1);
}
else
{
faceSigns.append(1);
}
faceIDs.append(faceID);
facePatchIDs.append(facePatchID);
}
}
faceID.append(faceIDs);
facePatchID.append(facePatchIDs);
faceSign.append(faceSigns);
}
void Foam::functionObjects::fluxSummary::initialiseFaceZoneAndDirection
(
const word& faceZoneName,
const vector& dir,
DynamicList<vector>& zoneRefDir,
DynamicList<word>& faceZoneNames,
DynamicList<List<label>>& faceID,
DynamicList<List<label>>& facePatchID,
DynamicList<List<scalar>>& faceSign
) const
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
vector refDir = dir/(mag(dir) + ROOTVSMALL);
label zonei = mesh.faceZones().findZoneID(faceZoneName);
if (zonei == -1)
{
FatalErrorInFunction
<< "Unable to find faceZone " << faceZoneName
<< ". Valid faceZones are: " << mesh.faceZones().names()
<< exit(FatalError);
}
faceZoneNames.append(faceZoneName);
zoneRefDir.append(refDir);
const faceZone& fZone = mesh.faceZones()[zonei];
DynamicList<label> faceIDs(fZone.size());
DynamicList<label> facePatchIDs(fZone.size());
DynamicList<scalar> faceSigns(fZone.size());
const surfaceVectorField& Sf = mesh.Sf();
const surfaceScalarField& magSf = mesh.magSf();
vector n(Zero);
forAll(fZone, i)
{
label facei = fZone[i];
label faceID = -1;
label facePatchID = -1;
if (mesh.isInternalFace(facei))
{
faceID = facei;
facePatchID = -1;
}
else
{
facePatchID = mesh.boundaryMesh().whichPatch(facei);
const polyPatch& pp = mesh.boundaryMesh()[facePatchID];
if (isA<coupledPolyPatch>(pp))
{
if (refCast<const coupledPolyPatch>(pp).owner())
{
faceID = pp.whichFace(facei);
}
else
{
faceID = -1;
}
}
else if (!isA<emptyPolyPatch>(pp))
{
faceID = facei - pp.start();
}
else
{
faceID = -1;
facePatchID = -1;
}
}
if (faceID >= 0)
{
// orientation set by comparison with reference direction
if (facePatchID != -1)
{
n = Sf.boundaryField()[facePatchID][faceID]
/(magSf.boundaryField()[facePatchID][faceID] + ROOTVSMALL);
}
else
{
n = Sf[faceID]/(magSf[faceID] + ROOTVSMALL);
}
if ((n & refDir) > tolerance_)
{
faceSigns.append(1);
}
else
{
faceSigns.append(-1);
}
faceIDs.append(faceID);
facePatchIDs.append(facePatchID);
}
}
faceID.append(faceIDs);
facePatchID.append(facePatchIDs);
faceSign.append(faceSigns);
}
void Foam::functionObjects::fluxSummary::initialiseCellZoneAndDirection
(
const word& cellZoneName,
const vector& dir,
DynamicList<vector>& zoneRefDir,
DynamicList<word>& faceZoneNames,
DynamicList<List<label>>& faceID,
DynamicList<List<label>>& facePatchID,
DynamicList<List<scalar>>& faceSign
) const
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
vector refDir = dir/(mag(dir) + ROOTVSMALL);
const label cellZonei = mesh.cellZones().findZoneID(cellZoneName);
if (cellZonei == -1)
{
FatalErrorInFunction
<< "Unable to find cellZone " << cellZoneName
<< ". Valid zones are: " << mesh.cellZones().names()
<< exit(FatalError);
}
const label nInternalFaces = mesh.nInternalFaces();
const polyBoundaryMesh& pbm = mesh.boundaryMesh();
labelList cellAddr(mesh.nCells(), -1);
const labelList& cellIDs = mesh.cellZones()[cellZonei];
UIndirectList<label>(cellAddr, cellIDs) = identity(cellIDs.size());
labelList nbrFaceCellAddr(mesh.nFaces() - nInternalFaces, -1);
forAll(pbm, patchi)
{
const polyPatch& pp = pbm[patchi];
if (pp.coupled())
{
forAll(pp, i)
{
label facei = pp.start() + i;
label nbrFacei = facei - nInternalFaces;
label own = mesh.faceOwner()[facei];
nbrFaceCellAddr[nbrFacei] = cellAddr[own];
}
}
}
// Correct boundary values for parallel running
syncTools::swapBoundaryFaceList(mesh, nbrFaceCellAddr);
// Collect faces
DynamicList<label> faceIDs(floor(0.1*mesh.nFaces()));
DynamicList<label> facePatchIDs(faceIDs.size());
DynamicList<label> faceLocalPatchIDs(faceIDs.size());
DynamicList<scalar> faceSigns(faceIDs.size());
// Internal faces
for (label facei = 0; facei < nInternalFaces; facei++)
{
const label own = cellAddr[mesh.faceOwner()[facei]];
const label nbr = cellAddr[mesh.faceNeighbour()[facei]];
if (((own != -1) && (nbr == -1)) || ((own == -1) && (nbr != -1)))
{
vector n = mesh.faces()[facei].normal(mesh.points());
n /= mag(n) + ROOTVSMALL;
if ((n & refDir) > tolerance_)
{
faceIDs.append(facei);
faceLocalPatchIDs.append(facei);
facePatchIDs.append(-1);
faceSigns.append(1);
}
else if ((n & -refDir) > tolerance_)
{
faceIDs.append(facei);
faceLocalPatchIDs.append(facei);
facePatchIDs.append(-1);
faceSigns.append(-1);
}
}
}
// Loop over boundary faces
forAll(pbm, patchi)
{
const polyPatch& pp = pbm[patchi];
forAll(pp, localFacei)
{
const label facei = pp.start() + localFacei;
const label own = cellAddr[mesh.faceOwner()[facei]];
const label nbr = nbrFaceCellAddr[facei - nInternalFaces];
if ((own != -1) && (nbr == -1))
{
vector n = mesh.faces()[facei].normal(mesh.points());
n /= mag(n) + ROOTVSMALL;
if ((n & refDir) > tolerance_)
{
faceIDs.append(facei);
faceLocalPatchIDs.append(localFacei);
facePatchIDs.append(patchi);
faceSigns.append(1);
}
else if ((n & -refDir) > tolerance_)
{
faceIDs.append(facei);
faceLocalPatchIDs.append(localFacei);
facePatchIDs.append(patchi);
faceSigns.append(-1);
}
}
}
}
// Convert into primitivePatch for convenience
indirectPrimitivePatch patch
(
IndirectList<face>(mesh.faces(), faceIDs),
mesh.points()
);
if (debug)
{
OBJstream os(mesh.time().path()/"patch.obj");
faceList faces(patch);
os.write(faces, mesh.points(), false);
}
// Data on all edges and faces
List<patchEdgeFaceRegion> allEdgeInfo(patch.nEdges());
List<patchEdgeFaceRegion> allFaceInfo(patch.size());
bool search = true;
DebugInfo
<< "initialiseCellZoneAndDirection: "
<< "Starting walk to split patch into faceZones"
<< endl;
globalIndex globalFaces(patch.size());
label oldFaceID = 0;
label regioni = 0;
while (search)
{
DynamicList<label> changedEdges;
DynamicList<patchEdgeFaceRegion> changedInfo;
label seedFacei = labelMax;
for (; oldFaceID < patch.size(); oldFaceID++)
{
if (allFaceInfo[oldFaceID].region() == -1)
{
seedFacei = globalFaces.toGlobal(oldFaceID);
break;
}
}
reduce(seedFacei, minOp<label>());
if (seedFacei == labelMax)
{
break;
}
if (globalFaces.isLocal(seedFacei))
{
label localFacei = globalFaces.toLocal(seedFacei);
const labelList& fEdges = patch.faceEdges()[localFacei];
forAll(fEdges, i)
{
if (allEdgeInfo[fEdges[i]].region() != -1)
{
WarningInFunction
<< "Problem in edge face wave: attempted to assign a "
<< "value to an edge that has already been visited. "
<< "Edge info: " << allEdgeInfo[fEdges[i]]
<< endl;
}
changedEdges.append(fEdges[i]);
changedInfo.append(regioni);
}
}
PatchEdgeFaceWave
<
indirectPrimitivePatch,
patchEdgeFaceRegion
> calc
(
mesh,
patch,
changedEdges,
changedInfo,
allEdgeInfo,
allFaceInfo,
returnReduce(patch.nEdges(), sumOp<label>())
);
if (debug)
{
label nCells = 0;
forAll(allFaceInfo, facei)
{
if (allFaceInfo[facei].region() == regioni)
{
nCells++;
}
}
Info<< "*** region:" << regioni
<< " found:" << returnReduce(nCells, sumOp<label>())
<< " faces" << endl;
}
regioni++;
}
// Collect the data per region
label nRegion = regioni;
List<DynamicList<label>> regionFaceIDs(nRegion);
List<DynamicList<label>> regionFacePatchIDs(nRegion);
List<DynamicList<scalar>> regionFaceSigns(nRegion);
forAll(allFaceInfo, facei)
{
regioni = allFaceInfo[facei].region();
regionFaceIDs[regioni].append(faceLocalPatchIDs[facei]);
regionFacePatchIDs[regioni].append(facePatchIDs[facei]);
regionFaceSigns[regioni].append(faceSigns[facei]);
}
// Transfer to persistent storage
forAll(regionFaceIDs, regioni)
{
const word zoneName = cellZoneName + ":faceZone" + Foam::name(regioni);
faceZoneNames.append(zoneName);
zoneRefDir.append(refDir);
faceID.append(regionFaceIDs[regioni]);
facePatchID.append(regionFacePatchIDs[regioni]);
faceSign.append(regionFaceSigns[regioni]);
// Write OBj of faces to file
if (debug)
{
OBJstream os(mesh.time().path()/zoneName + ".obj");
faceList faces(mesh.faces(), regionFaceIDs[regioni]);
os.write(faces, mesh.points(), false);
}
}
if (log)
{
Info<< type() << " " << name() << " output:" << nl
<< " Created " << faceID.size()
<< " separate face zones from cell zone " << cellZoneName << nl;
forAll(faceZoneNames, i)
{
label nFaces = returnReduce(faceID[i].size(), sumOp<label>());
Info<< " " << faceZoneNames[i] << ": "
<< nFaces << " faces" << nl;
}
Info<< endl;
}
}
void Foam::functionObjects::fluxSummary::initialiseFaceArea()
{
faceArea_.setSize(faceID_.size(), 0);
const fvMesh& mesh = refCast<const fvMesh>(obr_);
const surfaceScalarField& magSf = mesh.magSf();
forAll(faceID_, zonei)
{
const labelList& faceIDs = faceID_[zonei];
const labelList& facePatchIDs = facePatchID_[zonei];
scalar sumMagSf = 0;
forAll(faceIDs, i)
{
label facei = faceIDs[i];
if (facePatchIDs[i] == -1)
{
sumMagSf += magSf[facei];
}
else
{
label patchi = facePatchIDs[i];
sumMagSf += magSf.boundaryField()[patchi][facei];
}
}
faceArea_[zonei] = returnReduce(sumMagSf, sumOp<scalar>());
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fluxSummary::fluxSummary
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name, typeName, dict),
mode_(mdFaceZone),
scaleFactor_(1),
phiName_("phi"),
faceZoneName_(),
refDir_(),
faceID_(),
facePatchID_(),
faceSign_(),
faceArea_(),
filePtrs_(),
tolerance_(0.8)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fluxSummary::~fluxSummary()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fluxSummary::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
writeFile::read(dict);
mode_ = modeTypeNames_.read(dict.lookup("mode"));
phiName_= dict.lookupOrDefault<word>("phiName", "phi");
dict.readIfPresent("scaleFactor", scaleFactor_);
dict.readIfPresent("tolerance", tolerance_);
// Initialise with capacity of 10 faceZones
DynamicList<vector> refDir(10);
DynamicList<word> faceZoneName(refDir.size());
DynamicList<List<label>> faceID(refDir.size());
DynamicList<List<label>> facePatchID(refDir.size());
DynamicList<List<scalar>> faceSign(refDir.size());
switch (mode_)
{
case mdFaceZone:
{
List<word> zones(dict.lookup("faceZones"));
forAll(zones, i)
{
initialiseFaceZone
(
zones[i],
faceZoneName,
faceID,
facePatchID,
faceSign
);
}
break;
}
case mdFaceZoneAndDirection:
{
List<Tuple2<word, vector>>
zoneAndDirection(dict.lookup("faceZoneAndDirection"));
forAll(zoneAndDirection, i)
{
initialiseFaceZoneAndDirection
(
zoneAndDirection[i].first(),
zoneAndDirection[i].second(),
refDir,
faceZoneName,
faceID,
facePatchID,
faceSign
);
}
break;
}
case mdCellZoneAndDirection:
{
List<Tuple2<word, vector>>
zoneAndDirection(dict.lookup("cellZoneAndDirection"));
forAll(zoneAndDirection, i)
{
initialiseCellZoneAndDirection
(
zoneAndDirection[i].first(),
zoneAndDirection[i].second(),
refDir,
faceZoneName,
faceID,
facePatchID,
faceSign
);
}
break;
}
default:
{
FatalIOErrorInFunction(dict)
<< "unhandled enumeration " << modeTypeNames_[mode_]
<< abort(FatalIOError);
}
}
faceZoneName_.transfer(faceZoneName);
refDir_.transfer(refDir);
faceID_.transfer(faceID);
facePatchID_.transfer(facePatchID);
faceSign_.transfer(faceSign);
initialiseFaceArea();
if (writeToFile())
{
filePtrs_.setSize(faceZoneName_.size());
forAll(filePtrs_, filei)
{
const word& fzName = faceZoneName_[filei];
filePtrs_.set(filei, createFile(fzName));
writeFileHeader
(
fzName,
faceArea_[filei],
refDir_[filei],
filePtrs_[filei]
);
}
}
// Provide some output
if (log)
{
Info<< type() << " " << name() << " output:" << nl;
forAll(faceZoneName_, zonei)
{
const word& zoneName = faceZoneName_[zonei];
scalar zoneArea = faceArea_[zonei];
Info<< " Zone: " << zoneName << ", area: " << zoneArea << nl;
}
Info<< endl;
}
return true;
}
void Foam::functionObjects::fluxSummary::writeFileHeader
(
const word& fzName,
const scalar area,
const vector& refDir,
Ostream& os
) const
{
writeHeader(os, "Flux summary");
writeHeaderValue(os, "Face zone", fzName);
writeHeaderValue(os, "Total area", area);
switch (mode_)
{
case mdFaceZoneAndDirection:
case mdCellZoneAndDirection:
{
writeHeaderValue(os, "Reference direction", refDir);
break;
}
default:
{}
}
writeHeaderValue(os, "Scale factor", scaleFactor_);
writeCommented(os, "Time");
os << tab << "positive"
<< tab << "negative"
<< tab << "net"
<< tab << "absolute"
<< endl;
}
bool Foam::functionObjects::fluxSummary::execute()
{
return true;
}
bool Foam::functionObjects::fluxSummary::write()
{
const surfaceScalarField& phi = lookupObject<surfaceScalarField>(phiName_);
word flowType = "";
if (phi.dimensions() == dimVolume/dimTime)
{
flowType = "volumetric";
}
else if (phi.dimensions() == dimMass/dimTime)
{
flowType = "mass";
}
else
{
FatalErrorInFunction
<< "Unsupported flux field " << phi.name() << " with dimensions "
<< phi.dimensions() << ". Expected eithe mass flow or volumetric "
<< "flow rate" << abort(FatalError);
}
Log << type() << " " << name() << ' ' << flowType << " write:" << nl;
forAll(faceZoneName_, zonei)
{
const labelList& faceID = faceID_[zonei];
const labelList& facePatchID = facePatchID_[zonei];
const scalarList& faceSign = faceSign_[zonei];
scalar phiPos = scalar(0);
scalar phiNeg = scalar(0);
scalar phif = scalar(0);
forAll(faceID, i)
{
label facei = faceID[i];
label patchi = facePatchID[i];
if (patchi != -1)
{
phif = phi.boundaryField()[patchi][facei];
}
else
{
phif = phi[facei];
}
phif *= faceSign[i];
if (phif > 0)
{
phiPos += phif;
}
else
{
phiNeg += phif;
}
}
reduce(phiPos, sumOp<scalar>());
reduce(phiNeg, sumOp<scalar>());
phiPos *= scaleFactor_;
phiNeg *= scaleFactor_;
scalar netFlux = phiPos + phiNeg;
scalar absoluteFlux = phiPos - phiNeg;
Log << " faceZone " << faceZoneName_[zonei] << ':' << nl
<< " positive : " << phiPos << nl
<< " negative : " << phiNeg << nl
<< " net : " << netFlux << nl
<< " absolute : " << absoluteFlux
<< nl << endl;
if (writeToFile())
{
filePtrs_[zonei]
<< time_.value() << token::TAB
<< phiPos << token::TAB
<< phiNeg << token::TAB
<< netFlux << token::TAB
<< absoluteFlux
<< endl;
}
}
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,263 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fluxSummary
Group
grpFieldFunctionObjects
Description
This function object calculates the flux across selections of faces.
Output comprises, per set of faces, the fluxes:
- positive
- negative
- net
- absolute
Usage
\verbatim
fluxSummary1
{
type fluxSummary;
libs ("libutilityFunctionObjects.so");
...
write yes;
log yes;
mode cellZoneAndDirection;
cellZoneAndDirection
(
(porosity (1 0 0))
);
scaleFactor 1.2;
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: fluxSummary | yes |
write | write flux data to file | no | yes
log | write flux data to standard output | no | yes
mode | mode to generate faces to test | yes |
scaleFactor | optional factor to scale result | no | 1
\endtable
The mode is one of:
- faceZone
- faceZoneAndDirection
- cellZoneAndDirection
Output data is written to files of the form \<timeDir\>/<faceZoneName>.dat
See also
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
Foam::functionObjects::timeControl
SourceFiles
fluxSummary.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fluxSummary_H
#define functionObjects_fluxSummary_H
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "vector.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fluxSummary Declaration
\*---------------------------------------------------------------------------*/
class fluxSummary
:
public fvMeshFunctionObject,
public writeFile
{
public:
// Public enumerations
//- Face mode type
enum modeType
{
mdFaceZone, //!< face zone
mdFaceZoneAndDirection, //!< face zone with prescribed direction
mdCellZoneAndDirection //!< cell zone with prescribed direction
};
//- Mode type names
static const NamedEnum<modeType, 3> modeTypeNames_;
protected:
// Protected data
//- Mode for face determination
modeType mode_;
//- Scale factor
scalar scaleFactor_;
//- Name of flux field, default = phi
word phiName_;
// Per-faceZone information
//- Region names
List<word> faceZoneName_;
//- Reference direction
List<vector> refDir_;
//- Face IDs
List<List<label>> faceID_;
//- Face patch IDs
List<List<label>> facePatchID_;
//- Face flip map signs
List<List<scalar>> faceSign_;
//- Sum of face areas
List<scalar> faceArea_;
//- Output file per face zone
PtrList<OFstream> filePtrs_;
//- Tolerance applied when matching face normals
scalar tolerance_;
// Private Member Functions
//- Initialise face set from face zone
void initialiseFaceZone
(
const word& faceZoneName,
DynamicList<word>& faceZoneNames,
DynamicList<List<label>>& faceID,
DynamicList<List<label>>& facePatchID,
DynamicList<List<scalar>>& faceSign
) const;
//- Initialise face set from face zone and direction
void initialiseFaceZoneAndDirection
(
const word& faceZoneName,
const vector& refDir,
DynamicList<vector>& dir,
DynamicList<word>& faceZoneNames,
DynamicList<List<label>>& faceID,
DynamicList<List<label>>& facePatchID,
DynamicList<List<scalar>>& faceSign
) const;
//- Initialise face set from cell zone and direction
void initialiseCellZoneAndDirection
(
const word& cellZoneName,
const vector& refDir,
DynamicList<vector>& dir,
DynamicList<word>& faceZoneNames,
DynamicList<List<label>>& faceID,
DynamicList<List<label>>& facePatchID,
DynamicList<List<scalar>>& faceSign
) const;
//- Initialise the total area per derived faceZone
void initialiseFaceArea();
//- Output file header information
virtual void writeFileHeader
(
const word& fzName,
const scalar area,
const vector& refDir,
Ostream& os
) const;
//- Disallow default bitwise copy construct
fluxSummary(const fluxSummary&) = delete;
//- Disallow default bitwise assignment
void operator=(const fluxSummary&) = delete;
public:
//- Runtime type information
TypeName("fluxSummary");
// Constructors
//- Construct from Time and dictionary
fluxSummary
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~fluxSummary();
// Member Functions
//- Read the field min/max data
virtual bool read(const dictionary&);
//- Execute, currently does nothing
virtual bool execute();
//- Write the fluxSummary
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,73 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "grad.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(grad, 0);
addToRunTimeSelectionTable(functionObject, grad, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::grad::calc()
{
bool processed = false;
processed = processed || calcGrad<scalar>();
processed = processed || calcGrad<vector>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::grad::grad
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::grad::~grad()
{}
// ************************************************************************* //

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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::grad
Group
grpFieldFunctionObjects
Description
Calculates the gradient of a field.
The operation is limited to scalar and vector volume or surface fields, and
the output is a volume vector or tensor field.
See also
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
grad.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_grad_H
#define functionObjects_grad_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class grad Declaration
\*---------------------------------------------------------------------------*/
class grad
:
public fieldExpression
{
// Private Member Functions
//- Calculate the magnitude of the field and register the result
template<class Type>
bool calcGrad();
//- Calculate the gradient field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("grad");
// Constructors
//- Construct from Time and dictionary
grad
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~grad();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "gradTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,61 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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 "fvcGrad.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::grad::calcGrad()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (foundObject<VolFieldType>(fieldName_))
{
return store
(
resultName_,
fvc::grad(lookupObject<VolFieldType>(fieldName_)),
true
);
}
else if (foundObject<SurfaceFieldType>(fieldName_))
{
return store
(
resultName_,
fvc::grad(lookupObject<SurfaceFieldType>(fieldName_)),
true
);
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,200 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "histogram.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(histogram, 0);
addToRunTimeSelectionTable(functionObject, histogram, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::histogram::writeGraph
(
const coordSet& coords,
const word& fieldName,
const scalarField& values
) const
{
const wordList fieldNames(1, fieldName);
fileName outputPath = baseTimeDir();
mkDir(outputPath);
OFstream graphFile
(
outputPath/formatterPtr_().getFileName(coords, fieldNames)
);
Log << " Writing histogram of " << fieldName
<< " to " << graphFile.name() << endl;
List<const scalarField*> yPtrs(1);
yPtrs[0] = &values;
formatterPtr_().write(coords, fieldNames, yPtrs, graphFile);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::histogram::histogram
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
writeFile(obr_, name)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::histogram::~histogram()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::histogram::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
dict.lookup("field") >> fieldName_;
dict.lookup("max") >> max_;
min_ = dict.lookupOrDefault<scalar>("min", 0);
dict.lookup("nBins") >> nBins_;
word format(dict.lookup("setFormat"));
formatterPtr_ = writer<scalar>::New(format);
return true;
}
bool Foam::functionObjects::histogram::execute()
{
return true;
}
bool Foam::functionObjects::histogram::write()
{
Log << type() << " " << name() << " write:" << nl;
autoPtr<volScalarField> fieldPtr;
if (obr_.foundObject<volScalarField>(fieldName_))
{
Log << " Looking up field " << fieldName_ << endl;
}
else
{
Log << " Reading field " << fieldName_ << endl;
fieldPtr.reset
(
new volScalarField
(
IOobject
(
fieldName_,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh_
)
);
}
const volScalarField& field =
(
fieldPtr.valid()
? fieldPtr()
: obr_.lookupObject<volScalarField>(fieldName_)
);
// Calculate the mid-points of bins for the graph axis
pointField xBin(nBins_);
const scalar delta = (max_- min_)/nBins_;
scalar x = min_ + 0.5*delta;
forAll(xBin, i)
{
xBin[i] = point(x, 0, 0);
x += delta;
}
scalarField data(nBins_, 0);
const scalarField& V = mesh_.V();
forAll(field, celli)
{
const label bini = (field[celli] - min_)/delta;
if (bini >= 0 && bini < nBins_)
{
data[bini] += V[celli];
}
}
Pstream::listCombineGather(data, plusEqOp<scalar>());
if (Pstream::master())
{
const scalar sumData = sum(data);
if (sumData > SMALL)
{
data /= sumData;
const coordSet coords
(
fieldName_,
"x",
xBin,
mag(xBin)
);
writeGraph(coords, fieldName_, data);
}
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,173 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::histogram
Group
grpFieldFunctionObjects
Description
Write the volume-weighted histogram of a volScalarField.
Usage
Example:
\verbatim
histogram1
{
type histogram;
libs ("libfieldFunctionObjects.so");
field p;
nBins 100;
min -5;
max 5;
setFormat gnuplot;
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: histogram | yes |
field | Field to analyse | yes |
nBins | Number of bins for the histogram | yes|
max | Maximum value sampled | yes |
min | minimum value sampled | no | 0
setFormat | Output format | yes |
\endtable
See also
Foam::functionObject
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::writeFile
SourceFiles
histogram.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_histogram_H
#define functionObjects_histogram_H
#include "fvMeshFunctionObject.H"
#include "writeFile.H"
#include "writer.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class histogram Declaration
\*---------------------------------------------------------------------------*/
class histogram
:
public fvMeshFunctionObject,
public writeFile
{
// Private data
//- Name of field
word fieldName_;
//- Maximum value
scalar max_;
//- Minimum value
scalar min_;
//- Mumber of bins
label nBins_;
//- Output formatter to write
autoPtr<writer<scalar>> formatterPtr_;
// Private Member Functions
void writeGraph
(
const coordSet& coords,
const word& valueName,
const scalarField& values
) const;
//- Disallow default bitwise copy construct
histogram(const histogram&);
//- Disallow default bitwise assignment
void operator=(const histogram&);
public:
//- Runtime type information
TypeName("histogram");
// Constructors
//- Construct from Time and dictionary
histogram
(
const word& name,
const Time& runTime,
const dictionary& dict
);
// Destructor
virtual ~histogram();
// Member Functions
//- Read the histogram data
virtual bool read(const dictionary&);
//- Execute, currently does nothing
virtual bool execute();
//- Calculate the histogram and write.
// postProcess overrides the usual writeControl behaviour and
// forces writing always (used in post-processing mode)
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "mag.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(mag, 0);
addToRunTimeSelectionTable(functionObject, mag, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::mag::calc()
{
bool processed = false;
processed = processed || calcMag<scalar>();
processed = processed || calcMag<vector>();
processed = processed || calcMag<sphericalTensor>();
processed = processed || calcMag<symmTensor>();
processed = processed || calcMag<tensor>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::mag::mag
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::mag::~mag()
{}
// ************************************************************************* //

View File

@ -0,0 +1,111 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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::mag
Group
grpFieldFunctionObjects
Description
Calculates the magnitude of a field.
The operation can be applied to any volume or surface fields generating a
volume or surface scalar field.
See also
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
mag.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_mag_H
#define functionObjects_mag_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class mag Declaration
\*---------------------------------------------------------------------------*/
class mag
:
public fieldExpression
{
// Private Member Functions
//- Calculate the magnitude of the field and register the result
template<class Type>
bool calcMag();
//- Calculate the magnitude of the field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("mag");
// Constructors
//- Construct from Time and dictionary
mag
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~mag();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "magTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-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::mag::calcMag()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (foundObject<VolFieldType>(fieldName_))
{
return store
(
resultName_,
Foam::mag(lookupObject<VolFieldType>(fieldName_))
);
}
else if (foundObject<SurfaceFieldType>(fieldName_))
{
return store
(
resultName_,
Foam::mag(lookupObject<SurfaceFieldType>(fieldName_))
);
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::magSqr::~magSqr()
{}
// ************************************************************************* //

View File

@ -0,0 +1,113 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
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.
See also
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
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,209 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ 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 "mapFields.H"
#include "meshToMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(mapFields, 0);
addToRunTimeSelectionTable
(
functionObject,
mapFields,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::mapFields::createInterpolation
(
const dictionary& dict
)
{
const fvMesh& meshTarget = mesh_;
const word mapRegionName(dict.lookup("mapRegion"));
Log << name() << ':' << nl
<< " Reading mesh " << mapRegionName << endl;
mapRegionPtr_.reset
(
new fvMesh
(
IOobject
(
mapRegionName,
meshTarget.time().constant(),
meshTarget.time()
)
)
);
const fvMesh& mapRegion = mapRegionPtr_();
word mapMethodName(dict.lookup("mapMethod"));
if (!meshToMesh::interpolationMethodNames_.found(mapMethodName))
{
FatalErrorInFunction
<< type() << " " << name() << ": unknown map method "
<< mapMethodName << nl
<< "Available methods include: "
<< meshToMesh::interpolationMethodNames_.sortedToc()
<< exit(FatalError);
}
meshToMesh::interpolationMethod mapMethod
(
meshToMesh::interpolationMethodNames_[mapMethodName]
);
// Lookup corresponding AMi method
word patchMapMethodName =
AMIPatchToPatchInterpolation::interpolationMethodToWord
(
meshToMesh::interpolationMethodAMI(mapMethod)
);
// Optionally override
if (dict.readIfPresent("patchMapMethod", patchMapMethodName))
{
Log << " Patch mapping method: " << patchMapMethodName << endl;
}
bool consistent = readBool(dict.lookup("consistent"));
Log << " Creating mesh to mesh interpolation" << endl;
if (consistent)
{
interpPtr_.reset
(
new meshToMesh
(
mapRegion,
meshTarget,
mapMethodName,
patchMapMethodName
)
);
}
else
{
HashTable<word> patchMap(dict.lookup("patchMap"));
wordList cuttingPatches(dict.lookup("cuttingPatches"));
interpPtr_.reset
(
new meshToMesh
(
mapRegion,
meshTarget,
mapMethodName,
patchMapMethodName,
patchMap,
cuttingPatches
)
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::mapFields::mapFields
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
mapRegionPtr_(),
interpPtr_(),
fieldNames_()
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::mapFields::~mapFields()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::mapFields::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> fieldNames_;
createInterpolation(dict);
return true;
}
bool Foam::functionObjects::mapFields::execute()
{
return true;
}
bool Foam::functionObjects::mapFields::write()
{
Log << type() << " " << name() << " write:" << nl;
bool ok = false;
ok = writeFieldType<scalar>() || ok;
ok = writeFieldType<vector>() || ok;
ok = writeFieldType<sphericalTensor>() || ok;
ok = writeFieldType<symmTensor>() || ok;
ok = writeFieldType<tensor>() || ok;
if (log)
{
if (!ok)
{
Info<< " none" << nl;
}
Info<< endl;
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,176 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ 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::mapFields
Group
grpFieldFunctionObjects
Description
Map fields from local mesh to secondary mesh at run-time.
Usage
Example of function object specification to map fields:
\verbatim
mapFields1
{
type mapFields;
libs ("libfieldFunctionObjects.so");
...
mapRegion coarseMesh;
mapMethod cellVolumeWeight;
consistent yes;
fields ("U.*" p);
}
Where the entries comprise:
\table
Property | Description | Required | Default value
type | Type name: mapFields | yes |
mapRgion | Name of region to map to | yes |
mapMethod | Mapping method | yes |
patchMapMethod | Patch mapping method | no | <auto>
consistent | Mapping meshes have consistent boundaries | yes |
fields | List of field names to map | yes |
log | Log to standard output | no | yes
\endtable
SourceFiles
mapFields.C
IOmapFields.H
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_mapFields_H
#define functionObjects_mapFields_H
#include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class meshToMesh;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class mapFields Declaration
\*---------------------------------------------------------------------------*/
class mapFields
:
public fvMeshFunctionObject
{
// Private data
//- Locally cached map region mesh (map to this mesh)
autoPtr<fvMesh> mapRegionPtr_;
//- Mesh-to-mesh interpolation
autoPtr<meshToMesh> interpPtr_;
//- List of field names to interpolate
wordReList fieldNames_;
// Private Member Functions
//- Disallow default bitwise copy construct
mapFields(const mapFields&) = delete;
//- Disallow default bitwise assignment
void operator=(const mapFields&) = delete;
//- Helper function to create the mesh-to-mesh interpolation
void createInterpolation(const dictionary& dict);
//- Helper function to evaluate constraint patches after mapping
template<class Type>
void evaluateConstraintTypes
(
GeometricField<Type, fvPatchField, volMesh>& fld
) const;
//- Helper function to interpolate and write the field
template<class Type>
bool writeFieldType() const;
public:
//- Runtime type information
TypeName("mapFields");
// Constructors
//- Construct from Time and dictionary
mapFields
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~mapFields();
// Member Functions
//- Read the mapFields data
virtual bool read(const dictionary&);
//- Execute, currently does nothing
virtual bool execute();
//- Calculate the mapFields and write
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "mapFieldsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,157 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ 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 "fvMesh.H"
#include "polyPatch.H"
#include "lduSchedule.H"
#include "meshToMesh.H"
template<class Type>
void Foam::functionObjects::mapFields::evaluateConstraintTypes
(
GeometricField<Type, fvPatchField, volMesh>& fld
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typename VolFieldType::Boundary& fldBf = fld.boundaryFieldRef();
if
(
Pstream::defaultCommsType == Pstream::blocking
|| Pstream::defaultCommsType == Pstream::nonBlocking
)
{
label nReq = Pstream::nRequests();
forAll(fldBf, patchi)
{
fvPatchField<Type>& tgtField = fldBf[patchi];
if
(
tgtField.type() == tgtField.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type())
)
{
tgtField.initEvaluate(Pstream::defaultCommsType);
}
}
// Block for any outstanding requests
if
(
Pstream::parRun()
&& Pstream::defaultCommsType == Pstream::nonBlocking
)
{
Pstream::waitRequests(nReq);
}
forAll(fldBf, patchi)
{
fvPatchField<Type>& tgtField = fldBf[patchi];
if
(
tgtField.type() == tgtField.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type())
)
{
tgtField.evaluate(Pstream::defaultCommsType);
}
}
}
else if (Pstream::defaultCommsType == Pstream::scheduled)
{
const lduSchedule& patchSchedule =
fld.mesh().globalData().patchSchedule();
forAll(patchSchedule, patchEvali)
{
label patchi = patchSchedule[patchEvali].patch;
fvPatchField<Type>& tgtField = fldBf[patchi];
if
(
tgtField.type() == tgtField.patch().patch().type()
&& polyPatch::constraintType(tgtField.patch().patch().type())
)
{
if (patchSchedule[patchEvali].init)
{
tgtField.initEvaluate(Pstream::scheduled);
}
else
{
tgtField.evaluate(Pstream::scheduled);
}
}
}
}
}
template<class Type>
bool Foam::functionObjects::mapFields::writeFieldType() const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
const fvMesh& mapRegion = mapRegionPtr_();
wordList fieldNames(this->mesh_.names(VolFieldType::typeName));
labelList selected = findStrings(fieldNames_, fieldNames);
forAll(selected, i)
{
const word& fieldName = fieldNames[selected[i]];
const VolFieldType& field = lookupObject<VolFieldType>(fieldName);
Log << " " << fieldName;
IOobject mapRegionIO
(
fieldName,
time_.timeName(),
mapRegion
);
tmp<VolFieldType> tfieldMapRegion(interpPtr_->mapTgtToSrc(field));
Log << ": interpolated";
VolFieldType fieldMapRegion(mapRegionIO, tfieldMapRegion);
evaluateConstraintTypes(fieldMapRegion);
fieldMapRegion.write();
Log << " and written" << nl;
}
return selected.size() > 0;
}
// ************************************************************************* //

View File

@ -0,0 +1,237 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "findCellParticle.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::findCellParticle::findCellParticle
(
const polyMesh& mesh,
const vector& position,
const label celli,
const label tetFacei,
const label tetPti,
const point& end,
const label data
)
:
particle(mesh, position, celli, tetFacei, tetPti),
end_(end),
data_(data)
{}
Foam::findCellParticle::findCellParticle
(
const polyMesh& mesh,
Istream& is,
bool readFields
)
:
particle(mesh, is, readFields)
{
if (readFields)
{
if (is.format() == IOstream::ASCII)
{
is >> end_;
data_ = readLabel(is);
}
else
{
is.read
(
reinterpret_cast<char*>(&end_),
sizeof(end_) + sizeof(data_)
);
}
}
// Check state of Istream
is.check
(
"findCellParticle::findCellParticle"
"(const Cloud<findCellParticle>&, Istream&, bool)"
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::findCellParticle::move
(
trackingData& td,
const scalar maxTrackLen
)
{
td.switchProcessor = false;
td.keepParticle = true;
scalar tEnd = (1.0 - stepFraction())*maxTrackLen;
scalar dtMax = tEnd;
while (td.keepParticle && !td.switchProcessor && tEnd > SMALL)
{
// set the lagrangian time-step
scalar dt = min(dtMax, tEnd);
dt *= trackToFace(end_, td);
tEnd -= dt;
stepFraction() = 1.0 - tEnd/maxTrackLen;
}
if (tEnd < SMALL || !td.keepParticle)
{
// Hit endpoint or patch. If patch hit could do fancy stuff but just
// to use the patch point is good enough for now.
td.cellToData()[cell()].append(data());
td.cellToEnd()[cell()].append(position());
}
return td.keepParticle;
}
bool Foam::findCellParticle::hitPatch
(
const polyPatch&,
trackingData& td,
const label patchi,
const scalar trackFraction,
const tetIndices& tetIs
)
{
return false;
}
void Foam::findCellParticle::hitWedgePatch
(
const wedgePolyPatch&,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::findCellParticle::hitSymmetryPlanePatch
(
const symmetryPlanePolyPatch&,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::findCellParticle::hitSymmetryPatch
(
const symmetryPolyPatch&,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::findCellParticle::hitCyclicPatch
(
const cyclicPolyPatch&,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::findCellParticle::hitProcessorPatch
(
const processorPolyPatch&,
trackingData& td
)
{
// Remove particle
td.switchProcessor = true;
}
void Foam::findCellParticle::hitWallPatch
(
const wallPolyPatch& wpp,
trackingData& td,
const tetIndices&
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::findCellParticle::hitPatch
(
const polyPatch& wpp,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const findCellParticle& p)
{
if (os.format() == IOstream::ASCII)
{
os << static_cast<const particle&>(p)
<< token::SPACE << p.end_
<< token::SPACE << p.data_;
}
else
{
os << static_cast<const particle&>(p);
os.write
(
reinterpret_cast<const char*>(&p.end_),
sizeof(p.end_) + sizeof(p.data_)
);
}
// Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const findCellParticle&)");
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,274 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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::findCellParticle
Description
Particle class that finds cells by tracking
SourceFiles
findCellParticle.C
\*---------------------------------------------------------------------------*/
#ifndef findCellParticle_H
#define findCellParticle_H
#include "particle.H"
#include "autoPtr.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class findCellParticleCloud;
// Forward declaration of friend functions and operators
class findCellParticle;
Ostream& operator<<(Ostream&, const findCellParticle&);
/*---------------------------------------------------------------------------*\
Class findCellParticle Declaration
\*---------------------------------------------------------------------------*/
class findCellParticle
:
public particle
{
// Private data
//- End point to track to
point end_;
//- Passive data
label data_;
public:
friend class Cloud<findCellParticle>;
//- Class used to pass tracking data to the trackToFace function
class trackingData
:
public particle::TrackingData<Cloud<findCellParticle>>
{
labelListList& cellToData_;
List<List<point>>& cellToEnd_;
public:
// Constructors
trackingData
(
Cloud<findCellParticle>& cloud,
labelListList& cellToData,
List<List<point>>& cellToEnd
)
:
particle::TrackingData<Cloud<findCellParticle>>(cloud),
cellToData_(cellToData),
cellToEnd_(cellToEnd)
{}
// Member functions
labelListList& cellToData()
{
return cellToData_;
}
List<List<point>>& cellToEnd()
{
return cellToEnd_;
}
};
// Constructors
//- Construct from components
findCellParticle
(
const polyMesh& mesh,
const vector& position,
const label celli,
const label tetFacei,
const label tetPti,
const point& end,
const label data
);
//- Construct from Istream
findCellParticle
(
const polyMesh& mesh,
Istream& is,
bool readFields = true
);
//- Construct and return a clone
autoPtr<particle> clone() const
{
return autoPtr<particle>(new findCellParticle(*this));
}
//- Factory class to read-construct particles used for
// parallel transfer
class iNew
{
const polyMesh& mesh_;
public:
iNew(const polyMesh& mesh)
:
mesh_(mesh)
{}
autoPtr<findCellParticle> operator()(Istream& is) const
{
return autoPtr<findCellParticle>
(
new findCellParticle(mesh_, is, true)
);
}
};
// Member Functions
//- Point to track to
const point& end() const
{
return end_;
}
//- Transported label
label data() const
{
return data_;
}
// Tracking
//- Track all particles to their end point
bool move(trackingData&, const scalar);
//- Overridable function to handle the particle hitting a patch
// Executed before other patch-hitting functions
bool hitPatch
(
const polyPatch&,
trackingData& td,
const label patchi,
const scalar trackFraction,
const tetIndices& tetIs
);
//- Overridable function to handle the particle hitting a wedge
void hitWedgePatch
(
const wedgePolyPatch&,
trackingData& td
);
//- Overridable function to handle the particle hitting a
// symmetry plane
void hitSymmetryPlanePatch
(
const symmetryPlanePolyPatch&,
trackingData& td
);
//- Overridable function to handle the particle hitting a
// symmetry patch
void hitSymmetryPatch
(
const symmetryPolyPatch&,
trackingData& td
);
//- Overridable function to handle the particle hitting a cyclic
void hitCyclicPatch
(
const cyclicPolyPatch&,
trackingData& td
);
//- Overridable function to handle the particle hitting a
//- processorPatch
void hitProcessorPatch
(
const processorPolyPatch&,
trackingData& td
);
//- Overridable function to handle the particle hitting a wallPatch
void hitWallPatch
(
const wallPolyPatch&,
trackingData& td,
const tetIndices&
);
//- Overridable function to handle the particle hitting a polyPatch
void hitPatch
(
const polyPatch&,
trackingData& td
);
// Ostream Operator
friend Ostream& operator<<(Ostream&, const findCellParticle&);
};
template<>
inline bool contiguous<findCellParticle>()
{
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,42 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-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 "findCellParticle.H"
#include "Cloud.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTemplateTypeNameAndDebug(Cloud<findCellParticle>, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,367 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "nearWallFields.H"
#include "wordReList.H"
#include "findCellParticle.H"
#include "mappedPatchBase.H"
#include "OBJstream.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(nearWallFields, 0);
addToRunTimeSelectionTable(functionObject, nearWallFields, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::nearWallFields::calcAddressing()
{
// Count number of faces
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
{
label patchi = iter.key();
nPatchFaces += mesh_.boundary()[patchi].size();
}
// Global indexing
globalIndex globalWalls(nPatchFaces);
DebugInFunction << "nPatchFaces: " << globalWalls.size() << endl;
// Construct cloud
Cloud<findCellParticle> cloud
(
mesh_,
cloud::defaultName,
IDLList<findCellParticle>()
);
// Add particles to track to sample locations
nPatchFaces = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
{
label patchi = iter.key();
const fvPatch& patch = mesh_.boundary()[patchi];
vectorField nf(patch.nf());
vectorField faceCellCentres(patch.patch().faceCellCentres());
forAll(patch, patchFacei)
{
label meshFacei = patch.start()+patchFacei;
// Find starting point on face (since faceCentre might not
// be on face-diagonal decomposition)
pointIndexHit startInfo
(
mappedPatchBase::facePoint
(
mesh_,
meshFacei,
polyMesh::FACE_DIAG_TRIS
)
);
point start;
if (startInfo.hit())
{
start = startInfo.hitPoint();
}
else
{
// Fallback: start tracking from neighbouring cell centre
start = faceCellCentres[patchFacei];
}
const point end = start-distance_*nf[patchFacei];
// Find tet for starting location
label celli = -1;
label tetFacei = -1;
label tetPti = -1;
mesh_.findCellFacePt(start, celli, tetFacei, tetPti);
// Add to cloud. Add originating face as passive data
cloud.addParticle
(
new findCellParticle
(
mesh_,
start,
celli,
tetFacei,
tetPti,
end,
globalWalls.toGlobal(nPatchFaces) // passive data
)
);
nPatchFaces++;
}
}
if (debug)
{
// Dump particles
OBJstream str
(
mesh_.time().path()
/"wantedTracks_" + mesh_.time().timeName() + ".obj"
);
InfoInFunction << "Dumping tracks to " << str.name() << endl;
forAllConstIter(Cloud<findCellParticle>, cloud, iter)
{
const findCellParticle& tp = iter();
str.write(linePointRef(tp.position(), tp.end()));
}
}
// Per cell: empty or global wall index and end location
cellToWalls_.setSize(mesh_.nCells());
cellToSamples_.setSize(mesh_.nCells());
// Database to pass into findCellParticle::move
findCellParticle::trackingData td(cloud, cellToWalls_, cellToSamples_);
// Track all particles to their end position.
scalar maxTrackLen = 2.0*mesh_.bounds().mag();
//Debug: collect start points
pointField start;
if (debug)
{
start.setSize(nPatchFaces);
nPatchFaces = 0;
forAllConstIter(Cloud<findCellParticle>, cloud, iter)
{
const findCellParticle& tp = iter();
start[nPatchFaces++] = tp.position();
}
}
cloud.move(td, maxTrackLen);
// Rework cell-to-globalpatchface into a map
List<Map<label>> compactMap;
getPatchDataMapPtr_.reset
(
new mapDistribute
(
globalWalls,
cellToWalls_,
compactMap
)
);
// Debug: dump resulting tracks
if (debug)
{
getPatchDataMapPtr_().distribute(start);
{
OBJstream str
(
mesh_.time().path()
/"obtainedTracks_" + mesh_.time().timeName() + ".obj"
);
InfoInFunction << "Dumping obtained to " << str.name() << endl;
forAll(cellToWalls_, celli)
{
const List<point>& ends = cellToSamples_[celli];
const labelList& cData = cellToWalls_[celli];
forAll(cData, i)
{
str.write(linePointRef(ends[i], start[cData[i]]));
}
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::nearWallFields::nearWallFields
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
fieldSet_()
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::nearWallFields::~nearWallFields()
{
DebugInFunction << endl;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::nearWallFields::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> fieldSet_;
patchSet_ =
mesh_.boundaryMesh().patchSet(wordReList(dict.lookup("patches")));
distance_ = readScalar(dict.lookup("distance"));
// Clear out any previously loaded fields
vsf_.clear();
vvf_.clear();
vSpheretf_.clear();
vSymmtf_.clear();
vtf_.clear();
fieldMap_.clear();
reverseFieldMap_.clear();
// Generate fields with mappedField boundary condition
// Convert field to map
fieldMap_.resize(2*fieldSet_.size());
reverseFieldMap_.resize(2*fieldSet_.size());
forAll(fieldSet_, seti)
{
const word& fldName = fieldSet_[seti].first();
const word& sampleFldName = fieldSet_[seti].second();
fieldMap_.insert(fldName, sampleFldName);
reverseFieldMap_.insert(sampleFldName, fldName);
}
Log << type() << " " << name()
<< ": Sampling " << fieldMap_.size() << " fields" << endl;
// Do analysis
calcAddressing();
return true;
}
bool Foam::functionObjects::nearWallFields::execute()
{
DebugInFunction << endl;
if
(
fieldMap_.size()
&& vsf_.empty()
&& vvf_.empty()
&& vSpheretf_.empty()
&& vSymmtf_.empty()
&& vtf_.empty()
)
{
Log << type() << " " << name()
<< ": Creating " << fieldMap_.size() << " fields" << endl;
createFields(vsf_);
createFields(vvf_);
createFields(vSpheretf_);
createFields(vSymmtf_);
createFields(vtf_);
Log << endl;
}
Log << type() << " " << name()
<< " write:" << nl
<< " Sampling fields to " << time_.timeName()
<< endl;
sampleFields(vsf_);
sampleFields(vvf_);
sampleFields(vSpheretf_);
sampleFields(vSymmtf_);
sampleFields(vtf_);
return true;
}
bool Foam::functionObjects::nearWallFields::write()
{
DebugInFunction << endl;
Log << " Writing sampled fields to " << time_.timeName()
<< endl;
forAll(vsf_, i)
{
vsf_[i].write();
}
forAll(vvf_, i)
{
vvf_[i].write();
}
forAll(vSpheretf_, i)
{
vSpheretf_[i].write();
}
forAll(vSymmtf_, i)
{
vSymmtf_[i].write();
}
forAll(vtf_, i)
{
vtf_[i].write();
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,234 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::nearWallFields
Group
grpFieldFunctionObjects
Description
Samples near-patch volume fields.
Fields are stored
- every time step the field is updated with new values
- at output it writes the fields
This functionObject can either be used
- to calculate a new field as a post-processing step or
- since the fields are registered, used in another functionObject
Usage
Example of function object specification:
\verbatim
nearWallFields1
{
type nearWallFields;
libs ("libfieldFunctionObjects.so");
writeControl writeTime;
fields
(
(p pNear)
(U UNear)
);
patches (movingWall);
distance 0.13;
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: nearWallFields | yes |
fields | list of fields with corresponding output field names | yes |
patches | list of patches to sample | yes |
distance | distance from patch to sample | yes |
log | Log to standard output | no | yes
\endtable
See also
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
nearWallFields.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_nearWallFields_H
#define functionObjects_nearWallFields_H
#include "fvMeshFunctionObject.H"
#include "volFields.H"
#include "Tuple2.H"
#include "interpolationCellPoint.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class nearWallFields Declaration
\*---------------------------------------------------------------------------*/
class nearWallFields
:
public fvMeshFunctionObject
{
protected:
// Protected member data
// Read from dictionary
//- Fields to process
List<Tuple2<word, word>> fieldSet_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Patches to sample
labelHashSet patchSet_;
//- Distance away from wall
scalar distance_;
//- From original field to sampled result
HashTable<word> fieldMap_;
//- From resulting back to original field
HashTable<word> reverseFieldMap_;
// Calculated addressing
//- From cell to seed patch faces
labelListList cellToWalls_;
//- From cell to tracked end point
List<List<point>> cellToSamples_;
//- Map from cell based data back to patch based data
autoPtr<mapDistribute> getPatchDataMapPtr_;
// Locally constructed fields
PtrList<volScalarField> vsf_;
PtrList<volVectorField> vvf_;
PtrList<volSphericalTensorField> vSpheretf_;
PtrList<volSymmTensorField> vSymmtf_;
PtrList<volTensorField> vtf_;
// Protected Member Functions
//- Calculate addressing from cells back to patch faces
void calcAddressing();
template<class Type>
void createFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh>>&
) const;
//- Override boundary fields with sampled values
template<class Type>
void sampleBoundaryField
(
const interpolationCellPoint<Type>& interpolator,
GeometricField<Type, fvPatchField, volMesh>& fld
) const;
template<class Type>
void sampleFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh>>&
) const;
private:
//- Disallow default bitwise copy construct
nearWallFields(const nearWallFields&);
//- Disallow default bitwise assignment
void operator=(const nearWallFields&);
public:
//- Runtime type information
TypeName("nearWallFields");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
nearWallFields
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~nearWallFields();
// Member Functions
//- Read the controls
virtual bool read(const dictionary&);
//- Calculate the near-wall fields
virtual bool execute();
//- Write the near-wall fields
virtual bool write();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "nearWallFieldsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,150 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "nearWallFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::nearWallFields::createFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh>>& sflds
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
HashTable<const VolFieldType*> flds(obr_.lookupClass<VolFieldType>());
forAllConstIter(typename HashTable<const VolFieldType*>, flds, iter)
{
const VolFieldType& fld = *iter();
if (fieldMap_.found(fld.name()))
{
const word& sampleFldName = fieldMap_[fld.name()];
if (obr_.found(sampleFldName))
{
WarningInFunction
<< " a field named " << sampleFldName
<< " already exists on the mesh"
<< endl;
}
else
{
label sz = sflds.size();
sflds.setSize(sz+1);
IOobject io(fld);
io.readOpt() = IOobject::NO_READ;
io.writeOpt() = IOobject::NO_WRITE;
io.rename(sampleFldName);
sflds.set(sz, new VolFieldType(io, fld));
Log << " created " << sflds[sz].name()
<< " to sample " << fld.name() << endl;
}
}
}
}
template<class Type>
void Foam::functionObjects::nearWallFields::sampleBoundaryField
(
const interpolationCellPoint<Type>& interpolator,
GeometricField<Type, fvPatchField, volMesh>& fld
) const
{
// Construct flat fields for all patch faces to be sampled
Field<Type> sampledValues(getPatchDataMapPtr_().constructSize());
forAll(cellToWalls_, celli)
{
const labelList& cData = cellToWalls_[celli];
forAll(cData, i)
{
const point& samplePt = cellToSamples_[celli][i];
sampledValues[cData[i]] = interpolator.interpolate(samplePt, celli);
}
}
// Send back sampled values to patch faces
getPatchDataMapPtr_().reverseDistribute
(
getPatchDataMapPtr_().constructSize(),
sampledValues
);
typename GeometricField<Type, fvPatchField, volMesh>::
Boundary& fldBf = fld.boundaryFieldRef();
// Pick up data
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchSet_, iter)
{
label patchi = iter.key();
fvPatchField<Type>& pfld = fldBf[patchi];
Field<Type> newFld(pfld.size());
forAll(pfld, i)
{
newFld[i] = sampledValues[nPatchFaces++];
}
pfld == newFld;
}
}
template<class Type>
void Foam::functionObjects::nearWallFields::sampleFields
(
PtrList<GeometricField<Type, fvPatchField, volMesh>>& sflds
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
forAll(sflds, i)
{
const word& fldName = reverseFieldMap_[sflds[i].name()];
const VolFieldType& fld = obr_.lookupObject<VolFieldType>(fldName);
// Take over internal and boundary values
sflds[i] == fld;
// Construct interpolation method
interpolationCellPoint<Type> interpolator(fld);
// Override sampled values
sampleBoundaryField(interpolator, sflds[i]);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,277 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "pressure.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(pressure, 0);
addToRunTimeSelectionTable(functionObject, pressure, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::functionObjects::pressure::resultName() const
{
word rName;
if (calcTotal_)
{
rName = "total(" + fieldName_ + ")";
}
else
{
rName = "static(" + fieldName_ + ")";
}
if (calcCoeff_)
{
rName += "_coeff";
}
return rName;
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
(
const volScalarField& p
) const
{
if (p.dimensions() == dimPressure)
{
return p;
}
else
{
if (!rhoInfInitialised_)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< "pressure identified as incompressible, but reference "
<< "density is not set. Please set rhoName to rhoInf, and "
<< "set an appropriate value for rhoInf"
<< exit(FatalError);
}
return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*p;
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::rhoScale
(
const volScalarField& p,
const tmp<volScalarField>& tsf
) const
{
if (p.dimensions() == dimPressure)
{
return lookupObject<volScalarField>(rhoName_)*tsf;
}
else
{
return dimensionedScalar("rhoInf", dimDensity, rhoInf_)*tsf;
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pRef
(
const tmp<volScalarField>& tp
) const
{
if (calcTotal_)
{
return tp + dimensionedScalar("pRef", dimPressure, pRef_);
}
else
{
return std::move(tp);
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::pDyn
(
const volScalarField& p,
const tmp<volScalarField>& tp
) const
{
if (calcTotal_)
{
return
tp
+ rhoScale(p, 0.5*magSqr(lookupObject<volVectorField>(UName_)));
}
else
{
return std::move(tp);
}
}
Foam::tmp<Foam::volScalarField> Foam::functionObjects::pressure::coeff
(
const tmp<volScalarField>& tp
) const
{
if (calcCoeff_)
{
tmp<volScalarField> tpCoeff(tp.ptr());
volScalarField& pCoeff = tpCoeff.ref();
pCoeff -= dimensionedScalar("pInf", dimPressure, pInf_);
const dimensionedScalar pSmall("pSmall", dimPressure, SMALL);
const dimensionedVector U("U", dimVelocity, UInf_);
const dimensionedScalar rho("rho", dimDensity, rhoInf_);
pCoeff /= 0.5*rho*magSqr(U) + pSmall;
return tpCoeff;
}
else
{
return std::move(tp);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::pressure::calc()
{
if (foundObject<volScalarField>(fieldName_))
{
const volScalarField& p = lookupObject<volScalarField>(fieldName_);
return store
(
resultName_,
coeff(pRef(pDyn(p, rhoScale(p))))
);
}
else
{
return false;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::pressure::pressure
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict, "p"),
UName_("U"),
rhoName_("rho"),
calcTotal_(false),
pRef_(0),
calcCoeff_(false),
pInf_(0),
UInf_(Zero),
rhoInf_(1),
rhoInfInitialised_(false)
{
read(dict);
dimensionSet pDims(dimPressure);
if (calcCoeff_)
{
pDims /= dimPressure;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::pressure::~pressure()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::pressure::read(const dictionary& dict)
{
fieldExpression::read(dict);
dict.readIfPresent("U", UName_);
dict.readIfPresent("rho", rhoName_);
if (rhoName_ == "rhoInf")
{
dict.lookup("rhoInf") >> rhoInf_;
rhoInfInitialised_ = true;
}
dict.lookup("calcTotal") >> calcTotal_;
if (calcTotal_)
{
dict.lookup("pRef") >> pRef_;
}
dict.lookup("calcCoeff") >> calcCoeff_;
if (calcCoeff_)
{
dict.lookup("pInf") >> pInf_;
dict.lookup("UInf") >> UInf_;
dict.lookup("rhoInf") >> rhoInf_;
scalar zeroCheck = 0.5*rhoInf_*magSqr(UInf_) + pInf_;
if (mag(zeroCheck) < ROOTVSMALL)
{
WarningInFunction
<< type() << " " << name() << ": "
<< "Coefficient calculation requested, but reference "
<< "pressure level is zero. Please check the supplied "
<< "values of pInf, UInf and rhoInf" << endl;
}
rhoInfInitialised_ = true;
}
resultName_ = dict.lookupOrDefault<word>("result", resultName());
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,244 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::pressure
Group
grpFieldFunctionObjects
Description
Includes tools to manipulate the pressure into different forms.
These currently include:
- static pressure
\f[
p = \rho p_k
\f]
- total pressure
\f[
p_0 = p_{ref} + p + 0.5 \rho |U|^2
\f]
- static pressure coefficient
\f[
Cp = \frac{p - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
\f]
- total pressure coefficient
\f[
Cp_0 = \frac{p_0 - p_{\inf}}{0.5 \rho_{\inf} |U_{\inf}|^2}
\f]
where
\vartable
\rho | Density [kg/m3]
U | Velocity [m/s]
\rho_{\inf} | Freestream density [kg/m3]
p_{\inf} | Freestream pressure [Pa]
U_{\inf} | Freestream velocity [m/s]
p_k | Kinematic pressure (p/rho)[m2/s2]
p | Pressure [Pa]
p_0 | Total pressure [Pa]
p_{ref} | Reference pressure level [Pa]
Cp | Pressure coefficient
Cp_0 | Total pressure coefficient
\endvartable
The function object will operate on both kinematic (\f$ p_k \f$) and static
pressure (\f$ p \f$) fields, and the result is written as a
volScalarField.
The modes of operation are:
\table
Mode | calcTotal | calcCoeff
Static pressure | no | no
Total pressure | yes | no
Pressure coefficient | no | yes
Total pressure coefficient | yes | yes
\endtable
Usage
Example of function object specification to calculate pressure coefficient:
\verbatim
pressure1
{
type pressure;
libs ("libfieldFunctionObjects.so");
...
calcTotal no;
calcCoeff yes;
}
\endverbatim
Where the entries comprise:
\table
Property | Description | Required | Default value
type | type name: pressure | yes |
field | Name of the pressure field | no | p
U | Name of the velocity field | no | U
rho | Name of the density field | no | rho
result | Name of the resulting field | no | derived from p
calcTotal | Calculate total coefficient | yes |
pRef | Reference pressure for total pressure | no | 0
calcCoeff | Calculate pressure coefficient | yes |
pInf | Freestream pressure for coefficient calculation | no |
UInf | Freestream velocity for coefficient calculation | no |
rhoInf | Freestream density for coefficient calculation | no |
\endtable
See also
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
pressure.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_pressure_H
#define functionObjects_pressure_H
#include "fieldExpression.H"
#include "volFieldsFwd.H"
#include "dimensionedScalar.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class pressure Declaration
\*---------------------------------------------------------------------------*/
class pressure
:
public fieldExpression
{
// Private data
//- Name of velocity field, default is "U"
word UName_;
//- Name of density field, default is "rho"
word rhoName_;
// Total pressure calculation
//- Flag to calculate total pressure
bool calcTotal_;
//- Reference pressure level
scalar pRef_;
// Pressure coefficient calculation
//- Flag to calculate pressure coefficient
bool calcCoeff_;
//- Freestream pressure
scalar pInf_;
//- Freestream velocity
vector UInf_;
//- Freestream density
scalar rhoInf_;
//- Flag to show whether rhoInf has been initialised
bool rhoInfInitialised_;
// Private Member Functions
//- Return the name of the derived pressure field
word resultName() const;
//- Multiply the static pressure p by rhoInf if necessary and return
tmp<volScalarField> rhoScale(const volScalarField& p) const;
//- Multiply the given field by rho or rhoInf as appropriate and return
tmp<volScalarField> rhoScale
(
const volScalarField& p,
const tmp<volScalarField>& tsf
) const;
//- Return the reference pressure
tmp<volScalarField> pRef(const tmp<volScalarField>& tp) const;
//- Calculate and return the dynamic pressure
tmp<volScalarField> pDyn
(
const volScalarField& p,
const tmp<volScalarField>& tp
) const;
//- Convert to coeff by applying the freestream dynamic pressure scaling
tmp<volScalarField> coeff(const tmp<volScalarField>& tp) const;
//- Calculate the derived pressure field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("pressure");
// Constructors
//- Construct from Time and dictionary
pressure
(
const word& name,
const Time& runTime,
const dictionary&
);
//- Destructor
virtual ~pressure();
// Member Functions
//- Read the pressure data
virtual bool read(const dictionary&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,35 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: plus |
| \\ / A nd | Web: www.OpenFOAM.com |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object postProcessingDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
functions
{
processorField1
{
// Type of functionObject
type processorField;
// Where to load it from (if not already in solver)
libs ("libfieldFunctionObjects.so");
// Function object enabled flag
enabled true;
// When to output the average fields
writeControl writeTime;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,115 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-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 "processorField.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(processorField, 0);
addToRunTimeSelectionTable(functionObject, processorField, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::processorField::processorField
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict)
{
read(dict);
volScalarField* procFieldPtr
(
new volScalarField
(
IOobject
(
"processorID",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("0", dimless, 0.0)
)
);
mesh_.objectRegistry::store(procFieldPtr);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::processorField::~processorField()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::processorField::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
return true;
}
bool Foam::functionObjects::processorField::execute()
{
const volScalarField& procField =
mesh_.lookupObject<volScalarField>("processorID");
const_cast<volScalarField&>(procField) ==
dimensionedScalar("proci", dimless, Pstream::myProcNo());
return true;
}
bool Foam::functionObjects::processorField::write()
{
const volScalarField& procField =
mesh_.lookupObject<volScalarField>("processorID");
procField.write();
return true;
}
// ************************************************************************* //

Some files were not shown because too many files have changed in this diff Show More