
[Sponsors] 
Is it possible to plot momentum source defined using UDF? 

LinkBack  Thread Tools  Search this Thread  Display Modes 
April 4, 2021, 18:57 
Is it possible to plot momentum source defined using UDF?

#1 
New Member
Join Date: May 2012
Posts: 28
Rep Power: 11 
Hi,
I am trying to define momentum source representing manteic field using UDF in Ansys Fluent. There will be one magnet placed above or below of the channel as it is shown in image. The problem is placing the magnet above and below of the channel cause compeletely different results. However since there is no gravity effect I was expecting these two cases should be symmetricay just like an image in mirror. Magnet position 2 gives compeletely irrevelant results.I would like to see contour plot of momentum source therefore maby I could be able to figure out the problem. Is there any way to plot momentum source. Here is my UDF code; Code:
#include "udf.h" #include <math.h> /* sin */ #define PI 3.14159265 #define a1 0.2 /* these are magnet coordinates */ #define b1 0.5 #define a2 0.2 #define b2 0.5 DEFINE_SOURCE(B_x,c,t,dS,eqn) { real source; real pos_x; real pos_y; real x[ND_ND]; pos_x = x[0]; pos_y = x[1]; F_CENTROID(x, c, t); source = 2*0.0000001*50*1/sqrt(pow((pos_xa1),2)+pow((pos_yb1),2))*0.35*(pos_xa1)/pow((pow((pos_xa1),2)+pow((pos_yb1),2)),1.5); dS[eqn] = 0; return source; } Also,I got this warning during compile udf is this may be related my problem? udf_names.c(12) : warning C4113: 'void (*)()' differs in parameter lists from 'void (*)(void)' 

April 4, 2021, 20:52 

#2 
Senior Member
Alexander
Join Date: Apr 2013
Posts: 1,675
Rep Power: 23 
that warning is normal
your source is dependent on pos_x pos_y that's why you have difference when you apply it on top and bottom plates. (cause of different y values)
__________________
best regards ****************************** press LIKE if this message was helpful 

April 5, 2021, 03:38 

#3  
New Member
Join Date: May 2012
Posts: 28
Rep Power: 11 
Quote:
When I calculate the source in excel for same distances away from the magnet position 1 or 2 the equation gives same values regardless the pos_x and pos_y. pos_x and pos_y are epicenter of the source, and magnitude of the source is depend on the distance not the central position of it. 

April 5, 2021, 05:42 

#4 
Senior Member
Join Date: Nov 2013
Posts: 1,815
Rep Power: 23 
No, in your UDF, pos_x and pos_y is the position on which you should calculate the source.
Different pos_x and pos_y have different distances to the magnet,so different values.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". 

April 5, 2021, 07:09 

#5  
New Member
Join Date: May 2012
Posts: 28
Rep Power: 11 
Quote:
Consider I am simulating magnet placed bottom of the channel, so central cooridnates of the soruce will be a1 and b1. Let's say magnetic source at pos_x = 0.2 and pos_y = 0.4 is calculated from the equation as M1. In second case I switched a1 with a2 and b1 with b2 therefore magnet will be placed at the top of the channel. Magnetic source at the same distance away from the new position which is pos_x = 0.2 and pos_y = 0.4 (distance is 0.1 in ydirection in both case) will be M2. When I calculate this in excel I get same value in both cases(M1 = M2). Same situation should be avaiable in simulation in fluent but positioning the magnet different locations gives compeletely different flow patterns. 

April 5, 2021, 09:49 

#6 
Senior Member
Join Date: Nov 2013
Posts: 1,815
Rep Power: 23 
Can you show the code that you used for magnet 2 (just to make sure that you replaced everything correctly) and a plot of the "irrelevant results" with magnet 2?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". 

April 5, 2021, 09:54 

#7 
Senior Member
Join Date: Nov 2013
Posts: 1,815
Rep Power: 23 
Code:
pos_x = x[0]; pos_y = x[1]; F_CENTROID(x, c, t); Put the centroid line first. And I think you should use C_CENTROID, because you work with cells, not faces. Are you really sure you compiled this code, and that there were no errors other than the names.c error?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build". 

April 5, 2021, 10:09 

#8 
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 16 
as Pakk mentioned, these two lines must go below the C_CENTROID line
pos_x = x[0]; pos_y = x[1]; 

April 5, 2021, 11:04 

#9 
New Member
Join Date: May 2012
Posts: 28
Rep Power: 11 
Now it works friends. I have been struggling this for a few days since, it was compiled in each case I was not suspicious about the code. The flow pattern was not as I expected but at least I was hoping to get symetrical results. Now the flow pattern is as I expected and it is symetrical as shown pictures below.
If I know you in real life I would take you dinner tonight. Thank you very much! 

Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
[swak4Foam] Installation Problem with OF 6 version  Aurel  OpenFOAM Community Contributions  14  November 18, 2020 16:18 
[swak4Foam] Error bulding swak4Foam  sfigato  OpenFOAM Community Contributions  18  August 22, 2013 12:41 
OpenFOAM on MinGW crosscompiler hosted on Linux  allenzhao  OpenFOAM Installation  127  January 30, 2009 19:08 
DecomposePar links against liblamso0 with OpenMPI  jens_klostermann  OpenFOAM Bugs  11  June 28, 2007 17:51 
Momentum source UDF  Matthew Brannock  FLUENT  5  May 3, 2001 21:18 