Initial commit of NavalHydro package from Wikki to the ShipHydroSIG
[ShipHydroSIG.git] / src / vofDynamicMesh / lnInclude / numericalBeachFvPatchField.C
blob68ff8978e74f28b21b2917c4e802522ab2bf1ea6
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 "numericalBeachFvPatchField.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "volFields.H"
30 #include "surfaceFields.H"
31 #include "patchWave.H"
32 #include "mathematicalConstants.H"
33 #include "inletOutletFvPatchFields.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 using namespace Foam::mathematicalConstant;
39 namespace Foam
42 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
44 numericalBeachFvPatchField::numericalBeachFvPatchField
46     const fvPatch& p,
47     const DimensionedField<vector, volMesh>& iF
50     inletOutletFvPatchField<vector>(p, iF),
51     thickness_(0.0),
52     offset_(0.0),
53     nud_(0.0)
57 numericalBeachFvPatchField::numericalBeachFvPatchField
59     const numericalBeachFvPatchField& ptf,
60     const fvPatch& p,
61     const DimensionedField<vector, volMesh>& iF,
62     const fvPatchFieldMapper& mapper
65     inletOutletFvPatchField<vector>(ptf, p, iF, mapper),
66     thickness_(ptf.thickness_),
67     offset_(ptf.offset_),
68     nud_(ptf.nud_)
72 numericalBeachFvPatchField::numericalBeachFvPatchField
74     const fvPatch& p,
75     const DimensionedField<vector, volMesh>& iF,
76     const dictionary& dict
79     inletOutletFvPatchField<vector>(p, iF, dict),
80     thickness_(readScalar(dict.lookup("thickness"))),
81     nud_(readScalar(dict.lookup("nud")))
83     if (dict.found("offset"))
84     {
85         offset_ = readScalar(dict.lookup("offset", 0.0));
87         if (offset_ > thickness_)
88         {
89             FatalErrorIn
90             (
91                 "numericalBeachFvPatchField::numericalBeachFvPatchField("
92                 "const fvPatch& p,"
93                 "const DimensionedField<vector, volMesh>& iF,"
94                 "const dictionary& dict)"
95             )
96             << "Offset must be smaller than thickness"
97             << exit(FatalError);
98         }
99     }
103 numericalBeachFvPatchField::numericalBeachFvPatchField
105     const numericalBeachFvPatchField& pivpvf
108     inletOutletFvPatchField<vector>(pivpvf),
109     thickness_(pivpvf.thickness_),
110     offset_(pivpvf.offset_),
111     nud_(pivpvf.nud_)
115 numericalBeachFvPatchField::numericalBeachFvPatchField
117     const numericalBeachFvPatchField& pivpvf,
118     const DimensionedField<vector, volMesh>& iF
121     inletOutletFvPatchField<vector>(pivpvf, iF),
122     thickness_(pivpvf.thickness_),
123     offset_(pivpvf.offset_),
124     nud_(pivpvf.nud_)
128 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
130 void numericalBeachFvPatchField::updateCoeffs()
132     inletOutletFvPatchField<vector>::updateCoeffs();
136 tmp<volScalarField> numericalBeachFvPatchField::internalDamping() const
138     // Get patchids of walls
139     labelHashSet wallPatchIDs(1);
140     wallPatchIDs.insert(this->patch().index());
142     // Calculate distance starting from wallPatch faces.
143     patchWave wave(patch().boundaryMesh().mesh(), wallPatchIDs, false);
145     const scalarField& distance = wave.distance();
147     const fvMesh& mesh = this->patch().boundaryMesh().mesh();
149     tmp<volScalarField> tDamping
150     (
151         new volScalarField
152         (
153             IOobject
154             (
155                 "damping",
156                 mesh.time().timeName(),
157                 mesh,
158                 IOobject::NO_READ,
159                 IOobject::NO_WRITE
160             ),
161             mesh,
162             dimensionedScalar("zero", dimensionSet(0, 0, -1, 0, 0), 0.0)
163         )
164     );
166     volScalarField& damping = tDamping();
168     forAll(distance, cellI)
169     {
170         if ( distance[cellI] < offset_ )
171         {
172             damping[cellI] = nud_;
173         }
174         else if ( distance[cellI] < thickness_ )
175         {
176             scalar nonDimDist =
177                 (distance[cellI] - offset_)/(thickness_ - offset_);
179             damping[cellI] = nud_*(0.5 + 0.5*cos(pi*nonDimDist));
180         }
181     }
183     return tDamping;
187 void
188 numericalBeachFvPatchField::write(Ostream& os) const
190     inletOutletFvPatchField<vector>::write(os);
192     os.writeKeyword("thickness") << thickness_ << token::END_STATEMENT << nl;
193     if ( offset_ > 0 )
194     {
195         os.writeKeyword("offset") << offset_ << token::END_STATEMENT << nl;
196     }
197     os.writeKeyword("nud") << nud_ << token::END_STATEMENT << nl;
202 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
204 makePatchTypeField
206     fvPatchVectorField,
207     numericalBeachFvPatchField
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 } // End namespace Foam
214 // ************************************************************************* //