Q.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 | Copyright (C) 2013-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "Q.H"
27 #include "volFields.H"
28 #include "dictionary.H"
29 #include "fvcGrad.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const word& name,
44  const objectRegistry& obr,
45  const dictionary& dict,
46  const bool loadFromFiles
47 )
48 :
49  name_(name),
50  obr_(obr),
51  active_(true),
52  UName_("U"),
53  resultName_(name),
54  log_(true)
55 {
56  // Check if the available mesh is an fvMesh, otherwise deactivate
57  if (!isA<fvMesh>(obr_))
58  {
59  active_ = false;
61  << "No fvMesh available, deactivating " << name_ << nl
62  << endl;
63  }
64 
65  read(dict);
66 
67  if (active_)
68  {
69  const fvMesh& mesh = refCast<const fvMesh>(obr_);
70 
71  volScalarField* QPtr
72  (
73  new volScalarField
74  (
75  IOobject
76  (
77  resultName_,
78  mesh.time().timeName(),
79  mesh,
80  IOobject::NO_READ,
81  IOobject::NO_WRITE
82  ),
83  mesh,
85  )
86  );
87 
88  mesh.objectRegistry::store(QPtr);
89  }
90 }
91 
92 
93 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
94 
96 {}
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 {
103  if (active_)
104  {
105  log_.readIfPresent("log", dict);
106  dict.readIfPresent("UName", UName_);
107 
108  if (!dict.readIfPresent("resultName", resultName_))
109  {
110  resultName_ = name_;
111  if (UName_ != "U")
112  {
113  resultName_ = resultName_ + "(" + UName_ + ")";
114  }
115  }
116  }
117 }
118 
119 
121 {
122  if (active_)
123  {
124  const fvMesh& mesh = refCast<const fvMesh>(obr_);
125 
126  const volVectorField& U =
128 
129  const volTensorField gradU(fvc::grad(U));
130 
131  volScalarField& Q =
132  const_cast<volScalarField&>
133  (
134  mesh.lookupObject<volScalarField>(resultName_)
135  );
136 
137  Q = 0.5*(sqr(tr(gradU)) - tr(((gradU) & (gradU))));
138  }
139 }
140 
141 
143 {
144  // Do nothing
145 }
146 
147 
149 {
150  // Do nothing
151 }
152 
153 
155 {
156  if (active_)
157  {
158  const volScalarField& Q =
159  obr_.lookupObject<volScalarField>(resultName_);
160 
161  if (log_) Info
162  << type() << " " << name_ << " output:" << nl
163  << " writing field " << Q.name() << nl
164  << endl;
165 
166  Q.write();
167  }
168 }
169 
170 
171 // ************************************************************************* //
volFields.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::fvc::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::Q::Q
Q(const Q &)
Disallow default bitwise copy construct.
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::Q::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: Q.C:148
Foam::Q::write
virtual void write()
Calculate the Q and write.
Definition: Q.C:154
Q.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::Q::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: Q.C:142
Foam::Q::name
virtual const word & name() const
Return name of the set of Q.
Definition: Q.H:177
U
U
Definition: pEqn.H:46
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::Q
This function object calculates and outputs the second invariant of the velocity gradient tensor [1/s...
Definition: Q.H:119
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::Q::execute
virtual void execute()
Execute, currently does nothing.
Definition: Q.C:120
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::Q::read
virtual void read(const dictionary &)
Read the Q data.
Definition: Q.C:101
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::sqr
dimensionedSymmTensor sqr(const dimensionedVector &dv)
Definition: dimensionedSymmTensor.C:49
fvcGrad.H
Calculate the gradient of the given field.
dictionary.H
Foam::tr
dimensionedScalar tr(const dimensionedSphericalTensor &dt)
Definition: dimensionedSphericalTensor.C:49
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
Foam::Q::~Q
virtual ~Q()
Destructor.
Definition: Q.C:95
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47