Feel++ expressions

1. Mathematical functions

1.1. ceil

Description

ceil(v) computes the smallest integer value not less than arg.

Keyword

ceil

auto e = expr("ceil(u):u");

1.2. floor

Description

floor(v) computes the largest integer value not greater than arg.

Keyword

floor

auto e = expr("floor(u):u");

1.3. fract

Description

fract(v) compute the fractional part of the argument. This is calculated as \(v - floor(v)\).

Keyword

fract

auto e = expr("fract(u):u");

1.4. clamp

Description

clamp(v,lo,hi) If v compares less than lo, returns lo; otherwise if hi compares less than v, returns hi; otherwise returns v.

Keyword

clamp

auto e = expr("clamp(u,0,1):u");

1.5. Modulo

Description

mod(x,y) compute the modulo operation: it returns the remainder or signed remainder of the division \(x/y\).

Keyword

mod

auto e = expr("mod(u,v):u:v");
e.setParameterValues( { { "u", 2 }, { "v", 1 }} );
CHECK( std::abs( e.evaluate()(0,0) ) < 1e-12 ) << "Error in modulo";
e.setParameterValues( { { "u", 3 }, { "v", 6 }} );
CHECK( std::abs( e.evaluate()(0,0) - 3) < 1e-12 ) << "Error in modulo";
e.setParameterValues( { { "u", 6.1 }, { "v", 3 }} );
CHECK( std::abs( e.evaluate()(0,0) - 0.1) < 1e-12 ) << "Error in modulo";
}

1.6. sign

Description

sign(v) returns 1 if v positive, -1 if negative, 0 if v is zero. This is calculated as \((0 < v)- (v < 0)\).

Keyword

sign

auto e = expr("sign(u):u");

2. Mappings

2.1. mapabcd

mapabcd is the function \(f\) that allows to map \([a,b]\) to \([c,d]\), it is defines as follows

\[f(t) = c + \left(\frac{d-c}{b-a}\right)(t-a)\]

with \(f(a)=c\) and \(f(b)=d\).

auto e = expr("mapabcd(t,1,2,-1,1):t");
e.setParameterValues( { { "t", 1 } } );
CHECK( std::abs(e.evaluate()(0,0)- (-1)) < 1e-12 ) << "Invalid mapping";
e.setParameterValues( { { "t", 2 } } );
CHECK( std::abs( e.evaluate()(0,0)- 1 ) < 1e-12 ) << "Invalid mapping";
e.setParameterValues( { { "t", 1.5 } } );
CHECK( std::abs( e.evaluate()(0,0) ) < 1e-12 ) << "Invalid mapping";

3. Step functions

3.1. step1

3.2. smoothstep

Description

smoothstep(u,lo,hi) is calculated as follows:

\[\mbox{smoothstep}(x,lo,hi)=\left\{\begin{array}{ll}lo & x \leq lo \\ 3 x^{2}-2 x^{3} & lo \leq x \leq hi \\ hi & hi \leq x\end{array}\right.\]

smoothstep uses the clamp function

Keyword

smoothstep

"expr":"smoothstep(u,lo,hi):u:lo:hi"

3.3. triangle

3.4. rectangle

3.5. pulse

3.6. sinwave