|
[Sponsors] |
May 3, 2019, 14:26 |
UDF Define Source(magnetic field)
|
#1 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
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. |
|
May 6, 2019, 23:59 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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; } but first of all, what information does your array GradB contains? Why are you trying to multiply array on scalar? best regards |
|
May 7, 2019, 13:26 |
|
#3 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
GradB are values in every cell center of my geometry and gradB is used to get value of xm_source and ym_source.
|
|
May 8, 2019, 04:28 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
using
Code:
thread_loop_c(t,d) // loop over all cells in model { begin_c_loop(c,t) { 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; } Remember to allocate memory for UDMIs yousing Fluent GUI: User-Defined -> memory -> number of user-defined memory location -> set 3 best regards |
|
May 10, 2019, 17:04 |
|
#5 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
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. |
|
May 10, 2019, 17:20 |
|
#6 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
I don't know why i get error in line 12, there is my array.
|
|
May 12, 2019, 23:46 |
|
#7 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 |
|
May 22, 2019, 08:07 |
|
#8 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
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. |
|
May 22, 2019, 23:45 |
|
#9 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
remove
Code:
Thread *t; threads are already defined in the header of each function, for example here Code:
DEFINE_SOURCE(ymagnetic_source,c,t,dS,eqn) |
|
May 23, 2019, 06:01 |
|
#10 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
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. |
|
May 23, 2019, 08:04 |
|
#11 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Remember to allocate memory for UDMIs yousing Fluent GUI: User-Defined -> memory -> number of user-defined memory location -> set 3
best regards |
|
June 15, 2019, 18:20 |
|
#12 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
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?
Last edited by zwirekk; June 16, 2019 at 09:35. |
|
June 16, 2019, 14:13 |
|
#13 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
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.
|
|
June 17, 2019, 03:21 |
|
#14 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
for this code you need to allocate 4 UDMs, check it
best rergards |
|
June 17, 2019, 03:24 |
|
#15 |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
||
June 17, 2019, 07:41 |
|
#16 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
check how many elements are in your model and how long is your array
best regards |
|
June 17, 2019, 07:52 |
|
#17 | |
New Member
Mirek
Join Date: Nov 2018
Posts: 11
Rep Power: 8 |
Quote:
best regards |
||
June 18, 2019, 02:26 |
|
#18 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
load here your case file with all settings and udf
best regards |
|
February 23, 2024, 10:09 |
UDF for magnetic field effect
|
#19 |
New Member
Vikas
Join Date: Feb 2024
Posts: 2
Rep Power: 0 |
hello,
i need udf file of the Magnetic body force where can i get it? |
|
June 9, 2024, 15:12 |
MHD impact on nanofluid flow
|
#20 |
New Member
Ammar
Join Date: Jun 2024
Posts: 3
Rep Power: 2 |
I need a UDF to add the effect of MHD on nanofluid flow,
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF unit conversion | yeongjia | Fluent UDF and Scheme Programming | 3 | November 5, 2019 06:22 |
udf not running iteration | krushna | Fluent UDF and Scheme Programming | 6 | February 25, 2017 17:50 |
Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 07:20 |
ACCESS VIOLATION | MHDWill | FLUENT | 1 | September 23, 2007 03:51 |
Reaction Rate in UDF | mahdi | FLUENT | 2 | August 7, 2007 09:31 |