1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "numericalBeachFvPatchField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 #include "patchWave.H"
32 #include "mathematicalConstants.H"
33 #include "inletOutletFvPatchFields.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 using namespace Foam::mathematicalConstant;
42 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
44 numericalBeachFvPatchField::numericalBeachFvPatchField
47 const DimensionedField<vector, volMesh>& iF
50 inletOutletFvPatchField<vector>(p, iF),
57 numericalBeachFvPatchField::numericalBeachFvPatchField
59 const numericalBeachFvPatchField& ptf,
61 const DimensionedField<vector, volMesh>& iF,
62 const fvPatchFieldMapper& mapper
65 inletOutletFvPatchField<vector>(ptf, p, iF, mapper),
66 thickness_(ptf.thickness_),
72 numericalBeachFvPatchField::numericalBeachFvPatchField
75 const DimensionedField<vector, volMesh>& iF,
76 const dictionary& dict
79 inletOutletFvPatchField<vector>(p, iF, dict),
80 thickness_(readScalar(dict.lookup("thickness"))),
81 nud_(readScalar(dict.lookup("nud")))
83 if (dict.found("offset"))
85 offset_ = readScalar(dict.lookup("offset", 0.0));
87 if (offset_ > thickness_)
91 "numericalBeachFvPatchField::numericalBeachFvPatchField("
93 "const DimensionedField<vector, volMesh>& iF,"
94 "const dictionary& dict)"
96 << "Offset must be smaller than thickness"
103 numericalBeachFvPatchField::numericalBeachFvPatchField
105 const numericalBeachFvPatchField& pivpvf
108 inletOutletFvPatchField<vector>(pivpvf),
109 thickness_(pivpvf.thickness_),
110 offset_(pivpvf.offset_),
115 numericalBeachFvPatchField::numericalBeachFvPatchField
117 const numericalBeachFvPatchField& pivpvf,
118 const DimensionedField<vector, volMesh>& iF
121 inletOutletFvPatchField<vector>(pivpvf, iF),
122 thickness_(pivpvf.thickness_),
123 offset_(pivpvf.offset_),
128 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 void numericalBeachFvPatchField::updateCoeffs()
132 inletOutletFvPatchField<vector>::updateCoeffs();
136 tmp<volScalarField> numericalBeachFvPatchField::internalDamping() const
138 // Get patchids of walls
139 labelHashSet wallPatchIDs(1);
140 wallPatchIDs.insert(this->patch().index());
142 // Calculate distance starting from wallPatch faces.
143 patchWave wave(patch().boundaryMesh().mesh(), wallPatchIDs, false);
145 const scalarField& distance = wave.distance();
147 const fvMesh& mesh = this->patch().boundaryMesh().mesh();
149 tmp<volScalarField> tDamping
156 mesh.time().timeName(),
162 dimensionedScalar("zero", dimensionSet(0, 0, -1, 0, 0), 0.0)
166 volScalarField& damping = tDamping();
168 forAll(distance, cellI)
170 if ( distance[cellI] < offset_ )
172 damping[cellI] = nud_;
174 else if ( distance[cellI] < thickness_ )
177 (distance[cellI] - offset_)/(thickness_ - offset_);
179 damping[cellI] = nud_*(0.5 + 0.5*cos(pi*nonDimDist));
188 numericalBeachFvPatchField::write(Ostream& os) const
190 inletOutletFvPatchField<vector>::write(os);
192 os.writeKeyword("thickness") << thickness_ << token::END_STATEMENT << nl;
195 os.writeKeyword("offset") << offset_ << token::END_STATEMENT << nl;
197 os.writeKeyword("nud") << nud_ << token::END_STATEMENT << nl;
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
207 numericalBeachFvPatchField
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 } // End namespace Foam
214 // ************************************************************************* //