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 -------------------------------------------------------------------------------
10 License
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 
34 template<class FieldType>
35 int 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 
52  if (!foundObject<volScalarField>(outputName))
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  (
65  outputName,
66  time_.timeName(),
67  mesh_,
70  ),
71  mesh_,
72  dimensionedScalar(dims, Zero)
73  );
74 
75  store(outputName, tddt2);
76  }
77 
78  volScalarField& output = lookupObjectRef<volScalarField>(outputName);
79 
80  if (mag_)
81  {
83  }
84  else
85  {
87  }
88 
89  // Could add additional statistics here
90  Log << type() << ' ' << name()
91  << " field " << outputName
92  << " average: " << gAverage(output) << endl;
93 
94  state = +1;
95  return state;
96 }
97 
98 
99 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Log
#define Log
Definition: PDRblock.C:35
Foam::output
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:66
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::gAverage
Type gAverage(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:604
Foam::functionObjects::timeFunctionObject::time_
const Time & time_
Reference to the time database.
Definition: timeFunctionObject.H:65
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::functionObjects::regionFunctionObject::store
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
Definition: regionFunctionObjectTemplates.C:107
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
outputName
word outputName("finiteArea-edges.obj")
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:53
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:42
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Time.H
Foam::functionObject::name
const word & name() const noexcept
Return the name of this functionObject.
Definition: functionObject.C:143
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::functionObjects::fvMeshFunctionObject::mesh_
const fvMesh & mesh_
Reference to the fvMesh.
Definition: fvMeshFunctionObject.H:73
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
fvcDdt.H
Calculate the first temporal derivative.
Foam::fvc::ddt
tmp< GeometricField< Type, fvPatchField, volMesh > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition: fvcDdt.C:47
Foam::IOobject::NO_READ
Definition: IOobject.H:188
Foam::HashSet::set
bool set(const Key &key)
Same as insert (no value to overwrite)
Definition: HashSet.H:197
dimensionedType.H