CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Which DEFINE macro should I go with?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 19, 2012, 15:43
Question Which DEFINE macro should I go with?
  #1
New Member
 
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 13
darang is on a distinguished road
Hello,

I coded a subroutine in C and am trying to modify it into UDF. I'd like to extract coordiates of centroid of cells using the F_CENTROID function, calculate electromagnetic forces for each extracted coordinates by linear interpolation, and assign interpolated electromagnetic forces to each cell center.

Which DEFINE macro should I go with in this case?

Please give any comments or advices.

Thanks

Last edited by darang; July 20, 2012 at 09:13.
darang is offline   Reply With Quote

Old   July 19, 2012, 17:09
Default
  #2
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
I assume you will model the electromagnetig forces as momentum sources.
DEFINE_SOURCE is the only option available in this case.

BTW: The CELL centroid can be read with the C_CENTROID function
flotus1 is offline   Reply With Quote

Old   July 20, 2012, 09:19
Default
  #3
New Member
 
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 13
darang is on a distinguished road
Hi Alex,


Thank you so much for your advice. I have one more question. The unit for electomagnetic force is N (newton) but it sounds like I have to change it into the unit for momentum.

Could you let me know what I should do to convert body force into momentum source in fluent?

Thank you in advance!
darang is offline   Reply With Quote

Old   July 20, 2012, 10:01
Default
  #4
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
A momentum source has the unit N/m^3.
So you just need to integrate the momentum source over the volume and you get a force with the unit N.

Or the other way round: If you know which force you want to apply and you know the volume in which the force should be active.
Divide the force by the volume and you get the momentum source.
flotus1 is offline   Reply With Quote

Old   July 20, 2012, 14:18
Question
  #5
New Member
 
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 13
darang is on a distinguished road
Hi Alex,

Thanks a lot!

I thought about a UDF as below. But I don't know how to assign the interpolated momentum source to the centroid of each cell. Is there any macro fuction you'd like to suggest?

Thank you!!!!!




#include "udf.h"

DEFINE_SOURCE(fm_src_x_mom, cell, thread, dS, emforce)
{
float x[3]; /* defines vector x where the centroids of cells are to be stored */

cell_t c; /* defines a cell */
begin_c_loop(c, cell)
{
C_CENTROID(x, c, cell); /* stores centroid of a cell in x vector */
/* estimates electromagnetic force at the current centroid by interpolation*/
I don't know this part! /* Assigns electromagnetic force to each centroid */
}
end_c_loop(c, cell)
}
darang is offline   Reply With Quote

Old   July 23, 2012, 03:55
Default
  #6
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
Since you are a little bit on the wrong path, here is my suggestion:

Code:
#include "udf.h"

DEFINE_SOURCE(sourceterm,c,t,dS,eqn)
{
double x[ND_ND];                                //position vector
double source;                                    //returned value

C_CENTROID(x,c,t);                            //reads the position of the current cell and stores it in x
source = 100*x[0];                              //define whatever you want using c syntax
return source;                                    //returns the value and applies it to the sourceterm of the current cell
}
There is no need to loop over the cells, the SOURCE macro does this anyway.
If you assing no value to a certain cell, then the sourceterm will be set to 0 here.
flotus1 is offline   Reply With Quote

Old   July 23, 2012, 11:45
Default
  #7
New Member
 
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 13
darang is on a distinguished road
Hi Alex,

Thank you so much! It really helps!

What does 'ND_ND' stand for when you define a vector x?

double x[ND_ND];

Thanks!!!!
darang is offline   Reply With Quote

Old   July 23, 2012, 13:41
Default
  #8
Super Moderator
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,399
Rep Power: 46
flotus1 has a spectacular aura aboutflotus1 has a spectacular aura about
I forgot to mention.
ND_ND equals 2 in a 2-dimensional or axisymmetric simulation and 3 in a 3-dimensional simulation.
It is not really necessary, I just copied it from the examples in the manual.
flotus1 is offline   Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing OF 1.6 on Mac OS X gschaider OpenFOAM Installation 129 June 19, 2010 09:23
Missing math.h header Travis FLUENT 4 January 15, 2009 11:48
REAL GAS UDF brian FLUENT 6 September 11, 2006 08:23
Free surface boudary conditions with SOLA-VOF Fan Main CFD Forum 10 September 9, 2006 12:24
UDF FOR UNSTEADY TIME STEP mayur FLUENT 3 August 9, 2006 10:19


All times are GMT -4. The time now is 03:44.