|
[Sponsors] |
February 22, 2019, 13:35 |
Initializing array in udf
|
#1 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Hello!
I am defining an udf for my problem with define macros. I am defining array with 30 elements and want to initialize at time t=0. As we know that adjust get called at the beginning of the loop at every iteration. So, it gets initialized every time and old values get erased. It should be initialized at t=0 and keep on going with time. So, how do I initialize so that at any time it retain the values for that time? Thank you! |
|
February 24, 2019, 22:05 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
make your array global so you can use it everywhere, initialize it in DEFINE_INIT macro
best regards |
|
February 25, 2019, 12:33 |
|
#3 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Thank you. I tried that. But when I am printing the initialized values in adjust macros it is giving me 0 value instead of the desired value. I am initializing it with 0.0075 to all elements but on printing, it is giving '0'.
Now I am trying with 30(no. of elements) user-defined macros, which will store values at current time and can be used for next time step for particular cell. Here it is: //Initializing for(int j=0;j<30;j++) C_UDMI(c,t,j)=0.0075; Thank you |
|
February 26, 2019, 01:16 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Code:
DEFINE_INIT(init_vars, d) { cell_t c; Thread *t; int j; thread_loop_c (t,d) { begin_c_loop (c,t) { for(int j=0;j<30;j++) C_UDMI(c,t,j)=0.0075; } end_c_loop (c,t) } } best regards |
|
February 26, 2019, 08:24 |
|
#5 |
Member
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 10 |
Dear Durg,
Why didn't you define a matrix where for each time step you store the new values in an array with 30 elements ? If you use User Defined Memory, then you have to loop on all the cells of your domain and store the value in all of them. If you make the array global, you can initialize it as Array[29] = {0.0075}; Good luck Best regards Annan |
|
February 26, 2019, 12:50 |
|
#6 | |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Quote:
real arr[30]={0.0075}; DEFINE_ADJUST(myad, d) { cell_t c; Thread *t; printf("Value %f\n", arr[2]); d=Get_Domain(1); thread_loop_c (t,d) { begin_c_loop(c,t) { ------ } end_c_loop(c,t) } } for checking, I am printing one of the values of the initialized array and it is showing me 0 but it should be 0.0075. Am I doing right? Thank you |
||
February 26, 2019, 12:58 |
|
#7 | |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Quote:
Please clarify. Thank you Last edited by durg; February 26, 2019 at 15:48. |
||
February 27, 2019, 00:35 |
|
#8 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
UDM is a variable which is defined in all cells , it may have different value in different cell.
Same UDM (for instance C_UDMI(c,t,0)) may have value =1 in the first cell (finite volume element of mesh) and value = 11 in cell number 2 and so on. You may do with these values everything you want. about other your question Code:
real arr[30]={0.0075}; DEFINE_ADJUST(myad, d) { cell_t c; Thread *t; printf("Value %f\n", arr[2]); d=Get_Domain(1); thread_loop_c (t,d) { begin_c_loop(c,t) { ------ } end_c_loop(c,t) } } so if you want to pick first elemt from arry you should type Code:
Message("Value %f\n", arr[0]); best regards |
|
February 27, 2019, 03:57 |
|
#9 | |
Member
annan
Join Date: Nov 2016
Posts: 72
Rep Power: 10 |
Quote:
If your compiler is GCC, this will definitely work : real arr[30]={[0 ... 29] = 0.0075}; DEFINE_ON_DEMAND(Array_printing) { printf("Value %f\n", arr[2]); } I tested it and it worked Good luck Regards, Annan |
||
February 27, 2019, 15:09 |
|
#10 |
Member
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8 |
Thanks a lot!!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Save output of udf in another udf! | JuanJoMex | FLUENT | 0 | February 8, 2018 13:43 |
udf for valve closing a pipe using dynamic mesh | chem engineer | Fluent UDF and Scheme Programming | 2 | May 13, 2017 10:39 |
array in UDF | Kamal | FLUENT | 1 | November 7, 2013 02:15 |
UDF, UDF, UDF, UDF | Luc SEMINEL | Main CFD Forum | 0 | November 25, 2002 05:01 |
UDF for initializing VOF | Ray | Main CFD Forum | 0 | November 11, 1999 12:29 |