CourantNo.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 "CourantNo.H"
27 #include "surfaceFields.H"
28 #include "fvcSurfaceIntegrate.H"
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(CourantNo, 0);
35 }
36 
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
42 (
44 ) const
45 {
46  if (Co().dimensions() == dimDensity)
47  {
48  return Co/obr_.lookupObject<volScalarField>(rhoName_);
49  }
50  else
51  {
52  return Co;
53  }
54 }
55 
56 
57 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
58 
60 (
61  const word& name,
62  const objectRegistry& obr,
63  const dictionary& dict,
64  const bool loadFromFiles
65 )
66 :
67  name_(name),
68  obr_(obr),
69  active_(true),
70  phiName_("phi"),
71  rhoName_("rho"),
72  resultName_(name),
73  log_(true)
74 {
75  // Check if the available mesh is an fvMesh, otherwise deactivate
76  if (!isA<fvMesh>(obr_))
77  {
78  active_ = false;
80  << "No fvMesh available, deactivating " << name_ << nl
81  << endl;
82  }
83 
84  read(dict);
85 
86  if (active_)
87  {
88  const fvMesh& mesh = refCast<const fvMesh>(obr_);
89 
90  volScalarField* CourantNoPtr
91  (
92  new volScalarField
93  (
94  IOobject
95  (
96  resultName_,
97  mesh.time().timeName(),
98  mesh,
99  IOobject::NO_READ,
100  IOobject::NO_WRITE
101  ),
102  mesh,
103  dimensionedScalar("0", dimless, 0.0),
104  zeroGradientFvPatchScalarField::typeName
105  )
106  );
107 
108  mesh.objectRegistry::store(CourantNoPtr);
109  }
110 }
111 
112 
113 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
114 
116 {}
117 
118 
119 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
120 
122 {
123  if (active_)
124  {
125  log_.readIfPresent("log", dict);
126 
127  dict.readIfPresent("phiName", phiName_);
128  dict.readIfPresent("rhoName", rhoName_);
129  dict.readIfPresent("resultName", resultName_);
130  }
131 }
132 
133 
135 {
136  if (active_)
137  {
138  const fvMesh& mesh = refCast<const fvMesh>(obr_);
139 
140  const surfaceScalarField& phi =
142 
143  volScalarField& Co =
144  const_cast<volScalarField&>
145  (
146  mesh.lookupObject<volScalarField>(resultName_)
147  );
148 
149  Co.dimensionedInternalField() = byRho
150  (
151  (0.5*mesh.time().deltaT())
153  /mesh.V()
154  );
155  Co.correctBoundaryConditions();
156  }
157 }
158 
159 
161 {
162  // Do nothing
163 }
164 
165 
167 {}
168 
169 
171 {
172  if (active_)
173  {
174  const volScalarField& CourantNo =
175  obr_.lookupObject<volScalarField>(resultName_);
176 
177  if (log_) Info
178  << type() << " " << name_ << " output:" << nl
179  << " writing field " << CourantNo.name() << nl
180  << endl;
181 
182  CourantNo.write();
183  }
184 }
185 
186 
187 // ************************************************************************* //
Foam::fvc::surfaceSum
tmp< GeometricField< Type, fvPatchField, volMesh > > surfaceSum(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcSurfaceIntegrate.C:138
Foam::CourantNo::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: CourantNo.C:160
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::GeometricField::dimensionedInternalField
DimensionedInternalField & dimensionedInternalField()
Return dimensioned internal field.
Definition: GeometricField.C:713
Foam::CourantNo::write
virtual void write()
Calculate the CourantNo and write.
Definition: CourantNo.C:170
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::CourantNo::byRho
tmp< volScalarField::DimensionedInternalField > byRho(const tmp< volScalarField::DimensionedInternalField > &Co) const
Divide Co by rho if required.
Definition: CourantNo.C:42
Foam::TimeState::deltaT
dimensionedScalar deltaT() const
Return time step.
Definition: TimeState.C:79
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:118
Foam::dimDensity
const dimensionSet dimDensity
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
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
dimensionedInternalField
rDeltaT dimensionedInternalField()
Foam::CourantNo
This function object calculates and outputs the Courant number as a volScalarField....
Definition: CourantNo.H:111
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
surfaceFields.H
Foam::surfaceFields.
Foam::mag
dimensioned< scalar > mag(const dimensioned< Type > &)
Foam::CourantNo::name
virtual const word & name() const
Return name of the set of CourantNo.
Definition: CourantNo.H:178
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::fvMesh::V
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
Definition: fvMeshGeometry.C:199
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::CourantNo::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: CourantNo.C:166
fvcSurfaceIntegrate.H
Surface integrate surfaceField creating a volField. Surface sum a surfaceField creating a volField.
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::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
CourantNo.H
Foam::CourantNo::execute
virtual void execute()
Execute, currently does nothing.
Definition: CourantNo.C:134
Foam::CourantNo::read
virtual void read(const dictionary &)
Read the CourantNo data.
Definition: CourantNo.C:121
Foam::CourantNo::CourantNo
CourantNo(const CourantNo &)
Disallow default bitwise copy construct.
Foam::CourantNo::~CourantNo
virtual ~CourantNo()
Destructor.
Definition: CourantNo.C:115
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name) const
Lookup and return the object of the given Type.
Definition: objectRegistryTemplates.C:165
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