A package for Electromagnetic applications using MTFLibrary.
Project description
em-simulation-platform
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 modulesdemos/em/- Demo scriptsbenchmarks/- Performance and accuracy benchmarkstests/- Unit tests
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file em_app-0.2.2.tar.gz.
File metadata
- Download URL: em_app-0.2.2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85cde69af3d7dfc4d4e19603e912196fcddcf6ba7c6f66d1d851fa021cae82f3
|
|
| MD5 |
ac22c2d0ce4a0f87b1b760a7815c6523
|
|
| BLAKE2b-256 |
d71da5bea7284309df4950e989bb96f0e25d2d9b446bf4793a6d4290be5f7bc9
|
File details
Details for the file em_app-0.2.2-py3-none-any.whl.
File metadata
- Download URL: em_app-0.2.2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8fcd0cbe33fb51ee42c13377fea9c893a4b7b9a35af2f0a9a5c0cbe07045cc5e
|
|
| MD5 |
3237f4dce6fbeebcd5ee1350c9f111b1
|
|
| BLAKE2b-256 |
9aa9b841c1f1df905acd4af11801fd290129bd9ca6c625f7676154b4b84605dd
|