SquareI.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-2019 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 "Square.H"
27 #include "mathematicalConstants.H"
28 
29 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
30 
31 template<class Type>
32 inline Type Foam::Function1s::Square<Type>::value(const scalar x) const
33 {
34  const scalar markFraction = markSpace_/(1 + markSpace_);
35 
36  const scalar phi = frequency_*(x - start_);
37  const scalar fraction = phi - floor(phi);
38 
39  return
40  amplitude_->value(x)*(fraction < markFraction ? 1 : -1)
41  + level_->value(x);
42 }
43 
44 
45 template<class Type>
47 (
48  const scalar x1,
49  const scalar x2
50 ) const
51 {
52  if (!integrable_)
53  {
55  << "Integration is not defined for " << type() << " functions "
56  << "unless the amplitude is constant"
57  << exit(FatalError);
58  }
59 
60  auto integrate0 = [&](const scalar x)
61  {
62  const scalar markFraction = markSpace_/(1 + markSpace_);
63 
64  const scalar phi = frequency_*(x - start_);
65  const scalar fraction = phi - floor(phi);
66 
67  return
68  (2*amplitude_->value(x)/frequency_)
69  *(
70  markFraction*floor(phi + 1 - markFraction)
71  + fraction*(fraction < markFraction ? 1 : 0)
72  - frequency_/2*x
73  );
74  };
75 
76  return integrate0(x2) - integrate0(x1) + level_->integrate(x1, x2);
77 }
78 
79 
80 // ************************************************************************* //
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual Type value(const scalar x) const
Return value.
Definition: SquareI.H:32
phi
Definition: pEqn.H:104
virtual Type integrate(const scalar x1, const scalar x2) const
Integrate between two values.
Definition: SquareI.H:47
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488