Problem with subdomain having different material

I have tried to solve a poissons equation on subdomain with different materials.
but encountered error.

: runfile(’/home/akshay/My file/Q6.py’, wdir=’/home/akshay/My file’)
File “/home/akshay/My file/Q6.py”, line 48
kappa = K(facets=facets,k1,k2,degree=0)
^
SyntaxError: positional argument follows keyword argument

runfile(’/home/akshay/My file/Q6.py’, wdir=’/home/akshay/My file’)
WARNING: user expression has not supplied value_shape method or an element. Assuming scalar element.
Notation dx[meshfunction] is deprecated. Please use dx(subdomain_data=meshfunction) instead.
Traceback (most recent call last):

File “”, line 1, in
runfile(’/home/akshay/My file/Q6.py’, wdir=’/home/akshay/My file’)

File “/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py”, line 705, in runfile
execfile(filename, namespace)

File “/usr/lib/python3/dist-packages/spyder/utils/site/sitecustomize.py”, line 102, in execfile
exec(compile(f.read(), filename, ‘exec’), namespace)

File “/home/akshay/My file/Q6.py”, line 66, in
bcs = [DirichletBC(V,Constant(140),edges,1),

File “/usr/lib/python3/dist-packages/dolfin/fem/dirichletbc.py”, line 131, in init
super().init(*args)

RuntimeError:

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at


*** fenics-support@googlegroups.com


*** Remember to include the error message listed below and, if possible,
*** include a minimal running example to reproduce the error.


*** -------------------------------------------------------------------------
*** Error: Unable to create Dirichlet boundary condition.
*** Reason: Expecting a vector-valued boundary value but given function is scalar.
*** Where: This error was encountered inside DirichletBC.cpp.
*** Process: 0


*** DOLFIN version: 2019.1.0
*** Git changeset: unknown
*** -------------------------------------------------------------------------

please review the code

importing the necessary libraries from fenics

from future import print_function
from dolfin import *
from mshr import *
import matplotlib.pyplot as plt
import numpy as np

parameters[“form_compiler”][“cpp_optimize”] = True
parameters[“form_compiler”][“optimize”] = True

N = 50
k1 = 2
k2 = 0.9
domain = Rectangle(Point(0,0),Point(0.6,0.6)) - Rectangle(Point(0.2,0.2),Point(0.4,0.4))
mesh = generate_mesh(domain,N)
plot(mesh)

class Omega1(SubDomain):
def inside(self,x,on_boundary):
return (-x[0]+0.1) <= DOLFIN_EPS and (x[0]-0.5) <= DOLFIN_EPS and (-x[1]+0.1) <= DOLFIN_EPS and (x[1]-0.5) <= DOLFIN_EPS

class Omega2(SubDomain):
def inside(self,x,on_boundary):
return (x[0]-0.1) <= DOLFIN_EPS and (-x[0]+0.5) <= DOLFIN_EPS and (x[1]-0.1) <= DOLFIN_EPS and (-x[1]+0.5) <= DOLFIN_EPS

facets = MeshFunction(“size_t”,mesh,2)

subdomain_1 = Omega1()
subdomain_2 = Omega2()

subdomain_1.mark(facets,1)
subdomain_2.mark(facets,2)

class K(UserExpression):
def init(self,facets,k1,k2,**kwargs):
super().init(**kwargs)
self.facets = facets
self.k1 = k1
self.k2 = k2

def eval_cell(self,values,x,cell):
    if self.facets[cell.index] == 1:
        self.values[0] = self.k1
    else:
        self.values[0] = self.k2

kappa = K(facets=facets,k1=k1,k2=k2,degree=0)

class inside_boundary(SubDomain):
def inside(self,x,on_boundary):
return (near(x[0],0.2) or near(x[0],0.4) or near(x[1],0.2) or near(x[1],0.4)) and on_boundary

class outside_boundary(SubDomain):
def inside(self,x,on_boundary):
return (near(x[0],0) or near(x[0],0.6) or near(x[1],0) or near(x[1],0.6)) and on_boundary

edges = MeshFunction(“size_t”,mesh,1)

edges.set_all(0)
inside_boundary().mark(edges,1)
outside_boundary().mark(edges,2)

ds = Measure(“ds”)[edges]

bcs = [DirichletBC(V,Constant(140),edges,1),
DirichletBC(V,Constant(10),edges,2)]

“”“Variational form”""
V =FunctionSpace(mesh,“CG”,2)

dT = TrialFunction(V)
v = TestFunction(V)
s = Constant(0)

a = inner(grad(v),-kappagrad(dT))dx
L = s
v
dx

T = Function(V,name=“Temperature Field”)

solve(a==L,T,bcs)

plot(T)

Please format your code appropriately using ```, and make sure the code is executable.

There was some structural issue and syntax issue in code. solved.
Thanks…!!!

hi, I have a queryin defining variational form of poisson eq in cylindrical coordinate 1/r{d/dr{r*du/dr}} + d2u/dz2 = 0
with BC.
I tried but getting problem in defining it,
F = inner(grad(u), grad(v))*dx[0]*x[0] + inner(grad(u), grad(v))*dx[1]x[0] + (uv)*dx
can you help to define it and suggest some example over cylindrical coordinate?
thanks.

This seems rather off-topic for this post, and should either be posted in a relevant thread or a new post.