# out_mesh_global[j,1] = pow(output_mesh.points[j][1] + 0.5,outputScaling)*0.00001 # out_mesh_Combined[j,0] = pow(output_mesh.points[j][0] + 0.5,outputScaling)*0.00001 # out_mesh_Combined[j,1] = pow(output_mesh.points[j][1] + 0.5,outputScaling)*0.00001 # out_mesh_Split[j,0] = pow(output_mesh.points[j][0] + 0.5,outputScaling)*0.00001 # out_mesh_Split[j,1] = pow(output_mesh.points[j][1] + 0.5,outputScaling)*0.00001 #print("Original inmesh: ", in_mesh) #print("Original outmesh: ", out_mesh) #print("Original outmesh length: ", kk) #mesh_size = 1/math.sqrt(nPoints) mesh_size = 2 shape_parameter = 4.55228 / ((1.0) * mesh_size) print("mesh width: ", mesh_size) print("shape_parameter: ", shape_parameter) bf = basisfunctions.Gaussian(shape_parameter) ########################################################## ########################################################## ''' Functions to test ''' #func = lambda x,y: np.exp(-100*((0.5*pow(x-0.5,2))+(0.5*pow(y-0.5,2)))) func = lambda x, y: 0.75 * np.exp(-( (pow(9 * x - 2, 2)) + (pow(9 * y - 2, 2))) / 4) + 0.75 * np.exp(-(pow(9 * x + 1, 2) / 49) - ( (9 * y + 1) / 10)) + 0.5 * np.exp(-( (pow(9 * x - 7, 2)) + (pow(9 * y - 3, 2))) / 4) - 0.2 * np.exp(-( (pow(9 * x - 4, 2)) + (pow(9 * y - 7, 2)))) ## Complex sin function
func = lambda x, y: np.sin(2 * x) + (0.0000001 * y) one_func = lambda x: np.ones_like(x) in_vals = func(in_mesh[:, 0], in_mesh[:, 1]) #print(tree.query(pts)) #print("in_mesh: ", in_mesh) for k in range(5, 6): for j in range(0, nPoints): shape_params[j] = 4.55228 / (k * maxNN) #shape_params[j]=4.55228/(i*nearest_neighbors[j]) #print("shape_params: ", shape_params) #mesh_size = 1/math.sqrt(nPoints) #print("mesh_size: ",mesh_size) #shape_parameter = 4.55228/((5)*mesh_size) #print("shape_parameter: ",shape_parameter) bf = basisfunctions.Gaussian(list(shape_params)) #print("BF: ", bf) #func = lambda x: (x-0.1)**2 + 1 #in_meshChange = [0, 0.02, 0.03, 0.1,0.23,0.25,0.52,0.83,0.9,0.95,1] #for j in range(0,11): # in_mesh[j] = in_meshChange[j] #print(in_mesh) #plot_mesh = np.random.random((nPoints,2)) #print(in_vals) # evaluatine_vals = func(evaluate_mesh) # basis_vals = func(basis_mesh) #interp = NoneConsistent(bf, in_mesh, in_vals, rescale = False)
in_mesh = mesh.GaussChebyshev_1D(order=12, element_size=0.25, domain_size=1, domain_start=0) # in_mesh = np.linspace(0, 1, 48) out_mesh = np.linspace(np.min(in_mesh), np.max(in_mesh), 20) # in_mesh = np.geomspace(1, 100, 90) # in_mesh = in_mesh / 100 # out_mesh = np.linspace(0, 1, 80) in_vals = testfunction(in_mesh) m = 6 bf = basisfunctions.Gaussian( basisfunctions.Gaussian.shape_param_from_m(m, in_mesh)) interp = rbf.SeparatedConservative(bf, in_mesh, in_vals) one_interp = rbf.NoneConservative(bf, in_mesh, np.ones_like(in_vals), rescale=False) out_vals = interp(out_mesh) rescaled = out_vals / one_interp(out_mesh) print(out_vals) print("Conservativness Delta of Interp = ", np.sum(in_vals) - np.sum(out_vals)) print("Conservativness Delta of Rescaled = ", np.sum(in_vals) - np.sum(rescaled))
for k in range(1, n + 1): P = P @ (I - Alpha @ P) Pn = X @ P @ inv(X) return Pn, A if __name__ == "__main__": N = 500 # a = np.random.randint(0,100, size=(N,N)) # A = np.tril(a) + np.tril(a, -1).T in_mesh = np.linspace(1, 4, N) # in_mesh = mesh.GaussChebyshev_1D(24, 1, 4, 1) basisfunction = basisfunctions.Gaussian().shaped(5, in_mesh) coordinate_mesh = in_mesh[:, np.newaxis] A = scipy.spatial.distance_matrix(coordinate_mesh, coordinate_mesh) A = basisfunction(A) I = np.identity(len(A)) print("max(EV(A)) =", np.linalg.eigvalsh(A)[-1]) print("EV(A) > 0 =", np.all(np.linalg.eigvalsh(A) > 0)) print("||I-A||_2 =", norm(I - A, 2)) # Should be < 1 according to 5.3 P, A = MLS_PC(A) # P, A = MLS_PC_Alg1(A) print() print("||A^-1 - P|| =", norm(inv(A) - P)) print("||A - P|| =", norm(A - P))
domain_start=-1) test_mesh = np.linspace(-1, 1, 500) spacing = mesh.spacing(gc_points) h_max = np.max(spacing) print("h_max =", h_max) m = 4 support = h_max * m print("support =", support) local_m = support / spacing tf = testfunctions.Constant(1) bf = basisfunctions.Gaussian( basisfunctions.Gaussian.shape_param_from_m(m, gc_points)) interp = rbf.NoneConsistent(bf, gc_points, tf(gc_points)) fig, ax1 = plt.subplots() ax1.plot(gc_points, np.zeros_like(gc_points), "o") ax1.plot(gc_points, mesh.spacing(gc_points), label="spacing") ax1.plot(gc_points, local_m, "o-", label="local m") ax2 = plt.gca().twinx() ax2.plot(test_mesh, interp.error(tf, test_mesh)) df1 = pd.DataFrame(index=gc_points, data={ "Pos": np.zeros_like(gc_points), "Spacing": mesh.spacing(gc_points), "LocalM": local_m