SineI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2017-2020 OpenFOAM Foundation
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 
26 #include "Sine.H"
27 #include "mathematicalConstants.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
32 inline Type Foam::Function1s::Sine<Type>::value(const scalar x) const
33 {
34  const scalar phi = constant::mathematical::twoPi*frequency_*(x - start_);
35 
36  return amplitude_->value(x)*sin(phi) + level_->value(x);
37 }
38 
39 
40 template<class Type>
42 (
43  const scalar x1,
44  const scalar x2
45 ) const
46 {
47  using namespace constant::mathematical;
48 
49  if (!integrable_)
50  {
52  << "Integration is not defined for " << type() << " functions "
53  << "unless the amplitude is constant"
54  << exit(FatalError);
55  }
56 
57  const scalar phi1 = constant::mathematical::twoPi*frequency_*(x1 - start_);
58  const scalar phi2 = constant::mathematical::twoPi*frequency_*(x2 - start_);
59 
60  return
61  - amplitude_->value(NaN)*(cos(phi2) - cos(phi1))/(twoPi*frequency_)
62  + level_->integral(x1, x2);
63 }
64 
65 
66 // ************************************************************************* //
virtual Type integral(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: SineI.H:42
virtual Type value(const scalar x) const
Return value.
Definition: SineI.H:32
const Type & value() const
Return const reference to value.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const scalar twoPi(2 *pi)
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
dimensionedScalar sin(const dimensionedScalar &ds)
error FatalError
dimensionedScalar cos(const dimensionedScalar &ds)
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488