Clean up
[ShipHydroSIG.git] / src / vofDynamicMesh / lnInclude / linearWaveVelocityFvPatchField.C
blob82f8077b6817ea81cf8a2cda3be15a38eada7236
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 "linearWaveVelocityFvPatchField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "volFields.H"
31 #include "surfaceFields.H"
32 #include "mathematicalConstants.H"
34 using namespace Foam::mathematicalConstant;
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
41 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
43 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
45     const fvPatch& p,
46     const DimensionedField<vector, volMesh>& iF
49     fixedValueFvPatchVectorField(p, iF),
50     amplitude_(0),
51     period_(0),
52     valueAbove_(vector::zero),
53     curTimeIndex_(-1)
57 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
59     const fvPatch& p,
60     const DimensionedField<vector, volMesh>& iF,
61     const dictionary& dict
64     fixedValueFvPatchVectorField(p, iF),
65     amplitude_(readScalar(dict.lookup("amplitude"))),
66     period_(readScalar(dict.lookup("period"))),
67     valueAbove_(dict.lookup("valueAbove")),
68     curTimeIndex_(-1)
70     evaluate();
74 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
76     const linearWaveVelocityFvPatchField& ptf,
77     const fvPatch& p,
78     const DimensionedField<vector, volMesh>& iF,
79     const fvPatchFieldMapper& mapper
82     fixedValueFvPatchVectorField(ptf, p, iF, mapper),
83     amplitude_(ptf.amplitude_),
84     period_(ptf.period_),
85     valueAbove_(ptf.valueAbove_),
86     curTimeIndex_(-1)
90 linearWaveVelocityFvPatchField::linearWaveVelocityFvPatchField
92     const linearWaveVelocityFvPatchField& ptf,
93     const DimensionedField<vector, volMesh>& iF
96     fixedValueFvPatchVectorField(ptf, iF),
97     amplitude_(ptf.amplitude_),
98     period_(ptf.period_),
99     valueAbove_(ptf.valueAbove_),
100     curTimeIndex_(-1)
104 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
106 void linearWaveVelocityFvPatchField::updateCoeffs()
108     if (this->updated())
109     {
110         return;
111     }
113     if (curTimeIndex_ != this->db().time().timeIndex())
114     {
115         scalarField coord = this->patch().Cf().component(vector::Y);
117         scalar omega = twoPi/period_;
118         scalar lambda = 9.81*period_*period_/twoPi;
119         scalar k = twoPi/lambda;
121         scalar time = this->db().time().value();
123         scalar h = amplitude_*sin(twoPi*time/period_);
125         Info << "t = " << this->db().time().value()
126             << " h = " << h
127             << " U(0) = " <<  omega*cos(omega*time) << endl;
129         forAll (coord, faceI)
130         {
131             vector newU = valueAbove_;
133             scalar eky = exp(k*coord[faceI]);
135             if(coord[faceI] > h)
136             {
137                 eky = exp((h - coord[faceI])*3.0*k);
138                 newU.y() = 0.0;
139             }
140             else
141             {
142                 newU.y() = omega*amplitude_*eky*cos(omega*time);
143             }
145             newU.x() = omega*amplitude_*eky*sin(omega*time);
146             newU.z() = 0.0;
148             this->operator[](faceI) = newU;
149         };
151         curTimeIndex_ = this->db().time().timeIndex();
152     }
154     fixedValueFvPatchVectorField::updateCoeffs();
158 // Write
159 void linearWaveVelocityFvPatchField::write(Ostream& os) const
161     fvPatchVectorField::write(os);
162     os.writeKeyword("amplitude")
163         << amplitude_ << token::END_STATEMENT << nl;
164     os.writeKeyword("period")
165         << period_ << token::END_STATEMENT << nl;
166     os.writeKeyword("valueAbove")
167         << valueAbove_ << token::END_STATEMENT << nl;
168     writeEntry("value", os);
172 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
174 makePatchTypeField(fvPatchVectorField, linearWaveVelocityFvPatchField);
176 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
178 } // End namespace Foam
180 // ************************************************************************* //