# Incompatible constructor arguments for inner product

Hello community,

I’m working on elastic deformation of rotational symmetric cases. Therefore somebody gave me an example which I try to adapt.

The code of this example is:

``````from __future__ import print_function
from dolfin import *
from mshr import *
import matplotlib.pyplot as plt
#get_ipython().run_line_magic('matplotlib', 'notebook')

Re = 11.
Ri = 9.
rect = Rectangle(Point(0., 0.), Point(Re, Re))
domain = Circle(Point(0., 0.), Re, 100) - Circle(Point(0., 0.), Ri, 100)
domain = domain - Rectangle(Point(0., -Re), Point(-Re, Re))                 - Rectangle(Point(0., 0.), Point(Re, -Re))

mesh = generate_mesh(domain, 40)
plot(mesh)

class Bottom(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0) and on_boundary
class Left(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], 0) and on_boundary
class Outer(SubDomain):
def inside(self, x, on_boundary):
return near(sqrt(x[0]**2+x[1]**2), Re, 1e-1) and on_boundary

facets = MeshFunction("size_t", mesh, 1)
facets.set_all(0)
Bottom().mark(facets, 1)
Left().mark(facets, 2)
Outer().mark(facets, 3)
ds = Measure("ds", subdomain_data=facets)

x = SpatialCoordinate(mesh)

def eps(v):
return sym(as_tensor([[v[0].dx(0), 0, v[0].dx(1)],
[0, v[0]/x[0], 0],
[v[1].dx(0), 0, v[1].dx(1)]]))

E = Constant(1e5)
nu = Constant(0.3)
mu = E/2/(1+nu)
lmbda = E*nu/(1+nu)/(1-2*nu)
def sigma(v):
return lmbda*tr(eps(v))*Identity(3) + 2.0*mu*eps(v)

n = FacetNormal(mesh)
p = Constant(10.)

V = VectorFunctionSpace(mesh, 'CG', degree=1)
du = TrialFunction(V)
u_ = TestFunction(V)
a = inner(sigma(du), eps(u_))*x[0]*dx
``````

At first I tried to change the geometry and run the script until that point is reached.

``````from __future__ import print_function
from dolfin import *
from mshr import *
import matplotlib.pyplot as plt
#get_ipython().run_line_magic('matplotlib', 'notebook')
Ra=11
Ri=9
lz=2
#-----------------------------------------------------------------------------2D-domain and mesh
domain= Rectangle(Point(Ri, 0), Point(Ra, lz))
mesh = generate_mesh(domain, 10)

#-----------------------------------------------------------------------------2D-Boundarydefinition
class house(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], Ra, 1e-1) and on_boundary
class rod(SubDomain):
def inside(self, x, on_boundary):
return near(x[0], Ri, 1e-1) and on_boundary
class outer(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], lz, 1e-1) and on_boundary
class inner(SubDomain):
def inside(self, x, on_boundary):
return near(x[1], 0, 1e-1) and on_boundary

facets = MeshFunction("size_t", mesh, 1)
facets.set_all(0)
inner().mark(facets, 1)
house().mark(facets, 2)
outer().mark(facets, 3)
rod().mark(facets, 4)
ds = Measure("ds", subdomain_data=facets)

x = SpatialCoordinate(mesh)
def eps(v):
return sym(as_tensor([[v[0].dx(0), 0, 0.5*(v[1].dx(0)+v[0].dx(1))],
[0, v[0]/x[0], 0],
[0.5*(v[1].dx(0)+v[0].dx(1)), 0, v[1].dx(1)]]))

E = Constant(1e5)
nu = Constant(0.3)
mu = E/2/(1+nu)
lmbda = E * nu/(1+nu)/(1-2 * nu)
def sigma(v):
return lmbda * tr(eps(v)) * Identity(3) + 2.0 * mu * eps(v)

n = FacetNormal(mesh)
p = Constant(10.)

V = VectorFunctionSpace(mesh, 'CG', degree=1)
du = TrialFunction(V)
u_ = TestFunction(V)
a = inner(sigma(du), eps(u_))*x[0]*dx
``````

Now, I get the error, that eps and sigma are not compatible for the inner product. And exactly, by printing both, there is a clear difference between them. But I don’t get why. Sigma is computed from eps in exactly the same way in both codes? Or not?

Thank you very much for any help.

Florian

Please reformat the code such that indentation is preserved.

This should be the case if you encapsulate your code with 3x` after copy pasting it from a text editor

what do you mean with that? “3x`” and “```” both do not work.

3x` as in ``` should render code as follows:

``````def test(x):
return x[0]
``````
1 Like

like that?

This is because you have overloaded the function inner with this class. Change the name of this class.

2 Likes