FreeFOAM The Cross-Platform CFD Toolkit
oscillatingFixedValueFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 
34 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
35 
36 template<class Type>
37 scalar oscillatingFixedValueFvPatchField<Type>::currentScale() const
38 {
39  return
40  1.0
41  + amplitude_*
42  sin(2*mathematicalConstant::pi*frequency_*this->db().time().value());
43 }
44 
45 
46 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
47 
48 template<class Type>
50 (
51  const fvPatch& p,
53 )
54 :
56  refValue_(p.size()),
57  amplitude_(0.0),
58  frequency_(0.0),
59  curTimeIndex_(-1)
60 {}
61 
62 
63 template<class Type>
65 (
67  const fvPatch& p,
69  const fvPatchFieldMapper& mapper
70 )
71 :
72  fixedValueFvPatchField<Type>(ptf, p, iF, mapper),
73  refValue_(ptf.refValue_, mapper),
74  amplitude_(ptf.amplitude_),
75  frequency_(ptf.frequency_),
76  curTimeIndex_(-1)
77 {}
78 
79 
80 template<class Type>
82 (
83  const fvPatch& p,
85  const dictionary& dict
86 )
87 :
89  refValue_("refValue", dict, p.size()),
90  amplitude_(readScalar(dict.lookup("amplitude"))),
91  frequency_(readScalar(dict.lookup("frequency"))),
92  curTimeIndex_(-1)
93 {
94  if (dict.found("value"))
95  {
97  (
98  Field<Type>("value", dict, p.size())
99  );
100  }
101  else
102  {
103  fixedValueFvPatchField<Type>::operator==(refValue_*currentScale());
104  }
105 }
106 
107 
108 template<class Type>
110 (
112 )
113 :
115  refValue_(ptf.refValue_),
116  amplitude_(ptf.amplitude_),
117  frequency_(ptf.frequency_),
118  curTimeIndex_(-1)
119 {}
120 
121 
122 template<class Type>
124 (
127 )
128 :
130  refValue_(ptf.refValue_),
131  amplitude_(ptf.amplitude_),
132  frequency_(ptf.frequency_),
133  curTimeIndex_(-1)
134 {}
135 
136 
137 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
138 
139 template<class Type>
141 (
142  const fvPatchFieldMapper& m
143 )
144 {
146  refValue_.autoMap(m);
147 }
148 
149 
150 template<class Type>
152 (
153  const fvPatchField<Type>& ptf,
154  const labelList& addr
155 )
156 {
158 
160  refCast<const oscillatingFixedValueFvPatchField<Type> >(ptf);
161 
162  refValue_.rmap(tiptf.refValue_, addr);
163 }
164 
165 
166 template<class Type>
168 {
169  if (this->updated())
170  {
171  return;
172  }
173 
174  if (curTimeIndex_ != this->db().time().timeIndex())
175  {
176  Field<Type>& patchField = *this;
177 
178  patchField = refValue_*currentScale();
179 
180  curTimeIndex_ = this->db().time().timeIndex();
181  }
182 
184 }
185 
186 
187 template<class Type>
189 {
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 }
197 
198 
199 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
200 
201 } // End namespace Foam
202 
203 // ************************ vim: set sw=4 sts=4 et: ************************ //