FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "oscillatingFixedValueFvPatchField.H"
00027 #include <OpenFOAM/mathematicalConstants.H>
00028 
00029 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00030 
00031 namespace Foam
00032 {
00033 
00034 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00035 
00036 template<class Type>
00037 scalar oscillatingFixedValueFvPatchField<Type>::currentScale() const
00038 {
00039     return
00040         1.0
00041       + amplitude_*
00042         sin(2*mathematicalConstant::pi*frequency_*this->db().time().value());
00043 }
00044 
00045 
00046 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00047 
00048 template<class Type>
00049 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00050 (
00051     const fvPatch& p,
00052     const DimensionedField<Type, volMesh>& iF
00053 )
00054 :
00055     fixedValueFvPatchField<Type>(p, iF),
00056     refValue_(p.size()),
00057     amplitude_(0.0),
00058     frequency_(0.0),
00059     curTimeIndex_(-1)
00060 {}
00061 
00062 
00063 template<class Type>
00064 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00065 (
00066     const oscillatingFixedValueFvPatchField<Type>& ptf,
00067     const fvPatch& p,
00068     const DimensionedField<Type, volMesh>& iF,
00069     const fvPatchFieldMapper& mapper
00070 )
00071 :
00072     fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
00073     refValue_(ptf.refValue_, mapper),
00074     amplitude_(ptf.amplitude_),
00075     frequency_(ptf.frequency_),
00076     curTimeIndex_(-1)
00077 {}
00078 
00079 
00080 template<class Type>
00081 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00082 (
00083     const fvPatch& p,
00084     const DimensionedField<Type, volMesh>& iF,
00085     const dictionary& dict
00086 )
00087 :
00088     fixedValueFvPatchField<Type>(p, iF),
00089     refValue_("refValue", dict, p.size()),
00090     amplitude_(readScalar(dict.lookup("amplitude"))),
00091     frequency_(readScalar(dict.lookup("frequency"))),
00092     curTimeIndex_(-1)
00093 {
00094     if (dict.found("value"))
00095     {
00096         fixedValueFvPatchField<Type>::operator==
00097         (
00098             Field<Type>("value", dict, p.size())
00099         );
00100     }
00101     else
00102     {
00103         fixedValueFvPatchField<Type>::operator==(refValue_*currentScale());
00104     }
00105 }
00106 
00107 
00108 template<class Type>
00109 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00110 (
00111     const oscillatingFixedValueFvPatchField<Type>& ptf
00112 )
00113 :
00114     fixedValueFvPatchField<Type>(ptf),
00115     refValue_(ptf.refValue_),
00116     amplitude_(ptf.amplitude_),
00117     frequency_(ptf.frequency_),
00118     curTimeIndex_(-1)
00119 {}
00120 
00121 
00122 template<class Type>
00123 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
00124 (
00125     const oscillatingFixedValueFvPatchField<Type>& ptf,
00126     const DimensionedField<Type, volMesh>& iF
00127 )
00128 :
00129     fixedValueFvPatchField<Type>(ptf, iF),
00130     refValue_(ptf.refValue_),
00131     amplitude_(ptf.amplitude_),
00132     frequency_(ptf.frequency_),
00133     curTimeIndex_(-1)
00134 {}
00135 
00136 
00137 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00138 
00139 template<class Type>
00140 void oscillatingFixedValueFvPatchField<Type>::autoMap
00141 (
00142     const fvPatchFieldMapper& m
00143 )
00144 {
00145     fixedValueFvPatchField<Type>::autoMap(m);
00146     refValue_.autoMap(m);
00147 }
00148 
00149 
00150 template<class Type>
00151 void oscillatingFixedValueFvPatchField<Type>::rmap
00152 (
00153     const fvPatchField<Type>& ptf,
00154     const labelList& addr
00155 )
00156 {
00157     fixedValueFvPatchField<Type>::rmap(ptf, addr);
00158 
00159     const oscillatingFixedValueFvPatchField<Type>& tiptf =
00160         refCast<const oscillatingFixedValueFvPatchField<Type> >(ptf);
00161 
00162     refValue_.rmap(tiptf.refValue_, addr);
00163 }
00164 
00165 
00166 template<class Type>
00167 void oscillatingFixedValueFvPatchField<Type>::updateCoeffs()
00168 {
00169     if (this->updated())
00170     {
00171         return;
00172     }
00173 
00174     if (curTimeIndex_ != this->db().time().timeIndex())
00175     {
00176         Field<Type>& patchField = *this;
00177 
00178         patchField = refValue_*currentScale();
00179 
00180         curTimeIndex_ = this->db().time().timeIndex();
00181     }
00182 
00183     fixedValueFvPatchField<Type>::updateCoeffs();
00184 }
00185 
00186 
00187 template<class Type>
00188 void oscillatingFixedValueFvPatchField<Type>::write(Ostream& os) const
00189 {
00190     fixedValueFvPatchField<Type>::write(os);
00191     refValue_.writeEntry("refValue", os);
00192     os.writeKeyword("amplitude")
00193         << amplitude_ << token::END_STATEMENT << nl;
00194     os.writeKeyword("frequency")
00195         << frequency_ << token::END_STATEMENT << nl;
00196 }
00197 
00198 
00199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00200 
00201 } // End namespace Foam
00202 
00203 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines