Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / finiteVolume / fields / fvPatchFields / derived / oscillatingFixedValue / oscillatingFixedValueFvPatchField.C
blob62e3d8c59a7b12bb9f70d55ade3670251249b0e3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend 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 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "oscillatingFixedValueFvPatchField.H"
27 #include "mathematicalConstants.H"
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 namespace Foam
34 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
36 template<class Type>
37 scalar oscillatingFixedValueFvPatchField<Type>::currentScale() const
39     return
40         1.0
41       + amplitude_*
42         sin(2*mathematicalConstant::pi*frequency_*this->db().time().value());
46 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
48 template<class Type>
49 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
51     const fvPatch& p,
52     const DimensionedField<Type, volMesh>& iF
55     fixedValueFvPatchField<Type>(p, iF),
56     refValue_(p.size()),
57     amplitude_(0.0),
58     frequency_(0.0),
59     curTimeIndex_(-1)
63 template<class Type>
64 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
66     const fvPatch& p,
67     const DimensionedField<Type, volMesh>& iF,
68     const dictionary& dict
71     fixedValueFvPatchField<Type>(p, iF),
72     refValue_("refValue", dict, p.size()),
73     amplitude_(readScalar(dict.lookup("amplitude"))),
74     frequency_(readScalar(dict.lookup("frequency"))),
75     curTimeIndex_(-1)
77     if (dict.found("value"))
78     {
79         fixedValueFvPatchField<Type>::operator==
80         (
81             Field<Type>("value", dict, p.size())
82         );
83     }
84     else
85     {
86         fixedValueFvPatchField<Type>::operator==(refValue_*currentScale());
87     }
91 template<class Type>
92 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
94     const oscillatingFixedValueFvPatchField<Type>& ptf,
95     const fvPatch& p,
96     const DimensionedField<Type, volMesh>& iF,
97     const fvPatchFieldMapper& mapper
100     fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
101     refValue_(ptf.refValue_, mapper),
102     amplitude_(ptf.amplitude_),
103     frequency_(ptf.frequency_),
104     curTimeIndex_(-1)
108 template<class Type>
109 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
111     const oscillatingFixedValueFvPatchField<Type>& ptf
114     fixedValueFvPatchField<Type>(ptf),
115     refValue_(ptf.refValue_),
116     amplitude_(ptf.amplitude_),
117     frequency_(ptf.frequency_),
118     curTimeIndex_(-1)
122 template<class Type>
123 oscillatingFixedValueFvPatchField<Type>::oscillatingFixedValueFvPatchField
125     const oscillatingFixedValueFvPatchField<Type>& ptf,
126     const DimensionedField<Type, volMesh>& iF
129     fixedValueFvPatchField<Type>(ptf, iF),
130     refValue_(ptf.refValue_),
131     amplitude_(ptf.amplitude_),
132     frequency_(ptf.frequency_),
133     curTimeIndex_(-1)
137 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
139 template<class Type>
140 void oscillatingFixedValueFvPatchField<Type>::autoMap
142     const fvPatchFieldMapper& m
145     fixedValueFvPatchField<Type>::autoMap(m);
146     refValue_.autoMap(m);
150 template<class Type>
151 void oscillatingFixedValueFvPatchField<Type>::rmap
153     const fvPatchField<Type>& ptf,
154     const labelList& addr
157     fixedValueFvPatchField<Type>::rmap(ptf, addr);
159     const oscillatingFixedValueFvPatchField<Type>& tiptf =
160         refCast<const oscillatingFixedValueFvPatchField<Type> >(ptf);
162     refValue_.rmap(tiptf.refValue_, addr);
166 template<class Type>
167 void oscillatingFixedValueFvPatchField<Type>::updateCoeffs()
169     if (this->updated())
170     {
171         return;
172     }
174     if (curTimeIndex_ != this->db().time().timeIndex())
175     {
176         Field<Type>& patchField = *this;
178         patchField = refValue_*currentScale();
180         curTimeIndex_ = this->db().time().timeIndex();
181     }
183     fixedValueFvPatchField<Type>::updateCoeffs();
187 template<class Type>
188 void oscillatingFixedValueFvPatchField<Type>::write(Ostream& os) const
190     fvPatchField<Type>::write(os);
191     refValue_.writeEntry("refValue", os);
192     os.writeKeyword("amplitude")
193         << amplitude_ << token::END_STATEMENT << nl;
194     os.writeKeyword("frequency")
195         << frequency_ << token::END_STATEMENT << nl;
196     this->writeEntry("value", os);
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 } // End namespace Foam
204 // ************************************************************************* //