Hi,
I am trying to solve a problem with different materials, based on examples I have found so far.
The code i am using is:
from dolfin import *
import matplotlib.pyplot as plt
from ufl import nabla_div
import numpy as npLen = 10.0; W = 4.0; H=2.0;
mesh = BoxMesh(Point(0.0, 0.0, 0.0), Point(Len, W, H), 21, 8, 4)
V = VectorFunctionSpace(mesh, “Lagrange”, 1)Define boundary condition
tol = 1E-14
Mark boundary subdomians
left = CompiledSubDomain(“near(x[0], side) && on_boundary”, side = 0.0)
right = CompiledSubDomain(“near(x[0], side) && on_boundary”, side = 10.0)Material Variable
mu = 1
rho = 1
delta2 = 0.4*(W/Len)*2
delta1 = 0.4(2.0*W/Len)**2class Omega0(SubDomain):
def inside(self, x, on_boundary):
return True if x[2] <= 0.5 + tol else False
class Omega1(SubDomain):
def inside(self, x, on_boundary):
return True if x[2] >= 0.5 - tol else False
subdomains = MeshFunction(‘size_t’, mesh, mesh.topology().dim(), 0)
subdomain0 = Omega0().mark(subdomains, 0)
subdomain1 = Omega1().mark(subdomains, 1)class K(Expression):
def init(self, subdomains, k_0, k_1, **kwargs):
self.subdomains = subdomains
self.k_0 = k_0
self.k_1 = k_1def eval_cell(self, values, x, cell):
if self.subdomains[cell.index] == 0:
values[0] = self.k_0
else:
values[0] = self.k_1delta = K(subdomains, delta1, delta2, degree=0)
#gamma = 0.4*delta**2
beta = 1.25
lambda_ = beta
#g = gammac = Constant((0, 0, 0))
bcl = DirichletBC(V, c, left)
bcr = DirichletBC(V, c, right)
bcs = [bcl, bcr]Define strain and stress
def epsilon(u):
return 0.5*(nabla_grad(u) + nabla_grad(u).T)def sigma(u):
return lambda_nabla_div(u)Identity(d) + 2muepsilon(u)Define variational problem
u = TrialFunction(V)
d = u.geometric_dimension() # space dimension
v = TestFunction(V)
f = Constant((0, 0, -rho*delta))
T = Constant((0, 0, 0))
a = inner(sigma(u), epsilon(v))*dx
L = dot(f, v)*dx + dot(T, v)*dsCompute solution
u = Function(V)
solve(a == L, u, bcs)Save solution to file in VTK format
File(‘liner_def/displacement.pvd’) << u
However, I always get this Error:
Traceback (most recent call last):
File “test_def_linear2.py”, line 45, in
delta = K(subdomains, delta1, delta2, degree=0)
File “test_def_linear2.py”, line 35, in init
self.subdomains = subdomains
File “/usr/lib/python3/dist-packages/dolfin/function/expression.py”, line 438, in setattr
elif name in self._parameters:
File “/usr/lib/python3/dist-packages/dolfin/function/expression.py”, line 432, in getattr
return self._parameters[name]
File “/usr/lib/python3/dist-packages/dolfin/function/expression.py”, line 432, in getattr
return self._parameters[name]
File “/usr/lib/python3/dist-packages/dolfin/function/expression.py”, line 432, in getattr
return self._parameters[name]
[Previous line repeated 327 more times]
RecursionError: maximum recursion depth exceeded
Thanks for you help