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

how to plot new function or variable in fluent?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 4, 2014, 03:46
Default how to plot new function or variable in fluent?
  #1
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
i have a function that need to be plot..
the function is a new variable that i define by myself..
the function is "adsorption capacity"
i am doing ANG case (adsorbed Narutal Gas)
here my UDF

DEFINE_INIT(q_init,d)
{
cell_t c;
Thread *t;

thread_loop_c(t,d)
{
begin_c_loop_all(c,t)
{
C_T(c,t)=300;
C_P(c,t)=100000;
q = 0;
}
end_c_loop_all(c,t)
}
}


turq = k*(qe-q);
q = q+turq*time;

i need to plot the "q"

kindly help,
jups
Jups is offline   Reply With Quote

Old   July 4, 2014, 10:11
Default
  #2
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 15
Sun is on a distinguished road
you can probably use EXECUTE_ON_DEMAND or EXECUTE_AT_END to write the results of "q" in a text file and then use the output to plot "q". e.g.
Code:
FILE *fp;
fp=fopen("q_output.txt","w");
cheers!
Sun is offline   Reply With Quote

Old   July 4, 2014, 14:26
Default
  #3
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
Quote:
Originally Posted by Sun View Post
you can probably use EXECUTE_ON_DEMAND or EXECUTE_AT_END to write the results of "q" in a text file and then use the output to plot "q". e.g.
Code:
FILE *fp;
fp=fopen("q_output.txt","w");
cheers!

could you help me more?
i still dont get it
this is my full UDF
Code:
#include "udf.h"
#define P 3000000
#define T 300
#define e 0.65
#define Rc 500
#define k 0.00013996
#define qe 0.0698337
double q, time, turq;

DEFINE_INIT(q_init,d)
{
cell_t c;
Thread *t;

thread_loop_c(t,d)
  {
    begin_c_loop_all(c,t)
     {
       C_T(c,t)=300;
       C_P(c,t)=100000;
       q = 0;
     }
    end_c_loop_all(c,t)
   }
}



DEFINE_SOURCE(mass_source, cell, thread)
{
real source;
time = CURRENT_TIME;

turq = k*(qe-q);
q = q+turq*time;

source = -((1-e)/e)*turq*Rc;
return source;

}



DEFINE_SOURCE(y_velocity, cell, thread)
{
real source;
time = CURRENT_TIME;

turq = k*(qe-q);
q = q+turq*time;

source = -turq*Rc*C_V(cell,thread);
return source;
}



DEFINE_SOURCE(radial_velocity, cell, thread)
{
real source;
time = CURRENT_TIME;

turq = k*(qe-q);
q = q+turq*time;

source = -turq*Rc*C_V(cell,thread);
return source;
}



DEFINE_SOURCE(energy_source, cell, thread)
{
real ha, source;
time = CURRENT_TIME;

turq = k*(qe-q);
q = q+turq*time;

ha = 15568000;
source = -turq*Rc*H;
return source;
}
or can you edit the function so that the q can be plot?

thankyou for reply
Jups is offline   Reply With Quote

Old   July 5, 2014, 07:33
Default
  #4
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 15
Sun is on a distinguished road
I haven't been using fluent for a while and bit rusty with its syntax...but actually there is a more convenient way of doing it ... you can store your results inside a User Defined Memory (UDM) and if I remember correctly you can have up to 50 UDMs...And the cool thing is you can plot the UDMs vs time or any other independent variables of interest...For example I was looking at my old UDFs where I had stored the bubble Reynolds number inside UDM0...here is the code snippet:
Code:
#include "udf.h"

DEFINE_ON_DEMAND(someVariables)
	{
		Domain *mixd;
		
		/*INPUTS*/
		/*A bunch of computations here*/
		/* getting the domains and etc*/
		Thread *t;
		cell_t c;
		Thread *mixt;
		Thread *thread_g;
		Thread *thread_f;
	
		/** Mixture Domain **/	
		mixd = Get_Domain(1);	
		
		thread_loop_c(mixt,mixd)	
			{
				/*Gas and Pulp threads*/
				thread_g = THREAD_SUB_THREAD(mixt,1);
				thread_f = THREAD_SUB_THREAD(mixt,0);
				

/* This is where I am computing the slip velocity */
				begin_c_loop(c,mixt)
				{
					/*Slip velocity*/
					x_vel_f = C_U(c,thread_f);
   					y_vel_f = C_V(c,thread_f);
					z_vel_f = C_W(c,thread_f);
   					x_vel_g = C_U(c,thread_g);
   					y_vel_g = C_V(c,thread_g);
   					z_vel_g = C_W(c,thread_g);
   
   					slip_x = -x_vel_f + x_vel_g;
   					slip_y = -y_vel_f + y_vel_g;
   					slip_z = -z_vel_f + z_vel_g;
   
   					slip_vel = sqrt(slip_x*slip_x + slip_y*slip_y + slip_z*slip_z);
					/*Bubble Reynolds number*/
					re_b = (d_b*slip_vel)/kin_vis;
					
/* This is where I am storing it inside UDMI0 */
                                         
C_UDMI(c,mixt,0) = re_b;
					
/*I think you can do the same with respect to your problem*/
					
					
				}
				end_c_loop(c,mixt)
			}
		
	}
hope it helps.
Cheers!
Sun is offline   Reply With Quote

Old   July 5, 2014, 08:45
Default
  #5
Member
 
Christopher Hershey
Join Date: Feb 2012
Location: East Lansing, Michigan
Posts: 41
Rep Power: 14
Hershey is on a distinguished road
It seems to me that your value for q will always stay at zero from your initialization step. If you want to use it across each function then use Sun's suggestion of C_UDMI(cell,thread,0) for q. Then you can use it to plot in fluent. As your code stands right now, I do not see how the value of q will get passed to each function at each time step.
Hershey is offline   Reply With Quote

Old   July 5, 2014, 12:56
Default
  #6
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
sun, may i have your email?
so that i can consult with you more intensive..
thankyou before sun


Hersey, i think the q value only at start is zero because i put zero value only for initialize,, in my mind, initialize is the initial condition or the beginning condition.. am i wrong?
i have so much complicated thing in this fluent cause i only learn it 3 months ago,, my lecturer ask me to do this thing for my graduate.. i hope u could help me more Hersey.. I really really need someone help right now..



in this problem i need to define the q value for beginning is 0
then the next q value is the function below :

q = q + turq*time

i have turq value, i have time...
so the next q is
q = 0 (the intial q that zero) + turq*time
then we have new q value, let's we say it 10..
then the next q is
q = 10 + turq*time
like looping..
i confused to make this... after that, i need to plot the q function...



thanks before SUN and HERSHEY
i really really thank for you two )

Last edited by Jups; July 6, 2014 at 13:02.
Jups is offline   Reply With Quote

Old   July 5, 2014, 13:16
Default
  #7
Member
 
Mustafa
Join Date: May 2013
Posts: 54
Rep Power: 12
Mohawk is on a distinguished road
In fluent .go to define and choose custom field functions
Mohawk is offline   Reply With Quote

Old   July 6, 2014, 07:36
Default
  #8
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 15
Sun is on a distinguished road
let's keep the conversation in the forum, so others can join, benefit and contribute...but in case if the problem needs more talks on the details I can send you my email add. BTW, have you tried the UDMI ?
Sun is offline   Reply With Quote

Old   July 6, 2014, 07:43
Default
  #9
Member
 
Mustafa
Join Date: May 2013
Posts: 54
Rep Power: 12
Mohawk is on a distinguished road
I haven't tried udmi
Mohawk is offline   Reply With Quote

Old   July 6, 2014, 13:07
Default
  #10
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
Quote:
Originally Posted by Sun View Post
let's keep the conversation in the forum, so others can join, benefit and contribute...but in case if the problem needs more talks on the details I can send you my email add. BTW, have you tried the UDMI ?

okay.. benefit and contribute..
i tell you later if the case gets more and more complicated..
im still thinking, where should i link the UDMI?
Should i make a new UDF only for q then i link it to UDMI?
Jups is offline   Reply With Quote

Old   July 6, 2014, 13:10
Default
  #11
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
Quote:
Originally Posted by Mohawk View Post
In fluent .go to define and choose custom field functions
could you tell me more specific about custom field funtions mohawk?

thankyou before mohawk
Jups is offline   Reply With Quote

Old   July 7, 2014, 05:41
Default
  #12
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 15
Sun is on a distinguished road
Quote:
Originally Posted by Jups View Post
okay.. benefit and contribute..
im still thinking, where should i link the UDMI?
Should i make a new UDF only for q then i link it to UDMI?
you don't need to create a separate UDF for the UDMI. Just store the "q" ...like the example I shared

Code:
/* This is where I am storing it inside UDMI0 */
                                         
C_UDMI(c,mixt,0) = re_b;
					
/*I think you can do the same with respect to your problem*/
Have a look at this page to figure out how to link/define the UDMI:
http://aerojet.engr.ucdavis.edu/flue...udf/node96.htm

Cheers!
Sun is offline   Reply With Quote

Old   July 7, 2014, 09:21
Default
  #13
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
Quote:
Originally Posted by Sun View Post
you don't need to create a separate UDF for the UDMI. Just store the "q" ...like the example I shared

Code:
/* This is where I am storing it inside UDMI0 */
                                         
C_UDMI(c,mixt,0) = re_b;
                    
/*I think you can do the same with respect to your problem*/
Have a look at this page to figure out how to link/define the UDMI:
http://aerojet.engr.ucdavis.edu/flue...udf/node96.htm

Cheers!
i have try UDMI, it's work
thankyou very much sun..

but i have another problem right now,, i think the problem is q..
when the plot of q shown,, the q value from 0 suddenly increase to 0,069 (maksimum value for q in my case)..
q value should increase slowly, example..
0 then 0,00005 then 0,00006 then ..... then 0,069 (maksimum)..
do you have any idea?
Jups is offline   Reply With Quote

Old   July 7, 2014, 10:18
Default
  #14
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 15
Sun is on a distinguished road
Since the "q" mostly depends on time, reduce your time step and I think you should be able to see the gradual increase of this factor.
Cheers!
Sun is offline   Reply With Quote

Old   July 8, 2014, 08:03
Default
  #15
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
Quote:
Originally Posted by Sun View Post
Since the "q" mostly depends on time, reduce your time step and I think you should be able to see the gradual increase of this factor.
Cheers!
the time step i use is 1 second..
should i reduce it again sun? hmm,, make it about 0.5 second?
max iterations per time step is 1.
Jups is offline   Reply With Quote

Old   July 8, 2014, 08:10
Default
  #16
Member
 
Christopher Hershey
Join Date: Feb 2012
Location: East Lansing, Michigan
Posts: 41
Rep Power: 14
Hershey is on a distinguished road
Your problem is that each source udf is being called at each iteration. So every iteration, the value of q is changing. Then this factor is changing for each source term. I would recommend using a DEFINE_ADJUST udf to calculate the q value at the current time step, save it to the C_UDMI and then call the C_UDMI in each of the source udf. There is a way to only calculate q for the first iteration of the timestep, but I am not at my computer to look up the reference. I will get back to you.
Hershey is offline   Reply With Quote

Old   July 8, 2014, 11:45
Default
  #17
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 15
Sun is on a distinguished road
Quote:
Originally Posted by Jups View Post
the time step i use is 1 second..
should i reduce it again sun? hmm,, make it about 0.5 second?
max iterations per time step is 1.
I would probably change the time step to something around 1E-4 or 1E-5.
Sun is offline   Reply With Quote

Old   July 8, 2014, 14:13
Default
  #18
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
Quote:
Originally Posted by Hershey View Post
Your problem is that each source udf is being called at each iteration. So every iteration, the value of q is changing. Then this factor is changing for each source term. I would recommend using a DEFINE_ADJUST udf to calculate the q value at the current time step, save it to the C_UDMI and then call the C_UDMI in each of the source udf. There is a way to only calculate q for the first iteration of the timestep, but I am not at my computer to look up the reference. I will get back to you.

Hersey, you mean, i have to calculate q in DEFINE_ADJUST then save it to C_UDMI.. and then in DEFINE_SOURCE i call the C_UDMI for the q?
so i separate q and source? like that?
okay Hersey, i wait patiently
thankyou Hersey...
Jups is offline   Reply With Quote

Old   July 8, 2014, 14:14
Default
  #19
New Member
 
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 11
Jups is on a distinguished road
Quote:
Originally Posted by Sun View Post
I would probably change the time step to something around 1E-4 or 1E-5.
later i will try to change the time step.. i will tell you the result soon Sun..
thankyou very much Sun
Jups is offline   Reply With Quote

Old   July 8, 2014, 18:15
Default
  #20
Member
 
Christopher Hershey
Join Date: Feb 2012
Location: East Lansing, Michigan
Posts: 41
Rep Power: 14
Hershey is on a distinguished road
Quote:
Originally Posted by Jups View Post
Hersey, you mean, i have to calculate q in DEFINE_ADJUST then save it to C_UDMI.. and then in DEFINE_SOURCE i call the C_UDMI for the q?
so i separate q and source? like that?
okay Hersey, i wait patiently
thankyou Hersey...
Yes. Since your equation for q is the same in each source, it would be better to define it in DEFINE_ADJUST by saving the value as C_UDMI(c,t,0) = q. Then in the DEFINE_SOURCE you should just reference C_UDMI(c,t,0) instead of q.

In the DEFINE_ADJUST, there are a couple things you must do:

1. You must use begin_cell_loop(c,t) to loop through the cells for C_UDMI. Try looking at Google to fine this and an example.

2. Finally, since DEFINE_ADJUST is called at the beginning of every iteration (not time step), you will want to only calculate q for the first iteration. Look at the following link on how to do that:

http://www.cfd-online.com/Forums/flu...luent-5-a.html
Hershey is offline   Reply With Quote

Reply

Tags
new function, plot

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
heat transfer with RANS wall function, over a flat plate (validation with fluent) bruce OpenFOAM Running, Solving & CFD 6 January 20, 2017 07:22
LiencubiclowRemodel nzy102 OpenFOAM Bugs 14 January 10, 2012 09:53
Variable Density Function ryzd FLUENT 1 August 25, 2011 15:16
Problem with rhoSimpleFoam matteo_gautero OpenFOAM Running, Solving & CFD 0 February 28, 2008 07:51
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 18:51


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