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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
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 "CourantNo.H"
29 #include "surfaceFields.H"
30 #include "fvcSurfaceIntegrate.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionObjects
39 {
40  defineTypeNameAndDebug(CourantNo, 0);
41 
43  (
44  functionObject,
45  CourantNo,
46  dictionary
47  );
48 }
49 }
50 
51 
52 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
53 
55 Foam::functionObjects::CourantNo::byRho
56 (
57  const tmp<volScalarField::Internal>& Co
58 ) const
59 {
60  if (Co().dimensions() == dimDensity)
61  {
62  return Co/obr_.lookupObject<volScalarField>(rhoName_);
63  }
64 
65  return Co;
66 }
67 
68 
69 bool Foam::functionObjects::CourantNo::calc()
70 {
71  if (foundObject<surfaceScalarField>(fieldName_))
72  {
73  const surfaceScalarField& phi =
74  lookupObject<surfaceScalarField>(fieldName_);
75 
76  tmp<volScalarField::Internal> Coi
77  (
78  byRho
79  (
80  (0.5*mesh_.time().deltaT())
81  *fvc::surfaceSum(mag(phi))()()
82  /mesh_.V()
83  )
84  );
85 
86  if (foundObject<volScalarField>(resultName_, false))
87  {
88  volScalarField& Co =
89  lookupObjectRef<volScalarField>(resultName_);
90 
91  Co.ref() = Coi();
92  Co.correctBoundaryConditions();
93  }
94  else
95  {
96  auto tCo = tmp<volScalarField>::New
97  (
98  IOobject
99  (
100  resultName_,
101  mesh_.time().timeName(),
102  mesh_,
105  ),
106  mesh_,
108  zeroGradientFvPatchScalarField::typeName
109  );
110  tCo.ref().ref() = Coi();
111  tCo.ref().correctBoundaryConditions();
112  mesh_.objectRegistry::store(tCo.ptr());
113  }
114 
115  return true;
116  }
117 
118  return false;
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 
125 (
126  const word& name,
127  const Time& runTime,
128  const dictionary& dict
129 )
130 :
131  fieldExpression(name, runTime, dict, "phi"),
132  rhoName_("rho")
133 {
134  setResultName("Co", "phi");
135  read(dict);
136 }
137 
138 
139 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
140 
142 {}
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
148 {
150 
151  rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
152 
153  return true;
154 }
155 
156 
157 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::fvc::surfaceSum
tmp< GeometricField< Type, fvPatchField, volMesh > > surfaceSum(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcSurfaceIntegrate.C:135
Foam::functionObjects::regionFunctionObject::obr_
const objectRegistry & obr_
Reference to the region objectRegistry.
Definition: regionFunctionObject.H:100
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::dimDensity
const dimensionSet dimDensity
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::CourantNo::~CourantNo
virtual ~CourantNo()
Destructor.
Definition: CourantNo.C:141
Foam::functionObjects::fieldExpression::read
virtual bool read(const dictionary &dict)
Read the fieldExpression data.
Definition: fieldExpression.C:91
surfaceFields.H
Foam::surfaceFields.
Foam::functionObjects::CourantNo::CourantNo
CourantNo(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: CourantNo.C:125
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
Foam::objectRegistry::lookupObject
const Type & lookupObject(const word &name, const bool recursive=false) const
Definition: objectRegistryTemplates.C:434
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 a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
CourantNo.H
Foam::functionObjects::CourantNo::read
virtual bool read(const dictionary &)
Read the CourantNo data.
Definition: CourantNo.C:147
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Foam::functionObjects::fieldExpression
Base class for field expression function objects.
Definition: fieldExpression.H:60
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:54
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::IOobject::NO_READ
Definition: IOobject.H:123
zeroGradientFvPatchFields.H