|
[Sponsors] |
![]() |
![]() |
#1 |
New Member
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 14 ![]() |
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 10:13. |
|
![]() |
![]() |
![]() |
![]() |
#2 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 ![]() ![]() |
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 |
|
![]() |
![]() |
![]() |
![]() |
#3 |
New Member
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 14 ![]() |
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! |
|
![]() |
![]() |
![]() |
![]() |
#4 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 ![]() ![]() |
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. |
|
![]() |
![]() |
![]() |
![]() |
#5 |
New Member
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 14 ![]() |
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) } |
|
![]() |
![]() |
![]() |
![]() |
#6 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 ![]() ![]() |
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 } If you assing no value to a certain cell, then the sourceterm will be set to 0 here. |
|
![]() |
![]() |
![]() |
![]() |
#7 |
New Member
Jon Lee
Join Date: Jun 2012
Posts: 6
Rep Power: 14 ![]() |
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!!!! |
|
![]() |
![]() |
![]() |
![]() |
#8 |
Super Moderator
Alex
Join Date: Jun 2012
Location: Germany
Posts: 3,427
Rep Power: 49 ![]() ![]() |
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. |
|
![]() |
![]() |
![]() |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Installing OF 1.6 on Mac OS X | gschaider | OpenFOAM Installation | 129 | June 19, 2010 10:23 |
Missing math.h header | Travis | FLUENT | 4 | January 15, 2009 12:48 |
REAL GAS UDF | brian | FLUENT | 6 | September 11, 2006 09:23 |
Free surface boudary conditions with SOLA-VOF | Fan | Main CFD Forum | 10 | September 9, 2006 13:24 |
UDF FOR UNSTEADY TIME STEP | mayur | FLUENT | 3 | August 9, 2006 11:19 |