I want to solve the Poisson for a new function defined as newDivision, but fenics cannot integrate this solution. How could I reformulate my problem?
from fenics import *
import numpy as np
from mshr import *def newDivision(y,x):
if abs(x)<10**(-8):
z = 40000
return zelse: z= y/x return z
mesh = UnitSquareMesh(8, 8)
#mesh = UnitSquareMesh(i, i)
V = FunctionSpace(mesh, ‘Lagrange’, 1)u_D = Expression(‘newDivision(x[1]/x[0])’, degree=4)
def boundary(x, on_boundary):
return on_boundarybc = DirichletBC(V, u_D, boundary)
Define variational problem
u = TrialFunction(V)
v = TestFunction(V)
f = Expression(‘0’, degree=0)
a = dot(grad(u), grad(v))dx
L = fv*dxCompute solution
u = Function(V)
solve(a == L, u, bc)Plot solution and mesh
plot(u)
plot(mesh)Compute error in L2 norm
error= errornorm(u_D, u, ‘L2’)