Explain, please. Initial condition

Hello everyone, tell me why they do not match? how to make it match?

import numpy as np
from dolfin import *
import matplotlib.pyplot as plt


u0 = Expression('-1/2*sin(3*pi*x[0]) + 3/2*sin(pi*x[0])', degree=3)

mesh = UnitIntervalMesh(20)
V = FunctionSpace(mesh, 'CG', 2)

ut = [interpolate(Constant(0.0), V) for j in range(11)]
ut[0] = interpolate(u0, V)
plot(ut[0])


def u_analytic(x):
   return np.sin(3*pi*x)*(-1/2)+ np.sin(pi*x)*3/2 #t=0.1
x = np.linspace(0, 1, 20)
plt.plot(x, u_analytic(x), color='red')

plt.show()

test

The string is C++ code, which means that you are doing integer division when calling 1/2 and 3/2
Changing this to

u0 = Expression('-1./2*sin(3*pi*x[0]) + 3./2*sin(pi*x[0])', degree=3)

solves the issue

1 Like

Thank you, everything is working now