We would like to solve the 1D advection-diffusion equation with a constant source as a precursor to solving the advection-diffusion equation for temperature in a molten salt reactor with a heat source that is a function of the neutron fission distribution. Possible boundary conditions for the temperature might be a Dirichlet condition at the inlet with a zero Neumann condition at the outlet, e.g. all heat flux at the outlet is do to advection. I'll have to check and see if that's consistent with the Cammi paper.
In [1]:
x, _K1, _K2 = var('x _K1 _K2')
y = function('y')(x)
de = -diff(y,x,2) + diff(y,x) == 1
desolve(de, y, [0, 0, 1, 1])
Out[1]:
In [ ]:
desolve(de, y, [0, 1, 1, 2])
In [2]:
f = desolve(de, y)
print(f)
In [ ]:
type(f)
In [ ]:
f(10)
In [ ]:
f(x=10)
In [3]:
fprime = diff(f,x)
print(fprime)
solve(fprime == 0, _K1)
sol = solve([fprime(x=1) == 0], _K1)
g = f.subs(sol[0])
print(g)
sol2 = solve([g(x=0) == 0], _K2)
h = g.subs(sol2[0])
print(h)
print(h.simplify())
print(h.expand())
In [23]:
sol = solve([fprime(x=1) == 0], _K1)
g = f.subs(sol[0])
print(g)
sol2 = solve([g(x=0) == 0], _K2)
h = g.subs(sol2[0])
print(h)
print(h.simplify())
print(h.expand())
In [15]:
hprime = h.diff(x)
hpp = hprime.diff(x)
print(hprime)
print(hpp)
In [17]:
-hpp + hprime - 1
Out[17]:
In [18]:
print(h(x=0).simplify())
print(h(x=0).expand())
In [21]:
print(h(x=1))
print(h(x=1).expand())
print(h(x=1).n())
In [8]:
p = plot(h, (0, 1))
In [9]:
show(p)
In [2]:
x, _K1, _K2 = var('x _K1 _K2')
y = function('y')(x)
de = -diff((1 + x) * diff(y, x), x) + diff(y,x) == 1
f = desolve(de, y)
print(f)
In [7]:
fprime = diff(f,x)
sol = solve([fprime(x=1) == 0], _K2)
g = f.subs(sol[0])
sol2 = solve([g(x=0) == 0], _K1)
h = g.subs(sol2[0])
print(h.simplify())
print(h.expand())
hp = diff(h, x)
hpp = diff(hp, x)
print(hp)
print(hpp)
print(h(x=0))
print(hp(x=1))
print(-diff((1 + x) * diff(h, x), x) + diff(h,x) - 1)
print(h(x=1).n())
In [6]:
p = plot(h, (0, 1))
show(p)
In [27]:
sol = solve([fprime(x=1) == 0], _K1)
g = f.subs(sol[0])
print(g)
In [29]:
gprime = g.diff(x)
print(gprime)
print(gprime(x=1))
As indicated by the cell above and below, it is literally impossible to impose a Neumann condition at both inlet and outlet for the advection-diffusion problem because one condition specifies K1, but K2 vanishes after differentiation so it cannot be specified by imposing a Neumann condition. So Riveria must have been smoking some crack when she wrote those two conditions down.
In [25]:
sol2 = solve([gprime(x=0) == 0], _K2)
h = g.subs(sol2[0])
print(h)
print(h.simplify())
print(h.expand())
In [8]:
x, _K1, _K2 = var('x _K1 _K2')
y = function('y')(x)
de = -diff(y,x,2) + diff(y,x) == 0
f = desolve(de, y)
print(f)
In [10]:
fprime = diff(f, x)
print(fprime)
sol = solve(-fprime(x=1) == f(x=1), _K1)
g = f.subs(sol[0])
print(g)
In [16]:
gp = diff(g, x)
sol = solve(gp(x=0) - g(x=0) == -2, _K2)
h = g.subs(sol[0])
print(h)
print(h(x=0).n())
print(h(x=1).n())
In [15]:
p = plot(h, (0,1))
show(p)
In [17]:
x, _K1, _K2 = var('x _K1 _K2')
y = function('y')(x)
de = -diff(y,x,2) + diff(y,x) == 0
f = desolve(de, y)
print(f)
In [18]:
fprime = diff(f, x)
print(fprime)
sol = solve(-fprime(x=1) == f(x=1), _K1)
g = f.subs(sol[0])
print(g)
In [19]:
gp = diff(g, x)
sol = solve(g(x=0) == 1, _K2)
h = g.subs(sol[0])
print(h)
print(h(x=0).n())
print(h(x=1).n())
In [20]:
p = plot(h, (0,1))
show(p)
In [21]:
x, _K1, _K2 = var('x _K1 _K2')
y = function('y')(x)
de = -diff(y,x,2) + 100 * diff(y,x) == 0
f = desolve(de, y)
print(f)
In [22]:
fprime = diff(f, x)
print(fprime)
sol = solve(-fprime(x=1) == f(x=1), _K1)
g = f.subs(sol[0])
print(g)
In [23]:
gp = diff(g, x)
sol = solve(g(x=0) == 1, _K2)
h = g.subs(sol[0])
print(h)
print(h(x=0).n())
print(h(x=1).n())
In [24]:
p = plot(h, (0,1))
show(p)
In order to reproduce the analytical solution using Moltres, it is essential to add the InflowBC boundary condition on the inlet boundary for cases where advection is dominant. Here is the Moltres solution without the InflowBC:
and here is the Moltres solution with the InflowBC:
This undershoot behavior in the former case is what I was observing in my temperature simulations. Glad we are getting an understanding now!
In [ ]:
fprime(x=1)
In [ ]:
expr = (fprime(x=1) - 1) / e
print(expr)
In [ ]:
type(expr)
In [ ]:
type(x)
In [ ]:
x = var('x')
type(x)
In [ ]:
_K1, K1 = var('_K1 K1')
In [ ]:
solve(expr, _K1)
In [ ]: