ayda138000 commited on
Commit
c286f6f
·
verified ·
1 Parent(s): 8721d0a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +77 -63
README.md CHANGED
@@ -1,106 +1,120 @@
1
- # DualMaxwell (pinn_electromagnetics)
2
 
3
- [cite_start]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"**[cite: 1].
4
 
5
- [cite_start]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)[cite: 8, 19].
6
 
7
- [cite_start]The primary goal of this framework is to overcome the fundamental challenges that cause naive PINN implementations to fail in real-world engineering problems[cite: 6, 8].
8
 
9
- ## Key Challenges Addressed
10
 
11
- This framework is specifically engineered to solve three critical failure modes:
12
 
13
- 1. [cite_start]**The Scale Challenge:** The inherent "Scale Imbalance" (up to $10^9$) between the Electric (E) and Magnetic (B) fields in SI units, which causes the optimizer to ignore the B-field loss[cite: 10, 41].
14
- 2. [cite_start]**The Geometry Challenge:** The "Smoothing Bias" of standard MLPs, which fails to learn the "Sharp Corners" of real geometries (producing a "Squircle" instead)[cite: 11, 53].
15
- 3. [cite_start]**The Training Challenge:** The "Loss War" between the physics (PDE) and data (boundaries), leading to "Trivial Solutions" (e.g., $E=0$) and "Catastrophic Forgetting" during training[cite: 13, 46, 48].
16
 
17
- ## The Dual-Network Framework
18
 
19
- [cite_start]To solve these challenges, we developed a novel, hybrid, dual-network architecture[cite: 14].
20
 
 
21
 
 
22
 
23
- Our system is composed of:
24
 
25
- * **1. [cite_start]Non-Dimensionalization:** We non-dimensionalize the entire Maxwell problem, which completely resolves the E/B "Scale Imbalance" (Solution to Challenge 1)[cite: 16, 58].
26
- * **2. [cite_start]GeoNet (v26):** An advanced **"Multi-Resolution Hash Grid"** network (inspired by Instant-NGP)[cite: 17, 60]. [cite_start]It is pre-trained to learn the "sharp" geometry SDF and is then frozen (Solution to Challenge 2)[cite: 18, 60].
27
- * **3. [cite_start]PhysNet (v34):** A 4D (x,y,z,t) PINN that solves the full, non-dimensionalized Maxwell's equations[cite: 19, 61].
28
- * **4. [cite_start]Novel Training Strategy (v34):** A two-stage **"Pre-training and Annealing"** strategy combined with **"Aggressive Weight Balancing"** ($\lambda_{source}=10000$)[cite: 20, 62]. [cite_start]This forces the model to learn the "Source" first and prevents "Catastrophic Forgetting" (Solution to Challenge 3)[cite: 21].
29
 
30
- ---
 
 
31
 
32
- ## Installation and Usage
 
33
 
34
- **IMPORTANT:** This repository uses **Git LFS** (Large File Storage) to manage large model (`.pth`) and data (`.npz`) files. You **must** have Git LFS installed to clone this repository correctly.
 
 
 
35
 
36
- ### Step 1: Install Git LFS
37
 
38
- If you don't have it, install it from [https://git-lfs.github.com](https://git-lfs.github.com).
39
- Then, enable it (you only need to do this once per machine):
40
  ```bash
 
41
  git lfs install
42
- ```
43
 
44
- ### Step 2: Clone the Repository
 
45
 
46
- Clone this repository. Git LFS will automatically download the large files.
47
- ```bash
48
- git clone [https://huggingface.co/ayda138000/DualMaxwell](https://huggingface.co/ayda138000/DualMaxwell)
 
 
49
  ```
50
 
51
- ### Step 3: Install the Package
52
 
53
- Navigate into the cloned directory and install the package using `pip`. This will also install all required dependencies listed in `setup.py` (like `torch`, `numpy`, etc.).
54
- ```bash
55
- cd DualMaxwell
56
- pip install .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  ```
58
 
59
- ### Step 4: Run the Example
60
 
61
- You can now run the example script to load the pre-trained models, run the simulation, and visualize the results.
62
  ```bash
63
  python example_usage.py
64
  ```
65
 
66
  ---
67
 
68
- ## Expected Data Format
69
 
70
- The `example_usage.py` script expects a `ground_truth.npz` file containing the following NumPy arrays:
71
 
72
- * **`coords`**: `(N, 3)` array of 3D coordinates for sampling the geometry.
73
- * **`sdf`**: `(N,)` array of Signed Distance Function (SDF) values for the `coords`.
74
- * **`E0`**: `(N, 3)` array of initial E-field values (at $t=0$) at `coords`.
75
- * **`B0`**: `(N, 3)` array of initial B-field values (at $t=0$) at `coords`.
76
- * **`source_position`**: `(3,)` array for the (x,y,z) coordinates of the antenna source.
77
- * **`source_orientation`**: `(3,)` array for the orientation of the source E-field (e.g., `[1,0,0]` for x-polarized).
78
- * **`source_signal`**: `(T_steps,)` array for the time-varying signal of the source.
79
- * **`t`**: `(T_steps,)` array of time points corresponding to `source_signal`.
80
 
81
  ---
82
 
83
- ## Core Components
84
-
85
- ### Models Included
86
-
87
- * `HashGridEncoder`: Efficient multi-resolution hash grid encoder for spatial coordinates.
88
- * [cite_start]`GeoNetHash`: A geometry network that learns Signed Distance Functions (SDFs) of complex objects using `HashGridEncoder`[cite: 68, 119, 120].
89
- * `PositionalEncoder4D`: A standard positional encoder for 4D (x, y, z, t) inputs.
90
- * [cite_start]`MaxwellPINN`: The core physics-informed neural network that predicts electromagnetic fields (E, B) based on space and time coordinates[cite: 72].
91
 
92
- ### Loss Functions Inc
93
- * `compute_all_derivatives`: Helper function to compute all necessary partial derivatives of E and B fields with respect to x, y, z, and t.
94
- * [cite_start]`compute_maxwell_loss`: Implements the physics-based loss derived from the non-dimensionalized Maxwell's equations [cite: 78, 144-150].
95
- * [cite_start]`compute_data_loss`: Computes the data-driven loss from initial conditions (E0, B0) and source boundary conditions [cite: 75, 204-207].
96
 
97
- ## Citation
98
 
99
- If you use this framework or code in your research, please cite our paper:
100
 
101
- ```bibtex
102
- title = {A Novel, Hybrid, Dual-Network PINN Framework for Solving Maxwell's Equations: Overcoming Numerical Instabilities, Scale Imbalance, and Sharp Geometries},
103
 
104
- ## License
105
-
106
- This project is licensed under the MIT License.
 
1
+ # DualMaxwell: Hybrid Dual-Network PINN for Maxwell's Equations
2
 
3
+ 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"**.
4
 
5
+ 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).
6
 
7
+ ---
8
 
9
+ ## Key Features & Challenges Addressed
10
 
11
+ This framework is specifically engineered to solve critical failure modes in standard PINN implementations:
12
 
13
+ 1. **The Scale Challenge:** Overcomes the inherent "Scale Imbalance" (up to $10^9$) between Electric ($E$) and Magnetic ($B$) fields using non-dimensionalization.
14
+ 2. **The Geometry Challenge:** Utilizes **GeoNet** (a Multi-Resolution Hash Grid) to learn "sharp" geometry SDFs, avoiding the smoothing bias of standard MLPs.
15
+ 3. **The Training Challenge:** Implements a dual-network strategy with aggressive weight balancing to prevent "Catastrophic Forgetting" and trivial solutions.
16
 
17
+ ---
18
 
19
+ ## Installation
20
 
21
+ You can install and run this framework on a local machine or in cloud environments like Google Colab.
22
 
23
+ **Note:** This repository contains large model files (`.pth`). If running locally, ensure you have **Git LFS** installed.
24
 
25
+ ### Option 1: Google Colab (Recommended for Testing)
26
 
27
+ If you are running this on Google Colab, copy and paste the following commands into a code cell:
 
 
 
28
 
29
+ ```python
30
+ # 1. Clone the repository from Hugging Face
31
+ !git clone https://huggingface.co/ayda138000/DualMaxwell
32
 
33
+ # 2. Enter the directory
34
+ %cd DualMaxwell
35
 
36
+ # 3. Install the package and dependencies
37
+ !pip install .
38
+ !pip install torch numpy matplotlib huggingface_hub
39
+ ````
40
 
41
+ ### Option 2: Local Machine (Terminal)
42
 
 
 
43
  ```bash
44
+ # Install Git LFS if you haven't already
45
  git lfs install
 
46
 
47
+ # Clone the repository
48
+ git clone https://huggingface.co/ayda138000/DualMaxwell
49
 
50
+ # Navigate to the folder
51
+ cd DualMaxwell
52
+
53
+ # Install the package
54
+ pip install .
55
  ```
56
 
57
+ ---
58
 
59
+ ## Running the Simulation
60
+
61
+ The repository includes an `example_usage.py` script that loads the pre-trained models (GeoNet and PhysNet) and visualizes the results.
62
+
63
+ ### CRITICAL: Prepare Your Data (`ground_truth.npz`)
64
+
65
+ Before running the example, provide your own data file:
66
+
67
+ * The script expects a file named `ground_truth.npz` in the root `DualMaxwell` directory.
68
+ * **Google Colab:** Upload your `.npz` file into the `DualMaxwell` folder via the "Files" tab on the left sidebar.
69
+ * **Local:** Place the file in the cloned directory.
70
+
71
+ #### Required Data Structure
72
+
73
+ Your `ground_truth.npz` file must contain the following NumPy arrays:
74
+
75
+ * `coords`: Shape `(N, 3)`. Spatial coordinates $(x, y, z)$ used to normalize the geometry inputs.
76
+ * `t`: Shape `(T_steps,)` or `(N, 1)`. Time data, used to determine the maximum simulation time ($T_{max}$).
77
+
78
+ **Note:** If this file is missing or the keys `coords` and `t` do not exist, the script will exit with an error.
79
+
80
+ ### Execution
81
+
82
+ Once the file is uploaded/placed, run the script:
83
+
84
+ **In Google Colab:**
85
+
86
+ ```python
87
+ !python example_usage.py
88
  ```
89
 
90
+ **In Terminal:**
91
 
 
92
  ```bash
93
  python example_usage.py
94
  ```
95
 
96
  ---
97
 
98
+ ## Expected Output
99
 
100
+ The script performs the following actions:
101
 
102
+ 1. Loads GeoNet (`geonet_real_v30.pth`) to handle geometry boundaries.
103
+ 2. Loads PhysNet (`physnet_v31_real.pth`) to predict EM fields.
104
+ 3. Visualizes the $E_x$ field at time $t = 0.75 \times T_{max}$.
105
+ 4. Saves the result as an image: `v35_final_plot_defense.png`.
 
 
 
 
106
 
107
  ---
108
 
109
+ ## Models Included
 
 
 
 
 
 
 
110
 
111
+ * **GeoNetHash:** Pre-trained on the geometry SDF using Multi-Resolution Hash Grids.
112
+ * **MaxwellPINN:** The physics-informed network trained to solve Maxwell's equations.
 
 
113
 
 
114
 
115
+ ## License
116
 
117
+ This project is licensed under the MIT License.
 
118
 
119
+ ```
120
+ ```