def _build_L_deltaV(self, v, v0): """ Compute the matrix product L * delta_V as it remains constant over time delta_V = v - v0 :param v: expression of interest :param v0: neutral expression :return: """ LdV = [] for k in range(self.K): # compute delta_V if np.array_equal(v[k], v0): # avoid the case of v[k] = v0 dV = v[k] else: dV = v[k] - v0 # build mesh mesh = triangulate_vertices(dV) # build Laplacian L = build_Laplacian(mesh, n_v) L = L.todense() L_expand = np.zeros((n_n, n_n)) # expand L by 3 for i in range(n_n): for j in range(n_n): if i % 3 == 0 and j % 3 == 0: L_expand[i, j] = L[int(i / 3), int(j / 3)] if i % 3 == 1 and j % 3 == 1: L_expand[i, j] = L[int(i / 3), int(j / 3)] if i % 3 == 2 and j % 3 == 2: L_expand[i, j] = L[int(i / 3), int(j / 3)] LdV.append(L_expand @ dV) return np.array(LdV)
def __init__(self, delta_gk): self.delta_gk = delta_gk self.K = np.shape(self.delta_gk)[0] self.M = np.shape(self.delta_gk)[1] self.L = [] for k in range(self.K): mesh = triangulate_vertices(delta_gk[k]) self.L.append(build_Laplacian(mesh, self.M)) self.L = np.array(self.L)
def __init__(self, delta_gk, ref): self.delta_gk = delta_gk self.K = np.shape(self.delta_gk)[0] self.M = np.shape(self.delta_gk)[1] self.L = [] for k in range(self.K): # points = delta_gk[k] # mesh = triangulate_vertices(points) # L = build_Laplacian(mesh, self.M).todense() # # self.L.append(np.diag(L)) # self.L.append(L) points = ref + delta_gk[k] mesh = triangulate_vertices(points) L = build_Laplacian(mesh, self.M).todense() # self.L2.append(np.diag(L)) self.L.append(L) # self.L = np.array(self.L) self.L = np.array(self.L)
dgk = np.random.rand(n_k, n_m, 3) dp = np.random.rand(n_k, n_n) print("dgk") print(dgk) print("dp") print(dp) # create EMesh object e_mesh = EMesh(dgk) # control compute e_mesh print("compute control e_mesh") emesh_list = [] for k in range(n_k): mesh = triangulate_vertices(dgk[k]) L = build_Laplacian(mesh, n_m) dv = np.reshape(dp[k], (-1, 3)) - dgk[k] l_op = L.dot(dv) norm = np.linalg.norm(l_op, axis=1)**2 emesh_list.append(norm) emesh_ctrl = np.sum(emesh_list) / n_m print("emesh_ctrl =", emesh_ctrl) # compute e_mesh print("compute e_mesh") e_mesh_fn = e_mesh.get_eMesh() emesh = e_mesh_fn(dp) print("emesh =", emesh) assert emesh == emesh_ctrl
print("dgk") print(dgk) print("dp") print(dp) # create EMesh object e_mesh = EMesh(dgk, dg_ref) # control compute e_mesh print("compute control e_mesh") dp = np.reshape(dp, (n_k, n_m, 3)) emesh_ctrl = 0 for k in range(n_k): points = dg_ref + dgk[k] mesh = triangulate_vertices(points) L = build_Laplacian(mesh, n_m).todense() for m in range(n_m): dv = dp[k, m] - dgk[k, m] sum_Lm = np.sum(np.power(L[m, :], 2)) norm = np.linalg.norm(sum_Lm * dv)**2 emesh_ctrl += norm emesh_ctrl = emesh_ctrl / n_m print("emesh_ctrl =", emesh_ctrl) # compute e_mesh print("compute e_mesh") e_mesh_fn = e_mesh.get_eMesh() emesh = e_mesh_fn(dp) print("emesh =", emesh)