Module 2 - Forward

module2_forward.current_method(L, l, method=1, value=1)

This function create a numpy array (or a list of arrays) that represent the current density in the electrodes.

Parameters
  • L (int) – Number electrodes.

  • l (int) – Measurements number.

  • method (int) – Current pattern.

Returns

list of arrays – Return list with current density in each electrode for each measurement.

Method Values:
  1. 1 and -1 in opposite electrodes

  2. 1 and -1 in adjacent electrodes

  3. 1 in one electrode and -1/(L-1) for the rest

  4. For measureament k, we have: (sin(k*2*pi/16) sin(2*k*2*pi/16) … sin(16*k*2*pi/16))

Example

>>> I_all=current_method(L=4,l=4, method=1)
>>> print(I_all)
    [array([ 1.,  0., -1.,  0.]),
    array([ 0.,  1.,  0., -1.]),
    array([-1.,  0.,  1.,  0.]),
    array([ 0., -1.,  0.,  1.])]
>>> I_all=current_method(L=4,l=4, method=2)
>>> print(I_all)
    [array([ 1.,  -1., 0.,  0.]),
    array([ 0.,  1.,  -1., 0.]),
    array([0.,  0.,  1.,  -1.]),
    array([ 1., 0.,  0.,  -1.])]
module2_forward.GammaCircle(mesh, in_v, out_v, radius, centerx, centery)

Function to create a circle in the mesh with some proprieties

Parameters
  • mesh (dolfin.cpp.mesh.Mesh) – Mesh.

  • in_v (float) – Value inside circle

  • out_v (float) – Value outside circle

  • radius (float) – Circle radius

  • centerx (float) – Circle center position x

  • centery (float) – Circle center position y

Returns

Array – Return a vector where each position correspond de value of the function in that element.

Example

>>> ValuesCells0=GammaCircle(mesh=mesh_direct, in_v=3.0, out_v=1.0, radius=0.50, centerx=0.25, centery=0.25)
>>> print(ValuesCells0)
[1. 1. 1. ... 1. 1. 1.]
>>> "Plot"
>>> gamma0=CellFunction(mesh_direct, values=ValuesCells0);   
>>> V_DG=FiniteElement('DG',mesh_direct.ufl_cell(),0)
>>> plot_figure(mesh_direct, V_DG, gamma0, name="Resposta gamma");
../_images/gamma.png
class module2_forward.CellFunction(mesh, values, **kwargs)

Auxiliar function to transform an array to a Function We use it with GammaCircle()

Parameters
  • mesh (dolfin.cpp.mesh.Mesh) – Mesh.

  • values (array) – Array with values of the function in the cell.

Example

>>> ValuesCells0=np.zeros(mesh_inverse.num_cells())        #Define a vector of zeros
>>> ValuesCells0[5]=1                                      #Cell 5 has value 1
>>> gamma0=CellFunction(mesh_inverse, values=ValuesCells0);#Get vector and transform in a function cell

If you want plot the function:

>>> V_DG=FiniteElement('DG',mesh_inverse.ufl_cell(),0)     #Space of Finite Elemente descontinuous garlekin degree 0
>>> Q=FunctionSpace(mesh_inverse,V_DG)                     #Functionspace to interpolate gamma
>>> gamma0=interpolate(gamma0, Q)                          #Interpolation gamma to generate a function
>>> p=plot(gamma0)                                         #plot gamma0
>>> plot(mesh_inverse)                                     #plot mesh
>>> plt.colorbar(p)                                        #set colorbar.
../_images/cell_function_test.png
class module2_forward.ForwardProblem(mesh, ele_pos, z)

Object Forward Problem EIT 2D

Parameters
  • mesh (dolfin.cpp.mesh.Mesh) – Mesh. We recommend from MyMesh()

  • z (array) – Vector of impedances in electrodes

  • electrodes_obj (electrodes_position()) – Object, list of arrays with position of electrodes.

Example

>>> "Basic Definitions"
>>> L=16
>>> VD=FiniteElement('CG',mesh_direct.ufl_cell(),1) #Space Solution
>>> l=int(L)                                        #Measurements number.
>>> z=np.ones(L)*0.025                              #Impedance
>>> I_all=current_method(L,l, method=1)             #Current pattern

If you need it, see electrodes_position(), GammaCircle() and CellFunction().

>>> "Solver"
>>> DirectProblem=ForwardProblem(mesh_direct,  ele_pos,  z)
>>> list_u0, list_U0 = DirectProblem.solve_forward(VD, gamma0, I_all, l)
>>> list_U0 = DirectProblem.sol_asarray()
>>> print(list_U0[0:L])
[ 1.0842557   0.32826713  0.19591977  0.13158264  0.06214628 -0.03412964
 -0.17331413 -0.40308837 -1.18449889 -0.42369776 -0.21120216 -0.08218106
  0.01735219  0.10789938  0.20976791  0.37492101]
solve_forward(V, gamma, I_all, l)

Solver Forward Problem EIT 2D

Parameters
  • V (FiniteElement) – FiniteElement Fenics object

  • gamma (CellFunction()) – Finite Element Function

  • I_all (current_method() or list of arrays) – Current density in each electrode for each measurement

  • l (int) – Measurements number.

Returns

(Array, Array) – Return a vector where each position correspond de value the solution in the

domain, and other solution that contains the potencial in the electrodes. Both are Fenics Objects.

Example

>>> DirectProblem=ForwardProblem(mesh_direct,  ele_pos,  z)
>>> list_u0, list_U0 = DirectProblem.solve_forward(VD, gamma0, I_all, l)

sol_asarray()

Function that convert potential electrode results in array and concatenate them.

Returns

Array – Return a vector with potentials values concatenated, dimension: L*l.

Example

>>> list_U0 = DirectProblem.sol_asarray()
add_noise(noise_level=0, noise_type='uniform', seed=42)

Function that add noise in the potential values.

Parameters
  • data (array) – Vector with potencial in electrodes or any other vector.

  • level (float) – Noise level (%), expect values between 0 and 1.

  • noise_type (str.) – Noise type, uniform or cauchy.

Returns

Array – Return a vector with potentials values concatenated, dimension: L*l and noised.

Example

>>> list_U0_noised = DirectProblem.add_noise(noise_level=0.01, noise_type='uniform')
verify_solution_graphs(gamma0, sol_index=0, method=1)

Function that plot boundary information to verify solution.

Parameters
  • sol_index (int) – Index for solution, 0 to l.

  • method (int) – 1, 2 or 3

Returns

array – Plot boundary.

Example

data = DirectProblem.verify_solution_graphs(sol_index=0, method=2)
verify_solution_values(I_all, gamma0, sol_index=0, method=1)

Function that plot boundary information to verify solution.

Parameters
  • sol_index (int) – Index for solution, 0 to l.

  • method (int) – 1-Current Value, 2- Average potential on electrodes.

Returns

array – values.

Example

data = DirectProblem.verify_solution_graphs(sol_index=0, method=2)