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

Passing an array from one macro to another in a UDF while running in parallel

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 21, 2020, 07:40
Default Passing an array from one macro to another in a UDF while running in parallel
  #1
New Member
 
Join Date: Jun 2015
Posts: 3
Rep Power: 10
debbednut is on a distinguished road
Hi guys! The following code represents what I am trying to achieve in a much larger and more complicated UDF for a multiphase simulation in parallel.

I am assigning values to globally declared array A in a DEFINE_ADJUST macro. I am trying to pass the array A from the DEFINE_ADJUST macro to the DEFINE_PROFILE macro and display its values in the DEFINE_PROFILE.

The problem is that I am running the simulation in parallel, and any global variable/array gets initialized to 0 in a different macro. I have tried using host_to_node, etc. and PRF_CSEND, etc. but it hasn't worked out. Please help!

Code:
#include "udf.h"

int n = 10;
int A[n];

DEFINE_PROFILE(foo, bar, oof)
{
	int p = 0;

	for(p = 0; p < n; p++)
	{
		Message("%d\n", A[p]);
	}	
}

DEFINE_ADJUST(foobar, barfoo)
{
	int k = 0;
	
	#if !RP_HOST
	for(k = 0; k < n; k++)
	{
		A[k] = 10*k;
	}
	#endif
}
debbednut is offline   Reply With Quote

Old   January 22, 2020, 01:07
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
this code should work with no error
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   January 22, 2020, 07:13
Default Passing an array from one macro to another in a UDF while running in parallel
  #3
New Member
 
Join Date: Jun 2015
Posts: 3
Rep Power: 10
debbednut is on a distinguished road
Thanks for taking the time to reply, AlexanderZ.


The code runs without any errors, but the values of array A[z] which I assign in the DEFINE_ADJUST don't get carried over to the DEFINE_PROFILE. So the Message function prints 0 0 0 0 instead of 10 20 30 ...etc.
debbednut is offline   Reply With Quote

Old   January 22, 2020, 22:59
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
So the Message function prints 0 0 0 0 instead of 10 20 30 ...etc.
this is not true, show real console output and UDF, which you are using to get that output
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   January 28, 2020, 01:19
Default Passing an array from one macro to another in a UDF while running in parallel
  #5
New Member
 
Join Date: Jun 2015
Posts: 3
Rep Power: 10
debbednut is on a distinguished road
Hi AlexanderZ! Sorry for the late reply.


In the following code I want to pass the values of yo[] and uo[] from the DEFINE_ADJUST to the DEFINE_PROFILE.



Code:
    
DEFINE_PROFILE(x1_velocity,t,i)
{
      int n=0;
      face_t f;
      real r, R, y, x, utp, tin, tip, U1;
      real xc[ND_ND];/*This will hold the position vector*/
      real xc2[ND_ND];/*This will hold the position vector*/
      real time_step=RP_Get_Integer("time-step"); 
      tin= CURRENT_TIME;
      tip= PREVIOUS_TIME;  


      // int IDi=7;/*Zone ID for intlet zone from Boundary Conditions task page*/
        /* Send the ID value to all the nodes */
         // host_to_node_int_1(IDi); /* Does nothing in serial */                                                              
      
      R=0.0005;/*The radius of tube in m*/
      utp=0.1;
      U1 = 0.2;

      #if !RP_HOST

       if ((time_step)<5)
        {
          begin_f_loop(f,t)
           { 
                   if PRINCIPAL_FACE_P(f,t)
                   {
                     F_CENTROID(xc,f,t);
                     x=xc[0];
                     y=xc[1];
                     r=y/R; /*non-dimensional y coordinate*/

                     F_PROFILE(f,t,i)= 2*((U1+utp*(cos(omega*(tin-0.024995))))*(1-(r*r)));
                   }    
           }
          end_f_loop(f,t)
        }

      else if ((time_step)>=5)
       {           
            begin_f_loop (f,t)
            { 
              if PRINCIPAL_FACE_P(f,t)
              {
                  F_CENTROID(xc2,f,t);

                  for (n=0;n<65;n++)
                   {
                       if (n == 0)
                           Message("I am in DEFINE_PROFILE(x1_velocity,t,i)\n");
                       if (n < 5)
                           Message("yo[%d] = %f\n", n, yo[n]);
                    if ((fabs(xc2[1]-yo[n]))<0.000000001)
                      {
                         F_PROFILE (f,t,i) =  ((U1+utp*(cos(omega*(tin-0.024995)))))/((U1+utp*(cos(omega*(tip-0.024995)))))*(uo[n]);
                      }
                   }
               }
            }
           end_f_loop  (f,t)
       }
        #endif
}

DEFINE_ADJUST(outlet1_store,domain)
{
        real FC1[2];
        face_t f;

        int IDo=10;/*Zone ID for outlet zone from Boundary Conditions task page*/
        Thread *thread=Lookup_Thread(domain,IDo);

        real areao=0.0, uao=0.0;
        real NV_VEC(A);
        int p=0;

        /* Send the ID value to all the nodes */
         // host_to_node_int_1(IDo); /* Does nothing in serial */
  
        #if !RP_HOST
         begin_f_loop(f,thread)
          {
              if PRINCIPAL_FACE_P(f,thread)
              {
                F_CENTROID(FC1,f,thread);

                 yo[p]=FC1[1];
                 if (p == 0)
                     Message("I am in DEFINE_ADJUST(outlet1_store,domain).\n");
                 if (p<5)
                     Message("yo[%d] = %f\n", p, yo[p]);
                 uo[p]=F_U(f,thread);
                 vo[p]=F_V(f,thread);
                 to[p]=F_T(f,thread);
                 areao +=F_AREA(A,f,thread);
                 uao +=(F_U(f,thread))*(NV_MAG(A));


                 p+=1;
             }
          }
         end_f_loop(f,thread)

         # if RP_NODE /* Perform node synchronized actions here
                Does nothing in Serial */
          areao = PRF_GRSUM1(areao);
          uao = PRF_GRSUM1(uao);
        # endif /* RP_NODE */
        #endif

         uavgo=(uao/areao);
}
The code output here after the 5th timestep is


I am in DEFINE_PROFILE(x1_velocity,t,i)
yo[0] = 0.000000
yo[1] = 0.000000
yo[2] = 0.000000
yo[3] = 0.000000
yo[4] = 0.000000
......
I am in DEFINE_PROFILE(x1_velocity,t,i)
yo[0] = 0.000000
yo[1] = 0.000000
yo[2] = 0.000000
yo[3] = 0.000000
yo[4] = 0.000000
I am in DEFINE_ADJUST(outlet1_store,domain).
yo[0] = 0.000277
yo[1] = 0.000263
yo[2] = 0.000248
yo[3] = 0.000233
yo[4] = 0.000218




The yo[] values are different in the two macros. Please help.
debbednut is offline   Reply With Quote

Old   January 28, 2020, 21:48
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you've showed only part of code, I can't compile it
you've showed modified output, wtf? if you are running in parallel, you should have several SAME lines in output, if you are using this code
however you may try to add this code to your UDF
Code:
#include "udf.h"

DEFINE_PROFILE(x1_velocity,t,i)
{
      int n=0;
      face_t f;
      real r, R, y, x, utp, tin, tip, U1;
      real xc[ND_ND];/*This will hold the position vector*/
      real xc2[ND_ND];/*This will hold the position vector*/
      real time_step; 
      tin= CURRENT_TIME;
      tip= PREVIOUS_TIME;  
		#if !RP_NODE		/* SERIAL or HOST */
		time_step=RP_Get_Integer("time-step")
		#endif /* !RP_NODE */
		host_to_node_int_1(time_step);
      // int IDi=7;/*Zone ID for intlet zone from Boundary Conditions task page*/
        /* Send the ID value to all the nodes */
         // host_to_node_int_1(IDi); /* Does nothing in serial */                                                              
      #if !RP_HOST		/* SERIAL or NODE */
      R=0.0005;/*The radius of tube in m*/
      utp=0.1;
      U1 = 0.2;

       if ((time_step)<5)
        {
          begin_f_loop(f,t)
           { 
                   if PRINCIPAL_FACE_P(f,t)
                   {
                     F_CENTROID(xc,f,t);
                     x=xc[0];
                     y=xc[1];
                     r=y/R; /*non-dimensional y coordinate*/

                     F_PROFILE(f,t,i)= 2*((U1+utp*(cos(omega*(tin-0.024995))))*(1-(r*r)));
                   }    
           }
          end_f_loop(f,t)
        }

      else if ((time_step)>=5)
       {           
            begin_f_loop (f,t)
            { 
              if PRINCIPAL_FACE_P(f,t)
              {
                  F_CENTROID(xc2,f,t);

                  for (n=0;n<65;n++)
                   {
                       if (n == 0)
                           Message("I am in DEFINE_PROFILE(x1_velocity,t,i)\n");
                       if (n < 5)
                           Message("yo[%d] = %f\n", n, yo[n]);
                    if ((fabs(xc2[1]-yo[n]))<0.000000001)
                      {
                         F_PROFILE (f,t,i) =  ((U1+utp*(cos(omega*(tin-0.024995)))))/((U1+utp*(cos(omega*(tip-0.024995)))))*(uo[n]);
                      }
                   }
               }
            }
           end_f_loop  (f,t)
       }
	#endif /* !RP_HOST */
}

DEFINE_ADJUST(outlet1_store,domain)
{
        real FC1[2];
        face_t f;

        int IDo=10;/*Zone ID for outlet zone from Boundary Conditions task page*/
        Thread *thread=Lookup_Thread(domain,IDo);

        real areao=0.0, uao=0.0;
        real NV_VEC(A);
        int p=0;

        /* Send the ID value to all the nodes */
         // host_to_node_int_1(IDo); /* Does nothing in serial */
  
        #if !RP_HOST
         begin_f_loop(f,thread)
          {
              if PRINCIPAL_FACE_P(f,thread)
              {
                F_CENTROID(FC1,f,thread);

                 yo[p]=FC1[1];
                 if (p == 0)
                     Message("I am in DEFINE_ADJUST(outlet1_store,domain).\n");
                 if (p<5)
                     Message("yo[%d] = %f\n", p, yo[p]);
                 uo[p]=F_U(f,thread);
                 vo[p]=F_V(f,thread);
                 to[p]=F_T(f,thread);
                 areao +=F_AREA(A,f,thread);
                 uao +=(F_U(f,thread))*(NV_MAG(A));


                 p+=1;
             }
          }
         end_f_loop(f,thread)
		#endif
        # if RP_NODE /* Perform node synchronized actions here
                Does nothing in Serial */
          areao = PRF_GRSUM1(areao);
          uao = PRF_GRSUM1(uao);
        # endif /* RP_NODE */
        

         uavgo=(uao/areao);
}
debbednut likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
array, multiphase flow, parallel code


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
[snappyHexMesh] Problem with boundaries with sHM in parallel running Loekatoni OpenFOAM Meshing & Mesh Conversion 0 January 24, 2019 07:56
Explicitly filtered LES saeedi Main CFD Forum 16 October 14, 2015 11:58
Running parallel case after parallel meshing with snappyHexMesh? Adam Persson OpenFOAM Running, Solving & CFD 0 August 31, 2015 22:04
UDF could not be used in parallel by batch file, but could be used in single running 768643480 Fluent UDF and Scheme Programming 2 March 24, 2015 07:44
UDF for Species Mass Fraction Gradient *IN SPECIFIC ZONE * -- e.g. along axis of sym. ksiegs2 Fluent UDF and Scheme Programming 0 February 27, 2011 12:55


All times are GMT -4. The time now is 02:53.