Clean up
[ShipHydroSIG.git] / src / vofDynamicMesh / lnInclude / linearWaveFvPatchField.C
blob0a69b7cdfc5329b712afcfba8a66fe31b08a8b1e
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 namespace Foam
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 template<class Type>
39 linearWaveFvPatchField<Type>::linearWaveFvPatchField
41     const fvPatch& p,
42     const DimensionedField<Type, volMesh>& iF
45     mixedFvPatchField<Type>(p, iF),
46     valueAbove_(pTraits<Type>::zero),
47     valueBelow_(pTraits<Type>::zero),
48     amplitude_(0),
49     period_(1),
50     axis_("x"),
51     curTimeIndex_(-1),
52     phiName_("none")
56 template<class Type>
57 linearWaveFvPatchField<Type>::linearWaveFvPatchField
59     const fvPatch& p,
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")),
70     curTimeIndex_(-1),
71     phiName_(dict.lookupOrDefault<word>("phiName","none"))
73     this->refValue() = (valueBelow_);
75     if (dict.found("value"))
76     {
77         fvPatchField<Type>::operator=
78         (
79             Field<Type>("value", dict, p.size())
80         );
81     }
82     else
83     {
84         fvPatchField<Type>::operator=(valueBelow_);
85     }
87     this->refGrad() = pTraits<Type>::zero;
88     this->valueFraction() = 1.0;
92 template<class Type>
93 linearWaveFvPatchField<Type>::linearWaveFvPatchField
95     const linearWaveFvPatchField<Type>& ptf,
96     const fvPatch& p,
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_),
106     axis_(ptf.axis_),
107     curTimeIndex_(-1),
108     phiName_(ptf.phiName_)
112 template<class Type>
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_),
124     axis_(ptf.axis_),
125     curTimeIndex_(-1),
126     phiName_(ptf.phiName_)
130 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
132 // Update the coefficients associated with the patch field
133 template<class Type>
134 void linearWaveFvPatchField<Type>::updateCoeffs()
136     if (this->updated())
137     {
138         return;
139     }
141     if (curTimeIndex_ != this->db().time().timeIndex())
142     {
143         //Field<Type>& patchField = *this;
145         scalar twoPi = 2*mathematicalConstant::pi;
147         scalarField coord;
149         if (axis_ == "x")
150         {
151             coord = this->patch().Cf().component(vector::X);
152         }
153         else if (axis_ == "y")
154         {
155             coord = this->patch().Cf().component(vector::Y);
156         }
157         else if (axis_ == "z")
158         {
159             coord = this->patch().Cf().component(vector::Z);
160         }
161         else
162         {
163             FatalErrorIn("void linearWaveFvPatchField<Type>::updateCoeffs()")
164                 << "Unknown axis: " << axis_ << ".  Should be x, y or z"
165                 << abort(FatalError);
166         }
168         scalar h = amplitude_*
169             Foam::sin(twoPi*this->db().time().value()/period_);
171         Info<< "t = " << this->db().time().value()
172             << " h = " << h << endl;
174         this->refValue() =
175             pos(coord - h)*valueAbove_ + neg(coord - h)*valueBelow_;
177         curTimeIndex_ = this->db().time().timeIndex();
178     }
180     if (phiName_ != "none")
181     {
182         const Field<scalar>& phip = this->patch().lookupPatchField
183         (
184             phiName_,
185             reinterpret_cast<const surfaceScalarField*>(NULL),
186             reinterpret_cast<const scalar*>(NULL)
187         );
189         this->valueFraction() = 1.0 - pos(phip);
190     }
191     else
192     {
193         this->valueFraction() = 1.0;
194     }
196     mixedFvPatchField<Type>::updateCoeffs();
200 // Write
201 template<class Type>
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 // ************************************************************************* //