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

Indefinite hold when executing DEFINE_ON_DEMAND

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 19, 2020, 00:16
Default Indefinite hold when executing DEFINE_ON_DEMAND
  #1
New Member
 
Hosea Chan
Join Date: Nov 2018
Posts: 4
Rep Power: 7
Hosea_Chan is on a distinguished road
Dear forum users,

I am currently writing a code that sums the volume for 4 cell zones at the before the initialization, which the values will be used in 4 subsequent DEFINE_SOURCE macros. Specifically, I need to apply an x-momentum force that is dependent on the average velocity at the upstream face of the cell zone and apply the force evenly to the fluid body within the cell zone. Here is the portion of the code I have written for the volume sum:
Code:
#include "udf.h"
#define cell_zones 4

real total_volume[cell_zones];
real Ux[cell_zones];
int id_a[cell_zones] = {28,33,37,40}; /* get zone id of channel-in later, need input */
int id_v[cell_zones] = {9,10,11,12}; /* get zone id of channel volume later, need input */



DEFINE_ON_DEMAND(initialize)
{
	#if !RP_HOST

		Domain* d;
		
		int i;
		d = Get_Domain(1);
	
		for (i=0; i<4 ; i++) {
			Message0("Begin loop %d\n",i);
			cell_t c;
			Thread* t2 = Lookup_Thread(d,id_v[i]);
			begin_c_loop(c, t2) 
				{
				total_volume[i] += C_VOLUME(c,t2);
				}
			end_c_loop(c, t2)
			Message0("End loop %d\n",i);
			#if RP_NODE
				total_volume[i] = PRF_GRSUM1(total_volume[i]);
				
			#endif
			node_to_host_real_1(total_volume[i]);
			Message0("total_volume of zone %d: %12.4e\n", i,total_volume[i]);
			
		}
		#if RP_NODE

		#endif /* RP_NODE */
		
	#endif /* !RP_HOST */

}
However, when I execute this code through execute on demand, the code can execute to the end (as I have gotten the total volume displayed for all the cell zones) but Fluent are kept busy. I checked CPU usage and all the node processes are still busy as well. What could have gone wrong here? Thank you for the help in advance!

Best regards,
Hosea Chan

Last edited by Hosea_Chan; November 19, 2020 at 03:03.
Hosea_Chan is offline   Reply With Quote

Old   November 19, 2020, 05:13
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
#include "udf.h"
#define cell_zones 4

real total_volume[cell_zones];
real Ux[cell_zones];
int id_a[cell_zones] = {28,33,37,40}; /* get zone id of channel-in later, need input */
int id_v[cell_zones] = {9,10,11,12}; /* get zone id of channel volume later, need input */



DEFINE_ON_DEMAND(initialize)
{
#if !RP_HOST

Domain* d;

int i;
d = Get_Domain(1);

for (i=0; i<4 ; i++) {
Message0("Begin loop %d\n",i);
cell_t c;
Thread* t2 = Lookup_Thread(d,id_v[i]);
begin_c_loop(c, t2)
{
total_volume[i] += C_VOLUME(c,t2);
}
end_c_loop(c, t2)
Message0("End loop %d\n",i);
#if RP_NODE
total_volume[i] = PRF_GRSUM1(total_volume[i]);

#endif
Message0("total_volume of zone %d: %12.4e\n", i,total_volume[i]);

}
#endif /* !RP_HOST */

}
Hosea_Chan likes this.
__________________
best regards


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

Old   November 19, 2020, 05:23
Default
  #3
New Member
 
Hosea Chan
Join Date: Nov 2018
Posts: 4
Rep Power: 7
Hosea_Chan is on a distinguished road
Dear Alex,

Thank you so much! The code works! So it seems like it is the line of

node_to_host_real1(total_volume[i]);

is holding up the macro. As I have defined total_volume as a global variable, do I need to transfer it back to the host so that the variable can be used in the subsequent macros? Thanks!

Best regards,
Hosea
Hosea_Chan is offline   Reply With Quote

Old   November 19, 2020, 21:55
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
usually, you want to return values to host in cases:
1. you want to read/write from/to file
2. you want to transfer values to cortex (to use in scheme code for instance)

so most likely you don't need to transfer.
But if you are going to transfer, read how to make it for arrays

Ansys Fluent Customization manual
Hosea_Chan likes this.
__________________
best regards


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

Old   November 20, 2020, 08:09
Default
  #5
New Member
 
Hosea Chan
Join Date: Nov 2018
Posts: 4
Rep Power: 7
Hosea_Chan is on a distinguished road
Dear Alex,

Thank you very much for your clear explanation! This is a great help over the manual text!

Best regards,
Hosea
Hosea_Chan 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
Does Stokes hypothesis still hold for compressible flow? TurbJet Main CFD Forum 6 February 20, 2018 03:46
"epsAvg_0", "epsMax_0" and "epsMin_0" after executing foamLog KeiJun OpenFOAM Running, Solving & CFD 0 October 20, 2015 11:35
Force fluent to hold only last timestep ansys_matt FLUENT 3 August 24, 2014 23:07
Hold up in a closed vessel Pascale Fonteijn CFX 4 June 9, 2003 13:27


All times are GMT -4. The time now is 22:42.