This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

variable boundary conditions

0 votes

hi, all:
I want to solve this problem, as follows
loop:
1, \laplace(p) = f,
with a variable boundary conditions.
on the boudary, p = m - n; where m and n can be solve or given by other methods.
2, update m
3, update n
end loop
can anyone tells me how to define the variable boundary conditions, and how to implement this idea ?

By the way, I have one way to implement the idea, by point to point constrain.

#
### ############## some code

u1 = Constant(0.0)
u2 = Constant(0.25)
u3 = Constant(0.5)
u4 = Constant(0.75)
u5 = Constant(1.0)
bc_point1 = DirichletBC(V,u1,point1,"pointwise")
bc_point2 = DirichletBC(V,u2,point2,"pointwise")
bc_point3 = DirichletBC(V,u3,point3,"pointwise")
bc_point4 = DirichletBC(V,u4,point4,"pointwise")
bc_point5 = DirichletBC(V,u5,point5,"pointwise")
bc_point = [bc_point1,bc_point2,bc_point3,bc_point4,bc_point5]

#

however, I do not know how to define lots of boundary points automatically.
Could you help me, or give some comments ?

asked Mar 27, 2017 by Hamilton FEniCS Novice (500 points)

Defining a list or a tuple does not work

1 Answer

0 votes

Depending on what you want to do, you could add the fields m,n to an expression that is evaluated at the boundary, for example

        class boundary_source(Expression):
        def __init__(self,element, m, n ):
            self.element = element
            self.m = m
            self.n = n
        def eval(self, value, x):
            value[0] = f(m,n)

where f is the expression you want. This way, in each iteration or step you are doing, you wouldn't even have to change the boundary condition due to how things are referenced in python. It would only take some updates like

    boundary.m, boundary.n = new_m, new_n

Hope it works.

answered Mar 30, 2017 by nabarnaf FEniCS User (2,940 points)

Thanks a lot!

No worries. In the email noticing about your response there was something else. Was it really helpful? If not don't, worry and ask freely. If it worked, please mark the answer to close the thread :) .

Regards

Thanks for your comments.
I find a way to define the points boundary conditions.
list_bc = list_bc + [DirichletBC(V,u_bc_new[i],Pinpoint([x_coor[i],y_coor[i]]),"pointwise")]

...