Skip to content

Commit

Permalink
Merge 5feccba into 97e8d8c
Browse files Browse the repository at this point in the history
  • Loading branch information
kyrsjo committed Oct 31, 2018
2 parents 97e8d8c + 5feccba commit 7ff01e5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
51 changes: 42 additions & 9 deletions src/mad_beam.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ update_beam(struct command* comm)
else { /* unknown particle, then mass and charge must be given as well */
if (par_present("mass", comm)) mass = command_par_value("mass", comm);
else { // default is emass
warning("emass given to unknown particle:", name);
mass = get_variable("emass");
warning("emass given to unknown particle:", name);
mass = get_variable("emass");
}
if (par_present("charge", comm)) charge = command_par_value("charge", comm);
else { //default is charge +1
warning("charge +1 given to unknown particle:", name);
charge = 1;
warning("charge +1 given to unknown particle:", name);
charge = 1;
}
}
}
Expand Down Expand Up @@ -163,44 +163,77 @@ update_beam(struct command* comm)

// energy related
if (par_present("energy", comm)) {
energy = command_par_value("energy", comm);
if (energy <= mass) fatal_error("energy must be","> mass");
int inform = -1; // Set to 1 in set_defaults to indicate that it is marked as read;
// otherwise inform == 2
if ((inform=par_present("pc", comm)) && inform!=1)
warning("Both energy and pc specified;", "pc was ignored.");
if ((inform=par_present("gamma", comm)) && inform!=1)
warning("Both energy and gamma specified;", "gamma was ignored.");
if ((inform=par_present("beta", comm)) && inform!=1)
warning("Both energy and beta specified;", "beta was ignored.");
if ((inform=par_present("brho", comm)) && inform!=1)
warning("Both energy and bhro specified;", "brho was ignored.");

if ((energy = command_par_value("energy", comm)) <= mass) fatal_error("energy must be","> mass");

pc = sqrt(energy*energy - mass*mass);
gamma = energy / mass;
beta = pc / energy;
brho = pc / ( fabs(charge) * clight * 1.e-9);
}
else if(par_present("pc", comm)) {
pc = command_par_value("pc", comm);
int inform = -1;
if ((inform=par_present("gamma", comm)) && inform != 1)
warning("Both pc and gamma specified;", "gamma was ignored.");
if ((inform=par_present("beta", comm)) && inform != 1)
warning("Both pc and beta specified;", "beta was ignored.");
if ((inform=par_present("brho", comm)) && inform != 1)
warning("Both pc and brho specified;", "brho was ignored.");

if ((pc = command_par_value("pc", comm)) <= 0.0) fatal_error("pc must be", "> 0.0");

energy = sqrt(pc*pc + mass*mass);
gamma = energy / mass;
beta = pc / energy;
brho = pc / ( fabs(charge) * clight * 1.e-9);
}
else if(par_present("gamma", comm)) {
int inform = -1;
if ((inform=par_present("beta", comm)) && inform != 1)
warning("Both gamma and beta specified;", "beta was ignored.");
if ((inform=par_present("brho", comm)) && inform != 1)
warning("Both gamma and brho specified;", "brho was ignored.");

if ((gamma = command_par_value("gamma", comm)) <= one) fatal_error("gamma must be","> 1");

energy = gamma * mass;
pc = sqrt(energy*energy - mass*mass);
beta = pc / energy;
brho = pc / ( fabs(charge) * clight * 1.e-9);
}
else if(par_present("beta", comm)) {
int inform = -1;
if ((inform=par_present("brho", comm)) && inform != 1)
warning("Both beta and brho specified;", "brho was ignored.");

if ((beta = command_par_value("beta", comm)) >= one) fatal_error("beta must be","< 1");

gamma = one / sqrt(one - beta*beta);
energy = gamma * mass;
pc = sqrt(energy*energy - mass*mass);
brho = pc / ( fabs(charge) * clight * 1.e-9);
}
else if(par_present("brho", comm)) {
if ((brho = command_par_value("brho", comm)) < zero) fatal_error("brho must be","> 0");

pc = brho * fabs(charge) * clight * 1.e-9;
energy = sqrt(pc*pc + mass*mass);
gamma = energy / mass;
beta = pc / energy;
}
else {
energy = command_par_value("energy", current_beam);
if (energy <= mass) fatal_error("energy must be","> mass");
if ((energy = command_par_value("energy", current_beam)) <= mass) fatal_error("energy must be","> mass");

pc = sqrt(energy*energy - mass*mass);
gamma = energy / mass;
beta = pc / energy;
Expand Down
1 change: 0 additions & 1 deletion src/mad_err.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ void mad_error (const char* t1, const char* fmt, ...);
void mad_err_getwarn(int* cwarn, int* fwarn);

#endif // MAD_ERR_H

2 changes: 1 addition & 1 deletion tests/test-sequence-3/test-sequence-3.madx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ INITBETA0: BETA0,
* Beam
* NB! beam->ex == (beam->exn)/(beam->gamma*beam->beta*4)
*******************************************************************************/
Beam, particle=POSITRON, MASS=0.51099906E-3, ENERGY=1.0,PC=0.99999986944, GAMMA=1.956950762297E3;
Beam, particle=POSITRON, MASS=0.51099906E-3, ENERGY=1.0;
Use, sequence=ad;

select flag=twiss,column=name, s, l, alfx, betx,dx, alfy, bety;
Expand Down
8 changes: 4 additions & 4 deletions tests/test-sequence-3/test-sequence-3.ref
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

++++++++++++++++++++++++++++++++++++++++++++
+ MAD-X 5.04.00 (64 bit, Linux) +
+ MAD-X 5.04.02 (64 bit, Linux) +
+ Support: mad@cern.ch, http://cern.ch/mad +
+ Release date: 2018.03.02 +
+ Execution date: 2018.05.15 19:14:58 +
+ Release date: 2018.10.03 +
+ Execution date: 2018.10.31 10:08:01 +
++++++++++++++++++++++++++++++++++++++++++++


Expand Down Expand Up @@ -82,7 +82,7 @@ INITBETA0: BETA0,

*******************************************************************************/

Beam, particle=POSITRON, MASS=0.51099906E-3, ENERGY=1.0,PC=0.99999986944, GAMMA=1.956950762297E3;
Beam, particle=POSITRON, MASS=0.51099906E-3, ENERGY=1.0;

Use, sequence=ad;

Expand Down

0 comments on commit 7ff01e5

Please sign in to comment.