Skip to content

Packaged code for PyPI by singhaa #6

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
3 changes: 3 additions & 0 deletions $HOME/.pypirc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[testpypi]
username = __token__
password = pypi-AgENdGVzdC5weXBpLm9yZwIkMGU4ZTM2YzgtMWU1My00ZjI5LWFhYjgtMjdlNjdjYmNkMzUxAAIqWzMsIjFkNDA2ODdmLTYyZGItNDhhOC1hYTJmLTk5MGJhYTY1NmFhNSJdAAAGIGuTgrGeCqS9KP_XKI-zH8aHHbnZ1e1pUL1ejEy_VqHS
Binary file added Figure_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added __pycache__/output.cpython-313.pyc
Binary file not shown.
33 changes: 33 additions & 0 deletions adr1ja_diffusion2d.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Metadata-Version: 2.1
Name: adr1ja_diffusion2d
Version: 0.0.2
Summary: A simulation package for solving the 2D diffusion equation using finite difference methods
Author-email: Adrija <adrijasingh13@gmail.com>
Keywords: diffusion,simulation,finite difference,scientific computing
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=2.1.0
Requires-Dist: matplotlib>=3.9.0

# diffusion2D

## Instructions for students

Please follow the instructions in [pypi_exercise.md](https://github.com/Simulation-Software-Engineering/Lecture-Material/blob/main/03_building_and_packaging/pypi_exercise.md).

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

## Installing the package

### Using pip3 to install from PyPI

### Required dependencies

## Running this package

## Citing
9 changes: 9 additions & 0 deletions adr1ja_diffusion2d.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LICENSE
README.md
pyproject.toml
setup.py
adr1ja_diffusion2d.egg-info/PKG-INFO
adr1ja_diffusion2d.egg-info/SOURCES.txt
adr1ja_diffusion2d.egg-info/dependency_links.txt
adr1ja_diffusion2d.egg-info/requires.txt
adr1ja_diffusion2d.egg-info/top_level.txt
1 change: 1 addition & 0 deletions adr1ja_diffusion2d.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions adr1ja_diffusion2d.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy>=2.1.0
matplotlib>=3.9.0
1 change: 1 addition & 0 deletions adr1ja_diffusion2d.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Empty file added adr1ja_diffusion2d/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
57 changes: 57 additions & 0 deletions adr1ja_diffusion2d/diffusion2d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""
Solving the two-dimensional diffusion equation

Example acquired from https://scipython.com/book/chapter-7-matplotlib/examples/the-two-dimensional-diffusion-equation/
"""

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

def do_timestep(u_nm1, u, D, dt, dx2, dy2):
# Propagate with forward-difference in time, central-difference in space
u[1:-1, 1:-1] = u_nm1[1:-1, 1:-1] + D * dt * (
(u_nm1[2:, 1:-1] - 2 * u_nm1[1:-1, 1:-1] + u_nm1[:-2, 1:-1]) / dx2
+ (u_nm1[1:-1, 2:] - 2 * u_nm1[1:-1, 1:-1] + u_nm1[1:-1, :-2]) / dy2
)
u_nm1 = u.copy()
return u_nm1, u

def solve(dx=0.1, dy=0.1, D=4.0):
# Parameters
w = h = 10.0
T_cold = 300
T_hot = 700
nx, ny = int(w / dx), int(h / dy)
dx2, dy2 = dx * dx, dy * dy
dt = dx2 * dy2 / (2 * D * (dx2 + dy2))
nsteps = 101
n_output = [0, 10, 50, 100]

# Initial conditions
u0 = T_cold * np.ones((nx, ny))
u = u0.copy()
r = min(h, w) / 4.0
cx, cy = w / 2.0, h / 2.0
r2 = r ** 2
for i in range(nx):
for j in range(ny):
if (i * dx - cx) ** 2 + (j * dy - cy) ** 2 < r2:
u0[i, j] = T_hot

# Time loop and plotting
fig = plt.figure()
fig_counter = 0
for n in range(nsteps):
u0, u = do_timestep(u0, u, D, dt, dx2, dy2)
if n in n_output:
fig_counter += 1
im = create_plot(u, T_cold, T_hot, dt, n, fig, fig_counter)

# Output all plots together
output_plots(im, fig)

solve()



17 changes: 17 additions & 0 deletions adr1ja_diffusion2d/output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import matplotlib.pyplot as plt

def create_plot(u, T_cold, T_hot, dt, n, fig, fig_counter):
"""Creates a single plot for a given time step."""
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 im # return the image for color bar usage later

def output_plots(im, fig):
"""Combines plots into a single figure and displays the color bar."""
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()
81 changes: 0 additions & 81 deletions diffusion2d.py

This file was deleted.

Binary file added dist/adr1ja_diffusion2d-0.0.2-py3-none-any.whl
Binary file not shown.
Binary file added dist/adr1ja_diffusion2d-0.0.2.tar.gz
Binary file not shown.
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"]
build-backend = "setuptools.build_meta"

[project]
name = "adr1ja_diffusion2d"
version = "0.0.2"
description = "A simulation package for solving the 2D diffusion equation using finite difference methods"
readme = "README.md"
requires-python = ">=3.10"
authors = [{name = "Adrija", email = "adrijasingh13@gmail.com"}]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
keywords = ["diffusion", "simulation", "finite difference", "scientific computing"]
dependencies = [
"numpy>=2.1.0",
"matplotlib>=3.9.0"
]
Empty file added setup.config
Empty file.
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from setuptools import setup, find_packages

setup(
name="adr1ja_diffusion2d",
version="0.0.2",
packages=find_packages(where="adr1ja_diffusion2d"),
)