CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

UDF to modify gravity via M_gravity[ND_ND] or DEFINE_ADJUST

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   January 24, 2012, 11:26
Default UDF to modify gravity via M_gravity[ND_ND] or DEFINE_ADJUST
  #1
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
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.
jpo is offline   Reply With Quote

Old   January 24, 2012, 14:21
Default
  #2
Senior Member
 
duri
Join Date: May 2010
Posts: 130
Rep Power: 7
duri is on a distinguished road
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.
duri is offline   Reply With Quote

Old   January 24, 2012, 14:45
Default
  #3
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
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 is offline   Reply With Quote

Old   January 24, 2012, 18:59
Default
  #4
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 180
Rep Power: 7
ComputerGuy is on a distinguished road
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 View Post
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?
ComputerGuy is offline   Reply With Quote

Old   January 24, 2012, 19:11
Default
  #5
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
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 is offline   Reply With Quote

Old   January 24, 2012, 19:31
Default
  #6
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 180
Rep Power: 7
ComputerGuy is on a distinguished road
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 View Post
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 is offline   Reply With Quote

Old   January 24, 2012, 19:34
Default
  #7
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
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 is offline   Reply With Quote

Old   January 25, 2012, 15:34
Default
  #8
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 180
Rep Power: 7
ComputerGuy is on a distinguished road
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 View Post
just a straight pipe along z and gravity 9.81m/s2 against z
mass-inlet and a pressure outlet

Thank you for your time
ComputerGuy is offline   Reply With Quote

Old   January 25, 2012, 17:49
Default
  #9
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
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 is offline   Reply With Quote

Old   January 25, 2012, 18:01
Default
  #10
Senior Member
 
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 180
Rep Power: 7
ComputerGuy is on a distinguished road
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 View Post
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 is offline   Reply With Quote

Old   January 25, 2012, 18:41
Default
  #11
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
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 is offline   Reply With Quote

Old   April 24, 2012, 16:49
Default
  #12
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
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.
jpo is offline   Reply With Quote

Old   June 20, 2012, 08:40
Default
  #13
New Member
 
Join Date: Jun 2012
Posts: 5
Rep Power: 5
Dapb is on a distinguished road
Hello,

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

Thank you.
Dapb is offline   Reply With Quote

Old   June 20, 2012, 08:54
Default
  #14
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
It would not be possible to be done via the graphical interface, rather, via a UDF
jpo is offline   Reply With Quote

Old   June 20, 2012, 10:38
Default
  #15
New Member
 
Join Date: Jun 2012
Posts: 5
Rep Power: 5
Dapb is on a distinguished road
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.
Dapb is offline   Reply With Quote

Old   June 20, 2012, 12:44
Default
  #16
jpo
Member
 
Join Date: Apr 2009
Posts: 93
Rep Power: 8
jpo is on a distinguished road
Previous posts above should help to explain... gravity_source in the UDF is recognized by Fluent as gravity along the z-axis
jpo is offline   Reply With Quote

Old   June 21, 2012, 03:57
Default
  #17
New Member
 
Join Date: Jun 2012
Posts: 5
Rep Power: 5
Dapb is on a distinguished road
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
Dapb is offline   Reply With Quote

Old   June 21, 2012, 10:37
Default
  #18
Member
 
Payam D.
Join Date: Aug 2011
Posts: 79
Blog Entries: 3
Rep Power: 5
pdp.aero is on a distinguished road
You can also using the dT_CG(dt)[0]= ... for changing the CG location but you should use the 6DOF in your simulation.
pdp.aero is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
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 07: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 21:59
Modify the htc using UDF on NT frederic FLUENT 0 February 7, 2000 08:51


All times are GMT -4. The time now is 15:42.