Commit e362cbc
committed
perf(BMT): recover the primal tendency from the Rosenbrock Jacobian pass
ForwardDiff's Jacobian pass already evaluates the primal tendency f as the dual
.value and discards it, so a separate f = g(x) repeats a full (quadrature-
dominated) tendency evaluation. Recover f from the same pass: seed all N
partials of the state in a single call to g with static Duals, and read the
values and partials directly into the same FieldVector species type as x
(MicroState1M or MicroState2MP3). Applies to the 2M+P3 and the 1M
ExactJacobian paths; the analytic Donor/CoupledDonor 1M Jacobians (no f
by-product) keep their separate evaluation.
The DiffResults dependency is dropped: DiffResults.JacobianResult's mutable
result buffer heap-allocates on GPU, so the seeding is done directly with
StaticArrays instead. Both paths go through the shared
_tendency_and_jacobian(jacobian, g, x) method, removing the duplicated code
in the 2M+P3 substep loop.
Measured on MicroState2MP3 (N=8, quadrature-dominated) and MicroState1M
(N=4): the single full-width call is ~31% faster than the previous two-call
f = g(x); J = FD.jacobian(g, x) for 2M+P3, and ~39% faster for 1M, with zero
allocations in both cases. f and J are bitwise identical to the two-call
reference across representative states. The tendency and Jacobian are
unchanged, the path stays type-stable, and it composes with an outer AD pass.1 parent 1c96cf0 commit e362cbc
1 file changed
Lines changed: 33 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
438 | 438 | | |
439 | 439 | | |
440 | 440 | | |
441 | | - | |
442 | 441 | | |
443 | 442 | | |
444 | | - | |
| 443 | + | |
| 444 | + | |
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
| |||
451 | 451 | | |
452 | 452 | | |
453 | 453 | | |
| 454 | + | |
454 | 455 | | |
455 | 456 | | |
456 | 457 | | |
| |||
756 | 757 | | |
757 | 758 | | |
758 | 759 | | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
759 | 787 | | |
760 | 788 | | |
761 | 789 | | |
| |||
784 | 812 | | |
785 | 813 | | |
786 | 814 | | |
787 | | - | |
788 | 815 | | |
789 | 816 | | |
790 | 817 | | |
791 | 818 | | |
792 | 819 | | |
793 | 820 | | |
794 | 821 | | |
795 | | - | |
796 | 822 | | |
797 | 823 | | |
798 | | - | |
| 824 | + | |
| 825 | + | |
799 | 826 | | |
800 | 827 | | |
801 | 828 | | |
| |||
805 | 832 | | |
806 | 833 | | |
807 | 834 | | |
| 835 | + | |
808 | 836 | | |
809 | 837 | | |
810 | 838 | | |
| |||
0 commit comments