24#ifndef UTILITIES_EXPR_H
25#define UTILITIES_EXPR_H
47 std::string describe()
const {
54 std::string describe()
const {
55 return std::to_string(value);
61 std::shared_ptr<Expr> lhs;
63 std::shared_ptr<Expr> rhs;
67 lhs{std::make_shared<
Expr>(lhs)},
69 rhs{std::make_shared<
Expr>(rhs)} { }
71 std::string describe()
const {
73 case Op::Add:
return "(" + lhs->describe() +
") + (" + rhs->describe() +
")";
74 case Op::Sub:
return "(" + lhs->describe() +
") - (" + rhs->describe() +
")";
75 case Op::Mul:
return "(" + lhs->describe() +
") * (" + rhs->describe() +
")";
76 case Op::Div:
return "(" + lhs->describe() +
") / (" + rhs->describe() +
")";
77 case Op::Pow:
return "Pow(" + lhs->describe() +
"," + rhs->describe() +
")";
78 default:
throw std::invalid_argument(
"Unsupported binary operation");
86 std::shared_ptr<Expr> arg;
91 arg{std::make_shared<
Expr>(arg)} { }
93 std::string describe()
const {
95 case Op::Sqrt:
return "sqrt(" + arg->describe() +
")";
96 case Op::Abs:
return "Abs(" + arg->describe() +
")";
97 case Op::Exp:
return "exp(" + arg->describe() +
")";
98 default:
throw std::invalid_argument(
"Unsupported unary operation");
103 std::variant<Symbol,Constant,Binary,Unary> _payload;
107 _payload(rhs._payload) { }
110 _payload(Constant{v}) { }
116 _payload(Symbol{name}) { }
119 _payload(Binary(lhs, op, rhs)) { }
122 _payload(Unary(op, rhs)) { }
126 std::visit([&out](
auto& x) {
139 _payload = Binary(*
this,
Op::Add, rhs);
144 _payload = Binary(*
this,
Op::Sub, rhs);
149 _payload = Binary(*
this,
Op::Mul, rhs);
154 _payload = Binary(*
this,
Op::Div, rhs);
175 return Expr(-1.) * rhs;
Basic value-substitute enabling extraction of expression trees for code generation.
std::string describe() const
Expr & operator*=(Expr rhs)
Expr(Expr lhs, Op op, Expr rhs)
Expr & operator-=(Expr rhs)
Expr & operator/=(Expr rhs)
Expr & operator+=(Expr rhs)
cpu::simd::Pack< T > sqrt(cpu::simd::Pack< T > value)
cpu::simd::Pack< T > pow(cpu::simd::Pack< T > base, cpu::simd::Pack< T > exp)
cpu::simd::Pack< T > fabs(cpu::simd::Pack< T > value)
ADf< T, DIM > exp(const ADf< T, DIM > &a)
Top level namespace for all of OpenLB.
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator-(U a, const ScalarVector< T, D, IMPL > &b) any_platform
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator+(U a, const ScalarVector< T, D, IMPL > &b) any_platform
constexpr meta::enable_if_arithmetic_t< U, Vector< decltype(T{} *U{}), D > > operator*(U a, const ScalarVector< T, D, IMPL > &b) any_platform
constexpr meta::enable_if_arithmetic_t< U, Vector< T, D > > operator/(const ScalarVector< T, D, IMPL > &a, U b) any_platform