Loading...
Searching...
No Matches
ddt2Templates.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2016 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "Time.H"
29#include "dimensionedType.H"
30#include "fvcDdt.H"
31
32// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33
34template<class FieldType>
35int Foam::functionObjects::ddt2::apply(const word& inputName, int& state)
36{
37 // State: return 0 (not-processed), -1 (skip), +1 ok
38
39 // Already done, or not available
40 if (state || !foundObject<FieldType>(inputName))
41 {
42 return state;
43 }
44
45 const FieldType& input = lookupObject<FieldType>(inputName);
46
47 word outputName(resultName_);
48 outputName.replace("@@", inputName);
49
50 results_.set(outputName);
51
53 {
54 const dimensionSet dims =
55 (
56 mag_
57 ? mag(input.dimensions()/dimTime)
58 : magSqr(input.dimensions()/dimTime)
59 );
60
61 auto tddt2 = tmp<volScalarField>::New
62 (
63 IOobject
64 (
66 time_.timeName(),
67 mesh_,
71 ),
72 mesh_,
74 );
75
76 store(outputName, tddt2);
77 }
78
80
81 if (mag_)
82 {
83 output = mag(fvc::ddt(input));
84 }
85 else
86 {
87 output = magSqr(fvc::ddt(input));
88 }
89
90 // Could add additional statistics here
91 Log << type() << ' ' << name()
92 << " field " << outputName
93 << " average: " << gAverage(output) << endl;
94
95 state = +1;
96 return state;
97}
98
99
100// ************************************************************************* //
#define Log
Definition PDRblock.C:28
@ REGISTER
Request registration (bool: true).
@ NO_READ
Nothing to be read.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
const word & name() const noexcept
Return the name of this functionObject.
virtual const word & type() const =0
Runtime type information.
const fvMesh & mesh_
Reference to the fvMesh.
const ObjectType & lookupObject(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
bool foundObject(const word &fieldName) const
Find object (eg, a field) in the (sub) objectRegistry.
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
ObjectType & lookupObjectRef(const word &fieldName) const
Lookup and return object (eg, a field) from the (sub) objectRegistry.
const Time & time_
Reference to the time database.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition tmp.H:215
word outputName("finiteArea-edges.obj")
Calculate the first temporal derivative.
tmp< GeometricField< Type, fvPatchField, volMesh > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition fvcDdt.C:40
Type gAverage(const FieldField< Field, Type > &f, const label comm)
The global arithmetic average of a FieldField.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)