Project

General

Profile

i3_rvolt.txt

Kyle Hazelwood, 01/15/2015 10:53 AM

 
1
static int rvolt(int bka_is_input,int i,int type,CS_HV_TABLE *cs)
2
{
3
 int			j, j0, sts;
4
  float		twopi = 6.283185;
5
  float		pmass = 0.93828;  
6
  float		cbkta = 0.673301;
7
  float		cspeed = 2.998E8;
8
  float		degrad = 57.29578;
9
  float		tmin = 0.0001;
10
 float			x[HV_PARS_NUM]; /* plotting items */
11
 float			pmass2;
12
 float			p, e, gamma, r, cmpctn, eta,  rfmax;
13
 float			t0, dt, dppi, dppf, ddpp, vi, vf, dv, edot, g;
14
 float			phi, pdot, pdotr, freq;
15
 float			last_hv,bi,bf,db;
16
 char			mess[80];
17

    
18

    
19
 if (type == RFHV_SEG_TRMP) {
20
    /*  temp
21
    if (cs->slot[i].t > rampd.slot[(int)rampd.p1.ncs_rampdown_slot].t) {
22
       sprintf(mess,"Err Trmp seg(#%d) time %7.3f > fltop end time %7.3f",
23
              i,cs->slot[i].t,rampd.slot[(int)rampd.p1.ncs_rampdown_slot].t);
24
       return(util_errpost(MYERR,mess));
25
     }
26
    */
27
  }
28
 else if (type == RFHV_SEG_PRMP) {
29
    /*  temp
30
    if (cs->slot[i].t > rampd.slot[(int)rampd.p1.ncs_fltop_slot].t) {
31
       sprintf(mess,"Err Prmp seg(#%d) time %7.3f > fltop start time %7.3f",
32
               i,cs->slot[i].t,rampd.slot[(int)rampd.p1.ncs_fltop_slot].t);
33
       return(util_errpost(MYERR,mess));
34
     }
35
    */
36
  }
37
 else return(util_errpost(MYERR, "Wrong segment type"));
38

    
39
 if (cs->slot[i].dt < tmin) {
40
    sprintf(mess,"Warning: seg(#%d) dt %7.4f too short, minimum %7.4f",
41
            i+1,cs->slot[i].dt,tmin);
42
    return(util_errpost(MYERR,mess));
43
  }
44

    
45
 if (bka_is_input) { 
46
    bi = cs->slot[i - 1].bkta;
47
    bf = cs->slot[i].bkta;
48
    db = (bf - bi) / NSUBSEQ;
49
    last_hv = cs->slot[i-1].hv;
50
  }
51
 else {
52
     /* max RF (MeV/turn) */
53
    rfmax = hvp.par.tubmax * hvp.par.tubgain * cs->pars[PAR_RFNUM] / 1000.;
54
?? hvp.par.tubmax - max rf tube volt, 22.5 kv
55
?? hvp.par.tubgain - tube gain 10.8
56
    if (cs->slot[i].hv > rfmax) {
57
       cs->slot[i].hv = rfmax;
58
       error_message_c("Warning:max rf hv imposed!",0,YELLOW,TRUE); 
59
     }
60
    vi = cs->slot[i-1].hv;
61
    vf = cs->slot[i].hv;
62
    dv = (vf - vi) / NSUBSEQ;
63
  }
64

    
65
 pmass2 = pmass * pmass;
66
 t0 = cs->slot[i - 1].t;
67
 dt = cs->slot[i].dt / NSUBSEQ;
68
 dppi = cs->slot[i - 1].dpop / 100.;
69
 dppf = cs->slot[i].dpop / 100.;
70
 ddpp = (dppf - dppi) / NSUBSEQ;
71

    
72
 if (plt->plot) j0 = 0;
73
 else j0 = NSUBSEQ;         /* passing just once if not ploted */
74
 for (j = j0; j < NSUBSEQ; j++) {
75
    x[HV_T] = t0 + dt * (j + 1);
76
    x[HV_DPOP] = dppi + ddpp * (j + 1);
77
    p = mi_conv_t2p(x[HV_T],&rampd);
78
    pdot = mi_conv_t2pdot(x[HV_T],&rampd);
79
    x[HV_P] = p * (1. + x[HV_DPOP]);
80
    pdotr = pdot + x[HV_P] * (ddpp / dt);
81
    e = sqrt(x[HV_P] * x[HV_P] + pmass2);
82
    /* relativistic gamma */
83
    gamma = e / pmass;
84
    /* bunch radius */
85
    r = hvp.par.radius * (1. + x[HV_DPOP] / power(hvp.par.gammat, 2));
86
    /* momentum compaction */
87
    cmpctn = 1. / (gamma * gamma) - 1. / power(hvp.par.gammat, 2);
88
    eta = fabs(cmpctn);
89
    edot = x[HV_P] * pdotr / e;
90
    freq = cspeed * x[HV_P] / (e * twopi * r);
91
    x[HV_RFFREQ] = 1.0E-6 * hvp.par.aharm * freq;
92
    /* g = sin(phi) */
93

    
94
    if (bka_is_input) { 
95
       x[HV_BKTA] = bi + db * (j + 1);
96
       sts = bka2hv(&x[HV_HV],&g,last_hv,x[HV_BKTA],e,eta,hvp.par.aharm,
97
                    r,edot,freq);
98
       last_hv = x[HV_HV];
99
     }
100
    else {
101
       x[HV_HV] = vi + dv * (j + 1);
102
       if (x[HV_HV] != 0.) g = fabs(edot) / (x[HV_HV] * freq * 1.0E-3);
103
       else g = 0.;
104
       if (g > 1.0) {
105
          g = 0.;
106
          if (fabs(edot) >= 0.) { 
107
             sprintf(mess,
108
               "Err:seg(#%d) sin(phi)>1.0,when t=%7.3f,p=%7.3f,increase volt",
109
                   i,x[HV_T],x[HV_P]);
110
             return(util_errpost(MYERR,mess));
111
           }
112
        }
113
       x[HV_BKTA] = alphag(g) * sqrt(x[HV_HV] * e / 
114
                 (eta * power(hvp.par.aharm, 3))) * r * cbkta;
115
     }
116

    
117
    /* bucket area, eV-s */
118
    x[HV_BKTH] = betag(g) * sqrt(x[HV_HV] * e / 
119
                 (hvp.par.aharm*eta)) * cspeed * cbkta / (8.0E9 * x[HV_P]);
120
    x[HV_PHI] = degrad * asin(g) * SIGN(1.0, edot);
121
    if (x[HV_HV] == 0.) phi = 0.0;
122
    if (plt->plot) rcalc_for_plot(e, eta, gamma, g, x, cs);
123
  }
124

    
125
  /* note that p and pdot displayed are ramp values without dp/p factoer,
126
     but ploted values including corrections from dp/p  */
127

    
128
 cs->slot[i].hv = x[HV_HV];
129
 cs->slot[i].phi = x[HV_PHI];
130
 cs->slot[i].bkta = x[HV_BKTA];
131
 cs->slot[i].bkth = x[HV_BKTH] * 100.;
132
 cs->slot[i].freq = x[HV_RFFREQ];
133

    
134
 return(0);
135
}
136