#include #include #include #include #include #include #include // Set NITMAX to 100 (or more) to fit parameters. #define NITMAX 1 // Set FIT_LOSSES to 1 to fit lossy element resistivities. // Set FIT_LOSSES to 0 to fil model to reference elements. #define FIT_LOSSES 1 #if (FIT_LOSSES == 0) #define NO_OF_RODS 21 #else #define NO_OF_RODS (21+20) #endif float alfa=10; double q_teor[2*NO_OF_RODS]; double q_begin[2*NO_OF_RODS]; char *type_names[]={"Cu, massive 5011", //0 "Al, massive 6082", //1 "Al, tube 6063", //2 "Brass ", //3 "Al, elox 15 um ", //4 "Al, elox 30 um ", //5 "Al, Paint 30 um ", //6 "CO1(corroded Al) ", //7 "CO2(corroded Al) ", //8 "CO3(corroded Al) ", //9 "Thru boom, glue ", //10 "Thru boom, Starlock", //11 "Above boom " //12 }; double type_resistivity[]={17.2, //0 33.0, //1 31.0, //2 73., //3 36., //4 38., //5 67., //6 34., //7 78., //8 48., //9 66., //10 226., //11 55. //12 }; double odmin[]={ 3.98, 5.95, 7.97, 9.94, 3.88, 5.94, 8.12, 10.0, 15.93, 5.04, 14.94, 10.13, 9.91, 9.90, 3.89, 5.94, 10., 4., 6., 10., 10., 10.05, 3.88, 5.89, 10.03, 3.88, 5.90, 10.00, 3.89, 5.99, 9.86, 9.6, 8.03, 4., 6., 10., 4., 6., 10., 6., 10. }; double odmax[]={ 3.98, 5.95, 7.97, 9.94, 3.89, 5.95, 8.16, 10.15, 15.94, 5.05, 14.95, 10.15, 10.05, 10.23, 3.90, 5.96, 10., 4., 6., 10., 10., 10.16, 3.88, 5.90, 10.25, 3.89, 5.91, 10.15, 3.93, 6.10, 9.86, 9.6, 8.03, 4., 6., 10., 4., 6., 10., 6., 10. }; double id[]={ 0, 0, 0, 0, 0, 0, 6.025, 8.015, 13.02, 0, 0, 8, 8, 8, 0, 0, 0, 0, 0, 8, 8, 8, 0, 0, 8, 0, 0, 8, 0, 0, 8, 8, 6, 0, 0, 8, 0, 0, 8, 0, 8 }; int type[]={ 0, 0, 0, 0, 1, 1, 2, 2, 2, 3, 3, 2, 2, 2, 1, 1, 0, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 8, 9, 10, 10, 10, 11, 11, 11, 12, 12 }; double len[]={ 320.73, 315.28, 310.61, 307.53, 320.62, 315.24, 309.92, 307.16, 297.43, 317.43, 299.71, 307.19, 307.16, 307.13, 320.7, 315.25, 307.59, 320.70, 315.25, 307.19, 307.13, 307.19, 320.67, 315.15, 307.08, 320.48, 315.14, 306.06, 317.78, 312.72, 307.1, 307.4, 310.2 , 325.56, 320.85, 313.46, 326.27, 320.85, 313.58, 319.77, 311.04 }; double bw1[]={ 72.24, 53.34, 44.27, 38.27, 100.97, 75.18, 57.85, 49.82, 36.96, 116.81, 54.74, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; double freq1[]={ 413.1627, 413.4702, 413.9129, 413.5039, 414.2176, 413.8954, 414.5748, 414.1087, 415.0896, 413.4087, 413.5706, 413.698, 414.074, 413.875, 413.268, 413.538, 413.323, 413.285, 413.538, 413.733, 413.876, 413.704, 413.389, 413.576, 413.731, 413.249, 413.536, 413.750, 413.405, 413.522, 414.239, 413.409, 414.261, 414.569, 414.415, 414.591, 414.520, 414.127, 414.483, 413.365, 414.304 }; double q1[]={ 5723, 7743, 9345, 10800, 4081, 5500, 7147, 8320, 11200, 3537, 7563, 8191, 8150, 8295, 4097, 5470, 10780, 4030, 5485, 8313, 8350, 7825, 3908, 5315, 7663, 3748, 5145, 6272, 3026, 3846, 7900, 5576, 5926, 3295, 4525, 5700, 2120, 2875, 3250, 4407, 6651 }; double loss1[]={ 52.55, 48.85, 46.23, 44.75, 55.05, 50.96, 47.68, 47.14, 43.39, 55.89, 47.26, 50.68, 50.67, 50.33, 58.69, 55.54, 48.8, 59.0, 55.4, 50.2, 50.8, 50.92, 58.97, 55.65, 51.39, 59.32, 56.06, 52.72, 60.93, 58.77, 51.2, 54.0, 53.8, 59.9, 56.6, 53.8, 63.7, 60.5, 58.8, 57.9, 52.6 }; double bw2[]={ 74.52, 55.69, 48.81, 42.91, 102.88, 75.62, 60.01, 53.21, 45.01, 115.93, 59.6, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; double freq2[]={ 408.8191, 408.8197, 409.0333, 408.3346, 409.8517, 409.2518, 409.6101, 408.9654, 409.5114, 408.9406, 408.0118, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; double q2[]={ 5485, 7345, 8380, 9516, 3983, 5411, 6825, 7685, 9098, 3527, 6843, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; double loss2[]={ 51.18, 48.25, 45.71, 44.28, 54.05, 50.2, 47.41, 46.02, 42.96, 54.49, 46.66, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; double qbox1=18899.052713; double qbox2=14421.010924; double qrod_fac=3502.648812; double boxcap1=10.244590; double boxcap2=74.357215; double respar1=3164.674215; double respar2=1738.655660; #define LLSQ_MAXPAR 15 #define LLSQ_MAXEQ (2*NO_OF_RODS+LLSQ_MAXPAR) int llsq_neq; int llsq_npar; double llsq_derivatives[LLSQ_MAXEQ*LLSQ_MAXPAR]; double llsq_errors[LLSQ_MAXEQ]; double llsq_steps[2*LLSQ_MAXPAR]; double par[LLSQ_MAXPAR]; double qrod_i(int i); void compute_q(void) { double c1,c2; double t1, davg, tr; int i; llsq_neq=0; for(i=0;i 0) { // Compute Q for the large box c2=1/qbox1; // Add the conductances of losses of element and box (first order) t1=c1+c2; // The coupling may depend on the diameter. // This expression does not fit too badly: t1-=.000000001*boxcap1/(davg*davg*c1); // A small correction that depends on the resistivity t1-=.0000001*respar1/tr; q_teor[llsq_neq]=1/t1; } else { q_teor[llsq_neq]=q1[i]; } llsq_neq++; if(q2[i] > 0) { // Compute Q for the small box the same way c2=1/qbox2; t1=c1+c2; t1-=.000000001*boxcap2/(davg*davg*c1); t1-=.0000001*respar2/tr; q_teor[llsq_neq]=1/t1; } else { q_teor[llsq_neq]=q2[i]; } llsq_neq++; } llsq_neq+=llsq_npar; } double qrod_i(int i) { // Make the Q-value proportional to the average diameter // and inversely proportional to the resistivity. return qrod_fac*(odmax[i]+odmin[i])/sqrt(type_resistivity[type[i]]); } #if(FIT_LOSSES != 0) #define NN 9 void store_par(void) { int i; for(i=0; i LLSQ_MAXPAR) { printf("\nTOO MANY LLSQ PARAMETERS"); } kpiv=piv=0; for(k=0; k piv) { piv=t1; kpiv=k; } } if(piv == 0)return -1; sig=sqrt(piv); for(k=0; kk) { t1=aux[k]; aux[k]=aux[kpiv]; aux[kpiv]=t1; for(i=k; i 0) { sig=0; for(i=k; i piv) { piv=t1; kpiv=j; } } } t1=0; for(i=k; i=0; k--) { t1=llsq_errors[k ]; for(i=k+1; i0) { t1=1000*freq1[i]/bw1[i]; } else { t1=q1[i]; } if(bw2[i]>0) { t2=1000*freq2[i]/bw2[i]; } else { t2=q2[i]; } sprintf(s,"\n%2d %6.3f %6.3f ",i,100*(1-t1/q1[i]),100*(1-t2/q2[i])); fprintf(file,"%s",s); printf("%s",s); } // Zero order approximation. // Qrod=k*diam/sqrt(resistivity); // Qbox=constant // Qtotal=(Qbox*Qrod)/(Qbox+Qrod) sprintf(s,"\nNo Qteo Qexp ratio Qteo Qexp ratio"); fprintf(file,"%s",s); printf("%s",s); nit=0; compute_q(); minimize:; nit++; errsum=0; for(i=0;i 0.1)alfa*=.75; llsq1(); for(i=0;i