CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Global Reductions (https://www.cfd-online.com/Forums/fluent-udf/122769-global-reductions.html)

Kokemoor August 27, 2013 17:02

Global Reductions
 
I'm trying to use a global reduction, specifically PRF_GRSUM1, in my parallel interpreted UDF. Seems that it should be pretty straightforward, but I'm getting errors.

Code:

Error: ... line 30: MPT_gdsum1: no function prototype
I went digging around to find how it's defined, and found that prf.h has
Code:

#define PRF_GRSUM1 MPT_GDSUM1
, but no prototype. reductions.h has a prototype, but if I include it, I get the following:

Code:

Error: C:\\PROGRA~1\\ANSYSI~1\\v145\\fluent\\fluent14.5.0/multiport/src/reductions.h: line 393: MPT_check has already been defined in the current frame
Does anyone know anything about how this is all put together? Why isn't this covered by including udf.h?

rudofly November 27, 2014 09:16

Dear Andrew,

I am facing the same problem interpreting in Fluent's parallel mode. I have tried to avoid multiple definition by preprocessor statements in the usual pattern. But it didn't prevent reinterpreting of the files.
Code:

#ifndef SOMETHING
#include <udf.h>
#include <sg_ls.h>
#define SOMETHING
#endif

Have you been able to solve your problem?

Best regards,

Rudi

Kokemoor December 1, 2014 10:17

In the end, I ended up compiling my UDF. Not sure if that's what fixed it, or if I did something else, but my final UDF #includes udf.h and nothing else.

rudofly December 2, 2014 08:34

Upon your hint, I have removed sg_ls.h from includes. Instead I 'exported', which is to say I copied, the definition I needed into my file.

Interpreting it went through without redefinition error :-) Thanks!

Rudi

smilingwl September 16, 2019 04:43

I met the same problem
 
I have found the reductions.h,but,I can't find the define of the MPT_GDSUM1,could you tell me the define of the MPT_GDSUM1

AlexanderZ September 23, 2019 05:23

use PRF_GRSUM1 for global redution

read ansys fluent customization manual for more details

best regards

smilingwl September 25, 2019 03:55

Dear AlexanderZ:

Thank you so much for your answer.
The advice you suggested I have tried, but it still goes wrong.
It shows MPT_gdsum1: no function prototype.
I have no idea how to adjust my UDF.
My code as follow, could you tell me what is going wrong?

#include "udf.h"
#include "prf.h"

DEFINE_EXECUTE_AT_END(centroid)
{
#if !RP_HOST
real wcx = 0.0;
real wcy = 0.0;
real va_liq = 0.0;
real cx, cy;
real x, y;
cell_t c;
real z[ND_ND];
Domain *subdomain= Get_Domain(3);
Thread *t;
#endif
#if !RP_NODE
FILE *fout1;
FILE *fout2;
#endif
#if !RP_HOST
thread_loop_c(t,subdomain)
{
begin_c_loop(c, t)
{
if(0.5<=C_VOF(c,t)&&C_VOF(c,t)<=1.0)
{
va_liq = va_liq + C_VOLUME(c,t);
C_CENTROID(z,c,t);
wcx = wcx + z[0]*C_VOLUME(c,t);
wcy = wcy + z[1]*C_VOLUME(c,t);
}
}
end_c_loop(c, t)
}
va_liq = PRF_GDSUM1(va_liq);
wcx = PRF_GDSUM1(wcx);
wcy = PRF_GDSUM1(wcy);
cx = wcx/va_liq;
cy = wcy/va_liq;
#endif
#if !RP_NODE
fout1 = fopen("X-centroid of liquid.txt","a");
fout2 = fopen("Y-centroid of liquid.txt","a");
#endif
node_to_host_real_2(cx, cy);
#if RP_HOST
fprintf(fout1,"%g,%g\n",CURRENT_TIME,cx);
fprintf(fout2,"%g,%g\n",CURRENT_TIME,cy);
#endif
#if !RP_NODE
fclose(fout1);
fclose(fout2);
Message("\n X-centroid of liquid = %g\n", cx);
Message("\n Y-centroid of liquid = %g\n", cy);
#endif

}
Thanks a lot.
Best regards.
Wang Lu

AlexanderZ September 25, 2019 05:09

Code:

#include "udf.h"
#include "prf.h"

DEFINE_EXECUTE_AT_END(centroid)
{
real wcx = 0.0;
real wcy = 0.0;
real va_liq = 0.0;
real cx, cy;
real x, y;
cell_t c;
real z[ND_ND];
Domain *subdomain= Get_Domain(3);
Thread *t;
#if !RP_NODE
FILE *fout1;
FILE *fout2;
#endif
#if !RP_HOST
thread_loop_c(t,subdomain)
{
begin_c_loop(c, t)
{
if(0.5<=C_VOF(c,t)&&C_VOF(c,t)<=1.0)
{
va_liq = va_liq + C_VOLUME(c,t);
C_CENTROID(z,c,t);
wcx = wcx + z[0]*C_VOLUME(c,t);
wcy = wcy + z[1]*C_VOLUME(c,t);
}
}
end_c_loop(c, t)
}
va_liq = PRF_GDSUM1(va_liq);
wcx = PRF_GDSUM1(wcx);
wcy = PRF_GDSUM1(wcy);
cx = wcx/va_liq;
cy = wcy/va_liq;
#endif
#if !RP_NODE
fout1 = fopen("X-centroid of liquid.txt","a");
fout2 = fopen("Y-centroid of liquid.txt","a");
#endif
node_to_host_real_2(cx, cy);
#if RP_HOST
fprintf(fout1,"%g,%g\n",CURRENT_TIME,cx);
fprintf(fout2,"%g,%g\n",CURRENT_TIME,cy);
#endif
#if !RP_NODE
fclose(fout1);
fclose(fout2);
Message("\n X-centroid of liquid = %g\n", cx);
Message("\n Y-centroid of liquid = %g\n", cy);
#endif

}

this code is complied with no error

best regards

smilingwl September 25, 2019 07:23

Dear AlexanderZ:
Thank you for your answer. But when I interpret it, it gets wrong,I don't know what is up. Can you try to interpret my code in your fluent?I know it's rude to ask that. But I really want to know what is going up,my system or something else.
Thank you a lot.
Best regards.
Wang Lu.

AlexanderZ September 25, 2019 21:35

As I've told, compile this code and try to run it

best regards

smilingwl September 25, 2019 22:42

Thanks a lot for your answer.
Best regards!
Wang Lu

smilingwl September 26, 2019 03:54

Dear AlexanderZ:
Thank you for your answer.
I still can not compile my code.
When I compile my code ,it shows error like "The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64)".
Do you know what's wrong?
Beat regards!
Wang Lu

AlexanderZ September 26, 2019 20:11

this code, which I've attached, is compiled well

to compile code:
run fluent from visual studio command prompt (or SDK command prompt) -> user defined -> functions -> compiled -> BUILD

best regards

smilingwl September 27, 2019 08:48

Dear AlexanderZ:
Thank you for your answer.I just did what you have told,but it still shows wrong.I made a video which recorded what I did and upload on the website as follow,so that you can know what I have done.

https://user.qzone.qq.com/651668162/main
Best regards!
Wang Lu

smilingwl September 27, 2019 09:17

Dear AlexanderZ

I need to change the website to
https://user.qzone.qq.com/651668162

Best regards!
Wang Lu

smilingwl September 28, 2019 09:04

Dear AlexanderZ
Today,I try to compile my UDF,and run my Fluent. The UDF can be compiled,but it can't output the file, and the case interrupt.I think my UDF still have the coding error. Could you help me correct my UDF.
Blessing to you.
WangLu

pakk September 28, 2019 09:32

Show what is written on your screen after you click "build". (not what happens after you click "load").

It might be in your video, but I am not going to watch a video.

smilingwl September 28, 2019 21:00

Dear pakk:
Thank you for your answer.It shows as follow:
Copied F:\wldaoliuban\case\25_4/F:\wldaoliuban\case\25_4\centroid_parallel_wl.c to libudf\src
Copied F:\wldaoliuban\case\25_4/F:\wldaoliuban\case\25_4\udf.h to libudf\src
Creating user_nt.udf file for 3ddp_host ...
(system "copy "D:\ANSYS\ANSYS Inc\v180\fluent"\fluent18.0.0\src\udf\makefile_nt. udf "libudf\win64\3ddp_host\makefile" ")
已复制 1 个文件。
(chdir "libudf")(chdir "win64\3ddp_host")# Generating ud_io1.h
centroid_parallel_wl.c
# Generating udf_names.c because of makefile centroid_parallel_wl.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj centroid_parallel_wl.obj
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.

正在创建库 libudf.lib 和对象 libudf.exp
Creating user_nt.udf file for 3ddp_node ...
(system "copy "D:\ANSYS\ANSYS Inc\v180\fluent"\fluent18.0.0\src\udf\makefile_nt. udf "libudf\win64\3ddp_node\makefile" ")
已复制 1 个文件。
(chdir "libudf")(chdir "win64\3ddp_node")# Generating ud_io1.h
centroid_parallel_wl.c
# Generating udf_names.c because of makefile centroid_parallel_wl.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj centroid_parallel_wl.obj
Microsoft (R) Incremental Linker Version 12.00.21005.1
Copyright (C) Microsoft Corporation. All rights reserved.

正在创建库 libudf.lib 和对象 libudf.exp

Done.
Best regards!
WangLu

AlexanderZ September 29, 2019 21:44

try to run this code
Code:

#include "udf.h"
#include "prf.h"

DEFINE_EXECUTE_AT_END(centroid)
{
real wcx = 0.0;
real wcy = 0.0;
real va_liq = 0.0;
real cx, cy;
real x, y;
cell_t c;
real z[ND_ND];
Domain *subdomain= Get_Domain(3);
Thread *t;
#if !RP_NODE
FILE *fout1;
FILE *fout2;
#endif
#if !RP_HOST
thread_loop_c(t,subdomain)
{
begin_c_loop(c, t)
{
if(0.5<=C_VOF(c,t)&&C_VOF(c,t)<=1.0)
{
va_liq = va_liq + C_VOLUME(c,t);
C_CENTROID(z,c,t);
wcx = wcx + z[0]*C_VOLUME(c,t);
wcy = wcy + z[1]*C_VOLUME(c,t);
}
}
end_c_loop(c, t)
}
va_liq = PRF_GISUM1(va_liq);
wcx = PRF_GISUM1(wcx);
wcy = PRF_GISUM1(wcy);
cx = wcx/va_liq;
cy = wcy/va_liq;
Message0("cx cy where calculated successfully\n");
#endif
#if !RP_NODE
fout1 = fopen("X-centroid of liquid.txt","a");
fout2 = fopen("Y-centroid of liquid.txt","a");
Message0("store files where opened \n");
#endif
node_to_host_real_2(cx, cy);
#if RP_HOST
fprintf(fout1,"%g,%g\n",CURRENT_TIME,cx);
fprintf(fout2,"%g,%g\n",CURRENT_TIME,cy);
Message0("data stored successfully \n\n");
#endif
#if !RP_NODE
fclose(fout1);
fclose(fout2);
Message0("\n X-centroid of liquid = %g\n", cx);
Message0("\n Y-centroid of liquid = %g\n", cy);
#endif

}

if there still be problems -> show you console output

best regards

smilingwl October 2, 2019 23:43

Dear AlexanderZ:
Thank you so much to help me correct my UDF. I am so happy to see my case run well with the UDF. But it still has a little error. The result in the text the case output is different with the result in the serial veision.
It shows :"0.01,-1.#IND"
In the serial version, it shows:"0.01,0.053456"
Do you know what's wrong?
Thank you again.
Best Regards!
Wanglu


All times are GMT -4. The time now is 16:11.