#include <BLEngeFunction.hh>
z is the distance from the nominal edge, with z=0 being the edge. it should be divided by the aperture diameter or full width/height. z<0 is inside, z>0 is outside.
See the COSY reference manual (pp 32-35) for suggested values of a1-a6, or use the ENGE_BEND or ENGE_QUAD types (which come from there). http://cosy.pa.msu.edu/cosymanu/index.html
Mathematica was used to compute the derivatives.
Public Member Functions | |
BLEngeFunction () | |
default constructor. | |
BLEngeFunction (BLEngeType t) | |
constructor for common magnet types. | |
BLEngeFunction (double _a1, double _a2, double _a3, double _a4, double _a5, double _a6) | |
general constructor. | |
void | set (double _a1, double _a2, double _a3, double _a4, double _a5, double _a6) |
set the parameters. | |
double | operator() (double z) const |
evaluate the Enge function at z. | |
double | prime (double z) const |
evaluate the derivative of the Enge function at z. | |
double | first (double z) |
double | second (double z) const |
evaluate the second derivative of the Enge function at z. | |
double | third (double z) const |
evaluate the third derivative of the Enge function at z. | |
double | fourth (double z) const |
evaluate the fourth derivative of the Enge function at z. | |
double | fifth (double z) const |
evaluate the fifth derivative of the Enge function at z. | |
BLEngeType | getType () const |
return the type of Enge function | |
Private Attributes | |
BLEngeType | type |
double | a1 |
double | a2 |
double | a3 |
double | a4 |
double | a5 |
double | a6 |
BLEngeFunction::BLEngeFunction | ( | ) | [inline] |
BLEngeFunction::BLEngeFunction | ( | BLEngeType | t | ) | [inline] |
constructor for common magnet types.
References ENGE_BEND, ENGE_BLOCK, ENGE_OTHER, ENGE_QUAD, and type.
00047 { 00048 switch(t) { 00049 case ENGE_BLOCK: 00050 case ENGE_OTHER: 00051 set(0,0,0,0,0,0); 00052 break; 00053 case ENGE_BEND: 00054 set(0.478959,1.911289,-1.185953,1.630554,-1.082657,0.318111); 00055 break; 00056 case ENGE_QUAD: 00057 set(0.296471,4.533219,-2.270982,1.068627,-0.036391,0.022261); 00058 break; 00059 } 00060 type = t; 00061 }
BLEngeFunction::BLEngeFunction | ( | double | _a1, | |
double | _a2, | |||
double | _a3, | |||
double | _a4, | |||
double | _a5, | |||
double | _a6 | |||
) | [inline] |
void BLEngeFunction::set | ( | double | _a1, | |
double | _a2, | |||
double | _a3, | |||
double | _a4, | |||
double | _a5, | |||
double | _a6 | |||
) | [inline] |
set the parameters.
References a1, a2, a3, a4, a5, a6, ENGE_BLOCK, ENGE_OTHER, and type.
Referenced by GenericBendField::GenericBendField(), GenericQuadField::GenericQuadField(), and MultipoleField::MultipoleField().
00069 { 00070 a1=_a1; a2=_a2; a3=_a3; a4=_a4; a5=_a5; a6=_a6; 00071 if(a1==0.0 && a2==0.0 && a3==0.0 && a4==0.0 && a5==0.0 && 00072 a6==0.0) 00073 type = ENGE_BLOCK; 00074 else 00075 type = ENGE_OTHER; 00076 }
double BLEngeFunction::operator() | ( | double | z | ) | const [inline] |
double BLEngeFunction::prime | ( | double | z | ) | const [inline] |
evaluate the derivative of the Enge function at z.
References a1, a2, a3, a4, a5, a6, ENGE_BLOCK, and type.
Referenced by GenericQuadField::addFieldValue(), GenericBendField::addFieldValue(), and first().
00085 { 00086 if(type == ENGE_BLOCK) return 0.0; 00087 if(fabs(z) > 4.0) return 0.0; 00088 double exp1 = exp(a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6))))); 00089 return -exp1/(1.0+exp1)/(1.0+exp1)* 00090 (a2+z*(2.0*a3+z*(3.0*a4+z*(4.0*a5+z*5.0*a6)))); 00091 }
double BLEngeFunction::second | ( | double | z | ) | const [inline] |
evaluate the second derivative of the Enge function at z.
References a1, a2, a3, a4, a5, a6, ENGE_BLOCK, and type.
Referenced by GenericBendField::addFieldValue().
00094 { 00095 if(type == ENGE_BLOCK) return 0.0; 00096 if(fabs(z) > 4.0) return 0.0; 00097 double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6)))); 00098 double f2 = (a2+2*a3*z+3*a4*z*z+4*a5*z*z*z+5*a6*z*z*z*z); 00099 double f3 = (2*a3+6*a4*z+12*a5*z*z+20*a6*z*z*z); 00100 double exp1 = exp(f1); 00101 return exp1*((exp1-1.0)*f2*f2-(1.0+exp1)*f3)/ 00102 (1.0+exp1)/(1.0+exp1)/(1.0+exp1); 00103 }
double BLEngeFunction::third | ( | double | z | ) | const [inline] |
evaluate the third derivative of the Enge function at z.
References a1, a2, a3, a4, a5, a6, ENGE_BLOCK, and type.
Referenced by GenericBendField::addFieldValue().
00105 { 00106 if(type == ENGE_BLOCK) return 0.0; 00107 if(fabs(z) > 4.0) return 0.0; 00108 double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6)))); 00109 double f2 = a2+z*(2*a3+z*(3*a4+4*a5*z+5*a6*z*z)); 00110 double f3 = 2*(a3+z*(3*a4+2*z*(3*a5+5*a6*z))); 00111 double f4 = a4+2.0*z*(2.0*a5+5.0*a6*z); 00112 double exp1 = exp(f1); 00113 double onepexp1 = 1.0 + exp1; 00114 return -exp1*(6*exp1*exp1*f2*f2*f2-6*exp1*f2*(f2*f2+f3)*onepexp1 00115 +(f2*f2*f2+3*f2*f3+6*f4)*onepexp1*onepexp1) 00116 /(onepexp1*onepexp1*onepexp1*onepexp1); 00117 }
double BLEngeFunction::fourth | ( | double | z | ) | const [inline] |
evaluate the fourth derivative of the Enge function at z.
References a1, a2, a3, a4, a5, a6, ENGE_BLOCK, and type.
Referenced by GenericBendField::addFieldValue().
00119 { 00120 if(type == ENGE_BLOCK) return 0.0; 00121 if(fabs(z) > 4.0) return 0.0; 00122 double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6)))); 00123 double f2 = a2+z*(2*a3+z*(3*a4+4*a5*z+5*a6*z*z)); 00124 double f3 = 2*(a3+z*(3*a4+2*z*(3*a5+5*a6*z))); 00125 double f4 = a4+2.0*z*(2.0*a5+5.0*a6*z); 00126 double f5 = a5 + 5*a6*z; 00127 double exp1 = exp(f1); 00128 double onepexp1 = 1.0 + exp1; 00129 return -exp1*(-24*exp1*exp1*exp1*f2*f2*f2*f2+onepexp1* 00130 (36*exp1*exp1*f2*f2*(f2*f2+f3)-2*exp1*(7*f2*f2*f2*f2 00131 +18*f2*f2*f3+3*f3*f3+24*f2*f4)*onepexp1 00132 +(f2*f2*f2*f2+6*f2*f2*f3+3*f3*f3+24*f2*f4+24*f5) 00133 *onepexp1*onepexp1)) 00134 /(onepexp1*onepexp1*onepexp1*onepexp1*onepexp1); 00135 }
double BLEngeFunction::fifth | ( | double | z | ) | const [inline] |
evaluate the fifth derivative of the Enge function at z.
References a1, a2, a3, a4, a5, a6, ENGE_BLOCK, and type.
Referenced by GenericBendField::addFieldValue().
00137 { 00138 if(type == ENGE_BLOCK) return 0.0; 00139 if(fabs(z) > 4.0) return 0.0; 00140 double f1 = a1+z*(a2+z*(a3+z*(a4+z*(a5+z*a6)))); 00141 double f2 = a2+z*(2*a3+z*(3*a4+4*a5*z+5*a6*z*z)); 00142 double f3 = 2*(a3+z*(3*a4+2*z*(3*a5+5*a6*z))); 00143 double f4 = a4+2.0*z*(2.0*a5+5.0*a6*z); 00144 double f5 = a5 + 5*a6*z; 00145 double exp1 = exp(f1); 00146 double onepexp1 = 1.0 + exp1; 00147 return -exp1/(onepexp1*onepexp1*onepexp1*onepexp1*onepexp1*onepexp1) 00148 *(120*exp1*exp1*exp1*exp1*f2*f2*f2*f2*f2 00149 -240*exp1*exp1*exp1*f2*f2*f2*(f2*f2+f3)*onepexp1 00150 +onepexp1*onepexp1*(30*exp1*exp1*f2*(5*f2*f2*f2*f2 00151 +12*f2*f2*f3+3*f3*f3+12*f2*f4)-10*exp1*(3*f2*f2*f2*f2*f2 00152 +14*f2*f2*f2*f3+9*f2*f3*f3+36*f2*f2*f4+12*f3*f4+24*f2*f5) 00153 *onepexp1+(120*a6+f2*f2*f2*f2*f2+10*f2*f2*f2*f3+60*f2*f2*f4 00154 +60*f3*f4+15*f2*(f3*f3+8*f5))*onepexp1*onepexp1)); 00155 }
BLEngeType BLEngeFunction::getType | ( | ) | const [inline] |
return the type of Enge function
References type.
Referenced by GenericBendField::GenericBendField(), and GenericQuadField::GenericQuadField().
00157 { return type; }
BLEngeType BLEngeFunction::type [private] |
Referenced by BLEngeFunction(), fifth(), fourth(), getType(), operator()(), prime(), second(), set(), and third().
double BLEngeFunction::a1 [private] |
double BLEngeFunction::a2 [private] |
double BLEngeFunction::a3 [private] |
double BLEngeFunction::a4 [private] |
double BLEngeFunction::a5 [private] |
double BLEngeFunction::a6 [private] |