waveSurfacePressureFvPatchScalarField.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) 2011-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 
28 #include "fvPatchFieldMapper.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
32 #include "EulerDdtScheme.H"
33 #include "CrankNicolsonDdtScheme.H"
34 #include "backwardDdtScheme.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
40  template<>
41  const char* NamedEnum
42  <
44  3
45  >::names[] =
46  {
50  };
51 }
52 
53 
54 const Foam::NamedEnum
55 <
57  3
58 > Foam::waveSurfacePressureFvPatchScalarField::ddtSchemeTypeNames_;
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
65 (
66  const fvPatch& p,
68 )
69 :
70  fixedValueFvPatchScalarField(p, iF),
71  phiName_("phi"),
72  zetaName_("zeta"),
73  rhoName_("rho")
74 {}
75 
76 
79 (
80  const fvPatch& p,
82  const dictionary& dict
83 )
84 :
85  fixedValueFvPatchScalarField(p, iF, dict),
86  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
87  zetaName_(dict.lookupOrDefault<word>("zeta", "zeta")),
88  rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
89 {}
90 
91 
94 (
96  const fvPatch& p,
98  const fvPatchFieldMapper& mapper
99 )
100 :
101  fixedValueFvPatchScalarField(ptf, p, iF, mapper),
102  phiName_(ptf.phiName_),
103  zetaName_(ptf.zetaName_),
104  rhoName_(ptf.rhoName_)
105 {}
106 
107 
110 (
112 )
113 :
114  fixedValueFvPatchScalarField(wspsf),
115  phiName_(wspsf.phiName_),
116  zetaName_(wspsf.zetaName_),
117  rhoName_(wspsf.rhoName_)
118 {}
119 
120 
123 (
126 )
127 :
128  fixedValueFvPatchScalarField(wspsf, iF),
129  phiName_(wspsf.phiName_),
130  zetaName_(wspsf.zetaName_),
131  rhoName_(wspsf.rhoName_)
132 {}
133 
134 
135 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
136 
138 {
139  if (updated())
140  {
141  return;
142  }
143 
144  const label patchi = patch().index();
145 
146  const scalar dt = db().time().deltaTValue();
147 
148  // Retrieve non-const access to zeta field from the database
149  volVectorField& zeta = db().lookupObjectRef<volVectorField>(zetaName_);
150  vectorField& zetap = zeta.boundaryFieldRef()[patchi];
151 
152  // Lookup d/dt scheme from database for zeta
153  const word ddtSchemeName(zeta.mesh().ddtScheme(zeta.name()));
154  ddtSchemeType ddtScheme(ddtSchemeTypeNames_[ddtSchemeName]);
155 
156  // Retrieve the flux field from the database
157  const surfaceScalarField& phi =
158  db().lookupObject<surfaceScalarField>(phiName_);
159 
160  // Cache the patch face-normal vectors
161  tmp<vectorField> nf(patch().nf());
162 
163  // Change in zeta due to flux
164  vectorField dZetap(dt*nf()*phi.boundaryField()[patchi]/patch().magSf());
165 
167  {
168  const scalarField& rhop =
169  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
170 
171  dZetap /= rhop;
172  }
173 
174  const volVectorField& zeta0 = zeta.oldTime();
175 
176  switch (ddtScheme)
177  {
178  case tsEuler:
179  case tsCrankNicolson:
180  {
181  zetap = zeta0.boundaryField()[patchi] + dZetap;
182 
183  break;
184  }
185  case tsBackward:
186  {
187  scalar dt0 = db().time().deltaT0Value();
188 
189  scalar c = 1.0 + dt/(dt + dt0);
190  scalar c00 = dt*dt/(dt0*(dt + dt0));
191  scalar c0 = c + c00;
192 
193  zetap =
194  (
195  c0*zeta0.boundaryField()[patchi]
196  - c00*zeta0.oldTime().boundaryField()[patchi]
197  + dZetap
198  )/c;
199 
200  break;
201  }
202  default:
203  {
205  << ddtSchemeName << nl
206  << " on patch " << this->patch().name()
207  << " of field " << this->internalField().name()
208  << " in file " << this->internalField().objectPath()
209  << abort(FatalError);
210  }
211  }
212 
213 
214  Info<< "min/max zetap = " << gMin(zetap & nf()) << ", "
215  << gMax(zetap & nf()) << endl;
216 
217  // Update the surface pressure
219  db().lookupObject<uniformDimensionedVectorField>("g");
220 
221  operator==(-g.value() & zetap);
222 
223  fixedValueFvPatchScalarField::updateCoeffs();
224 }
225 
226 
228 {
230  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
231  writeEntryIfDifferent<word>(os, "zeta", "zeta", zetaName_);
232  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
233  writeEntry("value", os);
234 }
235 
236 
237 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
238 
239 namespace Foam
240 {
242  (
245  );
246 }
247 
248 // ************************************************************************* //
Foam::surfaceFields.
waveSurfacePressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
Second-oder Crank-Nicolson implicit ddt using the current and previous time-step fields as well as th...
const GeometricField< Type, PatchField, GeoMesh > & oldTime() const
Return old time field.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
ddtSchemeType
Enumeration defining the available ddt schemes.
const word & name() const
Return name.
Definition: IOobject.H:297
surfaceScalarField & phi
error FatalError
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
Type gMin(const FieldField< Field, Type > &f)
const Boundary & boundaryField() const
Return const-reference to the boundary field.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:362
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:51
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
const dimensionSet & dimensions() const
Return dimensions.
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
Foam::fvPatchFieldMapper.
const Type & value() const
Return const reference to value.
Second-order backward-differencing ddt using the current and two previous time-step values...
errorManip< error > abort(error &err)
Definition: errorManip.H:131
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
This is a pressure boundary condition, whose value is calculated as the hydrostatic pressure based on...
static const char nl
Definition: Ostream.H:265
const Mesh & mesh() const
Return mesh.
Type gMax(const FieldField< Field, Type > &f)
const dimensionSet dimDensity
label patchi
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
const dimensionedScalar c
Speed of light in a vacuum.
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
messageStream Info
A class for managing temporary objects.
Definition: PtrList.H:53
const dimensionedVector & g
Basic first-order Euler implicit/explicit ddt using only the current and previous time-step values...
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:57
Namespace for OpenFOAM.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
const dimensionSet dimVelocity