Skip to content

Commit

Permalink
memoize parameters for two yukawa as a speedup hack
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Kienzle committed Jan 21, 2024
1 parent b689157 commit 2f5f97b
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions sasmodels/models/TY_YukawaSq.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
static double checksum = 0.0;

double Iq(
double qexp,
double radius,
Expand All @@ -8,15 +10,38 @@ double Iq(
double z2
)
{
double a;
double b;
double c1;
double c2;
double d1;
double d2;
static double a;
static double b;
static double c1;
static double c2;
static double d1;
static double d2;
static double last_radius = -2.0; // Radius is always greater than zero
static double last_volumefraction = -0.0;
static double last_k1 = 0.0;
static double last_k2 = 0.0;
static double last_z1 = 0.0;
static double last_z2 = 0.0;
int debug;
int checkFlag;

int changed = (
(last_radius != radius)
|| (last_volumefraction != volumefraction)
|| (last_k1 != k1)
|| (last_k2 != k2)
|| (last_z1 != z1)
|| (last_z2 != z2)
);
if (changed) {

last_radius = radius;
last_volumefraction = volumefraction;
last_k1 = k1;
last_k2 = k2;
last_z1 = z1;
last_z2 = z2;

a = 1.0;
b = 1.0;
c1 = 1.0;
Expand Down Expand Up @@ -52,10 +77,10 @@ double Iq(
k2 = temp;
}


TY_SolveEquations(z1, z2, k1, k2, volumefraction, &a, &b, &c1, &c2, &d1, &d2,debug );
checkFlag = TY_CheckSolution( z1, z2, k1, k2, volumefraction, a, b, c1, c2, d1, d2 );

TY_SolveEquations(z1, z2, k1, k2, volumefraction, &a, &b, &c1, &c2, &d1, &d2,debug );
checkFlag = TY_CheckSolution( z1, z2, k1, k2, volumefraction, a, b, c1, c2, d1, d2 );
}

return SqTwoYukawa( qexp * 2 * radius, z1, z2, k1, k2, volumefraction, a, b, c1, c2, d1, d2 );

Expand Down

0 comments on commit 2f5f97b

Please sign in to comment.