CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Which DEFINE macro should I go with? (https://www.cfd-online.com/Forums/fluent/104974-define-macro-should-i-go.html)

darang July 19, 2012 15:43

Which DEFINE macro should I go with?
 
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

flotus1 July 19, 2012 17:09

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

darang July 20, 2012 09:19

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!

flotus1 July 20, 2012 10:01

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.

darang July 20, 2012 14:18

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)
}

flotus1 July 23, 2012 03:55

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.

darang July 23, 2012 11:45

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!!!!

flotus1 July 23, 2012 13:41

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.


All times are GMT -4. The time now is 19:26.