User Expression for initial condition of Mixture Model Miscible Fluids

Dear Community,

I’m working on a project based on the mixture model for miscible fluids with non-newtonian behavior. I’ve implemented the model with my team, but we are having lots of trouble to initialize a complex concentration field. Basically we wish to obtain the contours from the (already grayscaled and blurred) image, then apply for each point of the domain the referent intensity value, thus initializing an “alpha field”. One can visualize it by initializing an image with a square in it and then using some sort of expression to assign the values into the referent function space.

However i am having lots of trouble with the process, as I am not familiar with “User Expressions”, and I couldn’t find any reference about multiphase flow so far. Consider the following scenario:

Coordinates = mesh.coordinates()
alpha = "array of alpha values (float - 0 to 1) obtained from mapping the image pixel by pixel"

grayScaleNormalized = [ Coordinates, intensity ]

The strategy we ended up was this:

for i in range(0,len(grayScaleNormalized)):
    for j in range(0, len(grayScaleNormalized[0])):
        expr = df.Expression('x[0] == X && x[1] ==Y  ?GS:GSB',X = grayScaleNormalized[i][0], Y = grayScaleNormalized[i][1], GS = grayScaleNormalized[i][2], GSB = c0, degree=2) 
        c0.assign(df.project(expr,C))

Obs1.: This is a non’functional code;
Obs2.: I tried to use the ‘near’ checking within the expression but it didn’t work out

The field is initialized, it takes several hours to initialize, as we imagined (even for a 100x100 image, we get a gigantic array).

I’m trying to understand how User Expressions work by the “demo-tensorweighted_poisson.py” example, but I cant figure out how to adapt the User Expression into my case. If someone could provide some detailed info about this event, I would appreciate. It might be a really easy problem to handle, but since I just started working with fenics, I’m still trying to figure out how it really works.

Thanks in advance everyone!

Hi, maybe you can Get some inspiration from: