# Calculate a bubble average speed

Member

Hello everyone !

I am trying to calculate the average speed of a gas bubble in a liquid but I don't really know how to proceed... I think I should use a UDF (you will find it attached), I don't have any compilation error (so the grammar must be correct) but Fluent is crashing after an error message.

I am not used to creating a UDF, but I think I did everything as in the Ansys documentation.

• Member
edited July 23

I will put attached my error message.

By the way, I am pretty sure the error is happening at the very beginning of the code because my "test1" does not appear in the command window...

Thank you very much for your help !

Best regards,

Hugo

• GermanyForum Coordinator
edited July 23

• Member
edited July 23

Thank you for your answer, I understand, so here is the code :

#include "udf.h"

DEFINE_ON_DEMAND(on_demand_calc)

{

real u;

real uavg=0.;

int i;

int ph_index_gas = 3; /* This is the phase ID that has my gas in Fluent (foud in "phase") */

cell_t c;

Thread *mix_th, *subth; /* I believe mix_th is the mixture level thread pointer */

printf("\n test1 \n");

i=0;

/* Loop over all cells  */

begin_c_loop(c,mix_th)

{

printf("\n test2 \n");

u = C_U(c,mix_th);          /* get cell velocity */

uavg = uavg+u;

i = i+1;

}

end_c_loop(c,mix_th)

uavg = uavg/i;

printf("\n uavg = %g   u = %g   i = %g\n",uavg,u,i);

}

The error is a "received signal SIGSEGV"  type.

I am using a multiphase VOF model and the energy equation. The study is in 2D and the solver planar (so the bubble is more of an infinite cylinder).

Best regards,

Hugo

• GermanyForum Coordinator
edited July 23

UDF wrong as you are not getting first the right mixture thread just as hint. More information in the UDF manual: thread_sub_thread accepts the phase domain index as second argument which zero for primary phase.

By the way what you want to do in the UDF can be easily done via Report Definition and Volume Averaging or Sum Functions.

• Member
edited July 23

Oh ! So first I would like to ask you about the Report Definition because I looked there first. With that, I can have the Volume average speed, yes, but it is for the whole domain and not only for the air bubble (so taking into account all the liquid at rest)... Is there a way to isolate the average bubble speed ?

Best regards, Hugo

• GermanyForum Coordinator
edited July 23
Create an expression based report definition
• Member
edited July 23

Amine, I am so sorry I can't figure out what you want to make me understand !
By using this report section, I found the way to delete the velocity field in the liquid and to keep the one in the bubble (by multiplying the velocity field of the whole domain by the air volume fraction). But, then, if I use a volume or vertex average for the speed, this will be on the whole domain (meaning this is taking into account the liquid which as a velocity=0) and I don't know how to correct that...

Thanks,

Best regards, Hugo

• GermanyForum Coordinator
edited July 23
You can create a function like vof×velocity and average that in the domain so that it does only consider cells filled with vof.
• Member
edited July 23

Yes I see what you mean, but let's say my bubble as a uniform speed of 1m/s and occupies 1/4 of my domain. When I average this, I obtain a mean velocity of 1/4 m/s because the average function took into account the liquid. So it tells me that I have an average velocity of 0.25 m/s while we know the average velocity of the bubble is 1 m/s.

Best regards, Hugo

• GermanyForum Coordinator
edited July 24

For that reason you make a sum and not a volume average.You divide by the sum of cells containing that phase.

• Member
edited July 24

Obvioulsy ! Thank you very much for your patience Amine ! (for those interested, you can find the bubble surface in volume report -> Volume and select the gas phase, then you should know the size of your mesh and be able to deduce the number of cells in your bubble).

Best regards, Hugo