|
[Sponsors] |
March 25, 2021, 15:02 |
Using GET_REPORT_DEFINITION_VALUES correctly
|
#1 |
Member
Join Date: Jan 2018
Posts: 34
Rep Power: 8 |
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' |
|
March 25, 2021, 15:27 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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". |
|
March 26, 2021, 03:41 |
|
#3 |
Member
Join Date: Jan 2018
Posts: 34
Rep Power: 8 |
Same error!!
No change! |
|
March 26, 2021, 13:59 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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". |
|
March 28, 2021, 19:58 |
|
#5 |
Member
Yasser Selima
Join Date: Mar 2009
Location: Canada
Posts: 51
Rep Power: 19 |
You have to add this inside a function ... DEINE_ON_DEMAND for example
|
|
November 3, 2022, 10:11 |
|
#6 | |
New Member
Join Date: Nov 2022
Posts: 10
Rep Power: 4 |
Quote:
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"); } } } |
||
November 3, 2022, 23:32 |
|
#7 | |
New Member
Wang Yifan
Join Date: Jan 2018
Posts: 4
Rep Power: 8 |
Quote:
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. |
||
November 4, 2022, 05:55 |
|
#8 |
New Member
Join Date: Nov 2022
Posts: 10
Rep Power: 4 |
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 |
|
November 4, 2022, 21:48 |
|
#9 | |
New Member
Wang Yifan
Join Date: Jan 2018
Posts: 4
Rep Power: 8 |
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:
best, Yifan |
||
November 10, 2022, 05:22 |
|
#10 | |
New Member
Join Date: Nov 2022
Posts: 10
Rep Power: 4 |
Hi Yifan,
its seems to really be a compiling issue, when compiled my UDF works! Thanks for your help! Helen Quote:
|
||
Tags |
c2099, report definition udf, udf |
|
|
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 05:26 |
SIMPLER Code Temperatures not coming correctly | Dharma Vedula | Main CFD Forum | 5 | July 5, 2017 22:34 |
chtMultiRegionSimpleFoam planeWall2D case dont run correctly in OPenFOAM 1606+ | shengqiming | OpenFOAM Running, Solving & CFD | 0 | August 7, 2016 15:15 |
SU2 optimization does not work correctly with CGNS format | Andrei | SU2 Shape Design | 1 | April 22, 2016 11:35 |
interFoam running blowing up | sandy13 | OpenFOAM Running, Solving & CFD | 2 | May 5, 2015 08:16 |