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

Last change on this file since 11 was 11, checked in by zhangj, 11 years ago
  • Property svn:executable set to *
File size: 7.2 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 RF harmonic number in the lattice! \n"
156              "Because this parameter will be used to calculate stable phase for positive / negative momentum compaction factor\n");
157      exit_(1);
158    }
159   
160    /* Defines global variables for Tracy code */
161    globval.H_exact     = false;  // Small Ring Hamiltonian
162    globval.quad_fringe = true; // quadrupole fringe fields on/off
163    globval.EPU         = false; // Elliptically Polarizing Undulator
164    globval.IBS         = false; /* diffusion on/off */
165   
166    globval.MatMeth    = false; /* matrix method */
167    globval.Cavity_on  = false; /* Cavity on/off */
168    globval.radiation  = false; /* radiation on/off */
169    globval.emittance  = false; /* emittance  on/off */
170    globval.pathlength = false; /* Path lengthening computation */
171    globval.CODimax    = 40L;   /* maximum number of iterations for COD algo */
172    globval.dPcommon   = 1e-10; /* Common energy step for energy differentiation */
173    globval.delta_RF  = RFacceptance;/* energy acceptance for SOLEIL */
174
175   /* define x/y physical aperture, use the default values: +- 1 meter  */
176    globval.Aperture_on = false;
177   
178    /* Compute and get Twiss parameters */
179    Ring_GetTwiss(chroma = true, dP = 0.0);
180
181  //  Cell_SetdP(dP);  /* added for correcting BUG if non convergence: compute on momentum linear matrices */
182  }
183  else 
184  { // for transfer lines 
185    /* Initial settings : */
186    beta[0]  = 8.1;
187    alpha[0] = 0.0;
188    beta[1]  = 8.1;
189    alpha[1] = 0.0;
190    eta[0]   = 0.0;
191    etap[0]  = 0.0;
192    eta[1]   = 0.0;
193    etap[1]  = 0.0;
194
195     for (i = 0; i < ss_dim; i++) {
196    {
197      codvect[i] = 0.0;
198      globval.CODvect[i] = codvect[i];
199    }
200    dP = codvect[4];
201
202    /* Defines global variables for Tracy code */
203    globval.MatMeth = false;  /* matrix method */
204    globval.Cavity_on = false;  /* Cavity on/off */
205    globval.radiation = false;  /* radiation on/off */
206    globval.emittance = false;  /* emittance  on/off */
207    globval.pathlength = false;  /* Path lengthening computation */
208    globval.CODimax = 10L;  /* maximum number of iterations for COD algo */
209    globval.dPcommon = 1e-10;  /* Common energy step for energy differentiation */
210    globval.delta_RF = RFacceptance;  /* 6% + epsilon energy acceptance for SOLEIL */
211    globval.dPparticle = dP;
212     
213  /* define x/y physical aperture, use the default values: +- 1 meter  */
214    globval.Aperture_on = false;
215   
216   
217    TransTwiss(alpha, beta, eta, etap, codvect);
218    }
219  }//finish read the transfer line
220 
221}
222
223
224
225
226
Note: See TracBrowser for help on using the repository browser.