UDF to modify gravity via M_gravity[ND_ND] or DEFINE_ADJUST
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. 
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 zmomentum source as gx and gy =0. Turn off gravity in operating conditions panel. 
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? 
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 cellbycell value.
ComputerGuy. Quote:

I would rather modify M_gravity... if I had a way to define M_gravity[2] as a function of z
Is this possible? 
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). Quote:

just a straight pipe along z and gravity 9.81m/s2 against z
massinlet and a pressure outlet Thank you for your time 
OK, here's what I have so far
Code:
#include "udf.h" 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 underrelaxation 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 Quote:

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 
No prob  wish this could've worked. I'd simply ask them about applying a userdefined function to gravity, as we've tried to do. It's a caseindependent 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 Quote:

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 
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. 
Hello,
I would like to know how did you charge the UDF gravity_source in the fluent graphical interface? Thank you. 
It would not be possible to be done via the graphical interface, rather, via a UDF

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. 
Previous posts above should help to explain... gravity_source in the UDF is recognized by Fluent as gravity along the zaxis

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 
You can also using the dT_CG(dt)[0]= ... for changing the CG location but you should use the 6DOF in your simulation.

All times are GMT 4. The time now is 23:47. 