Skip to content

Commit

Permalink
137 velocity for temp (#138)
Browse files Browse the repository at this point in the history
* velocity for temp fix
* mkdocs update
* mkdocs versioning init
  • Loading branch information
o-murphy authored Jan 20, 2025
1 parent 34c6e91 commit 486874e
Show file tree
Hide file tree
Showing 25 changed files with 359 additions and 75 deletions.
2 changes: 1 addition & 1 deletion docs/api/conditions/atmo.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Atmo
::: py_ballisticcalc.conditions._conditions.Atmo
::: py_ballisticcalc.conditions.Atmo
options:
group_by_category: false
members:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/conditions/shot.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Shot
::: py_ballisticcalc.conditions._conditions.Shot
::: py_ballisticcalc.conditions.Shot
options:
group_by_category: true
members:
Expand Down
2 changes: 1 addition & 1 deletion docs/api/conditions/wind.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Wind
::: py_ballisticcalc.conditions._conditions.Wind
::: py_ballisticcalc.conditions.Wind
options:
group_by_category: false
members:
Expand Down
47 changes: 47 additions & 0 deletions docs/api/constants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
::: py_ballisticcalc.constants
options:
group_by_category: false
members:

### Global atmosphere constants

| Constant | Description | Value | Unit / Notes |
|---------------------|-------------------------------|--------------|--------------|
| `cStandardHumidity` | Relative Humidity in percents | 0.0 | % |
| `cPressureExponent` | =g*M/R*L | 5.255876 | - |
| `cA0` | Coefficient A0 | 1.24871 | - |
| `cA1` | Coefficient A1 | 0.0988438 | - |
| `cA2` | Coefficient A2 | 0.00152907 | - |
| `cA3` | Coefficient A3 | -3.07031e-06 | - |
| `cA4` | Coefficient A4 | 4.21329e-07 | - |
| `cA5` | Coefficient A5 | 3.342e-04 | - |

### [ISA, metric prefer_units](https://www.engineeringtoolbox.com/international-standard-atmosphere-d_985.html)

| Constant | Description | Value | Unit / Notes |
|----------------------------|-----------------------------------------|----------|------------------|
| `cDegreesCtoK` | Celsius to Kelvin conversion | 273.15 | °K = °C + 273.15 |
| `cStandardTemperatureC` | Standard temperature in Celsius | 15.0 | °C |
| `cLapseRateMetric` | Metric lapse rate | -6.5e-03 | °C/m |
| `cStandardPressureMetric` | Standard pressure (metric) | 1013.25 | hPa |
| `cSpeedOfSoundMetric` | Speed of sound in metric | 331.3 | m/s |
| `cStandardDensityMetric` | Standard air density (metric) | 1.2250 | kg/m³ |
| `cDensityImperialToMetric` | Density conversion (imperial to metric) | 16.0185 | lb/ft³ to kg/m³ |

### ICAO standard atmosphere

| Constant | Description | Value | Unit / Notes |
|-------------------------|------------------------------------|--------------|------------------|
| `cDegreesFtoR` | Fahrenheit to Rankine conversion | 459.67 | °R = °F + 459.67 |
| `cStandardTemperatureF` | Standard temperature in Fahrenheit | 59.0 | °F |
| `cLapseRateImperial` | Imperial lapse rate | -3.56616e-03 | °F/ft |
| `cStandardPressure` | Standard pressure (imperial) | 29.92 | InHg |
| `cSpeedOfSoundImperial` | Speed of sound (imperial) | 49.0223 | fps |
| `cStandardDensity` | Standard air density (imperial) | 0.076474 | lb/ft³ |

### Runtime limits constants

| Constant | Description | Value | Unit / Notes |
|------------------------|-----------------------------|-------|--------------|
| `cLowestTempF` | Lowest temperature recorded | -130 | °F |
| `cMaxWindDistanceFeet` | Maximum wind distance | 1e8 | ft |
4 changes: 4 additions & 0 deletions docs/api/drag_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
::: py_ballisticcalc.drag_model
options:
group_by_category: false
members:
4 changes: 4 additions & 0 deletions docs/api/trajectory_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
::: py_ballisticcalc.trajectory_data
options:
group_by_category: false
members:
4 changes: 4 additions & 0 deletions docs/api/vector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
::: py_ballisticcalc.vector.Vector
options:
group_by_category: false
members:
2 changes: 1 addition & 1 deletion docs/concepts/conditions/atmo.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
??? api "API Documentation"

[`py_ballisticcalc.conditions.Atmo`][py_ballisticcalc.conditions._conditions.Atmo]<br>
[`py_ballisticcalc.conditions.Atmo`][py_ballisticcalc.conditions.Atmo]<br>
2 changes: 1 addition & 1 deletion docs/concepts/conditions/shot.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
??? api "API Documentation"

[`py_ballisticcalc.conditions.Shot`][py_ballisticcalc.conditions._conditions.Shot]<br>
[`py_ballisticcalc.conditions.Shot`][py_ballisticcalc.conditions.Shot]<br>
2 changes: 1 addition & 1 deletion docs/concepts/conditions/wind.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
??? api "API Documentation"

[`py_ballisticcalc.conditions.Wind`][py_ballisticcalc.conditions._conditions.Wind]<br>
[`py_ballisticcalc.conditions.Wind`][py_ballisticcalc.conditions.Wind]<br>
3 changes: 3 additions & 0 deletions docs/concepts/constants.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
??? api "API Documentation"

[`py_ballisticcalc.constants`][py_ballisticcalc.constants]<br>
3 changes: 3 additions & 0 deletions docs/concepts/drag_model.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
??? api "API Documentation"

[`py_ballisticcalc.drag_model`][py_ballisticcalc.drag_model]<br>
3 changes: 3 additions & 0 deletions docs/concepts/trajectory_data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
??? api "API Documentation"

[`py_ballisticcalc.trajectory_data`][py_ballisticcalc.trajectory_data]<br>
3 changes: 3 additions & 0 deletions docs/concepts/vector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
??? api "API Documentation"

[`py_ballisticcalc.vector.Vector`][py_ballisticcalc.vector.Vector]<br>
34 changes: 34 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,56 @@ nav:
# - concepts/munition/index.md
- "🔫 Weapon": concepts/munition/weapon.md # <-- Added a dummy sub-level
- "💣 Ammo": concepts/munition/ammo.md
- DragModel: concepts/drag_model.md
- Conditions:
- "🌡️ Atmo": concepts/conditions/atmo.md
- "💨 Wind": concepts/conditions/wind.md
- "🎯 Shot": concepts/conditions/shot.md
- Units and Dimensions:
# - DSL:
- "📏 Unit": concepts/unit.md
# - AbstractUnit:
# - Distance:
# - Velocity:
# - Angular:
# - Pressure:
# - Temperature:
# - Weight:
# - Energy:
- TrajectoryData: concepts/trajectory_data.md
- Vector: concepts/vector.md
- Constants: concepts/constants.md
# - Interface:
- Engines:
- "⚙️ Engines": concepts/engines.md
# - Logger: concepts/logger.md
# - Performance:
- API Documentation:
# - Units:
# - DSL:
# - Unit:
# - AbstractUnit:
# - Distance:
# - Velocity:
# - Angular:
# - Pressure:
# - Temperature:
# - Weight:
# - Energy:
- Munition:
- Weapon: api/munition/weapon.md
- Ammo: api/munition/ammo.md
- DragModel: api/drag_model.md
- Conditions:
- Atmo: api/conditions/atmo.md
- Wind: api/conditions/wind.md
- Shot: api/conditions/shot.md
- TrajectoryData: api/trajectory_data.md
- Constants: api/constants.md
- Vector: api/vector.md
# - Interface:
# - Engines: api/engines.md
# - Logger: api/logger.md
#- Examples:
#- Error Messages:
- Internals:
Expand Down Expand Up @@ -93,6 +126,7 @@ repo_url: https://github.com/o-murphy/py_ballisticcalc
extra:
version:
provider: mike
# alias: true
analytics:
feedback:
title: Was this page helpful?
Expand Down
3 changes: 1 addition & 2 deletions py_ballisticcalc.exts/py_ballisticcalc_exts/cy_euler.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ cdef struct ShotData_t:
double stability_coefficient
Atmosphere_t atmo

cdef double cy_get_calc_step(Config_t * config, double step = ?)
cdef MachList_t cy_table_to_mach(list[object] data)
cdef Curve_t cy_calculate_curve(list[object] data_points)
cdef double cy_calculate_by_curve_and_mach_list(MachList_t *mach_list, Curve_t *curve, double mach)
Expand All @@ -73,8 +74,6 @@ cdef double cDegreesFtoR
cdef double cSpeedOfSoundImperial
cdef double cLapseRateImperial

cdef double _WIND_MAX_DISTANCE_FEET

cdef struct Wind_t:
double velocity
double direction_from
Expand Down
8 changes: 6 additions & 2 deletions py_ballisticcalc.exts/py_ballisticcalc_exts/cy_euler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ cdef Config_t config_bind(object config):
config.cMinimumAltitude,
)

cdef double cy_get_calc_step(Config_t * config, double step = 0):
cdef double preferred_step = config.max_calc_step_size_feet
if step == 0:
return preferred_step / 2.0
return min(step, preferred_step) / 2.0

cdef MachList_t cy_table_to_mach(list[object] data):
cdef int data_len = len(data)
cdef double * result = <double *> malloc(data_len * sizeof(double))
Expand Down Expand Up @@ -210,8 +216,6 @@ cdef void update_density_factor_and_mach_for_altitude(

mach[0] = sqrt(fahrenheit + cDegreesFtoR) * cSpeedOfSoundImperial

cdef double _WIND_MAX_DISTANCE_FEET = 1e8

cdef CVector wind_to_c_vector(Wind_t * w):
cdef:
# Downrange (x-axis) wind velocity component:
Expand Down
29 changes: 14 additions & 15 deletions py_ballisticcalc.exts/py_ballisticcalc_exts/trajectory_calc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ from py_ballisticcalc_exts.cy_euler cimport (
cy_update_stability_coefficient,
free_trajectory,
wind_to_c_vector,
_WIND_MAX_DISTANCE_FEET,
)

import warnings

from py_ballisticcalc.logger import logger
from py_ballisticcalc.unit import Angular, Unit, Velocity, Distance, Energy, Weight
from py_ballisticcalc.exceptions import ZeroFindingError, RangeError
from py_ballisticcalc.constants import cMaxWindDistanceFeet
from bisect import bisect_left


__all__ = (
Expand Down Expand Up @@ -135,12 +136,12 @@ cdef class _TrajectoryDataFilter:

@final
cdef class _WindSock:
cdef list[Wind_t] winds
cdef int current
cdef double next_range
# cdef Vector _last_vector_cache
cdef CVector _last_vector_cache
cdef int _length
cdef:
list[Wind_t] winds
int current
double next_range
CVector _last_vector_cache
int _length

def __cinit__(_WindSock self, object winds):
self.winds = [
Expand All @@ -152,7 +153,7 @@ cdef class _WindSock:
) for w in winds
]
self.current = 0
self.next_range = _WIND_MAX_DISTANCE_FEET
self.next_range = cMaxWindDistanceFeet
self._last_vector_cache = CVector(0.0, 0.0, 0.0)
self._length = len(self.winds)

Expand All @@ -170,14 +171,15 @@ cdef class _WindSock:
self.next_range = cur_wind.until_distance
else:
self._last_vector_cache = CVector(0.0, 0.0, 0.0)
self.next_range = _WIND_MAX_DISTANCE_FEET
self.next_range = cMaxWindDistanceFeet

cdef CVector vector_for_range(_WindSock self, double next_range):
if next_range >= self.next_range:
# if next_range + 1e-6 >= self.next_range:
self.current += 1
if self.current >= self._length:
self._last_vector_cache = CVector(0.0, 0.0, 0.0)
self.next_range = _WIND_MAX_DISTANCE_FEET
self.next_range = cMaxWindDistanceFeet
else:
self.update_cache() # This will trigger cache updates.
return self._last_vector_cache
Expand Down Expand Up @@ -249,6 +251,7 @@ cdef class TrajectoryCalc:
cant_sine=sin(shot_info.cant_angle._rad),
alt0=shot_info.atmo.altitude._feet,
calc_step=self.get_calc_step(),
# calc_step=cy_get_calc_step(self.__config),
diameter=shot_info.ammo.dm.diameter._inch,
stability_coefficient=0.0,
atmo=Atmosphere_t(
Expand All @@ -259,11 +262,7 @@ cdef class TrajectoryCalc:
density_ratio=shot_info.atmo.density_ratio,
)
)

if shot_info.ammo.use_powder_sensitivity:
self.__shot.muzzle_velocity = shot_info.ammo.get_velocity_for_temp(shot_info.atmo.powder_temp)._fps
else:
self.__shot.muzzle_velocity = shot_info.ammo.mv._fps
self.__shot.muzzle_velocity = shot_info.ammo.get_velocity_for_temp(shot_info.atmo.powder_temp)._fps
cy_update_stability_coefficient(&self.__shot)

self.ws = _WindSock(shot_info.winds)
Expand Down
2 changes: 1 addition & 1 deletion py_ballisticcalc.exts/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "py_ballisticcalc.exts"
version = "2.1.0b2"
version = "2.1.0b3"

authors = [
{ name="o-murphy", email="[email protected]" },
Expand Down
Loading

0 comments on commit 486874e

Please sign in to comment.