CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Using GET_REPORT_DEFINITION_VALUES correctly

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2021, 14:02
Default Using GET_REPORT_DEFINITION_VALUES correctly
  #1
Member
 
Join Date: Jan 2018
Posts: 31
Rep Power: 8
UchihaMadara is on a distinguished road
Has anyone been able to successfully use the above macro correctly?
Or if anyone could share a MWE for retrieving a report definition variable via a udf, that would be really helpful.


I tried running the example given in the manual, but get the following error, and I am not sure how do i solve this?


Code:
#include "udf.h"
int nrOfvalues=0;
real *values;
int *ids;
int index;
int counter;
/*First call to get the number of values. For number of values,
the int pointer is passed, which is 0 for iterations.*/
int rv = Get_Report_Definition_Values("area-avg-tot-pressure", 0, &nrOfvalues, NULL, NULL,NULL);
if (rv==0 && nrOfvalues)
{

    Message("Report definition evaluated at iteration has %d values\n", nrOfvalues);
    /*Memory is allocated for values and ids.*/
    values = (real*) malloc(sizeof(real)* nrOfvalues);
    ids = (int*) malloc(sizeof(int)* nrOfvalues);
    /* Second call to get data. The number of values is null, but the last
    * three are not.*/
    rv = Get_Report_Definition_Values("area-avg-tot-pressure", 0, NULL, values, ids, &index);
    Message("Values correspond to iteration index:%d\n", index);
    for ( counter = 0; counter < nrOfvalues; counter++ )
        {
            Message("report definition values: %d, %f\n", ids[counter], values[counter]);
        }
        /*Memory is freed.*/
    free(values);
    free(ids);
}
else
{
    /*The command can be unsuccessful if the report definition does not exist
    or if it has not been evaluated yet.*/
    if (rv == 1)
    {
    Message("report definition: %s does not exist\n", "area-avg-tot-pressure");
    }
    else if ( nrOfvalues == 0 )
    {
    Message("report definition: %s not evaluated at iteration level\n", "area-avg-tot-pressure");
    }
}



Error
Code:
..\..\src\get_report.c(9): error C2099: initializer is not a constant ..\..\src\get_report.c(10): error C2059: syntax error: 'if'
 ..\..\src\get_report.c(29): error C2059: syntax error: 'else'
UchihaMadara is offline   Reply With Quote

Old   March 25, 2021, 14:27
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Split line 9.
Code:
int rv;
rv =...
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   March 26, 2021, 02:41
Default
  #3
Member
 
Join Date: Jan 2018
Posts: 31
Rep Power: 8
UchihaMadara is on a distinguished road
Same error!!
No change!
UchihaMadara is offline   Reply With Quote

Old   March 26, 2021, 12:59
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Same line numbers?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   March 28, 2021, 18:58
Default
  #5
Member
 
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 52
Rep Power: 19
Yasser is on a distinguished road
You have to add this inside a function ... DEINE_ON_DEMAND for example
Yasser is offline   Reply With Quote

Old   November 3, 2022, 09:11
Question
  #6
New Member
 
Join Date: Nov 2022
Posts: 10
Rep Power: 3
hsze is on a distinguished road
Quote:
Originally Posted by Yasser View Post
You have to add this inside a function ... DEINE_ON_DEMAND for example
Hello, sorry for starting up this old Thread.
I'm having the same issue with getting the fundtion to work.

My code is included below.

I get a undeclared variable error (line 12) whenever I try to interpret this udf and I cannot seem to find my mistake, I think I'm using the function like everyone else and I think I declared everything correctly. My output parameter is definitely called t_out and I also defined a report plot with the same name in the GUI.

Can someone please spot my mistake or give me an idea for further debugging? Thanks in advance!

#include "udf.h"
DEFINE_EXECUTE_AT_END(get_report)
{
int nrOfvalues=0;
real *values;
int *ids;
int index;
int counter;
/*First call to get the number of values. For number of values,
the int pointer is passed, which is 0 for iterations.*/
int rv;
rv = Get_Report_Definition_Values("t_out", 0, &nrOfvalues, NULL, NULL,NULL);
if (rv==0 && nrOfvalues)
{

Message("Report definition evaluated at iteration has %d values\n", nrOfvalues);
/*Memory is allocated for values and ids.*/
values = (real*) malloc(sizeof(real)* nrOfvalues);
ids = (int*) malloc(sizeof(int)* nrOfvalues);
/* Second call to get data. The number of values is null, but the last
* three are not.*/
rv = Get_Report_Definition_Values("area-avg-tot-pressure", 0, NULL, values, ids, &index);
Message("Values correspond to iteration index:%d\n", index);
for ( counter = 0; counter < nrOfvalues; counter++ )
{
Message("report definition values: %d, %f\n", ids[counter], values[counter]);
}
/*Memory is freed.*/
free(values);
free(ids);
}
else
{
/*The command can be unsuccessful if the report definition does not exist
or if it has not been evaluated yet.*/
if (rv == 1)
{
Message("report definition: %s does not exist\n", "area-avg-tot-pressure");
}
else if ( nrOfvalues == 0 )
{
Message("report definition: %s not evaluated at iteration level\n", "area-avg-tot-pressure");
}
}
}
hsze is offline   Reply With Quote

Old   November 3, 2022, 22:32
Smile
  #7
New Member
 
Wang Yifan
Join Date: Jan 2018
Posts: 4
Rep Power: 8
YI Fan is on a distinguished road
Quote:
Originally Posted by hsze View Post
I get a undeclared variable error (line 12) whenever I try to interpret this udf and I cannot seem to find my mistake, I think I'm using the function like everyone else and I think I declared everything correctly. My output parameter is definitely called t_out and I also defined a report plot with the same name in the GUI.
Hi,
You should add #include "reportdefinitions.h" and try to compile it again. I'm troubling by this macro, too. I can run this macro and get right output value and print it to the screen. But the fluent main simulation break down immediately,with the error message like this:

Error: eval: unbound variable
symbol
Error encountered in critical code section

My code of this part is:
DEFINE_EXECUTE_AT_END(myudf)
{
#if RP_HOST
int nrOfvalues=1;
real *cx;
real *cz;
int *ids;
int index;
int rv;

cx = (real*) malloc(sizeof(real) * nrOfvalues);
cz = (real*) malloc(sizeof(real) * nrOfvalues);
ids =(int*) malloc(sizeof(int) * nrOfvalues);

if(N_ITER % 5 == 0)
{
//get cx value
rv = Get_Report_Definition_Values("cx", 0, NULL, cx, ids, &index);
if(rv == 1)
{
Message("report definition: %s does not exist\n", "cx");
}
//get cy value
rv = Get_Report_Definition_Values("cz", 0, NULL, cz, ids, &index);
if(rv == 1)
{
Message("report definition: %s does not exist\n", "cz");
}

std::cout << "cx = " << cx[0] << ", cz = " << cz[0] << std::endl;
}
#endif
}

Can someone give me some advice? Thanks in advance.
YI Fan is offline   Reply With Quote

Old   November 4, 2022, 04:55
Default
  #8
New Member
 
Join Date: Nov 2022
Posts: 10
Rep Power: 3
hsze is on a distinguished road
Hi YiFan,

I've tried to run you code and I get following error:

invalid type conversion: pointer to float -> float.

So you might get an error when doing the malloc for cx and cy?


and of course I get my always present error:

Get_Report_Definition_Values: undeclared variable


If tried to incooperate your header but that header is not found in my fluent file directorly, can you only use Get_Report_Definition_Values with that header?

Also: Can you only use Get_Report_Definition_Values with compiling and not interpreting?

Thanks,
Helen
hsze is offline   Reply With Quote

Old   November 4, 2022, 20:48
Default
  #9
New Member
 
Wang Yifan
Join Date: Jan 2018
Posts: 4
Rep Power: 8
YI Fan is on a distinguished road
Hi Helen
Maybe we have different fluent versions. Mine is 2022R2. I get Get_Report_Definition_Values: undeclared variable at first. Then I searched the fluent src directory for file that contain Get_Report_Definition_Values. I got "reportdefinitions.h" and my udf can be compiled successfully.
Quote:
Originally Posted by hsze View Post
If tried to incooperate your header but that header is not found in my fluent file directorly, can you only use Get_Report_Definition_Values with that header?

Also: Can you only use Get_Report_Definition_Values with compiling and not interpreting?
Yes, I only used it with compiling rather than interpreting.
best,
Yifan
YI Fan is offline   Reply With Quote

Old   November 10, 2022, 04:22
Default
  #10
New Member
 
Join Date: Nov 2022
Posts: 10
Rep Power: 3
hsze is on a distinguished road
Hi Yifan,

its seems to really be a compiling issue, when compiled my UDF works!
Thanks for your help!

Helen



Quote:
Originally Posted by YI Fan View Post
Hi Helen
Maybe we have different fluent versions. Mine is 2022R2. I get Get_Report_Definition_Values: undeclared variable at first. Then I searched the fluent src directory for file that contain Get_Report_Definition_Values. I got "reportdefinitions.h" and my udf can be compiled successfully.

Yes, I only used it with compiling rather than interpreting.
best,
Yifan
hsze is offline   Reply With Quote

Reply

Tags
c2099, report definition udf, udf


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM] How to correctly show the result of #codeStream# internalField? chengdi ParaView 24 July 14, 2022 04:26
SIMPLER Code Temperatures not coming correctly Dharma Vedula Main CFD Forum 5 July 5, 2017 21:34
chtMultiRegionSimpleFoam planeWall2D case dont run correctly in OPenFOAM 1606+ shengqiming OpenFOAM Running, Solving & CFD 0 August 7, 2016 14:15
SU2 optimization does not work correctly with CGNS format Andrei SU2 Shape Design 1 April 22, 2016 10:35
interFoam running blowing up sandy13 OpenFOAM Running, Solving & CFD 2 May 5, 2015 07:16


All times are GMT -4. The time now is 05:53.