From 2d40b724805f0e7f38b2000805896a38742df713 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Sun, 25 Oct 2026 18:49:12 -0400 Subject: [PATCH] use a pool for rk4 state parameters --- .../src/main/java/cnuphys/rk4/RungeKutta.java | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java index 667a48473f..f362f412b2 100644 --- a/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java +++ b/common-tools/cnuphys/swimmer/src/main/java/cnuphys/rk4/RungeKutta.java @@ -2,6 +2,7 @@ import java.util.ArrayDeque; import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; /** * Static methods for Runge-Kutta 4 integration, including a constant stepsize @@ -1062,6 +1063,42 @@ private int driver(double yo[], // A uniform step size advancer class UniformAdvance implements IAdvance { + static class State { + double k2[]; + double k3[]; + double k4[]; + double ytemp[]; + State(int dim) { + k2 = new double[dim]; + k3 = new double[dim]; + k4 = new double[dim]; + ytemp = new double[dim]; + } + State reset() { + for (int i=0; i { + StatePool(int size, int dim) { + for (int i=0; i