-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use parameter translation rather than memoization so that OpenMP can …
…operate along Q
- Loading branch information
Paul Kienzle
committed
Jan 23, 2024
1 parent
4d75dbd
commit 660ffc4
Showing
4 changed files
with
129 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,74 @@ | ||
static double checksum = 0.0; | ||
|
||
double Iq( | ||
double qexp, | ||
double radius, | ||
double volumefraction, | ||
double k1, | ||
double k2, | ||
double z1, | ||
double z2 | ||
) | ||
void translate( | ||
double *z1, double *z2, double *k1, double *k2, double *volumefraction, | ||
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; | ||
d1 = 1.0; | ||
c2 = 1.0; | ||
d2 = 1.0; | ||
debug = 0; | ||
checkFlag = 0; | ||
|
||
if ( z1 == z2 ) | ||
{ | ||
// Y_SolveEquations(z1, k1 + k2, volumefraction, &a, &b, &c1, &d1, debug ); | ||
// Y_CheckSolution(z1, k1 + k2, volumefraction, &a, &b, &c1, &d1 ); | ||
// return SqOneYukawa(qexp, z1, k1 + k2, volumefraction, &a, &b, &c1, &d1 ); | ||
return 0; | ||
} | ||
|
||
|
||
int debug = 0; | ||
// Theoretically speaking, z1 and z2 (and k1 and k2) are symetric. | ||
// Exchanging z1 (k1) with z2 (k2) does not altern the potential. | ||
// The results should be identical. However, the orginal model proposed | ||
// by Y. Liu treats z1 and z2 differently when implementing the numerical solution. // Hence, it is in general a good practice to require the z1 > z2. | ||
// The following code is added here to swap z1 (k1) with z2 (k2) if z1 < z2. | ||
|
||
double temp; | ||
if ( z1 < z2 ) | ||
if ( *z1 < *z2 ) | ||
{ | ||
temp = z1; | ||
z1 = z2; | ||
z2 = temp; | ||
temp = k1; | ||
k1 = k2; | ||
k2 = temp; | ||
double temp = *z1; | ||
*z1 = *z2; | ||
*z2 = temp; | ||
temp = *k1; | ||
*k1 = *k2; | ||
*k2 = temp; | ||
} | ||
|
||
else if ( *z1 == *z2) { | ||
// The calculator produces NaM when z1 == z2 so no need to precompute | ||
// from the parameter values. | ||
*a = NAN; | ||
return; | ||
} | ||
|
||
TY_SolveEquations(*z1, *z2, *k1, *k2, *volumefraction, a, b, c1, c2, d1, d2, debug ); | ||
|
||
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 ); | ||
int checkFlag = TY_CheckSolution( *z1, *z2, *k1, *k2, *volumefraction, *a, *b, *c1, *c2, *d1, *d2 ); | ||
if (!checkFlag) { | ||
*a = NAN; | ||
return; | ||
} | ||
//printf("Solving (z1=%g, z2=%g, k1=%g, k2=%g, Vf=%g)\n", *z1, *z2, *k1, *k2, *volumefraction); | ||
//printf("=> (a=%g, b=%g, c1=%g, c2=%g, d1=%g, d2=%g)\n", *a, *b, *c1, *c2, *d1, *d2); | ||
} | ||
|
||
return SqTwoYukawa( qexp * 2 * radius, z1, z2, k1, k2, volumefraction, a, b, c1, c2, d1, d2 ); | ||
// Normally constructed in generate.py, but we are doing something special here | ||
// so create them ourselves. | ||
// Using k1, k2 negative from the values given in the the model parameters | ||
#define TRANSLATION_VARS(_v) \ | ||
double z1=_v.z1, z2=_v.z2, k1=-_v.k1, k2=-_v.k2, vf=_v.volfraction; \ | ||
double a, b, c1, c2, d1, d2; \ | ||
translate(&z1, &z2, &k1, &k2, &vf, &a, &b, &c1, &c2, &d1, &d2) | ||
#define OVERRIDE_IQ(_q, _v) \ | ||
Iq(_q, _v.radius_effective, vf, k1, k2, z1, z2, a, b, c1, c2, d1, d2) | ||
|
||
} | ||
double Iq( | ||
double qexp, | ||
double radius, | ||
double volumefraction, | ||
double k1, | ||
double k2, | ||
double z1, | ||
double z2, | ||
// Hidden parameters set by translate before the q loop | ||
double a, | ||
double b, | ||
double c1, | ||
double c2, | ||
double d1, | ||
double d2 | ||
) | ||
{ | ||
if (isnan(a)) { | ||
return a; | ||
} else { | ||
return SqTwoYukawa( qexp * 2 * radius, z1, z2, k1, k2, volumefraction, a, b, c1, c2, d1, d2 ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters