SDDSlib
Loading...
Searching...
No Matches
elliptic.c File Reference

Functions for evaluating complete elliptic integrals of the first and second kind (K and E), as well as their total derivatives with respect to the modulus k. More...

#include "mdb.h"

Go to the source code of this file.

Functions

void setCeiAccuracy (double newAccuracy)
 
double K_cei (double k)
 Compute the complete elliptic integral of the first kind, K(k).
 
double E_cei (double k)
 Compute the complete elliptic integral of the second kind, E(k).
 
double * KE_cei (double k, double *buffer)
 
double dK_cei (double k)
 Compute the total derivative dK/dk of the complete elliptic integral of the first kind.
 
double dE_cei (double k)
 Compute the total derivative dE/dk of the complete elliptic integral of the second kind.
 

Variables

static double ceiAccuracy = 1e-14
 

Detailed Description

Functions for evaluating complete elliptic integrals of the first and second kind (K and E), as well as their total derivatives with respect to the modulus k.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file elliptic.c.

Function Documentation

◆ dE_cei()

double dE_cei ( double k)

Compute the total derivative dE/dk of the complete elliptic integral of the second kind.

Uses K(k) and E(k) to determine the derivative with respect to k.

Parameters
[in]kThe modulus of the elliptic integral.
Returns
The value of dE/dk.

Definition at line 143 of file elliptic.c.

144{
145 double buffer[2];
146 KE_cei(k, buffer);
147 return (buffer[1] - buffer[0]) / k;
148}

◆ dK_cei()

double dK_cei ( double k)

Compute the total derivative dK/dk of the complete elliptic integral of the first kind.

Uses K(k) and E(k) to determine the derivative with respect to k.

Parameters
[in]kThe modulus of the elliptic integral.
Returns
The value of dK/dk.

Definition at line 129 of file elliptic.c.

129 {
130 double buffer[2];
131 KE_cei(k, buffer);
132 return (buffer[1] / (1 - k * k) - buffer[0]) / k;
133}

◆ E_cei()

double E_cei ( double k)

Compute the complete elliptic integral of the second kind, E(k).

E(k) = ∫_0^(π/2) √(1 - k² sin² θ) dθ

Parameters
[in]kThe modulus of the elliptic integral.
Returns
The value of E(k).

Definition at line 59 of file elliptic.c.

59 {
60 double a0, b0, c0, a1, b1, c1, K, sum, powerOf2;
61
62 a0 = 1;
63 b0 = sqrt(1 - sqr(k));
64 c0 = k;
65 sum = sqr(c0);
66 powerOf2 = 1;
67
68 do {
69 /* do two steps of recurrence per pass in the loop */
70 a1 = (a0 + b0) / 2;
71 b1 = sqrt(a0 * b0);
72 c1 = (a0 - b0) / 2;
73 sum += sqr(c1) * (powerOf2 *= 2);
74 ;
75
76 a0 = (a1 + b1) / 2;
77 b0 = sqrt(a1 * b1);
78 c0 = (a1 - b1) / 2;
79 sum += sqr(c0) * (powerOf2 *= 2);
80 } while (fabs(c0) > ceiAccuracy);
81
82 K = PI / (2 * a0);
83 return K * (1 - sum / 2);
84}

◆ K_cei()

double K_cei ( double k)

Compute the complete elliptic integral of the first kind, K(k).

K(k) = ∫_0^(π/2) dθ / √(1 - k² sin² θ)

Parameters
[in]kThe modulus of the elliptic integral.
Returns
The value of K(k).

Definition at line 33 of file elliptic.c.

33 {
34 double a0, b0, c0, a1, b1;
35
36 a0 = 1;
37 b0 = sqrt(1 - sqr(k));
38 c0 = k;
39
40 do {
41 /* do two steps of recurrence per pass in the loop */
42 a1 = (a0 + b0) / 2;
43 b1 = sqrt(a0 * b0);
44 a0 = (a1 + b1) / 2;
45 b0 = sqrt(a1 * b1);
46 c0 = (a1 - b1) / 2;
47 } while (fabs(c0) > ceiAccuracy);
48 return PI / (2 * a0);
49}

◆ KE_cei()

double * KE_cei ( double k,
double * buffer )

Definition at line 86 of file elliptic.c.

86 {
87 double a0, b0, c0, a1, b1, c1, K, sum, powerOf2;
88
89 if (!buffer)
90 buffer = tmalloc(sizeof(*buffer) * 2);
91
92 a0 = 1;
93 b0 = sqrt(1 - sqr(k));
94 c0 = k;
95 sum = sqr(c0);
96 powerOf2 = 1;
97
98 do {
99 /* do two steps of recurrence per pass in the loop */
100 a1 = (a0 + b0) / 2;
101 b1 = sqrt(a0 * b0);
102 c1 = (a0 - b0) / 2;
103 sum += sqr(c1) * (powerOf2 *= 2);
104 ;
105
106 a0 = (a1 + b1) / 2;
107 b0 = sqrt(a1 * b1);
108 c0 = (a1 - b1) / 2;
109 sum += sqr(c0) * (powerOf2 *= 2);
110 } while (fabs(c0) > ceiAccuracy);
111
112 buffer[0] = K = PI / (2 * a0);
113 buffer[1] = K * (1 - sum / 2);
114 return buffer;
115}
void * tmalloc(uint64_t size_of_block)
Allocates a memory block of the specified size with zero initialization.
Definition array.c:59

◆ setCeiAccuracy()

void setCeiAccuracy ( double newAccuracy)

Definition at line 21 of file elliptic.c.

21 {
22 ceiAccuracy = newAccuracy;
23}

Variable Documentation

◆ ceiAccuracy

double ceiAccuracy = 1e-14
static

Definition at line 19 of file elliptic.c.