AMP2K - Converts amperes to simulator values k = amp2k(Family, Field, Amps, DeviceList, Energy, Coefficients, K2AmpScaleFactor) or k = amp2k(Family, Field, Amps, DeviceList, Energy, MagnetCoreType, K2AmpScaleFactor) Calculates the "K-value" from the coefficients (or MagnetCoreType), current [amps], energy, and linear scale factor A Coefficients vector or a MagnetCoreType string (coefficient found from magnetcoefficents.m) can be used Amps and Coefficients must have equal number of rows or one must only have one row INPUTS 1. Family - Family Name 2. Field - Family Field (like 'Setpoint') 3. Amps - Ampere vector to convert 4. DeviceList - Device list (Amps and DeviceList must have the same number of rows) 5. Energy - Energy in GeV {Default: getenergy} If Energy is a vector, each output column will correspond to that energy. Energy can be anything getenergy accepts, like 'Model' or 'Online'. (Note: If Energy is a vector, then Amps can only have 1 column)Family, Field, value(:,i), DeviceList, Energy, ParamsList{:} 6. C - % A Coefficients vector or a MagnetCoreType string (coefficient found from magnetcoefficents.m) can be used Amps and Coefficients must have equal number of rows or one must only have one row 7. K2AmpScaleFactor - linearly scales the input current: Amps = Amps ./ K2AmpScaleFactor This can be used to account for linear calibration errors of the power supply and magnet OUTPUT 1. K and B - K-value and field in AT convention For dipole: k = B / Brho For quadrupole: k = B'/ Brho For sextupole: k = B"/ Brho / 2 (to be compatible with AT) NOTES 1. If energy is not an input or empty, then the energy is obtained from getenergy. 2. Family and Field inputs are not used but there automatically part of the hw2physics call. See Also k2amp, magnetcoefficients
0001 function k = amp2k(Family, Field, Amps, DeviceList, Energy, C, K2AmpScaleFactor) 0002 %AMP2K - Converts amperes to simulator values 0003 % k = amp2k(Family, Field, Amps, DeviceList, Energy, Coefficients, K2AmpScaleFactor) 0004 % or 0005 % k = amp2k(Family, Field, Amps, DeviceList, Energy, MagnetCoreType, K2AmpScaleFactor) 0006 % 0007 % Calculates the "K-value" from the coefficients (or MagnetCoreType), current [amps], energy, and linear scale factor 0008 % 0009 % A Coefficients vector or a MagnetCoreType string (coefficient found from magnetcoefficents.m) can be used 0010 % Amps and Coefficients must have equal number of rows or one must only have one row 0011 % INPUTS 0012 % 1. Family - Family Name 0013 % 2. Field - Family Field (like 'Setpoint') 0014 % 3. Amps - Ampere vector to convert 0015 % 4. DeviceList - Device list (Amps and DeviceList must have the same 0016 % number of rows) 0017 % 5. Energy - Energy in GeV {Default: getenergy} 0018 % If Energy is a vector, each output column will correspond to that energy. 0019 % Energy can be anything getenergy accepts, like 'Model' or 'Online'. 0020 % (Note: If Energy is a vector, then Amps can only have 1 0021 % column)Family, Field, value(:,i), DeviceList, Energy, ParamsList{:} 0022 % 6. C - % A Coefficients vector or a MagnetCoreType string (coefficient found from magnetcoefficents.m) can be used 0023 % Amps and Coefficients must have equal number of rows or one must only 0024 % have one row 0025 % 7. K2AmpScaleFactor - linearly scales the input current: Amps = Amps ./ K2AmpScaleFactor 0026 % This can be used to account for linear calibration errors of the power supply and magnet 0027 % 0028 % OUTPUT 0029 % 1. K and B - K-value and field in AT convention 0030 % For dipole: k = B / Brho 0031 % For quadrupole: k = B'/ Brho 0032 % For sextupole: k = B"/ Brho / 2 (to be compatible with AT) 0033 % 0034 % NOTES 0035 % 1. If energy is not an input or empty, then the energy is obtained from getenergy. 0036 % 2. Family and Field inputs are not used but there automatically part of the hw2physics call. 0037 % 0038 % See Also k2amp, magnetcoefficients 0039 0040 % ALGORITHM 0041 % 0042 % k = (c0 + c1*I + ... + cn*I^n)/Brho 0043 0044 % 0045 % Written by M. Yoon 4/8/03 0046 % Adapted by Laurent S. Nadolski 0047 0048 if nargin < 4 0049 error('At least 4 inputs required'); 0050 end 0051 0052 if nargin < 6 0053 C = []; 0054 end 0055 if isempty(C) 0056 %[C, Leff, MagnetName] = magnetcoefficients(Family); 0057 C = getfamilydata(Family, Field, 'HW2PhysicsParams', DeviceList); 0058 C = C{1}; 0059 %Leff = getleff(Family, DeviceList(ii,:)); 0060 end 0061 0062 if nargin < 5 0063 Energy = []; 0064 end 0065 if isempty(Energy) 0066 Energy = getenergy; % like getenergy('Production') 0067 elseif ischar(Energy) 0068 Energy = getenergy(Energy); 0069 end 0070 0071 0072 % If Amps is a row vector make it a column vector 0073 Amps = Amps(:); 0074 0075 % Scale solution if required 0076 if nargin >= 7 0077 Amps = Amps ./ K2AmpScaleFactor; 0078 end 0079 0080 brho = getbrho(Energy); 0081 0082 % Compute polynomial expansion: polynom = c0 + c1*I ... 0083 % For dipole: polynom = B * Leff / I 0084 % For quadrupole: polynom = B' * Leff / I 0085 % For sextupole: polynom = B" * Leff / I (use AT unit /2 from MAD units) 0086 0087 % polynom = (C(8)+C(7)*Amps+C(6)*Amps^2+C(5)*Amps^3+C(4)*Amps^4+C(3)*Amps^5+C(2)*Amps^6+C(1)*Amps^7) 0088 % polynom = (c0+c1*Amps+c2*Amps^2+c3*Amps^3+c4*Amps^4+c5*Amps^5+c6*Amps^6+c7*Amps^7) 0089 0090 if isstr(C) 0091 TableLookUpFlag = 1; 0092 MagnetCoreType = C; 0093 [C, Leff, MagnetName] = magnetcoefficients(MagnetCoreType, Amps(1)); 0094 Amps0 = Amps(1); 0095 else 0096 TableLookUpFlag = 0; 0097 end 0098 0099 if any(size(C,1) ~= length(Amps)) 0100 if length(Amps) == 1 0101 Amps = ones(size(C,1),1) * Amps; 0102 elseif size(C,1) == 1 0103 %C = ones(size(Amps,1),1) * C; 0104 else 0105 error('Amps and Coefficients must have equal number of rows or one must only have one row'); 0106 end 0107 end 0108 0109 % B, B', or B" scaled by energy 0110 for i = 1:length(Amps) 0111 % For piecewise tables, get a new polynomial 0112 if TableLookUpFlag 0113 if Amps(i) ~= Amps0; 0114 [C, Leff, MagnetName] = magnetcoefficients(MagnetCoreType, Amps(i)); 0115 Amps0 = Amps(i); 0116 end 0117 end 0118 0119 if size(C,1) == 1 0120 k(i,1) = polyval(C, Amps(i)) / brho; 0121 else 0122 k(i,1) = polyval(C(i,:), Amps(i)) / brho; 0123 end 0124 end 0125 0126 0127 % switch upper(deblank(MagnetName)) 0128 % case 'BEND' 0129 % k = (Amps/brho)*polynom/Leff; % B scaled by energy 0130 % %BLeff = Amps*polynom; 0131 % %B = BLeff/Leff; 0132 % 0133 % case 'QUAD' 0134 % k = (Amps/brho)*polynom/Leff; % B' scaled by energy 0135 % %BPrimeLeff = Amps*polynom; 0136 % %Bprime = BPrimeLeff/Leff; 0137 % 0138 % case 'SEXT' 0139 % k = (Amps/brho)*polynom/Leff; % B" scaled by energy 0140 % %BPrimePrimeLeff = Amps*polynom; 0141 % %BPrimePrime = BPrimePrimeLeff/Leff; 0142 % end