Suppose I have an expression like the one of the classic Taylor Green 2D solution of the Navier-Stokes equations:
u0='-sin(pi*x[1])*cos(pi*x[0])*exp(-2.*pi*pi*nu*t)',
u1='sin(pi*x[0])*cos(pi*x[1])*exp(-2.*pi*pi*nu*t)',
p='-(cos(2*pi*x[0])+cos(2*pi*x[1]))*exp(-4.*pi*pi*nu*t)/4.0'
I would like to apply such a field as boundary condition on the boundary of a 2D circle, for example, but rotating it in time. In other words, I want to compose the field above with a rotation (with axis z of course). What is the most efficient and precise way to do this? I tried to define a custom UserExpression (suppose RM_ is the array of a certain rotation matrix 3by3), in order to rotate the coordinates and only then apply the starting Expression to the new coordinates:
RM_ = np.array([[0.70711, 0.70711, 0.0],
[-0.70711, 0.70711, 0.0],
[0.0, 0.0, 1.0]])
class RotExpression(UserExpression):
def eval(self, value, x):
xa_ = np.array([x[0], x[1], 0.])
xr_ = RM_ @ xa_ #ROTATE THE COORDINATES, MATRIX VECTOR PRODUCT
value[0] = xr_[0]
value[1] = xr_[1]
def value_shape(self):
return (2,)
cr_ = RotExpression(degree = 3)
u_ex_rot = Expression(('-(cos(pi*(cr[0]))*sin(pi*(cr[1])))*exp(-2.0*nu*pi*pi*t)',
' (cos(pi*(cr[1]))*sin(pi*(cr[0])))*exp(-2.0*nu*pi*pi*t)'),
cr=cr_, nu=nu, t=t, degree=3)
The domain here is a 2D disc with centre at the origin, so I rotate every point on the boundary by multiplying with a rotation matrix.
And then use this last u_ex_rot expression which I obtain in an usual DirichletBC on the boundary domain. The results I obtain however seem wrong and I would like to rule out that there’s something wrong that I’m doing with this implementation of the boundary conditions.