waveSurfacePressureFvPatchScalarField.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) 2011-2016 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),
86  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
87  zetaName_(dict.lookupOrDefault<word>("zeta", "zeta")),
88  rhoName_(dict.lookupOrDefault<word>("rho", "rho"))
89 {
91  (
92  scalarField("value", dict, p.size())
93  );
94 }
95 
96 
99 (
101  const fvPatch& p,
103  const fvPatchFieldMapper& mapper
104 )
105 :
106  fixedValueFvPatchScalarField(ptf, p, iF, mapper),
107  phiName_(ptf.phiName_),
108  zetaName_(ptf.zetaName_),
109  rhoName_(ptf.rhoName_)
110 {}
111 
112 
115 (
117 )
118 :
119  fixedValueFvPatchScalarField(wspsf),
120  phiName_(wspsf.phiName_),
121  zetaName_(wspsf.zetaName_),
122  rhoName_(wspsf.rhoName_)
123 {}
124 
125 
128 (
131 )
132 :
133  fixedValueFvPatchScalarField(wspsf, iF),
134  phiName_(wspsf.phiName_),
135  zetaName_(wspsf.zetaName_),
136  rhoName_(wspsf.rhoName_)
137 {}
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
143 {
144  if (updated())
145  {
146  return;
147  }
148 
149  const label patchi = patch().index();
150 
151  const scalar dt = db().time().deltaTValue();
152 
153  // retrieve non-const access to zeta field from the database
154  volVectorField& zeta =
155  const_cast<volVectorField&>
156  (
157  db().lookupObject<volVectorField>(zetaName_)
158  );
159  vectorField& zetap = zeta.boundaryFieldRef()[patchi];
160 
161  // lookup d/dt scheme from database for zeta
162  const word ddtSchemeName(zeta.mesh().ddtScheme(zeta.name()));
163  ddtSchemeType ddtScheme(ddtSchemeTypeNames_[ddtSchemeName]);
164 
165  // retrieve the flux field from the database
166  const surfaceScalarField& phi =
167  db().lookupObject<surfaceScalarField>(phiName_);
168 
169  // cache the patch face-normal vectors
170  tmp<vectorField> nf(patch().nf());
171 
172  // change in zeta due to flux
173  vectorField dZetap(dt*nf()*phi.boundaryField()[patchi]/patch().magSf());
174 
176  {
177  const scalarField& rhop =
178  patch().lookupPatchField<volScalarField, scalar>(rhoName_);
179 
180  dZetap /= rhop;
181  }
182 
183  const volVectorField& zeta0 = zeta.oldTime();
184 
185  switch (ddtScheme)
186  {
187  case tsEuler:
188  case tsCrankNicolson:
189  {
190  zetap = zeta0.boundaryField()[patchi] + dZetap;
191 
192  break;
193  }
194  case tsBackward:
195  {
196  scalar dt0 = db().time().deltaT0Value();
197 
198  scalar c = 1.0 + dt/(dt + dt0);
199  scalar c00 = dt*dt/(dt0*(dt + dt0));
200  scalar c0 = c + c00;
201 
202  zetap =
203  (
204  c0*zeta0.boundaryField()[patchi]
205  - c00*zeta0.oldTime().boundaryField()[patchi]
206  + dZetap
207  )/c;
208 
209  break;
210  }
211  default:
212  {
214  << ddtSchemeName << nl
215  << " on patch " << this->patch().name()
216  << " of field " << this->internalField().name()
217  << " in file " << this->internalField().objectPath()
218  << abort(FatalError);
219  }
220  }
221 
222 
223  Info<< "min/max zetap = " << gMin(zetap & nf()) << ", "
224  << gMax(zetap & nf()) << endl;
225 
226  // update the surface pressure
228  db().lookupObject<uniformDimensionedVectorField>("g");
229 
230  operator==(-g.value() & zetap);
231 
232  fixedValueFvPatchScalarField::updateCoeffs();
233 }
234 
235 
237 {
239  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
240  writeEntryIfDifferent<word>(os, "zeta", "zeta", zetaName_);
241  writeEntryIfDifferent<word>(os, "rho", "rho", rhoName_);
242  writeEntry("value", os);
243 }
244 
245 
246 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
247 
248 namespace Foam
249 {
251  (
254  );
255 }
256 
257 // ************************************************************************* //
Foam::surfaceFields.
waveSurfacePressureFvPatchScalarField(const fvPatch &, const DimensionedField< scalar, volMesh > &)
Construct from patch and internal field.
surfaceScalarField & phi
Second-oder Crank-Nicolson implicit ddt using the current and previous time-step fields as well as th...
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.
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)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
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:65
const Type & value() const
Return const reference to value.
Initialise the NamedEnum HashTable from the static list of names.
Definition: NamedEnum.H:52
Macros for easy insertion into run-time selection tables.
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
makePatchTypeField(fvPatchVectorField, SRFFreestreamVelocityFvPatchVectorField)
const GeometricField< Type, PatchField, GeoMesh > & oldTime() const
Return old time field.
const Boundary & boundaryField() const
Return const-reference to the boundary field.
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
A class for handling words, derived from string.
Definition: word.H:59
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Foam::fvPatchFieldMapper.
virtual label size() const
Return size.
Definition: fvPatch.H:161
Second-order backward-differencing ddt using the current and two previous time-step values...
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const dimensionSet & dimensions() const
Return dimensions.
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:262
const dimensionedVector & g
Type gMax(const FieldField< Field, Type > &f)
const dimensionSet dimDensity
label patchi
Boundary & boundaryFieldRef()
Return a reference to the boundary field.
const Mesh & mesh() const
Return mesh.
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:54
Basic first-order Euler implicit/explicit ddt using only the current and previous time-step values...
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
const word & name() const
Return name.
Definition: IOobject.H:260
const dimensionSet dimArea(sqr(dimLength))
Definition: dimensionSets.H:57
Namespace for OpenFOAM.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:363
const dimensionSet dimVelocity