Skip to content
Snippets Groups Projects
Commit 2dd9b391 authored by mark's avatar mark
Browse files

ENH: runTime calculation of (dp/dt)^2 - issue #224

- implemented using magSqr() instead of sqr().
  For scalar fields they are the same, but can be useful
  if this function object is extended for more field types.
parent 7ca9baec
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,9 @@ codedFunctionObject/codedFunctionObject.C ...@@ -6,6 +6,9 @@ codedFunctionObject/codedFunctionObject.C
CourantNo/CourantNo.C CourantNo/CourantNo.C
CourantNo/CourantNoFunctionObject.C CourantNo/CourantNoFunctionObject.C
ddt2/ddt2.C
ddt2/ddt2FunctionObject.C
DESModelRegions/DESModelRegions.C DESModelRegions/DESModelRegions.C
DESModelRegions/DESModelRegionsFunctionObject.C DESModelRegions/DESModelRegionsFunctionObject.C
......
...@@ -32,4 +32,4 @@ LIB_LIBS = \ ...@@ -32,4 +32,4 @@ LIB_LIBS = \
-lsampling \ -lsampling \
-lsurfMesh \ -lsurfMesh \
-lchemistryModel \ -lchemistryModel \
-lreactionThermophysicalModels -lreactionThermophysicalModels
\ No newline at end of file
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::IOddt2
Description
Instance of the generic IOOutputFilter for ddt2.
\*---------------------------------------------------------------------------*/
#ifndef IOddt2_H
#define IOddt2_H
#include "ddt2.H"
#include "IOOutputFilter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef IOOutputFilter<ddt2> IOddt2;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "ddt2.H"
#include "volFields.H"
#include "dictionary.H"
#include "FieldFunctions.H"
#include "fvcDdt.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(ddt2, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class FieldType>
bool Foam::ddt2::calculate
(
const fvMesh& mesh,
bool& done
)
{
if (done)
{
return true; // already done - skip
}
done = mesh.foundObject<FieldType>(fieldName_);
if (!done)
{
return false;
}
const FieldType& input =
mesh.lookupObject<FieldType>(fieldName_);
if (!mesh.foundObject<volScalarField>(resultName_))
{
const dimensionSet dims
(
mag_
? mag(input.dimensions()/dimTime)
: magSqr(input.dimensions()/dimTime)
);
mesh.objectRegistry::store
(
new volScalarField
(
IOobject
(
resultName_,
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE // OR IOobject::AUTO_WRITE
),
mesh,
dimensionedScalar
(
"zero",
dims,
Zero
),
emptyPolyPatch::typeName
)
);
}
volScalarField& field = const_cast<volScalarField&>
(
mesh.lookupObject<volScalarField>(resultName_)
);
if (mag_)
{
field = mag(fvc::ddt(input));
}
else
{
field = magSqr(fvc::ddt(input));
}
return done;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::ddt2::ddt2
(
const word& name,
const objectRegistry& obr,
const dictionary& dict,
const bool loadFromFiles
)
:
name_(name),
obr_(obr),
active_(true),
fieldName_("undefined-fieldName"),
resultName_(word::null),
log_(true),
mag_(dict.lookupOrDefault<Switch>("mag", false))
{
// Check if the available mesh is an fvMesh, otherwise deactivate
if (!isA<fvMesh>(obr_))
{
active_ = false;
WarningInFunction
<< "No fvMesh available, deactivating." << nl
<< endl;
}
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ddt2::~ddt2()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::ddt2::read(const dictionary& dict)
{
if (active_)
{
log_.readIfPresent("log", dict);
dict.lookup("fieldName") >> fieldName_;
dict.readIfPresent("resultName", resultName_);
if (resultName_.empty())
{
resultName_ =
(
word(mag_ ? "mag" : "magSqr")
+ "(ddt(" + fieldName_ + "))"
);
}
}
}
void Foam::ddt2::execute()
{
if (active_)
{
const fvMesh& mesh = refCast<const fvMesh>(obr_);
bool done = false;
calculate<volScalarField>(mesh, done);
calculate<volVectorField>(mesh, done);
if (!done)
{
WarningInFunction
<< "Unprocessed field " << fieldName_ << endl;
}
}
}
void Foam::ddt2::end()
{
// Do nothing
}
void Foam::ddt2::timeSet()
{
// Do nothing
}
void Foam::ddt2::write()
{
if (active_)
{
if (obr_.foundObject<regIOobject>(resultName_))
{
const regIOobject& io =
obr_.lookupObject<regIOobject>(resultName_);
if (log_)
{
const volScalarField& field = dynamicCast<const volScalarField&>
(
io
);
// could add additional statistics here
Info<< type() << " " << name_
<< " output: writing field " << field.name()
<< " average: " << gAverage(field) << endl;
}
// could also add option to suppress writing?
io.write();
}
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::ddt2
Group
grpFVFunctionObjects
Description
This function object calculates the magnitude squared
of d(scalarField)/dt.
The result can be used further for determining variance or RMS values
(for example).
Example of function object specification:
\verbatim
dpdt2
{
type ddt2;
functionObjectLibs ("libutilityFunctionObjects.so");
fieldName p;
resultName dpdt2;
...
}
\endverbatim
\heading Function object usage
\table
Property | Description | Required | Default value
type | type name: ddt2 | yes |
fieldName | Name of field to process | yes |
resultName | Name of magnitude field | no | magSqr(ddt(fieldName))
log | Log to standard output | no | yes
mag | Use 'mag' instead of 'magSqr' | no | false
\endtable
Note that the optional 'mag' entry cannot be changed during the simulation
since it alters the dimensions of the output field.
SourceFiles
ddt2.C
IOddt2.H
\*---------------------------------------------------------------------------*/
#ifndef ddt2_H
#define ddt2_H
#include "volFieldsFwd.H"
#include "surfaceFieldsFwd.H"
#include "pointFieldFwd.H"
#include "OFstream.H"
#include "Switch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class objectRegistry;
class dictionary;
class fvMesh;
class polyMesh;
class mapPolyMesh;
class dimensionSet;
/*---------------------------------------------------------------------------*\
Class ddt2 Declaration
\*---------------------------------------------------------------------------*/
class ddt2
{
// Private data
//- Name of this ddt2 object
word name_;
//- Reference to the database
const objectRegistry& obr_;
//- On/off switch
bool active_;
//- Name of field to process
word fieldName_;
//- Name of result field
word resultName_;
//- Switch to send output to Info as well as to file
Switch log_;
//- Use 'mag' instead of 'magSqr'.
// Cannot be adjusted during the simulation since it alters the
// dimensions of the output field.
const Switch mag_;
// Private Member Functions
//- Create result field upon demand
volScalarField& getOrCreateResultField
(
const fvMesh&,
const dimensionSet& inputDims
);
//- Create result field upon demand
template<class FieldType>
bool calculate(const FieldType& input);
//- Create result field upon demand
template<class FieldType>
bool calculate(const fvMesh&, bool& done);
//- Disallow default bitwise copy construct
ddt2(const ddt2&) = delete;
//- Disallow default bitwise assignment
void operator=(const ddt2&) = delete;
public:
//- Runtime type information
TypeName("ddt2");
// Constructors
//- Construct for given objectRegistry and dictionary.
// Allow the possibility to load fields from files
ddt2
(
const word& name,
const objectRegistry&,
const dictionary&,
const bool loadFromFiles = false
);
//- Destructor
virtual ~ddt2();
// Member Functions
//- Return name of the ddt2 function object
virtual const word& name() const
{
return name_;
}
//- Read the ddt2 specification
virtual void read(const dictionary&);
//- Execute, currently does nothing
virtual void execute();
//- Execute at the final time-loop, currently does nothing
virtual void end();
//- Called when time was set at the end of the Time::operator++
virtual void timeSet();
//- Calculate the ddt2 and write
virtual void write();
//- Update for changes of mesh
virtual void updateMesh(const mapPolyMesh&)
{}
//- Update for changes of mesh
virtual void movePoints(const polyMesh&)
{}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "ddt2FunctionObject.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineNamedTemplateTypeNameAndDebug(ddt2FunctionObject, 0);
addToRunTimeSelectionTable
(
functionObject,
ddt2FunctionObject,
dictionary
);
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::ddt2FunctionObject
Description
FunctionObject wrapper around ddt2 to allow it to be created
via the functions entry within controlDict.
SourceFiles
ddt2FunctionObject.C
\*---------------------------------------------------------------------------*/
#ifndef ddt2FunctionObject_H
#define ddt2FunctionObject_H
#include "ddt2.H"
#include "OutputFilterFunctionObject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef OutputFilterFunctionObject<ddt2> ddt2FunctionObject;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment