CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   How to access only one phase in multiphase model by UDF (

wersoe September 23, 2009 07:57

How to access only one phase in multiphase model by UDF
Hello guys,

I am trying to write an UDF to write data (cell volume, spec diss rate) only for one phase in multiphase (vof) model.
However, either I get all cells or a segmentation violation error.
I tried different methods to access only primary_phase by threads or domains, but I do not have any success.

Could you help me please...
For checking, used a quader with 8000 cells, patched to water in 4000 cells.
I did and didnt run some iterations, nothing helps...

This UDF writes cell volume of all cells, not only primary phase
If I switch C_VOLUME to C_D for spec diss rate, a seg viol error aoccurs.


#include "udf.h"

  cell_t c;
  int ID = 2;
      /* Zone ID for wall-1 zone from Boundary Conditions panel */
  Domain *mixture_domain = Get_Domain(1);
  Domain *subdomain = DOMAIN_SUB_DOMAIN(mixture_domain,0);
  Thread *thread = Lookup_Thread(subdomain, ID);

  FILE *output=fopen ("epsilon.out","w");

  begin_c_loop(c, thread)
        fprintf(output,"\nvof=%e", C_VOLUME(c,thread));
  end_c_loop(c, thread)

This UDF writes C_VOF for all cells, not only primary phase
eventhough C_VOF(c,pt[1])


#include "udf.h"


Domain *mix_domain = Get_Domain(1);
Thread *mix_thread;
Thread **pt;

mp_thread_loop_c(mix_thread, mix_domain, pt)
cell_t c;
begin_c_loop(c, pt[1])

Message("cell volume fraction = %f\n",C_VOF(c,pt[1]));

end_c_loop(c, pt[1])


This UDF writes values for all cells too.
Eventhough if(C_VOF(cell,subthread) = 1)

#include "udf.h"

Domain *mixture_domain = Get_Domain(1);
Domain *s_d = DOMAIN_SUB_DOMAIN(mixture_domain,0);                /*subdomain pointer, locally defined*/
Thread *mixture_thread;
cell_t cell;

int p_d;                /* loop counter for phase_domain_index, locally defined*/
int p_d_id;                /* mix_domain is available*/

FILE *output=fopen ("epsilon.out","w");
fprintf (output, "energy dissipation rate distriubtion\n");
fprintf (output, "epsilon,volume\n");
int phase_domain_index=0;

sub_domain_loop(s_d, mixture_domain, phase_domain_index)
        /* loop over all cell threads in the primary phase domain  */
                        /*Thread *st = THREAD_SUB_THREAD(cell_thread, 0);*/
                        /* loop over all cells in primary phase cell threads  */
                        /*if(C_VOF(cell,mixture_thread) = 1)*/
                        Message("\nDone... %g", C_VOF(cell,mixture_thread));
fclose (output);


Eventhough I have 3 examples here, I would like to go to the first one, since I need Lookup_Thread for determining the size of an array to parallelize the udf.
Examplers for parallelizing are here:
I do not know how I can to this when using a loop over domains or threads, since the size of the array needs to be send from nodes to host...
If I check the udf, it seems very clear to me: I define a domain, then a subdomain, then I define a thread by using subdomain for lookup...
That means, in thread it is supposed to point to thread in subdomian, or better to thread in domain with phase index 0...
However, C_VOLUME can be written, but C_D or C_VOF causes a seg viol error...

Actually, the task seems very easy to me.
Write cell values from cells which are associated with primary phase.
I have tried different methods to access one phase only.
However, I am at one's wit' end...
Any help is much appreaciated.

Thanks, Sören

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