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

Help me parallelize a serial UDF (UDS computed on each cell and faces)

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 13, 2023, 14:17
Post Help me parallelize a serial UDF (UDS computed on each cell and faces)
  #1
New Member
 
Hank
Join Date: Apr 2023
Posts: 1
Rep Power: 0
Hank- is on a distinguished road
Hello all,

I am trying to convert a serial UDF (which works fine in a single core) to work in a parallel environment (higher cores).

Here is the UDF in a single-core setting,

#include "udf.h"
#include "mem.h"
#include <stdio.h>
#include <math.h>

#define Q 60.e-06
#define e0 8.854e-12

// Define which user defined scalars to use
enum
{
phi, /* 0 - Electric potential*/
E, /* 1 - Electric field*/
Fdix, /* 2 - x-component Dielectrophoretic force*/
};

DEFINE_ADJUST(Adjust_fun, domain)
{
cell_t c;
face_t f;
real dp= 300.0e-09; //particle diameter
real ep = 4.6; //relative permittivity of particle
Thread *t; ;
real coff = M_PI*e0*pow(dp,3)*((ep-1)/(ep+2))*0.25/(2130.0*M_PI*pow(dp,3)/6.); // coefficienct in polarization force calculation

// Calculating Electric field E and the X-force Fdix from the potential (phi)
thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{
C_UDSI(c,t,E) = NV_MAG(C_UDSI_G(c,t,phi));
if(C_UDSI(c,t,E)<=0.0)
C_UDSI(c,t,E)=0.0;
if(C_UDSI(c,t,E)>(Q/e0))
C_UDSI(c,t,E) = Q/e0;

C_UDSI(c,t,Fdix) = (2.*coff*C_UDSI(c,t,E)*(C_UDSI_G(c,t,E)[0]));
}
end_c_loop(c,t)
}

// Calculating the electrostatic force F on the face of the cell
thread_loop_f(t,domain)
{
begin_f_loop(f,t)
{
if(NULL !=THREAD_STORAGE(t, SV_UDS_I(phi)) && NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(phi)))
F_UDSI(f,t,E)=C_UDSI(F_C0(f,t), t->t0, E);
if(NULL != THREAD_STORAGE(t,SV_UDS_I(E))&& NULL != T_STORAGE_R_NV(t->t0, SV_UDSI_G(E)))
{
F_UDSI(f,t,Fdix)=C_UDSI(F_C0(f,t), t->t0, Fdix);
}
}
end_f_loop(f,t)
}
}

The code calculates the electrostatic field in all the cells and faces of the domain from the potential values obtained from solving the scalar transport equation. The electrostatic force is then calculated from the electrostatic field.

So far I have tried looping over interior cells and principal faces only.
#include "udf.h"
#include "mem.h"
#include <stdio.h>
#include <math.h>

#define Q 60.e-06
#define e0 8.854e-12

// Define which user defined scalars to use
enum
{
phi, /* 0 - Electric potential*/
E, /* 1 - Electric field*/
Fdix, /* 2 - x-component Dielectrophoretic force*/
};

DEFINE_ADJUST(Adjust_fun, domain)
{
#if !RP_HOST
cell_t c;
face_t f;
real dp= 300.0e-09; //particle diameter
real ep = 4.6; //relative permittivity of particle
Thread *t; ;
real coff = M_PI*e0*pow(dp,3)*((ep-1)/(ep+2))*0.25/(2130.0*M_PI*pow(dp,3)/6.); // coefficienct in polarization force calculation

// Calculating Electric field E and the X-force Fdix from the potential (phi)
thread_loop_c(t,domain)
{
begin_c_loop_int(c,t)
{
C_UDSI(c,t,E) = NV_MAG(C_UDSI_G(c,t,phi));
if(C_UDSI(c,t,E)<=0.0)
C_UDSI(c,t,E)=0.0;
if(C_UDSI(c,t,E)>(Q/e0))
C_UDSI(c,t,E) = Q/e0;

C_UDSI(c,t,Fdix) = (2.*coff*C_UDSI(c,t,E)*(C_UDSI_G(c,t,E)[0]));
}
end_c_loop_int(c,t)
}

// Calculating the electrostatic force F on the face of the cell
thread_loop_f(t,domain)
{
begin_f_loop(f,t)
{
if PRINCIPAL_FACE_P(f,t)
{
if(NULL !=THREAD_STORAGE(t, SV_UDS_I(phi)) && NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(phi)))
F_UDSI(f,t,E)=C_UDSI(F_C0(f,t), t->t0, E);
if(NULL != THREAD_STORAGE(t,SV_UDS_I(E))&& NULL != T_STORAGE_R_NV(t->t0, SV_UDSI_G(E)))
{
F_UDSI(f,t,Fdix)=C_UDSI(F_C0(f,t), t->t0, Fdix);
}
}
}
end_f_loop(f,t)
}
#endif
}

However, it did not result in correct values. The electrostatic field values and forces did not even converge.


I also tried just looping over the compute nodes over all the faces and cells as shown,

#include "udf.h"
#include "mem.h"
#include <stdio.h>
#include <math.h>

#define Q 60.e-06
#define e0 8.854e-12

// Define which user defined scalars to use
enum
{
phi, /* 0 - Electric potential*/
E, /* 1 - Electric field*/
Fdix, /* 2 - x-component Dielectrophoretic force*/
};

DEFINE_ADJUST(Adjust_fun, domain)
{
#if !RP_HOST
cell_t c;
face_t f;
real dp= 300.0e-09; //particle diameter
real ep = 4.6; //relative permittivity of particle
Thread *t; ;
real coff = M_PI*e0*pow(dp,3)*((ep-1)/(ep+2))*0.25/(2130.0*M_PI*pow(dp,3)/6.); // coefficienct in polarization force calculation

// Calculating Electric field E and the X-force Fdix from the potential (phi)
thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{
C_UDSI(c,t,E) = NV_MAG(C_UDSI_G(c,t,phi));
if(C_UDSI(c,t,E)<=0.0)
C_UDSI(c,t,E)=0.0;
if(C_UDSI(c,t,E)>(Q/e0))
C_UDSI(c,t,E) = Q/e0;

C_UDSI(c,t,Fdix) = (2.*coff*C_UDSI(c,t,E)*(C_UDSI_G(c,t,E)[0]));
}
end_c_loop(c,t)
}

// Calculating the electrostatic force F on the face of the cell
thread_loop_f(t,domain)
{
begin_f_loop(f,t)
{
if(NULL !=THREAD_STORAGE(t, SV_UDS_I(phi)) && NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(phi)))
F_UDSI(f,t,E)=C_UDSI(F_C0(f,t), t->t0, E);
if(NULL != THREAD_STORAGE(t,SV_UDS_I(E))&& NULL != T_STORAGE_R_NV(t->t0, SV_UDSI_G(E)))
{
F_UDSI(f,t,Fdix)=C_UDSI(F_C0(f,t), t->t0, Fdix);
}
}
end_f_loop(f,t)
}
#endif
}

the values do not match the results from a single core.

If anyone has any advice on how I can parallelize the UDF it would be of great help.

Thank you.

Hank
Hank- is offline   Reply With Quote

Reply

Tags
#uds #parallelize


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] snappyHexMesh does not detect highly skewed faces? ptpacheco OpenFOAM Meshing & Mesh Conversion 1 January 4, 2022 13:37
[snappyHexMesh] Layers not growing at all zonda OpenFOAM Meshing & Mesh Conversion 12 June 6, 2020 12:28
[snappyHexMesh] sHM layer process keeps getting killed MBttR OpenFOAM Meshing & Mesh Conversion 4 August 15, 2016 04:21
[snappyHexMesh] No layers in a small gap bobburnquist OpenFOAM Meshing & Mesh Conversion 6 August 26, 2015 10:38
snappyhexmesh remove blockmesh geometry philipp1 OpenFOAM Running, Solving & CFD 2 December 12, 2014 11:58


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