OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

oscillatingFixedValueFvPatchField.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 #include "oscillatingFixedValueFvPatchField.H"
00028 #include "mathematicalConstants.H"
00029 
00030 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00031 
00032 namespace Foam
00033 {
00034 
00035 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00036 
00037 template<class Type>
00038 scalar oscillatingFixedValueFvPatchField<Type>::currentScale() const
00039 {
00040     return
00041         1.0
00042       + amplitude_*
00043         sin(2*mathematicalConstant::pi*frequency_*this->db().time().value());
00044 }
00045 
00046 
00047 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00048 
00049 template<class Type>
00050 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00051 (
00052     const fvPatch& p,
00053     const DimensionedField<Type, volMesh>& iF
00054 )
00055 :
00056     fixedValueFvPatchField<Type>(p, iF),
00057     refValue_(p.size()),
00058     amplitude_(0.0),
00059     frequency_(0.0),
00060     curTimeIndex_(-1)
00061 {}
00062 
00063 
00064 template<class Type>
00065 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00066 (
00067     const oscillatingFixedValueFvPatchField<Type>& ptf,
00068     const fvPatch& p,
00069     const DimensionedField<Type, volMesh>& iF,
00070     const fvPatchFieldMapper& mapper
00071 )
00072 :
00073     fixedValueFvPatchField<Type>(p, iF),
00074     refValue_(ptf.refValue_, mapper),
00075     amplitude_(ptf.amplitude_),
00076     frequency_(ptf.frequency_),
00077     curTimeIndex_(-1)
00078 {}
00079 
00080 
00081 template<class Type>
00082 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00083 (
00084     const fvPatch& p,
00085     const DimensionedField<Type, volMesh>& iF,
00086     const dictionary& dict
00087 )
00088 :
00089     fixedValueFvPatchField<Type>(p, iF),
00090     refValue_("refValue", dict, p.size()),
00091     amplitude_(readScalar(dict.lookup("amplitude"))),
00092     frequency_(readScalar(dict.lookup("frequency"))),
00093     curTimeIndex_(-1)
00094 {
00095     if (dict.found("value"))
00096     {
00097         fixedValueFvPatchField<Type>::operator==
00098         (
00099             Field<Type>("value", dict, p.size())
00100         );
00101     }
00102     else
00103     {
00104         fixedValueFvPatchField<Type>::operator==(refValue_*currentScale());
00105     }
00106 }
00107 
00108 
00109 template<class Type>
00110 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00111 (
00112     const oscillatingFixedValueFvPatchField<Type>& ptf
00113 )
00114 :
00115     fixedValueFvPatchField<Type>(ptf),
00116     refValue_(ptf.refValue_),
00117     amplitude_(ptf.amplitude_),
00118     frequency_(ptf.frequency_),
00119     curTimeIndex_(-1)
00120 {}
00121 
00122 
00123 template<class Type>
00124 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00125 (
00126     const oscillatingFixedValueFvPatchField<Type>& ptf,
00127     const DimensionedField<Type, volMesh>& iF
00128 )
00129 :
00130     fixedValueFvPatchField<Type>(ptf, iF),
00131     refValue_(ptf.refValue_),
00132     amplitude_(ptf.amplitude_),
00133     frequency_(ptf.frequency_),
00134     curTimeIndex_(-1)
00135 {}
00136 
00137 
00138 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00139 
00140 template<class Type>
00141 void oscillatingFixedValueFvPatchField<Type>::autoMap
00142 (
00143     const fvPatchFieldMapper& m
00144 )
00145 {
00146     fixedValueFvPatchField<Type>::autoMap(m);
00147     refValue_.autoMap(m);
00148 }
00149 
00150 
00151 template<class Type>
00152 void oscillatingFixedValueFvPatchField<Type>::rmap
00153 (
00154     const fvPatchField<Type>& ptf,
00155     const labelList& addr
00156 )
00157 {
00158     fixedValueFvPatchField<Type>::rmap(ptf, addr);
00159 
00160     const oscillatingFixedValueFvPatchField<Type>& tiptf =
00161         refCast<const oscillatingFixedValueFvPatchField<Type> >(ptf);
00162 
00163     refValue_.rmap(tiptf.refValue_, addr);
00164 }
00165 
00166 
00167 template<class Type>
00168 void oscillatingFixedValueFvPatchField<Type>::updateCoeffs()
00169 {
00170     if (this->updated())
00171     {
00172         return;
00173     }
00174 
00175     if (curTimeIndex_ != this->db().time().timeIndex())
00176     {
00177         Field<Type>& patchField = *this;
00178 
00179         patchField = refValue_*currentScale();
00180 
00181         curTimeIndex_ = this->db().time().timeIndex();
00182     }
00183 
00184     fixedValueFvPatchField<Type>::updateCoeffs();
00185 }
00186 
00187 
00188 template<class Type>
00189 void oscillatingFixedValueFvPatchField<Type>::write(Ostream& os) const
00190 {
00191     fvPatchField<Type>::write(os);
00192     refValue_.writeEntry("refValue", os);
00193     os.writeKeyword("amplitude")
00194         << amplitude_ << token::END_STATEMENT << nl;
00195     os.writeKeyword("frequency")
00196         << frequency_ << token::END_STATEMENT << nl;
00197     this->writeEntry("value", os);
00198 }
00199 
00200 
00201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00202 
00203 } // End namespace Foam
00204 
00205 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd