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-------------------------------------------------------------------------------
11License
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
27Namespace
28 Foam::Elliptic
29
30Description
31
32\*---------------------------------------------------------------------------*/
33
35
36using namespace Foam::constant;
37
38// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39
40namespace Foam
41{
42namespace Elliptic
43{
44
45// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46
47void 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
84Foam::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
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// ************************************************************************* //
CGAL::Exact_predicates_exact_constructions_kernel K
label n
const uniformDimensionedVectorField & g
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: FixedList.H:81
void JacobiSnCnDn(const scalar u, const scalar m, scalar &Sn, scalar &Cn, scalar &Dn)
Definition: Elliptic.H:134
void ellipticIntegralsKE(const scalar m, scalar &K, scalar &E)
Definition: Elliptic.H:47
Foam::scalar JacobiAmp(const scalar u, const scalar mIn)
Definition: Elliptic.H:84
constexpr scalar pi(M_PI)
Different types of constants.
Namespace for OpenFOAM.
dimensionedScalar asin(const dimensionedScalar &ds)
dimensionedScalar exp(const dimensionedScalar &ds)
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
dimensionedScalar sin(const dimensionedScalar &ds)
dimensionedScalar sqrt(const dimensionedScalar &ds)
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
static scalar Sn(const scalar a, const scalar x)
Definition: invIncGamma.C:70
dimensionedScalar atan(const dimensionedScalar &ds)
dimensionedScalar cos(const dimensionedScalar &ds)