示例#1
0
def hex_couette():
	m, n = 6, 12
	G, (l, r, t, b) = gds.hexagonal_lattice(m, n, with_boundaries=True)
	faces, outer_face = gds.embedded_faces(G)
	contractions = {}
	for j in range(1, 2*m+1):
		G = nx.algorithms.minors.contracted_nodes(G, (0, j), (n, j))
		contractions[(n, j)] = (0, j)
	nx.set_node_attributes(G, None, 'contraction')
	rendered_faces = set()
	for i, face in enumerate(faces):
		face = list(face)
		modified = False
		for j, node in enumerate(face):
			if node in contractions:
				n_l = contractions[node] # identified
				face[j] = n_l
				faces[i] = tuple(face)
				modified = True
		if not modified:
			rendered_faces.add(i)
	G.faces = faces
	G.rendered_faces = np.array(sorted(list(rendered_faces)), dtype=np.intp) # Hacky

	pressure, velocity = navier_stokes(G, viscosity=1., density=1e-2)
	vel = 1.0
	def walls(e):
		if (e[0][1] == e[1][1] == 0) and (e[0][0] == e[1][0] - 1):
			return vel
		elif e in t.edges or e == ((0, 2*m), (n, 2*m+1)):
			return 0.0
		return None
	velocity.set_constraints(dirichlet=walls)
	return pressure, velocity
示例#2
0
文件: laplace.py 项目: asrvsn/gds
def square_edge_diffusion():
    m, n = 10, 10
    G, (l, r, t, b) = gds.square_lattice(n, m, with_boundaries=True)
    faces, outer_face = gds.embedded_faces(G)
    for j in range(m):
        G.add_edge((n - 1, j), (0, j))
    aux_faces = [((n - 1, j), (0, j), (0, j + 1), (n - 1, j + 1))
                 for j in range(m - 1)]
    G.faces = faces + aux_faces  # Hacky
    G.rendered_faces = np.array(range(len(faces)), dtype=np.intp)  # Hacky
    v = gds.edge_gds(G)
    v.set_evolution(dydt=lambda t, y: v.laplacian(y))
    velocity = 1.0

    def boundary(e):
        if e in b.edges:
            return velocity
        elif e == ((0, 0), (m - 1, 0)):
            return -velocity
        elif e in t.edges or e == ((0, n - 1), (m - 1, n - 1)):
            return 0.0
        return None

    v.set_constraints(dirichlet=boundary)
    return v
示例#3
0
def tri_couette():
	m, n = 10, 20
	G, (l, r, t, b) = gds.triangular_lattice(m, n, with_boundaries=True)
	faces, outer_face = gds.embedded_faces(G)
	for j in range(m+1):
		G = nx.algorithms.minors.contracted_nodes(G, (0, j), ((n + 1) // 2, j))
	rendered_faces = set()
	r_nodes = set(r.nodes())
	for i, face in enumerate(faces):
		face = list(face)
		modified = False
		for j, node in enumerate(face):
			if node in r_nodes:
				n_l = (0, node[1]) # identified
				face[j] = n_l
				faces[i] = tuple(face)
				modified = True
		if not modified:
			rendered_faces.add(i)
	G.faces = faces
	G.rendered_faces = np.array(sorted(list(rendered_faces)), dtype=np.intp) # Hacky

	pressure, velocity = navier_stokes(G, viscosity=1., density=1e-2)
	vel = 1.0
	def walls(e):
		if e in b.edges:
			return vel
		elif e == ((0, 0), (n//2-1, 0)):
			return -vel
		elif e in t.edges or e == ((0, m), (n//2-1, m)):
			return 0.0
		return None
	velocity.set_constraints(dirichlet=walls)
	return pressure, velocity
示例#4
0
def tri_couette_ivp(viscosity, density):
	m, n = 10, 20
	G, (l, r, t, b) = gds.triangular_lattice(m, n, with_boundaries=True, with_lattice_components=True)
	lcomps = G.lattice_components
	faces, outer_face = gds.embedded_faces(G)
	for j in range(m+1):
		G = nx.algorithms.minors.contracted_nodes(G, (0, j), ((n + 1) // 2, j))
	rendered_faces = set()
	r_nodes = set(r.nodes())
	for i, face in enumerate(faces):
		face = list(face)
		modified = False
		for j, node in enumerate(face):
			if node in r_nodes:
				n_l = (0, node[1]) # identified
				face[j] = n_l
				faces[i] = tuple(face)
				modified = True
		if not modified:
			rendered_faces.add(i)
	G.faces = faces
	G.rendered_faces = np.array(sorted(list(rendered_faces)), dtype=np.intp) # Hacky

	# hacky
	nodes, edges = set(G.nodes()), set(G.edges())
	for comp in lcomps.values():
		comp.remove_nodes_from(set(comp.nodes()) - nodes)
		comp.remove_edges_from(set(comp.edges() - edges))
	G.lattice_components = lcomps 

	pressure, velocity = navier_stokes(G, viscosity=viscosity, density=density)
	vel = 1.0
	def walls(e):
		if e[0][1] == e[1][1] == m//2:
			if e == ((0, 0), (n//2-1, 0)):
				return -vel
			return vel
		return 0
	velocity.set_initial(y0=walls)
	return pressure, velocity
示例#5
0
def sq_couette():
	m, n = 11, 10
	G, (l, r, t, b) = gds.square_lattice(m, n, with_boundaries=True)
	faces, outer_face = gds.embedded_faces(G)
	for j in range(m):
		G.add_edge((n-1, j), (0, j))
	aux_faces = [((n-1, j), (0, j), (0, j+1), (n-1, j+1)) for j in range(m-1)]
	G.faces = faces + aux_faces # Hacky
	G.rendered_faces = np.array(range(len(faces)), dtype=np.intp) # Hacky

	pressure, velocity = navier_stokes(G, viscosity=1., density=1e-2)
	vel = 1.0
	def walls(e):
		if e in t.edges or e == ((0, m-1), (n-1, m-1)):
			return 0
		elif e in b.edges: 
			return vel
		elif e == ((0, 0), (n-1, 0)):
			return -vel
		return None
	velocity.set_constraints(dirichlet=walls)
	return pressure, velocity
示例#6
0
文件: laplace.py 项目: asrvsn/gds
def hex_edge_diffusion():
    m, n = 10, 20
    G, (l, r, t, b) = gds.hexagonal_lattice(m, n, with_boundaries=True)
    faces, outer_face = gds.embedded_faces(G)
    contractions = {}
    for j in range(1, 2 * m + 1):
        G = nx.algorithms.minors.contracted_nodes(G, (0, j), (n, j))
        contractions[(n, j)] = (0, j)
    nx.set_node_attributes(G, None, 'contraction')
    rendered_faces = set()
    for i, face in enumerate(faces):
        face = list(face)
        modified = False
        for j, node in enumerate(face):
            if node in contractions:
                n_l = contractions[node]  # identified
                face[j] = n_l
                faces[i] = tuple(face)
                modified = True
        if not modified:
            rendered_faces.add(i)
    G.faces = faces
    G.rendered_faces = np.array(sorted(list(rendered_faces)),
                                dtype=np.intp)  # Hacky
    # pdb.set_trace()
    v = gds.edge_gds(G)
    v.set_evolution(dydt=lambda t, y: v.laplacian(y))
    velocity = 1.0

    def boundary(e):
        if (e[0][1] == e[1][1] == 0) and (e[0][0] == e[1][0] - 1):
            return velocity
        elif e in t.edges or e == ((0, 2 * m), (n, 2 * m + 1)):
            return 0.0
        return None

    v.set_constraints(dirichlet=boundary)
    return v
示例#7
0
def sq_couette_ivp(viscosity, density):
	m, n = 11, 10
	G, (l, r, t, b) = gds.square_lattice(m, n, with_boundaries=True, with_lattice_components=True)
	faces, outer_face = gds.embedded_faces(G)
	for j in range(m):
		G.add_edge((n-1, j), (0, j))
	# for i in range(n):
	# 	G.add_edge((i, 0), (i, m-1))
	aux_faces = [((n-1, j), (0, j), (0, j+1), (n-1, j+1)) for j in range(m-1)]
	# aux_faces += [((i, 0), (i, m-1), (i+1, m-1), (i+1, 0)) for i in range(n-1)]
	G.faces = faces + aux_faces # Hacky
	G.rendered_faces = np.array(range(len(faces)), dtype=np.intp) # Hacky

	pressure, velocity = navier_stokes(G, viscosity=viscosity, density=density)
	vel = 1.0
	def walls(e):
		if e[0][1] == e[1][1] == m//2:
			if e[0][0] == 0 and e[1][0] == n-1:
				return -vel
			return vel
		return 0
	velocity.set_initial(y0=walls)
	return pressure, velocity
示例#8
0
文件: laplace.py 项目: asrvsn/gds
def tri_edge_diffusion():
    m, n = 10, 20
    G, (l, r, t, b) = gds.triangular_lattice(m, n, with_boundaries=True)
    faces, outer_face = gds.embedded_faces(G)
    for j in range(m + 1):
        G = nx.algorithms.minors.contracted_nodes(G, (0, j), ((n + 1) // 2, j))
    rendered_faces = set()
    r_nodes = set(r.nodes())
    for i, face in enumerate(faces):
        face = list(face)
        modified = False
        for j, node in enumerate(face):
            if node in r_nodes:
                n_l = (0, node[1])  # identified
                face[j] = n_l
                faces[i] = tuple(face)
                modified = True
        if not modified:
            rendered_faces.add(i)
    G.faces = faces
    G.rendered_faces = np.array(sorted(list(rendered_faces)),
                                dtype=np.intp)  # Hacky
    v = gds.edge_gds(G)
    v.set_evolution(dydt=lambda t, y: v.laplacian(y))
    velocity = 1.0

    def boundary(e):
        if e in b.edges:
            return velocity
        elif e == ((0, 0), (n // 2 - 1, 0)):
            return -velocity
        elif e in t.edges or e == ((0, m), (n // 2 - 1, m)):
            return 0.0
        return None

    v.set_constraints(dirichlet=boundary)
    return v