|
[Sponsors] |
June 12, 2021, 19:36 |
Moving average using UDF
|
#1 |
New Member
jo samuel
Join Date: Apr 2020
Posts: 3
Rep Power: 6 |
Hi all,
I'm trying to obtain the pressure values at a particular interface inside the domain in a transient 2D model using UDF. This calculation happens for every iteration. And I also want the moving average(aka rolling average) of these obtained pressure values over few timesteps(not iterations). After obtaining this averaged value I use them back as an input into the simulation. I have tried a code that I have pasted below. I was able to successfully obtain the pressure values at the interface for every iteration. But, UDF calculates the moving average of the obtained pressure values for every iteration, instead, I need it to be calculated over a few timesteps. Please help me where I went wrong. Thanks in advance! #include "udf.h" #define NumTempsToAvg 6 /* this number is the number of timesteps taken for average */ real Pr; int temps[NumTempsToAvg]; real sum = 0.0; DEFINE_ADJUST(Pint, domain) { int i; i= N_TIME; /* obtains the integer value of the timestep*/ real coord[ND_ND]; face_t f; cell_t c0; int ID = 23; Thread *thread, *t0; thread = Lookup_Thread(domain, ID); begin_f_loop(f, thread) { c0 = F_C0(f,thread); t0 = THREAD_T0(thread); F_CENTROID(coord,c0,t0); printf("x = %f\t y = %f\n\n ",coord[0], coord[1]); Pr += F_P(c0,t0); printf("Pr = %f\n\n", Pr); } end_f_loop(f,thread) Pr=Pr/14; /* this averages over the 14 faces */ printf("Pr = %f\n", Pr); for ( i= 1; i < NumTempsToAvg; i++) { temps[i] = Pr; /* array name is temps */ sum += temps[i]; printf("the sum is %f\n\n", sum); printf("avg: %f\n", sum / NumTempsToAvg); /* moving average */ sum -= temps[i]; temps[i] = Pr; sum += temps[i]; } } |
|
June 17, 2021, 01:09 |
|
#2 |
New Member
Genevieve
Join Date: Jun 2021
Posts: 1
Rep Power: 0 |
You can try using DEFINE_EXECUTE_AT_END, I believe it runs at the end of every timestep in a transient run.
|
|
June 25, 2021, 15:36 |
|
#3 |
New Member
jo samuel
Join Date: Apr 2020
Posts: 3
Rep Power: 6 |
Thanks Gensqy,
I used DEFINE_EXECUTE_AT_END and obtained values at the end of the timestep. Thanks for the idea and reply. However, my final goal of this UDF is to get the moving average. Unfortunately, it still ends up showing some errors. Any leads would be helpful. thanks in advance. |
|
June 27, 2021, 22:41 |
|
#4 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
show code you are using
show compilation log file explain in details problems/errors which you have
__________________
best regards ****************************** press LIKE if this message was helpful |
|
Tags |
fluent, moving average, transient 2d, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Moving mesh udf problem | vitali31 | Fluent UDF and Scheme Programming | 20 | August 29, 2018 12:42 |
UDF for moving wall (oscillating) | Sambhu.jayachandran | Fluent UDF and Scheme Programming | 3 | March 12, 2018 04:23 |
UDF for a moving sphere in 2D | Sufyan Abushaala | Fluent UDF and Scheme Programming | 0 | February 19, 2014 07:19 |
Moving Reference Frame (MRF) with UDF | Tobard | FLUENT | 0 | April 14, 2011 16:18 |
Moving Reference frame - UDF - Moving mesh | modisa | FLUENT | 0 | April 18, 2008 14:31 |