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

How do I change the serial udf to 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   February 14, 2019, 14:59
Default How do I change the serial udf to parallel?
  #1
New Member
 
dhdh89
Join Date: Oct 2018
Posts: 7
Rep Power: 8
dhdh89 is on a distinguished road
I use udf for membrane calculations.

I want to use face loops to store values ​​in udm consecutively.

When the code in serial mode is calculated in parallel mode, an error occurs.

If you check the values ​​stored in udm, a value of 0 is found.

I converted the example of the customer portal to code it.
How can you convert this code to parallel use?

--------------------------------------
Quote:
#include "udf.h"

#define WALLSIDE1 4
#define WALLSIDE2 9

#define UDM_NEIGHBOUR_C 0
#define UDM_NEIGHBOUR_TC 1
#define UDM_MASS_SOURCE 2

#define TOLERANCE 1E-10

#define SPECIES_NUMBER 0

#define PERMISSIVITY 1.0e-2

#define MY_PRINT Message


DEFINE_INIT(init_function,d)
{

Thread *tc1, *tc2;
Thread *tf1, *tf2;
cell_t c1, c2;
face_t f1, f2;
real f_c1[3], f_c2[3];


thread_loop_c(tc1,d)
{
begin_c_loop(c1,tc1)
{
C_UDMI(c1,tc1,UDM_NEIGHBOUR_C) = 0.0;
C_UDMI(c1,tc1,UDM_NEIGHBOUR_TC) = 0.0;
C_UDMI(c1,tc1,UDM_MASS_SOURCE) = 0.0;
}
end_c_loop(c1,tc1)
}


tf1 = Lookup_Thread(d,WALLSIDE1);
tf2 = Lookup_Thread(d,WALLSIDE2);

begin_f_loop(f1,tf1)
{
F_CENTROID(f_c1,f1,tf1);

c1 = F_C0(f1,tf1);
tc1 = THREAD_T0(tf1);

begin_f_loop(f2,tf2)
{

F_CENTROID(f_c2,f2,tf2);
if (fabs(f_c1[0]-f_c2[0]) <= TOLERANCE &&
fabs(f_c1[1]-f_c2[1]) <= TOLERANCE &&
fabs(f_c1[2]-f_c2[2]) <= TOLERANCE )
{
c2 = F_C0(f2,tf2);
tc2 = THREAD_T0(tf2);

C_UDMI(c1,tc1,UDM_NEIGHBOUR_C) = c2 + 0.1;
C_UDMI(c2,tc2,UDM_NEIGHBOUR_C) = c1 + 0.1;
C_UDMI(c1,tc1,UDM_NEIGHBOUR_TC) = THREAD_ID(tc2) + 0.1;
C_UDMI(c2,tc2,UDM_NEIGHBOUR_TC) = THREAD_ID(tc1) + 0.1;
}
}
end_f_loop(f2,tf2)
}
end_f_loop(f1,tf1)
MY_PRINT("\n Membrane initialisation completed.\n");
}

/////////////////////////////////////////

DEFINE_ADJUST(adjust_sources, d)
{
Thread *tc1, *tc2;
Thread *tf1;
cell_t c1, c2;
face_t f1;
real mass_flux, face_area, face_area_vector[3];
real massfrac1, cell_volume1;
real massfrac2, cell_volume2;

tf1 = Lookup_Thread(d,WALLSIDE1);

begin_f_loop(f1,tf1)
{

F_AREA(face_area_vector,f1,tf1);
face_area = NV_MAG(face_area_vector);

c1 = F_C0(f1,tf1);
tc1 = THREAD_T0(tf1);
cell_volume1 = C_VOLUME(c1,tc1);


c2 = (int)C_UDMI(c1,tc1,UDM_NEIGHBOUR_C);
tc2 = Lookup_Thread(d, (int)C_UDMI(c1,tc1,UDM_NEIGHBOUR_TC));
cell_volume2 = C_VOLUME(c2,tc2);

massfrac1 = C_YI(c1,tc1,SPECIES_NUMBER);
massfrac2 = C_YI(c2,tc2,SPECIES_NUMBER);

mass_flux = face_area * PERMISSIVITY * (massfrac1 - massfrac2);

C_UDMI(c1,tc1,UDM_MASS_SOURCE) = -mass_flux / cell_volume1;
C_UDMI(c2,tc2,UDM_MASS_SOURCE) = +mass_flux / cell_volume2;
}
end_f_loop(f1,tf1)

}
Thanks in advance
dhdh89 is offline   Reply With Quote

Old   February 14, 2019, 22:16
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
ansys fluent customization manual
chapter Parallel Considerations

best regards
AlexanderZ is offline   Reply With Quote

Old   February 19, 2019, 09:37
Default
  #3
New Member
 
dhdh89
Join Date: Oct 2018
Posts: 7
Rep Power: 8
dhdh89 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
ansys fluent customization manual
chapter Parallel Considerations

best regards
I have already tried it.

CODE is calculated, but 0 value is stored in the process of being stored in UDM.

even
C_UDMI (c1, tc1, UDM_MASS_H2_SOURCE) = 2;
0 is also found.
Attached Images
File Type: jpg pic.jpg (79.5 KB, 36 views)
File Type: jpg pic2.jpg (78.5 KB, 23 views)
dhdh89 is offline   Reply With Quote

Old   February 26, 2019, 07:17
Default
  #4
New Member
 
dhdh89
Join Date: Oct 2018
Posts: 7
Rep Power: 8
dhdh89 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
ansys fluent customization manual
chapter Parallel Considerations

best regards
#if !RP_HOST
#endif

I tried this code, but it is useless. Picture 1 shows the picture that succeeded in the serial mode, Picture 2 shows the error that failed in the parallel mode.

a1.jpg

a2.jpg

best regards
dhdh89 is offline   Reply With Quote

Old   February 26, 2019, 22:31
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
in your code you use c_loop once in DEFINE_INIT macro
Code:
thread_loop_c(tc1,d)
{
begin_c_loop(c1,tc1)
{
C_UDMI(c1,tc1,UDM_NEIGHBOUR_C) = 0.0;
C_UDMI(c1,tc1,UDM_NEIGHBOUR_TC) = 0.0;
C_UDMI(c1,tc1,UDM_MASS_SOURCE) = 0.0;
}
end_c_loop(c1,tc1)
}
0 everywhere, thats why you have 0 values.

Code:
C_UDMI (c1, tc1, UDM_MASS_H2_SOURCE) = 2;
what is it? UDM_MASS_H2_SOURCE is not defined

put the whole code you are using (testing)

go deep in ansys fluent customiztion manual,
because you are interested in faces take a look into
Code:
begin_f_loop_int
begin_f_loop_ext
besides this (faces issue) i dont see, why your code should be modified to run in parallel, it should work in both regimes

best regards
AlexanderZ is offline   Reply With Quote

Old   March 11, 2019, 04:26
Default
  #6
New Member
 
dhdh89
Join Date: Oct 2018
Posts: 7
Rep Power: 8
dhdh89 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
in your code you use c_loop once in DEFINE_INIT macro
Code:
thread_loop_c(tc1,d)
{
begin_c_loop(c1,tc1)
{
C_UDMI(c1,tc1,UDM_NEIGHBOUR_C) = 0.0;
C_UDMI(c1,tc1,UDM_NEIGHBOUR_TC) = 0.0;
C_UDMI(c1,tc1,UDM_MASS_SOURCE) = 0.0;
}
end_c_loop(c1,tc1)
}
0 everywhere, thats why you have 0 values.

Code:
C_UDMI (c1, tc1, UDM_MASS_H2_SOURCE) = 2;
what is it? UDM_MASS_H2_SOURCE is not defined

put the whole code you are using (testing)

go deep in ansys fluent customiztion manual,
because you are interested in faces take a look into
Code:
begin_f_loop_int
begin_f_loop_ext
besides this (faces issue) i dont see, why your code should be modified to run in parallel, it should work in both regimes

best regards
Hello AlexanderZ.

I completed my code by converting the reference (UDF69) found in the customer portal. test_question is my entire code (test).

(After initialization) This code can be computed in serial mode, but in parallel mode, it cannot be computed with the following error.

PHP Code:
==============================================================================

Node 999999Process 9616Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 0Process 10276Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 1Process 17332Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 2Process 16140Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 3Process 16116Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 4Process 15552Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 5Process 2596Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 6Process 14084Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 7Process 17948Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 8Process 12884Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 11Process 6856Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 14Process 7012Received signal SIGSEGV.

==============================================================================

==============================================================================

Node 15Process 8276Received signal SIGSEGV.

==============================================================================
MPI Application rank 0 exited before MPI_Finalize() with status 2
The fl process could not be started



I do not know why. I tried the RP_node code and the principal face_p code, but it is useless.

This problem has been blocked for three months. I ask for help.
Attached Files
File Type: c test_question.c (8.8 KB, 11 views)
File Type: c UDF69.c (5.4 KB, 20 views)
dhdh89 is offline   Reply With Quote

Old   March 11, 2019, 05:09
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
did you define enough UDMIs in fluent GUI?

problem my comes from second loop in INIT macro
Code:
  thread_loop_c(tc2,d)
  {
	  begin_c_loop(c2,tc2)
	  {
c2,tc2 are not defined, actually in your code there is no different between c1,tc1 and c2,tc2

best regards
AlexanderZ is offline   Reply With Quote

Old   March 13, 2019, 01:18
Default
  #8
New Member
 
dhdh89
Join Date: Oct 2018
Posts: 7
Rep Power: 8
dhdh89 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
did you define enough UDMIs in fluent GUI?

problem my comes from second loop in INIT macro
Code:
  thread_loop_c(tc2,d)
  {
	  begin_c_loop(c2,tc2)
	  {
c2,tc2 are not defined, actually in your code there is no different between c1,tc1 and c2,tc2

best regards
Yes. I defined 23 UDM in GUI.

c2 and tc2 are defined.

PHP Code:
DEFINE_INIT(init_function,d)
{
  
Thread *tc1, *tc2;
  
Thread *tf1, *tf2;
  
cell_t c1c2;
  
face_t f1f2;
  
real   f_c1[3], f_c2[3]; 
And tc1 and tc2 are obtained by the following values.
PHP Code:
 tf1 Lookup_Thread(d,WALLSIDE1);                            
 
tf2 Lookup_Thread(d,WALLSIDE2); 
This code is from UDF69.

"mpt_accept error accept failed no such file or directory"
As soon as I pressed run calculation after initialization, I got the above error.
This is some parallel / mpi error. I can not resolve this problem yet ..

best regards
dhdh89 is offline   Reply With Quote

Old   May 12, 2020, 04:10
Default UDF for membrane distillation
  #9
New Member
 
Rajeev Awasthi
Join Date: Apr 2020
Posts: 5
Rep Power: 6
rajeev2111 is on a distinguished road
Quote:
Originally Posted by dhdh89 View Post
Yes. I defined 23 UDM in GUI.

c2 and tc2 are defined.

PHP Code:
DEFINE_INIT(init_function,d)
{
  
Thread *tc1, *tc2;
  
Thread *tf1, *tf2;
  
cell_t c1c2;
  
face_t f1f2;
  
real   f_c1[3], f_c2[3]; 
And tc1 and tc2 are obtained by the following values.
PHP Code:
 tf1 Lookup_Thread(d,WALLSIDE1);                            
 
tf2 Lookup_Thread(d,WALLSIDE2); 
This code is from UDF69.

"mpt_accept error accept failed no such file or directory"
As soon as I pressed run calculation after initialization, I got the above error.
This is some parallel / mpi error. I can not resolve this problem yet ..

best regards
I am also working with the same example of UDF69.c . Can you please help me with this. I am also getting the same error. How have you resolved this problem?

Thanks in advance.
rajeev2111 is offline   Reply With Quote

Old   May 12, 2020, 04:35
Default UDMs
  #10
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
One reason could be UDM initialization. UDF69.c does it during initialization, however, if user forgot to hook DEFINE_INIT function, then it will lead to error. But usually, this would lead to segmentation violation. So, the other reason is parallelization. The code is quite old and not parallelized. Current version of Fluent runs in parallel even if you select serial (until you start with -t0), so, you need to parallelize it. Non-parallelized codes do not always cause syntactical problems, but logical ones, i.e., those run but give wrong results. However, sometimes, it may cause errors as well.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 12, 2020, 04:43
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
first of all show the code you are using
code above has some problems with parallelization, at least:
Code:
C_UDMI(c1,tc1,UDM_MASS_SOURCE) = -mass_flux / cell_volume1;
      C_UDMI(c2,tc2,UDM_MASS_SOURCE) = +mass_flux / cell_volume2;
put messages inside code to define the line, which leads to error

simplify code for debugging, later add necessary functionality
rajeev2111 likes this.
__________________
best regards


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

Old   May 12, 2020, 09:05
Default
  #12
New Member
 
Rajeev Awasthi
Join Date: Apr 2020
Posts: 5
Rep Power: 6
rajeev2111 is on a distinguished road
I am hooking the DEFINE_INIT and DEFINE_ADJUST function in the fluent, but still the error is there. I am new to UDF writing, Can you please help me with how to parallelize a UDF or any of the UDF parallelization examples you can provide. That will be a great help for me.

code:
#include "udf.h"

#define WALLSIDE1 30
#define WALLSIDE2 5

#define UDM_NEIGHBOUR_C 0
#define UDM_NEIGHBOUR_TC 1
#define UDM_MASS_SOURCE 2

#define TOLERANCE 1E-10

#define SPECIES_NUMBER 0

#define PERMISSIVITY 1.0e-2

#define MY_PRINT Message

/* User-Defined Functions for a membrane
* permeable to one species but not to fluid
* in general. The membrane is represented
* by a wall (with facezone numbers WALLSIDE1
* and WALLSIDE2 for the wall and its shadow),
* and the mass transfer is brought about by
* source terms in the neighbouring cells.
*
* Written by James Tibbetts and Ed Wynn,
* Fluent Europe, January 2006. */

DEFINE_INIT(init_function,d)
{

Thread *tc1, *tc2;
Thread *tf1, *tf2;
cell_t c1, c2;
face_t f1, f2;
real f_c1[3], f_c2[3];

/*
This routine is run on initialisation. It sets the User-Defined
Memory to appropriate values and initialises the species values
for the entire domain. Also, for the two wall face-zones WALLSIDE1
and WALLSIDE2 (one of which is the shadow of the other), it works
out pairs of cells on either side of each face.
*/

/* Here is the initialisation of the UDM & species: */
thread_loop_c(tc1,d)
{
begin_c_loop(c1,tc1)
{
C_UDMI(c1,tc1,UDM_NEIGHBOUR_C) = 0.0;
C_UDMI(c1,tc1,UDM_NEIGHBOUR_TC) = 0.0;
C_UDMI(c1,tc1,UDM_MASS_SOURCE) = 0.0;
}
end_c_loop(c1,tc1)
}

/* Here is the pairing of cells: */

/* First, find the threads of the two wall face-zones: */
tf1 = Lookup_Thread(d,WALLSIDE1);
tf2 = Lookup_Thread(d,WALLSIDE2);

/* Loop through all faces on one of the face-zones: */
begin_f_loop(f1,tf1)
{
/* Find the centroid of this face: */
F_CENTROID(f_c1,f1,tf1);

/* Find the cell linked to this face: */
c1 = F_C0(f1,tf1);
tc1 = THREAD_T0(tf1);

/* Loop through all faces of the other face-zone: */
begin_f_loop(f2,tf2)
{
/* Find the face with the same centroid, to within
TOLERANCE. TOLERANCE should therefore be a distance
smaller than the size of a cell (but not too much
smaller, to avoid missed pairings due to round-off). */
F_CENTROID(f_c2,f2,tf2);
if (fabs(f_c1[0]-f_c2[0]) <= TOLERANCE &&
fabs(f_c1[1]-f_c2[1]) <= TOLERANCE &&
fabs(f_c1[2]-f_c2[2]) <= TOLERANCE )
{
/* Having found the matching face, find its cell: */
c2 = F_C0(f2,tf2);
tc2 = THREAD_T0(tf2);

/* Note each cell's partner in the User-Defined Memory.
UDMs must record real values -- add 0.1 so that an
integer is not recorded as x.9999999 as the nearest
real. */
C_UDMI(c1,tc1,UDM_NEIGHBOUR_C) = c2 + 0.1;
C_UDMI(c2,tc2,UDM_NEIGHBOUR_C) = c1 + 0.1;
C_UDMI(c1,tc1,UDM_NEIGHBOUR_TC) = THREAD_ID(tc2) + 0.1;
C_UDMI(c2,tc2,UDM_NEIGHBOUR_TC) = THREAD_ID(tc1) + 0.1;
}
}
end_f_loop(f2,tf2)
}
end_f_loop(f1,tf1)
MY_PRINT("\n Membrane initialisation completed.\n");
}
DEFINE_SOURCE(source_mass,c,t,ds,eqn)
{
/* This source term should be applied to the entire
* fluid zone (because it is zero where not needed),
* as both a mass source and a species source. */
ds[eqn] = 0.0;
return C_UDMI(c,t,UDM_MASS_SOURCE);
}

Thanks in advance.
rajeev2111 is offline   Reply With Quote

Old   May 12, 2020, 09:51
Default Serial
  #13
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Check it in Serial first. I hope you are compiling it because it will not work as Interpreted code. If it works in Serial, then parallelization could be done. However, if you get some error in Serial mode, then parallelization may still be required, but only after the other issues have been resolved. And if you get an error during Serial Compilation or execute, please copy the whole error message.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   June 4, 2020, 09:33
Default UDF Error
  #14
New Member
 
Rajeev Awasthi
Join Date: Apr 2020
Posts: 5
Rep Power: 6
rajeev2111 is on a distinguished road
Quote:
Originally Posted by vinerm View Post
Check it in Serial first. I hope you are compiling it because it will not work as Interpreted code. If it works in Serial, then parallelization could be done. However, if you get some error in Serial mode, then parallelization may still be required, but only after the other issues have been resolved. And if you get an error during Serial Compilation or execute, please copy the whole error message.
Hi Vinerm,

I don't know how to run this code in serial. I am using ANSYS 2020R1. I have compiled the UDF successfully and also hooked the function but the fluent is exiting abruptly after the initialization of the case. Please help me in this regard.


Thanks in advance.
rajeev2111 is offline   Reply With Quote

Old   June 4, 2020, 10:04
Default Serial
  #15
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
Start Fluent with -t0 as option.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm 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
serial udf to parallel udf radioss Fluent UDF and Scheme Programming 10 January 19, 2019 09:56
Dynamic mesh in parallel udf rsarma Fluent UDF and Scheme Programming 3 August 2, 2018 08:02
Fluent UDF wrong number of cells in parallel - correct in serial dralexpe Fluent UDF and Scheme Programming 7 May 17, 2018 09:26
Unsteady boundary condition UDF for parallel FLUENT Hong M.H Fluent UDF and Scheme Programming 7 October 18, 2017 22:01
Dynamic Mesh- Parallel UDF DE HEART Fluent UDF and Scheme Programming 14 August 11, 2010 02:29


All times are GMT -4. The time now is 00:51.