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

changing scheme variable with UDF?

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By Joe

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 12, 2007, 09:35
Default changing scheme variable with UDF?
  #1
Wagemakers
Guest
 
Posts: n/a
Hi All,

Is it possible to change or set a scheme variable through an UDF? Currently, I use rpsetvar after I get the value from the UDF by printf. Is there a way to do this directly in the UDF?

Thanks

  Reply With Quote

Old   September 12, 2007, 09:41
Default Re: changing scheme variable with UDF?
  #2
Joe
Guest
 
Posts: n/a
yes. section 3.6 in the udf manual.
Kwin likes this.
  Reply With Quote

Old   September 13, 2007, 06:10
Default Re: changing scheme variable with UDF?
  #3
Wagemakers
Guest
 
Posts: n/a
Thanks joe for the rapid respons,

I can access a scheme variable by rpgetvar in an UDF, and I'd like to change that variable within this UDF, not trhough the text interface by using rpsetvar. Is there a command similar to rpsetvar that can be used in the UDF? I read the UDf manual 3.6, but I don't seem to find it. Am I overlooking something?

With regards, R. Wagemakers

  Reply With Quote

Old   November 24, 2014, 06:56
Default
  #4
New Member
 
Dr. Aliosha's Avatar
 
Join Date: Nov 2014
Location: Italy
Posts: 9
Rep Power: 12
Dr. Aliosha is on a distinguished road
Hi Wagemakers,
I'm facing the same problem.
Did you find any answer or workaround?

Regards,
Alessandro
Dr. Aliosha is offline   Reply With Quote

Old   November 24, 2014, 11:25
Default
  #5
Senior Member
 
Andrew Kokemoor
Join Date: Aug 2013
Posts: 122
Rep Power: 14
Kokemoor is on a distinguished road
UDF Manual, section 3.6.4, has what you're looking for.
Kokemoor is offline   Reply With Quote

Old   November 24, 2014, 11:45
Default
  #6
New Member
 
Dr. Aliosha's Avatar
 
Join Date: Nov 2014
Location: Italy
Posts: 9
Rep Power: 12
Dr. Aliosha is on a distinguished road
Hi Kokemoor,
Thanks for your reply.
Looking at the UDF Manual (section 3.6.4), however, it seems that it's possible to define a scheme variable or get and use its value within the UDF.
It is also possible to change the scheme-variable value, from the text interface.

What I am looking for is a way to change the scheme-variable value from the UDF (instead of the text interface).

Any suggestion?

Thanks.
Dr. Aliosha is offline   Reply With Quote

Old   November 24, 2014, 11:56
Default
  #7
Senior Member
 
Andrew Kokemoor
Join Date: Aug 2013
Posts: 122
Rep Power: 14
Kokemoor is on a distinguished road
Sure enough, I guess it doesn't show those. Can't imagine why not. I should've looked more closely at what I suggested myself

There are matching functions for all the RP_Get_* functions:
RP_Set_Real("variable-name",real)
RP_Set_Integer("variable-name",int)
etc...
Kokemoor is offline   Reply With Quote

Old   November 25, 2014, 10:15
Default
  #8
New Member
 
Dr. Aliosha's Avatar
 
Join Date: Nov 2014
Location: Italy
Posts: 9
Rep Power: 12
Dr. Aliosha is on a distinguished road
Good call!

Thank you Kokemoor.
Dr. Aliosha is offline   Reply With Quote

Old   September 28, 2015, 14:16
Default
  #9
New Member
 
UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 15
udayraj is on a distinguished road
Hi,

I am trying to update my 'temperature' boundary condition according to the total heat flux (radiation+convection) at the boundary during previous time step in an unsteady simulation. In order to do so, I am calling 'heat flux' in my UDF. Initially, I used

heatflux=BOUNDARY_HEAT_FLUX(f,t);

for this purpose. But I am not getting correct value of heat flux using this. So, now I want to use following command to obtain heat flux at each time step:

heatflux=RP_Get_Real("myheatflux");

where 'myheatflux' is to be defined using TUI. I have used following TUI command:

> (rp-var-define'myheatflux0.0'real#f)

But there is a problem and it says

Error: eval: unbound variable
Error Object: t

Can you please guide me what could be the reason for this error? or where I am wrong.

As, I want to call this 'myheatflux' in my udf to update the boundary condition with time. Please let me know if I can do it by any other possible way.


Thanks

Udayraj




Quote:
Originally Posted by Kokemoor View Post
Sure enough, I guess it doesn't show those. Can't imagine why not. I should've looked more closely at what I suggested myself

There are matching functions for all the RP_Get_* functions:
RP_Set_Real("variable-name",real)
RP_Set_Integer("variable-name",int)
etc...
udayraj is offline   Reply With Quote

Old   September 30, 2015, 05:32
Default
  #10
New Member
 
Dr. Aliosha's Avatar
 
Join Date: Nov 2014
Location: Italy
Posts: 9
Rep Power: 12
Dr. Aliosha is on a distinguished road
Hi Udayraj,

actually your procedure seems correct.

1- In the TUI you have to define your variable
(rp-var-define 'myheatflux 0.0 'real #f)

2- try to check in the TUI the variable just created and its value with

(rpgetvar 'myheatflux)

this should return the variable velue (0 in this case)

3- in the UDF you shoud be able to get the variable value with

heatflux=RP_Get_Real("myheatflux");


This should work...

Let me know if everything is ok!

Alsessandro
Dr. Aliosha is offline   Reply With Quote

Old   September 30, 2015, 05:50
Default
  #11
New Member
 
UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 15
udayraj is on a distinguished road
Hi Dr. Aliosha,

Thanks you very much.

As I said earlier also that fluent showing error as soon as I am typing first command. Please check below:

> (rp-var-define'myheatflux0.0'real#f)

Error: eval: unbound variable
Error Object: t

I am not able to define 'myheatflux'. Therefore, when I am giving second command as suggested by you it shows

> (rpgetvar'myheatflux)

Error: rp-var-value: undefined variable
Error Object: myheatflux


Can you suggest why I am not able to define 'myheatflux' using TUI command.


Thanks
Udayraj





Quote:
Originally Posted by Dr. Aliosha View Post
Hi Udayraj,

actually your procedure seems correct.

1- In the TUI you have to define your variable
(rp-var-define 'myheatflux 0.0 'real #f)

2- try to check in the TUI the variable just created and its value with

(rpgetvar 'myheatflux)

this should return the variable velue (0 in this case)

3- in the UDF you shoud be able to get the variable value with

heatflux=RP_Get_Real("myheatflux");


This should work...

Let me know if everything is ok!

Alsessandro
udayraj is offline   Reply With Quote

Old   September 30, 2015, 08:32
Default
  #12
New Member
 
Dr. Aliosha's Avatar
 
Join Date: Nov 2014
Location: Italy
Posts: 9
Rep Power: 12
Dr. Aliosha is on a distinguished road
If this (rp-var-define'myheatflux0.0'real#f) is the actual string that you wrote in the TUI, probably you miss the spaces...

try this

(rp-var-define 'myheatflux 0.0 'real #f)

and check with this

(rpgetvar 'myheatflux)

Let me know if it works,
Alessandro
Dr. Aliosha is offline   Reply With Quote

Old   September 30, 2015, 11:53
Default
  #13
New Member
 
UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 15
udayraj is on a distinguished road
Thanks Dr. Aliosha,

Thank you very much. It worked but I am facing a new problem now. I am able to define variable 'myheatflux' now using the command you suggested.

> (rp-var-define 'myheatflux 0.0 'real #f)
myheatflux

Then I checked it

> (rpgetvar 'myheatflux)
0

Now, I want to write report value into this variable. I used following command for that:

> (rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no"))
myheatflux

Here, I want to assign total (convection+radiation) heat transfer 'heat-transfer' to this variable 'myheatflux'. where 'sensor' is the wall whose total heat flux I want in my udf.

This is a transient problem and 'myheatflux' will be different at various time steps. Using this 'myheatflux' I want to update temperature assigned as boundary condition at the 'sensor' wall.

My problem is that the 'myheatflux' remains zero at all time steps. It is not updating with time.

Can you help in this? Am I missing something?


Thanks
Udayraj


Quote:
Originally Posted by Dr. Aliosha View Post
If this (rp-var-define'myheatflux0.0'real#f) is the actual string that you wrote in the TUI, probably you miss the spaces...

try this

(rp-var-define 'myheatflux 0.0 'real #f)

and check with this

(rpgetvar 'myheatflux)

Let me know if it works,
Alessandro
udayraj is offline   Reply With Quote

Old   September 30, 2015, 12:21
Default
  #14
New Member
 
Dr. Aliosha's Avatar
 
Join Date: Nov 2014
Location: Italy
Posts: 9
Rep Power: 12
Dr. Aliosha is on a distinguished road
If I have understood the problem, I think you could define an execute command to be executed each time step, with the string

(rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no"))

Than, you can change the heat flux through the udf where the command

heatflux=RP_Get_Real("myheatflux");


Did I get the problem correctly? Does it work?

Alessandro
Dr. Aliosha is offline   Reply With Quote

Old   September 30, 2015, 12:27
Default
  #15
New Member
 
UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 15
udayraj is on a distinguished road
Do I need to copy following line in execute command option of FLUENT?
(rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no"))

I was writing this command in TUI. Please let me know whether you mean that I should write this command as execute command.

Thanks




Quote:
Originally Posted by Dr. Aliosha View Post
If I have understood the problem, I think you could define an execute command to be executed each time step, with the string

(rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no"))

Than, you can change the heat flux through the udf where the command

heatflux=RP_Get_Real("myheatflux");


Did I get the problem correctly? Does it work?

Alessandro
udayraj is offline   Reply With Quote

Old   September 30, 2015, 12:33
Default
  #16
New Member
 
Dr. Aliosha's Avatar
 
Join Date: Nov 2014
Location: Italy
Posts: 9
Rep Power: 12
Dr. Aliosha is on a distinguished road
Yes, activate an execute command and copy the string inside!
Dr. Aliosha is offline   Reply With Quote

Old   September 30, 2015, 12:35
Default
  #17
New Member
 
UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 15
udayraj is on a distinguished road
Thanks...I will try it and let you know if I am able to do it. Thanks once again for prompt response.



Quote:
Originally Posted by Dr. Aliosha View Post
Yes, activate an execute command and copy the string inside!
udayraj is offline   Reply With Quote

Old   September 30, 2015, 15:34
Default
  #18
New Member
 
UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 15
udayraj is on a distinguished road
Hi Dr. Alessandro,

I tried to execute the command shown below

(rpsetvar 'myheatflux (pick-a-real " /report/fluxes sensor () heat-transfer no"))


My udf looks like

#include "udf.h"
real heatflux;
FILE *fid;
FILE *fid1;
FILE *fid2;

/* ------- Boundary Temperature Update -------------*/
DEFINE_PROFILE(boundary_temp,t,i)
{
face_t f;
real Tnew;
real Tp;
int zoneid=THREAD_ID(t);

heatflux=RP_Get_Real("myheatflux");

/* Write the property and thread id values for the flux condition to file */
fid=fopen("flux-ids","w");
fprintf(fid,"%d,%d\n",zoneid,i);
fclose(fid);

// Write total (Conduction+Radiation) heat flux value at the sensor
/* Read in the heat flux value at the sensor */
fid1=fopen("sensor_heatflux_report","w");
fprintf(fid1,"%f\n",heatflux);
fclose(fid1);

/* Set profile values */
begin_f_loop(f,t)
{
if (CURRENT_TIME<=0.1)
{
//Tnew=300.0;
F_PROFILE(f,t,i)=300.0;
}
else
{
/* Read the previous time step temp data */
Tp=C_T_M1(f,t);
//Tp=300.0;

/* Then calculate the new flux values */
Tnew=Tp+((-heatflux*4/(3.1416*0.04*0.04))*0.1*3.1416*0.04*0.04/(4.0*0.018*385.0)); // heatflux is actually heat-transfer-rate in watt (W)

/* Write the updated temperature to file */
fid2=fopen("Temperature","w");
fprintf(fid2,"%f,%d,%f,%f,%f\n",CURRENT_TIME,i,Tp, heatflux,Tnew);
fclose(fid2);

/* Then set the new flux values */
F_PROFILE(f,t,i)=Tnew;
}
}
end_f_loop(f,t)
}

I am getting a fatal error after first time step as shown below:

Updating solution at time level N... done.

Error:
FLUENT received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.
Error Object: #f


Then I changed Tp in the UDF to a constant value 300.0 just to check whether this is a problem due to the defined previous time temperature Tp or not. In that case there is no fatal error but still there is some problem. 'myheatflux' is not updating with time and it remains zero. Please check the two snapshots taken at the first and second time step. Please check attachment.


Your expert comments may help me to identify and rectify the error. Please let me know if there are some mistakes in my UDF.


Thanks
Udayraj


Quote:
Originally Posted by Dr. Aliosha View Post
Yes, activate an execute command and copy the string inside!
Attached Images
File Type: jpg Time step 1.jpg (46.9 KB, 27 views)
File Type: jpg Time step 2.jpg (40.7 KB, 15 views)
udayraj 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
emag beta feature: charge density charlotte CFX 4 March 22, 2011 10:14
How to combine UDF and Scheme? ali hemmati Fluent UDF and Scheme Programming 3 March 19, 2011 15:45
Do I need to use UDF to get time-averaged variable? ivanbuz Fluent UDF and Scheme Programming 0 August 11, 2009 15:26
Variable for AVERAGE VELOCITY, Pressure etc. in UDF? aam Fluent UDF and Scheme Programming 0 May 15, 2009 06:21
Boundary Condition Types Using Scheme and UDF Nasir FLUENT 0 September 15, 2008 22:54


All times are GMT -4. The time now is 20:38.