-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Error in equation for calculating u in linear convection #38
Comments
Hallo, you always should give a precise context ;-) |
Hi @Anirudh257 I suspect you are using Python 2, which has a different behavior than Python 3 when it comes to division. |
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> nx = 41
>>> dx = 2 / (nx - 1)
>>> dx
0.05
>>> u = numpy.ones(nx)
>>> u[int(0.5 / dx): int(1 / dx + 1)] = 2
>>> u
array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 2., 2., 2.,
2., 2., 2., 2., 2., 2., 2., 2., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1.]) |
Do not know to which 'convection' one is referring!
BUT the Python 2 - 3 problem is solved by enclosing the division by int( ..
) as is done!
2018-01-03 16:53 GMT+01:00 Olivier Mesnard <notifications@github.com>:
… Hi @Anirudh257 <https://github.com/anirudh257>
I suspect you are using Python 2, which has a different behavior than
Python 3 when it comes to division.
When using Python 2, the problem comes from the cell above the one you
mention where we compute the grid cell width dx.
With Python 2, division between two integers returns an integer and thus dx
= 2 / (nx - 1) will return 0.
With Python 3, it will return a float, i.e. 0.05.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#38 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA_t9w8NBiBdKzr5_2Ari6TS2zSzHpTJks5tG6JtgaJpZM4RRa5J>
.
|
Python 2.7.12 (default, Nov 20 2017, 18:23:56)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> nx = 41
>>> dx = 2 / (nx - 1)
>>> dx
0
>>> u = numpy.ones(nx)
>>> u[int(0.5 / dx): int(1 / dx + 1)] = 2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ZeroDivisionError: float division by zero |
with Python 2 you need e.g. use this dx = 2.0/(nx-1) to force a decimal ;- |
We explicitly do not support Python 2
…On Jan 3, 2018 11:16 AM, "PKHG" ***@***.***> wrote:
with Python 2 you need e.g. use this dx = 2.0/(nx-1) to force a decimal ;-
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#38 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADbix6TrqFee35ldbI-2P1sV_YQwzVfdks5tG6f1gaJpZM4RRa5J>
.
|
Sorry, @mesnardo I am a beginner on Github and this will never repeat again. The issue will be resolved on importing the future division method from Python 3. It has been pointed out above. I am closing this issue. |
In linear convection's equation:
`u = numpy.ones(nx)
u[int(.5/dx):int(1 / dx + 1)] = 2`
Line 2 will give a zero error.
The text was updated successfully, but these errors were encountered: