CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)

 jpo January 24, 2012 11:26

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.

 duri January 24, 2012 14:21

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.

 jpo January 24, 2012 14:45

You define gravity in every mesh cell...
Do I need to loop over all cells?

Could gravity be defined globally?

 ComputerGuy January 24, 2012 18:59

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.

Quote:
 Originally Posted by jpo (Post 340931) 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?

 jpo January 24, 2012 19:11

I would rather modify M_gravity... if I had a way to define M_gravity[2] as a function of z
Is this possible?

 ComputerGuy January 24, 2012 19:31

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

 jpo January 24, 2012 19:34

just a straight pipe along z and gravity 9.81m/s2 against z
mass-inlet and a pressure outlet

 ComputerGuy January 25, 2012 15:34

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; }```
I created a 10m vertical (z-direction) pipe, with a mass inlet at the bottom (z=0) and a pressure outlet (P=0 Pa gauge) at the top (z=10). The material is water (rho=1000 kg/m3). I have used a low viscosity, so that we won't get additional pressure losses from friction, and set the mass flow to be quite low (0.01 kg/s) in a pipe with a radius of 1m (very large). I initialize the simulation close to the "exact" answer for pressure and velocities.

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

Quote:
 Originally Posted by jpo (Post 340967) just a straight pipe along z and gravity 9.81m/s2 against z mass-inlet and a pressure outlet Thank you for your time

 jpo January 25, 2012 17:49

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

 ComputerGuy January 25, 2012 18:01

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

Quote:
 Originally Posted by jpo (Post 341179) 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

 jpo January 25, 2012 18:41

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

 jpo April 24, 2012 16:49

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.

 Dapb June 20, 2012 08:40

Hello,

I would like to know how did you charge the UDF gravity_source in the fluent graphical interface?

Thank you.

 jpo June 20, 2012 08:54

It would not be possible to be done via the graphical interface, rather, via a UDF

 Dapb June 20, 2012 10:38

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.

 jpo June 20, 2012 12:44

Previous posts above should help to explain... gravity_source in the UDF is recognized by Fluent as gravity along the z-axis

 Dapb June 21, 2012 03:57

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?