postProcessing: Replaced 'foamCalc' and the 'postCalc' utilities

with the more general and flexible 'postProcess' utility and '-postProcess' solver option

Rationale
---------

Both the 'postProcess' utility and '-postProcess' solver option use the
same extensive set of functionObjects available for data-processing
during the run avoiding the substantial code duplication necessary for
the 'foamCalc' and 'postCalc' utilities and simplifying maintenance.
Additionally consistency is guaranteed between solver data processing
and post-processing.

The functionObjects have been substantially re-written and generalized
to simplify development and encourage contribution.

Configuration
-------------

An extensive set of simple functionObject configuration files are
provided in

OpenFOAM-dev/etc/caseDicts/postProcessing

and more will be added in the future.  These can either be copied into
'<case>/system' directory and included into the 'controlDict.functions'
sub-dictionary or included directly from 'etc/caseDicts/postProcessing'
using the '#includeEtc' directive or the new and more convenient
'#includeFunc' directive which searches the
'<etc>/caseDicts/postProcessing' directories for the selected
functionObject, e.g.

functions
{
    #includeFunc Q
    #includeFunc Lambda2
}

'#includeFunc' first searches the '<case>/system' directory in case
there is a local configuration.

Description of #includeFunc
---------------------------

    Specify a functionObject dictionary file to include, expects the
    functionObject name to follow (without quotes).

    Search for functionObject dictionary file in
    user/group/shipped directories.
    The search scheme allows for version-specific and
    version-independent files using the following hierarchy:
    - \b user settings:
      - ~/.OpenFOAM/\<VERSION\>/caseDicts/postProcessing
      - ~/.OpenFOAM/caseDicts/postProcessing
    - \b group (site) settings (when $WM_PROJECT_SITE is set):
      - $WM_PROJECT_SITE/\<VERSION\>/caseDicts/postProcessing
      - $WM_PROJECT_SITE/caseDicts/postProcessing
    - \b group (site) settings (when $WM_PROJECT_SITE is not set):
      - $WM_PROJECT_INST_DIR/site/\<VERSION\>/caseDicts/postProcessing
      - $WM_PROJECT_INST_DIR/site/caseDicts/postProcessing
    - \b other (shipped) settings:
      - $WM_PROJECT_DIR/etc/caseDicts/postProcessing

    An example of the \c \#includeFunc directive:
    \verbatim
        #includeFunc <funcName>
    \endverbatim

postProcess
-----------

The 'postProcess' utility and '-postProcess' solver option provide the
same set of controls to execute functionObjects after the run either by
reading a specified set of fields to process in the case of
'postProcess' or by reading all fields and models required to start the
run in the case of '-postProcess' for each selected time:

postProcess -help

Usage: postProcess [OPTIONS]
options:
  -case <dir>       specify alternate case directory, default is the cwd
  -constant         include the 'constant/' dir in the times list
  -dict <file>      read control dictionary from specified location
  -field <name>     specify the name of the field to be processed, e.g. U
  -fields <list>    specify a list of fields to be processed, e.g. '(U T p)' -
                    regular expressions not currently supported
  -func <name>      specify the name of the functionObject to execute, e.g. Q
  -funcs <list>     specify the names of the functionObjects to execute, e.g.
                    '(Q div(U))'
  -latestTime       select the latest time
  -newTimes         select the new times
  -noFunctionObjects
                    do not execute functionObjects
  -noZero           exclude the '0/' dir from the times list, has precedence
                    over the -withZero option
  -parallel         run in parallel
  -region <name>    specify alternative mesh region
  -roots <(dir1 .. dirN)>
                    slave root directories for distributed running
  -time <ranges>    comma-separated time ranges - eg, ':10,20,40:70,1000:'
  -srcDoc           display source code in browser
  -doc              display application documentation in browser
  -help             print the usage

 pimpleFoam -postProcess -help

Usage: pimpleFoam [OPTIONS]
options:
  -case <dir>       specify alternate case directory, default is the cwd
  -constant         include the 'constant/' dir in the times list
  -dict <file>      read control dictionary from specified location
  -field <name>     specify the name of the field to be processed, e.g. U
  -fields <list>    specify a list of fields to be processed, e.g. '(U T p)' -
                    regular expressions not currently supported
  -func <name>      specify the name of the functionObject to execute, e.g. Q
  -funcs <list>     specify the names of the functionObjects to execute, e.g.
                    '(Q div(U))'
  -latestTime       select the latest time
  -newTimes         select the new times
  -noFunctionObjects
                    do not execute functionObjects
  -noZero           exclude the '0/' dir from the times list, has precedence
                    over the -withZero option
  -parallel         run in parallel
  -postProcess      Execute functionObjects only
  -region <name>    specify alternative mesh region
  -roots <(dir1 .. dirN)>
                    slave root directories for distributed running
  -time <ranges>    comma-separated time ranges - eg, ':10,20,40:70,1000:'
  -srcDoc           display source code in browser
  -doc              display application documentation in browser
  -help             print the usage

The functionObjects to execute may be specified on the command-line
using the '-func' option for a single functionObject or '-funcs' for a
list, e.g.

postProcess -func Q
postProcess -funcs '(div(U) div(phi))'

In the case of 'Q' the default field to process is 'U' which is
specified in and read from the configuration file but this may be
overridden thus:

postProcess -func 'Q(Ua)'

as is done in the example above to calculate the two forms of the divergence of
the velocity field.  Additional fields which the functionObjects may depend on
can be specified using the '-field' or '-fields' options.

The 'postProcess' utility can only be used to execute functionObjects which
process fields present in the time directories.  However, functionObjects which
depend on fields obtained from models, e.g. properties derived from turbulence
models can be executed using the '-postProcess' of the appropriate solver, e.g.

pisoFoam -postProcess -func PecletNo

or

sonicFoam -postProcess -func MachNo

In this case all required fields will have already been read so the '-field' or
'-fields' options are not be needed.

Henry G. Weller
CFD Direct Ltd.
This commit is contained in:
Henry Weller
2016-05-28 18:58:48 +01:00
parent 7a3f939aae
commit 8b672f0f1a
394 changed files with 1450 additions and 5384 deletions

15
src/functionObjects/Allwmake Executable file
View File

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

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 |
-------------------------------------------------------------------------------
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")
{
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,123 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::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.
SeeAlso
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 flux field, default is "phi"
word phiName_;
//- 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&,
const dictionary&
);
//- 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,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
This function object 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.
SeeAlso
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,101 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
This function object calculates and writes the Mach number as a
volScalarField.
SeeAlso
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,56 @@
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/cellSource/cellSource.C
fieldValues/faceSource/faceSource.C
nearWallFields/nearWallFields.C
nearWallFields/findCellParticle.C
nearWallFields/findCellParticleCloud.C
processorField/processorField.C
readFields/readFields.C
streamLine/streamLine.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
LIB = $(FOAM_LIBBIN)/libfieldFunctionObjects

View File

@ -0,0 +1,28 @@
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
LIB_LIBS = \
-lfiniteVolume \
-lfluidThermophysicalModels \
-lincompressibleTransportModels \
-lturbulenceModels \
-lcompressibleTransportModels \
-lincompressibleTurbulenceModels \
-lcompressibleTurbulenceModels \
-lmeshTools \
-lsurfMesh \
-llagrangian \
-lfileFormats \
-lsampling \
-lsurfMesh

View File

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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 * * * * * * * * * * * //
bool Foam::functionObjects::PecletNo::calc()
{
if (foundObject<surfaceScalarField>(fieldName_))
{
tmp<volScalarField> nuEff
(
mesh_.lookupObject<turbulenceModel>
(
turbulenceModel::propertiesName
).nuEff()
);
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(fieldName_);
return store
(
resultName_,
mag(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")
{
setResultName("Pe", "phi");
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::PecletNo::~PecletNo()
{}
// ************************************************************************* //

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::PecletNo
Group
grpFieldFunctionObjects
Description
This function object calculates and outputs the Peclet number as a
surfaceScalarField.
SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
PecletNo.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_PecletNo_H
#define functionObjects_PecletNo_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class PecletNo Declaration
\*---------------------------------------------------------------------------*/
class PecletNo
:
public fieldExpression
{
// Private Member Functions
//- Calculate the Peclet number field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("PecletNo");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
PecletNo
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~PecletNo();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // 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,104 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::Q
Group
grpFieldFunctionObjects
Description
This function object 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]
SeeAlso
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,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "blendingFactor.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(blendingFactor, 0);
addToRunTimeSelectionTable(functionObject, blendingFactor, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::blendingFactor::calc()
{
bool processed = false;
processed = processed || calcBF<scalar>();
processed = processed || calcBF<vector>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::blendingFactor::blendingFactor
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::blendingFactor::~blendingFactor()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::blendingFactor::read(const dictionary& dict)
{
fieldExpression::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
resultName_ = "blendingFactor:" + fieldName_;
return true;
}
// ************************************************************************* //

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 |
-------------------------------------------------------------------------------
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
This function object 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.
SeeAlso
Foam::functionObjects::fieldExpression
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
blendingFactor.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_blendingFactor_H
#define functionObjects_blendingFactor_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class blendingFactor Declaration
\*---------------------------------------------------------------------------*/
class blendingFactor
:
public fieldExpression
{
// Private member data
//- Name of flux field, default is "phi"
word phiName_;
// Private Member Functions
//- Calculate the blending factor field
template<class Type>
bool calcBF();
//- Calculate the blending factor field and return true if successful
virtual bool calc();
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&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "blendingFactorTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,79 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "gaussConvectionScheme.H"
#include "blendedSchemeBase.H"
#include "fvcCellReduce.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::blendingFactor::calcBF()
{
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>> cs =
fv::convectionScheme<Type>::New(mesh_, phi, its);
const fv::gaussConvectionScheme<Type>& gcs =
refCast<const fv::gaussConvectionScheme<Type>>(cs());
const surfaceInterpolationScheme<Type>& interpScheme =
gcs.interpScheme();
if (!isA<blendedSchemeBase<Type>>(interpScheme))
{
FatalErrorInFunction
<< interpScheme.typeName << " is not a blended scheme"
<< exit(FatalError);
}
// Retrieve the face-based blending factor
const blendedSchemeBase<Type>& blendedScheme =
refCast<const blendedSchemeBase<Type>>(interpScheme);
tmp<surfaceScalarField> factorf(blendedScheme.blendingFactor(field));
// Convert into vol field whose values represent the local face maxima
return store
(
resultName_,
fvc::cellReduce(factorf, maxEqOp<scalar>())
);
}
// ************************************************************************* //

View File

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "components.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(components, 0);
addToRunTimeSelectionTable(functionObject, components, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::components::calc()
{
bool processed = false;
processed = processed || calcComponents<vector>();
processed = processed || calcComponents<sphericalTensor>();
processed = processed || calcComponents<symmTensor>();
processed = processed || calcComponents<tensor>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::components::components
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::components::~components()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::components::write(const bool postProcess)
{
bool written = true;
forAll(resultNames_, i)
{
written = written && writeObject(resultNames_[i]);
}
return written;
}
bool Foam::functionObjects::components::clear()
{
bool cleared = true;
forAll(resultNames_, i)
{
cleared = cleared && clearObject(resultNames_[i]);
}
return cleared;
}
// ************************************************************************* //

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
This function object calculates the components of a field.
The operation can be applied to any volume or surface fields generating a
volume or surface scalar fields for each component.
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
components.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_components_H
#define functionObjects_components_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class components Declaration
\*---------------------------------------------------------------------------*/
class components
:
public fieldExpression
{
// Private member data
//- List of the component field names
wordList resultNames_;
// Private Member Functions
//- Calculate the components of the field with the specified type
// and register the result
template<class GeoFieldType>
bool calcFieldComponents();
//- Calculate the components of the field with the specified
// element type and register the result
template<class Type>
bool calcComponents();
//- Calculate the components of the field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("components");
// Constructors
//- Construct from Time and dictionary
components
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~components();
// Member Functions
//- Write the component fields
virtual bool write(const bool postProcess = false);
//- Clear the component fields from the objectRegistry
virtual bool clear();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "componentsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

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,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,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
This function object calculates the divergence of a field. The operation is
limited to surfaceScalarFields and volVectorFields, and the output is a
volScalarField.
SeeAlso
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
This function object calculates the enstrophy of the velocity.
SeeAlso
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
// ************************************************************************* //

View File

@ -0,0 +1,85 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application XXX;
startFrom latestTime;
startTime 0;
stopAt endTime;
endTime 0.1;
deltaT 1e-05;
writeControl timeStep;
writeInterval 10;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
fieldAverage1
{
// Type of functionObject
type fieldAverage;
// 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 averaged - runTime modifiable
fields
(
U
{
mean on;
prime2Mean on;
base time;
window 0.01; // optional averaging window
}
p
{
mean on;
prime2Mean on;
base time;
window 0.01; // optional averaging window
}
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,347 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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();
// 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);
}
// ensure first averaging works unconditionally
prevTimeIndex_ = -1;
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() << " output:" << 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() const
{
IOdictionary propsDict
(
IOobject
(
name() + "Properties",
obr_.time().timeName(),
"uniform",
obr_,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
)
);
forAll(faItems_, fieldi)
{
const word& fieldName = faItems_[fieldi].fieldName();
propsDict.add(fieldName, dictionary());
propsDict.subDict(fieldName).add("totalIter", totalIter_[fieldi]);
propsDict.subDict(fieldName).add("totalTime", totalTime_[fieldi]);
}
propsDict.regIOobject::write();
Log << endl;
}
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
{
IOobject propsDictHeader
(
name() + "Properties",
obr_.time().timeName(obr_.time().startTime().value()),
"uniform",
obr_,
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE,
false
);
if (!propsDictHeader.headerOk())
{
Log
<< " Starting averaging at time "
<< obr_.time().timeName() << nl;
return;
}
IOdictionary propsDict(propsDictHeader);
Log << " Restarting averaging for fields:" << nl;
forAll(faItems_, fieldi)
{
const word& fieldName = faItems_[fieldi].fieldName();
if (propsDict.found(fieldName))
{
dictionary fieldDict(propsDict.subDict(fieldName));
totalIter_[fieldi] = readLabel(fieldDict.lookup("totalIter"));
totalTime_[fieldi] = readScalar(fieldDict.lookup("totalTime"));
Log
<< " " << fieldName
<< " iters = " << totalIter_[fieldi]
<< " time = " << totalTime_[fieldi] << nl;
}
}
}
}
// * * * * * * * * * * * * * * * * 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(const bool postProcess)
{
calcAverages();
return true;
}
bool Foam::functionObjects::fieldAverage::write(const bool postProcess)
{
writeAverages();
writeAveragingProperties();
if (restartOnOutput_)
{
restart();
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,321 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldAverage
Group
grpFieldFunctionObjects
Description
This function object 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.
Example of function object specification:
\verbatim
fieldAverage1
{
type fieldAverage;
libs ("libfieldFunctionObjects.so");
...
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
\heading Function object usage
\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.
SeeAlso
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() const;
//- 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(const bool postProcess = false);
//- Write the field averages
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldAverageTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,118 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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()
:
fieldName_("unknown"),
mean_(0),
meanFieldName_("unknown"),
prime2Mean_(0),
prime2MeanFieldName_("unknown"),
base_(ITER),
window_(-1.0),
windowName_("")
{}
Foam::functionObjects::fieldAverageItem::fieldAverageItem
(
const fieldAverageItem& faItem
)
:
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
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,274 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
//- Field name
word fieldName_;
//- Compute mean flag
Switch mean_;
//- Name of mean field
word meanFieldName_;
//- Compute prime-squared mean flag
Switch 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 field name
const word& fieldName() const
{
return fieldName_;
}
//- Return const access to the mean flag
const Switch& mean() const
{
return mean_;
}
//- Return non-const access to the mean flag
Switch& 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
const Switch& prime2Mean() const
{
return prime2Mean_;
}
//- Return non-const access to the prime-squared mean flag
Switch& 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
Switch iterBase() const
{
return base_ == ITER;
}
//- Return true if base is time
Switch 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.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,149 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
#include "IOstreams.H"
#include "dictionaryEntry.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldAverageItem::fieldAverageItem(Istream& is)
:
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();
entry.lookup("mean") >> mean_;
entry.lookup("prime2Mean") >> 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.fieldName_ = entry.keyword();
entry.lookup("mean") >> faItem.mean_;
entry.lookup("prime2Mean") >> faItem.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.mean_
<< 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,411 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
#include "volFields.H"
#include "surfaceFields.H"
#include "OFstream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::fieldAverage::addMeanFieldType(const label fieldi)
{
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." << nl;
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,133 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
(
const bool postProcess
)
{
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
(
const bool postProcess
)
{
forAll(fieldSet_, fieldi)
{
writeObject(transformFieldName(fieldSet_[fieldi]));
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,170 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldCoordinateSystemTransform
Group
grpFieldFunctionObjects
Description
This function object transforms a user-specified selection of fields from
global Cartesian co-ordinates to a local co-ordinate system. The fields
are run-time modifiable.
Example of function object specification:
\verbatim
fieldCoordinateSystemTransform1
{
type fieldCoordinateSystemTransform;
libs ("libfieldFunctionObjects.so");
...
fields
(
U
UMean
UPrime2Mean
);
coordinateSystem
{
origin (0.001 0 0);
e1 (1 0.15 0);
e3 (0 0 -1);
}
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: fieldCoordinateSystemTransform | yes |
fields | list of fields to be transformed |yes |
coordinateSystem | local co-ordinate system | yes |
\endtable
SeeAlso
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_;
// 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(const bool postProcess = false);
//- Write the transformed fields
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldCoordinateSystemTransformTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,125 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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 (mesh_.foundObject<VolFieldType>(fieldName))
{
DebugInfo
<< type() << ": Field " << fieldName << " already in database"
<< endl;
transformField<VolFieldType>
(
mesh_.lookupObject<VolFieldType>(fieldName)
);
}
else if (mesh_.foundObject<SurfaceFieldType>(fieldName))
{
DebugInfo
<< type() << ": Field " << fieldName << " already in database"
<< endl;
transformField<SurfaceFieldType>
(
mesh_.lookupObject<SurfaceFieldType>(fieldName)
);
}
else
{
IOobject fieldHeader
(
fieldName,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if
(
fieldHeader.headerOk()
&& fieldHeader.headerClassName() == VolFieldType::typeName
)
{
DebugInfo
<< type() << ": Field " << fieldName << " read from file"
<< endl;
transformField<VolFieldType>
(
mesh_.lookupObject<VolFieldType>(fieldName)
);
}
else if
(
fieldHeader.headerOk()
&& fieldHeader.headerClassName() == SurfaceFieldType::typeName
)
{
DebugInfo
<< type() << ": Field " << fieldName << " read from file"
<< endl;
transformField<SurfaceFieldType>
(
mesh_.lookupObject<SurfaceFieldType>(fieldName)
);
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,50 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ 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
);
coordinateSystem
{
origin (0.001 0 0);
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(const bool postProcess)
{
if (!calc())
{
Warning
<< "functionObject " << type() << ": 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(const bool postProcess)
{
return writeObject(resultName_);
}
bool Foam::functionObjects::fieldExpression::clear()
{
return clearObject(resultName_);
}
// ************************************************************************* //

View File

@ -0,0 +1,138 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
SeeAlso
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(const bool postProcess = false);
//- Write the result field
virtual bool write(const bool postProcess = false);
//- Clear the result field from the objectRegistry
virtual bool clear();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,75 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application XXX;
startFrom latestTime;
startTime 0;
stopAt endTime;
endTime 0.1;
deltaT 1e-05;
writeControl timeStep;
writeInterval 10;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
minMax
{
// Type of functionObject
type fieldMinMax;
// Where to load it from (if not already in solver)
libs ("libfieldFunctionObjects.so");
// Function object enabled flag
enabled true;
// Log to output (default: false)
log false;
// Write information to file (default: true)
write true;
// Fields to be monitored - runTime modifiable
fields
(
U
p
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,173 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldMinMax::writeFileHeader(const label i)
{
OFstream& file = this->file();
writeHeader(file, "Field minima and maxima");
writeCommented(file, "Time");
if (location_)
{
writeTabbed(file, "field");
writeTabbed(file, "min");
writeTabbed(file, "location(min)");
if (Pstream::parRun())
{
writeTabbed(file, "processor");
}
writeTabbed(file, "max");
writeTabbed(file, "location(max)");
if (Pstream::parRun())
{
writeTabbed(file, "processor");
}
}
else
{
forAll(fieldSet_, fieldi)
{
writeTabbed(file, "min(" + fieldSet_[fieldi] + ')');
writeTabbed(file, "max(" + fieldSet_[fieldi] + ')');
}
}
file<< endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldMinMax::fieldMinMax
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
writeFiles(name, runTime, dict, name),
location_(true),
mode_(mdMag),
fieldSet_()
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
resetName(typeName);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldMinMax::~fieldMinMax()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldMinMax::read(const dictionary& dict)
{
writeFiles::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(const bool postProcess)
{
return true;
}
bool Foam::functionObjects::fieldMinMax::write(const bool postProcess)
{
writeFiles::write();
if (!location_) writeTime(file());
Log << type() << " " << name() << " output:" << 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,206 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldMinMax
Group
grpFieldFunctionObjects
Description
This function object 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.
Example of function object specification:
\verbatim
fieldMinMax1
{
type fieldMinMax;
libs ("libfieldFunctionObjects.so");
...
write yes;
log yes;
location yes;
mode magnitude;
fields
(
U
p
);
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: fieldMinMax | yes |
write | write min/max data to file | no | yes
log | write min/max data to standard output | no | no
location | write location of the min/max value | no | yes
mode | calculation mode: magnitude or component | no | magnitude
\endtable
Output data is written to the file \<timeDir\>/fieldMinMax.dat
SeeAlso
Foam::functionObject
Foam::functionObjects::writeFiles
SourceFiles
fieldMinMax.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldMinMax_H
#define functionObjects_fieldMinMax_H
#include "writeFiles.H"
#include "vector.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldMinMax Declaration
\*---------------------------------------------------------------------------*/
class fieldMinMax
:
public writeFiles
{
public:
enum modeType
{
mdMag,
mdCmpt
};
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
);
//- Disallow default bitwise copy construct
fieldMinMax(const fieldMinMax&);
//- Disallow default bitwise assignment
void operator=(const fieldMinMax&);
//- Calculate the field min/max
template<class Type>
void calcMinMaxFields
(
const word& fieldName,
const modeType& mode
);
//- Output file header information
virtual void writeFileHeader(const label i);
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(const bool postProcess = false);
//- Write the fieldMinMax
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldMinMaxTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,276 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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;
}
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 = obr_.lookupObject<fieldType>(fieldName);
const fvMesh& mesh = field.mesh();
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] = field.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] = field.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::gatherList(minCs);
Pstream::gatherList(maxVs);
Pstream::gatherList(maxCs);
if (Pstream::master())
{
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] = field.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] = field.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::gatherList(minCs);
Pstream::gatherList(maxVs);
Pstream::gatherList(maxCs);
if (Pstream::master())
{
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,331 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "cellSource.H"
#include "fvMesh.H"
#include "volFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
defineTypeNameAndDebug(cellSource, 0);
addToRunTimeSelectionTable(fieldValue, cellSource, dictionary);
addToRunTimeSelectionTable(functionObject, cellSource, dictionary);
}
}
}
template<>
const char*
Foam::NamedEnum
<
Foam::functionObjects::fieldValues::cellSource::sourceType,
2
>::names[] = {"cellZone", "all"};
template<>
const char*
Foam::NamedEnum
<
Foam::functionObjects::fieldValues::cellSource::operationType,
11
>::names[] =
{
"none",
"sum",
"sumMag",
"average",
"weightedAverage",
"volAverage",
"weightedVolAverage",
"volIntegrate",
"min",
"max",
"CoV"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::cellSource::sourceType,
2
> Foam::functionObjects::fieldValues::cellSource::sourceTypeNames_;
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::cellSource::operationType,
11
> Foam::functionObjects::fieldValues::cellSource::operationTypeNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::cellSource::setCellZoneCells()
{
switch (source_)
{
case stCellZone:
{
dict().lookup("sourceName") >> sourceName_;
label zoneId = mesh().cellZones().findZoneID(sourceName_);
if (zoneId < 0)
{
FatalErrorInFunction
<< "Unknown cell zone name: " << sourceName_
<< ". Valid cell zones are: " << mesh().cellZones().names()
<< nl << exit(FatalError);
}
cellId_ = mesh().cellZones()[zoneId];
nCells_ = returnReduce(cellId_.size(), sumOp<label>());
break;
}
case stAll:
{
cellId_ = identity(mesh().nCells());
nCells_ = returnReduce(cellId_.size(), sumOp<label>());
break;
}
default:
{
FatalErrorInFunction
<< "Unknown source type. Valid source types are:"
<< sourceTypeNames_ << nl << exit(FatalError);
}
}
if (debug)
{
Pout<< "Selected source size = " << cellId_.size() << endl;
}
}
Foam::scalar Foam::functionObjects::fieldValues::cellSource::volume() const
{
return gSum(filterField(mesh().V()));
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::cellSource::initialise
(
const dictionary& dict
)
{
setCellZoneCells();
if (nCells_ == 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Source has no cells" << exit(FatalError);
}
volume_ = volume();
Info<< type() << " " << name() << ":"
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " total cells = " << nCells_ << nl
<< " total volume = " << volume_
<< nl << endl;
if (dict.readIfPresent("weightField", weightFieldName_))
{
Info<< " weight field = " << weightFieldName_;
}
Info<< nl << endl;
}
void Foam::functionObjects::fieldValues::cellSource::writeFileHeader
(
const label i
)
{
writeCommented(file(), "Source : ");
file() << sourceTypeNames_[source_] << " " << sourceName_ << endl;
writeCommented(file(), "Cells : ");
file() << nCells_ << endl;
writeCommented(file(), "Volume : ");
file() << volume_ << endl;
writeCommented(file(), "Time");
if (writeVolume_)
{
file() << tab << "Volume";
}
forAll(fields_, i)
{
file()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
file() << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::cellSource::cellSource
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldValue(name, runTime, dict, typeName),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
nCells_(0),
cellId_(),
weightFieldName_("none"),
writeVolume_(dict.lookupOrDefault("writeVolume", false))
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
Foam::functionObjects::fieldValues::cellSource::cellSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
nCells_(0),
cellId_(),
weightFieldName_("none"),
writeVolume_(dict.lookupOrDefault("writeVolume", false))
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::cellSource::~cellSource()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::cellSource::read
(
const dictionary& dict
)
{
fieldValue::read(dict);
// No additional info to read
initialise(dict);
return true;
}
bool Foam::functionObjects::fieldValues::cellSource::write
(
const bool postProcess
)
{
fieldValue::write();
if (Pstream::master())
{
writeTime(file());
}
if (writeVolume_)
{
volume_ = volume();
if (Pstream::master())
{
file() << tab << volume_;
}
Log << " total volume = " << volume_ << endl;
}
forAll(fields_, i)
{
const word& fieldName = fields_[i];
bool processed = false;
processed = processed || writeValues<scalar>(fieldName);
processed = processed || writeValues<vector>(fieldName);
processed = processed || writeValues<sphericalTensor>(fieldName);
processed = processed || writeValues<symmTensor>(fieldName);
processed = processed || writeValues<tensor>(fieldName);
if (!processed)
{
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,306 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldValues::cellSource
Group
grpFieldFunctionObjects
Description
This function object provides a 'cell source' variant of the fieldValues
function object. Given a list of user-specified fields and a selection
of mesh cells, a number of operations can be performed, such as sums,
averages and integrations.
Example of function object specification:
\verbatim
cellSource1
{
type cellSource;
libs ("libfieldFunctionObjects.so");
...
log true;
valueOutput true;
source cellZone;
sourceName c0;
operation volAverage;
weightField alpha1;
fields
(
p
U
);
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | Type name: cellSource | yes |
log | Write data to standard output | no | no
valueOutput | Write the raw output values | yes |
writeVolume | Write the volume of the cellSource | no |
source | cell source: see below | yes |
sourceName | name of cell source 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
\linebreak
Where \c source is defined by
\plaintable
cellZone | requires a 'sourceName' entry to specify the cellZone
all | all cells
\endplaintable
\linebreak
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
SeeAlso
Foam::fieldValues
Foam::functionObject
SourceFiles
cellSource.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_cellSource_H
#define functionObjects_cellSource_H
#include "fieldValue.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class cellSource Declaration
\*---------------------------------------------------------------------------*/
class cellSource
:
public fieldValue
{
public:
// Public data types
//- Source type enumeration
enum sourceType
{
stCellZone,
stAll
};
//- Source type names
static const NamedEnum<sourceType, 2> sourceTypeNames_;
//- 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_;
private:
// Private Member Functions
//- Set cells to evaluate based on a cell zone
void setCellZoneCells();
//- Set cells to evaluate based on a patch
void setPatchCells();
//- Calculate and return volume of the cellSource: sum(V)
scalar volume() const;
protected:
// Protected data
//- Source type
sourceType source_;
//- Operation to apply to values
operationType operation_;
//- Global number of cells
label nCells_;
//- Local list of cell IDs
labelList cellId_;
//- Weight field name - only used for opWeightedAverage mode
word weightFieldName_;
//- Volume of the cellSource
scalar volume_;
//- Optionally write the volume of the cellSource
bool writeVolume_;
// 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>> setFieldValues
(
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(const label i);
public:
//- Run-time type information
TypeName("cellSource");
// Constructors
//- Construct from name, Time and dictionary
cellSource
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from name, objectRegistry and dictionary
cellSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~cellSource();
// Public Member Functions
//- Return the source type
inline const sourceType& source() const;
//- Return the local list of cell IDs
inline const labelList& cellId() const;
//- Templated helper function to output field values
template<class Type>
bool writeValues(const word& fieldName);
//- 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(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "cellSourceI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "cellSourceTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "cellSource.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::functionObjects::fieldValues::cellSource::sourceType&
Foam::functionObjects::fieldValues::cellSource::source() const
{
return source_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::cellSource::cellId() const
{
return cellId_;
}
// ************************************************************************* //

View File

@ -0,0 +1,229 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "cellSource.H"
#include "volFields.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::cellSource::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::cellSource::setFieldValues
(
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::cellSource::processValues
(
const Field<Type>& values,
const scalarField& V,
const scalarField& weightField
) const
{
Type result = Zero;
switch (operation_)
{
case opSum:
{
result = sum(values);
break;
}
case opSumMag:
{
result = sum(cmptMag(values));
break;
}
case opAverage:
{
result = sum(values)/values.size();
break;
}
case opWeightedAverage:
{
result = sum(weightField*values)/sum(weightField);
break;
}
case opVolAverage:
{
result = sum(V*values)/sum(V);
break;
}
case opWeightedVolAverage:
{
result = sum(weightField*V*values)/sum(weightField*V);
break;
}
case opVolIntegrate:
{
result = sum(V*values);
break;
}
case opMin:
{
result = min(values);
break;
}
case opMax:
{
result = max(values);
break;
}
case opCoV:
{
Type meanValue = sum(values*V)/sum(V);
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(sum(V*sqr(vals - mean))/sum(V))/mean;
}
break;
}
case opNone:
{}
}
return result;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::fieldValues::cellSource::writeValues
(
const word& fieldName
)
{
const bool ok = validField<Type>(fieldName);
if (ok)
{
Field<Type> values(setFieldValues<Type>(fieldName));
scalarField V(filterField(mesh().V()));
scalarField weightField(values.size(), 1.0);
if (weightFieldName_ != "none")
{
weightField = setFieldValues<scalar>(weightFieldName_, true);
}
// Combine onto master
combineFields(values);
combineFields(V);
combineFields(weightField);
if (Pstream::master())
{
Type result = processValues(values, V, weightField);
// Add to result dictionary, over-writing any previous entry
resultDict_.add(fieldName, result, true);
if (valueOutput_)
{
IOField<Type>
(
IOobject
(
fieldName + "_" + sourceTypeNames_[source_] + "-"
+ sourceName_,
obr_.time().timeName(),
obr_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
weightField*values
).write();
}
file()<< tab << result;
Log << " " << operationTypeNames_[operation_]
<< "(" << sourceName_ << ") of " << fieldName
<< " = " << result << endl;
}
}
return ok;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::cellSource::filterField
(
const Field<Type>& field
) const
{
return tmp<Field<Type>>(new Field<Type>(field, cellId_));
}
// ************************************************************************* //

View File

@ -0,0 +1,129 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
faceObj1
{
type faceSource;
libs ("libfieldFunctionObjects.so");
enabled true;
writeControl writeTime;
// Output to log&file (true) or to file only
log true;
// Output field values as well
valueOutput true;
// Type of source: patch/faceZone/sampledSurface
source patch;
// if patch or faceZone: name of patch or faceZone
sourceName movingWall;
//// if sampledSurface: dictionary with a sampledSurface
//// Note: will not sample surface fields.
//sampledSurfaceDict
//{
// // Sampling on triSurface
// type sampledTriSurfaceMesh;
// surface integrationPlane.stl;
// source cells; // sample cells or boundaryFaces
// interpolate true;
//}
// Operation: areaAverage/sum/weightedAverage ...
operation areaAverage;
fields
(
p
phi // surface fields not supported for sampledSurface
U
);
}
faceObj2
{
type faceSource;
libs ("libfieldFunctionObjects.so");
enabled true;
writeControl writeTime;
log true;
valueOutput true;
source faceZone;
sourceName f0;
operation sum;
fields
(
phi
);
}
cellObj1
{
type cellSource;
libs ("libfieldFunctionObjects.so");
enabled true;
writeControl writeTime;
log true;
valueOutput true;
source cellZone;
sourceName c0;
operation volAverage;
fields
(
p
U
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,800 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "faceSource.H"
#include "fvMesh.H"
#include "cyclicPolyPatch.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(faceSource, 0);
addToRunTimeSelectionTable(fieldValue, faceSource, dictionary);
addToRunTimeSelectionTable(functionObject, faceSource, dictionary);
}
}
}
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::faceSource::sourceType,
3
>::names[] =
{
"faceZone",
"patch",
"sampledSurface"
};
template<>
const char* Foam::NamedEnum
<
Foam::functionObjects::fieldValues::faceSource::operationType,
15
>::names[] =
{
"none",
"sum",
"sumMag",
"sumDirection",
"sumDirectionBalance",
"average",
"weightedAverage",
"areaAverage",
"weightedAreaAverage",
"areaIntegrate",
"min",
"max",
"CoV",
"areaNormalAverage",
"areaNormalIntegrate"
};
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::faceSource::sourceType,
3
> Foam::functionObjects::fieldValues::faceSource::sourceTypeNames_;
const Foam::NamedEnum
<
Foam::functionObjects::fieldValues::faceSource::operationType,
15
> Foam::functionObjects::fieldValues::faceSource::operationTypeNames_;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::fieldValues::faceSource::setFaceZoneFaces()
{
label zoneId = mesh().faceZones().findZoneID(sourceName_);
if (zoneId < 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Unknown face zone name: " << sourceName_
<< ". 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::faceSource::setPatchFaces()
{
const label patchid = mesh().boundaryMesh().findPatchID(sourceName_);
if (patchid < 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Unknown patch name: " << sourceName_
<< ". 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::faceSource::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::faceSource::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::faceSource::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::faceSource::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::faceSource::initialise
(
const dictionary& dict
)
{
dict.lookup("sourceName") >> sourceName_;
switch (source_)
{
case stFaceZone:
{
setFaceZoneFaces();
break;
}
case stPatch:
{
setPatchFaces();
break;
}
case stSampledSurface:
{
sampledSurfaceFaces(dict);
break;
}
default:
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< nl << " Unknown source type. Valid source types are:"
<< sourceTypeNames_.sortedToc() << nl << exit(FatalError);
}
}
if (nFaces_ == 0)
{
FatalErrorInFunction
<< type() << " " << name() << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):" << nl
<< " Source 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 (source_ == stSampledSurface)
{
FatalIOErrorInFunction(dict)
<< "Cannot use weightField for a sampledSurface"
<< exit(FatalIOError);
}
}
if (dict.found("orientedWeightField"))
{
if (weightFieldName_ == "none")
{
dict.lookup("orientedWeightField") >> weightFieldName_;
Info<< " 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);
}
if (dict.readIfPresent("scaleFactor", scaleFactor_))
{
Info<< " scale factor = " << scaleFactor_ << nl;
}
Info<< nl << endl;
if (valueOutput_)
{
const word surfaceFormat(dict.lookup("surfaceFormat"));
surfaceWriterPtr_.reset
(
surfaceWriter::New
(
surfaceFormat,
dict.subOrEmptyDict("formatOptions").
subOrEmptyDict(surfaceFormat)
).ptr()
);
}
}
void Foam::functionObjects::fieldValues::faceSource::writeFileHeader
(
const label i
)
{
writeCommented(file(), "Source : ");
file() << sourceTypeNames_[source_] << " " << sourceName_ << endl;
writeCommented(file(), "Faces : ");
file() << nFaces_ << endl;
writeCommented(file(), "Area : ");
file() << totalArea_ << endl;
writeCommented(file(), "Time");
if (writeArea_)
{
file() << tab << "Area";
}
forAll(fields_, i)
{
file()
<< tab << operationTypeNames_[operation_]
<< "(" << fields_[i] << ")";
}
file() << endl;
}
template<>
Foam::scalar Foam::functionObjects::fieldValues::faceSource::processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
switch (operation_)
{
case opSumDirection:
{
vector n(dict_.lookup("direction"));
return sum(pos(values*(Sf & n))*mag(values));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
const scalarField nv(values*(Sf & n));
return sum(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::faceSource::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 sum(pos(nv)*n*(nv));
}
case opSumDirectionBalance:
{
vector n(dict_.lookup("direction"));
n /= mag(n) + ROOTVSMALL;
const scalarField nv(n & values);
return sum(pos(nv)*n*(nv));
}
case opAreaNormalAverage:
{
scalar result = sum(values & Sf)/sum(mag(Sf));
return vector(result, 0.0, 0.0);
}
case opAreaNormalIntegrate:
{
scalar result = sum(values & Sf);
return vector(result, 0.0, 0.0);
}
default:
{
// Fall through to other operations
return processSameTypeValues(values, Sf, weightField);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::faceSource::faceSource
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldValue(name, runTime, dict, typeName),
surfaceWriterPtr_(NULL),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"),
orientWeightField_(false),
orientedFieldsStart_(labelMax),
scaleFactor_(1.0),
writeArea_(dict.lookupOrDefault("writeArea", false)),
nFaces_(0),
faceId_(),
facePatchId_(),
faceSign_()
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
Foam::functionObjects::fieldValues::faceSource::faceSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
)
:
fieldValue(name, obr, dict, typeName),
surfaceWriterPtr_(NULL),
source_(sourceTypeNames_.read(dict.lookup("source"))),
operation_(operationTypeNames_.read(dict.lookup("operation"))),
weightFieldName_("none"),
orientWeightField_(false),
orientedFieldsStart_(labelMax),
scaleFactor_(1.0),
writeArea_(dict.lookupOrDefault("writeArea", false)),
nFaces_(0),
faceId_(),
facePatchId_(),
faceSign_()
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::faceSource::~faceSource()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::faceSource::read
(
const dictionary& dict
)
{
fieldValue::read(dict);
initialise(dict);
return true;
}
bool Foam::functionObjects::fieldValues::faceSource::write
(
const bool postProcess
)
{
fieldValue::write();
if (surfacePtr_.valid())
{
surfacePtr_().update();
}
if (Pstream::master())
{
writeTime(file());
}
if (writeArea_)
{
totalArea_ = totalArea();
if (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_
);
}
// Combine onto master
combineFields(weightField);
// 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 (Pstream::master())
{
file()<< endl;
}
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,449 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldValues::faceSource
Group
grpFieldFunctionObjects
Description
This function object provides a 'face source' 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.
\linebreak
For example, to calculate the volumetric or mass flux across a patch,
apply the 'sum' operator to the flux field (typically \c phi)
Example of function object specification:
\verbatim
faceSource1
{
type faceSource;
libs ("libfieldFunctionObjects.so");
...
log yes;
valueOutput true;
surfaceFormat none;
source faceZone;
sourceName f0;
operation sum;
weightField alpha1;
fields
(
p
phi
U
);
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: faceSource | yes |
log | write data to standard output | no | no
valueOutput | write the output values | yes |
writeArea | Write the area of the faceSource | no |
surfaceFormat | output value format | no |
source | face source: see below | yes |
sourceName | name of face source 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
\linebreak
Where \c source is defined by
\plaintable
faceZone | requires a 'sourceName' entry to specify the faceZone
patch | requires a 'sourceName' entry to specify the patch
sampledSurface | requires a 'sampledSurfaceDict' sub-dictionary
\endplaintable
\linebreak
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 sampledSurfaces:
- 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
SeeAlso
Foam::fieldValues
Foam::functionObject
SourceFiles
faceSource.C
faceSourceTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_faceSource_H
#define functionObjects_faceSource_H
#include "fieldValue.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class sampledSurface;
class surfaceWriter;
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class faceSource Declaration
\*---------------------------------------------------------------------------*/
class faceSource
:
public fieldValue
{
public:
// Public data types
//- Source type enumeration
enum sourceType
{
stFaceZone,
stPatch,
stSampledSurface
};
//- Source type names
static const NamedEnum<sourceType, 3> sourceTypeNames_;
//- Operation type enumeration
enum operationType
{
opNone,
opSum,
opSumMag,
opSumDirection,
opSumDirectionBalance,
opAverage,
opWeightedAverage,
opAreaAverage,
opWeightedAreaAverage,
opAreaIntegrate,
opMin,
opMax,
opCoV,
opAreaNormalAverage,
opAreaNormalIntegrate
};
//- 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 faceSource: sum(magSf)
scalar totalArea() const;
protected:
// Protected data
//- Surface writer
autoPtr<surfaceWriter> surfaceWriterPtr_;
//- Source type
sourceType source_;
//- 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_;
//- Scale factor - optional
scalar scaleFactor_;
//- Total area of the faceSource
scalar totalArea_;
//- Optionally write the area of the faceSource
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(const label i);
public:
//- Run-time type information
TypeName("faceSource");
// Constructors
//- Construct from name, Time and dictionary
faceSource
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Construct from name, objectRegistry and dictionary
faceSource
(
const word& name,
const objectRegistry& obr,
const dictionary& dict
);
//- Destructor
virtual ~faceSource();
// Public Member Functions
//- Return the source type
inline const sourceType& source() 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;
//- 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(const bool postProcess = false);
};
//- Specialisation for scalar
template<>
scalar faceSource::processValues
(
const Field<scalar>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
//- Specialisation for vector
template<>
vector faceSource::processValues
(
const Field<vector>& values,
const vectorField& Sf,
const scalarField& weightField
) const;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "faceSourceI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "faceSourceTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

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 |
-------------------------------------------------------------------------------
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 "faceSource.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::functionObjects::fieldValues::faceSource::sourceType&
Foam::functionObjects::fieldValues::faceSource::source() const
{
return source_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::faceSource::faceId() const
{
return faceId_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::faceSource::facePatch() const
{
return facePatchId_;
}
inline const Foam::labelList&
Foam::functionObjects::fieldValues::faceSource::faceSign() const
{
return faceSign_;
}
// ************************************************************************* //

View File

@ -0,0 +1,436 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "faceSource.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::faceSource::validField
(
const word& fieldName
) const
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (source_ != 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::faceSource::getFieldValues
(
const word& fieldName,
const bool mustGet,
const bool applyOrientation
) const
{
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
typedef GeometricField<Type, fvPatchField, volMesh> vf;
if (source_ != 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::faceSource::processSameTypeValues
(
const Field<Type>& values,
const vectorField& Sf,
const scalarField& weightField
) const
{
Type result = Zero;
switch (operation_)
{
case opSum:
{
result = sum(values);
break;
}
case opSumMag:
{
result = sum(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:
{
result = sum(values)/values.size();
break;
}
case opWeightedAverage:
{
if (weightField.size())
{
result = sum(weightField*values)/sum(weightField);
}
else
{
result = sum(values)/values.size();
}
break;
}
case opAreaAverage:
{
const scalarField magSf(mag(Sf));
result = sum(magSf*values)/sum(magSf);
break;
}
case opWeightedAreaAverage:
{
const scalarField magSf(mag(Sf));
if (weightField.size())
{
result = sum(weightField*magSf*values)/sum(magSf*weightField);
}
else
{
result = sum(magSf*values)/sum(magSf);
}
break;
}
case opAreaIntegrate:
{
const scalarField magSf(mag(Sf));
result = sum(magSf*values);
break;
}
case opMin:
{
result = min(values);
break;
}
case opMax:
{
result = max(values);
break;
}
case opCoV:
{
const scalarField magSf(mag(Sf));
Type meanValue = sum(values*magSf)/sum(magSf);
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(sum(magSf*sqr(vals - mean))/sum(magSf))/mean;
}
break;
}
case opAreaNormalAverage:
{}
case opAreaNormalIntegrate:
{}
case opNone:
{}
}
return result;
}
template<class Type>
Type Foam::functionObjects::fieldValues::faceSource::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::faceSource::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);
}
// Combine onto master
combineFields(values);
combineFields(Sf);
// Write raw values on surface if specified
if (surfaceWriterPtr_.valid())
{
faceList faces;
pointField points;
if (surfacePtr_.valid())
{
combineSurfaceGeometry(faces, points);
}
else
{
combineMeshGeometry(faces, points);
}
if (Pstream::master())
{
fileName outputDir =
baseFileDir()/name()/"surface"/obr_.time().timeName();
surfaceWriterPtr_->write
(
outputDir,
word(sourceTypeNames_[source_]) + "_" + sourceName_,
points,
faces,
fieldName,
values,
false
);
}
}
// Apply scale factor
values *= scaleFactor_;
if (Pstream::master())
{
Type result = processValues(values, Sf, weightField);
// Add to result dictionary, over-writing any previous entry
resultDict_.add(fieldName, result, true);
file()<< tab << result;
Log << " " << operationTypeNames_[operation_]
<< "(" << sourceName_ << ") of " << fieldName
<< " = " << result << endl;
}
}
return ok;
}
template<class Type>
Foam::tmp<Foam::Field<Type>>
Foam::functionObjects::fieldValues::faceSource::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() << ": "
<< sourceTypeNames_[source_] << "(" << sourceName_ << "):"
<< 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::faceSource::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,119 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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
)
:
writeFiles(name, runTime, dict, name),
dict_(dict),
sourceName_(word::null),
fields_(dict.lookup("fields")),
valueOutput_(dict.lookup("valueOutput")),
resultDict_(fileName("name"), dictionary::null)
{
read(dict);
resetName(valueType);
}
Foam::functionObjects::fieldValue::fieldValue
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const word& valueType
)
:
writeFiles(name, obr, dict, name),
dict_(dict),
sourceName_(word::null),
fields_(dict.lookup("fields")),
valueOutput_(dict.lookup("valueOutput")),
resultDict_(fileName("name"), dictionary::null)
{
read(dict);
resetName(valueType);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValue::~fieldValue()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValue::read(const dictionary& dict)
{
dict_ = dict;
writeFiles::read(dict);
dict.lookup("fields") >> fields_;
dict.lookup("valueOutput") >> valueOutput_;
return true;
}
bool Foam::functionObjects::fieldValue::execute(const bool postProcess)
{
return true;
}
bool Foam::functionObjects::fieldValue::write(const bool postProcess)
{
writeFiles::write();
Log << type() << " " << name() << " output:" << nl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,201 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldValue
Group
grpFieldFunctionObjects
Description
Base class for field value -based function objects.
SourceFiles
fieldValue.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldValue_H
#define functionObjects_fieldValue_H
#include "writeFiles.H"
#include "Switch.H"
#include "Field.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class fvMesh;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class fieldValue Declaration
\*---------------------------------------------------------------------------*/
class fieldValue
:
public writeFiles
{
protected:
// Protected data
//- Construction dictionary
dictionary dict_;
//- Name of source object
word sourceName_;
//- List of field names to operate on
wordList fields_;
//- Output field values flag
Switch valueOutput_;
//- Results dictionary for external access of results
dictionary resultDict_;
// 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 source name
inline const word& sourceName() const;
//- Return the list of field names
inline const wordList& fields() const;
//- Return the output field values flag
inline const Switch& valueOutput() const;
//- Helper function to return the reference to the mesh
inline const fvMesh& mesh() const;
//- Return access to the latest set of results
inline const dictionary& resultDict() const;
//- Read from dictionary
virtual bool read(const dictionary& dict);
//- Execute
virtual bool execute(const bool postProcess = false);
//- Write to screen/file
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "fieldValueI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldValueTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,69 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "fieldValue.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::dictionary& Foam::functionObjects::fieldValue::dict() const
{
return dict_;
}
inline const Foam::word& Foam::functionObjects::fieldValue::sourceName() const
{
return sourceName_;
}
inline const Foam::wordList& Foam::functionObjects::fieldValue::fields() const
{
return fields_;
}
inline const Foam::Switch&
Foam::functionObjects::fieldValue::valueOutput() const
{
return valueOutput_;
}
inline const Foam::fvMesh& Foam::functionObjects::fieldValue::mesh() const
{
return refCast<const fvMesh>(obr_);
}
inline const Foam::dictionary&
Foam::functionObjects::fieldValue::resultDict() const
{
return resultDict_;
}
// ************************************************************************* //

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,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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);
if (Pstream::master())
{
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,218 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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
(
const label i
)
{
const wordList& fields1 = source1Ptr_->fields();
const wordList& fields2 = source2Ptr_->fields();
DynamicList<word> commonFields(fields1.size());
forAll(fields1, i)
{
label index = findIndex(fields2, fields1[i]);
if (index != -1)
{
commonFields.append(fields1[i]);
}
}
Ostream& os = file();
writeHeaderValue(os, "Source1", source1Ptr_->name());
writeHeaderValue(os, "Source2", source2Ptr_->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
)
:
writeFiles(name, runTime, dict, name),
operation_(opSubtract),
source1Ptr_(NULL),
source2Ptr_(NULL)
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
resetName(typeName);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::fieldValues::fieldValueDelta::~fieldValueDelta()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::fieldValues::fieldValueDelta::read
(
const dictionary& dict
)
{
writeFiles::read(dict);
source1Ptr_.reset
(
fieldValue::New
(
name() + ".source1",
obr_,
dict.subDict("source1"),
false
).ptr()
);
source2Ptr_.reset
(
fieldValue::New
(
name() + ".source2",
obr_,
dict.subDict("source2"),
false
).ptr()
);
operation_ = operationTypeNames_.read(dict.lookup("operation"));
return true;
}
bool Foam::functionObjects::fieldValues::fieldValueDelta::write
(
const bool postProcess
)
{
writeFiles::write();
source1Ptr_->write();
source2Ptr_->write();
if (Pstream::master())
{
writeTime(file());
}
Log << type() << " " << name() << " output:" << endl;
bool found = false;
processFields<scalar>(found);
processFields<vector>(found);
processFields<sphericalTensor>(found);
processFields<symmTensor>(found);
processFields<tensor>(found);
if (Pstream::master())
{
file()<< endl;
}
if (!found)
{
Log << " none" << endl;
}
else
{
Log << endl;
}
return true;
}
bool Foam::functionObjects::fieldValues::fieldValueDelta::execute
(
const bool postProcess
)
{
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,197 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::fieldValues::fieldValueDelta
Group
grpFieldFunctionObjects
Description
This function object provides a differencing option between two 'field
value' function objects.
Example of function object specification:
\verbatim
fieldValueDelta1
{
type fieldValueDelta;
libs ("libfieldFunctionObjects.so");
operation subtract;
fieldValue1
{
...
}
fieldValue2
{
...
}
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: fieldValueDelta | yes |
\endtable
\linebreak
The \c operation is one of:
\plaintable
add | add
subtract | subtract
min | minimum
max | maximum
average | average
\endplaintable
SeeAlso
Foam::fieldValue
SourceFiles
fieldValueDelta.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_fieldValueDelta_H
#define functionObjects_fieldValueDelta_H
#include "writeFiles.H"
#include "fieldValue.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace fieldValues
{
/*---------------------------------------------------------------------------*\
Class fieldValueDelta Declaration
\*---------------------------------------------------------------------------*/
class fieldValueDelta
:
public writeFiles
{
public:
//- Operation type enumeration
enum operationType
{
opAdd,
opSubtract,
opMin,
opMax,
opAverage
};
//- Operation type names
static const NamedEnum<operationType, 5> operationTypeNames_;
private:
// Private data
//- Operation to apply to values
operationType operation_;
//- Field value source object 1
autoPtr<fieldValue> source1Ptr_;
//- Field value source object 2
autoPtr<fieldValue> source2Ptr_;
// Private Member Functions
//- Templated function to process common fields
template<class Type>
void processFields(bool& found);
//- Templated function to apply the operation
template<class Type>
Type applyOperation(const Type& value1, const Type& value2) const;
protected:
// Protected Member Functions
//- Output file header information
virtual void writeFileHeader(const label i);
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(const bool postProcess = false);
//- Calculate and write
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fieldValues
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "fieldValueDeltaTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,128 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "GeometricField.H"
#include "volMesh.H"
#include "surfaceMesh.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Type Foam::functionObjects::fieldValues::fieldValueDelta::applyOperation
(
const Type& value1,
const Type& value2
) const
{
Type result = Zero;
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);
}
}
return result;
}
template<class Type>
void Foam::functionObjects::fieldValues::fieldValueDelta::processFields
(
bool& found
)
{
typedef GeometricField<Type, fvPatchField, volMesh> vf;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> sf;
const wordList& fields1 = source1Ptr_->fields();
const dictionary& results1 = source1Ptr_->resultDict();
const dictionary& results2 = source2Ptr_->resultDict();
Type r1(Zero);
Type r2(Zero);
forAll(fields1, i)
{
const word& fieldName = fields1[i];
if
(
(obr_.foundObject<vf>(fieldName) || obr_.foundObject<sf>(fieldName))
&& results2.found(fieldName)
)
{
results1.lookup(fieldName) >> r1;
results2.lookup(fieldName) >> r2;
Type result = applyOperation(r1, r2);
Log << " " << operationTypeNames_[operation_]
<< "(" << fieldName << ") = " << result
<< endl;
if (Pstream::master())
{
file()<< tab << result;
}
found = true;
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,102 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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
This function object 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
SeeAlso
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,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 "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)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::grad::~grad()
{}
// ************************************************************************* //

View File

@ -0,0 +1,110 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
This function object 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.
SeeAlso
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,205 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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
)
:
writeFile(name, runTime, dict, name)
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::histogram::~histogram()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::histogram::read(const dictionary& 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(const bool postProcess)
{
return true;
}
bool Foam::functionObjects::histogram::write(const bool postProcess)
{
Log << type() << " " << name() << " output:" << nl;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
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 volFrac(nBins_, 0);
const scalarField& V = mesh.V();
forAll(field, celli)
{
const label bini = (field[celli] - min_)/delta;
if (bini >= 0 && bini < nBins_)
{
volFrac[bini] += V[celli];
}
}
Pstream::listCombineGather(volFrac, plusEqOp<scalar>());
if (Pstream::master())
{
const scalar sumVol = sum(volFrac);
if (sumVol > SMALL)
{
volFrac /= sumVol;
const coordSet coords
(
"Volume_Fraction",
"x",
xBin,
mag(xBin)
);
writeGraph(coords, field.name(), volFrac);
}
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,169 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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.
Example:
\verbatim
histogram1
{
type histogram;
libs ("libfieldFunctionObjects.so");
field p;
nBins 100;
min -5;
max 5;
setFormat gnuplot;
}
\endverbatim
\heading Function object usage
\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
SeeAlso
Foam::functionObject
Foam::functionObjects::writeFile
SourceFiles
histogram.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_histogram_H
#define functionObjects_histogram_H
#include "writer.H"
#include "writeFile.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class histogram Declaration
\*---------------------------------------------------------------------------*/
class histogram
:
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(const bool postProcess = false);
//- Calculate the histogram and write.
// postProcess overrides the usual writeControl behaviour and
// forces writing always (used in post-processing mode)
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,78 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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)
{
read(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
This function object calculates the magnitude of a field.
The operation can be applied to any volume or surface fields generating a
volume or surface scalar field.
SeeAlso
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,78 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "magSqr.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(magSqr, 0);
addToRunTimeSelectionTable(functionObject, magSqr, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::magSqr::calc()
{
bool processed = false;
processed = processed || calcMagSqr<scalar>();
processed = processed || calcMagSqr<vector>();
processed = processed || calcMagSqr<sphericalTensor>();
processed = processed || calcMagSqr<symmTensor>();
processed = processed || calcMagSqr<tensor>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::magSqr::magSqr
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::magSqr::~magSqr()
{}
// ************************************************************************* //

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
This function object calculates the magnitude of the sqr of a field.
The operation can be applied to any volume or surface field generating a
volume or surface scalar field.
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
magSqr.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_magSqr_H
#define functionObjects_magSqr_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class magSqr Declaration
\*---------------------------------------------------------------------------*/
class magSqr
:
public fieldExpression
{
// Private Member Functions
//- Calculate the magnitude of the sqr of the field
// and register the result
template<class Type>
bool calcMagSqr();
//- Calculate the magnitude of the sqr of the field
// and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("magSqr");
// Constructors
//- Construct from Time and dictionary
magSqr
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~magSqr();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "magSqrTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

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,78 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
near
{
// Where to load it from
libs ("libfieldFunctionObjects.so");
type nearWallFields;
// Output every
writeControl writeTime; //timeStep;
//writeInterval 5;
// Fields to be sampled. Per field original name and mapped field to
// create.
// Note: fields only get updated when writing!
fields
(
(p pNear)
(U UNear)
);
// Patches to sample (regular expressions)
patches ("movingWall");
// Distance to sample
distance 0.009;
}
}
// ************************************************************************* //

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,266 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
/*---------------------------------------------------------------------------*\
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,364 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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_, 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(const bool postProcess)
{
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()
<< " output:" << nl
<< " Sampling fields to " << time_.timeName()
<< endl;
sampleFields(vsf_);
sampleFields(vvf_);
sampleFields(vSpheretf_);
sampleFields(vSymmtf_);
sampleFields(vtf_);
return true;
}
bool Foam::functionObjects::nearWallFields::write(const bool postProcess)
{
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();
}
Log << endl;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,221 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::nearWallFields
Group
grpFieldFunctionObjects
Description
This function object 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
Example of function object specification:
\verbatim
nearWallFields1
{
type nearWallFields;
libs ("libfieldFunctionObjects.so");
...
fields ((p pNear)(U UNear));
patches (movingWall);
distance 0.13;
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: nearWallFields | yes |
fields | list of fields with correspoding output field names | yes |
patches | list of patches to sample | yes |
distance | distance from patch to sample | yes |
\endtable
SeeAlso
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_;
//- 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(const bool postProcess = false);
//- Write the near-wall fields
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "nearWallFieldsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,149 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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))
{
Log << " a field " << 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,262 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "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
{
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)
{
read(dict);
dimensionSet pDims(dimPressure);
if (calcCoeff_)
{
pDims /= dimPressure;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::pressure::~pressure()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::pressure::read(const dictionary& dict)
{
dict.readIfPresent("U", UName_);
dict.readIfPresent("rho", rhoName_);
if (rhoName_ == "rhoInf")
{
dict.lookup("rhoInf") >> rhoInf_;
}
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;
}
}
resultName_ = dict.lookupOrDefault<word>("result", resultName());
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,240 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::pressure
Group
grpFieldFunctionObjects
Description
This function object 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
Example of function object specification to calculate pressure coefficient:
\verbatim
pressure1
{
type pressure;
libs ("libutilityFunctionObjects.so");
...
calcTotal no;
calcCoeff yes;
}
\endverbatim
\heading Function object usage
\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
SeeAlso
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_;
// 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: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ 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 bool postProcess)
{
const volScalarField& procField =
mesh_.lookupObject<volScalarField>("processorID");
const_cast<volScalarField&>(procField) ==
dimensionedScalar("proci", dimless, Pstream::myProcNo());
return true;
}
bool Foam::functionObjects::processorField::write(const bool postProcess)
{
const volScalarField& procField =
mesh_.lookupObject<volScalarField>("processorID");
procField.write();
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,130 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::processorField
Group
grpFieldFunctionObjects
Description
This function object writes a scalar field whose value is the local
processor ID. The output field name is 'processorID'.
Example of function object specification:
\verbatim
processorField1
{
type processorField;
libs ("libfieldFunctionObjects.so");
...
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: processorField | yes |
\endtable
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
processorField.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_processorField_H
#define functionObjects_processorField_H
#include "fvMeshFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class processorField Declaration
\*---------------------------------------------------------------------------*/
class processorField
:
public fvMeshFunctionObject
{
// Private member functions
//- Disallow default bitwise copy construct
processorField(const processorField&);
//- Disallow default bitwise assignment
void operator=(const processorField&);
public:
//- Runtime type information
TypeName("processorField");
// Constructors
//- Construct from Time and dictionary
processorField
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~processorField();
// Member Functions
//- Read the input data
virtual bool read(const dictionary&);
//- Calculate the processorID field
virtual bool execute(const bool postProcess = false);
//- Write the processorID field
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

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 "randomise.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(randomise, 0);
addToRunTimeSelectionTable(functionObject, randomise, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::functionObjects::randomise::calc()
{
bool processed = false;
processed = processed || calcRandomised<scalar>();
processed = processed || calcRandomised<vector>();
processed = processed || calcRandomised<sphericalTensor>();
processed = processed || calcRandomised<symmTensor>();
processed = processed || calcRandomised<tensor>();
return processed;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::randomise::randomise
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fieldExpression(name, runTime, dict)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::randomise::~randomise()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::randomise::read(const dictionary& dict)
{
fieldExpression::read(dict);
dict.lookup("magPerturbation") >> magPerturbation_;
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,123 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::randomise
Group
grpFieldFunctionObjects
Description
This function object adds a random component to a field,
with a specified perturbation magnitude.
The operation can be applied to any volume field.
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
randomise.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_randomise_H
#define functionObjects_randomise_H
#include "fieldExpression.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class randomise Declaration
\*---------------------------------------------------------------------------*/
class randomise
:
public fieldExpression
{
// Private member data
//- The magnitude of the purturbation
scalar magPerturbation_;
// Private Member Functions
//- Calculate the randomisenitude of the field and register the result
template<class Type>
bool calcRandomised();
//- Calculate the randomised field and return true if successful
virtual bool calc();
public:
//- Runtime type information
TypeName("randomise");
// Constructors
//- Construct from Time and dictionary
randomise
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~randomise();
// Member Functions
//- Read the randomise data
virtual bool read(const dictionary&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "randomiseTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "Random.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
bool Foam::functionObjects::randomise::calcRandomised()
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
if (foundObject<VolFieldType>(fieldName_))
{
const VolFieldType& field = lookupObject<VolFieldType>(fieldName_);
resultName_ = fieldName_ + "Random";
tmp<VolFieldType> rfieldt(new VolFieldType(field));
VolFieldType& rfield = rfieldt.ref();
Random rand(1234567);
forAll(field, celli)
{
Type rndPert;
rand.randomise(rndPert);
rndPert = 2.0*rndPert - pTraits<Type>::one;
rndPert /= mag(rndPert);
rfield[celli] += magPerturbation_*rndPert;
}
return store(resultName_, rfieldt);
}
else
{
return false;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,53 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object postProcessingDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
functions
{
readFields1
{
type readFields;
libs ("libfieldFunctionObjects.so");
enabled true;
writeControl timeStep;
writeInterval 1;
fields
(
interpolateU
);
}
faceObj2
{
type faceSource;
libs ("libfieldFunctionObjects.so");
enabled true;
writeControl timeStep;
writeInterval 1;
log true;
valueOutput true;
source faceZone;
sourceName f0;
operation areaAverage;
fields
(
interpolateU
);
}
}
// ************************************************************************* //

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 |
-------------------------------------------------------------------------------
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 "readFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(readFields, 0);
addToRunTimeSelectionTable(functionObject, readFields, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::readFields::readFields
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
fieldSet_()
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::readFields::~readFields()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::readFields::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
dict.lookup("fields") >> fieldSet_;
return true;
}
bool Foam::functionObjects::readFields::execute(const bool postProcess)
{
// Clear out any previously loaded fields
vsf_.clear();
vvf_.clear();
vSpheretf_.clear();
vSymmtf_.clear();
vtf_.clear();
ssf_.clear();
svf_.clear();
sSpheretf_.clear();
sSymmtf_.clear();
stf_.clear();
forAll(fieldSet_, fieldi)
{
const word& fieldName = fieldSet_[fieldi];
// If necessary load field
loadField<scalar>(fieldName, vsf_, ssf_);
loadField<vector>(fieldName, vvf_, svf_);
loadField<sphericalTensor>(fieldName, vSpheretf_, sSpheretf_);
loadField<symmTensor>(fieldName, vSymmtf_, sSymmtf_);
loadField<tensor>(fieldName, vtf_, stf_);
}
return true;
}
bool Foam::functionObjects::readFields::write(const bool postProcess)
{
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,179 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::readFields
Group
grpFieldFunctionObjects
Description
This function object reads fields from the time directories and adds them to
the mesh database for further post-processing.
Example of function object specification:
\verbatim
readFields1
{
type readFields;
libs ("libfieldFunctionObjects.so");
...
fields
(
U
p
);
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: readFields | yes |
fields | list of fields to read | no |
\endtable
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
SourceFiles
readFields.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_readFields_H
#define functionObjects_readFields_H
#include "fvMeshFunctionObject.H"
#include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class readFields Declaration
\*---------------------------------------------------------------------------*/
class readFields
:
public fvMeshFunctionObject
{
protected:
// Protected data
//- Fields to load
wordList fieldSet_;
//- Loaded fields
PtrList<volScalarField> vsf_;
PtrList<volVectorField> vvf_;
PtrList<volSphericalTensorField> vSpheretf_;
PtrList<volSymmTensorField> vSymmtf_;
PtrList<volTensorField> vtf_;
PtrList<surfaceScalarField> ssf_;
PtrList<surfaceVectorField> svf_;
PtrList<surfaceSphericalTensorField> sSpheretf_;
PtrList<surfaceSymmTensorField> sSymmtf_;
PtrList<surfaceTensorField> stf_;
// Protected Member Functions
template<class Type>
void loadField
(
const word&,
PtrList<GeometricField<Type, fvPatchField, volMesh>>&,
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>&
) const;
private:
// Private member functions
//- Disallow default bitwise copy construct
readFields(const readFields&);
//- Disallow default bitwise assignment
void operator=(const readFields&);
public:
//- Runtime type information
TypeName("readFields");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
readFields
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~readFields();
// Member Functions
//- Read the set of fields from dictionary
virtual bool read(const dictionary&);
//- Read the fields
virtual bool execute(const bool postProcess = false);
//- Do nothing
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "readFieldsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "readFields.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "Time.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::functionObjects::readFields::loadField
(
const word& fieldName,
PtrList<GeometricField<Type, fvPatchField, volMesh>>& vflds,
PtrList<GeometricField<Type, fvsPatchField, surfaceMesh>>& sflds
) const
{
typedef GeometricField<Type, fvPatchField, volMesh> VolFieldType;
typedef GeometricField<Type, fvsPatchField, surfaceMesh> SurfaceFieldType;
if (obr_.foundObject<VolFieldType>(fieldName))
{
DebugInfo
<< "readFields : Field " << fieldName << " already in database"
<< endl;
}
else if (obr_.foundObject<SurfaceFieldType>(fieldName))
{
DebugInfo
<< "readFields : Field " << fieldName
<< " already in database" << endl;
}
else
{
IOobject fieldHeader
(
fieldName,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
);
if
(
fieldHeader.headerOk()
&& fieldHeader.headerClassName() == VolFieldType::typeName
)
{
// Store field locally
Log << " Reading " << fieldName << endl;
label sz = vflds.size();
vflds.setSize(sz+1);
vflds.set(sz, new VolFieldType(fieldHeader, mesh_));
}
else if
(
fieldHeader.headerOk()
&& fieldHeader.headerClassName() == SurfaceFieldType::typeName
)
{
// Store field locally
Log << " Reading " << fieldName << endl;
label sz = sflds.size();
sflds.setSize(sz+1);
sflds.set(sz, new SurfaceFieldType(fieldHeader, mesh_));
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,857 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "regionSizeDistribution.H"
#include "fvcVolumeIntegrate.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(regionSizeDistribution, 0);
addToRunTimeSelectionTable
(
functionObject,
regionSizeDistribution,
dictionary
);
}
//- Plus op for FixedList<scalar>
template<class T, unsigned Size>
class ListPlusEqOp
{
public:
void operator()
(
FixedList<T, Size>& x,
const FixedList<T, Size>& y
) const
{
forAll(x, i)
{
x[i] += y[i];
}
}
};
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::functionObjects::regionSizeDistribution::writeGraph
(
const coordSet& coords,
const word& valueName,
const scalarField& values
) const
{
const wordList valNames(1, valueName);
fileName outputPath = baseTimeDir();
mkDir(outputPath);
OFstream str(outputPath/formatterPtr_().getFileName(coords, valNames));
Info<< " Writing distribution of " << valueName << " to " << str.name()
<< endl;
List<const scalarField*> valPtrs(1);
valPtrs[0] = &values;
formatterPtr_().write(coords, valNames, valPtrs, str);
}
void Foam::functionObjects::regionSizeDistribution::writeAlphaFields
(
const regionSplit& regions,
const Map<label>& patchRegions,
const Map<scalar>& regionVolume,
const volScalarField& alpha
) const
{
const scalar maxDropletVol = 1.0/6.0*pow(maxDiam_, 3);
// Split alpha field
// ~~~~~~~~~~~~~~~~~
// Split into
// - liquidCore : region connected to inlet patches
// - per region a volume : for all other regions
// - backgroundAlpha : remaining alpha
// Construct field
volScalarField liquidCore
(
IOobject
(
alphaName_ + "_liquidCore",
obr_.time().timeName(),
obr_,
IOobject::NO_READ
),
alpha,
fvPatchField<scalar>::calculatedType()
);
volScalarField backgroundAlpha
(
IOobject
(
alphaName_ + "_background",
obr_.time().timeName(),
obr_,
IOobject::NO_READ
),
alpha,
fvPatchField<scalar>::calculatedType()
);
// Knock out any cell not in patchRegions
forAll(liquidCore, celli)
{
label regionI = regions[celli];
if (patchRegions.found(regionI))
{
backgroundAlpha[celli] = 0;
}
else
{
liquidCore[celli] = 0;
scalar regionVol = regionVolume[regionI];
if (regionVol < maxDropletVol)
{
backgroundAlpha[celli] = 0;
}
}
}
liquidCore.correctBoundaryConditions();
backgroundAlpha.correctBoundaryConditions();
Info<< " Volume of liquid-core = "
<< fvc::domainIntegrate(liquidCore).value()
<< endl;
Info<< " Volume of background = "
<< fvc::domainIntegrate(backgroundAlpha).value()
<< endl;
Info<< " Writing liquid-core field to " << liquidCore.name() << endl;
liquidCore.write();
Info<< " Writing background field to " << backgroundAlpha.name() << endl;
backgroundAlpha.write();
}
Foam::Map<Foam::label>
Foam::functionObjects::regionSizeDistribution::findPatchRegions
(
const polyMesh& mesh,
const regionSplit& regions
) const
{
// Mark all regions starting at patches
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Count number of patch faces (just for initial sizing)
const labelHashSet patchIDs(mesh.boundaryMesh().patchSet(patchNames_));
label nPatchFaces = 0;
forAllConstIter(labelHashSet, patchIDs, iter)
{
nPatchFaces += mesh.boundaryMesh()[iter.key()].size();
}
Map<label> patchRegions(nPatchFaces);
forAllConstIter(labelHashSet, patchIDs, iter)
{
const polyPatch& pp = mesh.boundaryMesh()[iter.key()];
// Collect all regions on the patch
const labelList& faceCells = pp.faceCells();
forAll(faceCells, i)
{
patchRegions.insert
(
regions[faceCells[i]],
Pstream::myProcNo() // dummy value
);
}
}
// Make sure all the processors have the same set of regions
Pstream::mapCombineGather(patchRegions, minEqOp<label>());
Pstream::mapCombineScatter(patchRegions);
return patchRegions;
}
Foam::tmp<Foam::scalarField>
Foam::functionObjects::regionSizeDistribution::divide
(
const scalarField& num,
const scalarField& denom
)
{
tmp<scalarField> tresult(new scalarField(num.size()));
scalarField& result = tresult.ref();
forAll(denom, i)
{
if (denom[i] != 0)
{
result[i] = num[i]/denom[i];
}
else
{
result[i] = 0.0;
}
}
return tresult;
}
void Foam::functionObjects::regionSizeDistribution::writeGraphs
(
const word& fieldName, // name of field
const labelList& indices, // index of bin for each region
const scalarField& sortedField, // per region field data
const scalarField& binCount, // per bin number of regions
const coordSet& coords // graph data for bins
) const
{
if (Pstream::master())
{
// Calculate per-bin average
scalarField binSum(nBins_, 0.0);
forAll(sortedField, i)
{
binSum[indices[i]] += sortedField[i];
}
scalarField binAvg(divide(binSum, binCount));
// Per bin deviation
scalarField binSqrSum(nBins_, 0.0);
forAll(sortedField, i)
{
binSqrSum[indices[i]] += Foam::sqr(sortedField[i]);
}
scalarField binDev
(
sqrt(divide(binSqrSum, binCount) - Foam::sqr(binAvg))
);
// Write average
writeGraph(coords, fieldName + "_sum", binSum);
// Write average
writeGraph(coords, fieldName + "_avg", binAvg);
// Write deviation
writeGraph(coords, fieldName + "_dev", binDev);
}
}
void Foam::functionObjects::regionSizeDistribution::writeGraphs
(
const word& fieldName, // name of field
const scalarField& cellField, // per cell field data
const regionSplit& regions, // per cell the region(=droplet)
const labelList& sortedRegions, // valid regions in sorted order
const scalarField& sortedNormalisation,
const labelList& indices, // per region index of bin
const scalarField& binCount, // per bin number of regions
const coordSet& coords // graph data for bins
) const
{
// Sum on a per-region basis. Parallel reduced.
Map<scalar> regionField(regionSum(regions, cellField));
// Extract in region order
scalarField sortedField
(
sortedNormalisation
* extractData
(
sortedRegions,
regionField
)
);
writeGraphs
(
fieldName, // name of field
indices, // index of bin for each region
sortedField, // per region field data
binCount, // per bin number of regions
coords // graph data for bins
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::regionSizeDistribution::regionSizeDistribution
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
writeFile(name, runTime, dict, name),
alphaName_(dict.lookup("field")),
patchNames_(dict.lookup("patches"))
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::regionSizeDistribution::~regionSizeDistribution()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::regionSizeDistribution::read(const dictionary& dict)
{
dict.lookup("field") >> alphaName_;
dict.lookup("patches") >> patchNames_;
dict.lookup("threshold") >> threshold_;
dict.lookup("maxDiameter") >> maxDiam_;
minDiam_ = 0.0;
dict.readIfPresent("minDiameter", minDiam_);
dict.lookup("nBins") >> nBins_;
dict.lookup("fields") >> fields_;
word format(dict.lookup("setFormat"));
formatterPtr_ = writer<scalar>::New(format);
if (dict.found("coordinateSystem"))
{
coordSysPtr_.reset(new coordinateSystem(obr_, dict));
Info<< "Transforming all vectorFields with coordinate system "
<< coordSysPtr_().name() << endl;
}
return true;
}
bool Foam::functionObjects::regionSizeDistribution::execute
(
const bool postProcess
)
{
return true;
}
bool Foam::functionObjects::regionSizeDistribution::write
(
const bool postProcess
)
{
Info<< type() << " " << name() << " output:" << nl;
const fvMesh& mesh = refCast<const fvMesh>(obr_);
autoPtr<volScalarField> alphaPtr;
if (obr_.foundObject<volScalarField>(alphaName_))
{
Info<< " Looking up field " << alphaName_ << endl;
}
else
{
Info<< " Reading field " << alphaName_ << endl;
alphaPtr.reset
(
new volScalarField
(
IOobject
(
alphaName_,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh
)
);
}
const volScalarField& alpha =
(
alphaPtr.valid()
? alphaPtr()
: obr_.lookupObject<volScalarField>(alphaName_)
);
Info<< " Volume of alpha = "
<< fvc::domainIntegrate(alpha).value()
<< endl;
const scalar meshVol = gSum(mesh.V());
const scalar maxDropletVol = 1.0/6.0*pow(maxDiam_, 3);
const scalar delta = (maxDiam_-minDiam_)/nBins_;
Info<< " Mesh volume = " << meshVol << endl;
Info<< " Maximum droplet diameter = " << maxDiam_ << endl;
Info<< " Maximum droplet volume = " << maxDropletVol << endl;
// Determine blocked faces
boolList blockedFace(mesh.nFaces(), false);
label nBlocked = 0;
{
for (label facei = 0; facei < mesh.nInternalFaces(); facei++)
{
scalar ownVal = alpha[mesh.faceOwner()[facei]];
scalar neiVal = alpha[mesh.faceNeighbour()[facei]];
if
(
(ownVal < threshold_ && neiVal > threshold_)
|| (ownVal > threshold_ && neiVal < threshold_)
)
{
blockedFace[facei] = true;
nBlocked++;
}
}
// Block coupled faces
forAll(alpha.boundaryField(), patchi)
{
const fvPatchScalarField& fvp = alpha.boundaryField()[patchi];
if (fvp.coupled())
{
tmp<scalarField> townFld(fvp.patchInternalField());
const scalarField& ownFld = townFld();
tmp<scalarField> tnbrFld(fvp.patchNeighbourField());
const scalarField& nbrFld = tnbrFld();
label start = fvp.patch().patch().start();
forAll(ownFld, i)
{
scalar ownVal = ownFld[i];
scalar neiVal = nbrFld[i];
if
(
(ownVal < threshold_ && neiVal > threshold_)
|| (ownVal > threshold_ && neiVal < threshold_)
)
{
blockedFace[start+i] = true;
nBlocked++;
}
}
}
}
}
regionSplit regions(mesh, blockedFace);
Info<< " Determined " << regions.nRegions()
<< " disconnected regions" << endl;
if (debug)
{
volScalarField region
(
IOobject
(
"region",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh,
dimensionedScalar("zero", dimless, 0)
);
Info<< " Dumping region as volScalarField to " << region.name()
<< endl;
forAll(regions, celli)
{
region[celli] = regions[celli];
}
region.correctBoundaryConditions();
region.write();
}
// Determine regions connected to supplied patches
Map<label> patchRegions(findPatchRegions(mesh, regions));
// Sum all regions
const scalarField alphaVol(alpha.primitiveField()*mesh.V());
Map<scalar> allRegionVolume(regionSum(regions, mesh.V()));
Map<scalar> allRegionAlphaVolume(regionSum(regions, alphaVol));
Map<label> allRegionNumCells
(
regionSum
(
regions,
labelField(mesh.nCells(), 1.0)
)
);
if (debug)
{
Info<< " " << token::TAB << "Region"
<< token::TAB << "Volume(mesh)"
<< token::TAB << "Volume(" << alpha.name() << "):"
<< token::TAB << "nCells"
<< endl;
scalar meshSumVol = 0.0;
scalar alphaSumVol = 0.0;
label nCells = 0;
Map<scalar>::const_iterator vIter = allRegionVolume.begin();
Map<scalar>::const_iterator aIter = allRegionAlphaVolume.begin();
Map<label>::const_iterator numIter = allRegionNumCells.begin();
for
(
;
vIter != allRegionVolume.end()
&& aIter != allRegionAlphaVolume.end();
++vIter, ++aIter, ++numIter
)
{
Info<< " " << token::TAB << vIter.key()
<< token::TAB << vIter()
<< token::TAB << aIter()
<< token::TAB << numIter()
<< endl;
meshSumVol += vIter();
alphaSumVol += aIter();
nCells += numIter();
}
Info<< " " << token::TAB << "Total:"
<< token::TAB << meshSumVol
<< token::TAB << alphaSumVol
<< token::TAB << nCells
<< endl;
Info<< endl;
}
{
Info<< " Patch connected regions (liquid core):" << endl;
Info<< token::TAB << " Region"
<< token::TAB << "Volume(mesh)"
<< token::TAB << "Volume(" << alpha.name() << "):"
<< endl;
forAllConstIter(Map<label>, patchRegions, iter)
{
label regionI = iter.key();
Info<< " " << token::TAB << iter.key()
<< token::TAB << allRegionVolume[regionI]
<< token::TAB << allRegionAlphaVolume[regionI] << endl;
}
Info<< endl;
}
{
Info<< " Background regions:" << endl;
Info<< " " << token::TAB << "Region"
<< token::TAB << "Volume(mesh)"
<< token::TAB << "Volume(" << alpha.name() << "):"
<< endl;
Map<scalar>::const_iterator vIter = allRegionVolume.begin();
Map<scalar>::const_iterator aIter = allRegionAlphaVolume.begin();
for
(
;
vIter != allRegionVolume.end()
&& aIter != allRegionAlphaVolume.end();
++vIter, ++aIter
)
{
if
(
!patchRegions.found(vIter.key())
&& vIter() >= maxDropletVol
)
{
Info<< " " << token::TAB << vIter.key()
<< token::TAB << vIter()
<< token::TAB << aIter() << endl;
}
}
Info<< endl;
}
// Split alpha field
// ~~~~~~~~~~~~~~~~~
// Split into
// - liquidCore : region connected to inlet patches
// - per region a volume : for all other regions
// - backgroundAlpha : remaining alpha
writeAlphaFields(regions, patchRegions, allRegionVolume, alpha);
// Extract droplet-only allRegionVolume, i.e. delete liquid core
// (patchRegions) and background regions from maps.
// Note that we have to use mesh volume (allRegionVolume) and not
// allRegionAlphaVolume since background might not have alpha in it.
forAllIter(Map<scalar>, allRegionVolume, vIter)
{
label regionI = vIter.key();
if
(
patchRegions.found(regionI)
|| vIter() >= maxDropletVol
)
{
allRegionVolume.erase(vIter);
allRegionAlphaVolume.erase(regionI);
allRegionNumCells.erase(regionI);
}
}
if (allRegionVolume.size())
{
// Construct mids of bins for plotting
pointField xBin(nBins_);
scalar x = 0.5*delta;
forAll(xBin, i)
{
xBin[i] = point(x, 0, 0);
x += delta;
}
const coordSet coords("diameter", "x", xBin, mag(xBin));
// Get in region order the alpha*volume and diameter
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const labelList sortedRegions = allRegionAlphaVolume.sortedToc();
scalarField sortedVols
(
extractData
(
sortedRegions,
allRegionAlphaVolume
)
);
// Calculate the diameters
scalarField sortedDiameters(sortedVols.size());
forAll(sortedDiameters, i)
{
sortedDiameters[i] = Foam::cbrt
(
sortedVols[i]
*6/constant::mathematical::pi
);
}
// Determine the bin index for all the diameters
labelList indices(sortedDiameters.size());
forAll(sortedDiameters, i)
{
indices[i] = (sortedDiameters[i]-minDiam_)/delta;
}
// Calculate the counts per diameter bin
scalarField binCount(nBins_, 0.0);
forAll(sortedDiameters, i)
{
binCount[indices[i]] += 1.0;
}
// Write counts
if (Pstream::master())
{
writeGraph(coords, "count", binCount);
}
// Write to screen
{
Info<< " Bins:" << endl;
Info<< " " << token::TAB << "Bin"
<< token::TAB << "Min diameter"
<< token::TAB << "Count:"
<< endl;
scalar diam = 0.0;
forAll(binCount, binI)
{
Info<< " " << token::TAB << binI
<< token::TAB << diam
<< token::TAB << binCount[binI] << endl;
diam += delta;
}
Info<< endl;
}
// Write average and deviation of droplet volume.
writeGraphs
(
"volume", // name of field
indices, // per region the bin index
sortedVols, // per region field data
binCount, // per bin number of regions
coords // graph data for bins
);
// Collect some more field
{
wordList scalarNames(obr_.names(volScalarField::typeName));
labelList selected = findStrings(fields_, scalarNames);
forAll(selected, i)
{
const word& fldName = scalarNames[selected[i]];
Info<< " Scalar field " << fldName << endl;
const scalarField& fld = obr_.lookupObject
<
volScalarField
>(fldName).primitiveField();
writeGraphs
(
fldName, // name of field
alphaVol*fld, // per cell field data
regions, // per cell the region(=droplet)
sortedRegions, // valid regions in sorted order
1.0/sortedVols, // per region normalisation
indices, // index of bin for each region
binCount, // per bin number of regions
coords // graph data for bins
);
}
}
{
wordList vectorNames(obr_.names(volVectorField::typeName));
labelList selected = findStrings(fields_, vectorNames);
forAll(selected, i)
{
const word& fldName = vectorNames[selected[i]];
Info<< " Vector field " << fldName << endl;
vectorField fld = obr_.lookupObject
<
volVectorField
>(fldName).primitiveField();
if (coordSysPtr_.valid())
{
Info<< "Transforming vector field " << fldName
<< " with coordinate system "
<< coordSysPtr_().name()
<< endl;
fld = coordSysPtr_().localVector(fld);
}
// Components
for (direction cmp = 0; cmp < vector::nComponents; cmp++)
{
writeGraphs
(
fldName + vector::componentNames[cmp],
alphaVol*fld.component(cmp),// per cell field data
regions, // per cell the region(=droplet)
sortedRegions, // valid regions in sorted order
1.0/sortedVols, // per region normalisation
indices, // index of bin for each region
binCount, // per bin number of regions
coords // graph data for bins
);
}
// Magnitude
writeGraphs
(
fldName + "mag", // name of field
alphaVol*mag(fld), // per cell field data
regions, // per cell the region(=droplet)
sortedRegions, // valid regions in sorted order
1.0/sortedVols, // per region normalisation
indices, // index of bin for each region
binCount, // per bin number of regions
coords // graph data for bins
);
}
}
}
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,281 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::regionSizeDistribution
Group
grpFieldFunctionObjects
Description
This function object creates a size distribution via interrogating a
continuous phase fraction field.
Looks up a phase-fraction (alpha) field and splits the mesh into regions
based on where the field is below the threshold value. These
regions ("droplets") can now be analysed.
Regions:
- print the regions connected to a user-defined set of patches.
(in spray calculation these form the liquid core)
- print the regions with too large volume. These are the 'background'
regions.
- (debug) write regions as a volScalarField
- (debug) print for all regions the sum of volume and alpha*volume
Output (volume scalar) fields include:
- alpha_liquidCore : alpha with outside liquid core set to 0
- alpha_background : alpha with outside background set to 0.
%Histogram:
- determine histogram of diameter (given minDiameter, maxDiameter, nBins)
- write graph of number of droplets per bin
- write graph of sum, average and deviation of droplet volume per bin
- write graph of sum, average and deviation of user-defined fields. For
volVectorFields these are those of the 3 components and the magnitude.
Example of function object specification:
\verbatim
regionSizeDistribution1
{
type regionSizeDistribution;
libs ("libfieldFunctionObjects.so");
...
field alpha;
patches (inlet);
threshold 0.4;
fields (p U);
nBins 100;
maxDiameter 0.5e-4;
minDiameter 0;
setFormat gnuplot;
coordinateSystem
{
type cartesian;
origin (0 0 0);
e3 (0 1 1);
e1 (1 0 0);
}
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: regionSizeDistribution |yes|
field | phase field to interrogate | yes |
patches | patches from which the liquid core is identified | yes|
threshold | phase fraction applied to delimit regions | yes |
fields | fields to sample | yes |
nBins | number of bins for histogram | yes |
maxDiameter | maximum region equivalent diameter | yes |
minDiameter | minimum region equivalent diameter | no | 0
setFormat | writing format | yes |
coordinateSystem | transformation for vector fields | no |
\endtable
SeeAlso
Foam::functionObject
Foam::functionObjects::writeFile
SourceFiles
regionSizeDistribution.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_regionSizeDistribution_H
#define functionObjects_regionSizeDistribution_H
#include "writeFile.H"
#include "writer.H"
#include "Map.H"
#include "volFieldsFwd.H"
#include "wordReList.H"
#include "coordinateSystem.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class regionSplit;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class regionSizeDistribution Declaration
\*---------------------------------------------------------------------------*/
class regionSizeDistribution
:
public writeFile
{
// Private data
//- Name of field
word alphaName_;
//- Patches to walk from
wordReList patchNames_;
//- Clip value
scalar threshold_;
//- Maximum droplet diameter
scalar maxDiam_;
//- Minimum droplet diameter
scalar minDiam_;
//- Mumber of bins
label nBins_;
//- Names of fields to sample on regions
wordReList fields_;
//- Output formatter to write
autoPtr<writer<scalar>> formatterPtr_;
//- Optional coordinate system
autoPtr<coordinateSystem> coordSysPtr_;
// Private Member Functions
template<class Type>
Map<Type> regionSum(const regionSplit&, const Field<Type>&) const;
//- Get data in order
template<class Type>
List<Type> extractData(const UList<label>& keys, const Map<Type>&)
const;
void writeGraph
(
const coordSet& coords,
const word& valueName,
const scalarField& values
) const;
//- Write volfields with the parts of alpha which are not
// droplets (liquidCore, backGround)
void writeAlphaFields
(
const regionSplit& regions,
const Map<label>& keepRegions,
const Map<scalar>& regionVolume,
const volScalarField& alpha
) const;
//- Mark all regions starting at patches
Map<label> findPatchRegions(const polyMesh&, const regionSplit&) const;
//- Helper: divide if denom != 0
static tmp<scalarField> divide(const scalarField&, const scalarField&);
//- Given per-region data calculate per-bin average/deviation and graph
void writeGraphs
(
const word& fieldName, // name of field
const labelList& indices, // index of bin for each region
const scalarField& sortedField, // per region field data
const scalarField& binCount, // per bin number of regions
const coordSet& coords // graph data for bins
) const;
//- Given per-cell data calculate per-bin average/deviation and graph
void writeGraphs
(
const word& fieldName, // name of field
const scalarField& cellField, // per cell field data
const regionSplit& regions, // per cell the region(=droplet)
const labelList& sortedRegions, // valid regions in sorted order
const scalarField& sortedNormalisation,
const labelList& indices, // index of bin for each region
const scalarField& binCount, // per bin number of regions
const coordSet& coords // graph data for bins
) const;
//- Disallow default bitwise copy construct
regionSizeDistribution(const regionSizeDistribution&);
//- Disallow default bitwise assignment
void operator=(const regionSizeDistribution&);
public:
//- Runtime type information
TypeName("regionSizeDistribution");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
regionSizeDistribution
(
const word& name,
const Time& runTime,
const dictionary&
);
// Destructor
virtual ~regionSizeDistribution();
// Member Functions
//- Read the regionSizeDistribution data
virtual bool read(const dictionary&);
//- Do nothing
virtual bool execute(const bool postProcess = false);
//- Calculate the regionSizeDistribution and write
virtual bool write(const bool postProcess = false);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "regionSizeDistributionTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,80 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "regionSizeDistribution.H"
#include "regionSplit.H"
#include "volFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::Map<Type> Foam::functionObjects::regionSizeDistribution::regionSum
(
const regionSplit& regions,
const Field<Type>& fld
) const
{
// Per region the sum of fld
Map<Type> regionToSum(regions.nRegions()/Pstream::nProcs());
forAll(fld, celli)
{
label regionI = regions[celli];
typename Map<Type>::iterator fnd = regionToSum.find(regionI);
if (fnd == regionToSum.end())
{
regionToSum.insert(regionI, fld[celli]);
}
else
{
fnd() += fld[celli];
}
}
Pstream::mapCombineGather(regionToSum, plusEqOp<Type>());
Pstream::mapCombineScatter(regionToSum);
return regionToSum;
}
template<class Type>
Foam::List<Type> Foam::functionObjects::regionSizeDistribution::extractData
(
const UList<label>& keys,
const Map<Type>& regionData
) const
{
List<Type> sortedData(keys.size());
forAll(keys, i)
{
sortedData[i] = regionData[keys[i]];
}
return sortedData;
}
// ************************************************************************* //

View File

@ -0,0 +1,103 @@
/*--------------------------------*- C++ -*----------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: dev |
| \\ / A nd | Web: www.OpenFOAM.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
application icoFoam;
startFrom startTime;
startTime 0;
stopAt endTime;
endTime 0.5;
deltaT 0.005;
writeControl timeStep;
writeInterval 20;
purgeWrite 0;
writeFormat ascii;
writePrecision 6;
writeCompression off;
timeFormat general;
timePrecision 6;
runTimeModifiable true;
functions
{
streamLines
{
type streamLine;
// Where to load it from (if not already in solver)
libs ("libfieldFunctionObjects.so");
// Output every
writeControl writeTime;
// writeInterval 10;
setFormat vtk; //gnuplot, raw etc. See sampleDict.
// Interpolation method. Default is cellPoint. See sampleDict.
//interpolationScheme pointMVC;
// Tracked forwards (+U) or backwards (-U)
trackForward true;
// Names of fields to sample. Should contain above velocity field!
fields (p U);
// Steps particles can travel before being removed
lifeTime 10000;
//- Specify either absolute length of steps (trackLength) or a number
// of subcycling steps per cell (nSubCycle)
// Size of single track segment [m]
//trackLength 1e-3;
// Number of steps per cell (estimate). Set to 1 to disable
// subcycling.
nSubCycle 5;
// Cloud name to use
cloudName particleTracks;
// Seeding method. See the sampleSets in sampleDict.
seedSampleSet uniform; //cloud;//triSurfaceMeshPointSet;
uniformCoeffs
{
type uniform;
axis x; //distance;
start (-0.0205 0.0001 0.00001);
end (-0.0205 0.0005 0.00001);
nPoints 100;
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,698 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "Pstream.H"
#include "functionObjectList.H"
#include "streamLine.H"
#include "fvMesh.H"
#include "streamLineParticleCloud.H"
#include "ReadFields.H"
#include "meshSearch.H"
#include "sampledSet.H"
#include "globalIndex.H"
#include "mapDistribute.H"
#include "interpolationCellPoint.H"
#include "PatchTools.H"
#include "mapPolyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(streamLine, 0);
addToRunTimeSelectionTable(functionObject, streamLine, dictionary);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::autoPtr<Foam::indirectPrimitivePatch>
Foam::functionObjects::streamLine::wallPatch() const
{
const fvMesh& mesh = dynamic_cast<const fvMesh&>(obr_);
const polyBoundaryMesh& patches = mesh.boundaryMesh();
label nFaces = 0;
forAll(patches, patchi)
{
if (isA<wallPolyPatch>(patches[patchi]))
{
nFaces += patches[patchi].size();
}
}
labelList addressing(nFaces);
nFaces = 0;
forAll(patches, patchi)
{
if (isA<wallPolyPatch>(patches[patchi]))
{
const polyPatch& pp = patches[patchi];
forAll(pp, i)
{
addressing[nFaces++] = pp.start()+i;
}
}
}
return autoPtr<indirectPrimitivePatch>
(
new indirectPrimitivePatch
(
IndirectList<face>
(
mesh.faces(),
addressing
),
mesh.points()
)
);
}
void Foam::functionObjects::streamLine::track()
{
const fvMesh& mesh = dynamic_cast<const fvMesh&>(obr_);
IDLList<streamLineParticle> initialParticles;
streamLineParticleCloud particles
(
mesh,
cloudName_,
initialParticles
);
const sampledSet& seedPoints = sampledSetPtr_();
forAll(seedPoints, i)
{
particles.addParticle
(
new streamLineParticle
(
mesh,
seedPoints[i],
seedPoints.cells()[i],
lifeTime_
)
);
}
label nSeeds = returnReduce(particles.size(), sumOp<label>());
Info << " seeded " << nSeeds << " particles" << endl;
// Read or lookup fields
PtrList<volScalarField> vsFlds;
PtrList<interpolation<scalar>> vsInterp;
PtrList<volVectorField> vvFlds;
PtrList<interpolation<vector>> vvInterp;
label UIndex = -1;
label nScalar = 0;
label nVector = 0;
forAll(fields_, i)
{
if (mesh.foundObject<volScalarField>(fields_[i]))
{
nScalar++;
}
else if (mesh.foundObject<volVectorField>(fields_[i]))
{
nVector++;
}
else
{
FatalErrorInFunction
<< "Cannot find field " << fields_[i] << nl
<< "Valid scalar fields are:"
<< mesh.names(volScalarField::typeName) << nl
<< "Valid vector fields are:"
<< mesh.names(volVectorField::typeName)
<< exit(FatalError);
}
}
vsInterp.setSize(nScalar);
nScalar = 0;
vvInterp.setSize(nVector);
nVector = 0;
forAll(fields_, i)
{
if (mesh.foundObject<volScalarField>(fields_[i]))
{
const volScalarField& f = mesh.lookupObject<volScalarField>
(
fields_[i]
);
vsInterp.set
(
nScalar++,
interpolation<scalar>::New
(
interpolationScheme_,
f
)
);
}
else if (mesh.foundObject<volVectorField>(fields_[i]))
{
const volVectorField& f = mesh.lookupObject<volVectorField>
(
fields_[i]
);
if (f.name() == UName_)
{
UIndex = nVector;
}
vvInterp.set
(
nVector++,
interpolation<vector>::New
(
interpolationScheme_,
f
)
);
}
}
// Store the names
scalarNames_.setSize(vsInterp.size());
forAll(vsInterp, i)
{
scalarNames_[i] = vsInterp[i].psi().name();
}
vectorNames_.setSize(vvInterp.size());
forAll(vvInterp, i)
{
vectorNames_[i] = vvInterp[i].psi().name();
}
// Check that we know the index of U in the interpolators.
if (UIndex == -1)
{
FatalErrorInFunction
<< "Cannot find field to move particles with : " << UName_ << nl
<< "This field has to be present in the sampled fields " << fields_
<< " and in the objectRegistry."
<< exit(FatalError);
}
// Sampled data
// ~~~~~~~~~~~~
// Size to maximum expected sizes.
allTracks_.clear();
allTracks_.setCapacity(nSeeds);
allScalars_.setSize(vsInterp.size());
forAll(allScalars_, i)
{
allScalars_[i].clear();
allScalars_[i].setCapacity(nSeeds);
}
allVectors_.setSize(vvInterp.size());
forAll(allVectors_, i)
{
allVectors_[i].clear();
allVectors_[i].setCapacity(nSeeds);
}
// Additional particle info
streamLineParticle::trackingData td
(
particles,
vsInterp,
vvInterp,
UIndex, // index of U in vvInterp
trackForward_, // track in +u direction?
nSubCycle_, // automatic track control:step through cells in steps?
trackLength_, // fixed track length
allTracks_,
allScalars_,
allVectors_
);
// Set very large dt. Note: cannot use GREAT since 1/GREAT is SMALL
// which is a trigger value for the tracking...
const scalar trackTime = Foam::sqrt(GREAT);
// Track
particles.move(td, trackTime);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::streamLine::streamLine
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
functionObject(name),
obr_
(
runTime.lookupObject<objectRegistry>
(
dict.lookupOrDefault("region", polyMesh::defaultRegion)
)
),
dict_(dict),
nSubCycle_(0)
{
if (!isA<fvMesh>(obr_))
{
FatalErrorInFunction
<< "objectRegistry is not an fvMesh" << exit(FatalError);
}
read(dict_);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::streamLine::~streamLine()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::streamLine::read(const dictionary& dict)
{
Info<< type() << " " << name() << ":" << nl;
dict.lookup("fields") >> fields_;
if (dict.found("U"))
{
dict.lookup("U") >> UName_;
}
else
{
UName_ = "U";
if (dict.found("U"))
{
IOWarningInFunction(dict)
<< "Using deprecated entry \"U\"."
<< " Please use \"UName\" instead."
<< endl;
dict.lookup("U") >> UName_;
}
}
if (findIndex(fields_, UName_) == -1)
{
FatalIOErrorInFunction(dict)
<< "Velocity field for tracking " << UName_
<< " should be present in the list of fields " << fields_
<< exit(FatalIOError);
}
dict.lookup("trackForward") >> trackForward_;
dict.lookup("lifeTime") >> lifeTime_;
if (lifeTime_ < 1)
{
FatalErrorInFunction
<< "Illegal value " << lifeTime_ << " for lifeTime"
<< exit(FatalError);
}
bool subCycling = dict.found("nSubCycle");
bool fixedLength = dict.found("trackLength");
if (subCycling && fixedLength)
{
FatalIOErrorInFunction(dict)
<< "Cannot both specify automatic time stepping (through '"
<< "nSubCycle' specification) and fixed track length (through '"
<< "trackLength')"
<< exit(FatalIOError);
}
nSubCycle_ = 1;
if (dict.readIfPresent("nSubCycle", nSubCycle_))
{
trackLength_ = VGREAT;
if (nSubCycle_ < 1)
{
nSubCycle_ = 1;
}
Info<< " automatic track length specified through"
<< " number of sub cycles : " << nSubCycle_ << nl << endl;
}
else
{
dict.lookup("trackLength") >> trackLength_;
Info<< " fixed track length specified : "
<< trackLength_ << nl << endl;
}
interpolationScheme_ = dict.lookupOrDefault
(
"interpolationScheme",
interpolationCellPoint<scalar>::typeName
);
cloudName_ = dict.lookupOrDefault<word>("cloudName", "streamLine");
dict.lookup("seedSampleSet") >> seedSet_;
const fvMesh& mesh = dynamic_cast<const fvMesh&>(obr_);
meshSearchPtr_.reset(new meshSearch(mesh));
const dictionary& coeffsDict = dict.subDict(seedSet_ + "Coeffs");
sampledSetPtr_ = sampledSet::New
(
seedSet_,
mesh,
meshSearchPtr_(),
coeffsDict
);
coeffsDict.lookup("axis") >> sampledSetAxis_;
scalarFormatterPtr_ = writer<scalar>::New(dict.lookup("setFormat"));
vectorFormatterPtr_ = writer<vector>::New(dict.lookup("setFormat"));
return true;
}
bool Foam::functionObjects::streamLine::execute(const bool postProcess)
{
return true;
}
bool Foam::functionObjects::streamLine::write(const bool postProcess)
{
Info<< type() << " " << name() << " output:" << nl;
const Time& runTime = obr_.time();
const fvMesh& mesh = dynamic_cast<const fvMesh&>(obr_);
// Do all injection and tracking
track();
if (Pstream::parRun())
{
// Append slave tracks to master ones
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
globalIndex globalTrackIDs(allTracks_.size());
// Construct a distribution map to pull all to the master.
labelListList sendMap(Pstream::nProcs());
labelListList recvMap(Pstream::nProcs());
if (Pstream::master())
{
// Master: receive all. My own first, then consecutive
// processors.
label trackI = 0;
forAll(recvMap, proci)
{
labelList& fromProc = recvMap[proci];
fromProc.setSize(globalTrackIDs.localSize(proci));
forAll(fromProc, i)
{
fromProc[i] = trackI++;
}
}
}
labelList& toMaster = sendMap[0];
toMaster.setSize(globalTrackIDs.localSize());
forAll(toMaster, i)
{
toMaster[i] = i;
}
const mapDistribute distMap
(
globalTrackIDs.size(),
sendMap.xfer(),
recvMap.xfer()
);
// Distribute the track positions. Note: use scheduled comms
// to prevent buffering.
mapDistributeBase::distribute
(
Pstream::scheduled,
distMap.schedule(),
distMap.constructSize(),
distMap.subMap(),
false,
distMap.constructMap(),
false,
allTracks_,
flipOp()
);
// Distribute the scalars
forAll(allScalars_, scalarI)
{
allScalars_[scalarI].shrink();
mapDistributeBase::distribute
(
Pstream::scheduled,
distMap.schedule(),
distMap.constructSize(),
distMap.subMap(),
false,
distMap.constructMap(),
false,
allScalars_[scalarI],
flipOp()
);
allScalars_[scalarI].setCapacity(allScalars_[scalarI].size());
}
// Distribute the vectors
forAll(allVectors_, vectorI)
{
allVectors_[vectorI].shrink();
mapDistributeBase::distribute
(
Pstream::scheduled,
distMap.schedule(),
distMap.constructSize(),
distMap.subMap(),
false,
distMap.constructMap(),
false,
allVectors_[vectorI],
flipOp()
);
allVectors_[vectorI].setCapacity(allVectors_[vectorI].size());
}
}
label n = 0;
forAll(allTracks_, trackI)
{
n += allTracks_[trackI].size();
}
Info<< " Tracks:" << allTracks_.size() << nl
<< " Total samples:" << n
<< endl;
// Massage into form suitable for writers
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (Pstream::master() && allTracks_.size())
{
// Make output directory
fileName vtkPath
(
Pstream::parRun()
? runTime.path()/".."/"postProcessing"/"sets"/name()
: runTime.path()/"postProcessing"/"sets"/name()
);
if (mesh.name() != fvMesh::defaultRegion)
{
vtkPath = vtkPath/mesh.name();
}
vtkPath = vtkPath/mesh.time().timeName();
mkDir(vtkPath);
// Convert track positions
PtrList<coordSet> tracks(allTracks_.size());
forAll(allTracks_, trackI)
{
tracks.set
(
trackI,
new coordSet
(
"track" + Foam::name(trackI),
sampledSetAxis_ //"xyz"
)
);
tracks[trackI].transfer(allTracks_[trackI]);
}
// Convert scalar values
if (allScalars_.size() > 0)
{
List<List<scalarField>> scalarValues(allScalars_.size());
forAll(allScalars_, scalarI)
{
DynamicList<scalarList>& allTrackVals =
allScalars_[scalarI];
scalarValues[scalarI].setSize(allTrackVals.size());
forAll(allTrackVals, trackI)
{
scalarList& trackVals = allTrackVals[trackI];
scalarValues[scalarI][trackI].transfer(trackVals);
}
}
fileName vtkFile
(
vtkPath
/ scalarFormatterPtr_().getFileName
(
tracks[0],
scalarNames_
)
);
Info<< " Writing data to " << vtkFile.path() << endl;
scalarFormatterPtr_().write
(
true, // writeTracks
tracks,
scalarNames_,
scalarValues,
OFstream(vtkFile)()
);
}
// Convert vector values
if (allVectors_.size() > 0)
{
List<List<vectorField>> vectorValues(allVectors_.size());
forAll(allVectors_, vectorI)
{
DynamicList<vectorList>& allTrackVals =
allVectors_[vectorI];
vectorValues[vectorI].setSize(allTrackVals.size());
forAll(allTrackVals, trackI)
{
vectorList& trackVals = allTrackVals[trackI];
vectorValues[vectorI][trackI].transfer(trackVals);
}
}
fileName vtkFile
(
vtkPath
/ vectorFormatterPtr_().getFileName
(
tracks[0],
vectorNames_
)
);
vectorFormatterPtr_().write
(
true, // writeTracks
tracks,
vectorNames_,
vectorValues,
OFstream(vtkFile)()
);
}
}
return true;
}
void Foam::functionObjects::streamLine::updateMesh(const mapPolyMesh& mpm)
{
const fvMesh& mesh_ = dynamic_cast<const fvMesh&>(obr_);
if (&mpm.mesh() == &mesh_)
{
read(dict_);
}
}
void Foam::functionObjects::streamLine::movePoints(const polyMesh& mesh)
{
const fvMesh& mesh_ = dynamic_cast<const fvMesh&>(obr_);
if (&mesh == &mesh_)
{
// Moving mesh affects the search tree
read(dict_);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,268 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::streamLine
Group
grpFieldFunctionObjects
Description
This function object generates streamline data by sampling a set of
user-specified fields along a particle track, transported by a
user-specified velocity field.
Example of function object specification:
\verbatim
streamLine1
{
type streamLine;
libs ("libfieldFunctionObjects.so");
...
setFormat vtk;
trackForward yes;
fields
(
U
p
);
lifeTime 10000;
trackLength 1e-3;
nSubCycle 5;
cloudName particleTracks;
seedSampleSet uniform;
uniformCoeffs
{
type uniform;
axis x; //distance;
start (-0.0205 0.0001 0.00001);
end (-0.0205 0.0005 0.00001);
nPoints 100;
}
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | Type name: streamLine | yes |
setFormat | Output data type | yes |
U | Tracking velocity field name | yes |
fields | Fields to sample | yes |
lifetime | Maximum number of particle tracking steps | yes |
trackLength | Tracking segment length | no |
nSubCycle | Number of tracking steps per cell | no|
cloudName | Cloud name to use | yes |
seedSampleSet| Seeding method (see below)| yes |
\endtable
\linebreak
Where \c seedSampleSet is typically one of
\plaintable
uniform | uniform particle seeding
cloud | cloud of points
triSurfaceMeshPointSet | points according to a tri-surface mesh
\endplaintable
Note
When specifying the track resolution, the \c trackLength OR \c nSubCycle
option should be used
SeeAlso
Foam::functionObject
Foam::functionObjects::timeControl
Foam::sampledSet
Foam::wallBoundedStreamLine
SourceFiles
streamLine.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_streamLine_H
#define functionObjects_streamLine_H
#include "functionObject.H"
#include "volFieldsFwd.H"
#include "DynamicList.H"
#include "scalarList.H"
#include "vectorList.H"
#include "writer.H"
#include "indirectPrimitivePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class meshSearch;
class sampledSet;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class streamLine Declaration
\*---------------------------------------------------------------------------*/
class streamLine
:
public functionObject
{
// Private data
//- Database this class is registered to
const objectRegistry& obr_;
//- Input dictionary
dictionary dict_;
//- List of fields to sample
wordList fields_;
//- Field to transport particle with
word UName_;
//- Interpolation scheme to use
word interpolationScheme_;
//- Whether to use +u or -u
bool trackForward_;
//- Maximum lifetime (= number of cells) of particle
label lifeTime_;
//- Number of subcycling steps
label nSubCycle_;
//- Track length
scalar trackLength_;
//- Optional specified name of particles
word cloudName_;
//- Type of seed
word seedSet_;
//- Names of scalar fields
wordList scalarNames_;
//- Names of vector fields
wordList vectorNames_;
// Demand driven
//- Mesh searching enigne
autoPtr<meshSearch> meshSearchPtr_;
//- Seed set engine
autoPtr<sampledSet> sampledSetPtr_;
//- Axis of the sampled points to output
word sampledSetAxis_;
//- File writer for scalar data
autoPtr<writer<scalar>> scalarFormatterPtr_;
//- File writer for vector data
autoPtr<writer<vector>> vectorFormatterPtr_;
// Generated data
//- All tracks. Per particle the points it passed through
DynamicList<List<point>> allTracks_;
//- Per scalarField, per particle, the sampled value.
List<DynamicList<scalarList>> allScalars_;
//- Per scalarField, per particle, the sampled value.
List<DynamicList<vectorList>> allVectors_;
//- Construct patch out of all wall patch faces
autoPtr<indirectPrimitivePatch> wallPatch() const;
//- Do all seeding and tracking
void track();
//- Disallow default bitwise copy construct
streamLine(const streamLine&);
//- Disallow default bitwise assignment
void operator=(const streamLine&);
public:
//- Runtime type information
TypeName("streamLine");
// Constructors
//- Construct from Time and dictionary
streamLine
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~streamLine();
// Member Functions
//- Read the field average data
virtual bool read(const dictionary&);
//- Do nothing
virtual bool execute(const bool postProcess = false);
//- Calculate and write the steamlines
virtual bool write(const bool postProcess = false);
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&);
//- Update for mesh point-motion
virtual void movePoints(const polyMesh&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace functionObjects
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,507 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "streamLineParticle.H"
#include "vectorFieldIOField.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// defineParticleTypeNameAndDebug(streamLineParticle, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::scalar Foam::streamLineParticle::calcSubCycleDeltaT
(
trackingData& td,
const scalar dt,
const vector& U
) const
{
particle testParticle(*this);
bool oldKeepParticle = td.keepParticle;
bool oldSwitchProcessor = td.switchProcessor;
scalar fraction = testParticle.trackToFace(position()+dt*U, td);
td.keepParticle = oldKeepParticle;
td.switchProcessor = oldSwitchProcessor;
// Adapt the dt to subdivide the trajectory into substeps.
return dt*fraction/td.nSubCycle_;
}
Foam::vector Foam::streamLineParticle::interpolateFields
(
const trackingData& td,
const point& position,
const label celli,
const label facei
)
{
if (celli == -1)
{
FatalErrorInFunction
<< "Cell:" << celli << abort(FatalError);
}
sampledScalars_.setSize(td.vsInterp_.size());
forAll(td.vsInterp_, scalarI)
{
sampledScalars_[scalarI].append
(
td.vsInterp_[scalarI].interpolate
(
position,
celli,
facei
)
);
}
sampledVectors_.setSize(td.vvInterp_.size());
forAll(td.vvInterp_, vectorI)
{
sampledVectors_[vectorI].append
(
td.vvInterp_[vectorI].interpolate
(
position,
celli,
facei
)
);
}
const DynamicList<vector>& U = sampledVectors_[td.UIndex_];
return U.last();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::streamLineParticle::streamLineParticle
(
const polyMesh& mesh,
const vector& position,
const label celli,
const label lifeTime
)
:
particle(mesh, position, celli),
lifeTime_(lifeTime)
{}
Foam::streamLineParticle::streamLineParticle
(
const polyMesh& mesh,
Istream& is,
bool readFields
)
:
particle(mesh, is, readFields)
{
if (readFields)
{
//if (is.format() == IOstream::ASCII)
List<scalarList> sampledScalars;
List<vectorList> sampledVectors;
is >> lifeTime_ >> sampledPositions_ >> sampledScalars
>> sampledVectors;
sampledScalars_.setSize(sampledScalars.size());
forAll(sampledScalars, i)
{
sampledScalars_[i].transfer(sampledScalars[i]);
}
sampledVectors_.setSize(sampledVectors.size());
forAll(sampledVectors, i)
{
sampledVectors_[i].transfer(sampledVectors[i]);
}
}
// Check state of Istream
is.check
(
"streamLineParticle::streamLineParticle"
"(const Cloud<streamLineParticle>&, Istream&, bool)"
);
}
Foam::streamLineParticle::streamLineParticle
(
const streamLineParticle& p
)
:
particle(p),
lifeTime_(p.lifeTime_),
sampledPositions_(p.sampledPositions_),
sampledScalars_(p.sampledScalars_)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::streamLineParticle::move
(
trackingData& td,
const scalar trackTime
)
{
streamLineParticle& p = static_cast<streamLineParticle&>(*this);
td.switchProcessor = false;
td.keepParticle = true;
scalar tEnd = (1.0 - stepFraction())*trackTime;
scalar maxDt = mesh_.bounds().mag();
while
(
td.keepParticle
&& !td.switchProcessor
&& lifeTime_ > 0
)
{
// set the lagrangian time-step
scalar dt = maxDt;
// Cross cell in steps:
// - at subiter 0 calculate dt to cross cell in nSubCycle steps
// - at the last subiter do all of the remaining track
for (label subIter = 0; subIter < td.nSubCycle_; subIter++)
{
--lifeTime_;
// Store current position and sampled velocity.
sampledPositions_.append(position());
vector U = interpolateFields(td, position(), cell(), face());
if (!td.trackForward_)
{
U = -U;
}
scalar magU = mag(U);
if (magU < SMALL)
{
// Stagnant particle. Might as well stop
lifeTime_ = 0;
break;
}
U /= magU;
if (td.trackLength_ < GREAT)
{
dt = td.trackLength_;
//Pout<< " subiteration " << subIter
// << " : fixed length: updated dt:" << dt << endl;
}
else if (subIter == 0 && td.nSubCycle_ > 1)
{
// Adapt dt to cross cell in a few steps
dt = calcSubCycleDeltaT(td, dt, U);
}
else if (subIter == td.nSubCycle_ - 1)
{
// Do full step on last subcycle
dt = maxDt;
}
scalar fraction = trackToFace(position() + dt*U, td);
dt *= fraction;
tEnd -= dt;
stepFraction() = 1.0 - tEnd/trackTime;
if (tEnd <= ROOTVSMALL)
{
// Force removal
lifeTime_ = 0;
}
if
(
face() != -1
|| !td.keepParticle
|| td.switchProcessor
|| lifeTime_ == 0
)
{
break;
}
}
}
if (!td.keepParticle || lifeTime_ == 0)
{
if (lifeTime_ == 0)
{
if (debug)
{
Pout<< "streamLineParticle : Removing stagnant particle:"
<< p.position()
<< " sampled positions:" << sampledPositions_.size()
<< endl;
}
td.keepParticle = false;
}
else
{
// Normal exit. Store last position and fields
sampledPositions_.append(position());
interpolateFields(td, position(), cell(), face());
if (debug)
{
Pout<< "streamLineParticle : Removing particle:"
<< p.position()
<< " sampled positions:" << sampledPositions_.size()
<< endl;
}
}
// Transfer particle data into trackingData.
//td.allPositions_.append(sampledPositions_);
td.allPositions_.append(vectorList());
vectorList& top = td.allPositions_.last();
top.transfer(sampledPositions_);
forAll(sampledScalars_, i)
{
//td.allScalars_[i].append(sampledScalars_[i]);
td.allScalars_[i].append(scalarList());
scalarList& top = td.allScalars_[i].last();
top.transfer(sampledScalars_[i]);
}
forAll(sampledVectors_, i)
{
//td.allVectors_[i].append(sampledVectors_[i]);
td.allVectors_[i].append(vectorList());
vectorList& top = td.allVectors_[i].last();
top.transfer(sampledVectors_[i]);
}
}
return td.keepParticle;
}
bool Foam::streamLineParticle::hitPatch
(
const polyPatch&,
trackingData& td,
const label patchi,
const scalar trackFraction,
const tetIndices& tetIs
)
{
// Disable generic patch interaction
return false;
}
void Foam::streamLineParticle::hitWedgePatch
(
const wedgePolyPatch& pp,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::streamLineParticle::hitSymmetryPlanePatch
(
const symmetryPlanePolyPatch& pp,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::streamLineParticle::hitSymmetryPatch
(
const symmetryPolyPatch& pp,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::streamLineParticle::hitCyclicPatch
(
const cyclicPolyPatch& pp,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::streamLineParticle::hitProcessorPatch
(
const processorPolyPatch&,
trackingData& td
)
{
// Switch particle
td.switchProcessor = true;
}
void Foam::streamLineParticle::hitWallPatch
(
const wallPolyPatch& wpp,
trackingData& td,
const tetIndices&
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::streamLineParticle::hitPatch
(
const polyPatch& wpp,
trackingData& td
)
{
// Remove particle
td.keepParticle = false;
}
void Foam::streamLineParticle::readFields(Cloud<streamLineParticle>& c)
{
if (!c.size())
{
return;
}
particle::readFields(c);
IOField<label> lifeTime
(
c.fieldIOobject("lifeTime", IOobject::MUST_READ)
);
c.checkFieldIOobject(c, lifeTime);
vectorFieldIOField sampledPositions
(
c.fieldIOobject("sampledPositions", IOobject::MUST_READ)
);
c.checkFieldIOobject(c, sampledPositions);
// vectorFieldIOField sampleVelocity
// (
// c.fieldIOobject("sampleVelocity", IOobject::MUST_READ)
// );
// c.checkFieldIOobject(c, sampleVelocity);
label i = 0;
forAllIter(Cloud<streamLineParticle>, c, iter)
{
iter().lifeTime_ = lifeTime[i];
iter().sampledPositions_.transfer(sampledPositions[i]);
// iter().sampleVelocity_.transfer(sampleVelocity[i]);
i++;
}
}
void Foam::streamLineParticle::writeFields(const Cloud<streamLineParticle>& c)
{
particle::writeFields(c);
label np = c.size();
IOField<label> lifeTime
(
c.fieldIOobject("lifeTime", IOobject::NO_READ),
np
);
vectorFieldIOField sampledPositions
(
c.fieldIOobject("sampledPositions", IOobject::NO_READ),
np
);
// vectorFieldIOField sampleVelocity
// (
// c.fieldIOobject("sampleVelocity", IOobject::NO_READ),
// np
// );
label i = 0;
forAllConstIter(Cloud<streamLineParticle>, c, iter)
{
lifeTime[i] = iter().lifeTime_;
sampledPositions[i] = iter().sampledPositions_;
// sampleVelocity[i] = iter().sampleVelocity_;
i++;
}
lifeTime.write();
sampledPositions.write();
// sampleVelocity.write();
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const streamLineParticle& p)
{
os << static_cast<const particle&>(p)
<< token::SPACE << p.lifeTime_
<< token::SPACE << p.sampledPositions_
<< token::SPACE << p.sampledScalars_
<< token::SPACE << p.sampledVectors_;
// Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const streamLineParticle&)");
return os;
}
// ************************************************************************* //

View File

@ -0,0 +1,309 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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::streamLineParticle
Description
Particle class that samples fields as it passes through. Used in streamline
calculation.
SourceFiles
streamLineParticle.C
\*---------------------------------------------------------------------------*/
#ifndef streamLineParticle_H
#define streamLineParticle_H
#include "particle.H"
#include "autoPtr.H"
#include "interpolation.H"
#include "vectorList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class streamLineParticleCloud;
/*---------------------------------------------------------------------------*\
Class streamLineParticle Declaration
\*---------------------------------------------------------------------------*/
class streamLineParticle
:
public particle
{
public:
//- Class used to pass tracking data to the trackToFace function
class trackingData
:
public particle::TrackingData<Cloud<streamLineParticle>>
{
public:
const PtrList<interpolation<scalar>>& vsInterp_;
const PtrList<interpolation<vector>>& vvInterp_;
const label UIndex_;
const bool trackForward_;
const label nSubCycle_;
const scalar trackLength_;
DynamicList<vectorList>& allPositions_;
List<DynamicList<scalarList>>& allScalars_;
List<DynamicList<vectorList>>& allVectors_;
// Constructors
trackingData
(
Cloud<streamLineParticle>& cloud,
const PtrList<interpolation<scalar>>& vsInterp,
const PtrList<interpolation<vector>>& vvInterp,
const label UIndex,
const bool trackForward,
const label nSubCycle,
const scalar trackLength,
DynamicList<List<point>>& allPositions,
List<DynamicList<scalarList>>& allScalars,
List<DynamicList<vectorList>>& allVectors
)
:
particle::TrackingData<Cloud<streamLineParticle>>(cloud),
vsInterp_(vsInterp),
vvInterp_(vvInterp),
UIndex_(UIndex),
trackForward_(trackForward),
nSubCycle_(nSubCycle),
trackLength_(trackLength),
allPositions_(allPositions),
allScalars_(allScalars),
allVectors_(allVectors)
{}
};
private:
// Private data
//- Lifetime of particle. Particle dies when reaches 0.
label lifeTime_;
//- Sampled positions
DynamicList<point> sampledPositions_;
//- Sampled scalars
List<DynamicList<scalar>> sampledScalars_;
//- Sampled vectors
List<DynamicList<vector>> sampledVectors_;
// Private Member Functions
//- Estimate dt to cross from current face to next one in nSubCycle
// steps.
scalar calcSubCycleDeltaT
(
trackingData& td,
const scalar dt,
const vector& U
) const;
void constrainVelocity
(
trackingData& td,
const scalar dt,
vector& U
);
//- Interpolate all quantities; return interpolated velocity.
vector interpolateFields
(
const trackingData&,
const point&,
const label celli,
const label facei
);
public:
// Constructors
//- Construct from components
streamLineParticle
(
const polyMesh& c,
const vector& position,
const label celli,
const label lifeTime
);
//- Construct from Istream
streamLineParticle
(
const polyMesh& c,
Istream& is,
bool readFields = true
);
//- Construct copy
streamLineParticle(const streamLineParticle& p);
//- Construct and return a clone
autoPtr<particle> clone() const
{
return autoPtr<particle>(new streamLineParticle(*this));
}
//- Factory class to read-construct particles used for
// parallel transfer
class iNew
{
const polyMesh& mesh_;
public:
iNew(const polyMesh& mesh)
:
mesh_(mesh)
{}
autoPtr<streamLineParticle> operator()(Istream& is) const
{
return autoPtr<streamLineParticle>
(
new streamLineParticle(mesh_, is, true)
);
}
};
// Member Functions
// Tracking
//- Track all particles to their end point
bool move(trackingData&, const scalar trackTime);
//- 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
);
// I-O
//- Read
static void readFields(Cloud<streamLineParticle>&);
//- Write
static void writeFields(const Cloud<streamLineParticle>&);
// Ostream Operator
friend Ostream& operator<<(Ostream&, const streamLineParticle&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "streamLineParticleCloud.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTemplateTypeNameAndDebug(Cloud<streamLineParticle>, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::streamLineParticleCloud::streamLineParticleCloud
(
const polyMesh& mesh,
const word& cloudName,
bool readFields
)
:
Cloud<streamLineParticle>(mesh, cloudName, false)
{
if (readFields)
{
streamLineParticle::readFields(*this);
}
}
Foam::streamLineParticleCloud::streamLineParticleCloud
(
const polyMesh& mesh,
const word& cloudName,
const IDLList<streamLineParticle>& particles
)
:
Cloud<streamLineParticle>(mesh, cloudName, particles)
{}
// ************************************************************************* //

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