source: TRACY3/trunk/tracy/tracy/src/soleilcommon.cc @ 32

Last change on this file since 32 was 32, checked in by zhangj, 10 years ago

active the transport of the twiss functions and orbits of the transfer line.

  • Property svn:executable set to *
File size: 7.7 KB
Line 
1/***************************************************************************
2                          soleilcommon.c  -  description
3                             -------------------
4    begin                : Thu Oct 30 2003
5    copyright            : (C) 2003 by nadolski
6    email                : nadolski@synchrotron-soleil.fr
7 ***************************************************************************/
8/*
9  Transferred from Tracy 2.7 soleilcommon.c and
10  modified based on Read_Lattice() in Tracy III physlib.cc
11*/
12/* Current revision $Revision$
13 On branch $Name$
14 Latest change $Date$ by $Author$
15*/
16
17
18/***************************************************************************
19 *                                                                         *
20 *   This program is free software; you can redistribute it and/or modify  *
21 *   it under the terms of the GNU General Public License as published by  *
22 *   the Free Software Foundation; either version 2 of the License, or     *
23 *   (at your option) any later version.                                   *
24 *                                                                         *
25 ***************************************************************************/
26
27//#include "tracy.h"
28
29//#include "soleilcommon.h"
30//#include "soleillib.h"
31//#include "datatyp.h"
32//#include "physlib.h"
33
34
35
36/****************************************************************************/
37/* void  Read_Lattice(char *fic)
38
39   Purpose:
40       Read lattice file (fic.lat) and print statistics
41       Generate debugging info if problem in fic.lax
42       Initialize Tracy
43       Initialize the RING
44       Define the vacuum chamber
45       Compute Twiss parameters and chromaticities for on momentum particle
46         and save them in the file named linlat.lat
47
48   Input:
49       fic lattice file w/o its mandatory extension .lat
50
51   Output:
52       none
53
54   Return:
55       none
56
57   Global variables:
58       globval
59       S_SIZE
60
61   Specific functions:
62
63       t2init, Lattice_Read
64       Cell_Init()
65       DefineCh
66       Ring_GetTwiss
67       printglob
68
69   Comments:
70       27/04/03 energy RF acceptance added set to 6%
71       29/04/03 eps added for energy RF acceptance
72       28/10/03 modified for transfer lines, filename added in output
73       02/06/08 energy RF acceptance set to 1 just to avoid overflow during tracking
74       22/06/10 add new globval.  flag and modify new name of variables
75                 from Tracy III Read_Lattice(), which is defined in physlib.cc
76       30/06/11  Get the family index of RF cavity for the lattice of ring; and check whether the RF harmonic number is defined. This is critical to get the
77       correct COD for the lattice with negative momentum compact factor.
78       
79                 
80****************************************************************************/
81void Read_Lattice(char *fic)
82{
83  char fic_maille[S_SIZE + 4] = "";  //lattice file
84  char fic_erreur[S_SIZE + 4] = "";  //error file
85 
86  bool status;
87  bool chroma = true;
88  double dP = 0.0;
89  const double RFacceptance = 1.0; // maximum excursion during tracking
90 
91  Vector2  beta, alpha, eta, etap;
92  Vector   codvect;
93//  double beta[2], alpha[2], eta[2], etap[2], codvect[6];
94  int i;
95
96  strcpy(fic_maille, fic);
97  strcpy(fic_erreur, fic);
98 
99  /* automatic generation of filenames for lattice and error */
100  strcat(fic_maille, ".lat");
101  strcat(fic_erreur, ".lax");
102 
103  /* Initialisation de Tracy */
104  t2init();
105
106  /* open the lattice Input file  */
107
108  if ((fi = fopen(fic_maille, "r")) == NULL)
109  {
110    fprintf(stdout,
111       "ReadLattice: Error while opening file %s \n",
112       fic_maille);
113    fprintf(stdout, "The lattice file name is wrong! \n");
114    exit(1);
115  }
116
117  /* opens the lattice Output file */
118  if ((fo = fopen(fic_erreur, "w")) == NULL)
119  {
120    fprintf(stdout,
121       "ReadLattice: Error while opening file %s \n Access issue",
122       fic_erreur);
123    exit(1);
124  }
125
126  /* Reads lattice and set principle parameters
127   * Energy CODeps and energy offset
128   * print statistics
129   */
130  status = Lattice_Read(&fi, &fo);
131
132  if (status == false)
133  {
134    fprintf(stdout,
135       "Lattice_Read function has returned false\n");
136    fprintf(stdout, "See file %s \n", fic_erreur);
137    exit(1);
138  }
139  fprintf(stdout, "Lattice file: %s\n", fic_maille);
140
141  /* initializes cell structure: construction of the RING */
142  /* Creator of all the matrices for each element         */
143  Cell_Init();
144
145  // for a ring
146  if (globval.RingType == 1)
147  {     
148     /* find the family index of RF cavity*/
149    for(i=0; i<=globval.Cell_nLoc; i++){
150      if(Cell[i].Elem.Pkind == Cavity)
151        globval.cav =  ElemIndex(Cell[i].Elem.PName);   
152    }
153    /*check whether the RF cavity hormonic number is defined or not*/
154    if(Cell[Elem_GetPos(globval.cav, 1)].Elem.C->Ph == 0){
155      printf("soleilcommon():    Error!!! Please define the RF harmonic number in the lattice! \n"
156              "Because this parameter will be used to calculate the stable phase for the lattice with the "
157              "positive / negative momentum compaction factor\n");
158      exit_(1);
159    }
160   
161    /* Defines global variables for Tracy code */
162    globval.H_exact     = false;  // Small Ring Hamiltonian
163    globval.quad_fringe = true; // quadrupole fringe fields on/off
164    globval.EPU         = false; // Elliptically Polarizing Undulator
165    globval.IBS         = false; /* diffusion on/off */
166   
167    globval.MatMeth    = false; /* matrix method */
168    globval.Cavity_on  = false; /* Cavity on/off */
169    globval.radiation  = false; /* radiation on/off */
170    globval.emittance  = false; /* emittance  on/off */
171    globval.pathlength = false; /* Path lengthening computation */
172    globval.CODimax    = 40L;   /* maximum number of iterations for COD algorithm */
173    globval.dPcommon   = 1e-10; /* Common energy step for energy differentiation */
174    globval.delta_RF  = RFacceptance;/* energy acceptance for SOLEIL */
175
176   /* define x/y physical aperture (vacuum chamber), use the default values: +- 1 meter  */
177    globval.Aperture_on = false;
178   
179    /* Compute and get Twiss parameters */
180    Ring_GetTwiss(chroma = true, dP = 0.0);
181
182  //  Cell_SetdP(dP);  /* added for correcting BUG if non convergence: compute on momentum linear matrices */
183  }
184  else 
185  { // for transfer lines 
186    /* Initial optical parameters of the transfer line: */
187    beta[0]  = 34.46;   // beta_x
188    beta[1]  = 33.94;   // beta_y
189    alpha[0] = -4.24;   // alpha_x
190    alpha[1] = -4.34;   // alpha_y
191    eta[0]   = 0.0;   // eta_x
192    etap[0]  = 0.0;   // etap_x
193    eta[1]   = 0.0;   // eta_y
194    etap[1]  = 0.0;   // etap_y
195
196    // set the initial orbit of the transfer line is zero
197     for (i = 0; i < ss_dim; i++) {
198    {
199      codvect[i] = 0.0;
200      globval.CODvect[i] = codvect[i];
201    }
202    dP = codvect[4];
203
204    codvect[0]=1e-4;
205   
206    /* Defines global variables for Tracy code */
207    globval.MatMeth = false;  /* matrix method */
208    globval.Cavity_on = false;  /* Cavity on/off */
209    globval.radiation = false;  /* radiation on/off */
210    globval.emittance = false;  /* emittance  on/off */
211    globval.pathlength = false;  /* Path lengthening computation */
212    globval.CODimax = 10L;  /* maximum number of iterations for COD algo */
213    globval.dPcommon = 1e-10;  /* Common energy step for energy differentiation */
214    globval.delta_RF = RFacceptance;  /* 6% + epsilon energy acceptance for SOLEIL */
215    globval.dPparticle = dP;
216     
217  /* define x/y physical aperture, use the default values: +- 1 meter  */
218    globval.Aperture_on = false;
219   
220    // transfer the optical functions and the orbit
221    TransTwiss(alpha, beta, eta, etap, codvect);
222 
223    // print location, twiss parameters and close orbit/orbit at all elements position to a file
224      prt_cod("cod.out", globval.bpm, true);
225    }
226  }//finish read the transfer line
227 
228}
229
230
231
232
233
Note: See TracBrowser for help on using the repository browser.