Force in UDF
Hey,
does anybody know who to include a force in an udf. I would like to write an iteration where the mass flow rate is raised if the force is to low and reduced if it is to high as a define force. By force i mean a force which takes place on a special part of my figure because of the fluid flow. Another question is how can i write down an iteration in an udf. I hope somebody can help me i tried to do this a long time and it does not work. Thank you! |
Hi,
For monitoring the force over a given surface you could use the function Compute_Force_and_Moment inside your UDF. It gives you the forces in the x, y and z direction and moments around the x, y and z axis. The function should be applied to a surface that is already defined in the mesh that you import into Fluent, it shouldn't be a surface that you only create in Fluent. Based on the resultant force/pressure/moment you could then calculate the new mass flow rate that you want. From there you can calculate the new inlet velocity that satisfies your updated mass flow rate. You can then change the inlet velocity using a DEFINE_PROFILE macro. Not sure what you mean by writing down an iteration in a UDF. Hope it helps, Dorit |
Alright thank you very much now i got an idea how i can solve my problem. Do you know exactly how to write/ inlcude a Compute_Force_And_Moment function into an udf, because i did not find any information about that. If you have an example which shows how to use the Compute_Force_And_Moment function that would be very helpful. Or do you know where i can find some information about using the Compute_Force_And_Moment function. As you see i am not very good in writing udfs.
Thank you very much for your help! J14 |
Yeah there's very little information on Compute_Force_And_Moment.
You could try something like this: The UDF will need to be compiled & hooked to the velocity inlet (if that's what you're using). #include "udf.h" DEFINE_PROFILE(update_velocity,t_inlet,i) { /* get moment or force */ Domain *d = Get_Domain(1); /* for single phase flow*/ Thread *t_object = Lookup_Thread(d, Boundary_ID); /* you get Boundary_ID from the boundary condition panel in Fluent*/ real force[ND_ND], moment[ND_ND], cg[ND_ND]; /*initialise*/ Compute_Force_And_Moment (d,t_object,cg,force,moment,TRUE) real force_x = force[0]; /* force components of surface "Boundary_ID" */ real force_y = force[1]; real force_z = force[2]; real moment_x = moment[0]; /* moment components */ real moment_y = moment[1]; real moment_z = moment[3]; /* use some equation to calculate new inlet velocity */ real v_new = ..........; /* update inlet velocity */ face_t f; begin_f_loop(f,t_inlet) /* loop over all faces at velocity inelt */ { F_PROFILE(f,t_inlet,i) = v_new; } end_f_loop(f,t_inlet) } |
Actually you'll need to find a different macro I think, cause you're running an unsteady simulation right? If so, then you'll need something that's called at the start of every time step. Don't think DEFINE_PROFILE is continuously updated. But the moment stuff should still work.
|
Compute_Force_And_Moment problem
Hi,
I am using 'Compute_Force_And_Moment' to calculate lift and drag acting on cylinder. Here is my udf it shows parse error at line 13, but when I comment lines, containing function "Compute_Force_And_Moment" and "v_new = 0.0*force[0];", it runs smoothly. Please help me...:o #include "udf.h" DEFINE_PROFILE(update_velocity,t_inlet,i) { /* get moment or force */ Domain *d = Get_Domain(1); /* for single phase flow*/ face_t f; Thread *t_object = Lookup_Thread(d,17); /* you get Boundary_ID from the boundary condition panel in Fluent*/ real force[3], moment[3], cg[ND_ND]; /*initialize*/ real force_y,v_new; Compute_Force_And_Moment (d,t_object,cg,force,moment,TRUE) v_new = 0.0*force[0]; // at this line parse error is coming!! /* update inlet velocity */ begin_f_loop(f,t_inlet) /* loop over all faces at velocity inelt */ { F_PROFILE(f,t_inlet,i) = v_new; } end_f_loop(f,t_inlet) } |
If you read Dorit's post above, it says:
"The UDF will need to be compiled" Did you do that, or did you interpret? |
Yes I tried both options "compiled and interpreted ". problem still exist.
In 'interpreted' it gives parse error at "v_new = 0.0*force[0];" . whereas in 'compiled case' it shows "'nmake' is not recognized as an internal or external command,", when I build it and during loading it gives "The UDF library you are trying to load (libudf2) is not compiled for 2ddp on the curent platform (win64).The system cannot find the file specified. F:\Newfolder\libudf2\win64\2ddp\libudf.dll" |
Quote:
You need to have a compiler installed, Ansys suggests to use Microsoft SDK, which is available for free. There are other threads on this forum (you can probably find them by searching for "nmake not recognized"), which explain how to get a proper installation. The problem might also be that you miss a semicolon, so try to change Code:
Compute_Force_And_Moment (d,t_object,cg,force,moment,TRUE) Code:
Compute_Force_And_Moment (d,t_object,cg,force,moment,TRUE); |
Now, I compiled my udf by accessing fluent from "Visual studio command promp(2010)". but it gives following error messenge:
Copied F:\Newfolder\velocityprofile1.c to libudf3\src (system "copy "C:\PROGRA~1\ANSYSI~1\v140\fluent"\fluent14.0.0\sr c\makefile_nt.udf "libudf3\win64\2ddp\makefile" ") 1 file(s) copied. (chdir "libudf3")() (chdir "win64\2ddp")() # Generating ud_io1.h velocityprofile1.c # Generating udf_names.c because of makefile velocityprofile1.obj udf_names.c # Linking libudf.dll because of makefile user_nt.udf udf_names.obj velocityprofile1.obj Microsoft (R) Incremental Linker Version 10.00.30319.01 Copyright (C) Microsoft Corporation. All rights reserved. Creating library libudf.lib and object libudf.exp velocityprofile1.obj : error LNK2019: unresolved external symbol __imp__Compute_Force_And_Moment referenced in function _update_velocity velocityprofile1.obj : error LNK2019: unresolved external symbol __imp__Lookup_Thread referenced in function _update_velocity velocityprofile1.obj : error LNK2019: unresolved external symbol __imp__Get_Domain referenced in function _update_velocity libudf.dll : fatal error LNK1120: 3 unresolved externals Done. |
For some reason, your compiler is not properly configured. It can not find the functions defined by Fluent.
Even the "Get_Domain" function can not be found. It probably has something to do with compiler settings/configuration of Fluent, but I can not tell what to change or even where to change something. |
Is it due to function (Compute_Force_And_Moment) can only be used in dynamic meshing?
because.... Now, I tried it on another system with SDK installed. running fluent through sdk. It compiles as well load udf smoothly without any error. but when I initialize the case it gives "Access Violation error " any help! |
Actually I am simulating unsteady flow over cylinder, lift generated at previous time step is used to calculate inlet velocity at current time-step.
|
So there is your problem: when you initialize, there is no "previous time step".
You could change the UDF to detect that, or more pragmatic: first initialize, and then attach this profile boundary condition. |
Hey.... Problem solved.
Thank you very much. :) |
It works fine in fluent running on SDK.
For initialisation error : Initially I am running few time step without udf and then introduce my udf for velocity correction. |
All times are GMT -4. The time now is 12:00. |