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/)
-   -   How to access only one phase in multiphase model by UDF (https://www.cfd-online.com/Forums/fluent-udf/68535-how-access-only-one-phase-multiphase-model-udf.html)

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.

Code:

#include "udf.h"

DEFINE_ON_DEMAND(write_data)
{
  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)
fclose(output);
}


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

Code:

#include "udf.h"

DEFINE_ON_DEMAND(print_vof)

{
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)
Code:

#include "udf.h"

DEFINE_ON_DEMAND(print_id)
{
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_loop_c(mixture_thread,s_d)
                    {
                        /*Thread *st = THREAD_SUB_THREAD(cell_thread, 0);*/
                        /* loop over all cells in primary phase cell threads  */
                              begin_c_loop(cell,mixture_thread)
                        {
                        /*if(C_VOF(cell,mixture_thread) = 1)*/
                        Message("\nDone... %g", C_VOF(cell,mixture_thread));
                        fprintf(output,"\nDone...");
                        }
                        end_c_loop(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: http://www.fluentusers.com/fluent/do...df/node231.htm
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

gaza January 4, 2017 07:11

Quote:

Originally Posted by wersoe (Post 230287)
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.

Code:

#include "udf.h"

DEFINE_ON_DEMAND(write_data)
{
  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)
fclose(output);
}

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

Code:

#include "udf.h"

DEFINE_ON_DEMAND(print_vof)

{
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)
Code:

#include "udf.h"

DEFINE_ON_DEMAND(print_id)
{
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_loop_c(mixture_thread,s_d)
            {
                /*Thread *st = THREAD_SUB_THREAD(cell_thread, 0);*/
            /* loop over all cells in primary phase cell threads  */
                      begin_c_loop(cell,mixture_thread)
                {
            /*if(C_VOF(cell,mixture_thread) = 1)*/
            Message("\nDone... %g", C_VOF(cell,mixture_thread));
            fprintf(output,"\nDone...");
            }
            end_c_loop(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: http://www.fluentusers.com/fluent/do...df/node231.htm
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

Hi Soren,
Try this code:
Code:

DEFINE_INIT(my_init_function, domain)
{
  Thread *t;
  Thread **pt;
  Thread **st;
  cell_t c;
  Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,P_PHASE);
  Domain *sDomain = DOMAIN_SUB_DOMAIN(domain,S_PHASE);
 
  real xc[ND_ND], y, x;

      mp_thread_loop_c (t,domain,pt)
    if (FLUID_THREAD_P(t))
      {
        Thread *tp = pt[P_PHASE];

        begin_c_loop (c,t)
          {
    C_CENTROID(xc,c,t);
    x=xc[0];
   
      if ( x > 0.02)
      C_VOF(c,tp) = 0;
      else
      C_VOF(c,tp) = 1;

          }
          end_c_loop (c,t)
        }
       
              mp_thread_loop_c (t,domain,st)
    if (FLUID_THREAD_P(t))
      {
        Thread *sp = st[S_PHASE];

        begin_c_loop (c,t)
          {
    C_CENTROID(xc,c,t);
    x=xc[0];
   
      if ( x > 0.02 )
      C_VOF(c,sp) = 1;
      else
      C_VOF(c,sp) = 0;

          }
          end_c_loop (c,t)
        }
}



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