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_,
71  ),
72  mesh_,
73  dimensionedScalar(dims, Zero)
74  );
75 
76  store(outputName, tddt2);
77  }
78 
79  volScalarField& output = lookupObjectRef<volScalarField>(outputName);
80 
81  if (mag_)
82  {
84  }
85  else
86  {
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 // ************************************************************************* //
bool set(const Key &key)
Same as insert (no value to overwrite)
Definition: HashSet.H:240
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Ignore writing from objectRegistry::writeObject()
const word & name() const noexcept
Return the name of this functionObject.
tmp< GeometricField< Type, fvPatchField, volMesh > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition: fvcDdt.C:40
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:72
Calculate the first temporal derivative.
word outputName("finiteArea-edges.obj")
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:33
virtual const word & type() const =0
Runtime type information.
bool store(word &fieldName, const tmp< ObjectType > &tfield, bool cacheable=false)
Store the field in the (sub) objectRegistry under the given name.
static tmp< T > New(Args &&... args)
Construct tmp with forwarding arguments.
Definition: tmp.H:206
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Type gAverage(const FieldField< Field, Type > &f)
Nothing to be read.
#define Log
Definition: PDRblock.C:28
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
Request registration (bool: true)
const fvMesh & mesh_
Reference to the fvMesh.
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
const Time & time_
Reference to the time database.