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

UDF to Define Species Mass Fraction on mass flow-Inlet

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By pakk
  • 1 Post By pakk
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 28, 2020, 08:44
Unhappy UDF to Define Species Mass Fraction on mass flow-Inlet
  #1
Member
 
abdo
Join Date: Apr 2018
Posts: 42
Rep Power: 7
khaledhmz is an unknown quantity at this point
hello guys, I try for days to write a small UDF to specify the species mass fraction at 2d inlet reactive channel such I am new in c++ programming..
this is my udf:

#include "mem.h"
#define Y_CH4_in 0.032;
#define Y_O2_in 0.225;
#define t0 = 573;
DEFINE_PROFILE(mass_fraction, t, i)
{
thread *t0;
face_t f;
face *f;
cell_t c,c0;
int i;
begin_f_loop(f, t)
{
t0 = t_t0(t);
c0 = face_c0(f, t)
F_PROFILE(f,t,i) = Y_CH4_in 0.032;
F_PROFILE(f,t,i) = Y_O2_in 0.225;
}
end_f_loop(f,t)
}

I open the fluent from VS and I try fo compile it but I found many errors...
this is the errors:

(system "copy "C:\PROGRA~1\ANSYSI~1\v190\fluent"\fluent19.0.0\sr c\udf\makefile_nt.udf "libudf\win64\2ddp_node\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\2ddp_node")# Generating ud_io1.h
udf.c
..\..\src\udf.c(8): error C2065: 'thread': undeclared identifier
..\..\src\udf.c(8): error C2059: syntax error: '='
..\..\src\udf.c(10): error C2065: 'face': undeclared identifier
..\..\src\udf.c(10): warning C4552: '*': result of expression not used
..\..\src\udf.c(12): error C2082: redefinition of formal parameter 'i'
..\..\src\udf.c(15): error C2143: syntax error: missing ';' before '='
..\..\src\udf.c(17): error C2064: term does not evaluate to a function taking 337 arguments

Done.
I am confused and I am thankful for any suggestion!
khaledhmz is offline   Reply With Quote

Old   October 28, 2020, 10:06
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
Hi Khaledhmz,

OK, here are some initial hints:

You want #include "udf.h", not mem.h. Try to follow one of the examples in the manual.

The preprocessor macro #define does not need a semicolon at the end. The basic meaning of "#define XXX YYY" is that the preprocessor does a find-and-replace, finding every instance of XXX and replacing it with YYY. This is not 100% true -- for example, it will avoid instances of XXX inside quoted strings, and so on -- but it's a start.

The variable i is defined as a parameter in DEFINE_PROFILE, which is why you get an error message about Line 12. Delete Line 12.

Go through the compiler errors, and try to fix them, starting with the first one. In the current case, this complains that it knows nothing about the name (or identifier) "thread". Fix this, remembering that C is case-sensitive.

Given your preprocessor #define lines, this line:
Code:
F_PROFILE(f,t,i) = Y_CH4_in 0.032;
becomes
Code:
F_PROFILE(f,t,i) = 0.032; 0.032;
Strangely enough, this is probably two legal C statements. Once you remove the semicolon from your #define, it will become
Code:
F_PROFILE(f,t,i) = 0.032 0.032;
which is not a legal statement. The solution is this:
Code:
#define Y_CH4_in   0.032
F_PROFILE(f,t,i) = Y_CH4_in;
I don't know what you're trying to achieve with c0 and t0, but it's not working, whatever it is. (Maybe you're trying to use F_C0 and THREAD_T0, but you're writing them wrongly.) Delete all lines using these.

Good luck!
Ed
obscureed is offline   Reply With Quote

Old   October 31, 2020, 08:45
Default new warnings
  #3
Member
 
abdo
Join Date: Apr 2018
Posts: 42
Rep Power: 7
khaledhmz is an unknown quantity at this point
Quote:
Originally Posted by obscureed View Post
Hi Khaledhmz,

OK, here are some initial hints:

You want #include "udf.h", not mem.h. Try to follow one of the examples in the manual.

The preprocessor macro #define does not need a semicolon at the end. The basic meaning of "#define XXX YYY" is that the preprocessor does a find-and-replace, finding every instance of XXX and replacing it with YYY. This is not 100% true -- for example, it will avoid instances of XXX inside quoted strings, and so on -- but it's a start.

The variable i is defined as a parameter in DEFINE_PROFILE, which is why you get an error message about Line 12. Delete Line 12.

Go through the compiler errors, and try to fix them, starting with the first one. In the current case, this complains that it knows nothing about the name (or identifier) "thread". Fix this, remembering that C is case-sensitive.

Given your preprocessor #define lines, this line:
Code:
F_PROFILE(f,t,i) = Y_CH4_in 0.032;
becomes
Code:
F_PROFILE(f,t,i) = 0.032; 0.032;
Strangely enough, this is probably two legal C statements. Once you remove the semicolon from your #define, it will become
Code:
F_PROFILE(f,t,i) = 0.032 0.032;
which is not a legal statement. The solution is this:
Code:
#define Y_CH4_in   0.032
F_PROFILE(f,t,i) = Y_CH4_in;
I don't know what you're trying to achieve with c0 and t0, but it's not working, whatever it is. (Maybe you're trying to use F_C0 and THREAD_T0, but you're writing them wrongly.) Delete all lines using these.

Good luck!
Ed

hi bro , thank you for the replying
I corrected some errors but still I have some warning when I compiled it
the warning printed in fluent secreen is:

(system "copy "C:\PROGRA~1\ANSYSI~1\v190\fluent"\fluent19.0.0\sr c\udf\makefile_nt.udf "libudf\win64\2ddp_node\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\2ddp_node")# Generating ud_io1.h
udf.c
c:\users\khaled hmz\desktop\c++\libudf\src\udf.c(13) : warning C4789: buffer 'x' of size 8 bytes will be overrun; 8 bytes will be written starting at offset 8
# Generating udf_names.c because of makefile udf.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj udf.obj
Microsoft (R) Incremental Linker Version 14.16.27043.0
Copyright (C) Microsoft Corporation. All rights reserved.

Creating library libudf.lib and object libudf.exp

Done.

and this error also ;


> Copied C:\Users\KHALED hmz\Desktop\c++/udf.c to libudf\src
Creating user_nt.udf file for 2ddp_host ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v190\fluent"\fluent19.0.0\sr c\udf\makefile_nt.udf "libudf\win64\2ddp_host\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\2ddp_host")# Generating ud_io1.h
udf.c
..\..\src\udf.c(14): error C2064: term does not evaluate to a function taking 337 arguments
Creating user_nt.udf file for 2ddp_node ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v190\fluent"\fluent19.0.0\sr c\udf\makefile_nt.udf "libudf\win64\2ddp_node\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\2ddp_node")# Generating ud_io1.h
udf.c
..\..\src\udf.c(14): error C2064: term does not evaluate to a function taking 337 arguments

Done.

thank you
khaledhmz is offline   Reply With Quote

Old   October 31, 2020, 09:06
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
The only warning is about line 13. What is on line 13 of your new code? We can't see that.
khaledhmz likes this.
pakk is offline   Reply With Quote

Old   October 31, 2020, 10:46
Default
  #5
Member
 
abdo
Join Date: Apr 2018
Posts: 42
Rep Power: 7
khaledhmz is an unknown quantity at this point
Quote:
Originally Posted by pakk View Post
The only warning is about line 13. What is on line 13 of your new code? We can't see that.
this what I put at line 13

y = x[1]
I used it with th F_CENTROID macro
khaledhmz is offline   Reply With Quote

Old   October 31, 2020, 14:46
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Then your code is completely different from what you posted above. Put the full code here, otherwise we have to guess.
khaledhmz likes this.
pakk is offline   Reply With Quote

Old   October 31, 2020, 15:26
Default
  #7
Member
 
abdo
Join Date: Apr 2018
Posts: 42
Rep Power: 7
khaledhmz is an unknown quantity at this point
Quote:
Originally Posted by pakk View Post
Then your code is completely different from what you posted above. Put the full code here, otherwise we have to guess.

okey, this is my full code:


#include "udf.h"
#include "mem.h"
#define Y_CH4_in 0.032
#define Y_O2_in 0.225
DEFINE_PROFILE(mass_fraction, t, i)
{
double x[1];
double y;
face_t f;
begin_f_loop(f, t)
{
F_CENTROID(x, f, t);
y = x[1]
F_PROFILE(f, t, i) = Y_CH4_in;
F_PROFILE(f, t, i) = Y_O2_in;
}
end_f_loop(f, t)
}
khaledhmz is offline   Reply With Quote

Old   October 31, 2020, 15:57
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by khaledhmz View Post
okey, this is my full code:


#include "udf.h"
#include "mem.h"
#define Y_CH4_in 0.032
#define Y_O2_in 0.225
DEFINE_PROFILE(mass_fraction, t, i)
{
double x[1];
double y;
face_t f;
begin_f_loop(f, t)
{
F_CENTROID(x, f, t);
y = x[1]
F_PROFILE(f, t, i) = Y_CH4_in;
F_PROFILE(f, t, i) = Y_O2_in;
}
end_f_loop(f, t)
}
With the full code it's easy to see that you forgot a semicolon.

You still have to add code to distinguish mixture gases, but I don't remember how that is.
pakk is offline   Reply With Quote

Old   October 31, 2020, 16:58
Default
  #9
Member
 
abdo
Join Date: Apr 2018
Posts: 42
Rep Power: 7
khaledhmz is an unknown quantity at this point
You still have to add code to distinguish mixture gases, but I don't remember how that is.
did you mean should separate them,every mass fraction had a different symbol?
khaledhmz is offline   Reply With Quote

Old   October 31, 2020, 21:04
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by khaledhmz View Post
You still have to add code to distinguish mixture gases, but I don't remember how that is.
did you mean should separate them,every mass fraction had a different symbol?
I mean that with your code the mass fraction is set to 0.225. The value for CH4 is ignored.
khaledhmz likes this.
pakk is offline   Reply With Quote

Old   November 2, 2020, 06:11
Default
  #11
Member
 
abdo
Join Date: Apr 2018
Posts: 42
Rep Power: 7
khaledhmz is an unknown quantity at this point
ah okey
thank's for helping
khaledhmz is offline   Reply With Quote

Reply


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
UDF Error for defining 2D circular mass flow rate inlet type R.Velayati Fluent UDF and Scheme Programming 1 July 8, 2019 00:54
UDF to Define Species Mass Fraction on Velocity-Inlet MiBe Fluent UDF and Scheme Programming 3 August 3, 2017 04:36
Define mass flow profile with regards to species mass fraction danS Fluent UDF and Scheme Programming 0 June 20, 2017 06:21
Surface Integrals of Species Mass Flow to Wall Incorrect koad FLUENT 4 January 12, 2016 16:38
Installing OF 1.6 on Mac OS X gschaider OpenFOAM Installation 129 June 19, 2010 09:23


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