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 "linearWaveVelocityFvPatchField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "mathematicalConstants.H"
34 using namespace Foam::mathematicalConstant;
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
43 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
46 const DimensionedField<vector, volMesh>& iF
49 fixedValueFvPatchVectorField(p, iF),
52 valueAbove_(vector::zero),
57 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
60 const DimensionedField<vector, volMesh>& iF,
61 const dictionary& dict
64 fixedValueFvPatchVectorField(p, iF),
65 amplitude_(readScalar(dict.lookup("amplitude"))),
66 period_(readScalar(dict.lookup("period"))),
67 valueAbove_(dict.lookup("valueAbove")),
74 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
76 const linearWaveVelocityFvPatchField& ptf,
78 const DimensionedField<vector, volMesh>& iF,
79 const fvPatchFieldMapper& mapper
82 fixedValueFvPatchVectorField(ptf, p, iF, mapper),
83 amplitude_(ptf.amplitude_),
85 valueAbove_(ptf.valueAbove_),
90 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
92 const linearWaveVelocityFvPatchField& ptf,
93 const DimensionedField<vector, volMesh>& iF
96 fixedValueFvPatchVectorField(ptf, iF),
97 amplitude_(ptf.amplitude_),
99 valueAbove_(ptf.valueAbove_),
104 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 void linearWaveVelocityFvPatchField::updateCoeffs()
113 if (curTimeIndex_ != this->db().time().timeIndex())
115 scalarField coord = this->patch().Cf().component(vector::Y);
117 scalar omega = twoPi/period_;
118 scalar lambda = 9.81*period_*period_/twoPi;
119 scalar k = twoPi/lambda;
121 scalar time = this->db().time().value();
123 scalar h = amplitude_*sin(twoPi*time/period_);
125 Info << "t = " << this->db().time().value()
127 << " U(0) = " << omega*cos(omega*time) << endl;
129 forAll (coord, faceI)
131 vector newU = valueAbove_;
133 scalar eky = exp(k*coord[faceI]);
137 eky = exp((h - coord[faceI])*3.0*k);
142 newU.y() = omega*amplitude_*eky*cos(omega*time);
145 newU.x() = omega*amplitude_*eky*sin(omega*time);
148 this->operator[](faceI) = newU;
151 curTimeIndex_ = this->db().time().timeIndex();
154 fixedValueFvPatchVectorField::updateCoeffs();
159 void linearWaveVelocityFvPatchField::write(Ostream& os) const
161 fvPatchVectorField::write(os);
162 os.writeKeyword("amplitude")
163 << amplitude_ << token::END_STATEMENT << nl;
164 os.writeKeyword("period")
165 << period_ << token::END_STATEMENT << nl;
166 os.writeKeyword("valueAbove")
167 << valueAbove_ << token::END_STATEMENT << nl;
168 writeEntry("value", os);
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 makePatchTypeField(fvPatchVectorField, linearWaveVelocityFvPatchField);
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 } // End namespace Foam
180 // ************************************************************************* //