June 16, 2021 at 1:49 pmpmjsjsSubscriber
I'm trying to obtain the pressure values at a particular interface inside the domain in a transient 2D model using UDF. Also I 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 at end of every timestep using DEFINE_EXECUTE_AT_END macro. I'm using N_TIME macro to obtain the integer value of the timestep and calculate the moving average of the pressure values over few timesteps . But, UDF calculates the moving average of the obtained pressure values only for the current timestep, instead, I need it to be calculated over a few timesteps. Though I'm using N_TIME in a loop, the values of previous timesteps are not obtained. I have attached below the code few lines of the transcript of the calculations for one timestep for your reference. Please help me where I went wrong.
Thanks in advance!
#define NumTempsToAvg 6 /* this number is the number of timesteps taken for average */
real sum = 0.0;
int ID = 23;
Thread *thread, *t0;
d = Get_Domain(1);
thread = Lookup_Thread(d, ID);
c0 = F_C0(f,thread);
t0 = THREAD_T0(thread);
printf("x = %f y = %f ",coord, coord);
Pr += F_P(c0,t0);
printf("Pr = %f ", Pr);
Pr=Pr/14; /* average over 14 face*/
printf("Avgpr = %f ", Pr);
i= N_TIME; /* this marco obtains the integer value of the timestep*/
for ( i= 1; i < NumTempsToAvg; i++)
temps[i] = Pr;
sum += temps[i];
printf("the sum is %f ", sum);
printf("movavg: %f ", sum / NumTempsToAvg);
sum -= temps[i];
printf("the minussum is %f ", sum);
temps[i] = Pr;
sum += temps[i];
printf("the addsum is %f ", sum);
calculation transcript for one timestep(for reference)
Avgpr = -5031.508294
the sum is -312826 movavg: -52137.666667 the minussum is -307795 the addsum is -312826
the sum is -317857 movavg: -52976.166667 the minussum is -312826 the addsum is -317857
the sum is -322888 moving: -53814.666667 the minussum is -317857 the addsum is -322888
the sum is -327919 movavg: -54653.166667 the minussum is -322888 the addsum is -327919
the sum is -332950 movavg: -55491.666667 the minussum is -327919 the addsum is -332950June 22, 2021 at 12:09 pmKarthik RAdministratorHello To obtain the moving average, you will need to store your variable of interest (pressure, temperature, etc.) from previous timesteps (all the previous time-step data you wish to include) into separate UDMIs. You can use some of the Time-Dependent Macros for extracting the data from Fluent. Here is a link to these Macros.
Time-Dependent Macros: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v211/en/flu_udf/flu_udf_RPVariables.html?q=N_TIME
June 25, 2021 at 7:20 pmpmjsjsSubscriberThanks for the response.
I'm obtaining the pressure by using the flow variable macro for cell - F_P(c0,t0) and tried storing it using C_UDMI(c0,t0,0) and then used C_STORAGE_R(c,t,SV_P) to store it. After running few timestep when I obtained the plot of user-defined memory 0 the plot is showing zero throughout the plot.
I'm using the C_STORAGE_R(c,t,SV_P) to obtain the values of pressure and then divide by the timing sampling value to obtain the time-averaged value. Im not sure if this logic is correct. I'm a novice and recently started C programming. Also, can you advice me if the storage macro can be assigned a variable as mentioned below.
The code gets compiled in the fluent but while running the simulation I'm getting the following error - Process 18096: Received signal SIGSEGV. However, without the C_STORAGE_R macro, the simulation runs even though plot of user-defined memory 0 gives out only zero. Please advice where I went wrong in these macros.
Pr += F_P(c0,t0);
C_UDMI(c0,t0,0) = Pr;
avg = C_STORAGE_R(c0,t0,SV_P); /* where avg is a variable declared as real avg .*/
Viewing 2 reply threads
Ansys Innovation Space
- You must be logged in to reply to this topic.
Simulation World 2022
Check out more than 70 different sessions now available on demand. Get inspired as you hear from visionary companies, leading researchers and educators from around the globe on a variety of topics from life-saving improvements in healthcare, to bold new realities of space travel. Take a leap of certainty and check out a session today here.
Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.Trending discussions
- Suppress Fluent to open with GUI while performing in journal file
- Heat transfer coefficient
- What are the differences between CFX and Fluent?
- Floating point exception in Fluent
- The solver failed with a non-zero exit code of : 2
- Difference between K-epsilon and K-omega Turbulence Model
- Getting graph and tabular data from result in workbench mechanical
- Time Step Size and Courant Number
- Mesh Interfaces in ANSYS FLUENT
- error in cfd post
Top Rated Tags
© 2022 Copyright ANSYS, Inc. All rights reserved.Ansys does not support the usage of unauthorized Ansys software. Please visit www.ansys.com to obtain an official distribution.