Tutorial

Extracting the Data

# Install PyPEEC
#   - With a Python Environment
#   - With a Conda Environment

# Check the PyPEEC version
pypeec --version

# Extract the PyPEEC examples
pypeec examples examples

# Extract the PyPEEC documentation
pypeec documentation documentation

Solving a Problem

This tutorial demonstrates how PyPEEC can be used to simulate a four-layer PCB coil. The coil has two terminals and the simulation is done in the frequency domain. All the command are executed inside the virtual environment in the examples folder.

Mesher: Building and Meshing the Geometry

# Run the mesher
#   - geometry.yaml - contains the geometry description (input)
#   - voxel.json.gz - contains the meshed voxel structure (output)
pypeec mesher \
    --geometry tutorial/geometry.yaml \
    --voxel tutorial/voxel.json.gz
00:00:00.00 : MAIN     : INFO     : load the input data
00:00:00.01 : MAIN     : INFO     : load the mesher
00:00:01.15 : MAIN     : INFO     : run the mesher
00:00:01.15 : MESHER   : INFO     : check the input data
00:00:01.15 : MESHER   : INFO     : mesher_shape : enter : timing
00:00:01.15 : SHAPE    : DEBUG    :     parse the layers
00:00:01.15 : SHAPE    : DEBUG    :     create the shapes
00:00:01.16 : SHAPE    : DEBUG    :     get the voxel size
00:00:01.16 : SHAPE    : DEBUG    :     voxelize the shapes
00:00:01.19 : SHAPE    : DEBUG    :     trace: n_voxel = 19728
00:00:01.19 : SHAPE    : DEBUG    :     via: n_voxel = 1195
00:00:01.19 : SHAPE    : DEBUG    :     src: n_voxel = 361
00:00:01.19 : SHAPE    : DEBUG    :     sink: n_voxel = 361
00:00:01.19 : SHAPE    : DEBUG    :     merge the shapes
00:00:01.21 : MESHER   : INFO     : mesher_shape : exit : 00:00:00.05
00:00:01.21 : MESHER   : INFO     : voxel_resample : enter : timing
00:00:01.21 : SAMPLE   : DEBUG    :     use_reduce = False
00:00:01.21 : SAMPLE   : DEBUG    :     use_resample = False
00:00:01.21 : SAMPLE   : DEBUG    :     original number = 331056
00:00:01.21 : SAMPLE   : DEBUG    :     final number = 331056
00:00:01.21 : MESHER   : INFO     : voxel_resample : exit : 00:00:00.00
00:00:01.21 : MESHER   : INFO     : voxel_cloud : enter : timing
00:00:01.21 : CLOUD    : DEBUG    :     initial number = 9
00:00:01.22 : CLOUD    : DEBUG    :     final number = 9
00:00:01.22 : MESHER   : INFO     : voxel_cloud : exit : 00:00:00.00
00:00:01.22 : MESHER   : INFO     : voxel_conflict : enter : timing
00:00:01.22 : MESHER   : INFO     : voxel_conflict : exit : 00:00:00.00
00:00:01.22 : MESHER   : INFO     : voxel_connection : enter : timing
00:00:01.31 : MESHER   : INFO     : voxel_connection : exit : 00:00:00.08
00:00:01.31 : MESHER   : INFO     : voxel_summary : enter : timing
00:00:01.31 : SUMMARY  : DEBUG    :     voxel size
00:00:01.31 : SUMMARY  : DEBUG    :         n = (132, 132, 19)
00:00:01.31 : SUMMARY  : DEBUG    :         d = (3.50e-05, 3.50e-05, 3.50e-05)
00:00:01.31 : SUMMARY  : DEBUG    :         s = (4.63e-03, 4.63e-03, 6.65e-04)
00:00:01.31 : SUMMARY  : DEBUG    :         c = (1.94e-03, 1.94e-03, 0.00e+00)
00:00:01.31 : SUMMARY  : DEBUG    :         A = (2.14e-05, 3.08e-06, 3.08e-06)
00:00:01.31 : SUMMARY  : DEBUG    :     voxel summary
00:00:01.31 : SUMMARY  : DEBUG    :         V_total = 1.42e-08
00:00:01.31 : SUMMARY  : DEBUG    :         V_used = 9.12e-10
00:00:01.31 : SUMMARY  : DEBUG    :         n_total = 331056
00:00:01.31 : SUMMARY  : DEBUG    :         n_used = 21215
00:00:01.31 : SUMMARY  : DEBUG    :         ratio = 6.41e-02
00:00:01.31 : SUMMARY  : DEBUG    :         n_domain = 4
00:00:01.31 : SUMMARY  : DEBUG    :         n_graph = 1
00:00:01.31 : SUMMARY  : DEBUG    :     voxel domain
00:00:01.31 : SUMMARY  : DEBUG    :         trace = 19298
00:00:01.31 : SUMMARY  : DEBUG    :         via = 1195
00:00:01.31 : SUMMARY  : DEBUG    :         src = 361
00:00:01.31 : SUMMARY  : DEBUG    :         sink = 361
00:00:01.31 : MESHER   : INFO     : voxel_summary : exit : 00:00:00.00
00:00:01.31 : MESHER   : INFO     : duration: 00:00:00.15
00:00:01.31 : MAIN     : INFO     : successful termination
00:00:01.31 : MAIN     : INFO     : save the results

Viewer: Plot the Geometry and Mesh

# Run the viewer
#   - voxel.json.gz - contains the meshed voxel structure (input)
#   - viewer.yaml - contains the plot configuration (input)
#   - tag_plot - list of plots to be shown (defined in viewer.yaml)
pypeec viewer \
    --voxel tutorial/voxel.json.gz \
    --viewer config/viewer.yaml \
    --tag_plot domain connection
../_images/viewer_domain.png

Plot showing which the different domains.

../_images/viewer_connection.png

Plot showing which domains are interconnected.

Solver: Solve the PEEC Problem

# Run the solver
#   - voxel.json.gz - contains the meshed voxel structure (input)
#   - problem.yaml - contains the magnetic problem description (input)
#   - tolerance.yaml - contains the solver numerical tolerances (input)
#   - solution.json.gz - contains the problem solution (output)
pypeec solver \
    --voxel tutorial/voxel.json.gz \
    --problem tutorial/problem.yaml \
    --tolerance config/tolerance.yaml \
    --solution tutorial/solution.json.gz
00:00:00.00 : MAIN     : INFO     : load the input data
00:00:00.03 : MAIN     : INFO     : load the solver
00:00:00.24 : MAIN     : INFO     : run the solver
00:00:00.24 : SOLVER   : INFO     : check the voxel data
00:00:00.24 : SOLVER   : INFO     : check the input data
00:00:00.24 : SOLVER   : INFO     : combine the input data
00:00:00.25 : SOLVER   : INFO     : init : enter : timing
00:00:00.27 : SOLVER   : INFO     :     voxel_geometry : enter : timing
00:00:00.65 : SOLVER   : INFO     :     voxel_geometry : exit : 00:00:00.38
00:00:00.65 : SOLVER   : INFO     :     system_tensor : enter : timing
00:00:00.65 : GREEN    : DEBUG    :         analytical solution: 6D / 1
00:00:00.68 : GREEN    : DEBUG    :         analytical solution: 6D / 4624
00:00:00.83 : GREEN    : DEBUG    :         numerical approximation: 6D / 326432
00:00:00.86 : SOLVER   : INFO     :     system_tensor : exit : 00:00:00.20
00:00:00.86 : SOLVER   : INFO     :     problem_geometry : enter : timing
00:00:00.92 : PROBLEM  : DEBUG    :         n_voxel_total = 331056
00:00:00.92 : PROBLEM  : DEBUG    :         n_voxel_used = 21215
00:00:00.92 : PROBLEM  : DEBUG    :         n_face_total = 993168
00:00:00.92 : PROBLEM  : DEBUG    :         n_face_used = 42062
00:00:00.92 : PROBLEM  : DEBUG    :         n_voxel_electric = 21215
00:00:00.92 : PROBLEM  : DEBUG    :         n_voxel_magnetic = 0
00:00:00.92 : PROBLEM  : DEBUG    :         n_face_electric = 42062
00:00:00.92 : PROBLEM  : DEBUG    :         n_face_magnetic = 0
00:00:00.92 : PROBLEM  : DEBUG    :         n_src_current = 0
00:00:00.92 : PROBLEM  : DEBUG    :         n_src_voltage = 722
00:00:00.92 : PROBLEM  : DEBUG    :         ratio_voxel = 6.41e-02
00:00:00.92 : PROBLEM  : DEBUG    :         ratio_face = 4.24e-02
00:00:00.92 : SOLVER   : INFO     :     problem_geometry : exit : 00:00:00.06
00:00:00.92 : SOLVER   : INFO     :     system_matrix : enter : timing
00:00:00.92 : FFT      : DEBUG    :         multiplication: inductance
00:00:00.92 : FFT      : DEBUG    :             tensor size: (132, 132, 19)
00:00:00.92 : FFT      : DEBUG    :             tensor footprint: 40.41 MB
00:00:01.04 : SOLVER   : INFO     :     system_matrix : exit : 00:00:00.12
00:00:01.04 : SOLVER   : INFO     : init : exit : 00:00:00.79
00:00:01.04 : SOLVER   : INFO     : run sweep: sim_dc : enter : timing
00:00:01.04 : SOLVER   : INFO     :     problem_value : enter : timing
00:00:01.06 : SOLVER   : INFO     :     problem_value : exit : 00:00:00.01
00:00:01.06 : SOLVER   : INFO     :     equation_system : enter : timing
00:00:01.09 : FACTOR   : DEBUG    :         factorization: electric
00:00:01.09 : FACTOR   : DEBUG    :             matrix size: (21937, 21937)
00:00:01.09 : FACTOR   : DEBUG    :             matrix elements: 107505
00:00:01.09 : FACTOR   : DEBUG    :             matrix density: 2.23e-04
00:00:01.09 : FACTOR   : DEBUG    :             compute factorization
00:00:01.30 : FACTOR   : DEBUG    :             factorization success
00:00:01.30 : FACTOR   : DEBUG    :         factorization: magnetic
00:00:01.30 : SOLVER   : INFO     :     equation_system : exit : 00:00:00.24
00:00:01.30 : SOLVER   : INFO     :     equation_solver : enter : timing
00:00:01.30 : COND     : DEBUG    :         condition: electric
00:00:01.30 : COND     : DEBUG    :             matrix size: (21937, 21937)
00:00:01.30 : COND     : DEBUG    :             matrix elements: 107505
00:00:01.30 : COND     : DEBUG    :             matrix density: 2.23e-04
00:00:01.30 : COND     : DEBUG    :             compute LU decomposition
00:00:01.47 : COND     : DEBUG    :             estimate norm of the inverse
00:00:01.61 : COND     : DEBUG    :             estimate norm of the matrix
00:00:01.64 : COND     : DEBUG    :             compute condition estimate
00:00:01.65 : COND     : DEBUG    :         condition: magnetic
00:00:01.65 : EQUATION : DEBUG    :         condition summary
00:00:01.65 : EQUATION : DEBUG    :             check = True
00:00:01.65 : EQUATION : DEBUG    :             status = True
00:00:01.65 : EQUATION : DEBUG    :             cond_electric = 3.25e+06
00:00:01.65 : EQUATION : DEBUG    :             cond_magnetic = 0.00e+00
00:00:01.65 : EQUATION : DEBUG    :             matrix condition is good
00:00:01.65 : EQUATION : DEBUG    :         solver run
00:00:01.65 : EQUATION : DEBUG    :             init / 0.00e+00+0.00e+00j VA
00:00:01.77 : EQUATION : DEBUG    :             i = 1 / 0.00e+00+0.00e+00j VA
00:00:01.82 : EQUATION : DEBUG    :             i = 2 / 7.91e+01+0.00e+00j VA
00:00:01.84 : EQUATION : DEBUG    :             final / 7.91e+01+0.00e+00j VA
00:00:01.84 : EQUATION : DEBUG    :         solver summary
00:00:01.84 : EQUATION : DEBUG    :             check = True
00:00:01.84 : EQUATION : DEBUG    :             status = True
00:00:01.84 : EQUATION : DEBUG    :             n_dof_total = 63999
00:00:01.84 : EQUATION : DEBUG    :             n_dof_electric = 63999
00:00:01.84 : EQUATION : DEBUG    :             n_dof_magnetic = 0
00:00:01.84 : EQUATION : DEBUG    :             n_iter = 2
00:00:01.84 : EQUATION : DEBUG    :             n_sys_eval = 3
00:00:01.84 : EQUATION : DEBUG    :             n_pcd_eval = 3
00:00:01.84 : EQUATION : DEBUG    :             res_rms = 3.32e-13
00:00:01.84 : EQUATION : DEBUG    :             convergence achieved
00:00:01.85 : SOLVER   : INFO     :     equation_solver : exit : 00:00:00.54
00:00:01.85 : SOLVER   : INFO     :     extract_solution : enter : timing
00:00:02.27 : SOLUTION : DEBUG    :         domain: trace_via
00:00:02.27 : SOLUTION : DEBUG    :             P_electric = 7.84e+01 W
00:00:02.27 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:02.27 : SOLUTION : DEBUG    :             P_tot = 7.84e+01 W
00:00:02.27 : SOLUTION : DEBUG    :         domain: src_sink
00:00:02.27 : SOLUTION : DEBUG    :             P_electric = 6.78e-01 W
00:00:02.27 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:02.27 : SOLUTION : DEBUG    :             P_tot = 6.78e-01 W
00:00:02.27 : SOLUTION : DEBUG    :         terminal: src
00:00:02.27 : SOLUTION : DEBUG    :             type = voltage / lumped
00:00:02.27 : SOLUTION : DEBUG    :             V_src = +1.00e+00 + +0.00e+00j V
00:00:02.27 : SOLUTION : DEBUG    :             V_drop = +4.13e-02 + +0.00e+00j V
00:00:02.27 : SOLUTION : DEBUG    :             V = +9.59e-01 + +0.00e+00j V
00:00:02.27 : SOLUTION : DEBUG    :             I = +4.13e+01 + +0.00e+00j A
00:00:02.27 : SOLUTION : DEBUG    :             S = +3.96e+01 + +0.00e+00j VA
00:00:02.27 : SOLUTION : DEBUG    :         terminal: sink
00:00:02.27 : SOLUTION : DEBUG    :             type = voltage / lumped
00:00:02.27 : SOLUTION : DEBUG    :             V_src = -1.00e+00 + +0.00e+00j V
00:00:02.27 : SOLUTION : DEBUG    :             V_drop = -4.13e-02 + +0.00e+00j V
00:00:02.27 : SOLUTION : DEBUG    :             V = -9.59e-01 + +0.00e+00j V
00:00:02.27 : SOLUTION : DEBUG    :             I = -4.13e+01 + +0.00e+00j A
00:00:02.27 : SOLUTION : DEBUG    :             S = +3.96e+01 + +0.00e+00j VA
00:00:02.27 : SOLUTION : DEBUG    :         integral
00:00:02.27 : SOLUTION : DEBUG    :             S_tot_real = 7.91e+01 VA
00:00:02.27 : SOLUTION : DEBUG    :             S_tot_imag = 0.00e+00j VA
00:00:02.27 : SOLUTION : DEBUG    :             P_electric = 7.91e+01 W
00:00:02.27 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:02.27 : SOLUTION : DEBUG    :             W_electric = 4.97e-05 J
00:00:02.27 : SOLUTION : DEBUG    :             W_magnetic = 0.00e+00 J
00:00:02.27 : SOLUTION : DEBUG    :             P_tot = 7.91e+01 W
00:00:02.27 : SOLUTION : DEBUG    :             W_tot = 4.97e-05 J
00:00:02.30 : SOLVER   : INFO     :     extract_solution : exit : 00:00:00.45
00:00:02.30 : SOLVER   : INFO     : run sweep: sim_dc : exit : 00:00:01.25
00:00:02.30 : SOLVER   : INFO     : run sweep: sim_ac : enter : timing
00:00:02.30 : SOLVER   : INFO     :     problem_value : enter : timing
00:00:02.31 : SOLVER   : INFO     :     problem_value : exit : 00:00:00.01
00:00:02.31 : SOLVER   : INFO     :     equation_system : enter : timing
00:00:02.32 : FACTOR   : DEBUG    :         factorization: electric
00:00:02.32 : FACTOR   : DEBUG    :             matrix size: (21937, 21937)
00:00:02.32 : FACTOR   : DEBUG    :             matrix elements: 107505
00:00:02.32 : FACTOR   : DEBUG    :             matrix density: 2.23e-04
00:00:02.32 : FACTOR   : DEBUG    :             compute factorization
00:00:02.44 : FACTOR   : DEBUG    :             factorization success
00:00:02.44 : FACTOR   : DEBUG    :         factorization: magnetic
00:00:02.44 : SOLVER   : INFO     :     equation_system : exit : 00:00:00.12
00:00:02.44 : SOLVER   : INFO     :     equation_solver : enter : timing
00:00:02.44 : COND     : DEBUG    :         condition: electric
00:00:02.44 : COND     : DEBUG    :             matrix size: (21937, 21937)
00:00:02.44 : COND     : DEBUG    :             matrix elements: 107505
00:00:02.44 : COND     : DEBUG    :             matrix density: 2.23e-04
00:00:02.44 : COND     : DEBUG    :             compute LU decomposition
00:00:02.65 : COND     : DEBUG    :             estimate norm of the inverse
00:00:02.76 : COND     : DEBUG    :             estimate norm of the matrix
00:00:02.80 : COND     : DEBUG    :             compute condition estimate
00:00:02.80 : COND     : DEBUG    :         condition: magnetic
00:00:02.80 : EQUATION : DEBUG    :         condition summary
00:00:02.80 : EQUATION : DEBUG    :             check = True
00:00:02.80 : EQUATION : DEBUG    :             status = True
00:00:02.80 : EQUATION : DEBUG    :             cond_electric = 3.25e+06
00:00:02.80 : EQUATION : DEBUG    :             cond_magnetic = 0.00e+00
00:00:02.80 : EQUATION : DEBUG    :             matrix condition is good
00:00:02.80 : EQUATION : DEBUG    :         solver run
00:00:02.81 : EQUATION : DEBUG    :             init / 0.00e+00+0.00e+00j VA
00:00:02.98 : EQUATION : DEBUG    :             i = 1 / 0.00e+00+0.00e+00j VA
00:00:07.53 : EQUATION : DEBUG    :             i = 2 / 8.13e-01+5.40e+00j VA
00:00:07.89 : EQUATION : DEBUG    :             final / 8.13e-01+5.40e+00j VA
00:00:07.89 : EQUATION : DEBUG    :         solver summary
00:00:07.89 : EQUATION : DEBUG    :             check = True
00:00:07.89 : EQUATION : DEBUG    :             status = True
00:00:07.89 : EQUATION : DEBUG    :             n_dof_total = 63999
00:00:07.89 : EQUATION : DEBUG    :             n_dof_electric = 63999
00:00:07.89 : EQUATION : DEBUG    :             n_dof_magnetic = 0
00:00:07.89 : EQUATION : DEBUG    :             n_iter = 2
00:00:07.89 : EQUATION : DEBUG    :             n_sys_eval = 13
00:00:07.89 : EQUATION : DEBUG    :             n_pcd_eval = 13
00:00:07.89 : EQUATION : DEBUG    :             res_rms = 1.57e-09
00:00:07.89 : EQUATION : DEBUG    :             convergence achieved
00:00:07.89 : SOLVER   : INFO     :     equation_solver : exit : 00:00:05.45
00:00:07.89 : SOLVER   : INFO     :     extract_solution : enter : timing
00:00:08.24 : SOLUTION : DEBUG    :         domain: trace_via
00:00:08.24 : SOLUTION : DEBUG    :             P_electric = 8.05e-01 W
00:00:08.24 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:08.24 : SOLUTION : DEBUG    :             P_tot = 8.05e-01 W
00:00:08.24 : SOLUTION : DEBUG    :         domain: src_sink
00:00:08.24 : SOLUTION : DEBUG    :             P_electric = 7.84e-03 W
00:00:08.24 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:08.24 : SOLUTION : DEBUG    :             P_tot = 7.84e-03 W
00:00:08.24 : SOLUTION : DEBUG    :         terminal: src
00:00:08.24 : SOLUTION : DEBUG    :             type = voltage / lumped
00:00:08.24 : SOLUTION : DEBUG    :             V_src = +1.00e+00 + +0.00e+00j V
00:00:08.24 : SOLUTION : DEBUG    :             V_drop = +8.74e-04 + -5.40e-03j V
00:00:08.24 : SOLUTION : DEBUG    :             V = +9.99e-01 + +5.40e-03j V
00:00:08.24 : SOLUTION : DEBUG    :             I = +8.74e-01 + -5.40e+00j A
00:00:08.24 : SOLUTION : DEBUG    :             S = +4.06e-01 + +2.70e+00j VA
00:00:08.24 : SOLUTION : DEBUG    :         terminal: sink
00:00:08.24 : SOLUTION : DEBUG    :             type = voltage / lumped
00:00:08.25 : SOLUTION : DEBUG    :             V_src = -1.00e+00 + +0.00e+00j V
00:00:08.25 : SOLUTION : DEBUG    :             V_drop = -8.74e-04 + +5.40e-03j V
00:00:08.25 : SOLUTION : DEBUG    :             V = -9.99e-01 + -5.40e-03j V
00:00:08.25 : SOLUTION : DEBUG    :             I = -8.74e-01 + +5.40e+00j A
00:00:08.25 : SOLUTION : DEBUG    :             S = +4.06e-01 + +2.70e+00j VA
00:00:08.25 : SOLUTION : DEBUG    :         integral
00:00:08.25 : SOLUTION : DEBUG    :             S_tot_real = 8.13e-01 VA
00:00:08.25 : SOLUTION : DEBUG    :             S_tot_imag = 5.40e+00j VA
00:00:08.25 : SOLUTION : DEBUG    :             P_electric = 8.13e-01 W
00:00:08.25 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:08.25 : SOLUTION : DEBUG    :             W_electric = 4.30e-07 J
00:00:08.25 : SOLUTION : DEBUG    :             W_magnetic = 0.00e+00 J
00:00:08.25 : SOLUTION : DEBUG    :             P_tot = 8.13e-01 W
00:00:08.25 : SOLUTION : DEBUG    :             W_tot = 4.30e-07 J
00:00:08.27 : SOLVER   : INFO     :     extract_solution : exit : 00:00:00.38
00:00:08.27 : SOLVER   : INFO     : run sweep: sim_ac : exit : 00:00:05.97
00:00:08.27 : SOLVER   : INFO     : duration: 00:00:08.03
00:00:08.28 : MAIN     : INFO     : successful termination
00:00:08.28 : MAIN     : INFO     : save the results

Plotter: Plot the Solution

# Run the plotter
#   - solution.json.gz - contains the problem solution (input)
#   - plotter.yaml - contains the plot configuration (input)
#   - tag_plot - list of plots to be shown (defined in plotter.yaml)
pypeec plotter \
    --solution tutorial/solution.json.gz \
    --plotter config/plotter.yaml \
    --tag_plot V_c_norm J_c_norm H_p_norm residuum
../_images/plotter_V_c_norm.png

Plot showing the electric potential.

../_images/plotter_J_c_norm.png

Plot showing the current density.

../_images/plotter_H_p_norm.png

Plot showing the generated magnetic field.

../_images/plotter_residuum.png

Plot showing the equation system residuum.