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

How to change boundary conditions by judging the temperature of one point in fluent?

Register Blogs Community New Posts Updated Threads Search

Like Tree8Likes
  • 6 Post By hotin87
  • 2 Post By maverick123

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 23, 2015, 16:43
Default How to change boundary conditions by judging the temperature of one point in fluent?
  #1
New Member
 
Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 11
hotin87 is on a distinguished road
The reason I am writing this is that I received a lot of help from this forum. I search online about the problem. There is not a perfect solution for this problem. So I share my solution here and hope it can help somebody in the future.
The thought of my solution is to get value from a report, and compare it to the criterion, then do some action I need to do like change the boundary condition.
There are some solutions on this forum that loops all the cells in domain to get the value of one point.
The link is: http://www.cfd-online.com/Forums/flu...ure-point.html
It also works, however I think it is not very efficient because every time step, it loops all the cells. If the cell number is big, it has a problem. And if we want to use this UDF in parallel computing, it needs to be modified. And this modification needs some more advanced commands like global deduction, which can only be compiled to be used instead of interpreted. The code I present here does not have this problem.

1. First define a variable in Fluent TUI (i.e. text user interface, the lower right place in fluent window). The definition command is:

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

That defines a variable called my_monitor, and it has a real type and an initial value of 0.

2. Write the report value into the variable defined in step 1. For example, if we want to write the mass flow rate into my_monitor. The command would be like this:

(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))

But, the tricky thing is, if the report value changes with time. The writing would be different:

(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/vertex-avg t3-01 () temperature no"))

Here rpsetvar means set the variable value my_monitor. If you write (rpsetvar 'my_monitor 234), the value of my_monitor would be 234. You can check if the value is written into it by the command (rpgetvar ‘my_monitor) in the TUI. If it is written successfully, the value will appear in the TUI. If there is something wrong, #f will appear means error.

The command in this step needs to be performed to update every time step. To do this go to Calculation Activities>Execute Commands>... and create a scheme command.



3. Write a UDF, put my_monitor value into it. And compare the value with your criterion value. And do the things you want to. I put my code here as a reference. It changes the boundary condition at different temperature. Until now it works very well.
I would like to thank upeska, ghost82, Kokemoor for your help and teaching. And I really want to thank the ANSYS support!!! They give numerous advice on this case.


#include "udf.h"
#define upTemp 300.35
#define lowTemp 299.95



DEFINE_PROFILE(inlet_V,t,i)
{
real T=RP_Get_Real("my_monitor");
face_t f;
//printf("temperature: %f\n", T);
if (T>=upTemp)
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = 1.38;
}
end_f_loop(f,t)
}
else if (T<lowTemp)
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = 0;
}
end_f_loop(f,t)
}


}
macfly, ghost82, upeksa and 3 others like this.
hotin87 is offline   Reply With Quote

Old   January 25, 2015, 11:58
Default
  #2
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
macfly is on a distinguished road
Thanks for sharing!

I really hope the Fluent team is working on a new interface where this kind of operation will be much simpler to implement. It would be very easy to implement in Comsol for example.
macfly is offline   Reply With Quote

Old   January 25, 2015, 12:43
Default
  #3
New Member
 
Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 11
hotin87 is on a distinguished road
Quote:
Originally Posted by macfly View Post
Thanks for sharing!

I really hope the Fluent team is working on a new interface where this kind of operation will be much simpler to implement. It would be very easy to implement in Comsol for example.
can't agree more, it's also so much easier in Star-CCM+
hotin87 is offline   Reply With Quote

Old   February 5, 2015, 07:41
Default
  #4
New Member
 
Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 11
stardust111 is on a distinguished road
Hi hotin87:
Thanks for sharing your experience, it's really helpful.
I met a similar problems today, i need to change the inlet temperature condition according to the heat flux at one of the walls.
Step 1: i typed:
(rp-var-define 'my_monitor 0.0 'real #f)
in the commend window.
Step2: i typed
(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/facet-avg isothermal () heat-flux no"))
where the "isothermal" is the name of wall where the heat flux is used to further calculation in my udf.
However, Fluent replys:
"Error: eval: unbound variable
Error Object: pick-a-real"
Could you tell me how can i fix this?
thanks a lot
stardust111 is offline   Reply With Quote

Old   February 5, 2015, 08:19
Default
  #5
New Member
 
Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 11
stardust111 is on a distinguished road
.. continue to my problem

Even when i typed
(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
i get the same message.
Error: eval: unbound variable
Error Object: pick-a-real
stardust111 is offline   Reply With Quote

Old   February 5, 2015, 08:43
Default
  #6
Member
 
Join Date: Nov 2014
Posts: 31
Rep Power: 12
maverick123 is on a distinguished road
Hi,

Try to use scheme interface of fluent through your journal as following

(define stptmstp-getnewvalue
(lambda ()
;;; Insert a scheme function call here that
;;; returns the monitor value to be used:

(string->number (pick "/report/surface-mass-avg pressure-outlet-5 () velocity-magnitude"))

;;; End of insertion.
)) ;;; close parens.

I wanted to manipulate one variable based on its actual value. So i used a function as defined above and called with help of

/solve/execute-commands/add-edit

Best Luck!
maverick123 is offline   Reply With Quote

Old   February 5, 2015, 13:57
Default
  #7
New Member
 
Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 11
hotin87 is on a distinguished road
is the heat flux a changing value or a constant one? if it's a constant value, it should be put behind the "facet-avg". Before I type the things in step 2, I tried to enter "report" in the command window, then press enter again to see what options I have, then type "surface-integral"....

Quote:
Originally Posted by stardust111 View Post
Hi hotin87:
Thanks for sharing your experience, it's really helpful.
I met a similar problems today, i need to change the inlet temperature condition according to the heat flux at one of the walls.
Step 1: i typed:
(rp-var-define 'my_monitor 0.0 'real #f)
in the commend window.
Step2: i typed
(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/facet-avg isothermal () heat-flux no"))
where the "isothermal" is the name of wall where the heat flux is used to further calculation in my udf.
However, Fluent replys:
"Error: eval: unbound variable
Error Object: pick-a-real"
Could you tell me how can i fix this?
thanks a lot
hotin87 is offline   Reply With Quote

Old   February 5, 2015, 13:57
Default
  #8
New Member
 
Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 11
hotin87 is on a distinguished road
did you create a report first?

Quote:
Originally Posted by stardust111 View Post
.. continue to my problem

Even when i typed
(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
i get the same message.
Error: eval: unbound variable
Error Object: pick-a-real
hotin87 is offline   Reply With Quote

Old   February 5, 2015, 23:54
Default
  #9
New Member
 
Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 11
stardust111 is on a distinguished road
Hi
When i typed in
report/surface-integrals/facet-avg isothermal () heat-flux no
i can get the heat flux value

> report/surface-integrals/facet-avg isothermal () heat-flux no

Average of Facet Values
Total Surface Heat Flux (w/m2)
-------------------------------- --------------------
isothermal -962.11792

but the command

(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/facet-avg isothermal () heat-flux no"))

makes errors.

the boundary condition of the wall is of constant temperature, so the heat flux varies during the iteration. i need to get it to make a correction to my boundary condition.

The version of my FLUENT is 6.3.26

thanks a lot

Quote:
Originally Posted by hotin87 View Post
did you create a report first?
stardust111 is offline   Reply With Quote

Old   February 6, 2015, 00:18
Default
  #10
New Member
 
Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 11
stardust111 is on a distinguished road
Hi
sorry i am a new user to fluent scheme interface.

if i used such commands as you suggested, how can i use the obtained value in the udf?

for example, in the udf of hotin87's, there's a command
real T=RP_Get_Real("my_monitor");

thanks

Quote:
Originally Posted by maverick123 View Post
Hi,

Try to use scheme interface of fluent through your journal as following

(define stptmstp-getnewvalue
(lambda ()
;;; Insert a scheme function call here that
;;; returns the monitor value to be used:

(string->number (pick "/report/surface-mass-avg pressure-outlet-5 () velocity-magnitude"))

;;; End of insertion.
)) ;;; close parens.

I wanted to manipulate one variable based on its actual value. So i used a function as defined above and called with help of

/solve/execute-commands/add-edit

Best Luck!
stardust111 is offline   Reply With Quote

Old   February 6, 2015, 03:53
Default
  #11
Member
 
Join Date: Nov 2014
Posts: 31
Rep Power: 12
maverick123 is on a distinguished road
Hi,

Instead of UDF , try following lines in your journal. This may solve your problem.

(let ((my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
((upTemp 25))
)

(if (> my_monitor upTemp)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set boundary condition here
)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set else condition
)
)
)


Quote:
Originally Posted by stardust111 View Post
Hi
sorry i am a new user to fluent scheme interface.

if i used such commands as you suggested, how can i use the obtained value in the udf?

for example, in the udf of hotin87's, there's a command
real T=RP_Get_Real("my_monitor");

thanks
Kokemoor and hotin87 like this.
maverick123 is offline   Reply With Quote

Old   February 6, 2015, 05:05
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Wow.

That (pick-a-real), or (pick) command in scheme is so powerful... I wish I would have known that before, it would have saved me a lot of work.

It is so annoying that Ansys doesn't have a proper description of all their built-in scheme functions. It is like they don't realize how much possibilities it gives their users... It is good that there is a site like this to share this info.
pakk is offline   Reply With Quote

Old   February 6, 2015, 08:35
Default
  #13
Member
 
Join Date: Nov 2014
Posts: 31
Rep Power: 12
maverick123 is on a distinguished road
Hi ,

If you want to manipulate temperature after each iteration at particular face_zone you may try to define a function in journal (not in UDF)

(define function_name
(let ((my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
((upTemp 25))
)

(if (> my_monitor upTemp)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set boundary condition here
)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set else condition
)
)
)
)

and call it by

/solve/execute-commands/add-edit function_name 1 "iteration" "(function_name)"

so that this function is called after each iteration.

to enable function

/solve/execute-commands/enable function name

I found, there is a different way to manipulate variables using DEFINE_ADJUST in domain not to set boundary conditions.

Best Luck!
maverick123 is offline   Reply With Quote

Old   February 6, 2015, 11:05
Default
  #14
New Member
 
Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 11
stardust111 is on a distinguished road
Thanks for your suggestion,

i still have two questions:

1: at the place "/define/boundary-conditions/))", the temperature of my boundary condition is a function of "my_monitor", which is 293.15-0.325*my_monitor, can i use a function here to define a boundary condition?

2: i havn't ever used journal. i make a file "1.jour", paste the following lines, save, then click file/read/journal and choose the file, is this correct?

(define function_name
(let ((my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
((upTemp 25))
)

(if (> my_monitor upTemp)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set boundary condition here
)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set else condition
)
)
)
)

but i still get the message:

Error: eval: unbound variable
Error Object: pick-a-real

Warning: An error or interrupt occurred while reading the journal file.
Some commands may not have been completed.


Quote:
Originally Posted by maverick123 View Post
Hi ,

If you want to manipulate temperature after each iteration at particular face_zone you may try to define a function in journal (not in UDF)

(define function_name
(let ((my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
((upTemp 25))
)

(if (> my_monitor upTemp)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set boundary condition here
)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set else condition
)
)
)
)

and call it by

/solve/execute-commands/add-edit function_name 1 "iteration" "(function_name)"

so that this function is called after each iteration.

to enable function

/solve/execute-commands/enable function name

I found, there is a different way to manipulate variables using DEFINE_ADJUST in domain not to set boundary conditions.

Best Luck!
stardust111 is offline   Reply With Quote

Old   February 9, 2015, 15:46
Default
  #15
Member
 
Join Date: Nov 2014
Posts: 31
Rep Power: 12
maverick123 is on a distinguished road
Hi,

Set all boundary conditions in usual manner. (You don't need journal actually but it is easy to define functions by journal. If you are not using journal, then paste complete function in a single stroke in console.)
Then define following function.


(define function_name
(let ((my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
((upTemp 25))
)

(if (> my_monitor upTemp)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/~XXXXXXXXX));set boundary condition here
)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/~XXXXXXXXXX));set else condition
)
)
)
)

Make sure your function syntax is right otherwise it will give error once you enable it (not when you define it)

As per my understanding, hotin87's problem is that , you wan to change the temperature value at Inlet boundary conditions after some iterations based on the criteria.
One you define this function as mentioned above, you have to set control for the calling of this function as follows

/solve/execute-commands/add-edit function_name 1 "iteration" "(function_name)"
/solve/execute-commands/disable function name

so that after every iteration temperature will be chacked and corrected at inlet boundary as per criteria.

once flow is developed (say after 100-200 iteration) enable above mentioned function

/solve/execute-commands/enable function_name

and after this temperature will be adjusted at the boundary as your criteria.
I hope ,everything is clear now.




Quote:
Originally Posted by stardust111 View Post
Thanks for your suggestion,

i still have two questions:

1: at the place "/define/boundary-conditions/))", the temperature of my boundary condition is a function of "my_monitor", which is 293.15-0.325*my_monitor, can i use a function here to define a boundary condition?

2: i havn't ever used journal. i make a file "1.jour", paste the following lines, save, then click file/read/journal and choose the file, is this correct?

(define function_name
(let ((my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
((upTemp 25))
)

(if (> my_monitor upTemp)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set boundary condition here
)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/));set else condition
)
)
)
)

but i still get the message:

Error: eval: unbound variable
Error Object: pick-a-real

Warning: An error or interrupt occurred while reading the journal file.
Some commands may not have been completed.
maverick123 is offline   Reply With Quote

Old   February 11, 2015, 00:34
Default
  #16
New Member
 
Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 11
stardust111 is on a distinguished road
Hi

Thanks again for your help. I have learned a lot from your replies. Now i am trying that.

Quote:
Originally Posted by maverick123 View Post
Hi,

Set all boundary conditions in usual manner. (You don't need journal actually but it is easy to define functions by journal. If you are not using journal, then paste complete function in a single stroke in console.)
Then define following function.


(define function_name
(let ((my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))
((upTemp 25))
)

(if (> my_monitor upTemp)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/~XXXXXXXXX));set boundary condition here
)
(begin
(ti-menu-load-string (format
#f
"/define/boundary-conditions/~XXXXXXXXXX));set else condition
)
)
)
)

Make sure your function syntax is right otherwise it will give error once you enable it (not when you define it)

As per my understanding, hotin87's problem is that , you wan to change the temperature value at Inlet boundary conditions after some iterations based on the criteria.
One you define this function as mentioned above, you have to set control for the calling of this function as follows

/solve/execute-commands/add-edit function_name 1 "iteration" "(function_name)"
/solve/execute-commands/disable function name

so that after every iteration temperature will be chacked and corrected at inlet boundary as per criteria.

once flow is developed (say after 100-200 iteration) enable above mentioned function

/solve/execute-commands/enable function_name

and after this temperature will be adjusted at the boundary as your criteria.
I hope ,everything is clear now.
stardust111 is offline   Reply With Quote

Old   September 25, 2015, 04:01
Default
  #17
New Member
 
UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 15
udayraj is on a distinguished road
Quote:
Originally Posted by hotin87 View Post
The reason I am writing this is that I received a lot of help from this forum. I search online about the problem. There is not a perfect solution for this problem. So I share my solution here and hope it can help somebody in the future.
The thought of my solution is to get value from a report, and compare it to the criterion, then do some action I need to do like change the boundary condition.
There are some solutions on this forum that loops all the cells in domain to get the value of one point.
The link is: http://www.cfd-online.com/Forums/flu...ure-point.html
It also works, however I think it is not very efficient because every time step, it loops all the cells. If the cell number is big, it has a problem. And if we want to use this UDF in parallel computing, it needs to be modified. And this modification needs some more advanced commands like global deduction, which can only be compiled to be used instead of interpreted. The code I present here does not have this problem.

1. First define a variable in Fluent TUI (i.e. text user interface, the lower right place in fluent window). The definition command is:

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

That defines a variable called my_monitor, and it has a real type and an initial value of 0.

2. Write the report value into the variable defined in step 1. For example, if we want to write the mass flow rate into my_monitor. The command would be like this:

(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/mass-flow-rate inlet () no"))

But, the tricky thing is, if the report value changes with time. The writing would be different:

(rpsetvar 'my_monitor (pick-a-real "/report/surface-integrals/vertex-avg t3-01 () temperature no"))

Here rpsetvar means set the variable value my_monitor. If you write (rpsetvar 'my_monitor 234), the value of my_monitor would be 234. You can check if the value is written into it by the command (rpgetvar ‘my_monitor) in the TUI. If it is written successfully, the value will appear in the TUI. If there is something wrong, #f will appear means error.

The command in this step needs to be performed to update every time step. To do this go to Calculation Activities>Execute Commands>... and create a scheme command.



3. Write a UDF, put my_monitor value into it. And compare the value with your criterion value. And do the things you want to. I put my code here as a reference. It changes the boundary condition at different temperature. Until now it works very well.
I would like to thank upeska, ghost82, Kokemoor for your help and teaching. And I really want to thank the ANSYS support!!! They give numerous advice on this case.


#include "udf.h"
#define upTemp 300.35
#define lowTemp 299.95



DEFINE_PROFILE(inlet_V,t,i)
{
real T=RP_Get_Real("my_monitor");
face_t f;
//printf("temperature: %f\n", T);
if (T>=upTemp)
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = 1.38;
}
end_f_loop(f,t)
}
else if (T<lowTemp)
{
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = 0;
}
end_f_loop(f,t)
}


}
Hi everyone,

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("my_monitor");

And as per earlier post here, for defining my_monitor, I have used the TUI command:

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

But there is a problem and it says

invalid command [(rp-var-define]


Can anyone tell me what could be the reason for this error? or where I am wrong.


Thank you

Udayraj
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
Domain Imbalance HMR CFX 5 October 10, 2016 06:57
Difficulty In Setting Boundary Conditions Moinul Haque CFX 4 November 25, 2014 18:30
Low Mixing time Problem Mavier CFX 5 April 29, 2013 01:00
CFX doesn't continue calculation... mactech001 CFX 6 November 15, 2009 22:25
[Gmsh] Gmsh and samplesurface touf OpenFOAM Meshing & Mesh Conversion 2 December 10, 2007 03:27


All times are GMT -4. The time now is 14:44.