10 #if defined __cplusplus
18 static nfu_status
ptwXY_exp_s( ptwXYPoints *ptwXY,
double x1,
double y1,
double z1,
double x2,
double y2,
double z2,
int level );
19 static nfu_status
ptwXY_convolution2( ptwXYPoints *
f1, ptwXYPoints *
f2,
double y,
double yMin,
double *c );
20 static nfu_status
ptwXY_convolution3( ptwXYPoints *convolute, ptwXYPoints *
f1, ptwXYPoints *
f2,
double y1,
double c1,
double y2,
double c2,
double yMin );
24 nfu_status
ptwXY_pow( ptwXYPoints *ptwXY,
double v ) {
33 nfu_status status = nfu_Okay;
34 double *v = (
double *) argList;
47 double x1, y1, z1, x2, y2, z2;
49 length = ptwXY->length;
50 if( length < 1 )
return( ptwXY->status );
51 if( ptwXY->interpolation == ptwXY_interpolationFlat )
return( nfu_invalidInterpolation );
52 if( ptwXY->interpolation == ptwXY_interpolationOther )
return( nfu_otherInterpolation );
55 x2 = ptwXY->points[length-1].x;
56 y2 = a * ptwXY->points[length-1].y;
57 z2 = ptwXY->points[length-1].y =
G4Exp( y2 );
58 for( i = length - 2; i >= 0; i-- ) {
59 x1 = ptwXY->points[i].x;
60 y1 = a * ptwXY->points[i].y;
61 z1 = ptwXY->points[i].y =
G4Exp( y1 );
62 if( ( status =
ptwXY_exp_s( ptwXY, x1, y1, z1, x2, y2, z2, 0 ) ) != nfu_Okay )
return( status );
71 static nfu_status
ptwXY_exp_s( ptwXYPoints *ptwXY,
double x1,
double y1,
double z1,
double x2,
double y2,
double z2,
int level ) {
74 double x, y, dx, dy,
z, zp,
s;
76 if( ( x1 == x2 ) || ( y1 == y2 ) )
return( nfu_Okay );
77 if( level >= ptwXY->biSectionMax )
return( nfu_Okay );
82 x = 1. / s + x2 - z2 * dx / ( z2 - z1 );
83 y = ( y1 * ( x2 -
x ) + y2 * ( x - x1 ) ) / dx;
84 z = z1 *
G4Exp( 1 - dy / (
G4Exp( dy ) - 1 ) );
85 zp = ( z2 - z1 ) / ( y2 - y1 );
87 if( std::fabs( z - zp ) < std::fabs( z * ptwXY->accuracy ) )
return( nfu_Okay );
89 if( ( status =
ptwXY_exp_s( ptwXY, x, y, z, x2, y2, z2, level ) ) != nfu_Okay )
return( status );
90 if( ( status =
ptwXY_exp_s( ptwXY, x1, y1, z1, x, y, z, level ) ) != nfu_Okay )
return( status );
96 ptwXYPoints *
ptwXY_convolution( ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status,
int mode ) {
103 int64_t i1, i2, n1, n2,
n;
104 ptwXYPoints *
f1 = ptwXY1, *
f2 = ptwXY2, *convolute;
105 double accuracy = ptwXY1->accuracy, yMin, yMax, c, y, dy;
110 *status = nfu_unsupportedInterpolation;
111 if( ( ptwXY1->interpolation != ptwXY_interpolationLinLin ) || ( ptwXY2->interpolation != ptwXY_interpolationLinLin ) )
return( NULL );
117 if( ( n1 == 0 ) || ( n2 == 0 ) ) {
118 convolute =
ptwXY_new( ptwXY_interpolationLinLin, NULL, 1., accuracy, 0, 0, status, 0 );
122 if( ( n1 == 1 ) || ( n2 == 1 ) ) {
123 *status = nfu_tooFewPoints;
127 if( accuracy < ptwXY2->accuracy ) accuracy = ptwXY2->accuracy;
131 if( n > 1000 ) mode = -1;
133 if( n > 100000 ) mode = -1;
134 if( ( convolute =
ptwXY_new( ptwXY_interpolationLinLin, NULL, 1., accuracy, 400, 40, status, 0 ) ) == NULL )
return( NULL );
136 yMin = f1->points[0].x + f2->points[0].x;
137 yMax = f1->points[n1 - 1].x + f2->points[n2 - 1].x;
139 if( ( *status =
ptwXY_setValueAtX( convolute, yMin, 0. ) ) != nfu_Okay )
goto Err;
142 dy = ( yMax - yMin ) / 400;
143 for( y = yMin + dy; y < yMax; y += dy ) {
148 for( i1 = 0; i1 < n1; i1++ ) {
149 for( i2 = 0; i2 < n2; i2++ ) {
150 y = yMin + ( f1->points[i1].x - f1->points[0].x ) + ( f2->points[i2].x - f2->points[0].x );
151 if( y <= yMin )
continue;
152 if( y >= yMax )
continue;
158 if( ( *status =
ptwXY_setValueAtX( convolute, yMax, 0. ) ) != nfu_Okay )
goto Err;
160 for( i1 = convolute->length - 1; i1 > 0; i1-- ) {
161 if( ( *status =
ptwXY_convolution3( convolute, f1, f2, convolute->points[i1 - 1].x, convolute->points[i1 - 1].y,
162 convolute->points[i1].x, convolute->points[i1].y, yMin ) ) != nfu_Okay )
goto Err;
176 int64_t i1 = 0, i2 = 0, n1 = f1->length, n2 = f2->length, mode;
177 double dx1, dx2, x1MinP, x1Min, x2Max;
178 double f1x1 = 0, f1y1 = 0, f1x2 = 0, f1y2 = 0, f2x1 = 0, f2y1 = 0, f2x2 = 0, f2y2 = 0;
179 double f1x1p, f1y1p, f1x2p, f1y2p, f2x1p, f2y1p, f2x2p, f2y2p;
180 ptwXY_lessEqualGreaterX legx;
181 ptwXYOverflowPoint lessThanEqualXPoint, greaterThanXPoint;
184 x2Max = f2->points[0].x + ( y - yMin );
185 if( x2Max > f2->points[n2 - 1].x ) x2Max = f2->points[n2 - 1].x;
186 x1Min = f1->points[0].x;
187 x1MinP = y - f2->points[n2 - 1].x;
188 if( x1Min < x1MinP ) x1Min = x1MinP;
192 case ptwXY_lessEqualGreaterX_empty :
193 case ptwXY_lessEqualGreaterX_lessThan :
194 case ptwXY_lessEqualGreaterX_greater :
196 case ptwXY_lessEqualGreaterX_equal :
197 case ptwXY_lessEqualGreaterX_between :
198 i1 = lessThanEqualXPoint.index;
199 f1x1 = f1->points[i1].x;
200 f1y1p = f1y1 = f1->points[i1].y;
202 if( i1 == n1 )
return( nfu_Okay );
203 f1x2 = f1->points[i1].x;
204 f1y2 = f1->points[i1].y;
205 if( legx == ptwXY_lessEqualGreaterX_between ) {
206 if( ( status =
ptwXY_interpolatePoint( f1->interpolation, x1Min, &f1y1p, f1x1, f1y1, f1x2, f1y2 ) ) != nfu_Okay )
return( status );
212 case ptwXY_lessEqualGreaterX_empty :
213 case ptwXY_lessEqualGreaterX_lessThan :
214 case ptwXY_lessEqualGreaterX_greater :
216 case ptwXY_lessEqualGreaterX_equal :
217 case ptwXY_lessEqualGreaterX_between :
218 i2 = lessThanEqualXPoint.index;
219 if( i2 < f2->length - 1 ) i2++;
220 f2x2 = f2->points[i2].x;
221 f2y2p = f2y2 = f2->points[i2].y;
223 f2x1 = f2->points[i2].x;
224 f2y1 = f2->points[i2].y;
225 if( legx == ptwXY_lessEqualGreaterX_between ) {
226 if( ( status =
ptwXY_interpolatePoint( f2->interpolation, x2Max, &f2y2p, f2x1, f2y1, f2x2, f2y2 ) ) != nfu_Okay )
return( status );
235 while( ( i1 < n1 ) && ( i2 >= 0 ) ) {
240 if( dx1 < dx2 ) mode = 1;
244 if( f2x1p < f2->points[i2].
x ) {
248 if( ( status =
ptwXY_interpolatePoint( f2->interpolation, f2x1p, &f2y1p, f2x1, f2y1, f2x2, f2y2 ) ) != nfu_Okay )
return( status );
250 *c += ( ( f1y1p + f1y2p ) * ( f2y1p + f2y2p ) + f1y1p * f2y2p + f1y2p * f2y1p ) * dx1;
252 if( i1 == n1 )
break;
255 f1x2 = f1->points[i1].x;
256 f1y2p = f1y2 = f1->points[i1].y;
262 if( ( f1x2p > f1->points[i1].x ) || ( dx1 == dx2 ) ) {
266 if( ( status =
ptwXY_interpolatePoint( f1->interpolation, f1x2p, &f1y2p, f1x1, f1y1, f1x2, f1y2 ) ) != nfu_Okay )
return( status );
268 *c += ( ( f1y1p + f1y2p ) * ( f2y1p + f2y2p ) + f1y1p * f2y2p + f1y2p * f2y1p ) * dx2;
273 f2x1 = f2->points[i2].x;
274 f2y1p = f2y1 = f2->points[i2].y;
280 f1x2 = f1->points[i1].x;
281 f1y2p = f1y2 = f1->points[i1].y; }
284 f1y2p = f1->points[i1].y;
294 static nfu_status
ptwXY_convolution3( ptwXYPoints *convolute, ptwXYPoints *
f1, ptwXYPoints *
f2,
double y1,
double c1,
double y2,
double c2,
double yMin ) {
297 double yMid = 0.5 * ( y1 + y2 ), cMid = 0.5 * ( c1 + c2 ), c;
300 if( ( status =
ptwXY_convolution2( f1, f2, yMid, yMin, &c ) ) != nfu_Okay )
return( status );
301 if( std::fabs( c - cMid ) <= convolute->accuracy * 0.5 * ( std::fabs( c ) + std::fabs( cMid ) ) )
return( nfu_Okay );
302 if( ( status =
ptwXY_setValueAtX( convolute, yMid, c ) ) != nfu_Okay )
return( status );
303 if( ( status =
ptwXY_convolution3( convolute, f1, f2, y1, c1, yMid, c, yMin ) ) != nfu_Okay )
return( status );
307 #if defined __cplusplus
static G4Pow * GetInstance()
G4double powA(G4double A, G4double y) const
static c2_factory< G4double > c2
ptwXY_lessEqualGreaterX ptwXY_getPointsAroundX(ptwXYPoints *ptwXY, double x, ptwXYOverflowPoint *lessThanEqualXPoint, ptwXYOverflowPoint *greaterThanXPoint)
static nfu_status ptwXY_exp_s(ptwXYPoints *ptwXY, double x1, double y1, double z1, double x2, double y2, double z2, int level)
static nfu_status ptwXY_convolution3(ptwXYPoints *convolute, ptwXYPoints *f1, ptwXYPoints *f2, double y1, double c1, double y2, double c2, double yMin)
nfu_status ptwXY_simpleCoalescePoints(ptwXYPoints *ptwXY)
ptwXYPoints * ptwXY_free(ptwXYPoints *ptwXY)
nfu_status ptwXY_setValueAtX(ptwXYPoints *ptwXY, double x, double y)
nfu_status ptwXY_applyFunction(ptwXYPoints *ptwXY1, ptwXY_applyFunction_callback func, void *argList, int checkForRoots)
double ptwXY_getXMax(ptwXYPoints *ptwXY)
static nfu_status ptwXY_pow_callback(ptwXYPoint *point, void *argList)
ptwXYPoints * ptwXY_convolution(ptwXYPoints *ptwXY1, ptwXYPoints *ptwXY2, nfu_status *status, int mode)
G4double G4Exp(G4double initial_x)
Exponential Function double precision.
nfu_status ptwXY_exp(ptwXYPoints *ptwXY, double a)
const G4double x[NPOINTSGL]
nfu_status ptwXY_pow(ptwXYPoints *ptwXY, double v)
double ptwXY_getXMin(ptwXYPoints *ptwXY)
ptwXYPoints * ptwXY_new(ptwXY_interpolation interpolation, ptwXY_interpolationOtherInfo const *interpolationOtherInfo, double biSectionMax, double accuracy, int64_t primarySize, int64_t secondarySize, nfu_status *status, int userFlag)
nfu_status ptwXY_interpolatePoint(ptwXY_interpolation interpolation, double x, double *y, double x1, double y1, double x2, double y2)
static nfu_status ptwXY_convolution2(ptwXYPoints *f1, ptwXYPoints *f2, double y, double yMin, double *c)