Hi!
I'm currently trying to establish a model to determine the behavior of a hanging cable tied to both ends (with application in structural engineering), and I'd like to modify locally the characteristics of the cable (corresponding to an instrumentation added on the cable).
I'm trying to do this thanks to the tutorial Handling Domains with Different Materials but I'm having a hard time understanding how subdomains have to be implemented in that case... In order to understand that, I'm trying to solve a (very) simplified problem where the solution I want to have in the end is a piecewise linear function equal to x on [0,0.3]U[0.5,1] and 3*x on [0.3,0.5] (for example).
Here is my code:
First, create mesh and subdomain:
from dolfin import *
import sys, math, numpy
mesh = UnitIntervalMesh(100)
subdomains = FacetFunction('size_t', mesh, 1) #MeshFunction should be used?
class domain_1(SubDomain):
def inside(self, x, on_boundary):
return True if 0.3 <= x[0] <= 0.5 else False
subdomains.set_all(0)
subdomain1 = domain_1()
subdomain1.mark(subdomains, 1)
At this time, plot(subdomains) returns the mesh with the two domains without problem, then:
dx=Measure('dx')[subdomains]
ds=Measure('ds')[subdomains]
V=FunctionSpace(mesh,"DG",1)
u=TrialFunction(V)
v=TestFunction(V)
f1=Expression('x[0]',cell=interval)
f2=Expression('3*x[0]',cell=interval)
s=Function(V)
n=FacetNormal(mesh)
a=dot(grad(u),grad(v))*dx(0)+dot(grad(u),grad(v))*dx(1)
L=dot(inner(grad(f1),n),v)*ds(0)+dot(inner(grad(f2),n),v)*ds(1)
tol = 1E-16
def left_boundary(x, on_boundary):
return on_boundary and abs(x[0]) < tol
def right_boundary(x, on_boundary):
return on_boundary and abs(x[0]-1) < tol
Gamma_0_delr0 = DirichletBC(V, Constant(0.0), left_boundary)
Gamma_1_delr0 = DirichletBC(V, Constant(2.6), right_boundary)
bcs_delr0 = [Gamma_0_delr0, Gamma_1_delr0] #don't know how to impose the correct BCs...
solve(a==L,s,bcs_delr0)
plot(s)
This code returns an empty plot window ("nan" on y axis); which I believe is due to a bad implementation of boundary conditions... I tried to give it the solution at both ends of the mesh, but I believe that there is a lack of information on the boundaries of the subdomain 1, and maybe problems linked to the discontinuity of the function in 0.3 and 0.5...
I know this problem may be very basic, and I may lack of some mathematical background, so any help concerning subdomains and BCs would be much appreciated!
Regards.