Repository navigation
Commit d21abde
ENH: StochasticFreeFormFins for Monte Carlo simulations (#1117)
* BUG: accept a deterministic aerodynamic surface in StochasticRocket
`_add_surfaces` wrapped a plain surface with `stochastic_type(component=...)`,
but none of the stochastic aero-surface classes take a `component` keyword:
each names its first parameter after its own surface (`nosecone`, `tail`,
`trapezoidal_fins`, ...). Passing anything other than an already-stochastic
surface to `add_nose`, `add_trapezoidal_fins`, `add_elliptical_fins` or
`add_tail` therefore raised a TypeError, even though all four document the
deterministic type as accepted.
Passed positionally instead, which reaches every class regardless of what it
calls that parameter.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* ENH: StochasticFreeFormFins for Monte Carlo simulations
Closes #953. Free-form fin sets were the only aerodynamic surface without a
stochastic counterpart, so a rocket using them could not be varied in a Monte
Carlo run.
`shape_points` does not fit the one-number-per-input assumption the base class
makes, and a fin shape is only meaningful as a complete set of points, so the
outline is randomized as a block: one sampled deviation applied to every
coordinate. Two formats needed handling before reaching the base class, both of
them the natural thing to write:
- a bare outline is a `list`, which the base class reads as a list of candidate
values and would have sampled a single (x, y) point from. It is wrapped as the
one candidate outline it is, and a list of outlines still means a choice
between shapes.
- `(nominal outline, standard deviation)` has a list where `_validate_tuple`
requires a number. Only that first item is special-cased; the deviation and
the distribution name still go through the base class, so the distribution is
drawn from this model's generator like every other input.
An outline that cannot mean a fin shape - empty, ragged, fewer than three
points, three-dimensional - now fails during validation rather than reaching
FreeFormFins.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* BUG: seed the choice between the candidate values of a list input
`dict_generator` and `StochasticRocket._randomize_position` picked from a
list with `random.choice`, which draws from the interpreter-wide stream.
`_set_stochastic` only rebuilds the model's own numpy generator, so that
stream was never reseeded: a fixed-seed run did not reproduce the values
chosen from a list, and Monte Carlo workers forked from one process
inherited a single `random` state and walked the same choice sequence
instead of sampling independently.
The choice now comes from a generator of the model's own, derived from the
same seed through `_sampler_seed` but kept apart from the one the
distributions draw from, so that declaring a list input does not shift the
numbers every other input gets and existing fixed-seed baselines that use
no list input stay where they are.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* MNT: let a stochastic input hold an array as its nominal value
`StochasticFreeFormFins` needed a whole fin outline where the base class
reads a single number, and got there by overriding `_validate_tuple`,
comparing the input name against the literal `"shape_points"` and
smuggling a `0.0` placeholder through `super()`. The rest of the machinery
was never told, so `_validate_scalar`, `dict_generator` and
`visualize_attributes` all still believed the value was a number: the
public `visualize_attributes` raised a `TypeError` formatting an outline
with `:.5f`, and the next array-valued input would have had to rediscover
the same workaround.
`array_valued_inputs` declares those inputs by name on the class instead,
so validation, sampling and the report agree on which ones they are.
`_nominal_value` converts them where the nominal value is looked up, and
the report prints the array's shape rather than trying to format its
coordinates as one number.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* BUG: fix which shape_points StochasticFreeFormFins accepts and rejects
The `shape_points` contract did not hold up to the formats the docstring
and the user guide advertise:
- `_is_outline` caught only `IndexError`, but `np.shape` raises a
`ValueError` on a ragged sequence. A list of candidate outlines with
different numbers of points -- choosing between a three-point and a
four-point fin, the plainest form of choosing between shapes -- died
with an opaque numpy error, and a ragged outline did not fail during
validation as claimed. Each candidate is now converted on its own.
- Every distribution name was accepted, but the deviation is applied as
`dist_func(nominal_outline, std_dev)`, so only the ones that read the
first argument as the centre of the draw can work. `uniform` read the
outline as its lower bound and `wald` rejected the zeros of a root
point, both raising in the middle of a Monte Carlo run. The four that
can are accepted and the rest are rejected up front.
- An outline of non-numbers passed validation and died inside
`_FreeFormGeometry.infer_dimensions`; a numpy array was rejected even
though `create_object` produces one and `FreeFormFins` takes one; and
`shape_points=[]` raised where an empty list means "use the nominal
value" for every other input.
The fin root is also held on the body line now. `FreeFormFins` measures
the span from y = 0 and slices the chords over that interval, so
perturbing every y drove most samples off the line -- 227 of 300 outlines
had a point inside the airframe -- and the interference factors were
computed from the inflated span that followed. Points nominally on the
line stay there and none is allowed to cross it, which is what the root
edge of a fin does anyway.
The docstring and the user guide said a single outline "must be wrapped in
a list" while the code auto-detects a bare one, and that one deviation is
shared by every coordinate while each is in fact drawn on its own. Both
now describe what the code does.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent a4a61c6 commit d21abde
14 files changed
Lines changed: 933 additions & 18 deletions
File tree
- docs
- reference/classes/monte_carlo/stochastic_models
- user
- rocketpy
- stochastic
- tests
- fixtures/monte_carlo
- integration/simulation
- unit/stochastic
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
48 | 49 | | |
49 | 50 | | |
50 | 51 | | |
| 52 | + | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
| 56 | + | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
96 | 133 | | |
97 | 134 | | |
98 | 135 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
0 commit comments