Compute gradient for VOF
Suppose you have a VOF problem and you want to calculate the gradient of VOF. The solution provided here can be applied to other function as well. /************************************************************************* UDF used to calculate gradient for post-processing User defined scaler (UDS) and user defined memory (UDM) are used. For any UDS, fluent will automatically calculate the gradient. So, We need to pass the variable to UDS, and fluent will caculate the gradient for you. UDM is used to save the results. Steps to take to make it work 1. Read in the converged case and data 2. Link the udf (Define->User Defined->Functions->Intepreted) 3. Hook adjust funtion (Define->User Defined->Function Hooks->Adjust Function) 4. Define UDM (Define->User Defined->Memory 1) 5. Define UDS (Define->User Defined->Scalars 1) 6. Turn off all equations (Solve->Controls->Solution) 7. Do one iterations 8. Execute store_gradient (Define->User Defined->Execute On Demand) **************************************************************************/ # include "udf.h" # define domain_ID 2 DEFINE_ADJUST(adjust_gradient, domain) { Thread *t; cell_t c; face_t f; domain = Get_Domain(domain_ID); /* Fill UDS with the variable. */ thread_loop_c (t,domain) { begin_c_loop (c,t) { C_UDSI(c,t,0) = C_VOF(c,t); } end_c_loop (c,t) } thread_loop_f (t,domain) { if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL) begin_f_loop (f,t) { F_UDSI(f,t,0) = F_VOF(f,t); } end_f_loop (f,t) } } DEFINE_ON_DEMAND(store_gradient) { Domain *domain; cell_t c; Thread *t; domain=Get_Domain(1); /* Fill the UDM with magnitude of gradient. */ thread_loop_c (t,domain) { begin_c_loop (c,t) { C_UDMI(c,t,0) = NV_MAG(C_UDSI_G(c,t,0)); } end_c_loop (c,t) } } |
||
![]()
|