Esempio n. 1
0
def cylinder_with_hole():
    """Cylinder with hole"""
    def fd10(p):
        r = np.sqrt(p[:,0]**2 + p[:,1]**2)
        z = p[:,2]

        d1 = r-1.0
        d2 = z-1.0
        d3 = -z-1.0
        d4 = np.sqrt(d1**2+d2**2)
        d5 = np.sqrt(d1**2+d3**2)
        d = dm.dintersect(dm.dintersect(d1, d2), d3)

        ix = (d1>0)*(d2>0)
        d[ix] = d4[ix]
        ix = (d1>0)*(d3>0)
        d[ix] = d5[ix]

        return dm.ddiff(d, dm.dsphere(p, 0,0,0, 0.5))

    def fh10(p):
        h1 = 4*np.sqrt((p**2).sum(1))-1.0
        return np.minimum(h1, 2.0)

    return dm.distmeshnd(fd10, fh10, 0.1, (-1,-1,-1, 1,1,1))
Esempio n. 2
0
def cylinder_with_hole():
    """Cylinder with hole"""
    def fd10(p):
        r = np.sqrt(p[:, 0]**2 + p[:, 1]**2)
        z = p[:, 2]

        d1 = r - 1.0
        d2 = z - 1.0
        d3 = -z - 1.0
        d4 = np.sqrt(d1**2 + d2**2)
        d5 = np.sqrt(d1**2 + d3**2)
        d = dm.dintersect(dm.dintersect(d1, d2), d3)

        ix = (d1 > 0) * (d2 > 0)
        d[ix] = d4[ix]
        ix = (d1 > 0) * (d3 > 0)
        d[ix] = d5[ix]

        return dm.ddiff(d, dm.dsphere(p, 0, 0, 0, 0.5))

    def fh10(p):
        h1 = 4 * np.sqrt((p**2).sum(1)) - 1.0
        return np.minimum(h1, 2.0)

    return dm.distmeshnd(fd10, fh10, 0.1, (-1, -1, -1, 1, 1, 1))
Esempio n. 3
0
def unit_ball():
    """3-D Unit ball"""
    fd = lambda p: np.sqrt((p**2).sum(1)) - 1.0
    return dm.distmeshnd(fd, dm.huniform, 0.2, (-1, -1, -1, 1, 1, 1))
Esempio n. 4
0
	def __init__(self, lx, ly, cx, cy, r):
		fd = lambda p: dm.ddiff(dm.drectangle(p,-lx,lx,-ly,ly), dm.dcircle(p,cx,cx,r))
		fh = lambda p: 0.05+0.03*dm.dcircle(p,cx,cy,r)	
		p, t = dm.distmeshnd(fd, fh, 0.5, (-lx,-ly,lx,ly),[(-lx,-ly),(-lx,ly),(lx,-ly),(lx,ly)])
		self.nodes = p
		self.conn = t
Esempio n. 5
0
def unit_ball():
    """3-D Unit ball"""
    fd = lambda p: np.sqrt((p**2).sum(1))-1.0
    return dm.distmeshnd(fd, dm.huniform, 0.2, (-1,-1,-1, 1,1,1))
Esempio n. 6
0
# Test 11: Dilation
G = Grid(min_coord, max_coord, gran, gran, gran)
G.create(sphere(4))
before = all([G[0, 0, 0] == [-4.0], G[0, 0, 4] == [0.0]])
G = dilation(G, 2.0)
G.create(G.phi)
print("Test 11 (Dilation a):",
      test_text(all([G[0, 0, 0] == [-2.0], G[0, 0, 4] == [2.0]]) and before))

# Test 12: Opening
G = Grid(min_coord, max_coord, gran, gran, gran)
G.create(sphere(4))
before = all([G[0, 0, 0] == [-4.0], G[0, 0, 4] == [0.0]])
G = opening(G, 2.0)
G.create(G.phi)
print("Test 12 (Opening):",
      test_text(all([G[0, 0, 0] == [-4.0], G[0, 0, 4] == [0.0]]) and before))

# Test 13: Dilation
G = Grid(min_coord, max_coord, gran, gran, gran)
G.create(sphere(4))
before = all([G[0, 0, 0] == [-4.0], G[0, 0, 4] == [0.0]])
G = dilation(G, 5.0)
G.create(G.phi)
print([G[0, 0, 0], G[0, 0, 4]])
print(np.min(G.values))
print("Test 13 (Dilation b):",
      test_text(all([G[0, 0, 0] == [-4.0], G[0, 0, 4] == [0.0]]) and before))

p, t = dm.distmeshnd(G.phi, dm.huniform, 0.2, (-1, -1, -1, 1, 1, 1))
Esempio n. 7
0
import math
import random

import numpy as np
import distmesh as dm

import matplotlib.pyplot as plt

lines = []

p0 = Vec3(0, 0, 0)
p1 = Vec3(1, 0, 0)
p2 = Vec3(0, 1, 0)
p3 = Vec3(0, 0, 1)

lines.append([p0, p1])
lines.append([p0, p2])
lines.append([p0, p3])


def fn(p):
    # p = p[0]
    # return math.sqrt( p[0]**2+p[1]**2+p[2]**2 )-1.0
    return np.sqrt((p ** 2).sum(1)) - 1.0


p, t = dm.distmeshnd(fn, dm.huniform, 0.2, (-1, -1, -1, 1, 1, 1))

dm.simpplot(p, t)