Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Implement fluid simulation template classes #66

Merged
merged 12 commits into from
Feb 10, 2024
37 changes: 37 additions & 0 deletions boat_simulator/nodes/physics_engine/fluid_generation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Generator for fluid vectors used in the physics engine."""

import numpy as np
from numpy.typing import NDArray

from boat_simulator.common.generators import VectorGenerator
from boat_simulator.common.types import Scalar


class FluidGenerator:
def __init__(self, generator: VectorGenerator):
eomielan marked this conversation as resolved.
Show resolved Hide resolved
self.__generator = generator
self.__velocity = np.array([0, 0])
eomielan marked this conversation as resolved.
Show resolved Hide resolved
self.__speed = 0
self.__direction = 0

def next(self) -> NDArray:
"""Updates the fluid simulator by generating the next velocity vector.

Returns:
NDArray: An array representing the updated velocity vector for the fluid simulation.
"""

# TODO: Implement this method
return np.array([0, 0])

@property
def velocity(self) -> NDArray:
return self.__velocity

@property
def speed(self) -> Scalar:
return self.__speed

@property
def direction(self) -> Scalar:
return self.__direction
eomielan marked this conversation as resolved.
Show resolved Hide resolved
19 changes: 0 additions & 19 deletions boat_simulator/nodes/physics_engine/fluids.py

This file was deleted.

43 changes: 43 additions & 0 deletions boat_simulator/nodes/physics_engine/force_computation.py
eomielan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Class to compute lift and drag forces acting on a medium."""

from typing import Tuple

import numpy as np
from numpy.typing import NDArray

from boat_simulator.common.types import Scalar


class ForceComputation:
eomielan marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, lift_coefficient: Scalar, area: Scalar, fluid_density: Scalar):
self.__lift_coefficient = lift_coefficient
self.__area = area
self.__fluid_density = fluid_density
eomielan marked this conversation as resolved.
Show resolved Hide resolved

def compute(self, apparent_velocity: NDArray) -> Tuple[NDArray, NDArray]:
"""Computes the lift and drag forces acting on a medium.

Args:
apparent_velocity (NDArray): Apparent (relative) velocity between the fluid and the
medium, given in meters per second (m/s).
eomielan marked this conversation as resolved.
Show resolved Hide resolved

Returns:
Tuple[NDArray, NDArray]: A tuple where the first element represents lift force and the
second element represents the drag force, both of which are expressed in
newtons (N).
"""

# TODO: Implement this method
return (np.array([0, 0]), np.array([0, 0]))

@property
def lift_coefficient(self) -> Scalar:
return self.__lift_coefficient

@property
def area(self) -> Scalar:
return self.__area

@property
def fluid_density(self) -> Scalar:
return self.__fluid_density