|
[Sponsors] |
May 13, 2016, 06:13 |
UDF for variable surface tension on VOF
|
#1 |
New Member
Omar E. Godinez
Join Date: May 2016
Posts: 8
Rep Power: 10 |
Hello everyone,
I am very new to UDF coding in Fluent so I hope this is not a silly question, similar threads I've seen seem inconclusive or answers are not really applicable to my case. Basically, I want to write a UDF that assigns a different surface tension based on the concentration of a solute. My system has two phases, main phase has two components ( species transport model is enabled) and secondary phase has only one component. I am confused because I don't know if it is necessary to actually access mass fraction data for a particular phase. I keep on getting access violation errors . proposed UDF should have a structure similar to this (I know it is wrong as it is) #include "udf.h" DEFINE_PROPERTY(Custom_Surface_Tension,c,t) { real sigma,xm; xm=C_YI(c,t,1); /*some equation*/ sigma=-.02428*(xm)*(xm)*(xm)+.3759*(xm)*(xm)-.0415 return sigma; } I guess the main problem is that I am trying to read, for example, mass fraction data from the entire thread instead of only reading it from a main phase thread... Questions are in summary: 1.-Is it necessary to get the mass fraction from the main phase thread specifically? and if so, how can I control it such that It doesn't try to assign values to cells belonging to the secondary phase thread?. I've tried accessing secondary phase via THREAD_SUB_THREAD and reading C_VOF for the secondary phase to use it in an 'if' statement so as to separate it, but I get the same error. 2.-Is there another way of evaluating cells from each phase individually?, maybe with some sort of loop? 3.-Can surface tension be modified by addressing the interaction subdomain between each phase domain? and if so, how? 4.-Maybe the silliest of my questions but anyway: Would a function like this require compiling or is the interpreter enough? Thanks in advance. |
|
May 13, 2016, 18:59 |
|
#2 |
New Member
Omar E. Godinez
Join Date: May 2016
Posts: 8
Rep Power: 10 |
I have continued to try, now my UDF looks like this
#include "udf.h" DEFINE_PROPERTY(Custom_Surface_Tension,c,t) { real sigma,xm,vf1,vf2; Thread *Main_phase_thread=THREAD_SUPER_THREAD(t); Thread *main_phase=THREAD_SUB_THREAD(Main_phase_thread,0) ; Thread *secondary_phase=THREAD_SUB_THREAD(Main_phase_thre ad,1); vf1=C_VOF(c,main_phase); vf2=C_VOF(c,secondary_phase); if(vf1>vf2) { xm=C_YI(c,main_phase,0); sigma=-.02428*(xm)*(xm)*(xm)+.3759*(xm)*(xm)-.0415*(xm)+.0073; } else { sigma=0.05; } return sigma; } I have found that the default thread addressed in the DEFINE_PROPERTY macro for this property is in fact the main phase thread, so in order to access the secondary phase I have accessed the corresponding superthread, and then accessed each phase individually. Then, I get the volume fraction for each phase and compare them, if the main value is bigger, then I want to use the equation, otherwise I want to assign a constant value. Apparently it works, since if I add a couple of printf's I can see that I am actually calculating individual values of sigma for each cell in the first iteration, however it still crashes and brings back the "access violation" error. Maybe it is failing to return the sigma value? has anyone seen anything similar? |
|
May 15, 2016, 09:37 |
|
#3 |
New Member
Omar E. Godinez
Join Date: May 2016
Posts: 8
Rep Power: 10 |
I have continued to investigate on my own, I will update the post in case anyone can relate somehow and possibly help.
Apparently the problem is related to the thread Fluent passes over to the UDF by default. I am getting concentration results and surface tension evaluations only in the cells that belong to the wall (a boundary zone in the outline of the model, adjacent only to the main phase, I have the exact same number of evaluations displayed before I get the access violation error). My guess is Fluent maybe tries to identify the interface as an interaction domain zone_id from the boundary conditions, then it takes whatever it thinks the interface zone_id is and sends its corresponding thread to the surface tension evaluation. I think this is what is happening because my actual interface is not defined as a zone in fluent, the secondary phase was inserted using adapt>region>mark and then I patched the region. does anybody know how fluent manages or identifies interaction threads? maybe that's the source of the issue. Also, if this can be sorted from the geometry by defining the interface, how should I define the interface boundary condition? |
|
June 18, 2022, 02:08 |
Concentration Based - Variable Surface Tension Coefficient
|
#4 |
New Member
Brian Huffman
Join Date: Jun 2022
Posts: 4
Rep Power: 4 |
Hey there Omar, and anyone it may help. I know this reply is about 6 years too late, but this post helped me on my journey and I would like to answer.
I have the same objective as this post states, to write a UDF that controls the surface tension coefficient by analyzing the mixture species fraction. The following code seems to be the answer: DEFINE_PROPERTY(Custom_Surface_Tension, c, t) { Domain *mix; mix = Get_Domain(1); Thread *mix_thread = Lookup_Thread(mix, 2); Thread *sec_phase = THREAD_SUB_THREAD(mix_thread,1); real sigma, xm; xm = C_YI(c,sec_phase,1); sigma = 0.043*xm*xm - 0.1081*xm + 0.0702; return sigma; } The key part being the first 4 lines of code: Lines 1-2. grab the mixture domain pointer (domain ID=1 for mixture domain) & assign variable *mix. Line 3. Find the relevant thread (domain ID=1 for mixture, Zone ID=2 for fluid), assign the lookup to a variable *mix_thread (this is a mixture level thread) Line 4. Assign a phase level pointer (*sec_phase) to secondary phase thread *sec_phase now has the required data to proceed with mass fraction function C_YI |
|
Tags |
surface tension, udf, vof |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Weld surface deformation by VOF model | minhaj_iut | FLUENT | 5 | February 27, 2017 00:51 |
Help!! customize surface tension term in interFoam | w051cxw | OpenFOAM Programming & Development | 5 | February 12, 2016 15:56 |
Help!! customize surface tension term in interFoam | w051cxw | OpenFOAM Running, Solving & CFD | 0 | February 12, 2016 02:15 |
surface tension gradient using UDF; surface tension gradient as function of temperatu | marimuthusundar | Fluent UDF and Scheme Programming | 0 | June 21, 2012 05:48 |
Surface tension gradient - Marangoni stress- through UDF | marimuthusundar | FLUENT | 0 | October 11, 2010 10:07 |