|
[Sponsors] |
how to plot new function or variable in fluent? |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 4, 2014, 03:46 |
how to plot new function or variable in fluent?
|
#1 |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
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 |
|
July 4, 2014, 10:11 |
|
#2 |
Senior Member
Join Date: Nov 2010
Posts: 103
Rep Power: 16 |
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"); |
|
July 4, 2014, 14:26 |
|
#3 | |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
Quote:
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; } thankyou for reply |
||
July 5, 2014, 07:33 |
|
#4 |
Senior Member
Join Date: Nov 2010
Posts: 103
Rep Power: 16 |
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) } } Cheers! |
|
July 5, 2014, 08:45 |
|
#5 |
Member
Christopher Hershey
Join Date: Feb 2012
Location: East Lansing, Michigan
Posts: 41
Rep Power: 14 |
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.
|
|
July 5, 2014, 12:56 |
|
#6 |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
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. |
|
July 5, 2014, 13:16 |
|
#7 |
Member
Mustafa
Join Date: May 2013
Posts: 54
Rep Power: 13 |
In fluent .go to define and choose custom field functions
|
|
July 6, 2014, 07:36 |
|
#8 |
Senior Member
Join Date: Nov 2010
Posts: 103
Rep Power: 16 |
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 ?
|
|
July 6, 2014, 07:43 |
|
#9 |
Member
Mustafa
Join Date: May 2013
Posts: 54
Rep Power: 13 |
I haven't tried udmi
|
|
July 6, 2014, 13:07 |
|
#10 | |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
Quote:
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? |
||
July 6, 2014, 13:10 |
|
#11 |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
||
July 7, 2014, 05:41 |
|
#12 | |
Senior Member
Join Date: Nov 2010
Posts: 103
Rep Power: 16 |
Quote:
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*/ http://aerojet.engr.ucdavis.edu/flue...udf/node96.htm Cheers! |
||
July 7, 2014, 09:21 |
|
#13 | |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
Quote:
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? |
||
July 7, 2014, 10:18 |
|
#14 |
Senior Member
Join Date: Nov 2010
Posts: 103
Rep Power: 16 |
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! |
|
July 8, 2014, 08:03 |
|
#15 | |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
Quote:
should i reduce it again sun? hmm,, make it about 0.5 second? max iterations per time step is 1. |
||
July 8, 2014, 08:10 |
|
#16 |
Member
Christopher Hershey
Join Date: Feb 2012
Location: East Lansing, Michigan
Posts: 41
Rep Power: 14 |
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.
|
|
July 8, 2014, 11:45 |
|
#17 |
Senior Member
Join Date: Nov 2010
Posts: 103
Rep Power: 16 |
||
July 8, 2014, 14:13 |
|
#18 | |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
Quote:
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... |
||
July 8, 2014, 14:14 |
|
#19 |
New Member
Jups
Join Date: Jul 2014
Posts: 12
Rep Power: 12 |
||
July 8, 2014, 18:15 |
|
#20 | |
Member
Christopher Hershey
Join Date: Feb 2012
Location: East Lansing, Michigan
Posts: 41
Rep Power: 14 |
Quote:
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 |
||
Tags |
new function, plot |
|
|
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 |