CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

How to access only one phase in multiphase model by UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 23, 2009, 08:57
Default How to access only one phase in multiphase model by UDF
  #1
Member
 
Soeren Werner
Join Date: Mar 2009
Location: Wädenswil, Switzerland
Posts: 32
Rep Power: 17
wersoe is on a distinguished road
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

Last edited by wersoe; September 23, 2009 at 09:22.
wersoe is offline   Reply With Quote

Old   January 4, 2017, 08:11
Default
  #2
Senior Member
 
Przemek
Join Date: Jun 2011
Posts: 249
Rep Power: 16
gaza is on a distinguished road
Quote:
Originally Posted by wersoe View Post
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)
         }
}
__________________
best regards
pblasiak
gaza is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modified k-e turbulence model UDF Travis Fluent UDF and Scheme Programming 7 November 11, 2018 21:21
Discrete phase or two phase model in Fluent? andrea panizza FLUENT 14 September 6, 2015 17:18
Superlinear speedup in OpenFOAM 13 msrinath80 OpenFOAM Running, Solving & CFD 18 March 3, 2015 06:36
UDF problem in multiphase model Amir Khodabandeh FLUENT 1 March 13, 2009 09:43
air and water vapour mixture - multiphase model Saba FLUENT 0 February 10, 2009 13:05


All times are GMT -4. The time now is 15:13.