Skip to content

Commit

Permalink
Merge remote-tracking branch 'antonio-origin/porkchop_and_hybrid_modu…
Browse files Browse the repository at this point in the history
…les' into feature/porkchop_and_hybrid_modules
  • Loading branch information
DominicDirkx committed Oct 14, 2023
2 parents ae94de7 + 26ddfc4 commit 14ff2d0
Show file tree
Hide file tree
Showing 9 changed files with 1,102 additions and 4 deletions.
3 changes: 1 addition & 2 deletions docs/environment_readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
name: tudatpy-docs-readthedocs
channels:
- conda-forge
#- tudat-team/label/dev
- tudat-team
#- tudat-team
dependencies:
# All standard tudat-bundle deps are needed for sphinx-documentation for tudatpy.
- python=3.8
Expand Down
42 changes: 41 additions & 1 deletion tudatpy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,57 @@ install(TARGETS kernel
install(FILES ${TUDATPY_PYTHON_FILES} "${CMAKE_CURRENT_BINARY_DIR}/_version.py"
DESTINATION ${TUDATPY_INSTALL_PATH})

# Install the Python modules.
macro(INSTALL_PURE_PYTHON_MODULE_DIR module_dir_name)
install(DIRECTORY ${module_dir_name}/ DESTINATION "${TUDATPY_INSTALL_PATH}/${module_dir_name}")
file(COPY ${module_dir_name}/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${module_dir_name}/)
endmacro()

INSTALL_PURE_PYTHON_MODULE_DIR(apps)
INSTALL_PURE_PYTHON_MODULE_DIR(bodies)
INSTALL_PURE_PYTHON_MODULE_DIR(plotting)
INSTALL_PURE_PYTHON_MODULE_DIR(util)
INSTALL_PURE_PYTHON_MODULE_DIR(io)

# Install the Python components of kernel modules
macro(INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE module_dir_name)
install(DIRECTORY kernel_hybrid/${module_dir_name}/ DESTINATION "${TUDATPY_INSTALL_PATH}/${module_dir_name}")
file(COPY kernel_hybrid/${module_dir_name}/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${module_dir_name}/)
endmacro()
# INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(utils)
#INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(astro)
INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(trajectory_design)
#INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(constants)
#INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(interface)
# INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(io)
#INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(math)
#INSTALL_PYTHON_COMPONENTS_OF_HYBRID_MODULE(numerical_simulation)

# Expose hybrid C++/Python modules
file(COPY ${CMAKE_CURRENT_LIST_DIR}/setup_hybrid_modules.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../)
macro(EXPOSE_HYBRID_MODULES)
foreach(module ${ARGN})
# Might be more robust to use a combination of
# - add_custom_command
# - add_custom_target
# - add_dependencies
# See: https://stackoverflow.com/a/44225986
add_custom_command(TARGET kernel POST_BUILD
COMMAND ${PYTHON_EXECUTABLE} setup_hybrid_modules.py ${module}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/kernel.so)
endforeach()
endmacro()
EXPOSE_HYBRID_MODULES(
# utils
astro
trajectory_design
constants
interface
# io
math
numerical_simulation
)

#install(FILES test.py "${CMAKE_CURRENT_BINARY_DIR}/_version.py")
file(COPY ../tests DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/../)

Expand Down
4 changes: 3 additions & 1 deletion tudatpy/kernel/expose_math/expose_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ void expose_geometry(py::module &m) {
py::arg("rear_angle"),
py::arg("side_radius") )
.def_property_readonly("middle_radius", &tgs::Capsule::getMiddleRadius)
.def_property_readonly("volume", &tgs::Capsule::getVolume);
.def_property_readonly("volume", &tgs::Capsule::getVolume)
.def_property_readonly("length", &tgs::Capsule::getLength);



};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ void expose_propagation(py::module &m)
tpr::ThrustMagnitudeWrapper >(m, "ConstantThrustMagnitudeWrapper" )
.def_property("constant_thrust_magnitude", &tpr::ConstantThrustMagnitudeWrapper::getConstantThrustForceMagnitude,
&tpr::ConstantThrustMagnitudeWrapper::resetConstantThrustForceMagnitude );


py::class_<
tpr::CustomThrustMagnitudeWrapper,
std::shared_ptr< tpr::CustomThrustMagnitudeWrapper >,
tpr::ThrustMagnitudeWrapper >(m, "CustomThrustMagnitudeWrapper" )
.def_property("custom_thrust_magnitude", nullptr,
&tpr::CustomThrustMagnitudeWrapper::resetThrustMagnitudeFunction );
}
}// namespace propagation
}// namespace numerical_simulation
Expand Down
5 changes: 5 additions & 0 deletions tudatpy/kernel_hybrid/trajectory_design/porkchop/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
Tudat Porkchop Tool
"""
from tudatpy.trajectory_design.porkchop.porkchop import porkchop
from tudatpy.trajectory_design.porkchop._plot_porkchop import plot_porkchop
99 changes: 99 additions & 0 deletions tudatpy/kernel_hybrid/trajectory_design/porkchop/_lambert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'''
Copyright (c) 2010-2020, Delft University of Technology
All rigths reserved
This file is part of the Tudat. Redistribution and use in source and
binary forms, with or without modification, are permitted exclusively
under the terms of the Modified BSD license. You should have received
a copy of the license with this file. If not, please or visit:
http://tudat.tudelft.nl/LICENSE.
'''

# General imports
import numpy as np

# Tudat imports
from tudatpy.kernel.astro import two_body_dynamics
from tudatpy.kernel.interface import spice_interface
from tudatpy.kernel.numerical_simulation import environment


def calculate_lambert_arc_impulsive_delta_v(
bodies: environment.SystemOfBodies,
global_frame_orientation: str,
departure_body: str,
target_body: str,
departure_epoch: int,
arrival_epoch: int,
central_body: str = 'Sun' ) -> tuple[float]:

""""
This function solved Lambert's problem for a transfer from the `departure_body` (at departure epoch)
to a `target_body` (at arrival epoch), with the states of the `departure_body` and the `target_body`
defined by ephemerides stored inside the `bodies` (`SystemOfBodies` instance). Note that this solver
assumes that the transfer departs/arrives to/from the center of mass of the departure and the target body.
Parameters
----------
bodies: environment.SystemOfBodies
Body objects defining the physical simulation environment
global_frame_orientation: str
Orientation of the global reference frame at J2000
departure_body: str
The name of the body from which the transfer is to be computed
target_body: str
The name of the body to which the transfer is to be computed
departure_epoch: int
Epoch at which the departure from the `target_body`'s center of mass is to take place
arrival_epoch: int
Epoch at which the arrival at he target body's center of mass is to take place
Output
------
ΔV_launch: float
ΔV required for insertion into the Lambert transfer arc
ΔV_arrival: float
ΔV required for capture by the arrival body
"""

# Gravitational parameter of the Sun
central_body_gravitational_parameter = bodies.get_body(central_body).gravitational_parameter

# Retrieve states of departure and arrival body
initial_state = spice_interface.get_body_cartesian_state_at_epoch(
target_body_name = departure_body,
observer_body_name = central_body,
reference_frame_name = global_frame_orientation,
aberration_corrections = "NONE",
ephemeris_time = departure_epoch)
final_state = spice_interface.get_body_cartesian_state_at_epoch(
target_body_name = target_body,
observer_body_name = central_body,
reference_frame_name = global_frame_orientation,
aberration_corrections = "NONE",
ephemeris_time = arrival_epoch)

# Retrieve initial and final positions for Lambert targeter
departure_position = initial_state[:3]
arrival_position = final_state[:3]

# Create Lambert targeter
lambertTargeter = two_body_dynamics.LambertTargeterIzzo(
departure_position,
arrival_position,
arrival_epoch - departure_epoch,
central_body_gravitational_parameter)

# Obtain initial and final states
departure_velocity = lambertTargeter.get_departure_velocity()
arrival_velocity = lambertTargeter.get_arrival_velocity()

# Retrieve initial and insertion velocities to calculate ΔV
initial_velocity = initial_state[3:]
insertion_velocity = final_state[3:]

# Calculate ΔV
ΔV_launch = np.linalg.norm(departure_velocity - initial_velocity)
ΔV_arrival = np.linalg.norm(arrival_velocity - insertion_velocity)

return ΔV_launch, ΔV_arrival
Loading

0 comments on commit 14ff2d0

Please sign in to comment.