Example #1
0
def value(altitude: float, velocity: Vector, rho: float) -> Vector:
    if velocity.z < 0 and altitude > SECOND_PARACHUTE_OPENING_HEIGHT:  # First parachute
        return velocity.unary().multiply(
            scalar=-0.5 * rho * (velocity.norm()**2) *
            REFERENCE_AREA_FIRST_PARACHUTE * CD_VERTICAL_FIRST_PARACHUTE)
    else:
        return velocity.unary().multiply(
            scalar=-0.5 * rho * (velocity.norm()**2) *
            REFERENCE_AREA_SECOND_PARACHUTE * CD_VERTICAL_SECOND_PARACHUTE)
Example #2
0
    def value(self, data: Data) -> Vector:

        total_force: Vector = Vector(x=0, y=0, z=0)

        if self.stage == FlightStage.BASE:

            total_force = self.weight().add(vector=self.engine().add(
                vector=self.drag()))

            self.setFlightStage(data=data, total_force=total_force)

            if total_force.z < 0:
                return Vector(x=0, y=0, z=0)
            else:
                return total_force.divide(scalar=ROCKET_MASS)

        elif self.stage == FlightStage.LAUNCH_RAIL:

            total_force = self.weight().add(vector=self.engine().add(
                vector=self.drag()))

            self.setFlightStage(data=data, total_force=total_force)

            return total_force.divide(scalar=ROCKET_MASS)

        elif self.stage == FlightStage.PROPELLED:

            total_force = self.weight().add(vector=self.engine().add(
                vector=self.drag()))

            self.setFlightStage(data=data, total_force=total_force)

            return total_force.divide(scalar=ROCKET_MASS)

        elif self.stage == FlightStage.BALLISTIC:

            total_force = self.weight().add(vector=self.drag())

            self.setFlightStage(data=data, total_force=total_force)

            return total_force.divide(scalar=ROCKET_MASS)

        elif self.stage == FlightStage.PARACHUTE:

            total_force = self.weight().add(vector=self.parachute())

            self.setFlightStage(data=data, total_force=total_force)

            return total_force.divide(scalar=ROCKET_MASS)

        return total_force
Example #3
0
    def derivative(t, y) -> List[float]:  # t: float, y: List[float]

        # Create data model
        data_der = Data(position=Vector(x=y[0], y=y[1], z=y[2]), velocity=Vector(x=y[3], y=y[4], z=y[5]), time=t)

        y_dot = [0] * len(y)

        # Velocity
        y_dot[0], y_dot[1], y_dot[2] = y[3], y[4], y[5]

        # Acceleration
        y_dot[3], y_dot[4], y_dot[5] = acceleration.value(data=data_der)

        return y_dot
Example #4
0
 def engine() -> Vector:
     return Vector(x=0, y=0, z=0)
Example #5
0
 def normalForce() -> Vector:
     return Vector(x=0, y=0, z=0)
Example #6
0
 def launchRail() -> Vector:
     return Vector(x=0, y=0, z=0)
Example #7
0
 def drag() -> Vector:
     return Vector(x=0, y=0, z=0)
Example #8
0
 def updateVelocity(self, x: float, y: float, z: float):
     self.velocity = Vector(x=x, y=y, z=z)
Example #9
0
# Solve
from core.modules.simulation.solve import solve

# Models
from core.utils.math.models.vector_model import Vector
from core.modules.simulation.models.input_model import Input, Forces, InitialCondition
import forces

# Rocket
import rocket

####################################################################################################
# Inputs
inputs = Input(
    # Forces
    forces=Forces(weight=forces.weight,
                  thrust=forces.thrust,
                  drag=forces.drag,
                  parachute_drag=forces.parachute_drag),
    # Initial Conditions
    initial_condition=InitialCondition(velocity=Vector(x=0, y=0, z=0),
                                       position=Vector(x=0, y=0, z=0),
                                       atitude=Vector(x=0, y=0, z=1)),
    # Rocket
    rocket=rocket.getRocket(),
    # Launch Rail Length
    launch_rail_length=10)

# Solve
solve(y0=inputs)
Example #10
0
def value(mach: float, altitude: float, time: float,
          atitude: Vector) -> Vector:
    return atitude.unary().multiply(scalar=booster(time=time) +
                                    turbojet(mach=mach, altitude=altitude))
Example #11
0
def value(rho: float, area: float, velocity: Vector, cd: float) -> Vector:
    return velocity.unary().multiply(scalar=- 0.5 * rho * (velocity.norm() ** 2) * area * cd)
Example #12
0
 def insertVelocity(self, x: float, y: float, z: float):
     self.velocity.append(Vector(x=x, y=y, z=z))
Example #13
0
 def insertPosition(self, x: float, y: float, z: float):
     self.position.append(Vector(x=x, y=y, z=z))
Example #14
0
def solve(y0: Input):

    # Derivative equations
    # Inputs
    # t: time
    # y: [
    #       position_x,
    #       position_y,
    #       position_z,
    #       velocity_x,
    #       velocity_y,
    #       velocity_z
    # ]
    def derivative(t, y) -> List[float]:  # t: float, y: List[float]

        # Create data model
        data_der = Data(position=Vector(x=y[0], y=y[1], z=y[2]), velocity=Vector(x=y[3], y=y[4], z=y[5]), time=t)

        y_dot = [0] * len(y)

        # Velocity
        y_dot[0], y_dot[1], y_dot[2] = y[3], y[4], y[5]

        # Acceleration
        y_dot[3], y_dot[4], y_dot[5] = acceleration.value(data=data_der)

        return y_dot

    print('\n01 - Simulation Initialized\n')

    # Initial simulation time
    start_time = time()

    # Create class
    acceleration = Acceleration(inputs=y0)

    # Initial conditions
    output = OutputModel(
        position=[y0.initial_condition.position],
        velocity=[y0.initial_condition.position],
        time=[0.0],
    )

    # Solve
    solution = ode.RK45(derivative, t0=0.0, y0=y0.initial_condition.toList(), t_bound=MAX_SIMULATION_TIME, max_step=MAX_TIME_STEP)
    print_data = 0
    data = Data(position=Vector(x=0.0, y=0.0, z=0.0), velocity=Vector(x=0.0, y=0.0, z=0.0), time=0.0)
    printHeader()
    while True:
        solution.step()
        output.insertFromList(t=solution.t, y=solution.y)
        if output.position[len(output.position) - 1].z <= 0.0:
            data.updateFromList(t=solution.t, y=solution.y)
            printData(data=data)
            break
        if solution.t - print_data >= PRINT_INTERVAL or print_data == 0:
            print_data = solution.t + PRINT_INTERVAL
            data.updateFromList(t=solution.t, y=solution.y)
            printData(data=data)

    # End simulation time
    end_time = time()

    print('\n   Simulation ended in %.4f seconds' % (end_time - start_time))

    print('\n04 - Generating Log')

    print('\n05 - Generating Plots')
    makePlots(output=output)

    print('\n06 - Generating Report')
Example #15
0
 def weight() -> Vector:
     return Vector(x=0, y=0, z=0)
Example #16
0
 def updatePosition(self, x: float, y: float, z: float):
     self.position = Vector(x=x, y=y, z=z)
Example #17
0
 def parachute() -> Vector:
     return Vector(x=0, y=0, z=0)
Example #18
0
def value(mass: float, g: float) -> Vector:
    return Vector(x=0, y=0, z=-mass * g)