Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevents aperture moduel to run with wrong setting of twiss #667

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 15 additions & 2 deletions src/mad_aper.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#define MIN_DOUBLE 1.e-36

int isSliced = 0;
struct table;
struct aper_node /* aperture limit node */
{
Expand Down Expand Up @@ -1240,6 +1241,11 @@ pro_aperture(struct in_cmd* cmd)
struct aper_node *limit_pt = &limit_node;

limit_pt = aperture(table, use_range, tw_cp, &tw_cnt, limit_pt);
/*If TWISS CENTRE is used and some elements with a non-zero length and aperture. Than the node interpolation is wrong. */
if(current_sequ->tw_centre==1 && isSliced==1){
warning("Aperture module - not possible to use TWISS, CENTRE=TRUE with thick apperture elements.", "Aperture command ignored");
return;
}

if (limit_pt->n1 != -1) {
printf("\n\nAPERTURE LIMIT: %s, n1: %g, at: %g\n\n", limit_pt->name, limit_pt->n1, limit_pt->s);
Expand Down Expand Up @@ -1391,6 +1397,7 @@ aperture(char *table, struct node* use_range[], struct table* tw_cp, int *tw_cnt

/* get initial twiss parameters, from start of first element in range */
aper_read_twiss(tw_cp->name, tw_cnt, &s_end, &x, &y, &px, &py, &betx, &bety, &dx, &dy);

// LD: shift further results by one step (?) and finish outside the table
// (*tw_cnt)++;
aper_adj_halo_si(ex, ey, betx, bety, bbeat, halox, haloy, halolength, haloxsi, haloysi);
Expand Down Expand Up @@ -1470,7 +1477,6 @@ aperture(char *table, struct node* use_range[], struct table* tw_cp, int *tw_cnt
n1=999999; n1x_m=999999; n1y_m=999999; on_ap=-999999; nint=1;

aper_read_twiss(tw_cp->name, tw_cnt, &s_end, &x, &y, &px, &py, &betx, &bety, &dx, &dy);

aper_write_table(name, &n1, &n1x_m, &n1y_m, &r, &xshift, &yshift, &xoffset, &yoffset,
apertype, &ap1, &ap2, &ap3, &ap4, &on_ap, &on_elem, &spec,
&s_end, &x, &y, &px, &py, &betx, &bety, &dx, &dy, table);
Expand Down Expand Up @@ -1503,6 +1509,7 @@ aperture(char *table, struct node* use_range[], struct table* tw_cp, int *tw_cnt
node_n1 = 999999;
true_node = 0;
offs_node = 0;


/* calculate the number of slices per node */
if (true_flag == 0)
Expand All @@ -1518,7 +1525,13 @@ aperture(char *table, struct node* use_range[], struct table* tw_cp, int *tw_cnt
if (!nint) nint = 1;

/* do not interpolate 0-length elements*/
if (fabs(length) < MIN_DOUBLE ) is_zero_len = 1;
if (fabs(length) < MIN_DOUBLE ) {
is_zero_len = 1;
}
else{
isSliced = 1;
}


/* slice the node, call survey if necessary, make twiss for slices*/
interpolate_node(&nint);
Expand Down
1 change: 1 addition & 0 deletions src/mad_seq.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ struct sequence
struct node_list* ex_nodes; /* alphabetic list of nodes (no drifts) */
struct table* tw_table; /* pointer to latest twiss table created */
int tw_valid; /* true if current tw_table is valid */
int tw_centre; /* true if twiss center option is triggered */
struct constraint_list* cl; /* pointer to constraint list during match */
struct vector_list* orbits; /* pointer to list of stored orbits */
};
Expand Down
11 changes: 10 additions & 1 deletion src/mad_twiss.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,19 @@ pro_twiss(void)
}
}

if(par_present("centre", current_twiss)) set_option("centre", &k);
if(par_present("centre", current_twiss)) {
set_option("centre", &k);
// Special check that it really is set to TRUE (not only included in the argument)
if(command_par_value("centre", current_twiss)>0){
current_sequ->tw_centre=1;
}
}
else {
k = 0;
current_sequ->tw_centre=0;
set_option("centre", &k);
k = 1;

}

name = command_par_string_user("keeporbit", current_twiss);
Expand Down Expand Up @@ -1024,6 +1032,7 @@ embedded_twiss(void)
/* beta0 specified */
embedded_twiss_beta[0] = buffer(cp->m_string->p[0]);


/* START defining a TWISS input command for the sequence */
tnl = local_twiss[0]->cmd_def->par_names;
tpos = name_list_pos("beta0", tnl);
Expand Down