Comments (8)
with Python 2 you need e.g. use this dx = 2.0/(nx-1) to force a decimal ;-
Not needed with Python 3 (if not changed the division elsewhere)
from cfdpython.
Hallo, you always should give a precise context ;-)
[code]
import numpy
nx = 14
u = numpy.ones(nx)
dx =0.2
u[int(.5/dx):int(1 / dx + 1)] = 2
u
[/code]
gives: array([ 1., 1., 2., 2., 2., 2., 1., 1., 1., 1., 1., 1., 1., 1.])
from cfdpython.
Hi @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
.
from cfdpython.
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.])
from cfdpython.
from cfdpython.
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
from cfdpython.
from cfdpython.
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.
from cfdpython.
Related Issues (20)
- Statement of need could be more clear about the target audience
- Pressure is -ve in 11th step
- 11 step, d(div(U))/dt term HOT 2
- Typo in Step 11 HOT 1
- Typo in the Poisson equation discretization in Step 11 HOT 2
- No pressure gradient in step 12? HOT 2
- Maybe there is a bug in code of Array Operations with NumPy HOT 3
- About equation 4 in step11 HOT 4
- Step 8 transpose equations typo
- definition of L1 norm on Step 9: 2D Laplace Equation HOT 2
- CD Derivation - Step 3
- Initialization error in Step 7 HOT 1
- cfdpython HOT 1
- Disappearing viscosity term in the discrete version of Poisson-pressure equation HOT 10
- Initialization error in Step 9 HOT 1
- Step 5: matplotlib error HOT 3
- Outdated dependencies HOT 1
- Lesson 14 build_up_b
- CFD Code Writing HOT 2
- Step #4 Initial Conditions HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cfdpython.