HP-HEM
1.0.2
High Performance implementation of the Hybrid Electromagnetic Model
|
#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) |
enum Integration_type |
Type of integration and simplification thereof to be done.
Definition at line 18 of file electrode.h.
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 \).
zl | longitudinal impedance matrix \( Z_L \) as a flat array of size \( m^2 \) |
zt | transversal impedance matrix \( Z_T \) as a flat array of size \( m^2 \) |
electrodes | array of electrodes |
num_electrodes | number of electrodes \( m \) |
gamma | medium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \) |
s | complex angular frequency \( s = c + j\omega \) in [rad/s] |
mur | relative magnetic permeability of the medium \( \mu_r \) |
kappa | medium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m] |
max_eval | specifies a maximum number of function evaluations (0 for no limit) |
req_abs_error | the absolute error requested (0 to ignore) |
req_rel_error | the relative error requested (0 to ignore) |
integration_type | type of integration to be done. |
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 \).
ndim | should be 1 |
t | integration variable (electrode percentage 0 to 1) |
auxdata | pointer to Field_integrand_data structure |
fdim | should be 6 (Real and Imag.): \( (\Re(E_x), \Im(E_x), \Re(E_y), \Im(E_y), \Re(E_z), \Im(E_z)) \) |
fval | where 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 |
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 \)
point | array \( (x, y, z) \) |
electrodes | array of electrodes |
num_electrodes | number of electrodes \( m \) |
il | longitudinal currents array \( I_L \) |
it | transversal currents array \( I_T \) |
gamma | medium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \) |
s | complex angular frequency \( s = c + j\omega \) in [rad/s] |
mur | relative magnetic permeability of the medium \( \mu_r \) |
kappa | medium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m] |
max_eval | specifies a maximum number of function evaluations (0 for no limit) |
req_abs_error | the absolute error requested (0 to ignore) |
req_rel_error | the relative error requested (0 to ignore) |
ve | pointer to array of size 3 in which the electric field components \( (E_x, E_y, E_z) \) will be add to on return. |
_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.
point | array \((x, y, z)\) |
electrodes | array of electrodes |
num_electrodes | number of electrodes \( m \) |
it | transversal currents array \( I_T \) |
gamma | medium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \) |
kappa | medium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m] |
max_eval | specifies a maximum number of function evaluations (0 for no limit) |
req_abs_error | the absolute error requested (0 to ignore) |
req_rel_error | the relative error requested (0 to ignore) |
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".
file_name | path to the file |
electrodes | pointer to an array of Electrode to be filled |
num_electrodes | number of electrodes to read (number of lines in file). Any line number greater than num_electrodes will be ignored. |
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 \).
zl | longitudinal impedance matrix \( Z_L \) as a flat array of size \( m^2 \) |
zt | transversal impedance matrix \( Z_T \) as a flat array of size \( m^2 \) |
electrodes | array of electrodes |
images | array of electrodes |
num_electrodes | number of electrodes \( m \) |
gamma | medium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \) |
s | complex angular frequency \( s = c + j\omega \) in [rad/s] |
mur | relative magnetic permeability of the medium \( \mu_r \) |
kappa | medium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m] |
ref_l | longitudinal current reflection coefficient \( \Gamma_L \) |
ref_t | transversal current reflection coefficient \( \Gamma_T \) |
max_eval | specifies a maximum number of function evaluations (0 for no limit) |
req_abs_error | the absolute error requested (0 to ignore) |
req_rel_error | the relative error requested (0 to ignore) |
integration_type | type of integration to be done. |
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.
sender | Current carrying Electrode that generates the excitation. |
receiver | Potential receiving Electrode that receives the excitation. |
gamma | medium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \) |
max_eval | specifies a maximum number of function evaluations (0 for no limit) |
req_abs_error | the absolute error requested (0 to ignore) |
req_rel_error | the relative error requested (0 to ignore) |
integration_type | type of integration to be done. |
result | array[2] where to store the integral result (real and imaginary parts) |
error | array[2] where to store the integral error (real and imaginary parts) |
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.
ndim | must be = 2 |
t | array of size 2 of the electrodes' length as a percentage (0 to 1) |
auxdata | Integration_data with electrodes and propagation constant |
fdim | must be = 2 |
fval | pointer to where the result is stored |
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.
ndim | must be = 1 |
t | array of size 1 of the sender electrode's length as a percentage (0 to 1) |
auxdata | Integration_data with electrodes and propagation constant |
fdim | must be = 2 |
fval | pointer to where the result is stored |
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.
ndim | must be = 1 |
t | array of size 1 with receiver's length percentage (0 to 1) |
auxdata | Integration_data with electrodes and propagation constant |
fdim | must be = 2 |
fval | pointer to where the result is stored |
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 \).
point | array \((x, y, z)\) |
electrodes | array of electrodes |
num_electrodes | number of electrodes \( m \) |
il | longitudinal currents array \( I_L \) |
gamma | medium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \) |
mur | relative magnetic permeability of the medium \( \mu_r \) |
max_eval | specifies a maximum number of function evaluations (0 for no limit) |
req_abs_error | the absolute error requested (0 to ignore) |
req_rel_error | the relative error requested (0 to ignore) |
va | pointer to array of size 3 in which the magnetic vector potential components \( (A_x,A_y,A_z) \) will be stored on return. |
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".
file_name | path to the file |
nodes | array of double[3] to be filled |
num_nodes | number of nodes to read (number of lines in file). Any line number greater than num_nodes will be ignored. |
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.
nodes | flat array of size \(n \ge 3(m + 1)\) to be filled with the unique nodes. |
electrodes | array of electrodes |
num_electrodes | number $m$ of electrodes |
int populate_electrode | ( | Electrode * | electrode, |
const double | start_point[3], | ||
const double | end_point[3], | ||
double | radius | ||
) |
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.
electrodes | pointer to an array of Electrode to be filled |
nodes | flat array \(3 (n + 1)\) to be filled by the new nodes that are created |
num_segments | number \( n \) of segments to create |
start_point | electrode's start point |
end_point | electrode's end point |
radius | electrode's radius |
_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] \)
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.
ndim | should be 1 |
t | integration variable (electrode percentage 0 to 1) |
auxdata | pointer to Field_integrand_data structure |
fdim | should be 2: \( \Re(\vec A \cdot d\vec\ell) + \Im(\vec A \cdot d\vec\ell) \) |
fval | where the results are stored (array of size 2) return 0 on success |
_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 \)
point1 | Line integral start point \( \vec p_1 = (x,y,z)_1 \) |
point2 | Line integral start point \( \vec p_2 = (x,y,z)_2 \) |
electrodes | array of electrodes |
num_electrodes | number of electrodes \( m \) |
il | longitudinal currents array \( I_L \) |
gamma | medium propagation constant \( \gamma = \sqrt{j\omega\mu(\sigma + j\omega\varepsilon)} \) |
s | complex angular frequency \( s = c + j\omega \) in [rad/s] |
mur | relative magnetic permeability of the medium \( \mu_r \) |
kappa | medium complex conductivity \( \sigma + j\omega\varepsilon \) in [S/m] |
max_eval | specifies a maximum number of function evaluations (0 for no limit) |
req_abs_error | the absolute error requested (0 to ignore) |
req_rel_error | the relative error requested (0 to ignore) |