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/)
-   -   read volume fraction for a coordinate (https://www.cfd-online.com/Forums/fluent-udf/231113-read-volume-fraction-coordinate.html)

henry_cfd_questions October 21, 2020 17:21

read volume fraction for a coordinate
 
Dear All,

I need to write a UDF code that reports volume fraction value for a coordinate ( or could be a node ) within a two-phase flow problem at a certain time, I have the following code, I have two issues:

1) I don't know how to make the UDF print the result at the console, is " printf" the correct way to request the UDF to print to the console?
2) Is this the right way to set up the time? How can I request to report the volume fraction at end of each time step?

#include "udf.h"
DEFINE_ON_DEAMND(volume_fraction)
{
real current_time;
current_time=CURRENT_TIME;
real volume_fraction;
Domain *mixture_domain;
mixture_domain=Get_Domain(1);
cell_t c;
thread *t;
thread **pt;
volume_fraction=c_VOF(c,pt[1]);
}
printf("\n volume_fraction % g",volume_fraction)

Truly appreciate any advice.

AlexanderZ October 23, 2020 04:22

you may try this code, COMPILE IT, allocate 2 user defined variables in fluent GUI so you can plot vol_frac distribution along the domain
Code:

#include "udf.h"
DEFINE_ON_DEAMND(volume_fraction)
{
        Domain *domain;
        cell_t c;
        Thread *mix_thread,*thread_g, *thread_s;
        real current_time;
        domain=Get_Domain(1);
        /* find the threads for the gas (primary) */
        /* and solids (secondary phases) */

        current_time=CURRENT_TIME;

        thread_loop_c (mix_thread,domain)
        {
                begin_c_loop (c,mix_thread)
                {
                        thread_g = THREAD_SUB_THREAD(mix_thread, 0);/* gas phase */
                        thread_s = THREAD_SUB_THREAD(mix_thread, 1);/* solid phase*/
                       
                        void_g = C_VOF(cell, thread_g);/* gas vol frac*/
                        void_s = C_VOF(cell, thread_s);/* solid vol frac*/
                        C_UDMI(c,mix_thread,0) = void_g;
                        C_UDMI(c,mix_thread,1) = void_s;
                        Message0("volume_fraction of phase 0:  %f | volume_fraction of phase 1:  %f \n",void_g,void_s);
                }
                end_c_loop (c,mix_thread)
        }
}


AlexanderZ October 23, 2020 04:28

also you may try something like this, to write to file
Code:

#include "udf.h"
FILE *fout;

void Print_vol_fraction(Domain *domain, int id)
{
cell_t c;
real vol_frac;
Thread *t = Lookup_Thread(domain, id);
fprintf(fout,"thread id %d\n", id);
begin_c_loop(c,t)
{
vol_frac = C_VOF(c, t);
fprintf(fout, "c vol_frac: %f\n", c, vol_frac);
}
end_f_loop(c,t)
fprintf(fout, "\n");
}

DEFINE_ON_DEMAND(get_coords)
{
Domain *domain;
domain = Get_Domain(1);
fout = fopen("faces.out", "w");
Print_vol_fraction(domain, 0);
Print_vol_fraction(domain, 1);
fclose(fout);
}


henry_cfd_questions October 23, 2020 13:37

Thanks, AlexanderZ for your help, this is very helpful.

Would you also know how this code can be used to print the volume fraction in only one certain point (with given coordinate values of x,y,z ). I looked into the C_CETROID and Grid variables but couldn't make it to specify a point.

Here is how I tried to specify a point :

real xc[ND_ND];
C_CENTROID(xc,cell,cell_thread);

I think I need to use an "if" statement here to specify the point location?

Thanks
Henry

AlexanderZ October 26, 2020 07:55

last code will look like this:

Code:

#include "udf.h"
FILE *fout;

void Print_vol_fraction(Domain *domain, int id)
{
cell_t c;
real vol_frac;
real x[ND_ND];
real point = {0.1,0.1,0.1};
real delta = 0.05;
Thread *t = Lookup_Thread(domain, id);
fprintf(fout,"thread id %d\n", id);
begin_c_loop(c,t)
{
C_CENTROID(x,c,t); // here x[0] - coord along x-axis, x[1]  - coord along y-axis, x[2]  - coord along z-axis (if 3D)
vol_frac = C_VOF(c, t);
if ((x[0] > point[0]-delta) && (x[0] <= point[0]+delta))
        if ((x[1] > point[1]-delta) && (x[1] <= point[1]+delta))
                if ((x[2] > point[2]-delta) && (x[2] <= point[2]+delta))
                        fprintf(fout, "c vol_frac: %f\n", c, vol_frac);
}
end_f_loop(c,t)
fprintf(fout, "\n");
}

DEFINE_ON_DEMAND(get_coords)
{
Domain *domain;
domain = Get_Domain(1);
fout = fopen("faces.out", "w");
Print_vol_fraction(domain, 0);
Print_vol_fraction(domain, 1);
fclose(fout);
}

delta is some interval where you expect to get the center of cell (around the half of size of element volume)

henry_cfd_questions October 27, 2020 16:19

Very Helpful Alexander Z, thanks for your support.

henry_cfd_questions November 22, 2020 02:56

AlexanderZ

I am working on a 2 phase flow model and following all steps to generate the air fraction which is a bubble inside a channel. Then patch, initialize, and check contours for air phase, fluent doesn't show the air bubble. I am not sure what I do wrong but I have done this before and I did not have a problem with this part. Please let me know if you can help, this is very frustrating.

Thanks
Hanry

AlexanderZ November 22, 2020 22:55

initialize first, than patch, make sure you are not initializing case after patching it

henry_cfd_questions November 23, 2020 15:31

AlexanderZ,

I truly appreciate your help, one small mistake made me redo the model many times.:D

Thanks again.

henry_cfd_questions January 21, 2021 22:54

UDF compiling Error
 
Dear AlexanderZ,

It is been a while I see this error and have been looking to fix it, some says it is a visual studio issue, I would like to ask if you know how to make the files compiled, I get this error for compiling, the interpreting has its own issues, so it would be great if I could compile the files instead, but here it goes :


The error in windows :

The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).

AlexanderZ January 21, 2021 23:35

Code:

The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).
it means what it literally says
compile UDF file

henry_cfd_questions January 23, 2021 16:44

Does that mean my code has issues?
I have tried to compile simple files, still get the same error.

Thanks
Hanry

henry_cfd_questions January 23, 2021 16:46

What do you suggest I should do ?

pakk January 24, 2021 03:03

This is not the error that you see when you try to compile ;this is the error when you try to load. (read it!)

Look at the error(s) when you compile.

henry_cfd_questions January 25, 2021 03:06

Hi PAKK,

I agree, it is the error when loading, but does that mean the code has an issue that its why it is not compiling?

Thanks
Hanry

pakk January 27, 2021 01:40

It literally says that the code is not compiled. It does not say the reason, that's why I tell you to look what happens when you try to compile. There you should see the reason.


All times are GMT -4. The time now is 23:30.