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

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

 January 23, 2015, 15:43 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: 8 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

 January 25, 2015, 10:58 #2 Senior Member   François Grégoire Join Date: Jan 2010 Location: Canada Posts: 392 Rep Power: 14 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.

January 25, 2015, 11:43
#3
New Member

Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 8
Quote:
 Originally Posted by macfly 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+

 February 5, 2015, 06:41 #4 New Member   Guang Join Date: Feb 2015 Location: Stuttgart, Germany Posts: 15 Rep Power: 8 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

 February 5, 2015, 07:19 #5 New Member   Guang Join Date: Feb 2015 Location: Stuttgart, Germany Posts: 15 Rep Power: 8 .. 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

 February 5, 2015, 07:43 #6 Member   Join Date: Nov 2014 Posts: 31 Rep Power: 8 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!

February 5, 2015, 12:57
#7
New Member

Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 8
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 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

February 5, 2015, 12:57
#8
New Member

Haoting Wang
Join Date: Jan 2015
Location: Virginia
Posts: 19
Rep Power: 8
did you create a report first?

Quote:
 Originally Posted by stardust111 .. 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

February 5, 2015, 22:54
#9
New Member

Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 8
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 did you create a report first?

February 5, 2015, 23:18
#10
New Member

Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 8
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 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!

February 6, 2015, 02:53
#11
Member

Join Date: Nov 2014
Posts: 31
Rep Power: 8
Hi,

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

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

Quote:
 Originally Posted by stardust111 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

 February 6, 2015, 04:05 #12 Senior Member   Join Date: Nov 2013 Posts: 1,916 Rep Power: 23 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.

 February 6, 2015, 07:35 #13 Member   Join Date: Nov 2014 Posts: 31 Rep Power: 8 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!

February 6, 2015, 10:05
#14
New Member

Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 8

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
#f
"/define/boundary-conditions/));set boundary condition here
)
(begin
#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 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!

February 9, 2015, 14:46
#15
Member

Join Date: Nov 2014
Posts: 31
Rep Power: 8
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
#f
"/define/boundary-conditions/~XXXXXXXXX));set boundary condition here
)
(begin
#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/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 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.

February 10, 2015, 23:34
#16
New Member

Guang
Join Date: Feb 2015
Location: Stuttgart, Germany
Posts: 15
Rep Power: 8
Hi

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

Quote:
 Originally Posted by maverick123 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.

September 25, 2015, 03:01
#17
New Member

UDAYRAJ
Join Date: Oct 2011
Location: New Delhi, India
Posts: 7
Rep Power: 11
Quote:
 Originally Posted by hotin87 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
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