TypeError: Division.__float__ returned non-float (type NotImplementedType)

Hello everyone,
I want to use two different energies by changing E in my geometry (created on gmsh) by creating a subdomain, but the error I mentioned below appears. I would be glad if you help. Thank you in advance.

# Subdomain
class geometry(UserExpression):  # g0 is the middle rectangular, g1 is the main geometry
    def set_E_values(self, g_0, g_1):
        self.g_0, self.g_1 = g_0, g_1

    def eval(self, value, x):
        tol = 1E-14
        if 5.4 <= x[1] <= 7.8 + tol and 0.3 < x[0] < 0.7:
            value[0] = self.g_0
        else:
            value[0] = self.g_1
        # UserExpression.eval(self)

    def value_shape(self):
        # return (1,)
        return ()

E = geometry(degree=0)
# E.interpolate(UserExpression())
E.set_E_values(0.1,10.0)

Traceback (most recent call last):
File “disp.py”, line 85, in
mu, lmbda = Constant(E / (2 * (1 + nu))), Constant(E * nu / ((1 + nu) * (1 - 2 * nu)))
File “/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/constant.py”, line 68, in init
floats = list(map(float, array.flat))
TypeError: Division.float returned non-float (type NotImplementedType)

Your error message seems unrelated to the code you’ve posted. Please consider proving a MWE as outlined here.

1 Like

Thank you Nate, here it is.
Another question is, should I create a different surface plane for my subdomains?

Your Young’s modulus, E is not constant, it’s an Expression as you’ve defined in your geometry class. So when you try to wrap it in a Constant you get the error.

You’ll get a few more errors when trying to solve your system because you need to carefully decide which forms you want to solve. I can get it to work with

# Solve variational problem
solve(dPi == 0, u, bcs, J=Jac,
      form_compiler_parameters=ffc_options)

but you’ll need to choose whatever’s right for your physical problem.

1 Like

I realized my mistake, thank you for your great help!