Exemple #1
0
def makeGrid(shape, N):
    rmax = 2.0  # line length
    agrid, pts = [], []
    for th in np.linspace(0, np.pi, N, endpoint=True):
        lats = []
        for ph in np.linspace(0, 2 * np.pi, N, endpoint=True):
            p = np.array([sin(th) * cos(ph), sin(th) * sin(ph), cos(th)]) * rmax
            intersections = shape.intersectWithLine([0, 0, 0], p)
            if len(intersections):
                value = mag(intersections[0])
                lats.append(value - rbias)
                pts.append(intersections[0])
            else:
                lats.append(rmax - rbias)
                pts.append(p)
        agrid.append(lats)
    agrid = np.array(agrid)
    actor = Points(pts, c="k", alpha=0.4, r=1)
    return agrid, actor
    def FinalizeSolutionStep(self):
        super().FinalizeSolutionStep()
        if self.timestep > 1.5:
            if self.timestep == 2:
                self.a_mesh = vedo.load(
                    f'./vtk_output/VISUALIZE_HROM_0_{self.timestep}.vtk'
                ).tomesh(fill=True, shrink=1)
                displs = self.a_mesh.getPointArray("DISPLACEMENT")

            if self.timestep > 2:
                b_mesh = vedo.load(
                    f'./vtk_output/VISUALIZE_HROM_0_{self.timestep}.vtk'
                ).tomesh(fill=True, shrink=1)
                newpoints = b_mesh.points()
                displs = b_mesh.getPointArray("DISPLACEMENT")
                self.a_mesh.points(newpoints + displs)

            self.a_mesh.pointColors(vedo.mag(displs),
                                    cmap='jet',
                                    vmin=0,
                                    vmax=0.009).addScalarBar()
            self.a_mesh.show(axes=1, viewup='z')
        self.timestep += 1
Exemple #3
0
# Create the springs out of N links
link = [None] * N
for k in range(N):
    p0 = bob[k].pos()
    p1 = bob[k + 1].pos()
    link[k] = Spring(p0, p1, thickness=0.015, r=R / 3, c="gray")
    plt += link[k]

# Create some auxiliary variables
x_dot_m = np.zeros(N + 1)
y_dot_m = np.zeros(N + 1)
dij = np.zeros(N + 1)  # array with distances to previous bob
dij_m = np.zeros(N + 1)
for k in range(1, N + 1):
    dij[k] = mag([bob_x[k] - bob_x[k - 1], bob_y[k] - bob_y[k - 1]])

fctr = lambda x: (x - 1) / x
Dt *= np.sqrt(1 / g)
Dt2 = Dt / 2  # Midpoint time step
DiaSq = (2 * R)**2  # Diameter of bob squared

printc("Press ESC to exit.", c="red", invert=1)

while True:
    bob_x_m = list(map((lambda x, dx: x + Dt2 * dx), bob_x,
                       x_dot))  # midpoint variables
    bob_y_m = list(map((lambda y, dy: y + Dt2 * dy), bob_y, y_dot))

    for k in range(1, N + 1):
        factor = fctr(dij[k])
Exemple #4
0
    pz = pavg * np.cos(theta)
    poslist.append((x, y, z))
    plist.append((px, py, pz))
    mlist.append(mass)
    rlist.append(Ratom)

pos = np.array(poslist)
poscircle = pos
p = np.array(plist)
m = np.array(mlist)
m.shape = (Natoms, 1)
radius = np.array(rlist)
r = pos - pos[:, np.newaxis]  # all pairs of atom-to-atom vectors

ds = (p / m) * (dt / 2.0)
if "False" not in np.less_equal(mag(ds), radius).tolist():
    pos = pos + (p / mass) * (dt / 2.0)  # initial half-step

pb = ProgressBar(0, Nsteps, c=1)
for i in pb.range():

    # Update all positions
    ds = mag((p / m) * (dt / 2.0))
    if "False" not in np.less_equal(ds, radius).tolist():
        pos = pos + (p / m) * dt

    r = pos - pos[:, np.newaxis]  # all pairs of atom-to-atom vectors
    rmag = np.sqrt(np.sum(np.square(r), -1))  # atom-to-atom scalar distances
    hit = np.less_equal(rmag, radius + radius[:, None]) - np.identity(Natoms)
    hitlist = np.sort(np.nonzero(
        hit.flat)[0]).tolist()  # i,j encoded as i*Natoms+j
#############################################################

shape = load(datadir + 'apple.ply').normalize().pos(x0).lineWidth(0.1)

show(shape, at=0, N=2, axes=dict(zxGrid=False))

############################################################
# cast rays from the center and find intersections
agrid, pts = [], []
for th in np.linspace(0, np.pi, N, endpoint=False):
    lats = []
    for ph in np.linspace(0, 2 * np.pi, N, endpoint=False):
        p = spher2cart(rmax, th, ph)
        intersections = shape.intersectWithLine([0, 0, 0], p)
        if len(intersections):
            value = mag(intersections[0])
            lats.append(value)
            pts.append(intersections[0])
        else:
            lats.append(rmax)
            pts.append(p)
    agrid.append(lats)
agrid = np.array(agrid)

grid = pyshtools.SHGrid.from_array(agrid)
clm = grid.expand()
grid_reco = clm.expand(lmax=lmax)  # cut "high frequency" components

#############################################################
# interpolate to a finer grid
agrid_reco = grid_reco.to_array()