|
[Sponsors] |
UDF to modify gravity via M_gravity[ND_ND] or DEFINE_ADJUST |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 24, 2012, 11:26 |
UDF to modify gravity via M_gravity[ND_ND] or DEFINE_ADJUST
|
#1 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
Hello,
I have tried to modify the gravity vector in FLUENT. I need it to vary with altitude, but am having problems with the details how to accomplish this. Let's say that g = g(z), z is the altitude. Then it seems that one should use the DEFINE_ADJUST macro to modify M_gravity[ND_ND] I am unsure how to read M_gravity or how do I modify it. In the end, it should be altered to: M_gravity[0] = 0 M_gravity[1] = 0 M_gravity[2] = g(z) It was suggested that I could use DEFINE_SOURCE to add gravity as source I tried reading the help on this, but it is unclear how do I define the direction of gravity along z Does someone have experience with these... Thank you. |
|
January 24, 2012, 14:21 |
|
#2 |
Senior Member
duri
Join Date: May 2010
Posts: 245
Rep Power: 17 |
M_gravity[2] takes only one value, adding in define adjust will take only the last value it won't work.
Define_source should work and simple. #include "udf.h" DEFINE_SOURCE(gz_source,c,t,dS,eqn) { real x[ND_ND]; real source; C_CENTROID(x,c,t); // source = g(x)// gravity function of x cell centroid x=(x,y,z) source = source*C_R(c,t); dS[eqn] = 0.0; return source; } hook this to z-momentum source as gx and gy =0. Turn off gravity in operating conditions panel. |
|
January 24, 2012, 14:45 |
|
#3 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
Dear duri, thank you for your reply.
You define gravity in every mesh cell... Do I need to loop over all cells? Could gravity be defined globally? |
|
January 24, 2012, 18:59 |
|
#4 |
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16 |
Define source should loop over all cells for you (no need to program a loop); gravity can be defined globally with the M_gravity[0,1,or 2] term -- it is not a cell-by-cell value.
ComputerGuy. |
|
January 24, 2012, 19:11 |
|
#5 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
I would rather modify M_gravity... if I had a way to define M_gravity[2] as a function of z
Is this possible? |
|
January 24, 2012, 19:31 |
|
#6 |
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16 |
No, I don't think so, otherwise it would not "global"
ComputerGuy. p.s. I will have a look at your problem a bit later and let you know how to get it to converge. What does your geometry look like (simplify, if necessary). |
|
January 24, 2012, 19:34 |
|
#7 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
just a straight pipe along z and gravity 9.81m/s2 against z
mass-inlet and a pressure outlet Thank you for your time |
|
January 25, 2012, 15:34 |
|
#8 |
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16 |
OK, here's what I have so far
Code:
#include "udf.h" DEFINE_SOURCE(gravity_source,c,t,dS,eqn) { real gravity; real source; gravity = -9.81; source = gravity*C_R(c,t); return source; } With gravity turned off, and the UDF above hooked to the momentum source, I get a ~1e5 Pa pressure at the bottom (z=0). This is perfect. However the simulation isn't converging because the cells immediately adjacent to the inlet are predicted to have a very high velocity magnitude (10m/s). I suspect this has something to do with the way the boundary conditions there are handled. It's not clear to me why it's not predicting the correct behavior. I've tried a few different under-relaxation factor variants, as well as some other tricks. You might take this up with the folks at ANSYS. I would love to hear the answer. Sorry I couldn't help more -- at least we figured out that the UDF "works" ComputerGuy |
|
January 25, 2012, 17:49 |
|
#9 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
Dear ComputerGuy,
Highlty appreciate the time and effort... I will look at the case again and will talk to the people in my group as well; our admin could send the case to ANSYS and we'll see what they say. Or perhaps it is easier to use CFX to achieve the above -jpo |
|
January 25, 2012, 18:01 |
|
#10 |
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 16 |
No prob -- wish this could've worked. I'd simply ask them about applying a user-defined function to gravity, as we've tried to do. It's a case-independent problem. Up to v13, there's no hook to gravity, so I'm a little suspicious that it may require a different treatment than the simple method I proposed.
I'm very curious about the project/requirement for g(z). I would think that unless you're dealing with huge geometries where the force of gravity does significantly change with height, you could use a fixed value (globally applied to all cells in a given time step). If it's a transient situation (a rocket going into space), and you want to see the effect of changing gravity, you could simply change the gravitational force with time... Anyway, best of luck. I hope you can share the outcome here after you put it to rest. ComputerGuy |
|
January 25, 2012, 18:41 |
|
#11 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
Let me ask in my lab and see if we can get in touch with ANSYS... perhaps our prof can do that
I'll be sure to write how we solved it Many thanks |
|
April 24, 2012, 17:49 |
|
#12 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
the proposed udf did work:
#include "udf.h" DEFINE_SOURCE(gravity_source,c,t,dS,eqn) { real gravity; real source; gravity = -9.81; source = gravity*C_R(c,t); return source; } I have tried it with various constant gravity vectors and compared with identical cases without UDF, just enabled gravity with fluent menu. They matched in all parameters I looked at. Thus, I used the UDF to generate the variable gravity and it gave results we expected. |
|
June 20, 2012, 09:40 |
|
#13 |
New Member
Join Date: Jun 2012
Posts: 5
Rep Power: 14 |
Hello,
I would like to know how did you charge the UDF gravity_source in the fluent graphical interface? Thank you. |
|
June 20, 2012, 09:54 |
|
#14 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
It would not be possible to be done via the graphical interface, rather, via a UDF
|
|
June 20, 2012, 11:38 |
|
#15 |
New Member
Join Date: Jun 2012
Posts: 5
Rep Power: 14 |
Thanks for your reply.
Can you explain me how did you do for the Fluent to recognize the value defined by gravity_source as gravity? And is it g[0] or g[1]? In my case, I need to use a UDMI to calculate the components g[0] and g[1]. After, I will use this acceleration to calculate the flow in the domain. |
|
June 20, 2012, 13:44 |
|
#16 |
Member
Join Date: Apr 2009
Posts: 94
Rep Power: 17 |
Previous posts above should help to explain... gravity_source in the UDF is recognized by Fluent as gravity along the z-axis
|
|
June 21, 2012, 04:57 |
|
#17 |
New Member
Join Date: Jun 2012
Posts: 5
Rep Power: 14 |
I read almost all the topic, but I had not understood that. Thank you.
In my problem, I need to set the gravity in x, y and z cell by cell. Could you give me a simple example of how I can do that? Thank you in advance |
|
March 20, 2020, 13:29 |
|
#19 |
New Member
moon
Join Date: Feb 2012
Posts: 26
Rep Power: 14 |
I would like to know if this udf works to replace the gravity :
#include "udf.h" DEFINE_SOURCE(gravity_source,c,t,dS,eqn) { real gravity; real source; gravity = -9.81; source = gravity*C_R(c,t); return source; } I carried out many tests, but results are completely different |
|
March 20, 2020, 15:34 |
Gravity
|
#20 |
Senior Member
|
What is the objective of modifying the gravitational source? What exactly do you want to achieve?
Syntactically, UDF is correct. Fluent won't give any issue with it.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Modify the htc using UDF on NT | frederic | FLUENT | 1 | February 24, 2020 00:26 |
UDF to modify gravity vector ? | jpo | Fluent UDF and Scheme Programming | 3 | January 24, 2012 10:10 |
Error using UDF to modify density | NRD | FLUENT | 1 | July 13, 2011 08:35 |
Gravity, UDF Source & Operating Density. HELP ME! | Brian | FLUENT | 0 | November 1, 2005 16:17 |
How to modify velocity with UDF | jddmsh | FLUENT | 0 | June 28, 2003 22:59 |