-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create aerospace_dynamics_simulator.py
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import numpy as np | ||
from scipy.integrate import odeint | ||
|
||
class AerospaceDynamicsSimulator: | ||
def __init__(self, vehicle_mass, vehicle_size, atmospheric_conditions): | ||
self.vehicle_mass = vehicle_mass | ||
self.vehicle_size = vehicle_size | ||
self.atmospheric_conditions = atmospheric_conditions | ||
|
||
def simulate(self, time_step, total_time): | ||
# Define the equations of motion | ||
def equations_of_motion(state, t): | ||
# Calculate forces and moments | ||
forces = self.calculate_forces(state) | ||
moments = self.calculate_moments(state) | ||
|
||
# Update state variables | ||
state_dot = np.array([ | ||
state[1], | ||
forces / self.vehicle_mass, | ||
state[3], | ||
moments / self.vehicle_mass | ||
]) | ||
|
||
return state_dot | ||
|
||
# Initialize state variables | ||
state0 = np.array([0, 0, 0, 0]) | ||
|
||
# Simulate the dynamics | ||
state = odeint(equations_of_motion, state0, np.arange(0, total_time, time_step)) | ||
|
||
return state | ||
|
||
def calculate_forces(self, state): | ||
# Calculate aerodynamic forces | ||
aerodynamic_forces = self.calculate_aerodynamic_forces(state) | ||
|
||
# Calculate gravitational forces | ||
gravitational_forces = self.calculate_gravitational_forces(state) | ||
|
||
return aerodynamic_forces + gravitational_forces | ||
|
||
def calculate_moments(self, state): | ||
# Calculate aerodynamic moments | ||
aerodynamic_moments = self.calculate_aerodynamic_moments(state) | ||
|
||
return aerodynamic_moments | ||
|
||
def calculate_aerodynamic_forces(self, state): | ||
# Calculate air density | ||
air_density = self.atmospheric_conditions.air_density(state[2]) | ||
|
||
# Calculate aerodynamic coefficients | ||
aerodynamic_coefficients = self.vehicle_size.aerodynamic_coefficients(state[1]) | ||
|
||
# Calculate aerodynamic forces | ||
aerodynamic_forces = 0.5 * air_density * aerodynamic_coefficients * state[1]**2 | ||
|
||
return aerodynamic_forces | ||
|
||
def calculate_gravitational_forces(self, state): | ||
# Calculate gravitational acceleration | ||
gravitational_acceleration = self.atmospheric_conditions.gravitational_acceleration(state[2]) | ||
|
||
# Calculate gravitational forces | ||
gravitational_forces = self.vehicle_mass * gravitational_acceleration | ||
|
||
return gravitational_forces | ||
|
||
def calculate_aerodynamic_moments(self, state): | ||
# Calculate air density | ||
air_density = self.atmospheric_conditions.air_density(state[2]) | ||
|
||
# Calculate aerodynamic coefficients | ||
aerodynamic_coefficients = self.vehicle_size.aerodynamic_coefficients(state[1]) | ||
|
||
# Calculate aerodynamic moments | ||
aerodynamic_moments = 0.5 * air_density * aerodynamic_coefficients * state[1]**2 * self.vehicle_size.length | ||
|
||
return aerodynamic_moments |