-
Notifications
You must be signed in to change notification settings - Fork 39
/
mad_mkthin.cpp
2728 lines (2470 loc) · 135 KB
/
mad_mkthin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* mad_mkthin.cpp
Thick to thin lens converter makethin. Helmut Burkhardt
Major steps
2001, 2002 early versions by Mark Hayes
2005 : Standard selection SELECT,FLAG=makethin,RANGE=range,CLASS=class,PATTERN=pattern[,FULL][,CLEAR]; Implementation of slicing for solenoids
2012 : Extension of TEAPOT slicing to n>4
2013 : Keep thick elements if slice number <1, code now C++, thick slicing for quadrupoles, automatic generation of dipedge elements for dipoles
2014 : Thick bend slicing, with or without dipedge
2016 : Extra markers, sbend_from_rbend transmit aper_tol
2018 : Thick solenoid slicing, write bend angle to multipole if different from k0*l
2019 : New elements from element definition, all attributes enabled
*/
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <sstream>
#ifdef __cplusplus
extern "C" {
#endif
#include "madx.h"
#ifdef __cplusplus
}
#endif
template<class T> // define class print operator
auto operator << (std::ostream& os, const T& t) -> decltype(t.Print(os), os)
{
t.Print(os);
return os;
}
namespace MaTh
{
static int iMakeDipedge, iMakeEndMarkers, iMoreExpressions; // variables local to module that control makethin behavior
static const int el_type_maxlen=11; // theElProp->get_el_type_maxlen();
static const int el_name_maxlen=25;
static const int par_name_maxlen=19;
static unsigned int Verbose;
static const std::vector<std::string> DoNotCopy ={"l","lrad","slot_id","assembly_id","slice","comments"};
static const std::vector<std::string> DoNotCopy2= {"slot_id","assembly_id"};
static char ExtraChar='_';
}
//------------------------------- forward declarations --------------
class my_Element_List
{
public:
my_Element_List(){}; // constructor
~my_Element_List()=default; // destructor
std::vector<std::string> el_name_list;
std::vector<element*> el_ptr;
element* my_make_element(const std::string el_name, const std::string parent,command* def, int flag);
void Print(std::ostream &StrOut = std::cout) const;
};
class ElmAttr // used for current element, list of all attributes defined and flag if on
{
public:
ElmAttr(const element* el); // constructor
~ElmAttr()=default; // destructor
void Print(std::ostream &StrOut = std::cout) const;
void TurnOff(const std::vector<std::string>& off_list);
void TurnOnActive(const element* el);
std::vector<std::string> get_list_of_active_attributes() const;
std::vector<std::string> AttrNam;
std::vector<bool> On;
};
class SliceDistPos // defines the distances and positions, depending on number of slices and slicing style
{
public:
SliceDistPos(const int n,const bool teapot_fl); // constructor
~SliceDistPos(); // destructor
void Print(std::ostream &StrOut = std::cout) const;
double delta;
double Delta;
//
std::string delta_str,delta_half_str; // string expression
std::string Delta_str,Delta_half_str; // string expression
private:
int n; // number of slices
bool teapot_fl;
};
SliceDistPos::~SliceDistPos()=default; // destructor
class OneElementWithSlices // One Element with Slices used to work on slices, derived from thick_elem which is not modified - declared as constant
{
public:
OneElementWithSlices(const element* thick_elem,element* sliced_elem); // constructor
~OneElementWithSlices()=default; // destructor
const element* thick_elem; // pointer to the thick element
std::vector<element*> theSlices; // pointer(s) to the one or several slices
};
class ElementListWithSlices
{
public:
std::vector<OneElementWithSlices*> VecElemWithSlices; // vector of thick elements+slices
ElementListWithSlices(unsigned int verbose); // constructor
~ElementListWithSlices(); // destructor
void put_slice(const element* thick_elem, element* sliced_elem); // add sliced_elem to VecElemWithSlices
element* find_slice(const element* thick_elem, const int slice); // find address of thin slice by slice number for thick_elem
element* find_slice(const element* thick_elem, const std::string name); // find address of thin slice by slice name for thick_elem
void Print(std::ostream &StrOut = std::cout) const;
void PrintCounter(std::ostream &StrOut = std::cout) const;
private:
int find_thick(const element* thick_elem); // find thick_element in VecElemWithSlices, <0 means not found, used inside find_slice
unsigned int verbose;
unsigned int get_thin_calls,get_thin_iteractions; // to monitor the search (in-) efficiency find_slice
int ilast1,ilast2; // keep last two found find_slice, useful in recursive searches which switch between slices and parents
};
class SequenceList
{
public:
SequenceList(); // constructor
~SequenceList()=default; // destructor
sequence* slice_sequence(const std::string slice_style,sequence* thick_sequ,const std::string LastSequenceSliced="",const std::string LastStyle="");
void put_sequ(sequence* thick_sequ); // add a sequence to the sequence list
sequence* find_sequ(sequence* thick_sequ); // check if thick_sequ is already there, if yes return the pointer to it, used to check if the sequence was already sliced
void Print(std::ostream &StrOut = std::cout) const;
void Reset();
private:
std::vector<sequence*> my_sequ_list_vec; // list of sequences
};
static ElementListWithSlices *theSliceList=nullptr, *theRbendList=nullptr, *theBendEdgeList=nullptr; // global since MAD-X works with single global element_list
static my_Element_List *my_El_List=nullptr;
class SeqElList // sequence with elements considered for slicing
{
public:
SeqElList(const std::string seqname,const std::string slice_style,/*sequence* thick_sequ,*/sequence* sliced_seq,node* thick_node,SequenceList* theSequenceList); // constructor
~SeqElList(); // destructor
void Print(std::ostream &StrOut = std::cout) const;
void slice_node(); // decides what to do : nothing, slice_node_translate, slice_node_default
node* current_node() const { return thick_node;} // get
void current_node(node* thisnode) { work_node=thick_node=thisnode; } // set
private:
double simple_at_shift(const int slices, const int slice_no) const;
double teapot_at_shift(const int slices, const int slice_no) const;
double collim_at_shift(const int slices, const int slice_no) const;
double hybrid_at_shift(const int slices, const int slice_no) const;
double at_shift(const int slices, const int slice_no,const std::string local_slice_style) const; // return at relative shifts from centre of unsliced magnet
void kn_ks_from_thick_elem(const element* thick_elem,command_parameter* kn_pars[4],command_parameter* ks_pars[4]) const; // read k0-k3, k0s-k3s in thick_elem and put them in kn_pars, ks_pars
command_parameter* make_k_list(const std::string parnam,command_parameter* k_pars[4],command_parameter* k_param) const; // from k values 0-3 to expr lists
element* new_marker_element(const std::string el_name, const element* el_inp);
element* sbend_from_rbend(element* rbend_el);
element* create_thick_slice(const element* thick_elem,const int slice_type);
element* create_sliced_magnet(const element* thick_elem, int slice_no,bool ThickSLice);
element* create_thin_solenoid(const element* thick_elem, int slice_no);
element* create_thin_elseparator(const element* thick_elem, int slice_no);
element* create_sliced_element(const element* thick_elem, int slice_no);
element* create_bend_dipedge_element(element* thick_elem,const bool Entry);
void finish_make_sliced_elem(element*& sliced_elem, const element* thick_elem, command* cmd, const std::string parent_name, int slice_no); // final common steps
void slice_node_translate(); // slice/translate and add slices to sliced sequence
void slice_node_default(); // like collimator and add slices to sliced sequence
void slice_attributes_to_slice(command* cmd,const element* thick_elem); // deal with attributes like kick
void place_thick_slice(const element* thick_elem, element* sliced_elem, const int i);
void place_start_or_end_marker(const bool at_start);
node* copy_thin(node* thick_node);
node* thick_node; // current node, that is considered for slicing
node* work_node; // clone of thick_node for non-destructive rbend->sbend translation
SequenceList* theSequenceList;
sequence *sliced_seq;
std::string seqname; // name of the sequence
std::string slice_style;
unsigned int verbose;
int nslices;
const double eps;
bool MakeDipedge; // translate dipoles to dipedge, dipole without edge effects, dipedge
};
//------------------------------- source code --------------
static const int k_logical=0;
static const int k_int=1;
static const int k_double=2;
static const int k_cstring=3;
static const int k_int_array=11;
static const int k_double_array=12;
static const int k_cstring_array=13;
static const bool dipedge_h1_h2_fl=false; // normally false to avoid potentially non-simplectic partial higher order in dipedge. Optionally true as requested by Andrea Latina in 10/2014
static const bool kill_fringe_fl=true; // requested by Laurent et al., somewhat redundant, should be sufficient to check existance of non-default h1,e1; h2,e2 parameters
static const bool Enable_all_attr_fl=true; // set true to allow to enable all attibutes in the sliced sequence --- otherwise only attributes defined in thick
// check general options
inline bool thin_foc_fl() { return get_option("thin_foc"); }
inline bool rbarc_fl() { return get_option("rbarc"); } // by default on, then use (reduced) length of rbends
ElmAttr::ElmAttr(const element* el) // constructor
{
if(el)
{
const command* el_cmd=el->def;
const command_parameter_list *el_cmd_pl=el_cmd->par;
for (int i=0;i<el_cmd_pl->curr; ++i)
{
AttrNam.push_back(el_cmd_pl->parameters[i]->name);
On.push_back( el_cmd->par_names->inform[i] );
}
bool look_at_parent=true;
if(look_at_parent && el->parent && el != el->parent && std::string(el->parent->name) != std::string(el->parent->base_type->name) ) TurnOnActive(el->parent);
}
}
void ElmAttr::TurnOff(const std::vector<std::string>& off_list)
{
if ( MaTh::Verbose>1 ) std::cout << "ElmAttr remove ";
for(unsigned int i=0;i<AttrNam.size();++i)
{
std::string item=AttrNam[i];
for(unsigned int j=0;j<off_list.size();++j)
{
if(item==off_list[j])
{
if ( MaTh::Verbose>1 ) std::cout << " " << item;
On[i]=false;
break;
}
}
}
if ( MaTh::Verbose>1 ) std::cout << std::endl;
}
void ElmAttr::TurnOnActive(const element* el)
{ // use when ElmAttr aleady existing for same size element, like parent
if(el)
{
if ( MaTh::Verbose>1 ) std::cout << "ElmAttr turn on for " << el->name;
const command* el_cmd=el->def;
const command_parameter_list *el_cmd_pl=el_cmd->par;
if( (int)AttrNam.size() == el_cmd_pl->curr)
{
for (int i=0;i<el_cmd_pl->curr; ++i)
{
if(el_cmd->par_names->inform[i] && !On[i])
{
On[i]=true;
if ( MaTh::Verbose>1 ) std::cout << " " << AttrNam[i];
}
}
}
if ( MaTh::Verbose>1 ) std::cout << std::endl;
}
}
void ElmAttr::Print(std::ostream &StrOut) const
{
// show all attributes and mark in line below if on/off
StrOut << std::right;
StrOut << "ElmAttr "; for(unsigned int i=0;i<AttrNam.size();++i) StrOut << " " << AttrNam[i]; StrOut << '\n';
StrOut << " On/off "; for(unsigned int i=0;i<AttrNam.size();++i) StrOut << " " << std::setw((int)AttrNam[i].length()) << On[i]; StrOut << std::endl;
}
std::vector<std::string> ElmAttr::get_list_of_active_attributes() const
{
std::vector<std::string> result;
for(unsigned int i=0;i<AttrNam.size();++i) if(On[i]) result.push_back(AttrNam[i]);
return result;
}
static void warning_to_c(std::ostringstream& WarnStr) { warning((WarnStr.str()).c_str(),""); }
static bool NameIsInList(const std::string name,const std::vector<std::string>& namlist)
{
for(int i=0; i < (int) namlist.size(); ++i)
if( name==namlist[i] ) return true;
return false;
}
static std::vector<std::string> str_v_join(const std::vector<std::string> v1,const std::vector<std::string> v2) // join two string vectors
{
std::vector<std::string> result=v1;
result.reserve(v1.size() + v2.size());
for(unsigned int i=0;i<v2.size();++i) result.emplace_back(v2[i]);
return result;
}
static double my_get_expression_value(expression* ex) // check for NULL and update the value as done in dump_expression
{
double result=0;
if(ex)
{
result = expression_value(ex, 2); // get valie
ex->value = result; // also make sure the value stored agrees with the expression
}
return result;
}
static std::string my_dump_expression(expression* ex) // dump_expression in mad_expr.c only prints the value, here show also the expression and check for NULL
{
std::ostringstream ostr;
ostr << std::setprecision(15) << "expression ";
if(ex==nullptr) ostr << " is nullptr";
else
{
if(ex->string) ostr << " string=" << std::left << std::setw(MaTh::el_name_maxlen) << ex->string << std::right;
ostr << " value=" << std::setw(8) << my_get_expression_value(ex);
}
return ostr.str();
}
static double my_get_int_or_double_value(const element* el,const std::string parnam,bool &found) // works for integer and double, also useful as my_get_int_or_double_value(el->base_type,char* parnam); to get the default values
{
// just returning el_par_value(parnam,base_el); or el_par_value_recurse(parnam,base_el);
// is not good enough, gets 0 for integer parameters and in some cases too specific - like checks for non-zero length of dipoles which does not allow to compare with the base type for dipoles
// rather do all directly here, descending from el / el->def / el->def->par to parameters[i], loop through them and look at integer and double values
// in case of expression uses the expression_value
double val=0;
found=false;
if(el && el->def && el->def->par)
{
command_parameter_list* pl=el->def->par;
for (int i = 0; i < pl->curr; ++i)
{
if(pl->parameters[i])
{
command_parameter* cp=pl->parameters[i];
if( std::string(cp->name) == parnam )
{
if(cp->expr)
{
val = my_get_expression_value(cp->expr);
found=true;
}
else switch (cp->type)
{
case k_int: // int value of expression, actually same as double value
found=true;
val = cp->double_value;
break;
case k_double: // double value of expression
found=true;
val = cp->double_value;
break;
}
}
}
}
}
return val;
}
static double cmd_par_val(const command_parameter* par) // return the double value given by expression or directly the value
{
double result=0;
if(par)
{
if(par->type==k_double)
{
if(par->expr) result=expression_value(par->expr,0); else result=par->double_value;
}
}
return result;
}
static std::string my_dump_command_parameter(const command_parameter* cp) // dump_command_parameter in mad_cmdpar.c only prints the value, here show also the expression by calling my_dump_expression and check for NULL
{
std::ostringstream ostr;
ostr << std::setprecision(15) << "my_dump_command_parameter ";
if(cp==nullptr) ostr << " is NULL";
else
{
ostr << "parameter:" << std::left << std::setw(MaTh::par_name_maxlen) << cp->name;
ostr << std::right << " cp->type=" << std::setw(2) << cp->type;
ostr << " stamp=" << cp->stamp << " ";
double default_val=0;
const double eps=1.e-15; // used to check if strength is compatible with zero
switch (cp->type)
{
case k_logical:
ostr << "logical: ";
if( (int) cp->double_value) ostr << "true"; else ostr << "false";
ostr << '\n';
break;
case k_int: // int value of expression, actually same as double value
case k_double: // double value of expression
if(cp->expr) ostr << my_dump_expression(cp->expr); else ostr << " expression=NULL ";
if(cp->call_def) default_val=cp->call_def->double_value;
if(cp->expr==nullptr && fabs(cp->double_value-default_val)>eps)
ostr << " value=" << std::setw(10) << cp->double_value << " default=" << std::setw(10) << default_val;
ostr << '\n';
break;
case k_int_array: // int array, expr_list
case k_double_array: // double array, expr_list, used for example for Aperture, http://mad.web.cern.ch/mad/madx.old/Introduction/aperture.html
if (cp->double_array)
{
if (cp->expr_list) // calculate the values
{
ostr << "array of " << cp->double_array->curr << " ";
for (int ei = 0; ei < cp->double_array->curr; ++ei)
{
if (ei < cp->expr_list->curr && cp->expr_list->list[ei] != NULL)
{
ostr << std::right << std::setw(3) << ei << " :" << std::left << my_dump_expression(cp->expr_list->list[ei]) << std::right; // show expression and value
}
}
}
}
ostr << '\n';
break;
case k_cstring:
ostr << "cstring:";
if(cp->string) ostr << cp->string; else ostr << " NULL";
ostr << '\n';
break;
case k_cstring_array: // string array
dump_char_p_array(cp->m_string);
/* FALLTHRU */
case '?':
ostr << " cp->type=" << cp->type << " no info dump implemented so far" << '\n';
}
}
return ostr.str();
}
static std::string my_dump_command_parameter_list(command_parameter_list* pl)
{
std::ostringstream ostr;
ostr << std::setprecision(15) << "my_dump_command_parameter_list";
if(pl)
{
ostr << " name=" << std::setw(MaTh::par_name_maxlen) << pl->name;
ostr << " curr=" << pl->curr << " max=" << pl->max << '\n';
if(pl->curr > pl->max)
{
ostr << "*** error *** seen in my_dump_command_parameter_list max=" << pl->curr << " > " << " curr" << pl->curr << " set curr back to max" << '\n';
pl->curr = pl->max;
}
for (int i = 0; i < pl->curr; ++i)
{
ostr << std::setw(2) << i << " : ";
if(pl->parameters[i]) ostr << my_dump_command_parameter(pl->parameters[i]); else ostr << " NULL ";
}
}
else ostr << " is NULL";
return ostr.str();
}
static void SetParameterValue(const std::string parnam,element* el,const double val,const int type=k_double) // set value and type, by default double
{
command* el_def=el->def;
name_list* nl=el_def->par_names;
const int ei=name_list_pos(parnam.c_str(),nl);
if(ei > -1)
{
command_parameter* cp=el_def->par->parameters[ei];
if(cp)
{
if(MaTh::Verbose>1)
{
std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " el->name=" << std::setw(MaTh::el_name_maxlen) << el->name << " parameter " << parnam
<< " was double_value=" << cp->double_value
<< " and type=" << cp->type;
if(cp->expr) std::cout << " has " << my_dump_expression(cp->expr); else std::cout << " no expression";
std::cout << " set to val=" << val
<< " and type=" << type << '\n';
}
if(cp->expr) cp->expr=nullptr; // remove any expression
cp->double_value=val; // set the double value
cp->type=type; // set the type value
}
}
else
{
std::ostringstream WarnStr;
WarnStr << "SetParameterValue for parameter " << parnam << " failed for " << std::setw(MaTh::el_name_maxlen) << el->name << " parameter not in element name_list";
warning_to_c(WarnStr);
}
}
static void SetParameter_in_cmd(command* cmd, const command_parameter* param, const std::string parnam,const int inf)
{ // set param in cmd if exists
// if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " parnam=" << parnam << " param=" << param << '\n';
if(param)
{
name_list* nl=cmd->par_names;
const int ei=name_list_pos(parnam.c_str(),nl);
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << std::left << " parnam=" << std::setw(MaTh::par_name_maxlen) << parnam << " param=" << param << " parame->name=" << std::setw(MaTh::par_name_maxlen) << param->name << " ei=" << std::setw(2) << ei << std::right << '\n';
if(ei > -1)
{
nl->inform[ei]=inf;
command_parameter* param_copy=clone_command_parameter(param); // make copy which can be modified
if( parnam!=std::string(param->name) ) strcpy(param_copy->name, parnam.c_str()); // use parnam, can be different from parnam->name, like e2 of bend which becomes e1 in exit dipedge
cmd->par->parameters[ei]=param_copy;
}
}
}
static void ParameterTurnOn(const std::string parnam,element* el) // request that this parameter is written to output
{
const command* el_def=el->def;
name_list* nl=el_def->par_names;
const int ei=name_list_pos(parnam.c_str(),nl);
if(ei > -1) nl->inform[ei]=1; // Turn on by setting inform to 1
else
{
std::ostringstream WarnStr;
WarnStr << "ParameterTurnOn for parameter " << parnam << " failed for " << std::setw(MaTh::el_name_maxlen) << el->name << " parameter not in element name_list ";
warning_to_c(WarnStr);
}
}
static void ParameterRemove(const std::string parnam,element* el)
{
if(el)
{
const command* el_def=el->def;
name_list* nl=el_def->par_names;
const int ei=name_list_pos(parnam.c_str(),nl);
if(ei > -1)
{
nl->inform[ei]=0; // Turn off by setting inform to 0 -- effective in save, but still used in twiss; so really delete expression and turn value off
double default_value=0;
default_value=el->base_type->def->par->parameters[ei]->double_value; // el_par_value(parnam,el->base_type) cannot be used here, base element length may be zero
command_parameter* cp=el_def->par->parameters[ei];
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " in " << el-> name << " parameter" << std::setw(12) << parnam
<< " value=" << std::setw(6) << cp->double_value << " set to default=" << std::setw(6) << default_value
<< " for " << std::setw(12) << parnam << " cp->expr=" << cp->expr << " and set expression to nullptr" << '\n';
cp->type = k_double;
cp->double_value = default_value;
cp->expr=nullptr;
}
}
}
static command* new_cmdptr(const element* elem)
{ // new command* with all attributes as defined in elem
command* cmd=clone_command(elem->def); // definition has all inform on
for(int i=0; i< cmd->par->curr; ++i) cmd->par_names->inform[i]=0; // turn off
return cmd;
}
static std::string my_dump_command(const command* cmd)
{
std::ostringstream ostr;
if(cmd==nullptr) ostr << " is NULL";
else
{ // command defined in mad_elem.h, c-structures based on pointing to pointers, contains name_list par_names and command_parameter_list par
ostr << "my_dump_command command: ";
ostr << cmd->name;
ostr << " module: " ; ostr << cmd->module;
ostr << " group: " ; ostr << cmd->group;
ostr << " stamp= " << cmd->stamp << " link_type= " << cmd->link_type << " mad8_type= " << cmd->mad8_type;
ostr << " #par_names "; if(cmd->par_names->curr) ostr << cmd->par_names->curr; else ostr << " NULL";
ostr << " #par= " ; if(cmd->par->curr) ostr << cmd->group; else ostr << " NULL";
ostr << '\n';
for (int i = 0; i < cmd->par->curr; ++i) ostr << my_dump_command_parameter(cmd->par->parameters[i]);
ostr << "within command par:"; if(cmd->par) ostr << '\n' << my_dump_command_parameter_list(cmd->par); else ostr << " NULL" << '\n';
}
ostr << '\n';
ostr << "my_dump_command command end" << '\n';
return ostr.str();
}
static std::string my_dump_element(const element* el)
{
std::ostringstream ostr;
ostr << std::setprecision(15) << std::left << '\n' << "my_dump_element";
if(el==nullptr) ostr << " is NULL";
else
{ // element defined by c-structures based on pointing to pointers
ostr << " name=" << std::setw(MaTh::el_name_maxlen) << el->name;
if(el->base_type) ostr << " base_type=" << el->base_type->name;
ostr << " stamp=" << el->stamp << " length=" << el->length << " parent name=" << std::setw(MaTh::el_type_maxlen) << el->parent->name;
ostr << " def_type=" << el->def_type;
if(el->def_type) ostr << " which means defined separately"; else ostr << " which means inside sequence";
ostr << '\n';
ostr << "within element " << my_dump_command(el->def);
}
return ostr.str();
}
static void Remove_All_Fringe_Field_Parameters(element* el)
{
static std::vector<std::string> FringePar = {"e1","e2","fint","fintx","h1","h2","hgap"};
for(unsigned int i=0; i < FringePar.size(); ++i) ParameterRemove(FringePar[i].c_str(),el);
if(kill_fringe_fl)
{
SetParameterValue("kill_ent_fringe",el,true,k_logical);
SetParameterValue("kill_exi_fringe",el,true,k_logical);
ParameterTurnOn("kill_ent_fringe",el); // turn writing on
ParameterTurnOn("kill_exi_fringe",el); // turn writing on
}
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " el name=" << std::left << std::setw(MaTh::el_name_maxlen) << el->name << " base_type" << el->base_type->name << " after remove : " << my_dump_element(el) << '\n';
}
static std::string my_dump_node(const node* node)
{
std::ostringstream ostr;
ostr << std::setprecision(15) << '\n' << "my_dump_node";
if(node==nullptr) ostr << " is NULL";
else
{
ostr << std::setprecision(15) << " node:";
std::string pname, nname, from_name;
if (node->previous != nullptr) pname = node->previous->name;
if (node->next != nullptr) nname = node->next->name;
if (node->from_name != nullptr) from_name = node->from_name;
ostr << " name=" << std::left << std::setw(MaTh::el_name_maxlen) << node->name << std::right
<< " occ=" << node->occ_cnt
<< " node->base_name=" << std::left << std::setw(MaTh::el_type_maxlen) << node->base_name << std::right
<< " from_name=" << std::left << std::setw(10) << from_name << std::right
<< " at_value=" << std::setw(10) << node->at_value
<< " position=" << std::setw(10) << node->position
<< " previous=" << std::setw(MaTh::el_name_maxlen) << pname
<< " next=" << std::setw(MaTh::el_name_maxlen) << nname << std::right
<< " at_expr: ";
if(node->at_expr) ostr << my_dump_expression(node->at_expr); else ostr << "NULL ";
if(node->p_elem) ostr << my_dump_element(node->p_elem);
if(node->cl) { for(int i=0; i< node->cl->curr; ++i) dump_constraint(node->cl->constraints[i]); }
}
ostr << '\n';
return ostr.str();
}
static std::string my_dump_sequence(const sequence* c_sequ,const int level)
{ // level 1 little info, 3 dump also nodes, 4 dump also elements
std::ostringstream ostr;
if(c_sequ==nullptr) ostr << "sequence is NULL";
else
{
node* c_node;
double suml = zero;
ostr << "sequence:" << c_sequ->name;
if(c_sequ->refpos) ostr << " refpos=" << c_sequ->refpos; else ostr << " refpos=NULL";
if(c_sequ->next_sequ) ostr << " next_sequ=" << c_sequ->next_sequ; else ostr << " next_sequ=NULL";
ostr << " ref_flag=" << c_sequ->ref_flag; // -1 for exit, 0 for centre, 1 for entry
if(c_sequ->ref_flag==-1) ostr << " (exit) ";
else if(c_sequ->ref_flag==0) ostr << " (centre) ";
else if(c_sequ->ref_flag==1) ostr << " (entry) ";
ostr << " share=" << c_sequ->share << " nested=" << c_sequ->nested << " con_cnt=" << c_sequ->con_cnt << " stamp=" << c_sequ->stamp << " line=" << c_sequ->line << " add_pass=" << c_sequ->add_pass << " length=" << c_sequ->length << '\n';
c_node = c_sequ->start;
ostr << std::setprecision(15);
double lastvalue=0;
while(c_node != nullptr)
{
suml += c_node->length;
if (level > 2)
{
ostr << my_dump_node(c_node);
if (level > 3 && c_node->p_elem != nullptr) ostr << my_dump_element(c_node->p_elem);
}
else if (level > 0 && strcmp(c_node->base_name, "drift") != 0)
{
ostr << std::left << std::setw(MaTh::par_name_maxlen) << c_node->name << std::right
<< " at_value=" << std::setw(10) << c_node->at_value
<< " position=" << std::setw(6) << c_node->position
<< " length=" << std::setw(17) << c_node->length;
if(c_node->p_elem) // show lrad if available
{
double lrad=el_par_value("lrad",c_node->p_elem);
if(lrad>0) ostr << " lrad value=" << lrad;
}
if(c_node->from_name) ostr << " from " << c_node->from_name;
if(c_node->at_expr) ostr << " at_expr " << my_dump_expression(c_node->at_expr);
if(c_node->at_expr) { double currentvalue=my_get_expression_value(c_node->at_expr); ostr << " diff=" << std::setw(8) << currentvalue-lastvalue; lastvalue=currentvalue; }
ostr << '\n';
}
if (c_node == c_sequ->end) break;
c_node = c_node->next;
}
ostr << "===== sum of node length=" << std::setw(8) << suml << '\n';
ostr << '\n';
}
return ostr.str();
}
static std::string my_get_cmd_expr_str(const command_parameter* cmd) // return the expression as string, if there is only a value, return the value as string
{
std::string result="";
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " " << my_dump_command_parameter(cmd);
if(cmd)
{
if(cmd->expr && cmd->expr->string) result=cmd->expr->string; // the expression is define as string, use this
else // look for a value
{
const double eps=1.e-15; // used to check if strength is compatible with zero
if( fabs(cmd->double_value)>eps ) // value defined and non-zero
{
std::ostringstream ostr;
if(cmd->double_value<0) ostr << "("; // enclose negative value in brackets
ostr << cmd->double_value;
if(cmd->double_value<0) ostr << ")"; // enclose negative value in brackets
result=ostr.str();
}
}
}
if(result.length()<1) result="0";
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " result=" << result << '\n';
return result;
}
static expression* my_get_param_expression(const element* el,const std::string parnam) // get a new copy of the expression for a parameter from an element, use the value as new expression if the expression was NULL
{
const command* el_def=el->def;
name_list* nl=el_def->par_names;
const int ei=name_list_pos(parnam.c_str(),nl);
expression* ep=nullptr;
if(ei > -1)
{
const command_parameter* cp = el_def->par->parameters[ei]; // pointer to original parameter
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " for element " << std::setw(MaTh::par_name_maxlen) << el->name << " parameter " << std::setw(MaTh::par_name_maxlen) << parnam << " ei=" << ei << " my_dump_expression(cp->expr):" << my_dump_expression(cp->expr) << " cp->double_value=" << cp->double_value << '\n';
command_parameter* cp_copy = clone_command_parameter( cp ); // copy of the original parameter that can be modified
if(cp_copy->expr==nullptr) // no expression yet
{ // use the value as new expression if the expression was NULL
std::ostringstream ostr;
ostr << std::setprecision(15) << cp->double_value; // use the value as string
cp_copy->expr = new_expression(ostr.str().c_str(),deco); // where deco is a global. // cp_copy->expr->value = cp->double_value; has no effect and this not needed
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " cp_copy->expr was NULL, create new expression from string " << ostr.str() << " now " << my_dump_expression(cp_copy->expr) << '\n';
}
else if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " expression exists use it, expr=" << my_dump_expression(cp_copy->expr) << '\n';
ep = cp_copy->expr;
}
return ep;
}
static expression* my_get_param_expression(const command_parameter* cp) // get a new copy of the expression for a parameter, use the value as new expression if the expression was NULL
{
expression* ep=cp->expr;
if(ep==nullptr) // no expression yet
{ // use the value as new expression if the expression was NULL
std::ostringstream ostr;
ostr << std::setprecision(15) << cp->double_value; // use the value as string
ep = new_expression(ostr.str().c_str(),deco); // where deco is a global. // cp_copy->expr->value = cp->double_value; // seems to have no effect and this not needed
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " create new expression from string " << ostr.str() << " now " << my_dump_expression(ep) << '\n';
}
return ep;
}
element* my_Element_List::my_make_element(const std::string el_name, const std::string parent,command* def, int flag)
{
for(unsigned int i=0;i<el_name_list.size();++i)
{ // check if already there, not done in MAD-X make_element
if( el_name_list[i]==el_name)
{
element* elm=el_ptr[i]; // candidate, look at base
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << std::setw(4) << __LINE__ << " el_name=" << std::setw(10) << el_name << " base=" << elm->base_type->name << " base wanted=" << std::setw(10) << parent<< " already done " << '\n';
return elm;
}
}
element* new_elm=make_element(el_name.c_str(),parent.c_str(),def,flag);
el_name_list.push_back(el_name);
el_ptr.push_back(new_elm);
return new_elm;
}
void my_Element_List::Print(std::ostream &StrOut) const
{
StrOut << std::right;
for(unsigned int i=0;i<el_name_list.size();++i)
{
StrOut << std::setw(5) << i << std::setw(40) << el_name_list[i] << " " << el_ptr[i] << std::endl;
}
}
static command_parameter* par_scaled(const command_parameter* par_inp, const command_parameter* length_param, const std::string new_par_name, const int nslices)
{ // scale parmeter * length / nslices and give new name
command_parameter* par_out=nullptr;
if( par_inp && length_param )
{
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << std::setw(4) << __LINE__ << " par_inp: " << my_dump_command_parameter(par_inp);
par_out=clone_command_parameter(par_inp); // start from clone of input parameter
strcpy(par_out->name,new_par_name.c_str());
if (length_param->expr ) // first * l, expression or value
{
if(!par_out->expr) par_out->expr=my_get_param_expression(par_out);
par_out->expr = compound_expr(par_out->expr,par_out->double_value,"*",length_param->expr,length_param->double_value); // multiply expression with length
}
else
{
// if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << std::setw(4) << __LINE__ << " multiply par_out->double_value=" << par_out->double_value << '\n';
par_out->double_value *= length_param->double_value; // multiply value with length
// if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << std::setw(4) << __LINE__ << " now par_out->double_value=" << par_out->double_value << '\n';
}
if (nslices > 1) // 2nd step, divide by nslices, expression or number
{
if (par_out->expr) par_out->expr = compound_expr(par_out->expr,0.,"/",nullptr,nslices);
else par_out->double_value /= nslices;
}
if( MaTh::iMoreExpressions<1 && par_out->expr)
{
par_out->double_value=my_get_expression_value(par_out->expr);
par_out->expr=nullptr;
}
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __PRETTY_FUNCTION__ << " line " << std::setw(4) << __LINE__ << " par_out: " << my_dump_command_parameter(par_out) << '\n';
}
return par_out;
}
static bool thick_fl(const element* el) // true if the element has a thick parameter and if the value is positive, 0 otherwise
{
const command* el_def=el->def;
name_list* nl=el_def->par_names;
const int ei=name_list_pos("thick",nl);
return (ei > -1 && el_def->par->parameters[ei]->double_value > 0);
}
static std::string dump_slices(el_list* the_element_list) // Loops over all current elements and prints the number of slices. Used for debug and info
{
std::ostringstream ostr;
ostr << "++++++ dump_slices";
if(MaTh::Verbose>1)
ostr << " verbose on, all elements are listed" << '\n';
else
ostr << " only elements with non default selection (other than 1 thin) are shown" << '\n';
ostr << " name #slices derived from #slices" << '\n';
int n_elem_with_slice=0,n_elem_with_slice_gt_1=0;
for(int i=0; i< the_element_list->curr; ++i) // loop over the_element_list
{
element* el = the_element_list->elem[i];
const command* el_def=el->def;
name_list* nl=el_def->par_names;
const int ei=name_list_pos("slice",nl);
if(ei > -1) // element with slice number defined
{
n_elem_with_slice++;
const int slices=el->def->par->parameters[ei]->double_value;
int slices_parent=0;
std::string parent_name="no parent";
if(el->parent!=nullptr) // look also at parent if existing
{
slices_parent=el->parent->def->par->parameters[ei]->double_value;
parent_name=el->parent->name;
}
if(slices>1) n_elem_with_slice_gt_1++;
if(MaTh::Verbose>1|| slices !=1 || thick_fl(el)) // print all with verbose. with debug skip elements with default selection thin 1 slice
{
ostr << " " << std::setw(15) << el->name << " " << slices;
if(thick_fl(el)) ostr << " thick"; else ostr << " thin ";
if(el != el->parent)
{
ostr << " " << std::setw(18) << parent_name << " " << slices_parent; // show also parent if not same as child
if(thick_fl(el->parent)) ostr << " thick"; else ostr << " thin ";
}
ostr << std::endl;
}
}
}
if(MaTh::Verbose>1) ostr << " general option thin_foc=" << thin_foc_fl() << '\n'; // global option like debug or verbose, not element specific, still print here for info
ostr << "------ end of dump slices. There were " << std::setw(4) << the_element_list->curr << " elements, "
<< std::setw(3) << n_elem_with_slice << " with slice numbers and "
<< std::setw(2) << n_elem_with_slice_gt_1 << " with slice numbers>1\n\n";
return ostr.str();
}
static void force_consistent_slices(el_list* the_element_list) // hbu 10/2005 loop over all elements and check that #slices of child and parent agree, if not, use the maximum for both
{
for(int i=0; i< the_element_list->curr; ++i) // loop over the_element_list
{
element* el = the_element_list->elem[i];
const command* el_def=el->def;
name_list* nl=el_def->par_names;
const int ei=name_list_pos("slice",nl);
if(ei > -1 && el->parent!=nullptr && el != el->parent )
{
command_parameter* child=el_def->par->parameters[ei];
command_parameter* parent=el->parent->def->par->parameters[ei];
int slices=child->double_value;
int slices_parent=parent->double_value;
if(slices != slices_parent)
{
if(slices>slices_parent) slices_parent=slices; else slices=slices_parent;
child->double_value=slices;
parent->double_value=slices_parent;
int el_thick_pos = name_list_pos("thick",nl);
if(el_thick_pos > -1) el->parent->def->par->parameters[el_thick_pos]->double_value = el_def->par->parameters[el_thick_pos]->double_value; // copy thick flag from child to parent
}
}
}
}
static int get_slices_from_elem(const element* el)
{
int slices=1; // default
if(el)
{
name_list* nl=el->def->par_names;
const int ei=name_list_pos("slice",nl);
if( ei > -1) slices=el->def->par->parameters[ei]->double_value;
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " element " << el->name << " ei=" << ei << " slices=" << slices << '\n';
}
return slices;
}
static std::string make_thin_name(const std::string name_inp,const int slice) // make a node name from element name and slice number
{ // example e_name=mqxa.1r1 slice=1 result=mqxa.1r1..1
std::string name_out=name_inp+".."+std::to_string(slice);
if(name_out.length()>NAME_L)
{
warning(std::string("slice name is too long, truncated at "+std::to_string(NAME_L)+" characters").c_str(), name_out.c_str());
name_out=name_out.substr(0,NAME_L);
}
return name_out;
}
static command_parameter*
scale_and_slice(command_parameter* kn_param,const command_parameter* length_param,const int nslices,const bool mult_with_length,const int kl_flag) // multiply the k by length and divide by slice
{
int last_non_zero=-1;
if (kn_param == nullptr) return nullptr;
if (length_param == nullptr) return nullptr;
const double eps=1.e-15; // used to check if strength is compatible with zero
for (int i=0; i<kn_param->expr_list->curr; ++i)
{
expression* kn_i_expr = kn_param->expr_list->list[i];
double kn_i_val = kn_param->double_array->a[i];
// if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " kn_param->expr_list->curr=" << kn_param->expr_list->curr << " i=" << i << " kn_i_val=" << kn_i_val << " kn_i_expr=" << kn_i_expr << std::endl;
if ((kn_i_expr != nullptr && zero_string(kn_i_expr->string)==0) || fabs(kn_i_val)>eps )
{
last_non_zero=i;
if (kl_flag == 0 && (mult_with_length||i>0)) // apply mult_with_length only to zero order multipole
{
if (length_param->expr || kn_i_expr)
kn_i_expr = compound_expr(kn_i_expr, kn_i_val, "*", length_param->expr, length_param->double_value); // multiply expression with length
else kn_i_val *= length_param->double_value; // multiply value with length
}
if (nslices > 1) // give the correct weight by slice (divide by the number of slices)
{
if (kn_i_expr) kn_i_expr = compound_expr(kn_i_expr,kn_i_val,"/",nullptr,nslices);
else kn_i_val *= 1./nslices;
}
if(MaTh::Verbose>1)
{
std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " kn_i_val=" << kn_i_val << " kl_flag=" << kl_flag << " ";
if(kn_i_expr) std::cout << my_dump_expression(kn_i_expr) << '\n';
}
}
if(kn_i_expr) kn_param->expr_list->list[i] = kn_i_expr;
kn_param->double_array->a[i] = kn_i_val;
} // for i ..
if (last_non_zero==-1)
{
delete_command_parameter(kn_param);
kn_param=nullptr;
}
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " end" << std::endl;
return kn_param;
}
static void set_lrad(command* cmd,const command_parameter* length_param,const int nslices)
{ // to keep information of original length divided by nubmer of nslices
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " length_param=" << length_param << " nslices=" << nslices << '\n';
if(length_param)
{
name_list* nl=cmd->par_names;
const int ei=name_list_pos("lrad",nl);
if(ei>-1)
{
if(MaTh::Verbose>1) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " for lrad ei=" << ei << '\n';
command_parameter* l_par = cmd->par->parameters[ei] = clone_command_parameter(length_param); // keep what was l
strcpy(l_par->name,"lrad"); // rename to lrad
if (nslices > 1) // and divide numbers or expressions by the number of nslices
{
if (l_par->expr) l_par->expr = compound_expr(l_par->expr,0.,"/",nullptr,nslices);
else l_par->double_value /= nslices;
}
if( MaTh::iMoreExpressions<1 && l_par->expr)
{
double val=my_get_expression_value(l_par->expr);
l_par->double_value=val;
l_par->expr=nullptr;
}
nl->inform[ei]=1;
}
else if (MaTh::Verbose) std::cout << __FILE__ << " " << __FUNCTION__ << " line " << std::setw(4) << __LINE__ << " *** warning *** , element has no lrad, nothing done" << " length_param=" << length_param << " nslices=" << nslices << '\n';
}
}
static expression* curved_from_straight_length(const element* rbend_el)
{
expression* l_rbend_expr = my_get_param_expression(rbend_el,"l"); // get expression or create new from constant
expression* l_sbend_expr = nullptr;
if(rbarc_fl() && l_rbend_expr ) // increase the straight rbend length to sbend length
{ // RBEND, "l" parameter el_par_value("l","rbend") with rbarc on as default is the shorter straight length, val = l * angle / (two * sin(angle/two));
// this is also shown in twiss node and element length give always the curved length
// in going from rbend to sbend, this correction must be applied if the "l" expression is used, not for the value
std::string anglestr = my_get_cmd_expr_str( return_param_recurse("angle", rbend_el) );
const std::string rat = "1.0/sinc("+anglestr+"*0.5)"; // L_sbend / L_rbend
expression* rat_expr = new_expression(rat.c_str(),deco);
l_sbend_expr = compound_expr(l_rbend_expr,0,"*",rat_expr,0); // this also updates the value
if(MaTh::Verbose>1)
{
bool found=false;
double straight_length=my_get_int_or_double_value(rbend_el,"l",found);