Conditional statement in ufl form

Hello everyone,

Currently I am trying to write function in ufl form, which contains term that is depending on if-elif-else statement.
I could deal with simpler problem with ‘conditional’ method for if-else cases.
However, I couldn’t find some methods when it comes to more-than-two cases, like if-elif-else cases.

The motivation of doing so is because some term differs by distance from the origin,

def distance_function(P):

        return sqrt(P[0]**2 + P[1]**2 + P[2]**2)

So, after writing this function for distance, I have to generate the distance-based term like

    class map_function():
        def __init__(self, impact_radii, sigma, eps_lower, eps_upper):
            self.impact_radii = impact_radii
            self.sigma = sigma
            self.eps_lower = eps_lower
            self.eps_upper = eps_upper
        def __call__(self, r_hat):
            dist = distance_function(r_hat)
            if dist < a:
                factor = 
            elif dist < b:
                factor = 
            else:
                factor = 
            return factor * r_hat

As you can see, I am trying to control the variable factor depending on the condition of dist.

While writing this form, I recalled that the variable dist was in the ufl form, which cannot be used with logical operator ‘<’. (If it were if-else cases, I would simply use the conditional method)

How can I solve this issue?
Thanks!

You would have to make a nested set of conditionals, ufl.conditional(ufl.lt(dist, a), output_1, ufl.conditional(ufl.lt(dist, b), output_2, output_3))

Never thought such way. Thanks always!