Utils¶
flapjax.utils ¶
data_structures ¶
ConvergenceStatus ¶
ConvergenceStatus(
convergence_settings: ConvergenceSettings,
)
Object to track convergence status of an iterative solver based on absolute and relative tolerances. Absolute convergence is measured for the delta vector, while relative convergence is measured as the ratio of the maximum element in the delta vector to the total vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
convergence_settings
|
ConvergenceSettings
|
Convergence settings object containing tolerances and maximum iteration count for convergence failure. |
required |
Source code in src/flapjax/utils/data_structures.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
update ¶
update(
delta_disp: Array | None,
total_disp: Array | None,
delta_force: Array | None,
total_force: Array | None,
) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
delta_disp
|
Array | None
|
Difference in displacement vector between current and previous iteration. |
required |
total_disp
|
Array | None
|
Total displacement for time step, used for relative convergence calculation, typically the current solution vector. |
required |
delta_force
|
Array | None
|
Residual force vector, used for force convergence calculation. |
required |
total_force
|
Array | None
|
Total force vector for time step, used for relative convergence calculation. |
required |
Source code in src/flapjax/utils/data_structures.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 | |
get_status ¶
get_status() -> Array
Get overall convergence status.
Source code in src/flapjax/utils/data_structures.py
153 154 155 | |
reset_status ¶
reset_status() -> None
Reset convergence status for next load step, setting all convergence flags to False.
Source code in src/flapjax/utils/data_structures.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
print_struct_message ¶
print_struct_message(
i_ts: int | None, t: Array | None, i_load_step: int
) -> None
Print convergence message for structure based on status.
Source code in src/flapjax/utils/data_structures.py
209 210 211 212 213 | |
print_fsi_message ¶
print_fsi_message(
i_ts: int | None, t: Array | None
) -> None
Print convergence message for FSI based on status.
Source code in src/flapjax/utils/data_structures.py
215 216 217 | |
linear ¶
LinearModel ¶
LinearModel(reference: R, dt: float | Array)
Bases: ABC
Base class to represent a linearised system.
Source code in src/flapjax/utils/linear.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
unpack_state_vector ¶
unpack_state_vector(x: Array) -> S
Unpack a state vector into its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Array
|
State vector, |
required |
Returns:
| Type | Description |
|---|---|
S
|
StateUnflattened object. |
Source code in src/flapjax/utils/linear.py
286 287 288 289 290 291 292 | |
unpack_output_vector ¶
unpack_output_vector(y: Array) -> O
Unpack an output vector into its components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
Array
|
Output vector, |
required |
Returns:
| Type | Description |
|---|---|
O
|
OutputUnflattened object. |
Source code in src/flapjax/utils/linear.py
294 295 296 297 298 299 300 | |
pack_input_vector ¶
pack_input_vector(u_input: InputUnflattened) -> Array
Pack an input unflattened object into a vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_input
|
InputUnflattened
|
InputUnflattened object. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Input vector, |
Source code in src/flapjax/utils/linear.py
362 363 364 365 366 367 368 369 370 371 372 | |
pack_state_vector ¶
pack_state_vector(x_state: StateUnflattened) -> Array
Pack a state unflattened object into a vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_state
|
StateUnflattened
|
StateUnflattened object. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
State vector, |
Source code in src/flapjax/utils/linear.py
374 375 376 377 378 379 380 381 382 383 384 | |
pack_output_vector ¶
pack_output_vector(y_output: OutputUnflattened) -> Array
Pack an output unflattened object into a vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_output
|
OutputUnflattened
|
OutputUnflattened object. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Output vector, |
Source code in src/flapjax/utils/linear.py
386 387 388 389 390 391 392 393 394 395 396 | |
get_total_input ¶
get_total_input(u: InputUnflattened) -> InputUnflattened
Get the total input by adding the reference to the input perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
InputUnflattened
|
InputUnflattened perturbation object. |
required |
Returns:
| Type | Description |
|---|---|
InputUnflattened
|
InputUnflattened total object. |
Source code in src/flapjax/utils/linear.py
522 523 524 525 526 527 528 529 530 531 532 | |
get_total_state ¶
get_total_state(x: StateUnflattened) -> StateUnflattened
Get the total state by adding the reference to the state perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
StateUnflattened
|
StateUnflattened perturbation object. |
required |
Returns:
| Type | Description |
|---|---|
StateUnflattened
|
StateUnflattened total object. |
Source code in src/flapjax/utils/linear.py
534 535 536 537 538 539 540 541 542 543 544 | |
get_total_output ¶
get_total_output(y: OutputUnflattened) -> OutputUnflattened
Get the total output by adding the reference to the output perturbation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
OutputUnflattened
|
OutputUnflattened perturbation object. |
required |
Returns:
| Type | Description |
|---|---|
OutputUnflattened
|
OutputUnflattened total object. |
Source code in src/flapjax/utils/linear.py
546 547 548 549 550 551 552 553 554 555 556 | |
get_total_input_t ¶
get_total_input_t(
u_t: InputUnflattened,
) -> InputUnflattened
Get the total input time history by adding the reference to the input perturbation time history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u_t
|
InputUnflattened
|
InputUnflattened perturbation time history object. |
required |
Returns:
| Type | Description |
|---|---|
InputUnflattened
|
InputUnflattened total time history object. |
Source code in src/flapjax/utils/linear.py
558 559 560 561 562 563 564 565 566 567 568 569 570 | |
get_total_state_t ¶
get_total_state_t(
x_t: StateUnflattened,
) -> StateUnflattened
Get the total state time history by adding the reference to the state perturbation time history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_t
|
StateUnflattened
|
StateUnflattened perturbation time history object. |
required |
Returns:
| Type | Description |
|---|---|
StateUnflattened
|
StateUnflattened total time history object. |
Source code in src/flapjax/utils/linear.py
572 573 574 575 576 577 578 579 580 581 582 583 584 | |
get_total_output_t ¶
get_total_output_t(
y_t: OutputUnflattened,
) -> OutputUnflattened
Get the total output time history by adding the reference to the output perturbation time history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y_t
|
OutputUnflattened
|
OutputUnflattened perturbation time history object. |
required |
Returns:
| Type | Description |
|---|---|
OutputUnflattened
|
OutputUnflattened total time history object. |
Source code in src/flapjax/utils/linear.py
586 587 588 589 590 591 592 593 594 595 596 597 598 | |
get_zero_input ¶
get_zero_input() -> InputUnflattened
Get a zero input unflattened object.
Returns:
| Type | Description |
|---|---|
InputUnflattened
|
InputUnflattened object with zero arrays. |
Source code in src/flapjax/utils/linear.py
627 628 629 630 631 632 | |
get_zero_state ¶
get_zero_state() -> StateUnflattened
Get a zero state unflattened object.
Returns:
| Type | Description |
|---|---|
StateUnflattened
|
StateUnflattened object with zero arrays. |
Source code in src/flapjax/utils/linear.py
634 635 636 637 638 639 | |
get_zero_output ¶
get_zero_output() -> OutputUnflattened
Get a zero output unflattened object.
Returns:
| Type | Description |
|---|---|
OutputUnflattened
|
OutputUnflattened object with zero arrays. |
Source code in src/flapjax/utils/linear.py
641 642 643 644 645 646 | |
LinearSystem ¶
LinearSystem(
a: Array,
b: Array,
c: Array,
d: Array,
dt: float | Array,
continuous_time: bool = False,
removed_u_np1: bool = False,
)
Linear system represented in state-space form, with tools for time-stepping
Initialise the LinearSystem with state-space linear operators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
Array
|
System matrix A |
required |
b
|
Array
|
Input matrix B |
required |
c
|
Array
|
Output matrix C |
required |
d
|
Array
|
Feedthrough matrix D |
required |
removed_u_np1
|
bool
|
If true, indicates that the system is in terms of inputs at time step n only. |
False
|
Source code in src/flapjax/utils/linear.py
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 | |
remove_u_np1 ¶
remove_u_np1() -> None
Remove the dependence on u at time varphi+1 from the linear system, modifying b and d accordingly.
:math:D_{new} = C B + D and :math:B_{new} = A B
Source code in src/flapjax/utils/linear.py
714 715 716 717 718 719 720 721 722 723 724 | |
continuous_to_discrete ¶
continuous_to_discrete(
method: Literal["zoh", "tustin"] = "tustin",
) -> LinearSystem
Convert the continuous-time linear system to a discrete-time linear system.
Source code in src/flapjax/utils/linear.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
run ¶
run(
u: Array, x0: Array | None = None
) -> tuple[Array, Array]
Run the linear system for a time history of input vector u.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u
|
Array
|
Time history of input vectors, shape |
required |
x0
|
Array | None
|
Initial state vector, |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Array, Array]
|
State history and output history, |
Source code in src/flapjax/utils/linear.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 | |
conjugate_partner_mask ¶
conjugate_partner_mask(
freq_hz: Array, damping: Array, tiebreaker: Array
) -> Array
Return a boolean mask identifying the second member of each complex-conjugate mode pair.
Modes are first sorted by frequency, and falls back to a tiebreaker (typically the real part of the eigenvalue) as a secondary key. Each mode whose predecessor matches in frequency and |damping| is then flagged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq_hz
|
Array
|
Natural frequency of each mode |
required |
damping
|
Array
|
Damping ratio of each mode |
required |
tiebreaker
|
Array
|
Secondary sort key used to keep conjugate partners adjacent |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Boolean mask, True where the mode is the redundant partner in a conjugate pair |
Source code in src/flapjax/utils/linear.py
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 | |
print_utils ¶
get_verbosity ¶
get_verbosity() -> VerbosityLevel
Return the current verbosity level.
Source code in src/flapjax/utils/print_utils.py
45 46 47 48 49 | |
verbosity ¶
verbosity(
level: VerbosityLevel,
) -> Generator[None, None, None]
Context manager to temporarily change the verbosity level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
VerbosityLevel
|
Custom verbosity to use in context. |
required |
Source code in src/flapjax/utils/print_utils.py
52 53 54 55 56 57 58 59 60 61 62 63 | |
utils ¶
make_pytree ¶
make_pytree(cls: type[T]) -> type[T]
Register a class as a JAX pytree.
When applying to classes, define _static: ClassVar[tuple[str, ...]], listing
field names whose values are hashable / non-traced. Dynamic children are
auto-derived from vars(self) at flatten time. Instance attributes set
outside __init__ become part of the pytree structure.
Source code in src/flapjax/utils/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
dv_or ¶
dv_or(dv_val: V | None, fallback: V) -> V
Returndv_val if it is not None, otherwise return fallback. Used to collapse the
dv.x if dv.x is not None else self.x calls when combining two classes of design variables.
Source code in src/flapjax/utils/utils.py
71 72 73 74 75 76 | |
pytree_clone ¶
pytree_clone(obj: V) -> V
Cheap clone of a pytree-registered object
Source code in src/flapjax/utils/utils.py
79 80 81 82 83 84 | |
index_to_arr ¶
index_to_arr(
index: int | Array | Sequence[int] | slice | None,
n_entries: int,
) -> Array
Convert an input index to an Array index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int | Array | Sequence[int] | slice | None
|
Index to apply to a sequence |
required |
n_entries
|
int
|
Number of entries in the full un-indexed sequence |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array index corresponding to the input index |
Source code in src/flapjax/utils/utils.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |
nested_list_to_tuple ¶
nested_list_to_tuple(a: list[Any]) -> tuple[Any, ...]
Convert nested lists to nested tuples.
Source code in src/flapjax/utils/utils.py
116 117 118 119 120 121 122 123 124 125 126 127 | |
conditional_profile ¶
conditional_profile(
func: Callable[..., U],
n_loops: int | None,
func_name: str,
arg_name: str,
) -> Callable[..., tuple[U, float | None, float | None]]
Function wrapper which optionally profiles it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[..., U]
|
Function to be profiled. |
required |
n_loops
|
int | None
|
Number of times to run the function, where the average time will be taken. If None, no profiling is done. |
required |
func_name
|
str
|
Name of the function to be profiled, used for console printing. |
required |
arg_name
|
str
|
Name of the argument to be profiled, used for console printing. |
required |
Returns:
| Type | Description |
|---|---|
Callable[..., tuple[U, float | None, float | None]]
|
New function which returns the same value as |
Source code in src/flapjax/utils/utils.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |