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

Export flow rate through faces and the adjacent cells ID

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 31, 2020, 06:46
Unhappy Export flow rate through faces and the adjacent cells ID
  #1
New Member
 
Join Date: Mar 2020
Posts: 2
Rep Power: 0
vincentztl is on a distinguished road
Dear friends,

I'm trying to export flow rate as well as the adjacent cells ID for each face in the domain.
The first question:
My code can be compiled and loaded into FLUENT, but when I use "execute on demand" :
-----------------------------------------------------------------------------------
999999: mpt_accept: error: accept failed: No such file or directory

999999: mpt_accept: error: accept failedMPI Application rank 0 exited before MPI_Finalize() with status 2
The fl process could not be started.
-----------------------------------------------------------------------------------
The second question:
In UDF manual: Get_Domain(domain_id)
Does "domain_id" have the same meaning as "zone XXX" ?
e.g. 16000 hexahedral cells, zone 7, binary. zone 7 means domain_id is 7?




I'm a beginner and this is the first time I write UDF by myself. Maybe I made some stupid mistakes. Really hope someone can help me.


Here's my code:

Code:
#include "udf.h"
#include "mem.h"

 DEFINE_ON_DEMAND(getflux)
 {
 	FILE *fp;
 	Thread *t;
	Domain *domain= Get_Domain(1);
	face_t face;
 	cell_t c,c0,c1;
 	real fl;
 	int n;
 	
 	fp = fopen("data.txt","a+");
 	fprintf(fp,"c0,c1,flux\n");
	thread_loop_c(t,domain)
	{
		begin_c_loop(c,t)
		{
			c_face_loop(c,t,n)
			{
				face = C_FACE(c, t, n);
				c0 = F_C0(face,t);
				c1 = F_C1(face,t);
				fl = F_FLUX(face,t);
				
				fprintf(fp,"%d,%d,%g\n",c0,c1,fl);
			}
		}
		end_c_loop(c,t)
	 } 
 	fclose(fp);
 }

Thank you!
Ps.My English is not good, I'm sorry if it's bothering you.
vincentztl is offline   Reply With Quote

Old   July 31, 2020, 12:23
Default
  #2
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Try this.

#include "udf.h"
#include "mem.h"

DEFINE_ON_DEMAND(getflux)
{
Thread *t;
Domain *d;
d= Get_Domain(1);
face_t f;
cell_t c,c0,c1;
real fl;
int n;

t = Lookup_Thread(d, PROVIDE_THE_ID_HERE);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
c_face_loop(c,t,n)
{
face = C_FACE(c, t, n);
c0 = F_C0(f,t);
c1 = F_C1(f,t);
fl = F_FLUX(f,t);
}
}
end_c_loop(c,t)
}
}
arunraj is offline   Reply With Quote

Old   August 2, 2020, 19:12
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
your code seems to be correct for single core computation,
the only thing could be:
was
Code:
 int n;
to be
Code:
int n=0;
if you want to write into file in parallel fluent, you need to modify your code
Check ANsys Fluent Customization manual for more details
__________________
best regards


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

Old   August 2, 2020, 22:11
Smile
  #4
New Member
 
Join Date: Mar 2020
Posts: 2
Rep Power: 0
vincentztl is on a distinguished road
Hi arunraj and AlexanderZ,
Thanks for your advice !
I've tried your code but the program still can't run successfully. Thank you anyway.
Fortunately, I figure it out. Seems like it's the problem with the using of pointers. The following code can run successfully. Hope it help someone someday.

Code:
#include "udf.h"
#include "mem.h"

 DEFINE_ON_DEMAND(getflux)
 {
 	FILE *fp;
 	Thread *c_thread,*f_thread;
	Domain *domain= Get_Domain(1);
	face_t face;
 	cell_t c,c0,c1;
 	real fl;
 	int n;
 	
 	fp = fopen("data.txt","a+");
 	fprintf(fp,"c0,c1,flux\n");
	thread_loop_c(c_thread,domain)
	{
		begin_c_loop(c,c_thread)
		{
			c_face_loop(c,c_thread,n)
			{
				face = C_FACE(c, c_thread, n);
				f_thread=C_FACE_THREAD(c,c_thread,n);
				c0 = F_C0(face,f_thread);
				c1 = F_C1(face,f_thread);
				fl = F_FLUX(face,f_thread);
				fprintf(fp,"%d,%d,%g\n",c0,c1,fl);
			}
		}
		end_c_loop(c,c_thread)
	 } 
 	fclose(fp);
 }
vincentztl is offline   Reply With Quote

Reply

Tags
data exporting, udf and programming


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



All times are GMT -4. The time now is 19:25.