Skip to content

Commit

Permalink
Merge 4450637 into d2684a2
Browse files Browse the repository at this point in the history
  • Loading branch information
tpersson committed Feb 20, 2019
2 parents d2684a2 + 4450637 commit 450522d
Show file tree
Hide file tree
Showing 17 changed files with 324 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Makefile_test
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test-ptc-trackline test-ptc-trackline-2 test-ptc-trackline-3 \
test-ptc-align test-ptc-align-2 \
test-rfmultipole-ptc-1 \
test-touschek test-touschek-2 \
test-sequence test-sequence-2 test-sequence-3 test-sequence-4 test-sequence-5 test-sequence-6 test-sequence-7 test-sequence-8 \
test-sequence test-sequence-2 test-sequence-3 test-sequence-4 test-sequence-5 test-sequence-6 test-sequence-7 test-sequence-8 test-sequence-9\
test-line \
test-plot test-plot-2 \
test-setknob test-fillknob\
Expand Down
25 changes: 20 additions & 5 deletions doc/latexuguide/definitions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ \section{Editing Element Definitions}
When the type of the element remains the same, replacement of an
attribute is the more efficient way.

Element definitions can be edited freely. The changes do not affect
Element definitions can be edited freely. The changes only affect
already defined objects which belong to its
\hyperref[sec:element-classes]{element class} (see below).
\hyperref[sec:element-classes]{element class} in case the: \madxmp{option, update_from_parent} is used.
In case this option is used all elements which belong to that class will be updated.
An example is given in \hyperref[sec:element-classes]{element class}.


%\input{Introduction/elm_class}
Expand Down Expand Up @@ -125,7 +127,8 @@ \section{Element Classes}

The full power of the class concept is revealed when object classes are
used to select instances of elements for various purposes. Example:
\madxmp{


SELECT, FLAG=twiss, CLASS = QUADRUPOLE; \=! Select all quadrupoles for the\\
\>! Twiss TFS file
}
Expand All @@ -136,6 +139,18 @@ \section{Element Classes}
this class. A new object inherits all attributes from its class; but its
definition may override some of those values by new ones. All class and
object names can be used in range selections, providing a powerful
mechanism to specify positions for matching constraints and printing.

mechanism to specify positions for matching constraints and printing.

The default option is that if you change the parent of an element you will
not change the children of that class. Let's see in the following example how
it works:
\madxmp{ mb: sbend,l:=lenseq, angle =0.001; \\
mb2: mb;
}
This will create an element \texttt{mb} that then is used as the parent for \texttt{mb2}. If we now do want to give mb
an aperture we can do the following:
\madxmp{ apertype=ellipse, aperture:={ 1,4 }; }

This, however, does not modify \texttt{mb2}. In case we want \texttt{mb2} to also inherent the change from \texttt{mb} we need to use the
flag \madxmp{option, update_from_parent}. This should be used with care and is only changing the direct parent.
%% EOF
1 change: 1 addition & 0 deletions src/mad_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ const char *const_command_def =
"no_fatal_stop= [l, false, true], "
"twiss_print = [l, true, true], "
"warn = [l, true, true], "
"update_from_parent = [l, false, true], "
/* BB and SPCH related options */
"bborbit = [l, false, true], " /* frs */
"bb_ultra_relati = [l, false, true], " /* frs */
Expand Down
17 changes: 16 additions & 1 deletion src/mad_elem.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ make_element(const char* name, const char* parent, struct command* def, int flag
if((el->parent = find_element(parent, element_list)) == NULL)
fatal_error("unknown class type:", parent);
el->base_type = el->parent->base_type;
if(command_par_value("l",def) !=0 && belongs_to_class(el,"multipole"))
warning("Multipole defined with non-zero length:", el->name);
el->length = el_par_value("l", el);
}
add_to_el_list(&el, def->mad8_type, element_list, flag);
Expand Down Expand Up @@ -443,7 +445,7 @@ export_el_def_8(struct element* el, char* string)
}

int
belongs_to_class(struct element* el, char* class)
belongs_to_class(struct element* el, const char* class)
/* returns 1 if an element belongs to a class, else 0 */
{
int in = 0;
Expand Down Expand Up @@ -770,6 +772,7 @@ void
update_element(struct element* el, struct command* update)
/* updates the parameters of el from those read into update */
{

struct command_parameter_list* e_pl = el->def->par;
struct command_parameter_list* pl = update->par;
struct command_parameter *e_par, *par;
Expand Down Expand Up @@ -805,6 +808,18 @@ update_element(struct element* el, struct command* update)
}
}

void
update_element_children(struct element* el, struct command* update)
/* updates the parameters of the children to el. Note that it is only updating one layer (not recursive) */
{

for(int i=0; i<element_list->max;i++){
if(element_list->elem[i]==NULL) break;

if(strcmp(el->name,element_list->elem[i]->parent->name)==0)
update_element(element_list->elem[i], update);
}
}
void
add_to_el_list( /* adds element to alphabetic element list */
struct element** el, int inf, struct el_list* ell, int flag)
Expand Down
4 changes: 3 additions & 1 deletion src/mad_elem.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct element* make_element(const char* name, const char* parent, struct comman
struct element* clone_element(struct element*);
struct element* delete_element(struct element*);
void update_element(struct element*, struct command* update);
void update_element_children(struct element*, struct command* update);

void dump_element(struct element*);
void export_el_def(struct element*, char* string, int noexpr);
void export_el_def_8(struct element*, char* string);
Expand All @@ -59,7 +61,7 @@ void element_name(char* name, int* l);
double element_value(const struct node*, const char* par);
int element_vector(const struct element*, const char* par, double* vector);

int belongs_to_class(struct element*, char*);
int belongs_to_class(struct element*, const char*);
void get_node_vector(const char* par, int* length, double* vector);
int el_par_vector(int* total, double* vect);
double el_par_value(const char* par, const struct element*);
Expand Down
2 changes: 2 additions & 0 deletions src/mad_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,8 @@ process(void) /* steering routine: processes one command */
strcpy(this_cmd->clone->name, name);
scan_in_cmd(this_cmd);
update_element(el, this_cmd->clone);
if(get_option("update_from_parent ")==1)
update_element_children(el, this_cmd->clone);
}
}
break;
Expand Down

0 comments on commit 450522d

Please sign in to comment.