diff --git a/src/waveModels/waveGenerationModels/base/irregularWaveModel/irregularWaveModel.C b/src/waveModels/waveGenerationModels/base/irregularWaveModel/irregularWaveModel.C new file mode 100644 index 0000000000000000000000000000000000000000..a1b3d503f8ff4ed6cc9ae183a31f78b5dde10cd5 --- /dev/null +++ b/src/waveModels/waveGenerationModels/base/irregularWaveModel/irregularWaveModel.C @@ -0,0 +1,104 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015 IH-Cantabria +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "irregularWaveModel.H" +#include "mathematicalConstants.H" + +using namespace Foam::constant; + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace waveModels +{ + defineTypeNameAndDebug(irregularWaveModel, 0); +} +} + + +// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // + +Foam::scalar Foam::waveModels::irregularWaveModel::timeCoeff +( + const scalar t +) const +{ + return max(0, min(t/rampTime_, 1)); +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::waveModels::irregularWaveModel::irregularWaveModel +( + const dictionary& dict, + const fvMesh& mesh, + const polyPatch& patch, + const bool readFields +) +: + waveGenerationModel(dict, mesh, patch, false), + rampTime_(VSMALL) +{ + if (readFields) + { + readDict(dict); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::waveModels::irregularWaveModel::~irregularWaveModel() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::waveModels::irregularWaveModel::readDict +( + const dictionary& overrideDict +) +{ + if (waveGenerationModel::readDict(overrideDict)) + { + lookup("rampTime") >> rampTime_; + + return true; + } + + return false; +} + + +void Foam::waveModels::irregularWaveModel::info(Ostream& os) const +{ + waveGenerationModel::info(os); + + os << " Ramp time : " << rampTime_ << nl; +} + + +// ************************************************************************* // diff --git a/src/waveModels/waveGenerationModels/base/irregularWaveModel/irregularWaveModel.H b/src/waveModels/waveGenerationModels/base/irregularWaveModel/irregularWaveModel.H new file mode 100644 index 0000000000000000000000000000000000000000..02a816405a7e6f59e3f2b207a04a80e9a0aa13fc --- /dev/null +++ b/src/waveModels/waveGenerationModels/base/irregularWaveModel/irregularWaveModel.H @@ -0,0 +1,110 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015 IH-Cantabria +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::waveModels::irregularWaveModel + +Description + +\*---------------------------------------------------------------------------*/ + +#ifndef waveModels_irregularWaveModel_H +#define waveModels_irregularWaveModel_H + +#include "waveGenerationModel.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace waveModels +{ + +/*---------------------------------------------------------------------------*\ + Class irregularWaveModel Declaration +\*---------------------------------------------------------------------------*/ + +class irregularWaveModel +: + public waveGenerationModel +{ + // Private Member Functions + + //- Disallow default bitwise copy construct + irregularWaveModel(const irregularWaveModel&); + + //- Disallow default bitwise assignment + void operator=(const irregularWaveModel&); + + +protected: + + // Protected data + + //- Ramp time + scalar rampTime_; + + // Protected Member Functions + + //- Return the time scaling coefficient + virtual scalar timeCoeff(const scalar t) const; + +public: + + //- Runtime type information + TypeName("irregularWaveModel"); + + + //- Constructor + irregularWaveModel + ( + const dictionary& dict, + const fvMesh& mesh, + const polyPatch& patch, + const bool readFields = true + ); + + //- Destructor + virtual ~irregularWaveModel(); + + + // Public Member Functions + + //- Read from dictionary + virtual bool readDict(const dictionary& overrideDict); + + //- Info + virtual void info(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace waveModels +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/waveModels/waveGenerationModels/derived/irregularWavesMultiDirec/irregularWavesMultiDirecWaveModel.C b/src/waveModels/waveGenerationModels/derived/irregularWavesMultiDirec/irregularWavesMultiDirecWaveModel.C new file mode 100644 index 0000000000000000000000000000000000000000..eabf76acb68cb067426e88ab184768a5ae74328e --- /dev/null +++ b/src/waveModels/waveGenerationModels/derived/irregularWavesMultiDirec/irregularWavesMultiDirecWaveModel.C @@ -0,0 +1,339 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015 IH-Cantabria +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#include "irregularWavesMultiDirecWaveModel.H" +#include "mathematicalConstants.H" +#include "addToRunTimeSelectionTable.H" + +using namespace Foam::constant; + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +namespace Foam +{ +namespace waveModels +{ + defineTypeNameAndDebug(irregularWavesMultiDirec, 0); + addToRunTimeSelectionTable + ( + waveModel, + irregularWavesMultiDirec, + patch + ); +} +} + + +// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * // + +// First order wave height +Foam::scalar Foam::waveModels::irregularWavesMultiDirec::eta +( + const scalar H, + const scalar Kx, + const scalar x, + const scalar Ky, + const scalar y, + const scalar omega, + const scalar t, + const scalar phase +) const +{ + scalar phaseTot = Kx*x + Ky*y - omega*t + phase; + return H*0.5*cos(phaseTot); +} + + +// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * // + +//Calculate waveLength +Foam::scalar Foam::waveModels::irregularWavesMultiDirec::waveLength +( + const scalar h, + const scalar T +) const +{ + scalar L0 = mag(g_)*T*T/(2.0*mathematical::pi); + scalar L = L0; + + for (int iii=1; iii<=100; iii++) + { + L = L0*tanh(2.0*mathematical::pi*h/L); + } + + return L; +} + + +Foam::vector Foam::waveModels::irregularWavesMultiDirec::U +( + const scalar h, + const scalar x, + const scalar y, + const scalar t, + const scalar z +) const +{ + scalar u = 0.0; + scalar v = 0.0; + scalar w = 0.0; + + scalar phaseTot = 0.0; + scalar waveKs_ = 0.0; + scalar waveOmegas_ = 0.0; + + int ii; + int jj; + scalar COLUMNAS = 0; + scalar FILAS = irregWaveHeights_.size(); + + for (ii=0; ii<FILAS; ++ii) + { + COLUMNAS= irregWaveHeights_[ii].size(); + + for (jj=0; jj<COLUMNAS; ++jj) + { + waveKs_ = mathematical::twoPi/irregWaveLengths_[ii][jj]; + waveOmegas_ = mathematical::twoPi/irregWavePeriods_[ii][jj]; + + phaseTot = waveKs_*x*cos(irregWaveDirs_[ii][jj]) + waveKs_*y*sin(irregWaveDirs_[ii][jj]) - waveOmegas_*t + irregWavePhases_[ii][jj]; + + const vector Uf = uMultiDirec + ( + irregWaveHeights_[ii][jj], + waveOmegas_, + phaseTot, + waveKs_, + z, + h, + irregWaveDirs_[ii][jj] + ); + u = u + Uf[0]; + v = v + Uf[1]; + w = w + Uf[2]; + } + } + + return vector(u, v, w); +} + + +void Foam::waveModels::irregularWavesMultiDirec::setLevel +( + const scalar t, + const scalar tCoeff, + scalarField& level +) const +{ + scalar eta = 0.0; + + scalar COLUMNAS = 0; + scalar FILAS = 0; + + scalar waveKs_ = 0.0; + scalar waveOmegas_ = 0.0; + + int ii; + int jj; + + forAll(level, paddlei) + { + eta = 0.0; + FILAS= irregWaveHeights_.size(); + + for (ii=0; ii<FILAS; ++ii) + { + COLUMNAS= irregWaveHeights_[ii].size(); + + for (jj=0; jj<COLUMNAS; ++jj) + { + waveKs_ = mathematical::twoPi/irregWaveLengths_[ii][jj]; + waveOmegas_ = mathematical::twoPi/irregWavePeriods_[ii][jj]; + + eta += + this->eta + ( + irregWaveHeights_[ii][jj], + waveKs_*cos(irregWaveDirs_[ii][jj]), + xPaddle_[paddlei], + waveKs_*sin(irregWaveDirs_[ii][jj]), + yPaddle_[paddlei], + waveOmegas_, + t, + irregWavePhases_[ii][jj] + ); + } + } + + level[paddlei] = waterDepthRef_ + tCoeff*eta; + } +} + +Foam::vector Foam::waveModels::irregularWavesMultiDirec::uMultiDirec +( + const scalar irregH, + const scalar irregWaveOmega, + const scalar pha, + const scalar irregWaveKs, + const scalar zz, + const scalar hh, + const scalar irregDir +) const +{ + + scalar u = + irregH*0.5*irregWaveOmega* + cos(pha)* + (cosh(irregWaveKs*zz)/ + sinh(irregWaveKs*hh))* + cos(irregDir); + + scalar v = + irregH*0.5*irregWaveOmega* + cos(pha)* + (cosh(irregWaveKs*zz)/ + sinh(irregWaveKs*hh))* + sin(irregDir); + + scalar w = + irregH*0.5*irregWaveOmega* + sin(pha)* + (sinh(irregWaveKs*zz)/ + sinh(irregWaveKs*hh)); + + return vector(u, v, w); +} + +void Foam::waveModels::irregularWavesMultiDirec::setVelocity +( + const scalar t, + const scalar tCoeff, + const scalarField& level +) +{ + forAll(U_, facei) + { + // Fraction of geometry represented by paddle - to be set + scalar fraction = 1; + + // Height - to be set + scalar z = 0; + + setPaddlePropeties(level, facei, fraction, z); + + if (fraction > 0) + { + const label paddlei = faceToPaddle_[facei]; + + const vector Uf = U + ( + waterDepthRef_, + xPaddle_[paddlei], + yPaddle_[paddlei], + t, + z + ); + + U_[facei] = fraction*Uf*tCoeff; + + } + } + +} + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::waveModels::irregularWavesMultiDirec::irregularWavesMultiDirec +( + const dictionary& dict, + const fvMesh& mesh, + const polyPatch& patch, + const bool readFields +) +: + irregularWaveModel(dict, mesh, patch, false) +{ + if (readFields) + { + readDict(dict); + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::waveModels::irregularWavesMultiDirec::~irregularWavesMultiDirec() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::waveModels::irregularWavesMultiDirec::readDict(const dictionary& overrideDict) +{ + int ii; + int jj; + + if (irregularWaveModel::readDict(overrideDict)) + { + + lookup("irregWavePeriods") >> irregWavePeriods_; + lookup("irregWaveHeights") >> irregWaveHeights_; + lookup("irregWavePhases") >> irregWavePhases_; + lookup("irregWaveDirs") >> irregWaveDirs_; + + irregWaveLengths_ = irregWaveHeights_; + scalar COLUMNAS = 0; + scalar FILAS = irregWaveHeights_.size(); + + for (ii=0; ii<FILAS; ++ii) + { + COLUMNAS= irregWaveHeights_[ii].size(); + + for (jj=0; jj<COLUMNAS; ++jj) + { + irregWaveLengths_[ii][jj] = waveLength (waterDepthRef_, irregWavePeriods_[ii][jj]); + irregWaveDirs_[ii][jj] = irregWaveDirs_[ii][jj] * (mathematical::pi/180); + } + } + + return true; + + } + + return false; +} + +void Foam::waveModels::irregularWavesMultiDirec::info(Ostream& os) const +{ + irregularWaveModel::info(os); + + os << " WavePeriods (s) coefficients : " << irregWavePeriods_ << nl + << " WaveHeights (m) coefficients : " << irregWaveHeights_ << nl + << " WavePhases (rad) coefficients : " << irregWavePhases_ << nl + << " WaveLengths (m) coefficients : " << irregWaveLengths_ << nl + << " WaveDirections (rad) coefficients : " << irregWaveDirs_ << nl; +} + +// ************************************************************************* // diff --git a/src/waveModels/waveGenerationModels/derived/irregularWavesMultiDirec/irregularWavesMultiDirecWaveModel.H b/src/waveModels/waveGenerationModels/derived/irregularWavesMultiDirec/irregularWavesMultiDirecWaveModel.H new file mode 100644 index 0000000000000000000000000000000000000000..eaf10678ce4fb7a74284a698a5812f5e8d157a54 --- /dev/null +++ b/src/waveModels/waveGenerationModels/derived/irregularWavesMultiDirec/irregularWavesMultiDirecWaveModel.H @@ -0,0 +1,174 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015 IH-Cantabria +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Class + Foam::waveModels::irregularWavesMultiDirec + +Description + Multi-directional irregular wave model + +\*---------------------------------------------------------------------------*/ + +#ifndef waveModels_irregularWavesMultiDirec_H +#define waveModels_irregularWavesMultiDirec_H + +#include "irregularWaveModel.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ +namespace waveModels +{ + +/*---------------------------------------------------------------------------*\ + Class irregularWavesMultiDirec Declaration +\*---------------------------------------------------------------------------*/ + +class irregularWavesMultiDirec +: + public irregularWaveModel +{ +private: + + // Proteced Data + + //- Wave periods for irregularWavesMultiDirec case (seconds) + List< List<scalar> > irregWavePeriods_; + + //- Wave heights for irregularWavesMultiDirec case (meters) + List< List<scalar> > irregWaveHeights_; + + //- Wave lengths for irregularWavesMultiDirec case (meters) + List< List<scalar> > irregWaveLengths_; + + //- Wave phases for irregularWavesMultiDirec case (radians) + List< List<scalar> > irregWavePhases_; + + //- Direction of propagation for irregularWavesMultiDirec case (degrees, from X axis) + List< List<scalar> > irregWaveDirs_; + + + // Private Member Functions + + //- First Order Wave height (same as StokesI) + virtual scalar eta + ( + const scalar H, + const scalar Kx, + const scalar x, + const scalar Ky, + const scalar y, + const scalar omega, + const scalar t, + const scalar phase + ) const; + + +protected: + + // Protected Member Functions + + //- Return the wavelength + virtual scalar waveLength + ( + const scalar h, + const scalar T + ) const; + + //- Wave velocity + virtual vector U + ( + const scalar d, + const scalar x, + const scalar y, + const scalar t, + const scalar z + ) const; + + //- + virtual vector uMultiDirec + ( + const scalar irregH, + const scalar irregWaveOmega, + const scalar phaseTot, + const scalar irregWaveKs, + const scalar z, + const scalar h, + const scalar irregDir + ) const; + + //- Set the water level + virtual void setLevel + ( + const scalar t, + const scalar tCoeff, + scalarField& level + ) const; + + //- Calculate the wave model velocity + virtual void setVelocity + ( + const scalar t, + const scalar tCoeff, + const scalarField& level + ); + +public: + + //- Runtime type information + TypeName("irregularWavesMultiDirectional"); + + //- Constructor + irregularWavesMultiDirec + ( + const dictionary& dict, + const fvMesh& mesh, + const polyPatch& patch, + const bool readFields = true + ); + + //- Destructor + virtual ~irregularWavesMultiDirec(); + + + // Public Member Functions + + //- Read from dictionary + virtual bool readDict(const dictionary& overrideDict); + + //- Info + virtual void info(Ostream& os) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace waveModels +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //