Skip to content

Packaged code for PyPI by wanivi #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
__pycache__/
dist/
build/
*.egg-info/
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,30 @@ Please follow the instructions in [pypi_exercise.md](https://github.com/Simulati
The code used in this exercise is based on [Chapter 7 of the book "Learning Scientific Programming with Python"](https://scipython.com/book/chapter-7-matplotlib/examples/the-two-dimensional-diffusion-equation/).

## Project description
This project simulates the diffusion equation in 2D domain using finite difference methods. The simulation demonstrates how heat diffuses in a square region with an initial high-temperature circle at the center. The resulting temperature distrubution is visualized using Matplotliib.

## Installing the package
You can install this package from TestPyPI using the following command:
```bash
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple <your_username>_diffusion2D
```

### Using pip3 to install from PyPI
Once your package is live on PyPI, you can install it using:
```bash
pip install <your_username>_diffusion2D
```

### Required dependencies
This package requires numpy and matplotlib libraries.
These dependencies are automatically installed when you install the package via pip.

## Running this package
After installation, you can use following command to run the simulation:
```bash
python3 -m diffusion2d
```
This will generate a 2D plot showing the diffusion process at different time steps.
Comment on lines +29 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it is expected that instructions to run the package are provided.


## Citing
This project is based on materials from book [Learning Scientific Programming with Python](https://scipython.com/book/chapter-7-matplotlib/examples/two-dimensional-diffusion-equation/)
Binary file added diffusion_plots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["setuptools","wheel","build"]

[project]
name = "wanivi_diffusion2d"
description = "A 2D diffusion equation solver with visualization output"
version = "0.0.2"
authors = [
{name="Vaishnavi", email="vaishnaviwani671@gmail.com"}
]
readme = "README.md"
keywords = ["diffusion2D", "solver"]
classifiers = [
"Programming Language :: Python :: 3"
]
dependencies = [
"matplotlib",
"numpy"
]
requires-python = ">=3.0"
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from setuptools import setup

if __name__ == "__main__":
setup()
Empty file added src/diffusion2d_pkg/__init__.py
Empty file.
12 changes: 3 additions & 9 deletions diffusion2d.py → src/diffusion2d_pkg/diffusion2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import numpy as np
import matplotlib.pyplot as plt
from .output import create_plot, output_plots

# plate size, mm
w = h = 10.
Expand Down Expand Up @@ -68,14 +69,7 @@ def do_timestep(u_nm1, u, D, dt, dx2, dy2):
# Create figure
if n in n_output:
fig_counter += 1
ax = fig.add_subplot(220 + fig_counter)
im = ax.imshow(u.copy(), cmap=plt.get_cmap('hot'), vmin=T_cold, vmax=T_hot) # image for color bar axes
ax.set_axis_off()
ax.set_title('{:.1f} ms'.format(n * dt * 1000))
ax, im = create_plot(u,n,dt,T_cold,T_hot,fig,fig_counter)

# Plot output figures
fig.subplots_adjust(right=0.85)
cbar_ax = fig.add_axes([0.9, 0.15, 0.03, 0.7])
cbar_ax.set_xlabel('$T$ / K', labelpad=20)
fig.colorbar(im, cax=cbar_ax)
plt.show()
output_plots(fig, im)
15 changes: 15 additions & 0 deletions src/diffusion2d_pkg/output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import matplotlib.pyplot as plt

def create_plot(u, n, dt, T_cold, T_hot, fig, fig_counter):
ax=fig.add_subplot(220+fig_counter)
im=ax.imshow(u.copy(),cmap=plt.get_cmap('hot'),vmin=T_cold,vmax=T_hot)
ax.set_axis_off()
ax.set_title('{:.1f} ms'.format(n*dt*1000))
return ax, im

def output_plots(fig, im):
fig.subplots_adjust(right=0.85)
cbar_ax=fig.add_axes([0.9,0.15,0.03,0.7])
cbar_ax.set_xlabel('$T$/K',labelpad=20)
fig.colorbar(im,cax=cbar_ax)
plt.show()