### (Deleted) error TypeError: nb_float should return float object

295
views
-2
7 months ago by
Hello everyone:
when running appear the following error:
Traceback (most recent call last):
File "1层.py", line 90, in <module>
MMM =sqrt(pow(u[0],2)+pow(u[1],2))*dx
TypeError: nb_float should return float object

how can i solve?
Best wishes!
Community: FEniCS Project
Can you post brief details about the code that you are trying to run ? or perhaps the link to the code
written 7 months ago by Ovais
#encoding=utf-8*
from dolfin import*
import matplotlib.pyplot as plt
from math import sqrt
from math import pi
from math import pow
import cmath
from math import cos
from math import sin
from math import e

mesh=RectangleMesh(Point(0,-1000),Point(400,0),40,500)
def u0_boundary(x):
return near(x[1], 0.0)
# no multiply i
def sesq_inner(u_r, u_i, v_r, v_i):

re_part = inner(u_r, v_r) - inner(u_i, v_i)
im_part = inner(u_r, v_i) + inner(u_i, v_r)
return re_part + im_part
#multiply i
def sesq_inner1(u_r, u_i, v_r, v_i):
re_part =inner(u_r, v_i) + inner(u_i, v_r)
im_part = inner(u_r, v_r) - inner(u_i, v_i)
return im_part-re_part

class Bottom(SubDomain):
def inside(self,x,on_boundary):
return near(x[1],-1000.0,DOLFIN_EPS)
bottom=Bottom()

class Omega1(SubDomain):
def inside(self, x, on_boundary):
return x[1]>=-1000.0

subdomains = MeshFunction("size_t", mesh, 2)
# Mark subdomains with numbers 0 and 1

subdomain1 = Omega1()
subdomain1.mark(subdomains,1)

boundaries=FacetFunction("size_t",mesh,1)
bottom.mark(boundaries,2)

sigma1=1.0/100

e1=8.85*pow(10,-12)
miu=4.0*pi*pow(10,-7)
p_a=[]
w1=[]
u0=Constant((1.0,0))

ds = Measure('ds', domain=mesh, subdomain_data=boundaries)
dx = Measure('dx', domain=mesh, subdomain_data=subdomains)

w=2*pi/pow(10,2)

V= VectorFunctionSpace(mesh, 'P', 2)

u_r, u_i = TrialFunctions(V)
v_r, v_i = TestFunctions(V)

l = sigma1*sesq_inner(u_r, u_i, v_r, v_i)*dx(1)
c=(sqrt(sigma1)/sqrt(2*w*miu))*(sesq_inner1(u_r, u_i, v_r, v_i)-sesq_inner(u_r, u_i, v_r, v_i))*ds(2)

bc = DirichletBC(V,u0,u0_boundary) # Real BC

F=a-l+c
A=lhs(F)
L=rhs(F)
u = Function(V)

MMM =sqrt(pow(u[0], 2.0) + pow(u[1], 2.0))*dx
tol = 1.0e-4

problem = LinearVariationalProblem(A, L, u, bc)
solver.solve(tol)
solver.summary()
u_r,u_i=u.split(u)

interactive()
written 7 months ago by kevin
sqrt(pow(u[0],2),pow(u[1],2))*dx looks incorrect. Perhaps you meant sqrt(pow(u[0],2) + pow(u[1],2))*dx or just more Pythonic (u[0]**2 + u[1]**2)**0.5*dx.
written 7 months ago by Jan Blechta
I wrote sqrt(pow(u[0],2) + pow(u[1],2))*dx in the code and then there is such a problem, code is correct without the adaptive
written 7 months ago by kevin