-
-
March 25, 2021 at 2:47 am
atulsingh92
SubscriberHello,
I have a UDF that tries to calculate area weighted average of Pressure at the surface, as follows.
float Print_dynPressure(Domain *domain, int id) { cell_t c; Thread *t; face_t f; t = Lookup_Thread(domain, id); begin_f_loop(f,t) { uc = F_U(f,t); vc = F_V(f,t); wc = F_W(f,t); temp = F_T(f,t); stat_p = F_P(f,t); dens = F_R(f,t); Flux = F_FLUX(f,t); F_AREA(area,f,t); Amag = NV_MAG(area); total_area += Amag; vmag = sqrt(pow(uc,2) + pow(vc,2) + pow(wc,2)); vavg = Flux / (dens * Amag) ; //in a single cell dyn_p = 0.5*dens*pow(vavg,2); total_p = stat_p + dyn_p; p_sum += total_p * Amag; } end_f_loop(f,t) float pa_glob = PRF_GRSUM1(p_sum); float area_avg_p_f = pa_glob/total_area ; // for area averaged pressure i.e sigma p|A|/A return area_avg_p_f; }
The results obtained from above method called ad DEFINE_ON_DEMAND, with the resutls obtained from Area weighted average of Total pressure from gui are as follows,
March 25, 2021 at 5:10 amKeyur Kanade
Ansys EmployeeWhy do you want to replicate it in UDF it already exists in Fluent as standard function? nWe will not debug UDF. Others on forum can pitch in. nYou can see how area weighted is calculated in Fluent at following link. nPlease go through help manual for more details nRegards,nKeyurnHow to access Ansys Online Help DocumentnHow to show full resolution imagenGuidelines on the Student CommunitynHow to use Google to search within Ansys Student CommunitynMarch 25, 2021 at 8:18 amatulsingh92
SubscriberI guess the question is not to debug the udf, but rather to ask, if I have missed out on any formula that calculates the surface integral?nI already have the link that you provided in my equation, (see second last line within comments), so I am already summing the total pressure, multiplying with an area, summing this product, and dividing with total area.nOr perhaps a way to narrow down the source of this difference would also be helpful.nMarch 25, 2021 at 1:48 pmYasserSelima
SubscriberFirst, whatever you calculate using report definition is accessible to your UDF ... I don't have access to the manual now to get you the macro, but search for it in the manual. You can just get the value and report it in your files.nSecond, I suspect that you did a very common mistake ... Did you set p_sum = 0 before starting the loop every time ? I can't answer because I can't see the rest of the codenThird, make sure that you selected total pressure in the report definition, so you compare total pressure to total pressurennMarch 25, 2021 at 2:03 pmYasserSelima
SubscriberLook for Get_Report_Definition_Values to access the values calculated in your report definitioMarch 25, 2021 at 2:23 pmatulsingh92
SubscriberAs always, many thanks Yasser, nyes p_sum=0.0 was defined.nAnd yes, I knew about the Get_report_definition_values, however, the idea was to simply read/tally/ from surface-integrals instead, becuase choosing 4 surfaces, lets say, for a report definition gives a cumulative pressure at all the 4 surfaces, while doing the same on surface integral gives individual values at each surface.nThis means, there should be 4 such reports for 4 different surfaces, and this will quickly become cumbersome, if there are many surfaces, (inlet/outlets of tubes of heat exchangers).nMarch 25, 2021 at 2:43 pmYasserSelima
SubscriberThis would still be faster than recalculating the values ... And if you create the report definition for all 4 surfaces and checked the box per zone, the function will return the 4 values separately ... nAnyway, your function seems right but has two minor corrections which will not make much difference .. but let's trynnAdd this before calculating the average pressurentotal_area = PRF_GRSUM1(total_area);nand correct this, use the magnitude instead of vavgndyn_p = 0.5*dens*pow(vmag,2);nnMarch 27, 2021 at 10:36 amatulsingh92
Subscriberyes, it doesn't make much difference!nAnd could I request Fluent team to correct example 3.8.3 of Fluent manual on Get_Report_Definition_Values. Using this udf as it is, gives the following error.nPlease note, the udf has been used as it is given exactly in 3.8.3, Steady state example, as my requirement was the same.nc(9) is at int rv = Get....nc(10) is at the very next if condition.n..\..\src\get_report.c(9): error C2099: initializer is not a constant n..\..\src\get_report.c(10): error C2059: syntax error: 'if'n..\..\src\get_report.c(29): error C2059: syntax error: 'else'nnhere is the code.n#include udf.hnint nrOfvalues=0;nreal *values;nint *ids;nint index;nint counter;nint rv ;n nrv = Get_Report_Definition_Values(area-avg-tot-pressure, 0, &nrOfvalues, NULL, NULL,NULL); / 0 if successful, 1 if fails!nnMessage(Report definition evaluated at iteration has %d values, rv);nnif (rv==0 && nrOfvalues)n{nn Message(Report definition evaluated at iteration has %d values, nrOfvalues);n /*Memory is allocated for values and ids.*/n values = (real*) malloc(sizeof(real)* nrOfvalues);n ids = (int*) malloc(sizeof(int)* nrOfvalues);n /* Second call to get data. The number of values is null, but the lastn * three are not.*/n rv = Get_Report_Definition_Values(area-avg-tot-pressure, 0, NULL, values, ids, &index);n Message(Values correspond to iteration index:%d, index);n for ( counter = 0; counter < nrOfvalues; counter++ )n {n Message(report definition values: %d, %f, ids[counter], values[counter]);n }n /*Memory is freed.*/n free(values);n free(ids);nnelsen{n /*The command can be unsuccessful if the report definition does not existn or if it has not been evaluated yet.*/n if (rv == 1)n {n Message(report definition: %s does not exist, area-avg-tot-pressure);n }n else if ( nrOfvalues == 0 )n {n Message(report definition: %s not evaluated at iteration level, area-avg-tot-pressure);n }nnMarch 27, 2021 at 1:14 pmYasserSelima
SubscriberAdd it inside a Define function ... do not leave it like this ..nn#include udf.hnnDEFINE_ON_DEMAND(get_report)n{ nint nrOfvalues=0;nreal *values;nint *ids;nint index;nint counter;nint rv ;nn Add the code herenViewing 8 reply threads- You must be logged in to reply to this topic.
Ansys Innovation SpaceEarth 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.
Ansys Blog
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
- Floating point exception in Fluent
- What are the differences between CFX and Fluent?
- Heat transfer coefficient
- Getting graph and tabular data from result in workbench mechanical
- The solver failed with a non-zero exit code of : 2
- Difference between K-epsilon and K-omega Turbulence Model
- Time Step Size and Courant Number
- Mesh Interfaces in ANSYS FLUENT
- error in cfd post
Top Contributors-
2524
-
2066
-
1279
-
1096
-
457
Top Rated Tags© 2023 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.
-