DualMaxwell: Hybrid Dual-Network PINN for Maxwell's Equations
This repository provides the official Python implementation for the paper: "A Novel, Hybrid, Dual-Network PINN Framework for Solving Maxwell's Equations: Overcoming Numerical Instabilities, Scale Imbalance, and Sharp Geometries".
This package implements a framework for simulating electromagnetic (EM) fields by solving the full, 4D, vector Maxwell's equations using Physics-Informed Neural Networks (PINNs).
Key Features & Challenges Addressed
This framework is specifically engineered to solve critical failure modes in standard PINN implementations:
- The Scale Challenge: Overcomes the inherent "Scale Imbalance" (up to $10^9$) between Electric ($E$) and Magnetic ($B$) fields using non-dimensionalization.
- The Geometry Challenge: Utilizes GeoNet (a Multi-Resolution Hash Grid) to learn "sharp" geometry SDFs, avoiding the smoothing bias of standard MLPs.
- The Training Challenge: Implements a dual-network strategy with aggressive weight balancing to prevent "Catastrophic Forgetting" and trivial solutions.
Installation
You can install and run this framework on a local machine or in cloud environments like Google Colab.
Note: This repository contains large model files (.pth). If running locally, ensure you have Git LFS installed.
Option 1: Google Colab (Recommended for Testing)
If you are running this on Google Colab, copy and paste the following commands into a code cell:
# 1. Clone the repository from Hugging Face
!git clone https://huggingface.co/ayda138000/DualMaxwell
# 2. Enter the directory
%cd DualMaxwell
# 3. Install the package and dependencies
!pip install .
!pip install torch numpy matplotlib huggingface_hub
Option 2: Local Machine (Terminal)
# Install Git LFS if you haven't already
git lfs install
# Clone the repository
git clone https://huggingface.co/ayda138000/DualMaxwell
# Navigate to the folder
cd DualMaxwell
# Install the package
pip install .
Running the Simulation
The repository includes an example_usage.py script that loads the pre-trained models (GeoNet and PhysNet) and visualizes the results.
CRITICAL: Prepare Your Data (ground_truth.npz)
Before running the example, provide your own data file:
- The script expects a file named
ground_truth.npzin the rootDualMaxwelldirectory. - Google Colab: Upload your
.npzfile into theDualMaxwellfolder via the "Files" tab on the left sidebar. - Local: Place the file in the cloned directory.
Required Data Structure
Your ground_truth.npz file must contain the following NumPy arrays:
coords: Shape(N, 3). Spatial coordinates $(x, y, z)$ used to normalize the geometry inputs.t: Shape(T_steps,)or(N, 1). Time data, used to determine the maximum simulation time ($T_{max}$).
Note: If this file is missing or the keys coords and t do not exist, the script will exit with an error.
Execution
Once the file is uploaded/placed, run the script:
In Google Colab:
!python example_usage.py
In Terminal:
python example_usage.py
Expected Output
The script performs the following actions:
- Loads GeoNet (
geonet_real_v30.pth) to handle geometry boundaries. - Loads PhysNet (
physnet_v31_real.pth) to predict EM fields. - Visualizes the $E_x$ field at time $t = 0.75 \times T_{max}$.
- Saves the result as an image:
v35_final_plot_defense.png.
Models Included
- GeoNetHash: Pre-trained on the geometry SDF using Multi-Resolution Hash Grids.
- MaxwellPINN: The physics-informed network trained to solve Maxwell's equations.
License
This project is licensed under the MIT License.