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/)
-   -   Can I define density in terms of liquid fraction in UDF? (https://www.cfd-online.com/Forums/fluent-udf/219838-can-i-define-density-terms-liquid-fraction-udf.html)

mariam.sara August 11, 2019 02:10

Can I define density in terms of liquid fraction in UDF?
 
1 Attachment(s)
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

AlexanderZ August 11, 2019 19:20

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 August 12, 2019 04:42

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 (Post 741783)
it looks like some average value

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

best regards


AlexanderZ August 13, 2019 00:15

press build, not load

best regards

mariam.sara August 13, 2019 01:34

Quote:

Originally Posted by AlexanderZ (Post 741912)
press build, not load

best regards

I did build first I aware that same error apeared?

AlexanderZ August 13, 2019 03:12

if you've build the code without errors -> you will never get log error, that you have

best regards

mariam.sara August 13, 2019 03:22

Quote:

Originally Posted by AlexanderZ (Post 741921)
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.

AlexanderZ August 13, 2019 06:22

you should in install Visual Studio and run fluent from VS console

best regards

mariam.sara August 13, 2019 06:28

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;
}

AlexanderZ August 14, 2019 04:59

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

mariam.sara August 14, 2019 05:08

Quote:

Originally Posted by AlexanderZ (Post 742058)
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;

}

AlexanderZ August 16, 2019 00:26

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

mariam.sara August 19, 2019 07:53

1 Attachment(s)
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 (Post 742212)
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


AlexanderZ August 20, 2019 00:45

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

mariam.sara August 21, 2019 11:23

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 (Post 742212)
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


AlexanderZ August 22, 2019 00:21

unfortunately, have no idea about it

best regards

mariam.sara August 22, 2019 04:28

1 Attachment(s)
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?

AlexanderZ August 22, 2019 06:59

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

mariam.sara August 22, 2019 07:03

So I need if statement to add the conditions of f(t)? May you just write me the conditions to avoid any mistakes?

AlexanderZ August 22, 2019 07:16

you comparison conditions from picture are very strange
Tm-deltaT/2 is everywhere

check it
best regards


All times are GMT -4. The time now is 09:46.