I am trying to apply a boundary condition for which I have created the following Expression:
expr = Expression(
f"(x[0] < {ramp_start_x})? {disp_mag} : {disp_mag} * (10 - x[0]) / {10 - ramp_start_x}", degree=1
)
which is psuedo-code is as follows,
if x_coord < x_ramp_start:
x_disp = fixed_disp
else:
x_disp = linearly interpolated from fixed_disp to 0
I put degree = 1 since the maximum degree of the expression is 1.
However when I try to compute values from the expression, it’s not correct.
# Expression output for ramped drop in BCs at the top.
2.0, 2.0, 2.0, 2.0, 2.0, 2.0, **2.0, 1.344,** 1.2409, 1.13753, 1.0341, 0.93071, ... , 0.0
You can see that at the values in bold there is sudden drop (this is where the condition changes from true to false.), and then it ramps down to zero.
I have tried playing with the degree parameter for Expressions but that didn’t help. Honestly, I am not sure what the purpose of degree is exactly.
I converted the same thing to UserExpression object and it worked.
# Correct output (from UserExpression)
2.0, 2.0, 2.0, 2.0, 2.0, 2.0, **2.0, 1.9402,** 1.79104, 1.6417, 1.4925, 1.3432, ... , 0.0
I still want to know what’s wrong with Expression since we use it at many other places.
TIA