| Newbie | | Join Date: Aug 2009
Posts: 4
| |
Hello everyone,
I am new to python and i am stuck with this code.
for a fixed value of kr it was working fine but
i wan to put kr in a for loop.
but each time i get this error
For kr in range(1, 5)
^
SyntaxError: invalid syntax
i put the whole code which uses kr in the for loop of kr
but it doesn't work. -
...................................................................................................................
-
# This example computes the diffraction from a superhydrophobic optical grating
-
# immersed in water. A curved liquid-gas interface spans each groove.
-
-
-
from mrcwa import *
-
from tables import *
-
-
# dimensionless curvature of the interface
-
-
-
#Variable
-
M1=0
-
M2=0
-
M3=0
-
-
# groove width
-
g = 5.0
-
# wall width
-
w = 3.0
-
# depth
-
h = 6
-
# period
-
T = g + w
-
r = 0.5 * g
-
#Materials definition
-
air = material(1.0)
-
water = material(1.33,'blue')
-
Si = material((4.367+0.079j),'black')
-
output_file = open("SuperHydro_varying_kr","w")
-
-
For kr in range(1, 5)
-
-
R=r/kr
-
l = R * sqrt( 1 - r**2 / R**2 )
-
zeta = R * ( 1 - sqrt( 1 - r**2 / R**2 ) )
-
-
if kr < 0:
-
-
box + halfspace(-inf, 0.0, Si)
-
box + rectangle(g, h, air, (0, -0.5*h) )
-
box + circle(R, water, (.0,-l))
-
-
ymesh = hstack( ( array([0.0,r]), arange(r+h+zeta-d, h+r+d, d), array([h+g]) ) )
-
print 'good'
-
elif kr > 0:
-
-
box + circle(R, air, (.0,-l))
-
box + halfspace(-inf, 0.0, Si)
-
box + rectangle(g, h, air, (0, -0.5*h) )
-
-
ymesh = hstack( ( array([0.0,r]), arange(r+h-d, h+g+d, d) ) )
-
-
xmesh = hstack( (arange(0,g+0.01,0.001), array([T]) ) )
-
grating=stack( box.slice(xmesh=xmesh, ymesh=ymesh) )
-
print 'bad'
-
M1=0
-
M2=0
-
M3=0
-
M =-50
-
P = 50
-
-
grating.order=(M,P+1)
-
-
grating.l = 0.488
-
-
grating.fourier()
-
-
angles = arange(30,87,1)
-
orders = arange(M,P+1)
-
-
-
for i,theta in enumerate(angles):
-
grating.theta = theta
-
grating.wavevec()
-
grating.partialr()
-
L=grating.partialr()[49]*grating.partialr()[49]
-
Q=grating.partialr()[50]*grating.partialr()[50]
-
S=grating.partialr()[51]*grating.partialr()[51]
-
M1+=L
-
M2+=Q
-
M3+=S
-
output_file.write(" %s %s %s %s \n" % (kr, M1, M2, M3) )
-
output_file.close()
.................................................. .................................................. ...............
|