CourantNo.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2018 OpenFOAM Foundation
6  \\/ M anipulation |
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"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36 namespace functionObjects
37 {
38  defineTypeNameAndDebug(CourantNo, 0);
39 
41  (
42  functionObject,
43  CourantNo,
44  dictionary
45  );
46 }
47 }
48 
49 
50 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
51 
53 Foam::functionObjects::CourantNo::byRho
54 (
55  const tmp<volScalarField::Internal>& Co
56 ) const
57 {
58  if (Co().dimensions() == dimDensity)
59  {
60  return Co/obr_.lookupObject<volScalarField>(rhoName_);
61  }
62  else
63  {
64  return Co;
65  }
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> tCo
77  (
79  (
80  resultName_,
81  mesh_,
83  zeroGradientFvPatchScalarField::typeName
84  )
85  );
86 
87  tCo->ref() =
88  byRho
89  (
90  (0.5*mesh_.time().deltaT())
91  *fvc::surfaceSum(mag(phi))()()
92  /mesh_.V()
93  );
94 
95  tCo->correctBoundaryConditions();
96 
97  return store(resultName_, tCo);
98  }
99  else
100  {
101  return false;
102  }
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
107 
109 (
110  const word& name,
111  const Time& runTime,
112  const dictionary& dict
113 )
114 :
115  fieldExpression(name, runTime, dict, "phi")
116 {
117  setResultName("Co", "phi");
118  read(dict);
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
123 
125 {}
126 
127 
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
129 
131 {
132  fieldExpression::read(dict);
133 
134  rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
135 
136  return true;
137 }
138 
139 
140 // ************************************************************************* //
Foam::surfaceFields.
Surface integrate surfaceField creating a volField. Surface sum a surfaceField creating a volField...
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Macros for easy insertion into run-time selection tables.
virtual bool read(const dictionary &)
Read the CourantNo data.
Definition: CourantNo.C:130
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, const Mesh &, const dimensionSet &, const word &patchFieldType=fvPatchField< scalar >::calculatedType())
Return a temporary field constructed from name, mesh, dimensionSet.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
virtual bool read(const dictionary &)
Read the fieldExpression data.
defineTypeNameAndDebug(Qdot, 0)
const dimensionSet dimDensity
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
virtual ~CourantNo()
Destructor.
Definition: CourantNo.C:124
dimensioned< scalar > mag(const dimensioned< Type > &)
tmp< GeometricField< Type, fvPatchField, volMesh > > surfaceSum(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
A class for managing temporary objects.
Definition: PtrList.H:53
CourantNo(const word &name, const Time &, const dictionary &)
Construct from Time and dictionary.
Definition: CourantNo.C:109
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Namespace for OpenFOAM.