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

UDF Define Source(magnetic field)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 3, 2019, 13:26
Default UDF Define Source(magnetic field)
  #1
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
Hi all,
I have problem with my UDF. I modeling convection in magnetic field and I need to define new source which have impact on my fluid. So I calculated gradient of magnetic field for every cell centred of my mesh. Now I have to make array with my calculated data, but i don't know how excactly do it. It is my UDF code but i know that something is wrong.
I will be grateful for your help.
Attached Files
File Type: c momentum.c (29.7 KB, 102 views)
zwirekk is offline   Reply With Quote

Old   May 6, 2019, 22:59
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
this is your UDF
Code:
#include "udf.h"

#define N 2304
#define vf 0.000032768
#define xm -8.86E-9
#define ro 997.96
#define beta 21.37E-5
#define To 293
#define mi 9.84E-4

float GradB[N] =
{.......}    

Temp=C_T(c,t);

DEFINE_SOURCE(xmagnetic_source,c,t,dS,eqn)
{
	real xm_source;
		thread_loop_c(t,d)	// loop over all cells in model
	{
		begin_c_loop(c,t)
		{
				xm_source=-(xm*ro*beta*(Temp-To)*GradB*vf)/(2*mi)
				}
			}
		}
		end_c_loop (c,t)
	}
	
return xm_source;
	
}

DEFINE_SOURCE(ymagnetic_source,c,t,dS,eqn)
{
	real ym_source;
		thread_loop_c(t,d)	// loop over all cells in model
	{
		begin_c_loop(c,t)
		{
				ym_source=-(xm*ro*beta*(Temp-To)*GradB*vf)/(2*mi)
				}
			}
		}
		end_c_loop (c,t)
	}
	
return ym_source;
	
}
it has several problems.

but first of all, what information does your array GradB contains? Why are you trying to multiply array on scalar?

best regards
AlexanderZ is offline   Reply With Quote

Old   May 7, 2019, 12:26
Default
  #3
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
GradB are values in every cell center of my geometry and gradB is used to get value of xm_source and ym_source.
zwirekk is offline   Reply With Quote

Old   May 8, 2019, 03:28
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
using
Code:
thread_loop_c(t,d)	// loop over all cells in model
	{
		begin_c_loop(c,t)
		{
you make a loop over all cell in domain. so you should pick a value from your array and apply it to each cell. However, how do you know, that the order in your array and in loop is the same? You should think about it.
How did you get GradB?

Lets assume that the ordr is the same than you will get:

Code:
#include "udf.h"

#define N 2304
#define vf 0.000032768
#define xm -8.86E-9
#define ro 997.96
#define beta 21.37E-5
#define To 293
#define mi 9.84E-4

float GradB[N] =
{.......}  

DEFINE_SOURCE(xmagnetic_source,c,t,dS,eqn)
{
	real xm_source;
	real Temp;
	int i;
	i = 0;
		thread_loop_c(t,d)	// loop over all cells in model
		{
			begin_c_loop(c,t)
			{
				Temp = C_T(c,t);
				xm_source=-(xm*ro*beta*(Temp-To)*GradB[i]*vf)/(2*mi);
				C_UDMI(c,t,0) = GradB[i];
				C_UDMI(c,t,1) = xm_source;
				i++;
			}
			end_c_loop(c,t)
		}	
	return xm_source;
}

DEFINE_SOURCE(ymagnetic_source,c,t,dS,eqn)
{
	real ym_source;
	real Temp;
	int i;
	i = 0;
		thread_loop_c(t,d)	// loop over all cells in model
		{
			begin_c_loop(c,t)
			{
				Temp = C_T(c,t);
				ym_source=-(xm*ro*beta*(Temp-To)*GradB*vf)/(2*mi);
				C_UDMI(c,t,2) = ym_source;
				i++;
			}
			end_c_loop(c,t)
		}	
	return ym_source;
}
Using UDMIs you may make contors of your variables and check them.
Remember to allocate memory for UDMIs yousing Fluent GUI: User-Defined -> memory -> number of user-defined memory location -> set 3

best regards
AlexanderZ is offline   Reply With Quote

Old   May 10, 2019, 16:04
Default
  #5
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
Thanks for your reply.

I get GradB from Matlab. I copy coordinates of cell center in fluent and then I calculate value of GradB to my XY.
zwirekk is offline   Reply With Quote

Old   May 10, 2019, 16:20
Default
  #6
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
I don't know why i get error in line 12, there is my array.
zwirekk is offline   Reply With Quote

Old   May 12, 2019, 22:46
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you should put here output each time you have error, or any other question.

but this time most likely you forgot to put ; after {}

best regards
AlexanderZ is offline   Reply With Quote

Old   May 22, 2019, 07:07
Default
  #8
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
Hi AlexanderZ i corrected my mistakes which you mentioned me. Can you check this UDF one more time because I am getting two warrnings
Warning: line 2323: t definition shadows previous definition
Warning: line 2347: t definition shadows previous definition.
And I want to ask if it is possible to make contour in fluent with my values?
Thank you for help.
Attached Files
File Type: c udfonline.c (34.5 KB, 63 views)
zwirekk is offline   Reply With Quote

Old   May 22, 2019, 22:45
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
remove
Code:
Thread *t;
at lines : 2323 and 2347

threads are already defined in the header of each function,
for example here
Code:
DEFINE_SOURCE(ymagnetic_source,c,t,dS,eqn)
best regards
AlexanderZ is offline   Reply With Quote

Old   May 23, 2019, 05:01
Default
  #10
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
Thanks it help but now I have problem to start calculation. I get error and Fluent is crashing.
MPI Application rank 0 exited before MPI_Finalize() with status 2
The f1 process could not be started.
zwirekk is offline   Reply With Quote

Old   May 23, 2019, 07:04
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Remember to allocate memory for UDMIs yousing Fluent GUI: User-Defined -> memory -> number of user-defined memory location -> set 3

best regards
AlexanderZ is offline   Reply With Quote

Old   June 15, 2019, 17:20
Default
  #12
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
Hi sorry for so many questionons about this but i have problem. I allocate memory for UDMIs to number of user-defined memory location and number of user-defined memory location for node, next i choose source terms in cell zone conditions and next i initializate. I think my source should be in contours after initialization but something is wrong because nothing has change. Can anyone help me with this problem?
Attached Files
File Type: c wzór.c (1.4 KB, 46 views)

Last edited by zwirekk; June 16, 2019 at 08:35.
zwirekk is offline   Reply With Quote

Old   June 16, 2019, 13:13
Default
  #13
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
I also tried to compiled my udf in no parrarel mode but when i initializate my calculation my UDM are zero. And when i start calculation I get error received fatal signal.
zwirekk is offline   Reply With Quote

Old   June 17, 2019, 02:21
Default
  #14
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
for this code you need to allocate 4 UDMs, check it

best rergards
AlexanderZ is offline   Reply With Quote

Old   June 17, 2019, 02:24
Default
  #15
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
for this code you need to allocate 4 UDMs, check it

best rergards
Hi i allocated 4 UDMs and something is wrong
zwirekk is offline   Reply With Quote

Old   June 17, 2019, 06:41
Default
  #16
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
check how many elements are in your model and how long is your array

best regards
AlexanderZ is offline   Reply With Quote

Old   June 17, 2019, 06:52
Default
  #17
New Member
 
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 7
zwirekk is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
check how many elements are in your model and how long is your array

best regards
Thanks for reply. I checked number of elements and i have 94208 elements in mesh and the same in array. I dont know but when my UDF is interpreted very well. But the problem is to start calculation
best regards
zwirekk is offline   Reply With Quote

Old   June 18, 2019, 01:26
Default
  #18
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
load here your case file with all settings and udf

best regards
AlexanderZ is offline   Reply With Quote

Old   February 23, 2024, 09:09
Default UDF for magnetic field effect
  #19
New Member
 
Vikas
Join Date: Feb 2024
Posts: 2
Rep Power: 0
Vikaskori is on a distinguished road
hello,

i need udf file of the Magnetic body force
where can i get it?
Vikaskori 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
UDF unit conversion yeongjia Fluent UDF and Scheme Programming 3 November 5, 2019 05:22
udf not running iteration krushna Fluent UDF and Scheme Programming 6 February 25, 2017 16:50
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
ACCESS VIOLATION MHDWill FLUENT 1 September 23, 2007 02:51
Reaction Rate in UDF mahdi FLUENT 2 August 7, 2007 08:31


All times are GMT -4. The time now is 09:24.