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

Can I define density in terms of liquid fraction in UDF?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 11, 2019, 02:10
Default Can I define density in terms of liquid fraction in UDF?
  #1
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
Can I write a UDF for defining density as a function of solid & liquid densities (which they are known) and liquid fraction (as variable) as illustrated in picture?

Mariam
Attached Images
File Type: jpg dd.jpg (4.1 KB, 30 views)
Mashaqi likes this.
mariam.sara is offline   Reply With Quote

Old   August 11, 2019, 19:20
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
it looks like some average value

how are you going to apply average value and resolve fluid and gas phases simultaneously?

best regards
AlexanderZ is offline   Reply With Quote

Old   August 12, 2019, 04:42
Default
  #3
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
Dear Alexander,
many thanks for the answer. I did the UDFs successfully and interpreted it then it loaded within FLUENT now I want to use compile option but the following error appeared to me I used win10 64 bit what the problem? can you assist me?


Error: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).\n\nThe system cannot find the file specified.
\n\nC:\Users\AWm\AppData\Local\Temp\valid1.tmp\val id1_files\dp0\FFF\Fluent\libudf\win64\3ddp_host\li budf.dll

Quote:
Originally Posted by AlexanderZ View Post
it looks like some average value

how are you going to apply average value and resolve fluid and gas phases simultaneously?

best regards
mariam.sara is offline   Reply With Quote

Old   August 13, 2019, 00:15
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
press build, not load

best regards
AlexanderZ is offline   Reply With Quote

Old   August 13, 2019, 01:34
Default
  #5
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
press build, not load

best regards
I did build first I aware that same error apeared?
mariam.sara is offline   Reply With Quote

Old   August 13, 2019, 03:12
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
if you've build the code without errors -> you will never get log error, that you have

best regards
AlexanderZ is offline   Reply With Quote

Old   August 13, 2019, 03:22
Default
  #7
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
if you've build the code without errors -> you will never get log error, that you have

best regards
I hope you understand my point when I press build the following error appeared to me:


Copied D:\workkh\specific.C to libudf\src
************************************************** **************************
************************************************** **************************
** WARNING: Automatically switched to run in parallel -t1 mode. **
** Detected non-parallelized UDF usage, enabling parallel usage. **
** If you encounter any issues, please re-run with -t0 flag. **
************************************************** **************************
************************************************** **************************udf_names.c and user_nt.udf files in 3ddp_host are upto date.
(system "copy "C:\PROGRA~1\ANSYSI~1\v193\fluent"\fluent19.3.0\sr c\udf\makefile_nt.udf "libudf\win64\3ddp_host\makefile" ")
1 file(s) copied.
(chdir "libudf")(chdir "win64\3ddp_host")'nmake' is not recognized as an internal or external command,
operable program or batch file.
mariam.sara is offline   Reply With Quote

Old   August 13, 2019, 06:22
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you should in install Visual Studio and run fluent from VS console

best regards
AlexanderZ is offline   Reply With Quote

Old   August 13, 2019, 06:28
Default
  #9
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
I installed VS many thanks and the problem fixed. But I face another? I tried to define specific heat as a UDF but it not appear to me while I am trying to use the option user define for it and the following error now appear:

Error: No user-defined functions of type udf-type-specific-heat have been loaded.
Error Object: #f

Here is my UDF for specific heat what the problem:


#include "udf.h"
DEFINE_PROPERTY(cell_specific_heat, cell, thread)
{
real cpm,cps,cpl,Tm,dt,lat;
real temp = C_T(cell, thread);
real LIQF = C_T(cell, thread);
cps=1800.0;
cpl=2400.0;
Tm=308.0;
lat=160000.0;
dt=exp(-temp*(temp-Tm)*(temp-Tm)/4.0)/sqrt(4.0*3.14);
cpm =cps+(cpl-cps)*LIQF+lat*dt;
return cpm;
}
mariam.sara is offline   Reply With Quote

Old   August 14, 2019, 04:59
Default
  #10
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
specific heat is defined through other macro called DEFINE_SPECIFIC_HEAT(name,T,Tref,h,yi)
more information you can find in Ansys Fluent Customization manual

in your code
Code:
real temp = C_T(cell, thread);
real LIQF = C_T(cell, thread);
temp and LIQF are the same

best regards
AlexanderZ is offline   Reply With Quote

Old   August 14, 2019, 05:08
Default
  #11
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
specific heat is defined through other macro called DEFINE_SPECIFIC_HEAT(name,T,Tref,h,yi)
more information you can find in Ansys Fluent Customization manual

in your code
Code:
real temp = C_T(cell, thread);
real LIQF = C_T(cell, thread);
temp and LIQF are the same

best regards

I used the macro of define specific heat but there is still error as below:

chdir "D:\workkh\valid1_files\dp0\FFF\Fluent\libudf3")(c hdir "win64\3ddp_node")# Generating ud_io1.h
abcd.c
..\..\src\abcd.c(7) : error C2143: syntax error : missing ')' before 'constant'
..\..\src\abcd.c(7) : error C2143: syntax error : missing '{' before 'constant'
..\..\src\abcd.c(7) : error C2059: syntax error : 'constant'
..\..\src\abcd.c(7) : error C2059: syntax error : ')'

here is the UDF I wrote:

#include "udf.h"
#define cps 1800.0
#define cpl 2400.0
#define Tref 308.0
#define lat 160000.0

DEFINE_SPECIFIC_HEAT(cell_cp, T, Tref, h, yi)
{


float cpm,dt;

dt=exp(-T*(T-Tref)*(T-Tref)/4.0)/sqrt(4.0*3.14);
cpm =cps+(cpl-cps)*LIQF+lat*dt;

h = cpm*(T-Tref);
return cpm;

}

Last edited by mariam.sara; August 14, 2019 at 12:24.
mariam.sara is offline   Reply With Quote

Old   August 16, 2019, 00:26
Default
  #12
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
there are several problems:
1. Tref is defined in macro already, you don't need to redefine it

2. h has type *real, so you should use *h = ....

3. The most important one, LIQF is not defined
probably you want to use liquid mass fraction
in that case you may try to use yi, which is
Quote:
Pointer to array of mass fractions of gas phase species
to get mass fraction you can use yi[0], yi[1] and so on depending on how may species do you have
But I don't remember which value you should use, play with it

You final code may looks like this, lets assume, that liquid fraction is yi[1]:
Code:
#include "udf.h"

#define cps 1800.0
#define cpl 2400.0
#define lat 160000.0

DEFINE_SPECIFIC_HEAT(cell_cp, T, Tref, h, yi)
{
float cpm,dt;
Tref = 308;
dt=exp(-T*(T-Tref)*(T-Tref)/4.0)/sqrt(4.0*3.14);
cpm =cps+(cpl-cps)*yi[1]+lat*dt;
*h = cpm*(T-Tref);
return cpm;

}

put here final code, when you'll run it successfully

best regards
AlexanderZ is offline   Reply With Quote

Old   August 19, 2019, 07:53
Default
  #13
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
I used solidification and melting model hence there are only two phases solid and liquid? Hence I think your opinion related with liquid fraction is true in species model. Now I uploaded the UDF for specific heat successfully but an error happened and the program closed with unknown reason as soon as I initial the solution? I took quick capture screen picture for the error as the attached picture? knowing that the case is running normally without using the UDF? here is the UDF below is there an error on it:

#include "udf.h"
/*
#define cps 1800.0
#define cpl 2400.0
#define lat 160000.0
*/
DEFINE_SPECIFIC_HEAT(specificheat, T, Tref, h, yi)
{
real cpm,dt;
Tref=308;
real cps = 1800.0;
real cpl = 2400.0;
real lat = 160000.0;
Thread *t;
cell_t c;

dt=exp(-T*(T-Tref)*(T-Tref)/4.0)/sqrt(4.0*3.14);

cpm =cps+(cpl-cps)*C_LIQF(c,t)+lat*dt;

*h = cpm*(T-Tref);
return cpm;

}


Quote:
Originally Posted by AlexanderZ View Post
there are several problems:
1. Tref is defined in macro already, you don't need to redefine it

2. h has type *real, so you should use *h = ....

3. The most important one, LIQF is not defined
probably you want to use liquid mass fraction
in that case you may try to use yi, which is
to get mass fraction you can use yi[0], yi[1] and so on depending on how may species do you have
But I don't remember which value you should use, play with it

You final code may looks like this, lets assume, that liquid fraction is yi[1]:
Code:
#include "udf.h"

#define cps 1800.0
#define cpl 2400.0
#define lat 160000.0

DEFINE_SPECIFIC_HEAT(cell_cp, T, Tref, h, yi)
{
float cpm,dt;
Tref = 308;
dt=exp(-T*(T-Tref)*(T-Tref)/4.0)/sqrt(4.0*3.14);
cpm =cps+(cpl-cps)*yi[1]+lat*dt;
*h = cpm*(T-Tref);
return cpm;

}

put here final code, when you'll run it successfully

best regards
Attached Images
File Type: jpg 1.jpg (133.2 KB, 13 views)
mariam.sara is offline   Reply With Quote

Old   August 20, 2019, 00:45
Default
  #14
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
are you kidding me?
you cant you C_LIQF(c,t) inside DEFINE_SPECIFIC_HEAT, becasue c/t (which are cell/thread) are not defined, find other way

best regards
AlexanderZ is offline   Reply With Quote

Old   August 21, 2019, 11:23
Default
  #15
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
I referred for this reply from you? You mentioned that I can used y[0],yi[1] for the mass/liquid fraction? I used melting and solidification model not specices model, hence I have just two phases solid & liquid if I write the equation of Cp as you defined it previously as below :

cpm =cps+(cpl-cps)*yi[1]+lat*dt;

how can I ensure FLUENT will consider yi[1] as the liquid fraction?


Quote:
Originally Posted by AlexanderZ View Post
there are several problems:
1. Tref is defined in macro already, you don't need to redefine it

2. h has type *real, so you should use *h = ....

3. The most important one, LIQF is not defined
probably you want to use liquid mass fraction
in that case you may try to use yi, which is
to get mass fraction you can use yi[0], yi[1] and so on depending on how may species do you have
But I don't remember which value you should use, play with it

You final code may looks like this, lets assume, that liquid fraction is yi[1]:
Code:
#include "udf.h"

#define cps 1800.0
#define cpl 2400.0
#define lat 160000.0

DEFINE_SPECIFIC_HEAT(cell_cp, T, Tref, h, yi)
{
float cpm,dt;
Tref = 308;
dt=exp(-T*(T-Tref)*(T-Tref)/4.0)/sqrt(4.0*3.14);
cpm =cps+(cpl-cps)*yi[1]+lat*dt;
*h = cpm*(T-Tref);
return cpm;

}

put here final code, when you'll run it successfully

best regards
mariam.sara is offline   Reply With Quote

Old   August 22, 2019, 00:21
Default
  #16
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
unfortunately, have no idea about it

best regards
AlexanderZ is offline   Reply With Quote

Old   August 22, 2019, 04:28
Default
  #17
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
OK I want to try to define the liquid fraction at Cp relation using the definition at the attached picture (where f(T) is LIQF). As it appeared LIQF is a function of temp so can I give this definition inside specific heat UDF?
Attached Images
File Type: jpg 1.jpg (8.8 KB, 24 views)
mariam.sara is offline   Reply With Quote

Old   August 22, 2019, 06:59
Default
  #18
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you do have temperature in this macro
DEFINE_SPECIFIC_HEAT(cell_cp, T, Tref, h, yi)

so you can define f(T) easily

best regards
AlexanderZ is offline   Reply With Quote

Old   August 22, 2019, 07:03
Default
  #19
Senior Member
 
Join Date: Jan 2011
Posts: 339
Rep Power: 16
mariam.sara is on a distinguished road
So I need if statement to add the conditions of f(t)? May you just write me the conditions to avoid any mistakes?
mariam.sara is offline   Reply With Quote

Old   August 22, 2019, 07:16
Default
  #20
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you comparison conditions from picture are very strange
Tm-deltaT/2 is everywhere

check it
best regards
AlexanderZ 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
liquid volume fraction decrease(Eulerian + Degassing BC) Dereje Fluent Multiphase 0 June 19, 2019 02:26
UDF error for Heat Generation mame Fluent UDF and Scheme Programming 4 March 3, 2016 04:22
UDF C_P(c,t) Define density initialization error yuanmengyuan1989 Fluent UDF and Scheme Programming 0 May 29, 2014 22:12
Installing OF 1.6 on Mac OS X gschaider OpenFOAM Installation 129 June 19, 2010 09:23
Missing math.h header Travis FLUENT 4 January 15, 2009 11:48


All times are GMT -4. The time now is 21:01.