Dear everyone,
I tried to solve the advection equation
$$ u_t - c u_x = 0, \quad x \in[x_l, x_r] $$
with initial condition
$$ u0 = 0.5(u_l - u_r) \tanh(100(0.5 - x)) + u_r $$
with the method of characteristic.
I don't know how will you implement this method using FENICS. My approach is to define a function below
class CharacteristicMethod(Expression):
def eval(self, values, x):
if ((x+ c*dt) > x_r):
tmp = ur
else:
tmp = u(x+c*dt)
values[0] = tmp
def value_shape(self):
return (1,)
then in every time step I use the interpolate method of the FEMfunction
u_init = InitialConditions(degree=1)
u.interpolate(u_init)
dt = 0.1
t = 0
Tend = 1
while (t < Tend):
t += dt
u_characteristic = CharacteristicMethod(degree=1)
u.interpolate(u_characteristic)
# I need to do some other things with u in every time step ...
However this approach is not very efficient. How will you implement the method of characteristic for the linear advection equation?
Thank you in advance!
Jesse