Exemplo n.º 1
0
def main():

    HEIGTH = Shape.HEIGTH
    WIDTH = Shape.WIDTH
    FORCE_VALUE = 500
    DELAY_MILISECONDS = 17
    FRICTION = 0.5

    Shape.SCALING_FACTOR = 10  #TODO CHANGE THIS TO CHANGE SCALING
    #Note - acts weird if scaling is >= 14

    enviroment = Fluid(1.225, np.array([0, 0]))

    #TODO COMMENT AND UNCOMMENT TO SWITCH FROM RECTANGLE TO BALL AND VICE VERSA

    ball = Ball(10, (250, 0, 0), 15, enviroment, FRICTION)
    #ball = Rect(10, (250, 0, 0), 200, 10, enviroment, FRICTION)

    #TODO COMMENT AND UNCOMMENT TO SWITCH FROM RECTANGLE TO BALL AND VICE VERSA

    east_wall = Rect(100, (0, 250, 0), 50, HEIGTH, enviroment, FRICTION, True)
    east_wall.position[0] = WIDTH - 5
    east_wall.position[1] = HEIGTH / 2

    west_wall = Rect(100, (0, 250, 0), 50, HEIGTH, enviroment, FRICTION, True)
    west_wall.position[0] = 50
    west_wall.position[1] = HEIGTH / 2

    south_wall = Rect(100, (0, 250, 0), WIDTH, 50, enviroment, FRICTION, True)
    south_wall.position[0] = WIDTH / 2
    south_wall.position[1] = HEIGTH - 5

    north_wall = Rect(100, (0, 250, 0), WIDTH, 50, enviroment, FRICTION, True)
    north_wall.position[0] = WIDTH / 2
    north_wall.position[1] = 50

    square = Rect(1, (0, 250, 0), 100, 20, enviroment, FRICTION, False)
    square.position[0] = 250
    square.position[1] = 250

    sprite_ball = Ball(100, (0, 250, 0), 20, enviroment, FRICTION, True)
    sprite_ball.position[0] = 250
    sprite_ball.position[1] = 400

    enviroment.add(ball)
    enviroment.add(east_wall)
    enviroment.add(west_wall)
    enviroment.add(south_wall)
    enviroment.add(north_wall)
    enviroment.add(square)
    enviroment.add(sprite_ball)

    enviroment.recalibrate_shapes_positions()

    pygame.init()
    window = pygame.display.set_mode((WIDTH, HEIGTH))
    pygame.display.set_caption("Koralovo")

    run = True

    while True:
        pygame.time.delay(DELAY_MILISECONDS)

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit(0)
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_p:
                    run = not run
                elif event.key == pygame.K_SPACE and not run:
                    loop(ball, FORCE_VALUE, enviroment, window)
        if run:
            loop(ball, FORCE_VALUE, enviroment, window)
Exemplo n.º 2
0
from Fluid import Fluid
from Ellipse import Ellipse
from MatrixUtility import Stack, Unstack

# Simulation parameters
N = 128
RestrictToEulerian = False  # If True we restrict the fiber points to Eulerian intersections. When done the matrix should give EXACT results.

# Create the fiber in the shape of an ellipse
X = Ellipse(2 * N, s=10e6, c=[.5, .5], p1=[.8, .5], p2=[.5, .6])
if RestrictToEulerian:
    X.X = floor(X.X * N) / N

# Initialize the fluid solver
u = Fluid(dt=1. / N, N=[N, N], dims=[1., 1.])

# Calculate dX/dt (stored in X.U) using a fluid solve
X.CalcForceDistribution()
X.ToGrid(u)
u.UpdateFluid(u.f)
X.FromGrid(u)

# Calculate dX/dt (stored in U) using the fluid matrix
# First construt the fluid matrix
M = X.ConstructFluidMatrix(u)

# Then calculate U = M * F, where F is the fiber force
U = Unstack(dot(M, Stack(X.F)), 2)

# Calculate difference between X.U and U (the induced flow calculated via a fluid solve and via the matrix)
Exemplo n.º 3
0
    for i in range(0,2):
        vx = np.random.uniform(-3,3)
        vy = np.random.uniform(-3,3)      
        t += 0.01
        fluid.addVelocity(cx, cy, vx, vy)

    fluid.step()
    image = fluid.render()
    im = plt.imshow(image, cmap='YlOrRd', interpolation = "nearest", animated=True)
    return im

if __name__ == "__main__":
    # Define the fluid object with a given time resolution
    # diffusion and viscosity
    fluid = Fluid(0.1, 0, 0.0000005)

    fig = plt.figure()

    ims = []
    for i in tqdm(range(step)):
        im = iterate(fluid, t)
        ims.append([im])

    ani = animation.ArtistAnimation(fig, ims, interval=100, blit=True,
                                    repeat_delay=1000)

    if(output_type == "mp4"):
        ani.save(f'./movies/movie_dif_vis_steps{step}.mp4')
    elif(output_type == "gif"):  
        ani.save(f'./movies/movie_dif_vis_steps{step}_.gif', dpi=80, writer='imagemagick')
Exemplo n.º 4
0
    "Antoine coeff": [13.9320, 3056.96, 217.625]
}

Toluene = PureComponent(toluene)
# PureComponent.save_component(toluene)
# Toluene1 = PureComponent.load_component("toluene")

Benzene = PureComponent(benzene)
# PureComponent.save_component(benzene)
# Benzene1 = PureComponent.load_component("benzene")

Water = PureComponent(water)
# PureComponent.save_component(water)
# Water1 = PureComponent.load_component("water")

fluid1 = Fluid(2, 288, 101325, [Benzene, Toluene], [0.6, 0.4], PR)
fluid2 = Fluid(2, 363, 101325, [Water], [1], PR)

phase_list1 = fluid1.phase_list
phase_list2 = fluid2.phase_list

# here you can read all phase properties like: phase_list1[0].H
new_conditions1 = {"T": 300, "P": 100000, "composition": [0.5, 0.5]}
fluid1.update(new_conditions1)

new_conditions2 = {"T": 300, "P": 100000}
fluid2.update(new_conditions2)

new_conditions3 = {"T": 320}
fluid1.update(new_conditions3)