TAGGED: calculation-error, density-based, transient, udf-fluent, udf-macro
-
-
June 16, 2021 at 1:49 pmpmjsjsSubscriber
Hi,
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!
#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_EXECUTE_AT_END(average_pressure)
{
int i;
Domain *d;
real coord[ND_ND];
face_t f;
cell_t c0;
int ID = 23;
Thread *thread, *t0;
d = Get_Domain(1);
thread = Lookup_Thread(d, ID);
begin_f_loop(f, thread)
{
c0 = F_C0(f,thread);
t0 = THREAD_T0(thread);
F_CENTROID(coord,c0,t0);
printf("x = %f y = %f ",coord[0], coord[1]);
Pr += F_P(c0,t0);
printf("Pr = %f ", Pr);Â
}
end_f_loop(f,thread)
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 -332950
June 22, 2021 at 12:09 pmKarthik RemellaAdministratorHello 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.
UDMIs: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v211/en/flu_udf/flu_udf_sec_udm_macros.html?q=UDMI
Time-Dependent Macros: https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v211/en/flu_udf/flu_udf_RPVariables.html?q=N_TIME
Karthik
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.
Thanks
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- The topic ‘Moving average using UDF using N_TIME macro giving out calculation error.’ is closed to new replies.
Ansys Innovation SpaceTrending discussions- Non-Intersected faces found for matching interface periodic-walls
- Script error Code: 800a000d
- Unburnt Hydrocarbons contour in ANSYS FORTE for sector mesh
- Help: About the expression of turbulent viscosity in Realizable k-e model
- Fluent fails with Intel MPI protocol on 2 nodes
- Cyclone (Stairmand) simulation using RSM
- error udf
- Diesel with Ammonia/Hydrogen blend combustion
- Mass Conservation Issue in Methane Pyrolysis Shock Tube Simulation
- Script Error
Top Contributors-
1336
-
591
-
569
-
525
-
366
Top Rated Tags© 2025 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.
-