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 "linearWaveFvPatchField.H"
28 #include "surfaceFields.H"
29 #include "mathematicalConstants.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 linearWaveFvPatchField<Type>::linearWaveFvPatchField
42 const DimensionedField<Type, volMesh>& iF
45 mixedFvPatchField<Type>(p, iF),
46 valueAbove_(pTraits<Type>::zero),
47 valueBelow_(pTraits<Type>::zero),
57 linearWaveFvPatchField<Type>::linearWaveFvPatchField
60 const DimensionedField<Type, volMesh>& iF,
61 const dictionary& dict
64 mixedFvPatchField<Type>(p, iF),
65 valueAbove_(pTraits<Type>(dict.lookup("valueAbove"))),
66 valueBelow_(pTraits<Type>(dict.lookup("valueBelow"))),
67 amplitude_(readScalar(dict.lookup("amplitude"))),
68 period_(readScalar(dict.lookup("period"))),
69 axis_(dict.lookup("axis")),
71 phiName_(dict.lookupOrDefault<word>("phiName","none"))
73 this->refValue() = (valueBelow_);
75 if (dict.found("value"))
77 fvPatchField<Type>::operator=
79 Field<Type>("value", dict, p.size())
84 fvPatchField<Type>::operator=(valueBelow_);
87 this->refGrad() = pTraits<Type>::zero;
88 this->valueFraction() = 1.0;
93 linearWaveFvPatchField<Type>::linearWaveFvPatchField
95 const linearWaveFvPatchField<Type>& ptf,
97 const DimensionedField<Type, volMesh>& iF,
98 const fvPatchFieldMapper& mapper
101 mixedFvPatchField<Type>(ptf, p, iF, mapper),
102 valueAbove_(ptf.valueAbove_),
103 valueBelow_(ptf.valueBelow_),
104 amplitude_(ptf.amplitude_),
105 period_(ptf.period_),
108 phiName_(ptf.phiName_)
113 linearWaveFvPatchField<Type>::linearWaveFvPatchField
115 const linearWaveFvPatchField<Type>& ptf,
116 const DimensionedField<Type, volMesh>& iF
119 mixedFvPatchField<Type>(ptf, iF),
120 valueAbove_(ptf.valueAbove_),
121 valueBelow_(ptf.valueBelow_),
122 amplitude_(ptf.amplitude_),
123 period_(ptf.period_),
126 phiName_(ptf.phiName_)
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 // Update the coefficients associated with the patch field
134 void linearWaveFvPatchField<Type>::updateCoeffs()
141 if (curTimeIndex_ != this->db().time().timeIndex())
143 //Field<Type>& patchField = *this;
145 scalar twoPi = 2*mathematicalConstant::pi;
151 coord = this->patch().Cf().component(vector::X);
153 else if (axis_ == "y")
155 coord = this->patch().Cf().component(vector::Y);
157 else if (axis_ == "z")
159 coord = this->patch().Cf().component(vector::Z);
163 FatalErrorIn("void linearWaveFvPatchField<Type>::updateCoeffs()")
164 << "Unknown axis: " << axis_ << ". Should be x, y or z"
165 << abort(FatalError);
168 scalar h = amplitude_*
169 Foam::sin(twoPi*this->db().time().value()/period_);
171 Info<< "t = " << this->db().time().value()
172 << " h = " << h << endl;
175 pos(coord - h)*valueAbove_ + neg(coord - h)*valueBelow_;
177 curTimeIndex_ = this->db().time().timeIndex();
180 if (phiName_ != "none")
182 const Field<scalar>& phip = this->patch().lookupPatchField
185 reinterpret_cast<const surfaceScalarField*>(NULL),
186 reinterpret_cast<const scalar*>(NULL)
189 this->valueFraction() = 1.0 - pos(phip);
193 this->valueFraction() = 1.0;
196 mixedFvPatchField<Type>::updateCoeffs();
202 void linearWaveFvPatchField<Type>::write(Ostream& os) const
204 fvPatchField<Type>::write(os);
205 os.writeKeyword("valueAbove")
206 << valueAbove_ << token::END_STATEMENT << nl;
207 os.writeKeyword("valueBelow")
208 << valueBelow_ << token::END_STATEMENT << nl;
209 os.writeKeyword("amplitude")
210 << amplitude_ << token::END_STATEMENT << nl;
211 os.writeKeyword("period")
212 << period_ << token::END_STATEMENT << nl;
213 os.writeKeyword("axis")
214 << axis_ << token::END_STATEMENT << nl;
215 os.writeKeyword("phiName")
216 << phiName_ << token::END_STATEMENT << nl;
217 this->writeEntry("value", os);
221 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
223 } // End namespace Foam
225 // ************************************************************************* //