In previous versions of FEniCS, I was able to define specific boundary conditions in the domain, like this.
import numpy as np
from dolfin import *
from mshr import *
import matplotlib.pyplot as plt
pcoorx_obs = [1800.0]
pcoory_obs = [1600.0]
hp_obs = [20.9135966045882817]
pcoorx_v = [2100.0]
pcoory_v = [2100.0]
flow = [-2000.0] # m3/s
valork = 20.0
b = 10.0
u_w = Constant(11.0)
u_e = Constant(11.0)
x0 = 0.0
y0 = 0.0
x1 = 4200.0
y1 = 4200.0
resolution = 30
rect = Rectangle(Point(x0, y0), Point(x1, y1))
mesh = generate_mesh(rect, resolution)
V = FunctionSpace(mesh, "Lagrange", 1)
def uw_boundary(x):
return x[0] < DOLFIN_EPS
def ue_boundary(x):
return near(x[0], x1, DOLFIN_EPS)
def condition_p0(x):
return near(x[0], pcoorx_obs[0], DOLFIN_EPS) and near(x[1], pcoory_obs[0], DOLFIN_EPS)
bcw = DirichletBC(V, u_w, uw_boundary)
bce = DirichletBC(V, u_e, ue_boundary)
bcp_0 = DirichletBC(V, hp_obs[0], condition_p0, method='pointwise') # This condition is not working!!!!!
bc_obs = [bcw, bce, bcp_0]
class K(UserExpression):
def __init__(self, mesh, **kwargs):
self.mesh = mesh
super().__init__(**kwargs)
def eval(self, values, x):
T = valork * b
values[0] = T
T = K(mesh, degree=1)
u_obs = TrialFunction(V)
v_obs = TestFunction(V)
a_obs = inner(T*nabla_grad(u_obs), nabla_grad(v_obs))*dx
L_obs = Constant(0.0)*v_obs*dx
A_obs = assemble(a_obs)
rhs1_obs = None
rhs_obs = assemble(L_obs, tensor=rhs1_obs)
u_obs = Function(V)
for bc in bc_obs:
bc.apply(A_obs, rhs_obs)
for i in range(len(flow)):
delta_obs = PointSource(V, Point(pcoorx_v[i], pcoory_v[i]), flow[i])
delta_obs.apply(rhs_obs)
solve(A_obs, u_obs.vector(), rhs_obs)
plt.figure()
plot(mesh)
plt.figure()
plot(u_obs, title='Head')
plt.show()
In older versions this condition worked bcp_0 = DirichletBC(V, hp_obs[0], condition_p0, method='pointwise')
. but now it has no effect.