Problem with Maximum Removal
Hi Everyone, I have here an advection-reaction problem, with two removal terms: one is constant removal (k1) and the other is limited to a maximum value so that it disappears when this value has been reached. My problem is in the implementation of the term lang which is where 1-S/Smax. C is the solution of the pde, and S of a converted compilation of the total removed C by the k2 term.
I've tried to set lang to 1 during the first time step, then allow it to be calculated in the later steps. I think there is something wrong with this as changing this initial value to 0 has a huge effect on the solution.
I've also tried to limit the S using: S.vector(
but I think this is then just changing the values greater than the max, but not limiting the value when solved, so a portion of C is removed and then changed. Then I end up with less mass in the system than has been introduced. This is also obvious when looking at the solution of C, because it goes almost immediately to 0, but this removed C isn't seen in S near the left boundary. Is there any better way to formulate this?
Thanks in advance for the help!
Here is the code:
from dolfin import *
# Create mesh and define function space
mesh = Rectangle(0, 0, 2, 1, 100, 1, "crossed")
V = FunctionSpace(mesh, "CG", 1)
# Define Dirichlet boundary (x = 0), neumann at (x=4)
def Dirichlet_
return x[0] < DOLFIN_EPS
dt = 300
T = 9000
t = dt
C1 = Constant(10)
bc1 = DirichletBC(V, C1, Dirichlet_
C0 = Constant(0)
C_prev = interpolate(C0, V)
S=Constant(0)
S_prev = interpolate(S, V)
# Define variational problem
C = TrialFunction(V)
w = TestFunction(V)
v=Constant(5e-3) #velocity
S0max = Constant(1e-2) # Maximum possible Sorption
Smax=float(S0max)
k1=Constant(5e-4)
k2=Constant(5e-2)
if t<=dt:
lang=Constant(1)
a = C*w*dx + dt*v*w*C.dx(0)*dx + k1*dt*w*C*dx+ k2*lang*dt*w*C*dx
L = C_prev*w*dx
C = Function(V)
A = assemble(a)
# Save solution in VTK format
file = File("Ssolution
while t <= T:
b = assemble(L)
bc1.apply(A,b)
solve(
t += dt
C_prev.assign(C)
S_prev.assign(S)
def langmuir():
return 1-(S_prev/Smax)
lang=project(
def S():
return S_prev+
S=project(S(), V)
file<<(S)
S.vector(
b = assemble(L, tensor=b)
plot(lang, title="Langmuir coefficient")
plot(S, title="S")
plot(C, title="C")
interactive()
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- Martin Sandve Alnæs
- Solved:
- Last query:
- Last reply: