コード例 #1
0
 def Error_test_Momentum(self, mu):
     t_sym = syp.symbols("t_sym")
     fakeSolnx = syp.exp(-t_sym) * self.phi[0]
     fakeSolny = syp.exp(-t_sym) * self.phi[0]
     fx = syp.lambdify([self.x, self.y, t_sym], fakeSolnx, "numpy")
     fy = syp.lambdify([self.x, self.y, t_sym], fakeSolny, "numpy")
     SourceTermx = syp.diff(fakeSolnx, t_sym) + fakeSolnx * syp.diff(
         fakeSolnx, self.x) + fakeSolny * syp.diff(
             fakeSolnx,
             self.y) - mu * (syp.diff(syp.diff(fakeSolnx, self.x), self.x) +
                             syp.diff(syp.diff(fakeSolnx, self.y), self.y))
     SourceTermy = syp.diff(fakeSolny, t_sym) + fakeSolnx * syp.diff(
         fakeSolny, self.x) + fakeSolny * syp.diff(
             fakeSolny,
             self.y) - mu * (syp.diff(syp.diff(fakeSolny, self.x), self.x) +
                             syp.diff(syp.diff(fakeSolny, self.y), self.y))
     source_x = syp.MutableDenseNDimArray(zeros((1, self.N))[0])
     source_y = syp.MutableDenseNDimArray(zeros((1, self.N))[0])
     self.a_error[0, 0] = 1.0
     self.b_error[0, 0] = 1.0
     for i in range(self.N):
         source_x[i] = integrate(SourceTermx * self.phi[i] * self.orthW,
                                 self.wx, self.x_int, self.wy, self.y_int)
         source_y[i] = integrate(SourceTermy * self.phi[i] * self.orthW,
                                 self.wx, self.x_int, self.wy, self.y_int)
     return fx, fy, syp.lambdify([t_sym], source_x), syp.lambdify([t_sym],
                                                                  source_y)
コード例 #2
0
 def AssembleNonLinearTerms(self):
     print("Assembling Non-Linear terms...")
     starttime = ti.time()
     i = 0
     w = self.w
     phi = self.phi
     dxphi = self.dxphi
     dyphi = self.dyphi
     A = syp.MutableDenseNDimArray(zeros((self.N, self.N)))
     B = syp.MutableDenseNDimArray(zeros((self.N, self.N)))
     while i < self.N:
         weight_func = w[i]
         for j in range(self.N):
             phi1 = phi[j]
             for k in range(self.N):
                 A[i, j] += self.a_sym[k] * integrate(
                     weight_func * phi1 * dxphi[k] * self.orthW, self.wx,
                     self.x_int, self.wy, self.y_int)
                 B[i, j] += self.a_sym[k] * integrate(
                     weight_func * phi1 * dyphi[k] * self.orthW, self.wx,
                     self.x_int, self.wy, self.y_int)
         i += 1
     print("Done")
     print("that took:",
           ti.time() - starttime, "s")
     return syp.lambdify([self.a_sym], A), syp.lambdify([self.a_sym], B)
コード例 #3
0
 def AssembleLinearTerms(self):
     print("Assembling Linear terms...")
     L1 = zeros((self.N, self.N))
     L2 = zeros((self.N, self.N))
     L3 = zeros((self.N, self.N))
     L4 = zeros((self.N, self.N))
     L5 = zeros((self.N, self.N))
     Lp1 = zeros((self.N, self.N))
     Lp2 = zeros((self.N, self.N))
     Lp3 = zeros((self.N, self.N))
     starttime = ti.time()
     for i in range(self.N):
         phi1 = self.w[i]
         for j in range(self.N):
             phi2 = self.phi[j]
             dxphi2 = self.dxphi[j]
             dyphi2 = self.dyphi[j]
             # x & y momentum:
             L1[i, j] = integrate(phi1 * phi2 * self.orthW, self.wx,
                                  self.x_int, self.wy, self.y_int)
             # Left side of equation   phi_i*phi_j
             L2[i, j] = integrate(phi1 * self.dxphi_p[j] * self.orthW,
                                  self.wx, self.x_int, self.wy, self.y_int)
             # Grad P   dphi_i/dx*phi_j
             L3[i,
                j] = integrate(phi1 * syp.diff(dxphi2, self.x) * self.orthW,
                               self.wx, self.x_int, self.wy, self.y_int)
             # Visc terms   d2phi_i/dx*phi_j
             L4[i,
                j] = integrate(phi1 * syp.diff(dyphi2, self.y) * self.orthW,
                               self.wx, self.x_int, self.wy, self.y_int)
             # Visc terms   d2phi_i/dy*phi_j
             L5[i, j] = integrate(phi1 * self.dyphi_p[j] * self.orthW,
                                  self.wx, self.x_int, self.wy, self.y_int)
             # Grad P   dphi_i/dy*phi_j
             # Pressure
             Lp1[i,
                 j] = integrate(self.phi_p[i] * self.phi_p[j] * self.orthW,
                                self.wx, self.x_int, self.wy, self.y_int)
             Lp2[i, j] = integrate(self.phi_p[i] * dxphi2 * self.orthW,
                                   self.wx, self.x_int, self.wy, self.y_int)
             Lp3[i, j] = integrate(self.phi_p[i] * dyphi2 * self.orthW,
                                   self.wx, self.x_int, self.wy, self.y_int)
     Pu = inv(L1).dot(L2)
     Pv = inv(L1).dot(L5)
     Al = inv(L1).dot(L3 + L4)
     Lup = inv(Lp1).dot(Lp2)
     Lvp = inv(Lp1).dot(Lp3)
     print("Done")
     print("that took:",
           ti.time() - starttime, "s")
     # Returns phi_i*phi_j, dphi_i/dx*phi_j, dphi_i/dy*phi_j
     return L1, Pu, Pv, Al, Lp1, Lup, Lvp
コード例 #4
0
 def Error_test_Pressure(self):
     t_sym = syp.symbols("t_sym")
     fakeSoln = syp.exp(-t_sym) * self.phi_p[0]
     fP = syp.lambdify([self.x, self.y, t_sym], fakeSoln, "numpy")
     SourceTerm = syp.diff(fakeSoln, t_sym)
     source = syp.MutableDenseNDimArray(zeros((1, self.N))[0])
     self.p_error[0, 0] = 1
     for i in range(self.N):
         source[i] = integrate(SourceTerm * self.phi_p[i] * self.orthW,
                               self.wx, self.x_int, self.wy, self.y_int)
     return fP, syp.lambdify([t_sym], source, "numpy")
コード例 #5
0
    def Source(self):
        t_sym = syp.symbols("t_sym")
        a = 0.0001
        SourceTermx = (syp.exp(-t_sym**2 / a**2) + syp.exp(
            -(t_sym - 0.3)**2 / a**2) + syp.exp(-(t_sym - 0.6)**2 / a**2)) * (
                2 * self.phi[0] + 6.7 * self.phi[1] - 3.5 * self.phi[2] +
                1.4 * self.phi[3])
        source_x = syp.MutableDenseNDimArray(zeros((1, self.N))[0])
        for i in range(self.N):
            source_x[i] = integrate(SourceTermx * self.phi[i] * self.orthW,
                                    self.wx, self.x_int, self.wy, self.y_int)
        return syp.lambdify([t_sym], source_x, "numpy")

    #def SourceTerm(self, t):
    #	u = self.UV(self.a[:, t], x_mesh, y_mesh);
    #	v = self.UV(self.b[:, t], x_mesh, y_mesh);
    #	b = zeros_like(u);
    #	b[1: -1, 1: -1] = (rho*(1/dt*((u[1: -1, 2:] - u[1: -1, 0: -2])/(2*dx) + (v[2:, 1: -1] - v[0: -2, 1: -1])/(2*dy)) - ((u[1: -1, 2:] - u[1: -1, 0: -2])/(2*dx))**2 -
    #						2*((u[2:, 1: -1] - u[0: -2, 1: -1])/(2*dy)*(v[1: -1, 2:] - v[1: -1, 0: -2])/(2*dx)) - ((v[2:, 1: -1] - v[0: -2, 1: -1])/(2*dy))**2));
    #	return b;

    #def Pressure_Update(p, t, iter_max = 50):
    #	iter = 1;
    #	b = self.SourceTerm(t);
    #	while iter <= iter_max:
    #		pn = p.copy();
    #		p[1: -1, 1: -1] = (((pn[1: -1, 2:] + pn[1: -1, 0: -2])*dy**2 + (pn[2:, 1: -1] + pn[0: -2, 1: -1])*dx**2)/(2*(dx**2 + dy**2)) -
    #						dx**2*dy**2/(2*(dx**2 + dy**2))*b[1: -1, 1: -1]);

    #		# Wall BC
    #		p[:, -1] = p[:, -2];				# @ x = 1
    #		p[0, :] = p[1, :];					# @ y = -1
    #		p[:, 0] = p[:, 1];					# @ x = -1
    #		p[-1, :] = p[-2, :];				# @ y = 1
    #		iter += 1
    #	return p;