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

Is it possible to plot momentum source defined using UDF?

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

Like Tree5Likes
  • 2 Post By pakk
  • 1 Post By Yasser
  • 2 Post By CaptainCombo

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 4, 2021, 18:57
Default Is it possible to plot momentum source defined using UDF?
  #1
New Member
 
Join Date: May 2012
Posts: 28
Rep Power: 11
CaptainCombo is on a distinguished road
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_x-a1),2)+pow((pos_y-b1),2))*0.35*(pos_x-a1)/pow((pow((pos_x-a1),2)+pow((pos_y-b1),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)'
CaptainCombo is offline   Reply With Quote

Old   April 4, 2021, 20:52
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,675
Rep Power: 23
AlexanderZ will become famous soon enough
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
AlexanderZ is offline   Reply With Quote

Old   April 5, 2021, 03:38
Default
  #3
New Member
 
Join Date: May 2012
Posts: 28
Rep Power: 11
CaptainCombo is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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)

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.
CaptainCombo is offline   Reply With Quote

Old   April 5, 2021, 05:42
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,815
Rep Power: 23
pakk will become famous soon enough
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".
pakk is offline   Reply With Quote

Old   April 5, 2021, 07:09
Default
  #5
New Member
 
Join Date: May 2012
Posts: 28
Rep Power: 11
CaptainCombo is on a distinguished road
Quote:
Originally Posted by pakk View Post
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.

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 y-direction 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.
CaptainCombo is offline   Reply With Quote

Old   April 5, 2021, 09:49
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,815
Rep Power: 23
pakk will become famous soon enough
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".
pakk is offline   Reply With Quote

Old   April 5, 2021, 09:54
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,815
Rep Power: 23
pakk will become famous soon enough
Code:
  pos_x = x[0];
  pos_y = x[1];
  F_CENTROID(x, c, t);
This should be given a warning when you compiled: you read the value of x before setting it!

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?
Yasser and CaptainCombo like this.
__________________
"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".
pakk is offline   Reply With Quote

Old   April 5, 2021, 10:09
Default
  #8
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 16
Yasser is on a distinguished road
as Pakk mentioned, these two lines must go below the C_CENTROID line

pos_x = x[0];
pos_y = x[1];
CaptainCombo likes this.
Yasser is offline   Reply With Quote

Old   April 5, 2021, 11:04
Default
  #9
New Member
 
Join Date: May 2012
Posts: 28
Rep Power: 11
CaptainCombo is on a distinguished road
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!
Yasser and pakk like this.
CaptainCombo is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

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


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


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