-
Notifications
You must be signed in to change notification settings - Fork 26
Packaged code for PyPI by heidrifx
#5
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
heidrifx
wants to merge
5
commits into
Simulation-Software-Engineering:main
Choose a base branch
from
heidrifx:pypi
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
heidrifx_diffusion2d/_version.py export-subst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
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 heidrifx_diffusion2d.output import create_plot, output_plots | ||
|
||
def solve(dx = 0.1, dy = 0.1, D = 4): | ||
# plate size, mm | ||
w = h = 10. | ||
# intervals in x-, y- directions, mm | ||
dx = dy = 0.1 | ||
# Thermal diffusivity of steel, mm^2/s | ||
D = 4. | ||
|
||
# Initial cold temperature of square domain | ||
T_cold = 300 | ||
|
||
# Initial hot temperature of circular disc at the center | ||
T_hot = 700 | ||
|
||
# Number of discrete mesh points in X and Y directions | ||
nx, ny = int(w / dx), int(h / dy) | ||
|
||
# Computing a stable time step | ||
dx2, dy2 = dx * dx, dy * dy | ||
dt = dx2 * dy2 / (2 * D * (dx2 + dy2)) | ||
|
||
print("dt = {}".format(dt)) | ||
|
||
u0 = T_cold * np.ones((nx, ny)) | ||
u = u0.copy() | ||
|
||
# Initial conditions - circle of radius r centred at (cx,cy) (mm) | ||
r = min(h, w) / 4.0 | ||
cx = w / 2.0 | ||
cy = h / 2.0 | ||
r2 = r ** 2 | ||
for i in range(nx): | ||
for j in range(ny): | ||
p2 = (i * dx - cx) ** 2 + (j * dy - cy) ** 2 | ||
if p2 < r2: | ||
u0[i, j] = T_hot | ||
|
||
|
||
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 | ||
|
||
|
||
# Number of timesteps | ||
nsteps = 101 | ||
# Output 4 figures at these timesteps | ||
n_output = [0, 10, 50, 100] | ||
fig_counter = 0 | ||
fig = plt.figure() | ||
|
||
# Time loop | ||
for n in range(nsteps): | ||
u0, u = do_timestep(u0, u, D, dt, dx2, dy2) | ||
|
||
# Create figure | ||
if n in n_output: | ||
im, fig_counter = create_plot(u, T_cold, T_hot, n, dt, fig_counter, fig) | ||
|
||
# Plot output figures | ||
output_plots(fig, im) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import matplotlib.pyplot as plt | ||
|
||
def create_plot(u, T_cold, T_hot, n, dt, fig_counter, fig): | ||
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) | ||
ax.set_axis_off() | ||
ax.set_title('{:.1f} ms'.format(n * dt * 1000)) | ||
return im, fig_counter | ||
|
||
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() |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Metadata-Version: 2.1 | ||
Name: heidrifx_diffusion2d | ||
Version: 0.post0.dev5 | ||
Summary: A student project from the course 'Simulation Software Engineering' | ||
Keywords: SSE,student project | ||
Classifier: Programming Language :: Python :: 3 | ||
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication | ||
Classifier: Operating System :: OS Independent | ||
Requires-Python: >=3.6 | ||
Description-Content-Type: text/markdown | ||
License-File: LICENSE | ||
Requires-Dist: numpy | ||
Requires-Dist: matplotlib | ||
|
||
# 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 | ||
This code solves the diffusion equation in 2D over a square domain which is at a certain temperature and a circular disc at the center which is at a higher temperature. This code solves the diffusion equation using the Finite Difference Method. The thermal diffusivity and initial conditions of the system can be changed by the user. The code produces four plots at various timepoints of the simulation. The diffusion process can be clearly observed in these plots. | ||
|
||
## Installing the package | ||
|
||
### Using pip3 to install from PyPI | ||
For the default release use: | ||
|
||
```bash | ||
pip install --user --index-url https://test.pypi.org/simple/ heidrifx_diffusion2d | ||
``` | ||
|
||
For a pre-release version, i.e. a packed versioned by `versioneer` use for example: | ||
|
||
```bash | ||
pip install --user --index-url https://test.pypi.org/simple/ heidrifx-diffusion2d==0.post0.dev4 | ||
``` | ||
|
||
### Required dependencies | ||
```bash | ||
pip install numpy matplotlib | ||
``` | ||
|
||
## Running this package | ||
```python | ||
from sse-diffusion2d import diffusion2d | ||
|
||
diffusion2d.solve(dx = 0.1, dy = 0.1, D = 4) | ||
``` | ||
|
||
## Citing | ||
This was forked from https://github.com/Simulation-Software-Engineering/diffusion2D. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
LICENSE | ||
README.md | ||
pyproject.toml | ||
setup.cfg | ||
setup.py | ||
heidrifx_diffusion2d/__init__.py | ||
heidrifx_diffusion2d/_version.py | ||
heidrifx_diffusion2d/diffusion2d.py | ||
heidrifx_diffusion2d/output.py | ||
heidrifx_diffusion2d.egg-info/PKG-INFO | ||
heidrifx_diffusion2d.egg-info/SOURCES.txt | ||
heidrifx_diffusion2d.egg-info/dependency_links.txt | ||
heidrifx_diffusion2d.egg-info/requires.txt | ||
heidrifx_diffusion2d.egg-info/top_level.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
numpy | ||
matplotlib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
heidrifx_diffusion2d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
from . import _version | ||
__version__ = _version.get_versions()['version'] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
-
sign here causes a syntactical error. The following worked:from heidrifx_diffusion2d import diffusion2d
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, my bad. I totally forgot to change this part of the README.md.