This repository contains an implementation of Physics-Informed Neural Networks (PINNs) for solving partial differential equations (PDEs) and ordinary differential equations (ODEs). PINNs leverage the power of neural networks to approximate the solution of PDEs and ODEs by incorporating the governing equations and boundary conditions into the loss function.
- Solve PDEs and ODEs using physics-informed neural networks
- Flexible and modular framework for defining custom PDEs, ODEs, initial conditions, and boundary conditions
- Easy-to-use training and evaluation pipeline
- Visualization of the approximated solution
- Python 3.x
- PyTorch
- NumPy
- Matplotlib
-
Clone the repository:
git clone https://github.com/your-username/physics-informed-neural-networks.git
-
Install the required dependencies:
pip install torch numpy matplotlib
-
Define your problem:
- Specify the PDE or ODE governing equation in the
pde_function
orode_function
. - Define the initial and boundary conditions using the
ic_function
andbc_function
. - Set the problem domain and parameters, such as the spatial and temporal ranges and the number of training points.
- Specify the PDE or ODE governing equation in the
-
Create an instance of the
PhysicsInformedNN
model:model = PhysicsInformedNN(input_dim, hidden_dim, output_dim)
-
Generate the training data using the
generate_training_data
function:x_ic, t_bc, x_bc, u_ic, u_bc, x_collocation, t_collocation = generate_training_data(...)
-
Create an optimizer and train the model:
optimizer = get_optimizer(model) for epoch in range(num_epochs): # Training loop ...
-
Evaluate the trained model on test data and visualize the approximated solution:
with torch.no_grad(): # Evaluate the model on test data ... # Visualize the solution plt.figure(figsize=(8, 6)) plt.pcolormesh(...) plt.colorbar(label='Solution') plt.xlabel('x') plt.ylabel('t') plt.title('PDE/ODE Solution') plt.tight_layout() plt.show()
The repository includes example scripts for solving different PDEs and ODEs:
test_heat_equation.py
: Solves the 1D heat equation, a parabolic PDE.test_burger_equation.py
: Solves the 1D Burger's equation, a parabolic PDE.
You can use these examples as a starting point and modify them to solve your specific PDEs or ODEs.
-
physicsinformed/models/physics_informed_models.py
: Contains the implementation of the Physics-Informed Neural Network (PINN) model. -
physicsinformed/models/losses.py
: Defines the physics-informed loss functions for PDEs and ODEs. -
physicsinformed/training/optimizers.py
: Provides the optimizer used for training the PINN model. -
physicsinformed/utils/data_utils.py
: Contains utility functions for generating training data.
Contributions to this repository are welcome. If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
The implementation of Physics-Informed Neural Networks in this repository is based on the research paper:
- M. Raissi, P. Perdikaris, and G. E. Karniadakis. "Physics-Informed Neural Networks: A Deep Learning Framework for Solving Forward and Inverse Problems Involving Nonlinear Partial Differential Equations." Journal of Computational Physics, 2019.
Special thanks to the authors for their groundbreaking work in this field.