|
[Sponsors] |
Variable Surface Tension Modelling UDF (Modifications to CSF) |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 8, 2021, 16:18 |
Variable Surface Tension Modelling UDF (Modifications to CSF)
|
#1 |
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 |
Hey,
I'm new to UDFs in FLUENT and am writing a UDF involving a modification in the interface curvature calculation part of the CSF model to smoothen it. So far, I've understood that C_VOF_G(c,t) can calculate gradient of volume fraction and NV_MAG(C_VOF_G(c,t)) can calculate magnitude of volume fraction. For the divergence part, will I have to save the unit normal in a UDS (C_UDSI) using a cell loop, and assign C_USDI_G to the interface curvature "k" to directly access the gradient of the scalar? I would also like to modify the property determination method for the VOF model as indicated in the picture. How would I be implementing this change on FLUENT? Also where would I be hooking both these UDFs exactly? |
|
March 23, 2021, 06:28 |
|
#2 | |
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 |
I've written a UDF for the surface tension force which I'm sharing below. I'm getting a bunch of errors that I've looked around for but am unable to resolve. Any help would be appreciated.
Code:
/*********************************************************************** UDF for defining surface tension source term and interface smoothening ************************************************************************/ #include "udf.h" DEFINE_SOURCE(surface_tension_force,c,t,dS,eqn) { /* Note that t is the mixture thread passed by the solver in this case */ Domain *d; real source; real k; /* interface curvature */ real ncap; /* unit normal */ real n; /* a function of the phase fraction */ real sigma = 0.072; /* surface tension coefficient */ real alphacell = C_UDMI(c,t,1); /* calculates the area averaged volume fraction of individual cell */ real rho1 = 1.225; /* Density of air */ real rho2 = 1; /* Density of non-Newtonian fluid */ C_UDSI(c,t,0) = alphacell; /* Fill UDS with the alphacell values to get gradient value */ n = C_UDSI_G(c,t,0); /* Get value of n as the gradient of alphacell (phase fraction) */ ncap = n/NV_MAG(n); /* calculate unit vector */ C_UDSI(c,t,1) = ncap; /* Fill another UDS with the variable ncap */ k = C_UDSI_G(c,t,1); /* Get value of k as the gradient of ncap */ source = sigma*k*C_R(c,t)*n/(0.5*(rho1+rho2)); /* Calculate the surface tension force */ dS[eqn] = 0; return source; } Quote:
|
||
March 23, 2021, 12:40 |
|
#3 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Ignoring the errors: your concept can not work.
You fill UDS, and want to get the gradient at the same time. How should that work after the first cell? How can Fluent calculate a gradient if only one cell has a value? I think you have to do this in three steps : 1. Fill UDS0 completely. 2.calculate UDS 1 completely as gradient. 3.calculate the source completely as gradient of UDS1. Even then, I'm not sure if this is the right approach, but I don't have enough time to think a better one.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". |
|
March 23, 2021, 14:35 |
|
#4 | ||
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 |
Quote:
However I'm still receiving the same errors and I'm not sure what they mean. I thought maybe it meant I can't store my UDS and UDS_G values in 'real' variables and also tried storing them in UDMs and not real variables like "n, ncap and k" as I've used below, but my errors remain the same irrespective of the approach. Below are my code and errors. All errors pertain to the lines involving calculation of n, ncap and k. Please suggest. Code:
/*********************************************************************** UDF for defining surface tension source term and interface smoothening ************************************************************************/ #include "udf.h" DEFINE_SOURCE(surface_tension_force,c,t,dS,eqn) { /* Note that t is the mixture thread passed by the solver in this case */ Domain *d = Get_Domain(1); /* defines the mixture domain */ real source; real k; /* interface curvature */ real ncap; /* unit normal */ real n; /* a function of the phase fraction */ real sigma = 0.072; /* surface tension coefficient */ real alphacell = C_UDMI(c,t,1); /* calculates the area averaged volume fraction of individual cell */ real rho1 = 1.225; /* Density of air */ real rho2 = 1; /* Density of non-Newtonian fluid */ /* Fill UDS with the alphacell values to get gradient value */ thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDSI(c,t,0) = alphacell; } end_c_loop(c,t) } /* Get value of n as the gradient of alphacell (phase fraction) */ thread_loop_c(t,d) { begin_c_loop(c,t) { n = C_UDSI_G(c,t,0); } end_c_loop(c,t) } ncap = n/NV_MAG(n); /* calculate unit vector */ /* Fill another UDS with the variable ncap */ thread_loop_c(t,d) { begin_c_loop(c,t) { C_UDSI(c,t,1) = ncap; } end_c_loop(c,t) } thread_loop_c(t,d) { begin_c_loop(c,t) { k = C_UDSI_G(c,t,1); /* Get value of k as the gradient of ncap */ } end_c_loop(c,t) } source = sigma*k*C_R(c,t)*n/(0.5*(rho1+rho2)); /* Calculate the surface tension force */ dS[eqn] = 0; return source; } Quote:
|
|||
March 23, 2021, 15:15 |
|
#5 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Your problem now is that gradient is a vector. You can not store that in a scalar.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". |
|
March 23, 2021, 15:23 |
|
#6 | |
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 |
Quote:
The below are the concepts I'm struggling with right now. 1. ncap is a vector that has the value ( n/NV_MAG(n) ), where n is also a vector. How would I perform the operation of dividing a vector by a scalar? As the command as it is gives me an error "error C2296: '/': illegal, left operand has type 'real [2]'" Is there a NV macro that can handle this? 2. I need to calculate the divergence of the vector ncap (or simply said - the Laplacian) and store it in k. How would I go about this? Last edited by Venky_94; March 24, 2021 at 00:24. |
||
March 25, 2021, 12:08 |
|
#7 | |
Member
Venkat Ganesh
Join Date: May 2020
Location: Cincinnati, Ohio
Posts: 49
Rep Power: 6 |
Quote:
I was able to achieve the first part using the command NV_VS(ncap, =, n, /, NV_MAG(n)). So now I have the unit vector ncap. All I need to do it figure out how to calculate the term ∇⋅ncap (divergence of the unit vector). Any suggestions would be great. |
||
May 28, 2024, 11:28 |
|
#8 |
New Member
Guilherme Luz
Join Date: Mar 2021
Posts: 2
Rep Power: 0 |
Deleted my own answer because coding was wrong. For anyone looking, this are two DEFINE_ADJUST functions to store and calculate the gradient of the VOF:
Of course, there are some things which need to be done in order for it to work (hooking the UDFs, defining the required UDSs in the GUI, enabling "keep shared memory", etc). Code:
DEFINE_ADJUST(store_vof_liquid, domain) { cell_t cell; face_t face; Thread **pt; Thread *cell_threads, *face_threads; #if !RP_HOST if(! Data_Valid_P()) { Message0("\n\n-------\nstore_vof_liquid: invalid data. Returning...\n-------\n\n"); return; } mp_thread_loop_c(cell_threads,domain,pt) { if(FLUID_THREAD_P(cell_threads)) { begin_c_loop(cell,cell_threads) { C_UDSI(cell,cell_threads,0) = C_VOF(cell,pt[1]); } end_c_loop(cell,cell_threads) } } mp_thread_loop_f(face_threads,domain,pt) { if(THREAD_STORAGE(face_threads,SV_UDS_I(0)) != NULL) { begin_f_loop(face,face_threads) { F_UDSI(face,face_threads,0) = F_VOF(face,pt[1]); } end_f_loop(face,face_threads) } } // Message0("\n\n-------\nstore_vof_liquid: end call. Returning...\n-------\n\n"); #endif } DEFINE_ADJUST(store_grad_vof_liquid, domain) { cell_t cell; Thread **pt; Thread *cell_threads; #if !RP_HOST if(! Data_Valid_P()) { Message0("\n\n-------\nstore_grad_vof_liquid: invalid data. Returning...\n-------\n\n"); return; } mp_thread_loop_c(cell_threads,domain,pt) { if(FLUID_THREAD_P(cell_threads)) { if(NULL != THREAD_STORAGE(cell_threads, SV_UDS_I(0)) && NULL != T_STORAGE_R_NV(cell_threads,SV_UDSI_G(0))) { begin_c_loop(cell,cell_threads) { C_UDSI(cell,cell_threads,1) = C_UDSI_G(cell,cell_threads,0)[0]; C_UDSI(cell,cell_threads,2) = C_UDSI_G(cell,cell_threads,0)[1]; #if RP_3D C_UDSI(cell,cell_threads,3) = C_UDSI_G(cell,cell_threads,0)[2]; #else C_UDSI(cell,cell_threads,3) = 0; #endif } end_c_loop(cell,cell_threads) } } } // Message0("\n\n-------\nstore_grad_vof_liquid: End call. Returning...\n-------\n\n"); #endif } Last edited by qwertyus; June 3, 2024 at 10:10. |
|
Tags |
interface curvature, surface tension model, udf, vof multiphase, volume fraction |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Surface tension UDF | Diconico | FLUENT | 3 | March 12, 2021 13:38 |
OpenFOAM error | Vinay Kumar V | Main CFD Forum | 0 | February 20, 2020 10:17 |
How to add Surface Tension in cavitatingFoam solver | jamestangx | OpenFOAM Programming & Development | 1 | April 6, 2016 17:39 |
Surface Tension Force Model | Miguel | CFX | 7 | October 2, 2006 06:30 |
UDF for surface tension gradient | kiran | FLUENT | 2 | July 15, 2003 13:00 |