From 17cc783133a78749e557f87b42638f9ba7cc39b1 Mon Sep 17 00:00:00 2001 From: Nathan Baltzell Date: Wed, 4 Nov 2026 17:14:30 -0500 Subject: [PATCH 1/2] Revert "use a pool of RK4Vec (#1523)" This reverts commit 79013412c97f2e584e17624da9f6b8850ff2178b. --- .../tracking/utilities/RungeKuttaDoca.java | 79 ++++--------------- 1 file changed, 16 insertions(+), 63 deletions(-) diff --git a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/RungeKuttaDoca.java b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/RungeKuttaDoca.java index 26b60a5785..47129534df 100644 --- a/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/RungeKuttaDoca.java +++ b/common-tools/clas-tracking/src/main/java/org/jlab/clas/tracking/utilities/RungeKuttaDoca.java @@ -1,6 +1,5 @@ package org.jlab.clas.tracking.utilities; -import java.util.concurrent.ConcurrentLinkedQueue; import org.jlab.clas.pdg.PhysicsConstants; import org.jlab.jnp.matrix.*; import org.jlab.clas.swimtools.Swim; @@ -24,11 +23,12 @@ public void SwimToZ(int sector, StateVec vec, Swim swim, double z0, float[] bf) swim.Bfield(sector, vec.x, vec.y, vec.z, bf); vec.B = Math.sqrt(bf[0]*bf[0] + bf[1]*bf[1] + bf[2]*bf[2]); + double s = vec.B; final double travelSign = Math.signum(z0 - vec.z); double BatMeas = 0; while(travelSign * vec.z < travelSign * z0) { - double s = travelSign * stepSize; + s = travelSign * stepSize; if (travelSign*(vec.z+s) > travelSign*z0) s = travelSign*Math.abs(z0-vec.z); this.RK4transport(sector, s, swim, vec); @@ -82,8 +82,8 @@ private double[] RK4step(int sector, double z0, double h, Swim swim, double[] sI public void RK4transport(int sector, double h, Swim swim, Matrix cMat, StateVec vec) { // Set initial state and Jacobian. double qv = vec.Q*v; - RK4Vec s0 = RK4VEC_POOL.poll(vec); - RK4Vec sNull = RK4VEC_POOL.poll(); + RK4Vec s0 = new RK4Vec(vec); + RK4Vec sNull = new RK4Vec(); // Perform steps. RK4Vec s1 = RK4step(sector, vec.z, 0, swim, s0, sNull, qv); @@ -94,11 +94,6 @@ public void RK4transport(int sector, double h, Swim swim, Matrix cMat, StateVec // Compute and set final state and covariance matrix. RK4Vec sF = computeFinalState(h, s0, s1, s2, s3, s4); - RK4VEC_POOL.offer(s1); - RK4VEC_POOL.offer(s2); - RK4VEC_POOL.offer(s3); - RK4VEC_POOL.offer(s4); - vec.x = sF.x; vec.y = sF.y; vec.tx = sF.tx; @@ -107,17 +102,12 @@ public void RK4transport(int sector, double h, Swim swim, Matrix cMat, StateVec vec.B = Math.sqrt(_b[0]*_b[0]+_b[1]*_b[1]+_b[2]*_b[2]); vec.deltaPath += Math.sqrt((s0.x-vec.x)*(s0.x-vec.x) + (s0.y-vec.y)*(s0.y-vec.y) + h*h); vec.CM.set(computeCovMat(cMat, sF)); - - RK4VEC_POOL.offer(sF); - - RK4VEC_POOL.offer(s0); - RK4VEC_POOL.offer(sNull); } /** Perform one RK4 step, updating the covariance matrix. */ private RK4Vec RK4step(int sector, double z0, double h, Swim swim, RK4Vec sInit, RK4Vec sPrev, double qv) { - RK4Vec sNext = RK4VEC_POOL.poll(); + RK4Vec sNext = new RK4Vec(); swim.Bfield(sector, sInit.x + h*sPrev.x, sInit.y + h*sPrev.y, z0 + h, _b); // State. @@ -158,7 +148,7 @@ private RK4Vec RK4step(int sector, double z0, double h, Swim swim, /** Compute the final state for each entry in the internal state matrix. */ private RK4Vec computeFinalState(double h, RK4Vec s0, RK4Vec s1, RK4Vec s2, RK4Vec s3, RK4Vec s4) { - RK4Vec sF = RK4VEC_POOL.poll(); + RK4Vec sF = new RK4Vec(); sF.x = s0.x + this.RK4(s1.x, s2.x, s3.x, s4.x, h); sF.dxdtx0 = this.RK4(s1.dxdtx0, s2.dxdtx0, s3.dxdtx0, s4.dxdtx0, h); @@ -339,34 +329,8 @@ private double dty_dq0(double qv, double Ay, double dAy_dtx, double dAy_dty, return v*Ay + qv * (dAy_dtx*dtx_dq0 + dAy_dty*dty_dq0); } - static class RK4VecPool extends ConcurrentLinkedQueue { - public RK4VecPool(int size) { - super(); - for (int i=0; i Date: Wed, 4 Nov 2026 17:19:44 -0500 Subject: [PATCH 2/2] Revert "use a pool for rk4 state parameters (#1526)" This reverts commit fa7b22b8f89e75bd253f5317679b8b3c3e4116c0. --- .../src/main/java/cnuphys/rk4/RungeKutta.java | 59 ++++--------------- 1 file changed, 12 insertions(+), 47 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 f362f412b2..667a48473f 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,7 +2,6 @@ import java.util.ArrayDeque; import java.util.List; -import java.util.concurrent.ConcurrentLinkedQueue; /** * Static methods for Runge-Kutta 4 integration, including a constant stepsize @@ -1063,42 +1062,6 @@ 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