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

Print data from UDF to txt file

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 28, 2021, 05:30
Default Print data from UDF to txt file
  #1
New Member
 
Giovanni Fazzone
Join Date: Feb 2021
Posts: 9
Rep Power: 5
fazzesco is on a distinguished road
Hi everybody,
I am writing an UDF in order to update the contact angle between droplet phases of a droplet impacting a wall.
The UDF seems to do not work properly, so I tried to print in a txt file the informations I ned, but the the UDF does not print anything. Does anyone know what can be the problem? Is there a specific folder where I Should save the txt file?

PS if anyone has some other idea for the UDF, please share
Thank you all

My UDF is this
#include "udf.h"
double contact_line_position=0;
double time=0;
double dynamic_contact_angle=15.0;
double contact_velocity=0;
FILE *file_export;
double sum=0.0,R;

DEFINE_ADJUST(Contact_Angle_Update, domain)
{
Thread *thread = Lookup_Thread(domain, 12);
Thread **pt = THREAD_SUB_THREADS(thread);
cell_t cell;
face_t f;
real x[ND_ND];
double max_x=0;
FILE *file_export_2;
int n;
sum=0.0;

begin_c_loop_all (cell,pt[1])
{
if(C_VOF(cell,pt[1])!=0)
{
C_CENTROID(x,cell,pt[1]);
//printf("## x=%f y=%f z=%f vof=%f\n",x[0],x[1],x[2],C_VOF(cell,pt[1]));
if(x[1]>max_x)
max_x=x[1];
}
sum+=C_VOF(cell,pt[1]);
}
end_c_loop_all (cell,pt[1])

R=sqrt(sum*1.0e-08/M_PI);
printf("max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f sum=%f\n",max_x,R,contact_velocity,time,dynamic_co ntact_angle,sum);

contact_velocity= (R-contact_line_position)/(RP_Get_Real("flow-time")-time);
contact_line_position = R;
time=RP_Get_Real("flow-time");

if(contact_velocity>=0)
dynamic_contact_angle= (120.0*M_PI/180.0) ;
else
dynamic_contact_angle= (65.0*M_PI/180.0) ;


file_export = fopen("file_export.txt", "a+");
fprintf(file_export,"max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f\n",max_x,R,contact_veloci ty,time,dynamic_contact_angle);
fclose(file_export);


file_export_2 = fopen("file_export_2.txt", "a+");
fprintf(file_export_2,"max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f\n",max_x,R,contact_veloci ty,time,dynamic_contact_angle);
fclose(file_export_2);

}

DEFINE_PROFILE(Contact_Angle_Set_Profile,t,i)
{
face_t f;
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = dynamic_contact_angle;
}
end_f_loop(f,t)
}
fazzesco is offline   Reply With Quote

Old   April 29, 2021, 01:12
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
if you are using fluent version 2019 and above you must make code in parallel

compile following code:
Code:
#include "udf.h"
real contact_line_position=0;
real time=0;
real dynamic_contact_angle=15.0;
real contact_velocity=0;
real sum=0.0,R;

DEFINE_ADJUST(Contact_Angle_Update, domain)
{
Thread *thread = Lookup_Thread(domain, 12);
Thread **pt = THREAD_SUB_THREADS(thread);
cell_t cell;
face_t f;
real x[ND_ND],cur_time;
real max_x=0;
FILE *file_export, *file_export_2;
int n;
sum=0.0;
cur_time = CURRENT_TIME;
begin_c_loop_all (cell,pt[1])
{
if(C_VOF(cell,pt[1])!=0)
{
C_CENTROID(x,cell,pt[1]);
//printf("## x=%f y=%f z=%f vof=%f\n",x[0],x[1],x[2],C_VOF(cell,pt[1]));
if(x[1]>max_x)
max_x=x[1];
}
sum+=C_VOF(cell,pt[1]);
}
end_c_loop_all (cell,pt[1])
#if RP_NODE
	sum = PRF_GRSUM1(sum);
#endif
R=sqrt(sum*1.0e-08/M_PI);
Message0("max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f sum=%f\n",max_x,R,contact_velocity,time,dynamic_contact_angle,sum);

contact_velocity= (R-contact_line_position)/(cur_time-time);
contact_line_position = R;
time=cur_time;

if(contact_velocity>=0)
dynamic_contact_angle= (120.0*M_PI/180.0) ;
else
dynamic_contact_angle= (65.0*M_PI/180.0) ;

node_to_host_real_5(max_x,R,contact_velocity,time,dynamic_contact_angle);

#if RP_HOST
file_export = fopen("file_export.txt", "a+");
fprintf(file_export,"max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f\n",max_x,R,contact_velocity,time,dynamic_contact_angle);
fclose(file_export);


file_export_2 = fopen("file_export_2.txt", "a+");
fprintf(file_export_2,"max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f\n",max_x,R,contact_velocity,time,dynamic_contact_angle);
fclose(file_export_2);
#endif
}

DEFINE_PROFILE(Contact_Angle_Set_Profile,t,i)
{
face_t f;
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = dynamic_contact_angle;
}
end_f_loop(f,t)
}
brucelqs likes this.
__________________
best regards


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

Old   April 29, 2021, 02:49
Default
  #3
New Member
 
Giovanni Fazzone
Join Date: Feb 2021
Posts: 9
Rep Power: 5
fazzesco is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
if you are using fluent version 2019 and above you must make code in parallel

compile following code:
Code:
#include "udf.h"
real contact_line_position=0;
real time=0;
real dynamic_contact_angle=15.0;
real contact_velocity=0;
real sum=0.0,R;

DEFINE_ADJUST(Contact_Angle_Update, domain)
{
Thread *thread = Lookup_Thread(domain, 12);
Thread **pt = THREAD_SUB_THREADS(thread);
cell_t cell;
face_t f;
real x[ND_ND],cur_time;
real max_x=0;
FILE *file_export, *file_export_2;
int n;
sum=0.0;
cur_time = CURRENT_TIME;
begin_c_loop_all (cell,pt[1])
{
if(C_VOF(cell,pt[1])!=0)
{
C_CENTROID(x,cell,pt[1]);
//printf("## x=%f y=%f z=%f vof=%f\n",x[0],x[1],x[2],C_VOF(cell,pt[1]));
if(x[1]>max_x)
max_x=x[1];
}
sum+=C_VOF(cell,pt[1]);
}
end_c_loop_all (cell,pt[1])
#if RP_NODE
	sum = PRF_GRSUM1(sum);
#endif
R=sqrt(sum*1.0e-08/M_PI);
Message0("max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f sum=%f\n",max_x,R,contact_velocity,time,dynamic_contact_angle,sum);

contact_velocity= (R-contact_line_position)/(cur_time-time);
contact_line_position = R;
time=cur_time;

if(contact_velocity>=0)
dynamic_contact_angle= (120.0*M_PI/180.0) ;
else
dynamic_contact_angle= (65.0*M_PI/180.0) ;

node_to_host_real_5(max_x,R,contact_velocity,time,dynamic_contact_angle);

#if RP_HOST
file_export = fopen("file_export.txt", "a+");
fprintf(file_export,"max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f\n",max_x,R,contact_velocity,time,dynamic_contact_angle);
fclose(file_export);


file_export_2 = fopen("file_export_2.txt", "a+");
fprintf(file_export_2,"max_x=%f R=%f contact_velocity=%f time=%f dynamic_contact_angle=%f\n",max_x,R,contact_velocity,time,dynamic_contact_angle);
fclose(file_export_2);
#endif
}

DEFINE_PROFILE(Contact_Angle_Set_Profile,t,i)
{
face_t f;
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = dynamic_contact_angle;
}
end_f_loop(f,t)
}
Hi Alexander, thank you for your help.
Yes I am using Fluent 19.2. At the program strating, I set it for use in parallele. But, when I try to load the new library with your UDF code, Fluent shows me this error:

Error: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).\n\nImpossibile trovare il file specificato.
\n\nC:\Users\giova\Desktop\Prova UDF da forum\libudf\win64\2ddp_host\libudf.dll
Error Object: #f

Do you know what can be the mistake? Thank you for you help
fazzesco is offline   Reply With Quote

Old   April 29, 2021, 03:13
Default
  #4
New Member
 
Giovanni Fazzone
Join Date: Feb 2021
Posts: 9
Rep Power: 5
fazzesco is on a distinguished road
Sorry, the error was due to the having saved the UDF with a name with spaces.
Now I loaded it, but still does not save the data in the txt files.
Do you have any idea?
fazzesco 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
[OpenFOAM.com] swak4foam compiling issues on a cluster saj216 OpenFOAM Installation 5 January 17, 2023 16:05
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 35 April 29, 2022 15:35
polynomial BC srv537 OpenFOAM Pre-Processing 4 December 3, 2016 09:07
[swak4Foam] build problem swak4Foam OF 2.2.0 mcathela OpenFOAM Community Contributions 14 April 23, 2013 13:59
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 05:18


All times are GMT -4. The time now is 07:43.