def __init__(self, linedg): self.__linedg = linedg self.__params = linedg.params self.__lim = self.__params.LimitSolution() self.__nnodes = self.__params.nnodes() self.__nquads = self.__params.nquads() self.__nels = self.__params.nels() self.__neqs = self.__params.neqs() self.__dx = linedg.mesh.dx() self.ip = Interpolation.Interpolation(self.__nnodes, self.__nquads)
def __init__(self, domain, numOfEls, numOfNodes, numOfQuads): self.__xmin = domain[0] self.__xmax = domain[1] self.__K = numOfEls self.__nN = numOfNodes self.__nQ = numOfQuads self.__ip = ip.Interpolation(self.__nN, self.__nQ) self.__dx = (self.__xmax - self.__xmin) / self.__K self.__J = self.__dx self.__detJ = np.abs(self.__J) self.__invJ = 1 / self.__J
def Shock(params, x): ip = Interpolation.Interpolation(params.nnodes(), params.nquads()) uinit = np.zeros([params.nels(), params.nnodes(), params.neqs()]) for i in range(params.nels()): #compute center of cell xc = np.sum(np.matmul(ip.W(), np.matmul(ip.B(), x[i, :]))) # print(xc) if (xc < params.ShockLoc()): uinit[i, :, :] = params.LeftBC() elif (xc >= params.ShockLoc()): uinit[i, :, :] = params.RightBC() return uinit
def DoubleShock(params, x): ip = Interpolation.Interpolation(params.nnodes(), params.nquads()) uinit = np.zeros([params.nels(), params.nnodes(), params.neqs()]) for i in range(params.nels()): xc = np.sum(np.matmul(ip.W(), np.matmul(ip.B(), x[i, :]))) if (xc <= 0.3): uinit[i, :, :] = 4 elif (xc > 0.3 and xc <= 0.6): uinit[i, :, :] = 2 elif (xc > 0.6): uinit[i, :, :] = -1 return uinit
def build(self): root = ScreenManager() root.transition = SwapTransition() root.add_widget(MainMenu()) root.add_widget( bm.BracketMethods(screenManager=root, name='bracket_methods')) root.add_widget(om.OpenMethods(screenManager=root, name='open_methods')) root.add_widget( soe.SystemOfEquations(screenManager=root, name='system_equations')) root.add_widget( ip.Interpolation(screenManager=root, name='interpolation')) root.add_widget(rg.Regression(screenManager=root, name='regression')) return root
def Sod(params, x): ip = Interpolation.Interpolation(params.nnodes(), params.nquads()) # prim array rho, pressure, u Uinit = np.zeros([params.nels(), params.nnodes(), params.neqs()]) for i in range(params.nels()): #compute center of cell xc = np.sum(np.matmul(ip.W(), np.matmul(ip.B(), x[i, :]))) if (xc < params.ShockLoc()): Uinit[i, :, :] = params.LeftBC() elif (xc >= params.ShockLoc()): Uinit[i, :, :] = params.RightBC() print(Uinit) return Uinit
def do(self): if self.var.get() == 0: st = "sinx" function = f elif self.var.get() == 1: st = "5/(x^2+2)" function = g elif self.var.get() == 2: st = "sin(x) - y" function = z else: st = "x^2 + 2y" function = s euler_method = EulerMethod(float(self.x0.get()), float(self.y0.get()), float(self.accuracy.get()), float(self.xn.get()), function) array_with_dots = euler_method.solve_with_euler_method() plt.title("График") plt.xlabel("x") plt.ylabel("y") plt.grid() if len(array_with_dots) <= MaxCountOfDots: interpolation_method = Interpolation(float(self.x0.get()), float(self.xn.get()), array_with_dots) array = interpolation_method.get_dots_for_function() x = [array[i][0] for i in range(len(array))] y = [array[i][1] for i in range(len(array))] else: x = [array_with_dots[i][0] for i in range(len(array_with_dots))] y = [array_with_dots[i][1] for i in range(len(array_with_dots))] plt.plot(x, y, color='#008B8B', label='результат') if st == "sinx": value_of_function = [] for i in range(len(x)): value_of_function.append(f_true(x[i])) plt.plot(x, value_of_function, color='blue', label="true") for i in range(len(array_with_dots)): plt.scatter(array_with_dots[i][0], array_with_dots[i][1], color='red', s=5, marker='o') plt.legend() plt.show()
def __init__(self, mesh, params, equations): self.params = params self.__dim = 1 self.__neqs = params.neqs() self.__order = params.order() self.__nnodes = self.__order + 1 self.__nels = params.nels() self.__nquads = params.nquads() self.ip = interpolation.Interpolation(self.__nnodes, self.__nquads) self.mesh = mesh self.mass = np.matmul(np.transpose(self.ip.B()), np.matmul(self.ip.W(), self.ip.B())) self.invMass = np.linalg.inv(self.mass) self.__q = np.zeros([self.__nels, self.__nnodes, self.__neqs]) self.equations = equations self.__leftBC = np.zeros([self.__neqs]) self.__rightBC = np.zeros([self.__neqs])
def graphicTable(x, y, func=False): #Spline and Interpolating polinomial calculation #initiates classes data = spl.Spline(x, y) data2 = inter.Interpolation(x, y) spline = data.buildNormalSpline() #calculates the spline for the dataset data2_x, data2_y = data2.interpolateData( ) #calculates the interpolating pol xs = np.arange(x[0], x[-1] + 0.0001, 0.0001) plt.plot(x, y, "o", label="Data") if func: #displays the actual function f plt.plot(xs, f(xs), label='True Value') plt.plot(xs, spline(xs), label="Spline Trace") plt.plot(data2_x, data2_y, label="Interpolation") plt.legend(loc='lower left', ncol=2) plt.grid() plt.show() return data, spline, data2