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/)
-   -   Interfacial species transport UDF in Eulerian model (https://www.cfd-online.com/Forums/fluent-udf/171848-interfacial-species-transport-udf-eulerian-model.html)

richard222 May 18, 2016 10:32

Interfacial species transport UDF in Eulerian model
 
I am simulating species transport in a 2 phase vapor-liquid bubble column using the Eulerian framework. This UDF is designed to calculate the mass transfer rate of one species from the primary phase (liquid) to the secondary phase (gas).

The UDF compiles and hooks successfully in fluent, but no mass transfer occurs when the simulation is run. I wasn't sure whether it is necessary to introduce a the "thread_loop_c" loop over all cells (see code below), but when I tried excluding the loop it would produce an error during initialization. Any thoughts on why the UDF does not work? Thank you in advance

#include "udf.h"
#include "mem.h"
#include "sg.h"
#include "flow.h"
#include "metric.h"

DEFINE_MASS_TRANSFER(source,cell,thread,from_index ,from_species_index,to_index,to_species_index)
{

Domain *mixture_domain=Get_Domain(1);

thread_loop_c(thread, mixture_domain)
{
if( THREAD_ID(thread) == 1)
{
begin_c_loop(cell, thread)
{
real m_lg;
Thread *liq=THREAD_SUB_THREAD(thread,from_index);
Thread *gas=THREAD_SUB_THREAD(thread,to_index);
m_lg=0.3*pow(10,-7)*C_R(cell,liq);
return (m_lg);
}
end_c_loop(cell, thread)
}
}
}

Notes:

- getDomain(1) is the mixture domain (containing both liquid and gas phases).

- THREAD_ID(thread)= 1 is the interior zone of the fluid, from define-> boundary conditions .

- I have been running serial (not parallel) simulations, and have tried both compiling and interpreting the UDF (results are the same).

Bruno Machado May 19, 2016 06:11

Quote:

- THREAD_ID(thread)= 1 is the interior zone of the fluid, from define-> boundary conditions .
shouldn't this be the cell zone (cell zone condition) rather than the interior boundary?

richard222 May 19, 2016 08:00

Hi Bruno. Yes it looks like you are correct according to the UDF manual. So, I changed it to THREAD_ID(thread)= 2 as the cell zone ID number of the fluid is 2. But this still didn't fix the problem. I also tried removing the IF statement entirely from the code but there was no difference

Bruno Machado May 19, 2016 08:12

Quote:

Originally Posted by richard222 (Post 600727)
Hi Bruno. Yes it looks like you are correct according to the UDF manual. So, I changed it to THREAD_ID(thread)= 2 as the cell zone ID number of the fluid is 2. But this still didn't fix the problem. I also tried removing the IF statement entirely from the code but there was no difference

return (m_lg);

this should be your last line, before closing the DEFINE_MASS_TRANSFER macro. try to change it and see if it works. and according to the manual, there is no need to loop over the cells.

richard222 May 20, 2016 07:18

I tried changing the position of return (m_lg) but it didnt work.
I also tried no loop at all but it didnt work. Without a loop it returns a cortex error at initialisation

`e` May 20, 2016 18:24

The DEFINE_MASS_TRANSFER macro is called for each cell and includes arguments with the cell index and its mixture-level thread. You've then looped over all cells within this thread and since you're always exiting the macro on the first loop, the m_lg of the first cell (index of 0) is returned. Remove the cell loop and check the UDF manual for an example.

richard222 May 23, 2016 04:38

I've noticed something strange that I hadn't realised before. When trying to compile the UDF, it builds and loads without any errors. However, when I try to hook the UDF in the phase interactions panel, it says "no UDF has been loaded" and I am unable to hook the UDF there. But if I set the phase interactions panel to the "species mass transfer" option, and then try to hook the compiled UDF to the mass transfer coefficient panel, it DOES work. When I interpret the same UDF, it works fine, and there is no problem hooking it to either the mass transfer coefficient panel or the phase interactions panel. This makes me think that there is something wrong with the way my UDF is being compiled . I am launching fluent (ver 16.1) using the Microsoft VS2015 x64 command prompt, with the case files inside the same directory as the UDF file, and when I compile the UDF it seems to load the library without any problems, so I am not sure where the problem lies. Is it completely necessary to compile rather than interpret this type of UDF? Thanks for your help

richard222 May 23, 2016 05:45

Quote:

Originally Posted by `e` (Post 601025)
The DEFINE_MASS_TRANSFER macro is called for each cell and includes arguments with the cell index and its mixture-level thread. You've then looped over all cells within this thread and since you're always exiting the macro on the first loop, the m_lg of the first cell (index of 0) is returned. Remove the cell loop and check the UDF manual for an example.

Yes, this definitely makes sense. I'd expect the code without the loop to work, which is why i am beginning to think the problem is due to a problem with compilation.

richard222 May 23, 2016 05:56

To summarise:

In interpreted mode: Interprets UDF fine, but produces a segmentation error when I try to initialise.

In compiled mode: Builds and loads fine, but isnt visible on phase interactions panel to hook (is only visible in mass transfer coefficient panel, if "species mass transfer" model is enabled).

`e` May 23, 2016 08:56

There's no specific instruction to compile DEFINE_MASS_TRANSFER macros in the UDF manual but it's generally best to compile all UDFs to avoid potential issues. Are there any errors or warnings when you're compiling? And check my compiling process for Fluent UDFs with an existing library loaded.

pakk May 23, 2016 09:05

I guess what you want to have is this:

Code:

#include "udf.h"

DEFINE_MASS_TRANSFER(source,cell,thread,from_index,
from_species_index,to_index,to_species_index)
{
Thread *liq=THREAD_SUB_THREAD(thread,from_index);
real m_lg=0.3*pow(10,-7)*C_R(cell,liq);
return (m_lg);
}

At least that is what you get when you remove all unnecessary loops and variables from your code.

richard222 May 23, 2016 09:35

1 Attachment(s)
I tried using the simplified code that you suggested, Pak. There are no error messages during building or loading the UDF, until I select "user defined" option from the phase interactions panel and then I get "Error: No user-defined functions have been loaded". I checked to see if I could unload any previous libraries (there weren't any though) before loading the new one and I compiled the UDF library using the recommended steps.I have attached a screenshot of the fluent command prompt.

pakk May 23, 2016 09:38

From the manual:
Quote:

"In order to hook a DEFINE_MASS_TRANSFER UDF to Fluent, you must first issue the TUI command solve/set/expert and enter no at the Linearized Mass Transfer UDF? prompt."
Did you do that?

richard222 May 23, 2016 11:52

Thanks pak. That solved the problem of allowing me to hook the compiled UDF to the phase interactions panel. But, when I run the compiled UDF, there is no mass transfer occurring (it appears that ml_g=0). I can't figure out why this is the case

pakk May 23, 2016 12:04

And if you print the mass transfer in this way:
Code:

#include "udf.h"

DEFINE_MASS_TRANSFER(source,cell,thread,from_index,
from_species_index,to_index,to_species_index)
{
Thread *liq=THREAD_SUB_THREAD(thread,from_index);
real m_lg=0.3*pow(10,-7)*C_R(cell,liq);
Message("m_lg=%e\n",m_lg);
return (m_lg);
}

Warning: this prints one line per face, so only run this for one time step.

Do you see "m_lg=0" many times?

Or do you see small but positive values? If it is the latter, then Fluent is exactly calculation what you want, but the mass flow is just too small to notice...

richard222 May 23, 2016 12:25

I get very small values of ml_g being repeated many times. Yes it seems that the UDF is working. It is strange though that I am not observing any transfer from the liquid to the gas phase (it is a bubbly flow column). Normally in CFD-post when viewing the mass fraction profile in the liquid phase of the specie being transferred the scalebar of the y axis can deal with a very large number of decimal points

richard222 May 24, 2016 13:40

Thank you for your help. The problem has been solved. It appears that the mass transfer rate was so small that the simulation needed to be run for an extremely long time to achieve a measurable level of mass transfer


All times are GMT -4. The time now is 08:10.