|
[Sponsors] |
August 11, 2020, 04:23 |
Can you check my code of writing UDF?
|
#1 |
New Member
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6 |
Hello!I am writing a code in C-programming to make UDF for my problem. Of course, I do not know about the code at all, but I just look at some examples in the ANSYS UDF Manual,then I wrote this follow the manual. My purpose is to input mass flux(0.5 kg/m²s) of a species and diffusion coefficient(3E-05m²/s) of a species on a wall boundary, so can you check my code and correct it? Because I cannot compile this code to the Fluent. I am really struggling with this kind of code, because I never studied or wrote code before. Please help me. I will appreciate your help. My codes are as the following:
#include “udf.h” DEFINE_UDS_FLUX(my_uds_flux,f,t,i) { cell_t c0, c1=-1; Thread *t0, t1=NULL; real NV_VEC(psi_vec), NV_VEC(A), flux = 0.5; c0 = F_C0(f,t); t0 = F_C0_THREAD(f,t); F_AREA(A, f, t); /* If face lies at domain boundary, use face values; */ /* If face lies IN the domain, use average of adjacent cells. */ if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/ { real dens; /* Depending on its BC, density may not be set on face thread*/ if (NNULLP(THREAD_STORAGE(t,SV_DENSITY))) dens = F_R(f,t); /* Set dens to face value if available */ else dens = C_R(c0,t0); /* else, set dens to cell value */ NV_DS(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t), *, dens); flux = NV_DOT(psi_vec, A); /* flux through Face */ } else { c1=F_C1(f,t); /* Get cell on other side of face*/ t1=F_C1_THREAD(f,t); NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,C_R(c0,t0)); NV_DS(psi_vec, =, C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,C_R(c1,t1)); flux=NV_DOT(psi_vec, A)/2.0; /* Average flux through face*/ } /* ANSYS FLUENT will multiply the returned value by phi_f (the scalar's value at the face) to get the "complete'' advective term. */ return flux; } DEFINE_DEFFUSIVITY(tri_diff,c,t,i) { return C_R(c,t)*3.0e-05+C_MU_EFF(c,t)/0.7; } |
|
August 12, 2020, 09:28 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
code is this
Code:
#include "udf.h" DEFINE_UDS_FLUX(my_uds_flux,f,t,i) { cell_t c0,c1=-1; Thread *t0,*t1=NULL; real NV_VEC(psi_vec), NV_VEC(A), flux = 0.5; c0 = F_C0(f,t); t0 = F_C0_THREAD(f,t); F_AREA(A,f,t); if (BOUNDARY_FACE_THREAD_P(t)) { real dens; if (NNULLP(THREAD_STORAGE(t,SV_DENSITY))) dens = F_R(f,t); else dens = C_R(c0,t0); NV_DS(psi_vec,=,F_U(f,t),F_V(f,t),F_W(f,t),*,dens); flux = NV_DOT(psi_vec,A); } else { c1 = F_C1(f,t); t1 = F_C1_THREAD(f,t); NV_DS(psi_vec, = ,C_U(c0,t),C_V(c0,t),C_W(c0,t),*,C_R(c0,t0)); NV_DS(psi_vec, = ,C_U(c1,t),C_V(c1,t),C_W(c1,t),*,C_R(c1,t1)); flux = NV_DOT(psi_vec,A)/2.0; } return flux; } DEFINE_DIFFUSIVITY(tru_diff,c,t,i) { return C_R(c,t)*3.0e-05+C_MU_EFF(c,t)/0.7;; } but you don't need it, as it was made to calculate user defined scalar equation. in addition you have constant flux so you don't need UDF at all How the mass can get into your domain without any velocity? I can hardly imagine. I have no experience in this kind of simulations.
__________________
best regards ****************************** press LIKE if this message was helpful |
|
August 12, 2020, 10:30 |
Is it possible to input mass flux without velocity in UDF?
|
#3 | |
New Member
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6 |
Quote:
I think that in Fluent, if there is no velocity, flux will be automatically zero. If you are available, can I contact you through E-mail? Because I am a new user of this group, thus I do not know how to upload pictures to show my problem, I really want to show the boundary that I want to input mass flux of a species to you, it will make you more easily to know my problem. I think that I can input only the concentration in the expression instead of mass fraction of a species without writing code, then I can check my mass flux on that boundary by equation m=-(D*(dc/dy)), I really appreciate your help! @AlexanderZ: My Email: thaseanghai@gmail.com I just want to talk to you to get some opinions. Thank again! |
||
August 12, 2020, 23:07 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
the thing is, I have no experience in this kind of simulations, so most likely, Im not able to help you.
try to continue this thread. to share pictures here upload it on any online storage, for example https://upload.photobox.com/en/ and put link in your message
__________________
best regards ****************************** press LIKE if this message was helpful |
|
August 13, 2020, 02:46 |
Anyway, thank for your reply! I will try to upload my problem figure here
|
#5 | |
New Member
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6 |
Quote:
|
||
August 13, 2020, 03:24 |
Here are the boundary's names.
|
#6 | |
New Member
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6 |
Quote:
2. https://www.photobox.co.uk/my/photo/...d=503161122047 3. https://www.photobox.co.uk/my/photo/...d=503161121568 4. https://www.photobox.co.uk/my/photo/...d=503161121848 You can see the 4 above pictures and I will describe all the info. about each boundary as the following: 1. Inlet: at the inlet, I input only X-velocity of air(1m/s). 2. Outlet: just work in the atmospheric pressure.(101325Pa) 3. Species-wall: on the species wall, I want to input mass flux of a species without velocity, but I realized that on the species wall, there are X-velocities coming from the inlet and Y-velocity is zero. I am curious about this point, can X-velocity coming from the inlet create the mass flux on the species wall? For my test without writing code, I just enable the species model and use it, at the species wall, I input the only concentration(kmol/m³), not mass flux(kg/m2s), then can ANSYS Fluent calculate mass flux from the concentration which I input? 4. Wall: Stationary wall, specified shear stress=0 Pa, and i input zero diffusivity to this boundary. Therefore, what I am curious about is number 3. Species wall. Thank you and I hope you will look at it and if you have any suggestion, please tell me. |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to Mix AIR and WATER | Elvis1991 | FLUENT | 12 | December 1, 2016 13:28 |
having problem in writing a UDF for specific heat in fluent 14.0 | nands_bullwalker | Fluent UDF and Scheme Programming | 1 | June 29, 2013 11:32 |
critical error during installation of openfoam | Fabio88 | OpenFOAM Installation | 21 | June 2, 2010 04:01 |
correct UDF code for unsteady pressure boundary | James W | FLUENT | 0 | November 2, 2005 12:38 |
Design Integration with CFD? | John C. Chien | Main CFD Forum | 19 | May 17, 2001 16:56 |