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-2020 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  cannotFindObject<surfaceScalarField>(fieldName_);
102 
103  return false;
104  }
105 }
106 
107 
108 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
109 
111 (
112  const word& name,
113  const Time& runTime,
114  const dictionary& dict
115 )
116 :
117  fieldExpression(name, runTime, dict, "Co", "phi")
118 {
119  read(dict);
120 }
121 
122 
123 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
124 
126 {}
127 
128 
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 
132 {
133  fieldExpression::read(dict);
134 
135  rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
136 
137  return true;
138 }
139 
140 
141 // ************************************************************************* //
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:156
addToRunTimeSelectionTable(functionObject, Qdot, dictionary)
static tmp< GeometricField< scalar, fvPatchField, volMesh > > New(const word &name, const Internal &, const PtrList< fvPatchField< scalar >> &)
Return a temporary field constructed from name,.
const dimensionSet dimless
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:131
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
bool read(const char *, int32_t &)
Definition: int32IO.C:85
A class for handling words, derived from string.
Definition: word.H:59
const dimensionSet dimDensity
virtual bool read(const dictionary &)
Read the fieldExpression data.
defineTypeNameAndDebug(Qdot, 0)
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:125
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:111
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Namespace for OpenFOAM.