HP-HEM  1.0.2
High Performance implementation of the Hybrid Electromagnetic Model
Data Structures | Enumerations | Functions
electrode.h File Reference
#include <complex.h>
#include <stdlib.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  Electrode
 
struct  Integration_data
 
struct  Field_integrand_data
 

Enumerations

enum  Integration_type { INTG_NONE = 1, INTG_DOUBLE = 2, INTG_SINGLE = 3, INTG_MHEM = 4 }
 

Functions

int populate_electrode (Electrode *electrode, const double start_point[3], const double end_point[3], double radius)
 
bool equal_electrodes (const Electrode *sender, const Electrode *receiver)
 
int electrodes_file (const char file_name[], Electrode *electrodes, size_t num_electrodes)
 
int nodes_file (const char file_name[], double *nodes, size_t num_nodes)
 
int segment_electrode (Electrode *electrodes, double *nodes, size_t num_segments, const double *start_point, const double *end_point, double radius)
 
size_t nodes_from_elecs (double *nodes, Electrode *electrodes, size_t num_electrodes)
 
int integrand_double (unsigned ndim, const double *t, void *auxdata, unsigned fdim, double *fval)
 
int integrand_single (unsigned ndim, const double *t, void *auxdata, unsigned fdim, double *fval)
 
int logNf (unsigned ndim, const double *t, void *auxdata, unsigned fdim, double *fval)
 
_Complex double self_integral (const Electrode *sender)
 
int integral (const Electrode *sender, const Electrode *receiver, _Complex double gamma, size_t max_eval, double req_abs_error, double req_rel_error, int integration_type, double result[2], double error[2])
 
int calculate_impedances (_Complex double *zl, _Complex double *zt, const Electrode *electrodes, size_t num_electrodes, _Complex double gamma, _Complex double s, double mur, _Complex double kappa, size_t max_eval, double req_abs_error, double req_rel_error, int integration_type)
 
int impedances_images (_Complex double *zl, _Complex double *zt, const Electrode *electrodes, const Electrode *images, size_t num_electrodes, _Complex double gamma, _Complex double s, double mur, _Complex double kappa, _Complex double ref_l, _Complex double ref_t, size_t max_eval, double req_abs_error, double req_rel_error, int integration_type)
 
_Complex double electric_potential (const double *point, const Electrode *electrodes, size_t num_electrodes, const _Complex double *it, _Complex double gamma, _Complex double kappa, size_t max_eval, double req_abs_error, double req_rel_error)
 
int magnetic_potential (const double *point, const Electrode *electrodes, size_t num_electrodes, const _Complex double *il, _Complex double gamma, double mur, size_t max_eval, double req_abs_error, double req_rel_error, _Complex double *va)
 
int elec_field_integrand (unsigned ndim, const double *t, void *auxdata, unsigned fdim, double *fval)
 
int electric_field (const double *point, const Electrode *electrodes, size_t num_electrodes, const _Complex double *il, const _Complex double *it, _Complex double gamma, _Complex double s, double mur, _Complex double kappa, size_t max_eval, double req_abs_error, double req_rel_error, _Complex double *ve)
 
int v_mag_pot_integrand (unsigned ndim, const double *t, void *auxdata, unsigned fdim, double *fval)
 
_Complex double voltage (const double *point1, const double *point2, const Electrode *electrodes, size_t num_electrodes, const _Complex double *il, const _Complex double *it, _Complex double gamma, _Complex double s, double mur, _Complex double kappa, size_t max_eval, double req_abs_error, double req_rel_error)
 

Enumeration Type Documentation

◆ Integration_type

Type of integration and simplification thereof to be done.

Enumerator
INTG_NONE 

No integration, returns the geometric distance between middle points

INTG_DOUBLE 

Traditional integral along both electrodes \( \int_0^{L_i} \int_0^{L_k} \frac{e^{-\gamma r}}{r} d\ell_k \, d\ell_i \)

INTG_SINGLE 

Traditional integral along sender electrodes \( \int_0^{L_k} \frac{e^{-\gamma r}}{r} d\ell_k \)

INTG_MHEM 

Modified HEM integral \( \int_0^{L_k} \log_e \left( \frac{R_1 + R_2 + L_i}{R_1 + R_2 - L_i} \right) d\ell_k \)

Definition at line 18 of file electrode.h.

Function Documentation

◆ calculate_impedances()

int calculate_impedances ( _Complex double *  zl,
_Complex double *  zt,
const Electrode electrodes,
size_t  num_electrodes,
_Complex double  gamma,
_Complex double  s,
double  mur,
_Complex double  kappa,
size_t  max_eval,
double  req_abs_error,
double  req_rel_error,
int  integration_type 
)

Calculates the impedance matrices \( Z_L, Z_T \). As they are symmetric, only their lower half is stored (set). If pointer zl = zt, then the resulting matrix will be filled with zt.
If integration_type == INTG_MHEM or integration_type == INTG_NONE, then parameters gamma, s, mur and kappa are ignored such that \( \frac{j\omega\mu}{4\pi} = \frac{1}{4\pi\,(\sigma + j\omega\varepsilon)} = 1 \).

Parameters
zllongitudinal impedance matrix \( Z_L \) as a flat array of size \( m^2 \)
zttransversal impedance matrix \( Z_T \) as a flat array of size \( m^2 \)
electrodesarray of electrodes
num_electrodesnumber of electrodes \( m \)
gammamedium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \)
scomplex angular frequency \( s = c + j\omega \) in [rad/s]
murrelative magnetic permeability of the medium \( \mu_r \)
kappamedium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m]
max_evalspecifies a maximum number of function evaluations (0 for no limit)
req_abs_errorthe absolute error requested (0 to ignore)
req_rel_errorthe relative error requested (0 to ignore)
integration_typetype of integration to be done.
Returns
0 on success
See also
integral
Integration_type
https://github.com/stevengj/cubature

◆ elec_field_integrand()

int elec_field_integrand ( unsigned  ndim,
const double *  t,
void *  auxdata,
unsigned  fdim,
double *  fval 
)

Integrand to calculate the electric field caused by a differential transversal current \( dI_T \).

Parameters
ndimshould be 1
tintegration variable (electrode percentage 0 to 1)
auxdatapointer to Field_integrand_data structure
fdimshould be 6 (Real and Imag.): \( (\Re(E_x), \Im(E_x), \Re(E_y), \Im(E_y), \Re(E_z), \Im(E_z)) \)
fvalwhere the results are stored \( (\Re(E_x), \Im(E_x), \Re(E_y), \Im(E_y), \Re(E_z), \Im(E_z)) \) return 0 on success
See also
https://github.com/stevengj/cubature
electric_field

◆ electric_field()

int electric_field ( const double *  point,
const Electrode electrodes,
size_t  num_electrodes,
const _Complex double *  il,
const _Complex double *  it,
_Complex double  gamma,
_Complex double  s,
double  mur,
_Complex double  kappa,
size_t  max_eval,
double  req_abs_error,
double  req_rel_error,
_Complex double *  ve 
)

Calculates the electric field at a point. \( \vec E = -\nabla u - s \vec A \)

Parameters
pointarray \( (x, y, z) \)
electrodesarray of electrodes
num_electrodesnumber of electrodes \( m \)
illongitudinal currents array \( I_L \)
ittransversal currents array \( I_T \)
gammamedium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \)
scomplex angular frequency \( s = c + j\omega \) in [rad/s]
murrelative magnetic permeability of the medium \( \mu_r \)
kappamedium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m]
max_evalspecifies a maximum number of function evaluations (0 for no limit)
req_abs_errorthe absolute error requested (0 to ignore)
req_rel_errorthe relative error requested (0 to ignore)
vepointer to array of size 3 in which the electric field components \( (E_x, E_y, E_z) \) will be add to on return.
Returns
0 on success
See also
elec_field_integrand

◆ electric_potential()

_Complex double electric_potential ( const double *  point,
const Electrode electrodes,
size_t  num_electrodes,
const _Complex double *  it,
_Complex double  gamma,
_Complex double  kappa,
size_t  max_eval,
double  req_abs_error,
double  req_rel_error 
)

Calculates the scalar electric potential \( u \) to remote earth at a point.

Parameters
pointarray \((x, y, z)\)
electrodesarray of electrodes
num_electrodesnumber of electrodes \( m \)
ittransversal currents array \( I_T \)
gammamedium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \)
kappamedium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m]
max_evalspecifies a maximum number of function evaluations (0 for no limit)
req_abs_errorthe absolute error requested (0 to ignore)
req_rel_errorthe relative error requested (0 to ignore)
Returns
potential \( u \) to remote earth
See also
https://github.com/stevengj/cubature

◆ electrodes_file()

int electrodes_file ( const char  file_name[],
Electrode electrodes,
size_t  num_electrodes 
)

Populates an Electrode array from a CSV file. Each Electrode must be defined in a single line with parameters: "x0, y0, z0, x1, y1, z1, radius".

Parameters
file_namepath to the file
electrodespointer to an array of Electrode to be filled
num_electrodesnumber of electrodes to read (number of lines in file). Any line number greater than num_electrodes will be ignored.
Returns
error == 0 on success
error < 0: number of missing arguments from last line read (as a negative integer)
error > 0: bad input

◆ equal_electrodes()

bool equal_electrodes ( const Electrode sender,
const Electrode receiver 
)

Compares two electrodes for equality: have the same radius and coincide the starts and end points (independent of direction).

Parameters
senderElectrode
receiverElectrode
Returns
true or false

◆ impedances_images()

int impedances_images ( _Complex double *  zl,
_Complex double *  zt,
const Electrode electrodes,
const Electrode images,
size_t  num_electrodes,
_Complex double  gamma,
_Complex double  s,
double  mur,
_Complex double  kappa,
_Complex double  ref_l,
_Complex double  ref_t,
size_t  max_eval,
double  req_abs_error,
double  req_rel_error,
int  integration_type 
)

Add the images' effect to the impedance matrices \( Z_L \) and \( Z_T \). As they are symmetric, only their lower half is stored (set). If pointer zl = zt, then the resulting matrix will be filled with zt.
If integration_type == INTG_MHEM or integration_type == INTG_NONE, then parameters gamma, s, mur, kappa, ref_l and ref_t are ignored such that \( \Gamma_L \frac{j\omega\mu}{4\pi} = \Gamma_T \frac{1}{4\pi\,(\sigma + j\omega\varepsilon)} = 1 \).

Parameters
zllongitudinal impedance matrix \( Z_L \) as a flat array of size \( m^2 \)
zttransversal impedance matrix \( Z_T \) as a flat array of size \( m^2 \)
electrodesarray of electrodes
imagesarray of electrodes
num_electrodesnumber of electrodes \( m \)
gammamedium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \)
scomplex angular frequency \( s = c + j\omega \) in [rad/s]
murrelative magnetic permeability of the medium \( \mu_r \)
kappamedium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m]
ref_llongitudinal current reflection coefficient \( \Gamma_L \)
ref_ttransversal current reflection coefficient \( \Gamma_T \)
max_evalspecifies a maximum number of function evaluations (0 for no limit)
req_abs_errorthe absolute error requested (0 to ignore)
req_rel_errorthe relative error requested (0 to ignore)
integration_typetype of integration to be done.
Returns
0 on success
See also
integral
Integration_type
https://github.com/stevengj/cubature

◆ integral()

int integral ( const Electrode sender,
const Electrode receiver,
_Complex double  gamma,
size_t  max_eval,
double  req_abs_error,
double  req_rel_error,
int  integration_type,
double  result[2],
double  error[2] 
)

Calculates the integral along the sender and receiver using Cubature. Note that the integration stops when either max_eval or req_abs_error or req_rel_error is reached.

Parameters
senderCurrent carrying Electrode that generates the excitation.
receiverPotential receiving Electrode that receives the excitation.
gammamedium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \)
max_evalspecifies a maximum number of function evaluations (0 for no limit)
req_abs_errorthe absolute error requested (0 to ignore)
req_rel_errorthe relative error requested (0 to ignore)
integration_typetype of integration to be done.
resultarray[2] where to store the integral result (real and imaginary parts)
errorarray[2] where to store the integral error (real and imaginary parts)
Returns
0 on success
-10 if integration_type is unrecognized.
See also
Integration_type
https://github.com/stevengj/cubature

◆ integrand_double()

int integrand_double ( unsigned  ndim,
const double *  t,
void *  auxdata,
unsigned  fdim,
double *  fval 
)

Calculates the integrand \( \frac{e^{-\gamma r}}{r} \) to be integrated using Cubature.

Parameters
ndimmust be = 2
tarray of size 2 of the electrodes' length as a percentage (0 to 1)
auxdataIntegration_data with electrodes and propagation constant
fdimmust be = 2
fvalpointer to where the result is stored
Returns
0 on success
See also
Integration_type
Integration_data
integral
https://github.com/stevengj/cubature

◆ integrand_single()

int integrand_single ( unsigned  ndim,
const double *  t,
void *  auxdata,
unsigned  fdim,
double *  fval 
)

Calculates the integrand \( \frac{e^{-\gamma r}}{r} \) to be integrated using Cubature; but the point on the receiver electrode is fixed at its middle.

Parameters
ndimmust be = 1
tarray of size 1 of the sender electrode's length as a percentage (0 to 1)
auxdataIntegration_data with electrodes and propagation constant
fdimmust be = 2
fvalpointer to where the result is stored
Returns
0 on success
See also
Integration_type
Integration_data
integral
https://github.com/stevengj/cubature

◆ logNf()

int logNf ( unsigned  ndim,
const double *  t,
void *  auxdata,
unsigned  fdim,
double *  fval 
)

Calculates the mHEM integrand \( \int_0^{L_k} \log_e \left( \frac{R_1 + R_2 + L_i}{R_1 + R_2 - L_i} \right) d\ell_k \) to be used in Cubature integration.

Parameters
ndimmust be = 1
tarray of size 1 with receiver's length percentage (0 to 1)
auxdataIntegration_data with electrodes and propagation constant
fdimmust be = 2
fvalpointer to where the result is stored
Returns
0 on success
See also
Integration_type
Integration_data
integral
https://github.com/stevengj/cubature

◆ magnetic_potential()

int magnetic_potential ( const double *  point,
const Electrode electrodes,
size_t  num_electrodes,
const _Complex double *  il,
_Complex double  gamma,
double  mur,
size_t  max_eval,
double  req_abs_error,
double  req_rel_error,
_Complex double *  va 
)

Calculates the magnetic vector potential \( \vec A \).

Parameters
pointarray \((x, y, z)\)
electrodesarray of electrodes
num_electrodesnumber of electrodes \( m \)
illongitudinal currents array \( I_L \)
gammamedium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \)
murrelative magnetic permeability of the medium \( \mu_r \)
max_evalspecifies a maximum number of function evaluations (0 for no limit)
req_abs_errorthe absolute error requested (0 to ignore)
req_rel_errorthe relative error requested (0 to ignore)
vapointer to array of size 3 in which the magnetic vector potential components \( (A_x,A_y,A_z) \) will be stored on return.
Returns
0 on success
See also
https://github.com/stevengj/cubature

◆ nodes_file()

int nodes_file ( const char  file_name[],
double *  nodes,
size_t  num_nodes 
)

Fill a nodes array from a CSV file. Each node must be defined in a single line with parameters: "x, y, z".

Parameters
file_namepath to the file
nodesarray of double[3] to be filled
num_nodesnumber of nodes to read (number of lines in file). Any line number greater than num_nodes will be ignored.
Returns
error == 0 on success
error < 0: number of missing arguments from last line read (as a negative integer)
error > 0: bad input

◆ nodes_from_elecs()

size_t nodes_from_elecs ( double *  nodes,
Electrode electrodes,
size_t  num_electrodes 
)

DON'T USE THIS FUNCTIONS, IT'S BUGGED.

Given an array of electrodes, populates the nodes array with all the unique nodes.

Parameters
nodesflat array of size \(n \ge 3(m + 1)\) to be filled with the unique nodes.
electrodesarray of electrodes
num_electrodesnumber $m$ of electrodes
Returns
number of unique nodes \(n_u\); can be used to realloc the nodes array

◆ populate_electrode()

int populate_electrode ( Electrode electrode,
const double  start_point[3],
const double  end_point[3],
double  radius 
)

Populates an Electrode structure.

Parameters
pointerto an allocated memory
start_pointArray \((x,y,z)_0\) that defines the starting point of the electrode
start_pointArray \((x,y,z)_0\) that defines the ending point of the electrode
radiuselectrode radius The Electrode radius
Returns
0 on success

◆ segment_electrode()

int segment_electrode ( Electrode electrodes,
double *  nodes,
size_t  num_segments,
const double *  start_point,
const double *  end_point,
double  radius 
)

Segments an electrode populating a passed array of electrodes and an array of nodes.

Parameters
electrodespointer to an array of Electrode to be filled
nodesflat array \(3 (n + 1)\) to be filled by the new nodes that are created
num_segmentsnumber \( n \) of segments to create
start_pointelectrode's start point
end_pointelectrode's end point
radiuselectrode's radius
Returns
0 on success

◆ self_integral()

_Complex double self_integral ( const Electrode sender)

Calculates the mHEM closed form solution of the integral when the sender and receiver segments are the same (self impedance). \( 2 L_k \left[ \log_e \left( \frac{\sqrt{1 + (b/L_k)^2} + 1}{b/L_k} \right) - \sqrt{1 + \left(\frac{b}{L_k}\right)^2} + \frac{b}{L_k} \right] \)

◆ v_mag_pot_integrand()

int v_mag_pot_integrand ( unsigned  ndim,
const double *  t,
void *  auxdata,
unsigned  fdim,
double *  fval 
)

Interface to pass magnetic_potential as an integrand to Cubature when calculating the voltage along a path.

Parameters
ndimshould be 1
tintegration variable (electrode percentage 0 to 1)
auxdatapointer to Field_integrand_data structure
fdimshould be 2: \( \Re(\vec A \cdot d\vec\ell) + \Im(\vec A \cdot d\vec\ell) \)
fvalwhere the results are stored (array of size 2) return 0 on success
See also
https://github.com/stevengj/cubature

◆ voltage()

_Complex double voltage ( const double *  point1,
const double *  point2,
const Electrode electrodes,
size_t  num_electrodes,
const _Complex double *  il,
const _Complex double *  it,
_Complex double  gamma,
_Complex double  s,
double  mur,
_Complex double  kappa,
size_t  max_eval,
double  req_abs_error,
double  req_rel_error 
)

Calculates the voltage \( \Delta U_{12} \) along a straight line from \( \vec p_1 \) to \( \vec p_2 \).
\( \Delta U_{12} = \int_{\vec p_1}^{\vec p_2} \left( -\nabla u - s \vec A \right) d\vec\ell \)

Parameters
point1Line integral start point \( \vec p_1 = (x,y,z)_1 \)
point2Line integral start point \( \vec p_2 = (x,y,z)_2 \)
electrodesarray of electrodes
num_electrodesnumber of electrodes \( m \)
illongitudinal currents array \( I_L \)
gammamedium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \)
scomplex angular frequency \( s = c + j\omega \) in [rad/s]
murrelative magnetic permeability of the medium \( \mu_r \)
kappamedium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m]
max_evalspecifies a maximum number of function evaluations (0 for no limit)
req_abs_errorthe absolute error requested (0 to ignore)
req_rel_errorthe relative error requested (0 to ignore)
Returns
the voltage along the line
See also
https://github.com/stevengj/cubature