I want to assemble the bilinear form res
and linear formL
with the boundaries composed of 5 parts. The definition of the constant functions used in res
and L
are
f=fem.Constant(domain,PETSc.ScalarType(1))
a=fem.Constant(domain,np.array([1,1],dtype=PETSc.ScalarType))
kappa=fem.Constant(domain,PETSc.ScalarType(1e-3))
boundary_zero=fem.Constant(domain,PETSc.ScalarType(0))
boundary_one=fem.Constant(domain,PETSc.ScalarType(1))
and the definition of res
and L
are
res_Galerkin=dot(a,grad(u))*v*dx+kappa*dot(grad(u),grad(v))*dx+(-div(grad(u))*kappa+dot(a,grad(u))-f)*dot(coeff*a,grad(v))*h*dx
res_boundary=-dot(a,n)*u*v*ds(1)-dot(a,n)*u*v*ds(2)-dot(a,n)*u*v*ds(3)-kappa*dot(grad(u),n)*v*ds(1)-kappa*dot(grad(u),n)*v*ds(2)-kappa*dot(grad(u),n)*v*ds(3)-kappa*dot(grad(u),n)*v*ds(4)-kappa*dot(grad(u),n)*v*ds(5)+u*dot(kappa*grad(v),n)*ds(1)+u*dot(kappa*grad(v),n)*ds(2)+u*dot(kappa*grad(v),n)*ds(3)+u*dot(kappa*grad(v),n)*ds(4)+u*dot(kappa*grad(v),n)*ds(5)+beta/h*u*kappa*v*ds(1)+beta/h*u*kappa*v*ds(2)+beta/h*u*kappa*v*ds(3)+beta/h*u*kappa*v*ds(4)+beta/h*u*kappa*v*ds(5)
res=res_Galerkin+res_boundary
L=(f*v*dx+f*dot(coeff*a,grad(v))*h*dx
-dot(a,n)*boundary_one*v*ds(1)
+boundary_one*dot(kappa*grad(v),n)*ds(1)+beta/h*boundary_one*kappa*v*ds(1))
where n is the facet normal.
I put the res and L into LinearProblem()
and try to solve this problem and I catch the following error
ArityMismatch: Adding expressions with non-matching form arguments ('v_1',) vs ().
But when I try to use res1=lhs(res+L)
and L1=rhs(res+L)
and solve the problem, it is right.
So I want to know where is wrong with my original assembling? Thanks in advance!
The boundaries are defined as
boundaries=[(1,lambda x:np.logical_and(np.isclose(x[0],0),np.logical_and(x[1]>0.3-1e-10,x[1]<=1))),
(2,lambda x:np.logical_and(np.isclose(x[0],0),np.logical_and(x[1]<0.3+1e-10,x[1]>=0))),
(3,lambda x:np.isclose(x[1],0)),
(4,lambda x:np.isclose(x[0],1)),
(5,lambda x:np.isclose(x[1],1))]
facet_indices,facet_markers=[],[]
fdim=domain.topology.dim-1
for (marker,locator) in boundaries:
facets=mesh.locate_entities(domain,fdim,locator)
facet_indices.append(facets)
facet_markers.append(np.full_like(facets,marker))
facets_indices=np.hstack(facet_indices).astype(np.int32)
facets_markers=np.hstack(facet_markers).astype(np.int32)
sorted_facets=np.argsort(facets_indices)
facet_tag=mesh.meshtags(domain,fdim,facets_indices[sorted_facets],facets_markers[sorted_facets])