from math import sin, cos, pi, exp class fourcenters2d(object): """Describes the four centers vector field.""" def __init__(self, Scale = 1, Al_t = 1): self.scale = Scale self.al_t = Al_t # Samples the vector field of the four centers flow def sample(self, x, y, t): u = exp(-y * y - x * x)*(self.al_t*y*exp(y*y + x * x) - 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*y*y*y + (12 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)) - 6 * self.scale)*x*y*y + (6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*x + 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t))*y + (3 * self.scale - 6 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)))*x) v = -exp(-y * y - x * x)*(self.al_t*x*exp(y*y + x * x) - 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*y*y + ((12 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)) - 6 * self.scale)*x*x - 6 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)) + 3 * self.scale)*y + 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*x*x - 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x) return u, v; # Samples the x-partial of the vector field of the four centers flow def sample_dx(self, x, y, t): u = 3 * self.scale*(4 * cos(self.al_t*t)*sin(self.al_t*t)*x*y*y*y - 8 * (cos(self.al_t*t)*cos(self.al_t*t)) * x*x * y*y + 4 * x*x * y*y + 4 * (cos(self.al_t*t)*cos(self.al_t*t)) * y*y - 2 * y*y - 4 * cos(self.al_t*t)*sin(self.al_t*t)*x*x*x * y + 4 * (cos(self.al_t*t)*cos(self.al_t*t)) * x*x - 2 * x*x - 2 * (cos(self.al_t*t)*cos(self.al_t*t)) + 1)*exp(-y * y - x * x) v = -exp(-y * y - x * x)*(self.al_t*exp(y*y + x * x) + 12 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*x * y*y - 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*y*y - 24 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)) * x*x*x * y + 12 * self.scale*x*x*x * y + 36 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)) * x*y - 18 * self.scale*x*y - 12 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*x*x*x + 30 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*x - 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)) return u, v; # Samples the y-partial of the vector field of the four centers flow def sample_dy(self, x, y, t): u = exp(-y * y - x * x)*(self.al_t*exp(y*y + x * x) + 12 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*y*y*y*y - 24 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)) * x*y*y*y + 12 * self.scale*x*y*y*y - 12 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*x * y*y - 30 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*y*y + 36 * self.scale*(cos(self.al_t*t)*cos(self.al_t*t)) * x*y - 18 * self.scale*x*y + 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)*x*x + 6 * self.scale*cos(self.al_t*t)*sin(self.al_t*t)) v = -3 * self.scale*(4 * cos(self.al_t*t)*sin(self.al_t*t)*x*y*y*y - 8 * (cos(self.al_t*t)*cos(self.al_t*t)) * x*x * y*y + 4 * x*x * y*y + 4 * (cos(self.al_t*t)*cos(self.al_t*t)) * y*y - 2 * y*y - 4 * cos(self.al_t*t)*sin(self.al_t*t)*x*x*x * y + 4 * (cos(self.al_t*t)*cos(self.al_t*t)) * x*x - 2 * x*x - 2 * (cos(self.al_t*t)*cos(self.al_t*t)) + 1)*exp(-y * y - x * x) return u, v; # Samples the t-partial of the vector field of the four centers flow def sample_dt(self, x, y, t): u = 6 * self.al_t*self.scale*((sin(self.al_t*t)*sin(self.al_t*t)) * y*y*y - (cos(self.al_t*t)*cos(self.al_t*t)) * y*y*y - 4 * cos(self.al_t*t)*sin(self.al_t*t)*x*y*y - (sin(self.al_t*t)*sin(self.al_t*t)) * x*x * y + (cos(self.al_t*t)*cos(self.al_t*t)) * x*x * y - (sin(self.al_t*t)*sin(self.al_t*t)) * y + (cos(self.al_t*t)*cos(self.al_t*t)) * y + 2 * cos(self.al_t*t)*sin(self.al_t*t)*x)*exp(-y * y - x * x) v = -6 * self.al_t*self.scale*((sin(self.al_t*t)*sin(self.al_t*t)) * x*y*y - (cos(self.al_t*t)*cos(self.al_t*t)) * x*y*y - 4 * cos(self.al_t*t)*sin(self.al_t*t)*x*x * y + 2 * cos(self.al_t*t)*sin(self.al_t*t)*y - (sin(self.al_t*t)*sin(self.al_t*t)) * x*x*x + (cos(self.al_t*t)*cos(self.al_t*t)) * x*x*x + (sin(self.al_t*t)*sin(self.al_t*t)) * x - (cos(self.al_t*t)*cos(self.al_t*t)) * x)*exp(-y * y - x * x) return u, v;