|
[Sponsors] |
October 21, 2020, 18:21 |
read volume fraction for a coordinate
|
#1 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
Dear All,
I need to write a UDF code that reports volume fraction value for a coordinate ( or could be a node ) within a two-phase flow problem at a certain time, I have the following code, I have two issues: 1) I don't know how to make the UDF print the result at the console, is " printf" the correct way to request the UDF to print to the console? 2) Is this the right way to set up the time? How can I request to report the volume fraction at end of each time step? #include "udf.h" DEFINE_ON_DEAMND(volume_fraction) { real current_time; current_time=CURRENT_TIME; real volume_fraction; Domain *mixture_domain; mixture_domain=Get_Domain(1); cell_t c; thread *t; thread **pt; volume_fraction=c_VOF(c,pt[1]); } printf("\n volume_fraction % g",volume_fraction) Truly appreciate any advice. |
|
October 23, 2020, 05:22 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
you may try this code, COMPILE IT, allocate 2 user defined variables in fluent GUI so you can plot vol_frac distribution along the domain
Code:
#include "udf.h" DEFINE_ON_DEAMND(volume_fraction) { Domain *domain; cell_t c; Thread *mix_thread,*thread_g, *thread_s; real current_time; domain=Get_Domain(1); /* find the threads for the gas (primary) */ /* and solids (secondary phases) */ current_time=CURRENT_TIME; thread_loop_c (mix_thread,domain) { begin_c_loop (c,mix_thread) { thread_g = THREAD_SUB_THREAD(mix_thread, 0);/* gas phase */ thread_s = THREAD_SUB_THREAD(mix_thread, 1);/* solid phase*/ void_g = C_VOF(cell, thread_g);/* gas vol frac*/ void_s = C_VOF(cell, thread_s);/* solid vol frac*/ C_UDMI(c,mix_thread,0) = void_g; C_UDMI(c,mix_thread,1) = void_s; Message0("volume_fraction of phase 0: %f | volume_fraction of phase 1: %f \n",void_g,void_s); } end_c_loop (c,mix_thread) } }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
October 23, 2020, 05:28 |
|
#3 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
also you may try something like this, to write to file
Code:
#include "udf.h" FILE *fout; void Print_vol_fraction(Domain *domain, int id) { cell_t c; real vol_frac; Thread *t = Lookup_Thread(domain, id); fprintf(fout,"thread id %d\n", id); begin_c_loop(c,t) { vol_frac = C_VOF(c, t); fprintf(fout, "c vol_frac: %f\n", c, vol_frac); } end_f_loop(c,t) fprintf(fout, "\n"); } DEFINE_ON_DEMAND(get_coords) { Domain *domain; domain = Get_Domain(1); fout = fopen("faces.out", "w"); Print_vol_fraction(domain, 0); Print_vol_fraction(domain, 1); fclose(fout); }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
October 23, 2020, 14:37 |
|
#4 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
Thanks, AlexanderZ for your help, this is very helpful.
Would you also know how this code can be used to print the volume fraction in only one certain point (with given coordinate values of x,y,z ). I looked into the C_CETROID and Grid variables but couldn't make it to specify a point. Here is how I tried to specify a point : real xc[ND_ND]; C_CENTROID(xc,cell,cell_thread); I think I need to use an "if" statement here to specify the point location? Thanks Henry |
|
October 26, 2020, 08:55 |
|
#5 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
last code will look like this:
Code:
#include "udf.h" FILE *fout; void Print_vol_fraction(Domain *domain, int id) { cell_t c; real vol_frac; real x[ND_ND]; real point = {0.1,0.1,0.1}; real delta = 0.05; Thread *t = Lookup_Thread(domain, id); fprintf(fout,"thread id %d\n", id); begin_c_loop(c,t) { C_CENTROID(x,c,t); // here x[0] - coord along x-axis, x[1] - coord along y-axis, x[2] - coord along z-axis (if 3D) vol_frac = C_VOF(c, t); if ((x[0] > point[0]-delta) && (x[0] <= point[0]+delta)) if ((x[1] > point[1]-delta) && (x[1] <= point[1]+delta)) if ((x[2] > point[2]-delta) && (x[2] <= point[2]+delta)) fprintf(fout, "c vol_frac: %f\n", c, vol_frac); } end_f_loop(c,t) fprintf(fout, "\n"); } DEFINE_ON_DEMAND(get_coords) { Domain *domain; domain = Get_Domain(1); fout = fopen("faces.out", "w"); Print_vol_fraction(domain, 0); Print_vol_fraction(domain, 1); fclose(fout); }
__________________
best regards ****************************** press LIKE if this message was helpful |
|
October 27, 2020, 17:19 |
|
#6 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
Very Helpful Alexander Z, thanks for your support.
|
|
November 22, 2020, 03:56 |
|
#7 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
AlexanderZ
I am working on a 2 phase flow model and following all steps to generate the air fraction which is a bubble inside a channel. Then patch, initialize, and check contours for air phase, fluent doesn't show the air bubble. I am not sure what I do wrong but I have done this before and I did not have a problem with this part. Please let me know if you can help, this is very frustrating. Thanks Hanry |
|
November 22, 2020, 23:55 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
initialize first, than patch, make sure you are not initializing case after patching it
__________________
best regards ****************************** press LIKE if this message was helpful |
|
November 23, 2020, 16:31 |
|
#9 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
AlexanderZ,
I truly appreciate your help, one small mistake made me redo the model many times. Thanks again. |
|
January 21, 2021, 23:54 |
UDF compiling Error
|
#10 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
Dear AlexanderZ,
It is been a while I see this error and have been looking to fix it, some says it is a visual studio issue, I would like to ask if you know how to make the files compiled, I get this error for compiling, the interpreting has its own issues, so it would be great if I could compile the files instead, but here it goes : The error in windows : The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64). |
|
January 22, 2021, 00:35 |
|
#11 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Code:
The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64). compile UDF file
__________________
best regards ****************************** press LIKE if this message was helpful |
|
January 23, 2021, 17:44 |
|
#12 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
Does that mean my code has issues?
I have tried to compile simple files, still get the same error. Thanks Hanry |
|
January 23, 2021, 17:46 |
|
#13 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
What do you suggest I should do ?
|
|
January 24, 2021, 04:03 |
|
#14 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
This is not the error that you see when you try to compile ;this is the error when you try to load. (read it!)
Look at the error(s) when you compile. |
|
January 25, 2021, 04:06 |
|
#15 |
New Member
Join Date: Mar 2018
Posts: 11
Rep Power: 8 |
Hi PAKK,
I agree, it is the error when loading, but does that mean the code has an issue that its why it is not compiling? Thanks Hanry |
|
January 27, 2021, 02:40 |
|
#16 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
It literally says that the code is not compiled. It does not say the reason, that's why I tell you to look what happens when you try to compile. There you should see the reason.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Simulation crashes when turbulence is on (reactingMultiphaseEulerFoam) | remidemol | OpenFOAM Running, Solving & CFD | 3 | May 26, 2020 06:47 |
Is it possible that multi-phase flow shows gradation of volume fraction? | kjh9537 | Fluent UDF and Scheme Programming | 0 | June 23, 2017 15:16 |
volume fraction = nan | Virtual-iCFD | OpenFOAM Running, Solving & CFD | 8 | June 12, 2015 19:15 |
Water subcooled boiling | Attesz | CFX | 7 | January 5, 2013 04:32 |
[blockMesh] error message with modeling a cube with a hold at the center | hsingtzu | OpenFOAM Meshing & Mesh Conversion | 2 | March 14, 2012 10:56 |