NimbleSM
NimbleSM is a solid mechanics simulation code for dynamic systems
Loading...
Searching...
No Matches
ExpressionParsing Namespace Reference

Classes

struct  BoundaryConditionFunctor
 
struct  DeletableObjectBaseClass
 
class  EquationContext
 
struct  Evaluatable
 
struct  GenericConstant
 
struct  GenericReference
 
class  MemoryManager
 
struct  Reader
 

Typedefs

typedef Evaluatable< double > RealValuedExpression
 
typedef GenericConstant< double > DoubleConstant
 
typedef GenericAdd< double, double, double > DoubleAdd
 
typedef GenericSubtract< double, double, double > DoubleSubtract
 
typedef GenericMultiply< double, double, double > DoubleMultiply
 
typedef GenericDivide< double, double, double > DoubleDivide
 
typedef GenericPow< double, double, double > DoublePow
 
typedef GenericMod< double, double, double > DoubleMod
 
typedef GenericPow< double, double, int > DoubleToIntegerPow
 
typedef Evaluatable< bool > BooleanExpression
 
typedef GenericConstant< bool > BooleanConstant
 
typedef Conditional< double > RealValuedConditional
 

Functions

 MakeGenericFunction (GenericSin, std::sin) MakeGenericFunction(GenericCos
 
std::cos MakeGenericFunction (GenericTan, std::tan) MakeGenericFunction(GenericErf
 
std::cos std::erf MakeGenericFunction (GenericExp, std::exp) MakeGenericFunction(GenericLog
 
std::cos std::erf std::log MakeGenericFunction (GenericAbs, std::abs) MakeGenericFunction(GenericASin
 
std::cos std::erf std::log std::asin MakeGenericFunction (GenericACos, std::acos) MakeGenericFunction(GenericATan
 
std::cos std::erf std::log std::asin std::atan MakeGenericFunction (GenericSqrt, std::sqrt) MakeGenericFunction(GenericCbrt
 
std::cos std::erf std::log std::asin std::atan std::cbrt MakeGenericFunction (GenericErfc, std::erfc) MakeGenericFunction(GenericCeil
 
std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil MakeGenericFunction (GenericRound, std::round) MakeGenericFunction(GenericFloor
 
std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor MakeGenericFunction (GenericLog10, std::log10) MakeGenericFunction(GenericNeg
 
std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor MakeGenericFunction (GenericNot, !) MakeGenericOperator(GenericAdd
 
std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor MakeGenericOperator (GenericMultiply, *) MakeGenericOperator(GenericDivide
 
std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor MakeGenericOperator (GenericSubtract, -) MakeGenericOperator(GenericGreater
 
std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor MakeGenericOperator (GenericGreaterOrEqual, >=) MakeGenericOperator(GenericLess
 
std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor<) MakeGenericOperator(GenericLessOrEqual,<=) MakeGenericOperator(GenericEqual,==) MakeGenericOperator(GenericInequal, !=) MakeGenericOperator(GenericAnd, &&) MakeGenericOperator(GenericXor, xor) MakeGenericOperator(GenericOr,||) MakeGenericTwoInputFunc(GenericPow, std::pow) MakeGenericTwoInputFunc(GenericMod, std::fmod) template< typename Out > struct Conditional :Evaluatable< Out > { Evaluatable< bool > *condition;Evaluatable< Out > *IfTrue;Evaluatable< Out > *IfFalse;operator Out() const { return(*condition) ?(*IfTrue) :(*IfFalse);} Conditional(Evaluatable< bool > *condition, Evaluatable< Out > *WhenTrue, Evaluatable< Out > *WhenFalse) :condition(condition), IfTrue(WhenTrue), IfFalse(WhenFalse) { } Evaluatable< Out > *optimize(MemoryManager &m) { Evaluatable< bool > *condition=this-> condition optimize (m)
 
 if (auto ConstCondition=dynamic_cast< GenericConstant< bool > * >(condition))
 
bool IsCMathFunc (Reader r)
 
RealValuedExpressionGetCMathFunc (Reader r, RealValuedExpression *input, MemoryManager &m)
 
bool IsDigit (char c)
 
bool IsInteger (Reader r)
 
bool IsNumber (Reader r)
 
void ConvertStringToLowercase (std::string &s)
 
void RemoveWhitespace (Reader &text)
 
void RemoveRedundantParenthesis (Reader &text)
 
void ApplyNecessaryFormatting (Reader &text)
 

Variables

Evaluatable< Out > * IfTrue = this->IfTrue->optimize(m)
 
Evaluatable< Out > * IfFalse = this->IfFalse->optimize(m)
 
this condition = condition
 
return this
 

Typedef Documentation

◆ BooleanConstant

◆ BooleanExpression

◆ DoubleAdd

typedef GenericAdd<double, double, double> ExpressionParsing::DoubleAdd

◆ DoubleConstant

◆ DoubleDivide

typedef GenericDivide<double, double, double> ExpressionParsing::DoubleDivide

◆ DoubleMod

typedef GenericMod<double, double, double> ExpressionParsing::DoubleMod

◆ DoubleMultiply

typedef GenericMultiply<double, double, double> ExpressionParsing::DoubleMultiply

◆ DoublePow

typedef GenericPow<double, double, double> ExpressionParsing::DoublePow

◆ DoubleSubtract

typedef GenericSubtract<double, double, double> ExpressionParsing::DoubleSubtract

◆ DoubleToIntegerPow

typedef GenericPow<double, double, int> ExpressionParsing::DoubleToIntegerPow

◆ RealValuedConditional

typedef Conditional<double> ExpressionParsing::RealValuedConditional

◆ RealValuedExpression

Function Documentation

◆ ApplyNecessaryFormatting()

void ExpressionParsing::ApplyNecessaryFormatting ( ExpressionParsing::Reader & text)
167{
168 if (text.IsEmpty()) return;
169 RemoveWhitespace(text);
171}
void RemoveWhitespace(Reader &text)
Definition nimble_expression_parser.cc:136
void RemoveRedundantParenthesis(Reader &text)
Definition nimble_expression_parser.cc:149
bool IsEmpty()
Definition nimble_expression_parser.h:489

◆ ConvertStringToLowercase()

void ExpressionParsing::ConvertStringToLowercase ( std::string & s)
127{
128 int len = s.size();
129 char* c = (char*)s.c_str();
130 for (int i = 0; i < len; i++) {
131 if (c[i] >= 'A' && c[i] <= 'Z') c[i] += 32;
132 }
133}

◆ GetCMathFunc()

61{
62 if (r == "sin") return m.New<GenericSin<double, double>>(input);
63 if (r == "cos") return m.New<GenericCos<double, double>>(input);
64 if (r == "tan") return m.New<GenericTan<double, double>>(input);
65 if (r == "erf") return m.New<GenericErf<double, double>>(input);
66 if (r == "exp") return m.New<GenericExp<double, double>>(input);
67 if (r == "log") return m.New<GenericLog<double, double>>(input);
68 if (r == "abs") return m.New<GenericAbs<double, double>>(input);
69 if (r == "asin") return m.New<GenericASin<double, double>>(input);
70 if (r == "acos") return m.New<GenericACos<double, double>>(input);
71 if (r == "atan") return m.New<GenericATan<double, double>>(input);
72 if (r == "sqrt") return m.New<GenericSqrt<double, double>>(input);
73 if (r == "cbrt") return m.New<GenericCbrt<double, double>>(input);
74 if (r == "erfc") return m.New<GenericErfc<double, double>>(input);
75 if (r == "ceil") return m.New<GenericCeil<double, double>>(input);
76 if (r == "round") return m.New<GenericRound<double, double>>(input);
77 if (r == "floor") return m.New<GenericFloor<double, double>>(input);
78 if (r == "log10") return m.New<GenericLog10<double, double>>(input);
79 return 0;
80}
T * New(In... inputs)
Definition nimble_expression_parser.h:86

◆ if()

ExpressionParsing::if ( auto ConstCondition = dynamic_cast<GenericConstant<bool>*>(condition))
343 {
344 if (ConstCondition->value) {
345 return IfTrue;
346 } else
347 return IfFalse;
348 }
Evaluatable< Out > * IfFalse
Definition nimble_expression_parser.h:342
Evaluatable< Out > * IfTrue
Definition nimble_expression_parser.h:341

◆ IsCMathFunc()

bool ExpressionParsing::IsCMathFunc ( ExpressionParsing::Reader r)
48{
49 if (r == "sin" || r == "cos" || r == "tan" || r == "erf" || r == "exp" || r == "log" || r == "abs" || r == "asin" ||
50 r == "acos" || r == "atan" || r == "sqrt" || r == "cbrt" || r == "erfc" || r == "ceil" || r == "round" ||
51 r == "floor" || r == "log10")
52 return true;
53 return false;
54}

◆ IsDigit()

bool ExpressionParsing::IsDigit ( char c)
84{
85 return c >= '0' && c <= '9';
86}

◆ IsInteger()

bool ExpressionParsing::IsInteger ( ExpressionParsing::Reader r)
90{
91 if (r.IsEmpty()) return false;
92 int len = r.length;
93 if (len == 1 && (r[0] == '-' || r[0] == '+')) return false;
94 if (r[0] != '-' && r[0] != '+' && !IsDigit(r[0])) return false;
95 for (int i = 1; i < len; i++)
96 if (!IsDigit(r[i])) return false;
97 return true;
98}
bool IsDigit(char c)
Definition nimble_expression_parser.cc:83
unsigned int length
Definition nimble_expression_parser.h:372

◆ IsNumber()

bool ExpressionParsing::IsNumber ( ExpressionParsing::Reader r)
102{
103 if (r.length == 0) return false;
104 r.pos = 0;
105 bool decimal = false;
106 bool digits = false;
107 if (r == '-' || r == '+') r.pos++;
108 while (r.pos < r.length) {
109 char c = r;
110 r.pos++;
111 if (IsDigit(c)) {
112 digits = true;
113 continue;
114 }
115 if (c == '.' && !decimal) {
116 decimal = true;
117 continue;
118 }
119 if (c == 'e' && digits) { return IsInteger(r.sub(r.pos, r.length)); }
120 return false;
121 }
122 return true;
123}
bool IsInteger(Reader r)
Definition nimble_expression_parser.cc:89
Reader sub(const char *start, const char *end)
Definition nimble_expression_parser.h:381
unsigned int pos
Definition nimble_expression_parser.h:373

◆ MakeGenericFunction() [1/10]

std::cos std::erf std::log ExpressionParsing::MakeGenericFunction ( GenericAbs ,
std::abs  )

◆ MakeGenericFunction() [2/10]

std::cos std::erf std::log std::asin ExpressionParsing::MakeGenericFunction ( GenericACos ,
std::acos  )

◆ MakeGenericFunction() [3/10]

std::cos std::erf std::log std::asin std::atan std::cbrt ExpressionParsing::MakeGenericFunction ( GenericErfc ,
std::erfc  )

◆ MakeGenericFunction() [4/10]

std::cos std::erf ExpressionParsing::MakeGenericFunction ( GenericExp ,
std::exp  )

◆ MakeGenericFunction() [5/10]

std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor ExpressionParsing::MakeGenericFunction ( GenericLog10 ,
std::log10  )

◆ MakeGenericFunction() [6/10]

std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor ExpressionParsing::MakeGenericFunction ( GenericNot ,
!  )

◆ MakeGenericFunction() [7/10]

std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil ExpressionParsing::MakeGenericFunction ( GenericRound ,
std::round  )

◆ MakeGenericFunction() [8/10]

ExpressionParsing::MakeGenericFunction ( GenericSin ,
std::sin  )

◆ MakeGenericFunction() [9/10]

std::cos std::erf std::log std::asin std::atan ExpressionParsing::MakeGenericFunction ( GenericSqrt ,
std::sqrt  )

◆ MakeGenericFunction() [10/10]

std::cos ExpressionParsing::MakeGenericFunction ( GenericTan ,
std::tan  )

◆ MakeGenericOperator() [1/3]

std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor ExpressionParsing::MakeGenericOperator ( GenericGreaterOrEqual ,
>=  )

◆ MakeGenericOperator() [2/3]

std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor ExpressionParsing::MakeGenericOperator ( GenericMultiply ,
*  )

◆ MakeGenericOperator() [3/3]

std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor ExpressionParsing::MakeGenericOperator ( GenericSubtract ,
-  )

◆ optimize()

std::cos std::erf std::log std::asin std::atan std::cbrt std::ceil std::floor<) MakeGenericOperator(GenericLessOrEqual,<=) MakeGenericOperator(GenericEqual,==) MakeGenericOperator(GenericInequal, !=) MakeGenericOperator(GenericAnd, &&) MakeGenericOperator(GenericXor, xor) MakeGenericOperator(GenericOr,||) MakeGenericTwoInputFunc(GenericPow, std::pow) MakeGenericTwoInputFunc(GenericMod, std::fmod) template< typename Out > struct Conditional :Evaluatable< Out > { Evaluatable< bool > *condition;Evaluatable< Out > *IfTrue;Evaluatable< Out > *IfFalse;operator Out() const { return(*condition) ?(*IfTrue) :(*IfFalse);} Conditional(Evaluatable< bool > *condition, Evaluatable< Out > *WhenTrue, Evaluatable< Out > *WhenFalse) :condition(condition), IfTrue(WhenTrue), IfFalse(WhenFalse) { } Evaluatable< Out > *optimize(MemoryManager &m) { Evaluatable< bool > *condition=this-> condition ExpressionParsing::optimize ( m )

◆ RemoveRedundantParenthesis()

void ExpressionParsing::RemoveRedundantParenthesis ( ExpressionParsing::Reader & text)
150{
151 text.pos = 0;
152 while (text == '(') {
153 text.Next('(', ')'); // Jumps to the closing parenthesis
154 if (text.pos == text.length - 1) {
155 text.first++;
156 text.length -= 2;
157 text.pos = 0;
158 } else {
159 text.pos = 0;
160 break;
161 }
162 }
163}
const char * first
Definition nimble_expression_parser.h:371
int Next(char open, char close)
Definition nimble_expression_parser.h:399

◆ RemoveWhitespace()

void ExpressionParsing::RemoveWhitespace ( ExpressionParsing::Reader & text)
137{
138 const char* first = text.first;
139 const char* last = first + text.length - 1;
140 if (*first != ' ' && *last != ' ') return;
141 while (*first == ' ' && first < last) first++;
142 while (*last == ' ' && last > first) last--;
143 text.first = first;
144 text.length = (last - first + 1);
145 return;
146}

Variable Documentation

◆ condition

this ExpressionParsing::condition = condition

◆ IfFalse

this ExpressionParsing::IfFalse = this->IfFalse->optimize(m)

◆ IfTrue

this ExpressionParsing::IfTrue = this->IfTrue->optimize(m)

◆ this

return ExpressionParsing::this