waveVelocityFvPatchVectorField.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) 2017-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 
29 #include "levelSet.H"
30 #include "volFields.H"
31 #include "fvMeshSubset.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
36 (
37  const fvPatch& p,
39 )
40 :
41  directionMixedFvPatchVectorField(p, iF),
42  phiName_("phi"),
43  pName_("p"),
44  inletOutlet_(true),
45  faceCellSubset_(nullptr),
46  faceCellSubsetTimeIndex_(-1)
47 {
48  refValue() = Zero;
49  refGrad() = Zero;
50  valueFraction() = Zero;
51 }
52 
53 
55 (
56  const fvPatch& p,
58  const dictionary& dict
59 )
60 :
61  directionMixedFvPatchVectorField(p, iF),
62  phiName_(dict.lookupOrDefault<word>("phi", "phi")),
63  pName_(dict.lookupOrDefault<word>("p", "p")),
64  inletOutlet_(dict.lookupOrDefault<Switch>("inletOutlet", true)),
65  faceCellSubset_(nullptr),
66  faceCellSubsetTimeIndex_(-1)
67 {
68  if (dict.found("value"))
69  {
70  fvPatchVectorField::operator=(vectorField("value", dict, p.size()));
71  }
72  else
73  {
74  fvPatchVectorField::operator=(patchInternalField());
75  }
76 
77  refValue() = *this;
78  refGrad() = Zero;
79  valueFraction() = Zero;
80 }
81 
82 
84 (
86  const fvPatch& p,
88  const fvPatchFieldMapper& mapper
89 )
90 :
91  directionMixedFvPatchVectorField(ptf, p, iF, mapper),
92  phiName_(ptf.phiName_),
93  pName_(ptf.pName_),
94  inletOutlet_(ptf.inletOutlet_),
95  faceCellSubset_(nullptr),
96  faceCellSubsetTimeIndex_(-1)
97 {}
98 
99 
101 (
104 )
105 :
106  directionMixedFvPatchVectorField(ptf, iF),
107  phiName_(ptf.phiName_),
108  pName_(ptf.pName_),
109  inletOutlet_(ptf.inletOutlet_),
110  faceCellSubset_(nullptr),
111  faceCellSubsetTimeIndex_(-1)
112 {}
113 
114 
115 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
116 
117 const Foam::fvMeshSubset&
119 {
120  const fvMesh& mesh = patch().boundaryMesh().mesh();
121  const label timeIndex = mesh.time().timeIndex();
122 
123  if
124  (
125  !faceCellSubset_.valid()
126  || (mesh.changing() && faceCellSubsetTimeIndex_ != timeIndex)
127  )
128  {
129  faceCellSubset_.reset(new fvMeshSubset(mesh));
130  faceCellSubset_->setCellSubset(patch().faceCells());
131  faceCellSubsetTimeIndex_ = timeIndex;
132 
133  // Ask for the tetBasePtIs to trigger all processors to build them.
134  // Without this, processors that do not contain this patch will
135  // generate a comms mismatch.
136  faceCellSubset_->subMesh().tetBasePtIs();
137  }
138 
139  return faceCellSubset_();
140 }
141 
142 
144 {
145  const scalar t = db().time().timeOutputValue();
146  const waveSuperposition& waves = waveSuperposition::New(db());
147 
148  return
150  (
151  patch(),
152  waves.height(t, patch().Cf()),
153  waves.height(t, patch().patch().localPoints()),
154  waves.UGas(t, patch().Cf())(),
155  waves.UGas(t, patch().patch().localPoints())(),
156  waves.ULiquid(t, patch().Cf())(),
157  waves.ULiquid(t, patch().patch().localPoints())()
158  );
159 }
160 
161 
163 {
164  const scalar t = db().time().timeOutputValue();
165  const waveSuperposition& waves = waveSuperposition::New(db());
166 
168  const fvMesh& meshs = subset.subMesh();
169  const label patchis = findIndex(subset.patchMap(), patch().index());
170 
171  const vectorField Us
172  (
174  (
175  meshs,
176  waves.height(t, meshs.cellCentres())(),
177  waves.height(t, meshs.points())(),
178  waves.UGas(t, meshs.cellCentres())(),
179  waves.UGas(t, meshs.points())(),
180  waves.ULiquid(t, meshs.cellCentres())(),
181  waves.ULiquid(t, meshs.points())()
182  )
183  );
184 
185  tmp<vectorField> tResult(new vectorField(patch().size()));
186  vectorField& result = tResult.ref();
187 
188  if (patchis != -1)
189  {
190  forAll(meshs.boundary()[patchis], is)
191  {
192  const label fs = is + meshs.boundary()[patchis].patch().start();
193  const label cs = meshs.boundary()[patchis].faceCells()[is];
194  const label f = subset.faceMap()[fs];
195  const label i = patch().patch().whichFace(f);
196  result[i] = Us[cs];
197  }
198  }
199 
200  return tResult;
201 }
202 
203 
205 {
206  if (updated())
207  {
208  return;
209  }
210 
211  const fvPatchScalarField& pp =
212  patch().lookupPatchField<volScalarField, scalar>(pName_);
213 
214  if (isA<wavePressureFvPatchScalarField>(pp))
215  {
216  const vectorField U(this->U()), Un(this->Un());
217  const scalarField out(pos0(U & patch().Sf()));
218 
219  // Where inflow, set all velocity components to values specified by the
220  // wave model. Where outflow, set the tangential values and the normal
221  // gradient.
222  valueFraction() = symmTensor::I - out*sqr(patch().nf());
223  refValue() = U;
224  refGrad() = (U - Un)*patch().deltaCoeffs();
225  }
226  else
227  {
228  const vectorField U(this->U());
229 
230  if (inletOutlet_)
231  {
232  const scalarField& phip =
233  patch().lookupPatchField<surfaceScalarField, scalar>(phiName_);
234  const scalarField out(pos0(phip));
235 
236  // Where inflow, fix all velocity components to values specified by
237  // the wave model.
238  refValue() = (1 - out)*U;
239  valueFraction() = (1 - out)*symmTensor::I;
240 
241  // Where outflow, set the normal component of the velocity to a
242  // value consistent with phi, but scale it to get the volumetric
243  // flow rate specified by the wave model. Tangential components are
244  // extrapolated.
245  const scalar QPhip = gSum(out*phip);
246  const scalar QWave = gSum(out*(U & patch().Sf()));
247  const vectorField nBySf(patch().Sf()/sqr(patch().magSf()));
248  if (QPhip > vSmall)
249  {
250  refValue() += out*(QWave/QPhip)*phip*nBySf;
251  }
252  else
253  {
254  refValue() += out*QWave*nBySf;
255  }
256  valueFraction() += out*sqr(patch().nf());
257  }
258  else
259  {
260  refValue() = U;
261  valueFraction() = symmTensor::I;
262  }
263  }
264 
265  directionMixedFvPatchVectorField::updateCoeffs();
267 }
268 
269 
271 (
272  Ostream& os
273 ) const
274 {
276  writeEntryIfDifferent<word>(os, "phi", "phi", phiName_);
277  writeEntryIfDifferent<word>(os, "p", "p", pName_);
278  writeEntryIfDifferent<Switch>(os, "inletOutlet", true, inletOutlet_);
279 }
280 
281 
282 // * * * * * * * * * * * * * * Build Macro Function * * * * * * * * * * * * //
283 
284 namespace Foam
285 {
287  (
290  );
291 }
292 
293 // ************************************************************************* //
bool changing() const
Is mesh changing (topology changing and/or moving)
Definition: polyMesh.H:540
A wrapper around a list of wave models. Superimposes the modelled values of elevation and velocity...
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:643
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
virtual tmp< vectorField > UGas(const scalar t, const vectorField &p) const
Get the gas velocity at a given time and global positions.
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
waveVelocityFvPatchVectorField(const fvPatch &, const DimensionedField< vector, volMesh > &)
Construct from patch and internal field.
const fvMeshSubset & faceCellSubset() const
Access the face-cell subset.
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
dimensionedSymmTensor sqr(const dimensionedVector &dv)
virtual void write(Ostream &) const
Write.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:62
A simple wrapper around bool so that it can be read as a word: true/false, on/off, yes/no, y/n, t/f, or none/any.
Definition: Switch.H:60
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
virtual tmp< vectorField > ULiquid(const scalar t, const vectorField &p) const
Get the liquid velocity at a given time and global positions.
volVectorField vectorField(fieldObject, mesh)
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
Macros for easy insertion into run-time selection tables.
const labelList & faceMap() const
Return face map.
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1131
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
const labelList & patchMap() const
Return patch map.
const fvMesh & subMesh() const
Return reference to subset mesh.
virtual tmp< scalarField > height(const scalar t, const vectorField &p) const
Get the height above the waves at a given time and global positions.
dynamicFvMesh & mesh
Type gSum(const FieldField< Field, Type > &f)
static const SymmTensor I
Definition: SymmTensor.H:72
A class for handling words, derived from string.
Definition: word.H:59
Foam::fvPatchFieldMapper.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
static const zero Zero
Definition: zero.H:97
This boundary condition provides a waveVelocity condition. This sets the velocity to that specified b...
const vectorField & cellCentres() const
static const waveSuperposition & New(const objectRegistry &db)
Return a reference to the wave model on the given database,.
virtual label size() const
Return size.
Definition: fvPatch.H:156
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
dimensionedScalar pos0(const dimensionedScalar &ds)
tmp< Field< Type > > levelSetAverage(const fvMesh &mesh, const scalarField &levelC, const scalarField &levelP, const Field< Type > &positiveC, const Field< Type > &positiveP, const Field< Type > &negativeC, const Field< Type > &negativeP)
Calculate the average value of two fields, one on each side of a level set.
labelList f(nPoints)
Post-processing mesh subset tool. Given the original mesh and the list of selected cells...
Definition: fvMeshSubset.H:73
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
tmp< vectorField > Un() const
Return the current modelled velocity field in the neighbour cell.
label timeIndex() const
Return current time index.
Definition: TimeStateI.H:35
T lookupOrDefault(const word &, const T &, bool recursive=false, bool patternMatch=true) const
Find and return a T,.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
label timeIndex
Definition: getTimeIndex.H:4
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
ListType subset(const UList< T > &select, const T &value, const ListType &)
Extract elements of List when select is a certain value.
Field< vector > vectorField
Specialisation of Field<T> for vector.
A class for managing temporary objects.
Definition: PtrList.H:53
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
makePatchTypeField(fvPatchScalarField, atmBoundaryLayerInletEpsilonFvPatchScalarField)
Namespace for OpenFOAM.
tmp< vectorField > U() const
Return the current modelled velocity field on the patch faces.
const fvBoundaryMesh & boundary() const
Return reference to boundary mesh.
Definition: fvMesh.C:540