Skip to main content

A package for Electromagnetic applications using MTFLibrary.

Project description

em-simulation-platform

Python CI PyPI version License: MIT Documentation Status

EM simulation tools for electromagnetic field analysis, visualization, and benchmarking.

Features

  • Modular solvers for EM field calculations
  • Source modeling (dipoles, wires, loops, solenoids)
  • Advanced plotting and visualization
  • Demo scripts for validation and exploration
  • Benchmarking utilities
  • Extensible architecture for research and teaching

Installation

This project uses pyproject.toml to manage dependencies. For development, it is recommended to install the package in "editable" mode along with the development extras.

# Clone the repository
git clone https://github.com/shashi-manikonda/em-simulation-platform.git
cd em-simulation-platform

# (Recommended) Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install the package in editable mode with all development dependencies
pip install -e .[dev,benchmark]

The [dev] extra includes dependencies for running tests and building the documentation. The [benchmark] extra includes dependencies for running the benchmark scripts.

Usage

Run all demos

python run_all_demos.py

Run a specific demo

To run a specific demo, you can execute the script directly. For notebooks, you can use a tool like jupytext to run it as a script:

jupytext --execute demos/em/01_validation_demo.ipynb

Run tests

pytest

Building the Documentation

This project uses Sphinx to generate API documentation from the source code. The necessary dependencies are included in the [dev] extra.

Build Script

A helper script is provided to simplify the build process. To build the documentation, run the following command from the project root:

./docs/build_docs.sh

The script will clean the previous build and generate the HTML documentation in the docs/_build/html directory.

Viewing the Documentation

To view the documentation, open the docs/_build/html/index.html file in your web browser.

Example: Calculate and Plot the Magnetic Field of a Ring Coil

This example demonstrates how to define a current source, calculate its magnetic field on a grid, and visualize the results.

import numpy as np
import matplotlib.pyplot as plt
from em_app.sources import RingCoil
from em_app.solvers import calculate_b_field
from mtflib import mtf

# Initialize the MTF library for vector field calculations
mtf.initialize_mtf(max_order=1, max_dimension=4)

# --- 1. Setup the Coil Geometry ---
coil = RingCoil(
    current=1.0,
    radius=0.5,
    num_segments=20,
    center_point=np.array([0, 0, 0]),
    axis_direction=np.array([0, 0, 1]),
)

# --- 2. Define the Field Points for Calculation ---
grid_size = 1.0
num_points = 15
x_points = np.linspace(-grid_size, grid_size, num_points)
z_points = np.linspace(-grid_size, grid_size, num_points)
X, Z = np.meshgrid(x_points, z_points)
field_points = np.vstack([X.ravel(), np.zeros_like(X.ravel()), Z.ravel()]).T

# --- 3. Calculate the Magnetic Field ---
b_field = calculate_b_field(coil, field_points)
b_vectors = np.array([b.to_numpy_array() for b in b_field._vectors_mtf])

# --- 4. Plot the Results ---
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111, projection="3d")

# Plot the coil geometry
coil.plot(ax, color="b", wire_thickness=0.02)

# Plot the magnetic field vectors
ax.quiver(
    field_points[:, 0],
    field_points[:, 1],
    field_points[:, 2],
    b_vectors[:, 0],
    b_vectors[:, 1],
    b_vectors[:, 2],
    length=0.2,
    normalize=True,
    color="gray",
)

# --- 5. Customize and Show the Plot ---
ax.set_title("Magnetic Field of a Ring Coil")
ax.set_xlabel("X (m)")
ax.set_ylabel("Y (m)")
ax.set_zlabel("Z (m)")
ax.view_init(elev=20.0, azim=-60)
plt.show()

Live Demos

For more detailed examples, see the demo scripts in the demos/em directory. These scripts cover topics such as solver validation, dipole approximation, and advanced plotting.

You can run all demos at once using the following command:

python run_all_demos.py

This will generate output files and plots in the runoutput directory.

Project Structure

  • src/em_app/ - Core library modules
  • demos/em/ - Demo scripts
  • benchmarks/ - Performance and accuracy benchmarks
  • tests/ - Unit tests

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

em_app-0.2.1.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

em_app-0.2.1-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file em_app-0.2.1.tar.gz.

File metadata

  • Download URL: em_app-0.2.1.tar.gz
  • Upload date:
  • Size: 30.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for em_app-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7a0bce6799fa778a05cc313b7943ceee79ffb0ef6baeb53feaaaaf13c28e5d1c
MD5 af4608929e50f959e9d26bf6d2178688
BLAKE2b-256 63912dcf27e2e57cdae6e56d3625281809bec78987a2660b3b7a8dc1c17a7eed

See more details on using hashes here.

File details

Details for the file em_app-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: em_app-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for em_app-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e83bbe5e888a60a0b3c7b6facb4d71214b7fe7c03695e290dc52506959c936f
MD5 2d5de9d0989d4841e874e6da7cd0abed
BLAKE2b-256 d36f222c5f712688920fde6fb81a18f9056009b97d89e18157e84311458f1443

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page