Coder Social home page Coder Social logo

Comments (3)

mesnardo avatar mesnardo commented on May 22, 2024

Thank you for opening this issue @fidle.
Correct me if I am wrong, but I think you are referring to In [5] and In [6] in Lesson 06 (06_Array_Operations_with_NumPy.ipynb).
If so, the parenthesis in In [6] are indeed misplaced.

Here is a small example that reflects this issue:

> python
Python 3.6.8 |Anaconda custom (64-bit)| (default, Dec 29 2018, 19:04:46)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> numpy.__version__
'1.15.4'
>>> c = 1.0
>>> dx = 2 / 80
>>> dy = 2 / 80
>>> sigma = 0.2
>>> dt = sigma * dx
>>> un = numpy.random.rand(80, 80)
>>> u1 = un[1:, 1:] - ((c * dt / dx * (un[1:, 1:] - un[1:, 0:-1])) - (c * dt / dy * (un[1:, 1:] - un[0:-1, 1:])))
>>> u2 = (un[1:, 1:] - (c * dt / dx * (un[1:, 1:] - un[1:, 0:-1])) - (c * dt / dy * (un[1:, 1:] - un[0:-1, 1:])))
>>> numpy.allclose(u1, u2)
False
>>>

Since you found the bug @fidle, would you like to provide a patch in a pull-request?

from cfdpython.

fidle avatar fidle commented on May 22, 2024

sorry to reply you so late. @mesnardo
you are right , the parenthesis in In[6] is misplace. I am sorry I did make it clear in the issue.
I hope I could make a pull-request. but I don't know how(I am a fresh man in github).
I rewrite this part to make the code output a result, so people can see that both method can get the same result.
here is the code
`import numpy
from matplotlib import pyplot

nx = 81
ny = 81
dx = 2/(nx-1)
dy = 2/(ny-1)
c = 1
nt = 100
sigma =0.2
dt = sigma*dx

x = numpy.linspace(0,2,nx)
y = numpy.linspace(0,2,ny)
%%timeit
u = numpy.ones((ny, nx))
u[int(.5 / dy): int(1 / dy + 1), int(.5 / dx):int(1 / dx + 1)] = 2

for n in range(nt + 1): ##loop across number of time steps
un = u.copy()
row, col = u.shape
for j in range(1, row):
for i in range(1, col):
u[j, i] = (un[j, i] - (c * dt / dx *
(un[j, i] - un[j, i - 1])) -
(c * dt / dy *
(un[j, i] - un[j - 1, i])))
u[0, :] = 1
u[-1, :] = 1
u[:, 0] = 1
u[:, -1] = 1
pyplot.pcolormesh(u)`

`%%timeit
u = numpy.ones((ny, nx))
u[int(.5 / dy): int(1 / dy + 1), int(.5 / dx):int(1 / dx + 1)] = 2

for n in range(nt + 1): ##loop across number of time steps
un = u.copy()
u[1:, 1:] = un[1:, 1:] - (c * dt / dx * (un[1:, 1:] - un[1:, 0:-1]))-(c * dt / dy * (un[1:, 1:] - un[0:-1, 1:]))
u[0, :] = 1
u[-1, :] = 1
u[:, 0] = 1
u[:, -1] = 1
pyplot.pcolormesh(u)`

from cfdpython.

mesnardo avatar mesnardo commented on May 22, 2024

Thank you @fidle.
I opened a pull-request to correct the parenthesis.
Here are the steps I did to submit a pull-request:

  • I forked the repository barbagroup/CFDPython to my GitHub account.
  • On my local machine, I cloned the forked repository mesnardo/CFDPython.
  • I created a new branch called misplaced-parenthesis from the master branch.
  • I corrected the Notebook (based on your report) and re-ran the entire Notebook.
  • I committed and pushed to mesnardo/CFDPython to the branch misplaced-parenthesis.
  • On GitHub, I created a pull-request to request a merge from my branch misplaced-parenthesis to the master branch of barbagroup/CFDPython (see PR #61).
  • I am now waiting for one of the maintainers to review and approve my pull-request and to finalize the merge.

(@fidle, I gave you credit in the commit message 3c692c4.)

from cfdpython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.