Tutorial

Installing the Code

# Installation of PyPEEC with pip
#    - The Python executable can be "python" or "python3"
#    - Alternatively, Conda can be used for the environment

# Install Python Virtual Environment
python -m pip install virtualenv

# Create a Python Virtual Environment
python -m venv venv

# Activate the Python Virtual Environment
source venv/bin/activate

# Install PyPEEC from PyPi
python -m pip install pypeec

Extracting the Data

# 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: Meshing of the Geometry

# Run the mesher
#   - geometry.yaml - contains the geometry description (input)
#   - voxel.pck - contains the meshed voxel structure (output)
pypeec mesher \
    --geometry tutorial/geometry.yaml \
    --voxel tutorial/voxel.pck
  ╔═══════════════════════════════════════════════════════╗
  ║  ╔═══╗   ╔═══╦═══╦═══╦═══╗            3D PEEC Solver  ║
  ║  ║╔═╗║   ║╔═╗║╔══╣╔══╣╔═╗║      Quasi-Magnetostatics  ║
  ║  ║╚═╝╠╗ ╔╣╚═╝║╚══╣╚══╣║ ╚╝          Frequency Domain  ║
  ║  ║╔══╣║ ║║╔══╣╔══╣╔══╣║ ╔╗          Voxel Geometries  ║
  ║  ║║  ║╚═╝║║  ║╚══╣╚══╣╚═╝║       FFT/GPU Accelerated  ║
  ║  ╚╝  ╚═╗ ╠╝  ╚═══╩═══╩═══╝    Python and Open Source  ║
  ╚══════╦═╝ ╠════════════════════════════════════════════╝
         ╚═══╝
  ╔═══════════════════════════════════════════════════════╗
  ║ Website - https://pypeec.otvam.ch                     ║
  ║ Thomas Guillod - Dartmouth College                    ║
  ║ Mozilla Public License Version 2.0                    ║
  ╚═══════════════════════════════════════════════════════╝

00:00:00.00 : MAIN     : INFO     : load the input data
00:00:00.01 : MAIN     : INFO     : load the mesher
00:00:00.82 : MAIN     : INFO     : run the mesher
00:00:00.82 : MESHER   : INFO     : check the input data
00:00:00.82 : MESHER   : INFO     : mesher_shape : enter : timing
00:00:00.82 : SHAPE    : DEBUG    :     parse the layers
00:00:00.82 : SHAPE    : DEBUG    :     create the shapes
00:00:00.83 : SHAPE    : DEBUG    :     get the voxel size
00:00:00.83 : SHAPE    : DEBUG    :     voxelize the shapes
00:00:00.85 : SHAPE    : DEBUG    :     trace: n_voxel = 19728
00:00:00.85 : SHAPE    : DEBUG    :     via: n_voxel = 1205
00:00:00.85 : SHAPE    : DEBUG    :     src: n_voxel = 361
00:00:00.85 : SHAPE    : DEBUG    :     sink: n_voxel = 361
00:00:00.85 : SHAPE    : DEBUG    :     merge the shapes
00:00:00.87 : MESHER   : INFO     : mesher_shape : exit : 00:00:00.04
00:00:00.87 : MESHER   : INFO     : voxel_conflict : enter : timing
00:00:00.88 : MESHER   : INFO     : voxel_conflict : exit : 00:00:00.00
00:00:00.88 : MESHER   : INFO     : voxel_resample : enter : timing
00:00:00.88 : SAMPLE   : DEBUG    :     original number = 331056
00:00:00.88 : SAMPLE   : DEBUG    :     use_reduce = False
00:00:00.88 : SAMPLE   : DEBUG    :     use_resample = False
00:00:00.88 : SAMPLE   : DEBUG    :     final number = 331056
00:00:00.88 : MESHER   : INFO     : voxel_resample : exit : 00:00:00.00
00:00:00.88 : MESHER   : INFO     : voxel_connection : enter : timing
00:00:00.97 : MESHER   : INFO     : voxel_connection : exit : 00:00:00.08
00:00:00.97 : MESHER   : INFO     : voxel_summary : enter : timing
00:00:00.97 : SUMMARY  : DEBUG    :     voxel size
00:00:00.97 : SUMMARY  : DEBUG    :         n = (132, 132, 19)
00:00:00.97 : SUMMARY  : DEBUG    :         d = (3.50e-05, 3.50e-05, 3.50e-05)
00:00:00.97 : SUMMARY  : DEBUG    :         s = (4.63e-03, 4.63e-03, 6.65e-04)
00:00:00.97 : SUMMARY  : DEBUG    :         c = (1.94e-03, 1.94e-03, 0.00e+00)
00:00:00.97 : SUMMARY  : DEBUG    :         A = (2.14e-05, 3.08e-06, 3.08e-06)
00:00:00.97 : SUMMARY  : DEBUG    :     voxel summary
00:00:00.97 : SUMMARY  : DEBUG    :         V_total = 1.42e-08
00:00:00.97 : SUMMARY  : DEBUG    :         V_used = 9.12e-10
00:00:00.97 : SUMMARY  : DEBUG    :         n_total = 331056
00:00:00.97 : SUMMARY  : DEBUG    :         n_used = 21225
00:00:00.97 : SUMMARY  : DEBUG    :         ratio = 6.41e-02
00:00:00.97 : SUMMARY  : DEBUG    :         n_domain = 4
00:00:00.97 : SUMMARY  : DEBUG    :         n_graph = 1
00:00:00.97 : SUMMARY  : DEBUG    :     voxel domain
00:00:00.97 : SUMMARY  : DEBUG    :         trace = 19298
00:00:00.97 : SUMMARY  : DEBUG    :         via = 1205
00:00:00.97 : SUMMARY  : DEBUG    :         src = 361
00:00:00.97 : SUMMARY  : DEBUG    :         sink = 361
00:00:00.97 : MESHER   : INFO     : voxel_summary : exit : 00:00:00.00
00:00:00.97 : MESHER   : INFO     : duration: 00:00:00.14
00:00:00.97 : MESHER   : INFO     : successful termination
00:00:00.97 : MAIN     : INFO     : save the results

Viewer: Plot the Geometry

# Run the viewer
#   - voxel.pck - contains the meshed voxel structure (input)
#   - point.yaml - contains the points used for field evaluation (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.pck \
    --point tutorial/point.yaml \
    --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 Problem

# Run the solver
#   - voxel.pck - contains the meshed voxel structure (input)
#   - problem.yaml - contains the magnetic problem description (input)
#   - tolerance.yaml - contains the solver numerical tolerances (input)
#   - solution.pck - contains the problem solution (output)
pypeec solver \
    --voxel tutorial/voxel.pck \
    --problem tutorial/problem.yaml \
    --tolerance config/tolerance.yaml \
    --solution tutorial/solution.pck
  ╔═══════════════════════════════════════════════════════╗
  ║  ╔═══╗   ╔═══╦═══╦═══╦═══╗            3D PEEC Solver  ║
  ║  ║╔═╗║   ║╔═╗║╔══╣╔══╣╔═╗║      Quasi-Magnetostatics  ║
  ║  ║╚═╝╠╗ ╔╣╚═╝║╚══╣╚══╣║ ╚╝          Frequency Domain  ║
  ║  ║╔══╣║ ║║╔══╣╔══╣╔══╣║ ╔╗          Voxel Geometries  ║
  ║  ║║  ║╚═╝║║  ║╚══╣╚══╣╚═╝║       FFT/GPU Accelerated  ║
  ║  ╚╝  ╚═╗ ╠╝  ╚═══╩═══╩═══╝    Python and Open Source  ║
  ╚══════╦═╝ ╠════════════════════════════════════════════╝
         ╚═══╝
  ╔═══════════════════════════════════════════════════════╗
  ║ Website - https://pypeec.otvam.ch                     ║
  ║ Thomas Guillod - Dartmouth College                    ║
  ║ Mozilla Public License Version 2.0                    ║
  ╚═══════════════════════════════════════════════════════╝

00:00:00.00 : MAIN     : INFO     : load the input data
00:00:00.57 : MAIN     : INFO     : load the solver
00:00:00.64 : MAIN     : INFO     : run the solver
00:00:00.64 : SOLVER   : INFO     : check the input data
00:00:00.64 : SOLVER   : INFO     : combine the input data
00:00:00.64 : SOLVER   : INFO     : init : enter : timing
00:00:00.64 : SOLVER   : INFO     :     voxel_geometry : enter : timing
00:00:00.83 : SOLVER   : INFO     :     voxel_geometry : exit : 00:00:00.18
00:00:00.83 : SOLVER   : INFO     :     system_tensor : enter : timing
00:00:00.83 : GREEN    : DEBUG    :         analytical solution: 6D / 1
00:00:00.85 : GREEN    : DEBUG    :         analytical solution: 6D / 4624
00:00:01.02 : GREEN    : DEBUG    :         numerical approximation: 6D / 326432
00:00:01.04 : SOLVER   : INFO     :     system_tensor : exit : 00:00:00.20
00:00:01.04 : SOLVER   : INFO     :     problem_geometry : enter : timing
00:00:01.08 : PROBLEM  : DEBUG    :         n_voxel_total = 331056
00:00:01.08 : PROBLEM  : DEBUG    :         n_voxel_used = 21225
00:00:01.08 : PROBLEM  : DEBUG    :         n_face_total = 993168
00:00:01.08 : PROBLEM  : DEBUG    :         n_face_used = 42094
00:00:01.08 : PROBLEM  : DEBUG    :         n_voxel_electric = 21225
00:00:01.08 : PROBLEM  : DEBUG    :         n_voxel_magnetic = 0
00:00:01.08 : PROBLEM  : DEBUG    :         n_face_electric = 42094
00:00:01.08 : PROBLEM  : DEBUG    :         n_face_magnetic = 0
00:00:01.08 : PROBLEM  : DEBUG    :         n_src_current = 0
00:00:01.08 : PROBLEM  : DEBUG    :         n_src_voltage = 722
00:00:01.08 : PROBLEM  : DEBUG    :         ratio_voxel = 6.41e-02
00:00:01.08 : PROBLEM  : DEBUG    :         ratio_face = 4.24e-02
00:00:01.08 : SOLVER   : INFO     :     problem_geometry : exit : 00:00:00.04
00:00:01.08 : SOLVER   : INFO     :     system_matrix : enter : timing
00:00:01.08 : FFT      : DEBUG    :         multiplication: inductance
00:00:01.08 : FFT      : DEBUG    :             tensor size: (132, 132, 19)
00:00:01.08 : FFT      : DEBUG    :             tensor footprint: 40.41 MB
00:00:01.08 : FFT      : DEBUG    :             library: SciPy / GPU: False
00:00:01.17 : SOLVER   : INFO     :     system_matrix : exit : 00:00:00.08
00:00:01.17 : SOLVER   : INFO     : init : exit : 00:00:00.52
00:00:01.17 : SOLVER   : INFO     : run sweep: sim_default : enter : timing
00:00:01.17 : SOLVER   : INFO     :     problem_value : enter : timing
00:00:01.18 : SOLVER   : INFO     :     problem_value : exit : 00:00:00.01
00:00:01.18 : SOLVER   : INFO     :     equation_system : enter : timing
00:00:01.20 : FACTOR   : DEBUG    :         factorization: electric
00:00:01.20 : FACTOR   : DEBUG    :             matrix size: (21947, 21947)
00:00:01.20 : FACTOR   : DEBUG    :             matrix elements: 107579
00:00:01.20 : FACTOR   : DEBUG    :             matrix density: 2.23e-04
00:00:01.20 : FACTOR   : DEBUG    :             library: SuperLU
00:00:01.20 : FACTOR   : DEBUG    :             compute factorization
00:00:01.33 : FACTOR   : DEBUG    :             factorization success
00:00:01.33 : FACTOR   : DEBUG    :         factorization: magnetic
00:00:01.34 : SOLVER   : INFO     :     equation_system : exit : 00:00:00.15
00:00:01.34 : SOLVER   : INFO     :     equation_solver : enter : timing
00:00:01.34 : COND     : DEBUG    :         condition: electric
00:00:01.34 : COND     : DEBUG    :             matrix size: (21947, 21947)
00:00:01.34 : COND     : DEBUG    :             matrix elements: 107579
00:00:01.34 : COND     : DEBUG    :             matrix density: 2.23e-04
00:00:01.34 : COND     : DEBUG    :             compute LU decomposition
00:00:01.49 : COND     : DEBUG    :             estimate norm of the inverse
00:00:01.63 : COND     : DEBUG    :             estimate norm of the matrix
00:00:01.69 : COND     : DEBUG    :             compute condition estimate
00:00:01.69 : COND     : DEBUG    :         condition: magnetic
00:00:01.69 : EQUATION : DEBUG    :         condition summary
00:00:01.69 : EQUATION : DEBUG    :             check = True
00:00:01.69 : EQUATION : DEBUG    :             status = True
00:00:01.69 : EQUATION : DEBUG    :             value_electric = 3.25e+06
00:00:01.69 : EQUATION : DEBUG    :             value_magnetic = 0.00e+00
00:00:01.69 : EQUATION : DEBUG    :             matrix condition is good
00:00:01.69 : ITER     : DEBUG    :         matrix solver
00:00:01.69 : ITER     : DEBUG    :             init solver
00:00:01.69 : ITER     : DEBUG    :             solver: GMRES
00:00:01.69 : ITER     : DEBUG    :             n_dof: 64041
00:00:01.69 : ITER     : DEBUG    :             call solver
00:00:01.76 : ITER     : DEBUG    :             i = 1 / 0.00e+00+0.00e+00j VA
00:00:06.25 : ITER     : DEBUG    :             i = 2 / 8.44e-01+5.40e+00j VA
00:00:06.62 : EQUATION : DEBUG    :         solver summary
00:00:06.62 : EQUATION : DEBUG    :             n_dof = 64041
00:00:06.62 : EQUATION : DEBUG    :             n_iter = 2
00:00:06.62 : EQUATION : DEBUG    :             n_sys_eval = 12
00:00:06.62 : EQUATION : DEBUG    :             n_pcd_eval = 13
00:00:06.62 : EQUATION : DEBUG    :             res_rms = 1.52e-09
00:00:06.62 : EQUATION : DEBUG    :             check = True
00:00:06.62 : EQUATION : DEBUG    :             status_pcd = True
00:00:06.62 : EQUATION : DEBUG    :             status_solver = True
00:00:06.62 : EQUATION : DEBUG    :             status_res = True
00:00:06.62 : EQUATION : DEBUG    :             convergence achieved
00:00:06.62 : SOLVER   : INFO     :     equation_solver : exit : 00:00:05.28
00:00:06.62 : SOLVER   : INFO     :     extract_solution : enter : timing
00:00:06.96 : SOLUTION : DEBUG    :         domain: trace_via
00:00:06.96 : SOLUTION : DEBUG    :             P_electric = 8.05e-01 W
00:00:06.96 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:06.96 : SOLUTION : DEBUG    :             P_tot = 8.05e-01 W
00:00:06.96 : SOLUTION : DEBUG    :         domain: src_sink
00:00:06.96 : SOLUTION : DEBUG    :             P_electric = 7.84e-03 W
00:00:06.96 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:06.96 : SOLUTION : DEBUG    :             P_tot = 7.84e-03 W
00:00:06.96 : SOLUTION : DEBUG    :         terminal: src
00:00:06.96 : SOLUTION : DEBUG    :             V = +9.99e-01 + +5.40e-03j V
00:00:06.96 : SOLUTION : DEBUG    :             I = +8.74e-01 + -5.40e+00j A
00:00:06.96 : SOLUTION : DEBUG    :             S = +4.22e-01 + +2.70e+00j VA
00:00:06.96 : SOLUTION : DEBUG    :         terminal: sink
00:00:06.96 : SOLUTION : DEBUG    :             V = -9.99e-01 + -5.40e-03j V
00:00:06.96 : SOLUTION : DEBUG    :             I = -8.74e-01 + +5.40e+00j A
00:00:06.96 : SOLUTION : DEBUG    :             S = +4.22e-01 + +2.70e+00j VA
00:00:06.96 : SOLUTION : DEBUG    :         integral
00:00:06.96 : SOLUTION : DEBUG    :             S_tot_real = 8.44e-01 VA
00:00:06.96 : SOLUTION : DEBUG    :             S_tot_imag = 5.40e+00j VA
00:00:06.96 : SOLUTION : DEBUG    :             P_electric = 8.13e-01 W
00:00:06.96 : SOLUTION : DEBUG    :             P_magnetic = 0.00e+00 W
00:00:06.96 : SOLUTION : DEBUG    :             W_electric = 4.30e-07 J
00:00:06.96 : SOLUTION : DEBUG    :             W_magnetic = 0.00e+00 J
00:00:06.96 : SOLUTION : DEBUG    :             P_tot = 8.13e-01 W
00:00:06.96 : SOLUTION : DEBUG    :             W_tot = 4.30e-07 J
00:00:06.96 : SOLVER   : INFO     :     extract_solution : exit : 00:00:00.34
00:00:06.96 : SOLVER   : INFO     : run sweep: sim_default : exit : 00:00:05.79
00:00:06.96 : SOLVER   : INFO     : duration: 00:00:06.32
00:00:06.96 : SOLVER   : INFO     : successful termination
00:00:06.96 : MAIN     : INFO     : save the results

Plotter: Plot the Solution

# Run the plotter
#   - solution.pck - contains the problem solution (input)
#   - point.yaml - contains the points used for field evaluation (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.pck \
    --point tutorial/point.yaml \
    --plotter config/plotter.yaml \
    --tag_plot V_c_abs J_c_norm H_norm residuum
../_images/plotter_V_c_abs.png

Plot showing the electric potential.

../_images/plotter_J_c_norm.png

Plot showing the current density.

../_images/plotter_H_norm.png

Plot showing the generated magnetic field.

../_images/plotter_residuum.png

Plot showing the equation system residuum.