CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Gradient of volume fraction(C_VOF_G) (https://www.cfd-online.com/Forums/fluent-udf/240253-gradient-volume-fraction-c_vof_g.html)

Cooper24 December 21, 2021 13:04

Gradient of volume fraction(C_VOF_G)
 
I request all the experts and the senior members on the forum that once and for all if you could confirm whether the following piece of code can be used to access the gradient of volume fraction(C_VOF_G) in a UDF. I have seen this piece of code somewhere being used for accessing the C_VOF_G but could not confirm the validity of the source.

Thread *t;
Thread **pt;
cell_t c;
int phase_domain_index = 1;
Domain *d = Get_Domain(1);
Domain *pDomain = DOMAIN_SUB_DOMAIN(d,phase_domain_index);
{
Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_N ULL);
Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL);
Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG, Vof_Deriv_Accumulate);
}

mp_thread_loop_c(t,d,pt)
if (FLUID_THREAD_P(t))
{
Thread *ppt = pt[phase_domain_index];
begin_c_loop (c,t)
{
C_UDMI(c,t,0) = C_VOF_G(c,ppt)[0];
C_UDMI(c,t,1) = C_VOF_G(c,ppt)[1];
C_UDMI(c,t,2) = C_VOF_G(c,ppt)[2];
C_UDMI(c,t,3) = sqrt(C_UDMI(c,t,0)*C_UDMI(c,t,0) + C_UDMI(c,t,1)*C_UDMI(c,t,1) + C_UDMI(c,t,2)*C_UDMI(c,t,2)); // magnitude of gradient of volume fraction
C_UDMI(c,t,4) = C_UDMI(c,t,0)/C_UDMI(c,t,3); // x gradient of volume fraction divided by magnitude of gradient of volume fraction
C_UDMI(c,t,5) = C_UDMI(c,t,1)/C_UDMI(c,t,3); // y gradient of volume fraction divided by magnitude of gradient of volume fraction
C_UDMI(c,t,6) = C_UDMI(c,t,2)/C_UDMI(c,t,3); //z gradient of volume fraction divided by magnitude of gradient of volume fraction
}
end_c_loop (c,t)
}
Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NU LL);
}

If this is not correct then what is the correct way of accessing C_VOF_G?

Thanks in advance

pakk December 21, 2021 13:52

If you want to know if this is correct, then... just try it, and see if it does what you want! You don't need "experts and senior members" for that! Open Fluent, compile the code, make a simple simulation with a VOF, and see if this code works.

If it does not work, explain here in what way it did not work (compile errors, crashing, wrong results, divergence, or something else), and we can help.

Cooper24 December 21, 2021 14:06

Thanks pakk for your reply. The code compiles without any error. Actually I am new to UDF writing and not an expert coder also. I learnt that C_VOG_G is not available as an inbuilt macro in fluent. When I run the simulation, the solution starts good but after a few steps it does not converge. So, I am unable to point out where the issue is. That's why I asked if the piece of code is right for storing C_VOF_G. Then atleast I would be sure that I can accessC_VOF_G using this code and the problem is somewhere else.

pakk December 21, 2021 18:03

Quote:

Originally Posted by Cooper24 (Post 818969)
When I run the simulation, the solution starts good but after a few steps it does not converge.

For next time: include this information with the question.

The code that you just showed only saves things in memory, it does not change the convergence in any way. So you must be doing something with these UDMs.

To find out where your problem comes from: don't do that something. Simulate a few iterations, and then plot the gradient of the VOF, and plot the VOF, and see if it looks more or less correct.

Cooper24 December 21, 2021 23:02

Thanks for your reply pakk. As I said I am new to UDF and to coding in general. I will do what you have suggested.
I just wanted to know whether the piece of code can be used to store C_VOF_G as the macro is not available as an inbuilt function in FLUENT. I hope it can be used to store C_VOF_G.

pakk December 22, 2021 04:04

I also hope that it is able to do that, but the way to find out is to test it. It does not matter if you are an expert or a beginner, I don't know why you feel the need to repeat that so many times.
If you want to know if something works: try it, and see if it does what you want. You do that for a car, you do that for a new recipe for a meal, and you also do that for software.

Cooper24 December 22, 2021 06:11

Thanks pakk for your encouragement. I will try what you have suggested. I can't say about others, but as I beginner I sometimes feel that if I try to do something out of book, I might destroy it beyond repair or might not be able to know the reason for destruction.
Anyways, thank you very much for all your help.

pakk December 22, 2021 11:20

There is a nice trick in Fluent: save your simulations before you experiment.
Then you can always go back to the point where it worked. The only thing you can lose is time, nothing can be damaged beyond repairs.


All times are GMT -4. The time now is 07:20.