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

read volume fraction for a coordinate

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 21, 2020, 17:21
Default read volume fraction for a coordinate
  #1
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
Dear All,

I need to write a UDF code that reports volume fraction value for a coordinate ( or could be a node ) within a two-phase flow problem at a certain time, I have the following code, I have two issues:

1) I don't know how to make the UDF print the result at the console, is " printf" the correct way to request the UDF to print to the console?
2) Is this the right way to set up the time? How can I request to report the volume fraction at end of each time step?

#include "udf.h"
DEFINE_ON_DEAMND(volume_fraction)
{
real current_time;
current_time=CURRENT_TIME;
real volume_fraction;
Domain *mixture_domain;
mixture_domain=Get_Domain(1);
cell_t c;
thread *t;
thread **pt;
volume_fraction=c_VOF(c,pt[1]);
}
printf("\n volume_fraction % g",volume_fraction)

Truly appreciate any advice.
henry_cfd_questions is offline   Reply With Quote

Old   October 23, 2020, 04:22
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
you may try this code, COMPILE IT, allocate 2 user defined variables in fluent GUI so you can plot vol_frac distribution along the domain
Code:
#include "udf.h"
DEFINE_ON_DEAMND(volume_fraction)
{
	Domain *domain;
	cell_t c;
	Thread *mix_thread,*thread_g, *thread_s;
	real current_time;
	domain=Get_Domain(1);
	/* find the threads for the gas (primary) */
	/* and solids (secondary phases) */

	current_time=CURRENT_TIME;

	thread_loop_c (mix_thread,domain)
	{
		begin_c_loop (c,mix_thread)
		{
			thread_g = THREAD_SUB_THREAD(mix_thread, 0);/* gas phase */
			thread_s = THREAD_SUB_THREAD(mix_thread, 1);/* solid phase*/
			
			void_g = C_VOF(cell, thread_g);/* gas vol frac*/
			void_s = C_VOF(cell, thread_s);/* solid vol frac*/
			C_UDMI(c,mix_thread,0) = void_g; 
			C_UDMI(c,mix_thread,1) = void_s;
			Message0("volume_fraction of phase 0:  %f | volume_fraction of phase 1:  %f \n",void_g,void_s);
		}
		end_c_loop (c,mix_thread)
	}
}
__________________
best regards


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

Old   October 23, 2020, 04:28
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
also you may try something like this, to write to file
Code:
#include "udf.h"
FILE *fout;

void Print_vol_fraction(Domain *domain, int id)
{
cell_t c;
real vol_frac;
Thread *t = Lookup_Thread(domain, id);
fprintf(fout,"thread id %d\n", id);
begin_c_loop(c,t)
{
vol_frac = C_VOF(c, t);
fprintf(fout, "c vol_frac: %f\n", c, vol_frac);
}
end_f_loop(c,t)
fprintf(fout, "\n");
}

DEFINE_ON_DEMAND(get_coords)
{
Domain *domain;
domain = Get_Domain(1);
fout = fopen("faces.out", "w");
Print_vol_fraction(domain, 0);
Print_vol_fraction(domain, 1);
fclose(fout);
}
__________________
best regards


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

Old   October 23, 2020, 13:37
Default
  #4
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
Thanks, AlexanderZ for your help, this is very helpful.

Would you also know how this code can be used to print the volume fraction in only one certain point (with given coordinate values of x,y,z ). I looked into the C_CETROID and Grid variables but couldn't make it to specify a point.

Here is how I tried to specify a point :

real xc[ND_ND];
C_CENTROID(xc,cell,cell_thread);

I think I need to use an "if" statement here to specify the point location?

Thanks
Henry
henry_cfd_questions is offline   Reply With Quote

Old   October 26, 2020, 07:55
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
last code will look like this:

Code:
#include "udf.h"
FILE *fout;

void Print_vol_fraction(Domain *domain, int id)
{
cell_t c;
real vol_frac;
real x[ND_ND];
real point = {0.1,0.1,0.1};
real delta = 0.05;
Thread *t = Lookup_Thread(domain, id);
fprintf(fout,"thread id %d\n", id);
begin_c_loop(c,t)
{
C_CENTROID(x,c,t); // here x[0] - coord along x-axis, x[1]  - coord along y-axis, x[2]  - coord along z-axis (if 3D)
vol_frac = C_VOF(c, t);
if ((x[0] > point[0]-delta) && (x[0] <= point[0]+delta))
	if ((x[1] > point[1]-delta) && (x[1] <= point[1]+delta))
		if ((x[2] > point[2]-delta) && (x[2] <= point[2]+delta))
			fprintf(fout, "c vol_frac: %f\n", c, vol_frac);
}
end_f_loop(c,t)
fprintf(fout, "\n");
}

DEFINE_ON_DEMAND(get_coords)
{
Domain *domain;
domain = Get_Domain(1);
fout = fopen("faces.out", "w");
Print_vol_fraction(domain, 0);
Print_vol_fraction(domain, 1);
fclose(fout);
}
delta is some interval where you expect to get the center of cell (around the half of size of element volume)
__________________
best regards


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

Old   October 27, 2020, 16:19
Default
  #6
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
Very Helpful Alexander Z, thanks for your support.
henry_cfd_questions is offline   Reply With Quote

Old   November 22, 2020, 02:56
Default
  #7
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
AlexanderZ

I am working on a 2 phase flow model and following all steps to generate the air fraction which is a bubble inside a channel. Then patch, initialize, and check contours for air phase, fluent doesn't show the air bubble. I am not sure what I do wrong but I have done this before and I did not have a problem with this part. Please let me know if you can help, this is very frustrating.

Thanks
Hanry
henry_cfd_questions is offline   Reply With Quote

Old   November 22, 2020, 22:55
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
initialize first, than patch, make sure you are not initializing case after patching it
__________________
best regards


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

Old   November 23, 2020, 15:31
Default
  #9
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
AlexanderZ,

I truly appreciate your help, one small mistake made me redo the model many times.

Thanks again.
henry_cfd_questions is offline   Reply With Quote

Old   January 21, 2021, 22:54
Default UDF compiling Error
  #10
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
Dear AlexanderZ,

It is been a while I see this error and have been looking to fix it, some says it is a visual studio issue, I would like to ask if you know how to make the files compiled, I get this error for compiling, the interpreting has its own issues, so it would be great if I could compile the files instead, but here it goes :


The error in windows :

The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).
henry_cfd_questions is offline   Reply With Quote

Old   January 21, 2021, 23:35
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
Code:
The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).
it means what it literally says
compile UDF file
__________________
best regards


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

Old   January 23, 2021, 16:44
Default
  #12
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
Does that mean my code has issues?
I have tried to compile simple files, still get the same error.

Thanks
Hanry
henry_cfd_questions is offline   Reply With Quote

Old   January 23, 2021, 16:46
Default
  #13
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
What do you suggest I should do ?
henry_cfd_questions is offline   Reply With Quote

Old   January 24, 2021, 03:03
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
This is not the error that you see when you try to compile ;this is the error when you try to load. (read it!)

Look at the error(s) when you compile.
pakk is offline   Reply With Quote

Old   January 25, 2021, 03:06
Default
  #15
New Member
 
Join Date: Mar 2018
Posts: 11
Rep Power: 8
henry_cfd_questions is on a distinguished road
Hi PAKK,

I agree, it is the error when loading, but does that mean the code has an issue that its why it is not compiling?

Thanks
Hanry
henry_cfd_questions is offline   Reply With Quote

Old   January 27, 2021, 01:40
Default
  #16
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
It literally says that the code is not compiled. It does not say the reason, that's why I tell you to look what happens when you try to compile. There you should see the reason.
pakk 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
Simulation crashes when turbulence is on (reactingMultiphaseEulerFoam) remidemol OpenFOAM Running, Solving & CFD 3 May 26, 2020 05:47
Is it possible that multi-phase flow shows gradation of volume fraction? kjh9537 Fluent UDF and Scheme Programming 0 June 23, 2017 14:16
volume fraction = nan Virtual-iCFD OpenFOAM Running, Solving & CFD 8 June 12, 2015 18:15
Water subcooled boiling Attesz CFX 7 January 5, 2013 03:32
[blockMesh] error message with modeling a cube with a hold at the center hsingtzu OpenFOAM Meshing & Mesh Conversion 2 March 14, 2012 09:56


All times are GMT -4. The time now is 03:23.