72 bool Or(
bool a,
bool b) {
return a || b; }
73 static const TFunction2<bool, bool> logOr = {
"||", 1,
Or};
75 bool And(
bool a,
bool b) {
return a && b; }
76 static const TFunction2<bool, bool> logAnd = {
"&&", 2,
And};
78 bool Le(
double a,
double b) {
return a <= b; }
79 static const TFunction2<bool, double> lessEqual = {
"<=", 3,
Le};
81 bool Lt(
double a,
double b) {
return a < b; }
82 static const TFunction2<bool, double> less = {
"<", 3,
Lt};
84 bool Ge(
double a,
double b) {
return a >= b; }
85 static const TFunction2<bool, double> greaterEqual = {
">=", 3,
Ge};
87 bool Gt(
double a,
double b) {
return a > b; }
88 static const TFunction2<bool, double> greater = {
">", 3,
Gt};
90 bool Eq(
double a,
double b) {
return a == b; }
91 static const TFunction2<bool, double> equal = {
"==", 3,
Eq};
93 bool Ne(
double a,
double b) {
return a != b; }
94 static const TFunction2<bool, double> notEqual = {
"!=", 3,
Ne};
99 double Neg(
double a) {
return -a; }
101 static const TFunction1<double, double> negate = {
"-", 5,
Neg};
103 double Sign(
double a) {
return (a > 0.) ? 1. : (a < 0.) ? -1. : 0.; }
109 }
while (std::abs(x) > a);
113 double Add(
double a,
double b) {
return a + b; }
115 static const TFunction2<double, double> plus = {
"+", 4,
Add};
117 double Sub(
double a,
double b) {
return a - b; }
119 static const TFunction2<double, double> minus = {
"-", 4,
Sub};
121 double Mpy(
double a,
double b) {
return a * b; }
123 static TFunction2<double, double> times = {
"*", 5,
Mpy};
125 double Div(
double a,
double b) {
134 static TFunction2<double, double> divide = {
"/", 5,
Div};
143 std::cout <<
"PartBuch valid" << std::endl;
145 std::cout <<
"PartBuch not valid" << std::endl;
161 static TFunction0<double> table0[] = {
164 {
"GAUSS", -2,
gauss},
173 static const TFunction1<double, double> table1[] = {
174 {
"TRUNC", -1, std::trunc}, {
"ROUND", -1, std::round}, {
"FLOOR", -1, std::floor},
175 {
"CEIL", -1, std::ceil}, {
"SIGN", -1,
Sign}, {
"SQRT", -1, std::sqrt},
176 {
"LOG", -1, std::log}, {
"EXP", -1, std::exp}, {
"SIN", -1, std::sin},
177 {
"COS", -1, std::cos}, {
"ABS", -1, std::abs}, {
"TAN", -1, std::tan},
178 {
"ASIN", -1, std::asin}, {
"ACOS", -1, std::acos}, {
"ATAN", -1, std::atan},
179 {
"TGAUSS", -2,
Tgauss}, {
"ERF", -1, std::erf}, {0, -1, 0}};
184 double Max(
double a,
double b) {
return std::max(a, b); }
186 double Min(
double a,
double b) {
return std::min(a, b); }
188 double Mod(
double a,
double b) {
189 if (b <= 0.0) errno = EDOM;
193 static TFunction2<double, double> power = {
"^", 6, pow};
195 static const TFunction2<double, double> table2[] = {{
"ATAN2", -1, atan2}, {
"MAX", -1,
Max},
196 {
"MIN", -1,
Min}, {
"MOD", -1,
Mod},
197 {
"POW", -2, pow}, {0, -1, 0}};
202 double Mina(
const std::vector<double>& array) {
204 double result = array[0];
205 for (std::vector<double>::size_type i = 1; i < array.size(); ++i) {
206 result =
Min(array[i], result);
210 std::cerr <<
"\n### Warning ### \"VMIN\" function of empty array.\n" << std::endl;
215 double Maxa(
const std::vector<double>& array) {
217 double result = array[0];
218 for (std::vector<double>::size_type i = 1; i < array.size(); ++i) {
219 result = std::max(array[i], result);
223 std::cerr <<
"\n### Warning ### \"VMAX\" function of empty array.\n" << std::endl;
228 double Rmsa(
const std::vector<double>& array) {
231 for (std::vector<double>::size_type i = 0; i < array.size(); ++i) {
232 result += array[i] * array[i];
234 return sqrt(result /
double(array.size()));
236 std::cerr <<
"\n### Warning ### \"VRMS\" function of empty array.\n" << std::endl;
241 double AbsMax(
const std::vector<double>& array) {
243 double result = std::abs(array[0]);
244 for (std::vector<double>::size_type i = 1; i < array.size(); ++i) {
245 result = std::max(std::abs(array[i]), result);
249 std::cerr <<
"\n### Warning ### \"VABSMAX\" function of empty array.\n" << std::endl;
353 return expr->evaluate();
357 std::string result = std::string(
"");
359 bool isWord = stat.
word(temp);
361 while (isWord || stat.
str(temp)) {
362 if (isWord && temp ==
"TO_STRING") {
366 std::ostringstream os;
374 isWord = stat.
word(temp);
377 if (result.empty()) {
378 std::string errorMsg(msg);
379 errorMsg = stat.
str() +
"\n" + errorMsg;
380 throw ParseError(
"Expressions::parseString()", errorMsg);
390 bool isWord = stat.
word(temp);
392 bool isConversion = isWord && temp ==
"TO_STRING";
394 while (stat.
str(temp) || isValidObject || isConversion) {
403 }
else if (isConversion) {
407 std::ostringstream os;
419 isWord = stat.
word(temp);
421 isConversion = isWord && temp ==
"TO_STRING";
424 if (result.empty()) {
425 std::string errorMsg(msg);
426 errorMsg = stat.
str() +
"\n" + errorMsg;
427 throw ParseError(
"Expressions::parseStringValue()", errorMsg);
486 std::vector<double> value = arg->evaluate();
497 std::vector<std::string> array;
517 "Expressions::parseDelimiter()",
518 std::string(
"Delimiter '") + delim +
"' expected.");
525 "Expressions::parseDelimiter()",
526 std::string(
"Delimiter '") + delim +
"' expected.");
531 if (stat.
keyword(
"SELECTED")) {
538 static char msg[] =
"Expected 'S' or 'E' after '#'.";
541 }
else if (stat.
keyword(
"E")) {
544 throw ParseError(
"Expression::parsePlace()", msg);
548 std::string name =
parseString(stat,
"Expected <name> or '#'.");
554 if (occurrence <= 0) {
556 "Expressions::parsePlace()",
557 "Occurrence counter must be positive.");
560 pos.
append(name, occurrence);
580 std::string objName =
parseString(stat,
"Object name expected.");
583 std::string attrName;
587 attrName =
parseString(stat,
"Attribute name expected.");
598 throw ParseError(
"Expressions::parseReference()",
"Index must be positive.");
607 std::string tabName =
parseString(stat,
"Table name expected.");
623 std::list<Token> result;
625 while (!stat.
atEnd()) {
632 || token.
isDel(
'}')) {
638 result.push_back(token);
640 if (token.
isDel(
'(')) {
642 }
else if (token.
isDel(
'[')) {
644 }
else if (token.
isDel(
'{')) {
653 std::vector<std::list<Token> > array;
709 }
else if (stat.
keyword(
"COLUMN")) {
711 }
else if (stat.
keyword(
"ROW")) {
713 }
else if (stat.
keyword(
"TABLE")) {
715 }
else if (stat.
real(value)) {
720 std::string frstName =
parseString(stat,
"Object name expected.");
733 }
else if (frstName ==
"EVAL") {
739 }
else if (
const ArrayFun* fun =
find(tablea, frstName)) {
746 "parseArrayPrimary()",
747 "Invalid array function name \"" + frstName +
"\".");
751 std::string scndName =
parseString(stat,
"Attribute name expected.");
758 result =
new ARow(frstName, row, cols);
760 throw ParseError(
"Expressions::parseReal()",
"Expected a column name.");
793 "Expressions::parseBracketList()",
794 "Parentheses, brackets or braces do not nest.");
798 result.push_back(token);
800 if (token.
isDel(
'(')) {
802 }
else if (token.
isDel(
'[')) {
804 }
else if (token.
isDel(
'{')) {
806 }
else if (token.
isDel(close)) {
834 }
else if (stat.
real(value)) {
842 std::string frstName =
parseString(stat,
"Real primary expected.");
854 }
else if (frstName ==
"EVAL") {
858 }
else if (
const ArrayFun* fun =
find(tablea, frstName)) {
863 "parsePrimary()",
"Unknown function name \"" + frstName +
"\".");
868 std::string scndName =
parseString(stat,
"Attribute or element name expected.");
883 std::string col =
parseString(stat,
"Column name expected.");
884 result =
new SCell(frstName, row, col);
886 throw ParseError(
"Expressions::parseReal()",
"Expected a column name.");
922 }
else if (stat.
boolean(value)) {
940 code = &greaterEqual;
948 throw ParseError(
"parseRelation()",
"Invalid boolean expression.");
982 std::string tabName =
parseString(stat,
"Table name expected.");
986 std::string colName =
parseString(stat,
"Column name expected.");
995 return new AColumn(tabName, colName, range);
1004 std::string tabName =
parseString(stat,
"Table name expected.");
1011 std::vector<std::string> columns;
1017 return new ARow(tabName, row, columns);
1044 "Expressions::parseTableGenerator()",
"Index set incorrect or missing.");
1048 if (frst <= 0 || last <= 0 || step <= 0) {
1049 throw ParseError(
"Expressions::parseTableGenerator()",
"Invalid array index set.");
1053 currentArray = std::make_unique<ATable>(frst, last, step);
Template PIC bunch: IPPL PicManager, shared field mesh/solver, and multiple particle containers.
virtual bool getBool() const
Return value.
An array expression with two array operands.
An array expression defined as a table column.
An array expression defined by a list of scalar expressions.
An expression defined as a reference to an array.
An array expression defined as a table row.
A scalar expression with one array operand.
An array expression with one array operand.
An array of pointers to scalar expressions.
A scalar expression to retrieve an indexed component from an array.
A pointer to an array expression.
A pointer to a scalar expression.
static Scalar< T > * make(const TFunction2< T, U > &, PtrToScalar< U > left, PtrToScalar< U > right)
Make a new expression.
A scalar expression referring to a table cell.
A scalar constant expression.
A scalar expression without operands.
static Scalar< T > * make(const TFunction0< T > &function)
Make expression.
An attribute defined as a reference to a scalar.
An expression defined as a reference to a scalar.
static Scalar< T > * make(const TFunction1< T, U > &function, PtrToScalar< U > operand)
Make a new expression.
The base class for all OPAL objects.
PartBunch_t * getPartBunch()
Object * find(const std::string &name)
Find entry.
static OpalData * getInstance()
Representation of a place within a beam line or sequence.
void append(const std::string &, int occur)
Add a name/occurrence pair.
void gauss(double &gr1, double &gr2)
Gaussian distribution.
double uniform()
Uniform distribution.
Representation of a range within a beam line or sequence.
static double arcIn()
Return arc length at entrance SI().
static double arcOut()
Return arc length at exit SO().
static double arcCtr()
Return arc length at center SC().
Interface for statements.
Token & getCurrent()
Return current token and skip it.
bool str(std::string &value)
Return string value.
void restore()
Return to marked position.
bool keyword(const char *s)
Test for keyword.
void mark()
Mark position in command.
bool word(std::string &value)
Return word value.
bool boolean(bool &value)
Return boolean value.
bool real(double &value)
Return real value.
bool atEnd() const
Test for end of command.
bool delimiter(char c)
Test for delimiter.
virtual std::string getString() const
Return value.
Representation of a table row reference.
The base class for all OPAL tables.
virtual Expressions::PtrToScalar< double > makeColumnExpression(const std::string &) const =0
Representation of a single input token.
bool isDel(char del) const
Test for delimiter.
Representation objects and parsers for attribute expressions.
std::string parseStringValue(Statement &, const char msg[])
double Add(double a, double b)
PtrToScalar< bool > parseBool(Statement &)
Parse boolean expression.
bool Ge(double a, double b)
TFunction1< double, const std::vector< double > & > ArrayFun
PtrToScalar< double > parseReal(Statement &)
Parse real expression.
bool Lt(double a, double b)
double Min(double a, double b)
PtrToArray< double > parseArrayTerm(Statement &stat)
double Max(double a, double b)
PtrToScalar< bool > parseAnd(Statement &stat)
double Div(double a, double b)
PtrToScalar< double > parseTerm(Statement &stat)
bool Eq(double a, double b)
PtrToArray< double > parseRealConstArray(Statement &)
Parse real array constant.
double Rmsa(const std::vector< double > &array)
PtrToArray< double > parseRowGenerator(Statement &stat)
double Mod(double a, double b)
std::vector< std::string > parseStringArray(Statement &)
Parse string array.
RangeRep parseRange(Statement &)
Parse range specification.
PlaceRep parsePlace(Statement &)
Parse place specification.
const T * find(const T table[], const std::string &name)
Look up name.
double Maxa(const std::vector< double > &array)
bool Ne(double a, double b)
SRefAttr< double > * parseReference(Statement &)
Parse variable reference.
std::vector< std::list< Token > > parseTokenListArray(Statement &)
Parse a token list array (for LIST commands).
PtrToArray< double > parseRealArray(Statement &)
Parse real array expression.
PtrToArray< double > parseArrayFactor(Statement &stat)
PtrToArray< double > parseTableGenerator(Statement &stat)
PtrToScalar< double > parseTableExpression(Statement &, const Table *)
Parse table expression (depends on a table's rows).
std::list< Token > parseTokenList(Statement &)
Parse a token list (for macro argument and the like).
double Mpy(double a, double b)
double AbsMax(const std::vector< double > &array)
TableRowRep parseTableRow(Statement &)
Parse a token list (for macro argument and the like).
std::string parseString(Statement &, const char msg[])
Parse string value.
PtrToScalar< bool > parseRelation(Statement &stat)
void parseBracketList(Statement &stat, char close, std::list< Token > &result)
PtrToArray< double > parseArrayPrimary(Statement &stat)
const Table * currentTable
double Mina(const std::vector< double > &array)
void parseDelimiter(Statement &stat, char delim)
Test for one-character delimiter.
PtrToScalar< double > parsePrimary(Statement &stat)
std::unique_ptr< ATable > currentArray
double Sub(double a, double b)
double parseRealConst(Statement &)
Parse real constant.
PtrToArray< bool > parseBoolArray(Statement &)
Parse boolean array expression.
PtrToArray< double > parseColumnGenerator(Statement &stat)
bool Gt(double a, double b)
bool Le(double a, double b)
PtrToScalar< double > parseFactor(Statement &stat)
An operand-less function returning a T.
A function of one U, returning a T.
A function of two U's returning a T.