How to apply flux on a curved surface?

Hi everyone,

I’ve have implemented flux boundary conditions as follows:

#Define Problem
u = TrialFunction(V)
v = TestFunction(V)

#Variables
D = Constant(1.71*pow(10,-5)) # mm^2/s
sim_time = 61 # seconds
time_steps = 122
dt = sim_time/time_steps
tol = 1E-14

#Define Boundary Conditions
k1 = Constant(0.009221) # per second
A1 = Constant(0.24) # micro-gram per mm^2
Flux = Expression('t<30+1e-9 ? k1*A1*exp(-1*k1*t) : 0', degree = 1, k1=k1, A1=A1, t=0)
u_D = Constant(0)

boundaryconditions = { 
    1 : {"Neumann" : 0},
    2 : {"Neumann" : 0},
    3 : {"Neumann" : 0},
    4 : {"Neumann" : 0},
    5 : {"Neumann" : 0},
    6 : {"Neumann" : 0},
    7 : {"Neumann" : Flux},
    8 : {"Neumann" : 0},
    9 : {"Neumann" : 0},
    10 : {"Neumann" : 0}
}

ds = Measure('ds', domain=mesh, subdomain_data=mf)

integrals_N = []
for i in boundaryconditions:
    if "Neumann" in boundaryconditions[i]:
        if boundaryconditions[i]["Neumann"] != 0: #if not zero flux
            g = boundaryconditions[i]["Neumann"]
            integrals_N.append(D*dt*v*g*ds(i))

F = u*v*dx + D*dt*dot(grad(u),grad(v))*dx -sum(integrals_N) - v*u_n*dx
a,L = lhs(F),rhs(F)

#Solving Problem
u = Function(V)
t = -1*dt

for i in range(time_steps):
    t+=dt
    Flux.t = t
    solve(a==L,u,bcs)
    vtkfile<<(u,t)
    u_n.assign(u)

The problems I’m having are:

  1. The flux does not seem to be implemented uniformly? Does this have to do with a curved surface?
  2. How do I minimize the negative values? To make it more obvious I’ve scaled the same image to exclude the negative values.

Any help will be greatly appreciated.

For anyone who made a similar mistake: The error lies in the flux function which should not include the diffusivity term. So it should be:

integrals_N.append(dt*v*g*ds(i))
1 Like

Hi, could you please explain how to apply flux boundary condition for me?Does anybody has a reference example?Thank you.

Hi, you can refer to the example above. Simply use an expression to to define your flux and subsequently use that expression in your numerical integration (see “integrals_N.append(…)” and “F = u * v * dx + … - sum(integrals_N)” ).
The only mistake I had made was multiplying the diffusivity term again when its value was already captured in my expression. Hope that helps :slight_smile:

Thank you.I will have a try.Is this flux a scalar or a vector?

Its applied normal to the surface specified by ‘ds’ in the code

OK.Thank you very much.