Elliptic.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2015 IH-Cantabria
9  Copyright (C) 2016 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Namespace
28  Foam::Elliptic
29 
30 Description
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #include "mathematicalConstants.H"
35 
36 using namespace Foam::constant;
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 namespace Elliptic
43 {
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 void ellipticIntegralsKE(const scalar m, scalar& K, scalar& E)
48 {
49  if (m == 0)
50  {
51  K = 0.5*mathematical::pi;
52  E = 0.5*mathematical::pi;
53  return;
54  }
55 
56  scalar a = 1;
57  scalar g = Foam::sqrt(1 - m);
58  scalar ga = g*a;
59  scalar aux = 1;
60  scalar sum = 2 - m;
61 
62  while (true)
63  {
64  scalar aOld = a;
65  scalar gOld = g;
66  ga = gOld*aOld;
67  a = 0.5*(gOld + aOld);
68  aux += aux;
69  sum -= aux*(a*a - ga);
70 
71  if (mag(aOld - gOld) < SMALL)
72  {
73  break;
74  }
75 
76  g = sqrt(ga);
77  }
78 
79  K = 0.5*mathematical::pi/a;
80  E = 0.25*mathematical::pi/a*sum;
81 }
82 
83 
84 Foam::scalar JacobiAmp(const scalar u, const scalar mIn)
85 {
86  static const label ITER = 25;
88  scalar aux, amp;
89  label n;
90 
91  const scalar m = mag(mIn);
92 
93  if (m == 0)
94  {
95  return u;
96  }
97 
98  if (m == 1)
99  {
100  return 2*atan(exp(u)) - mathematical::pi/2;
101  }
102 
103  a[0] = 1.0;
104  g[0] = Foam::sqrt(1.0 - m);
105  c[0] = Foam::sqrt(m);
106 
107  aux = 1.0;
108 
109  for (n = 0; n < ITER; n++)
110  {
111  if (mag(a[n] - g[n]) < SMALL)
112  {
113  break;
114  }
115 
116  aux += aux;
117  a[n+1] = 0.5*(a[n] + g[n]);
118  g[n+1] = Foam::sqrt(a[n]*g[n]);
119  c[n+1] = 0.5*(a[n] - g[n]);
120  }
121 
122  amp = aux*a[n]*u;
123 
124  for (; n > 0; n--)
125  {
126  amp = 0.5*(amp + asin(c[n]*sin(amp)/a[n]));
127  }
128 
129  return scalar(amp);
130 }
131 
132 
133 void JacobiSnCnDn
134 (
135  const scalar u,
136  const scalar m,
137  scalar& Sn,
138  scalar& Cn,
139  scalar& Dn
140 )
141 {
142  const scalar amp = Elliptic::JacobiAmp(u, m);
143 
144  Sn = sin(amp);
145  Cn = cos(amp);
146  Dn = sqrt(1.0 - m*sin(amp)*sin(amp));
147  return;
148 }
149 
150 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
151 
152 } // End namespace Elliptic
153 } // End namespace Foam
154 
155 // ************************************************************************* //
mathematicalConstants.H
Foam::constant
Different types of constants.
Definition: atomicConstants.C:38
Foam::sin
dimensionedScalar sin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:264
Foam::exp
dimensionedScalar exp(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:261
K
CGAL::Exact_predicates_exact_constructions_kernel K
Definition: CGALTriangulation3DKernel.H:58
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::Elliptic::JacobiSnCnDn
void JacobiSnCnDn(const scalar u, const scalar m, scalar &Sn, scalar &Cn, scalar &Dn)
Definition: Elliptic.H:134
Foam::Elliptic::ellipticIntegralsKE
void ellipticIntegralsKE(const scalar m, scalar &K, scalar &E)
Definition: Elliptic.H:47
Foam::Elliptic::JacobiAmp
Foam::scalar JacobiAmp(const scalar u, const scalar mIn)
Definition: Elliptic.H:84
g
const uniformDimensionedVectorField & g
Definition: createFluidFields.H:26
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::constant::mathematical::pi
constexpr scalar pi(M_PI)
Foam::Sn
static scalar Sn(const scalar a, const scalar x)
Definition: invIncGamma.C:68
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::FixedList
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:104
Foam::sum
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:327
Foam::atan
dimensionedScalar atan(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:269
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::asin
dimensionedScalar asin(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:267
Foam::cos
dimensionedScalar cos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:265