|
[Sponsors] |
Is it possible? Changing BC from wall to pressure-outlet with an UDF trigger |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 2, 2015, 16:06 |
Is it possible? Changing BC from wall to pressure-outlet with an UDF trigger
|
#1 |
New Member
Juan Man
Join Date: Apr 2015
Posts: 6
Rep Power: 11 |
Hi everyone, I don't know if the title is clear enough.
This is what I want to do: I have a tank (circle, BC=wall) subject to a wave. I want to monitor the pressure on the wall, and if it is greater than a limit value I want to simulate the breaking of the tank by changing its boundary-condition to pressure-outlet. Is this possible with UDFs or Scheme? To monitor the pressure I'd use something like this: Code:
DEFINE_ADJUST(test_de_explosion,domain) { int ID = 7; int exploded = 0; Thread *thread = Lookup_Thread(domain,ID); face_t f; begin_f_loop(f, thread) { if ( F_P(f, thread) > 700000.0) { exploded = 1; } } end_f_loop(f, thread) if (exploded == 1) { printf("Explosion\n"); } else { printf("Nothing\n"); } } Juan |
|
June 2, 2015, 19:12 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Yes, it's possible. First, try converting your UDF to a Scheme file and run this script at each time step. Use the corresponding TUI commands for changing boundary conditions and implement them with ti-menu-load-string. Alternatively, if you can't code the face loops (or similar) in Scheme (there's a number of limitations I've come across with Scheme), use a flag with a rp-variable or text file to inform the Scheme script when to convert the boundary condition.
|
|
June 3, 2015, 16:54 |
|
#3 |
New Member
Juan Man
Join Date: Apr 2015
Posts: 6
Rep Power: 11 |
Hi `e`, thanks for your answer.
I understand the part about the TUI commands for changing the BC. What I don't get is how i could convert the UDF to a Scheme file, I couldn't find any information about that in the manual. How would i access simulation results with Scheme? Maybe with a monitor? If not possible, I'm going to try with an rp-variable. |
|
June 3, 2015, 19:59 |
|
#4 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
I'm not sure if it'd be possible to convert your UDF to a Scheme file directly (I've had similar issues and couldn't find a solution); however, this approach would be the most elegant which is why I suggested to try it first. The alternative approach with an rp-variable would be the second best method (I believe rp-variables are accessible by both Scheme and UDFs).
What I've done (because it required more information than a single flag) was write a Scheme file from inside a UDF and run this script at every time step (Calculation Activity); defaults to empty, but otherwise has a number of commands. This question of coupling UDFs with Scheme files have been appearing frequently on these forums so I might post a tutorial in the future. |
|
June 8, 2015, 14:00 |
Did it!
|
#5 |
New Member
Juan Man
Join Date: Apr 2015
Posts: 6
Rep Power: 11 |
Thanks `e`, I did it!
This is how I managed, in case someone encounters a similiar issue: This is the UDF that checks the pressure on the wall that I wanted to monitor: Code:
#include "udf.h" DEFINE_ON_DEMAND(pres_check) { int ID; face_t f; real maxPressure; Thread *thread; Domain *d; ID = 6; maxPressure = 1.0; d = Get_Domain(1); thread = Lookup_Thread(d, ID); begin_f_loop(f, thread) { if (F_P(f, thread) > maxPressure) maxPressure = F_P(f, thread); } end_f_loop(f, thread) printf("Max Pressure = %f \n",maxPressure); RP_Set_Real("pressure_on_wall",maxPressure); } Code:
(rp-var-define 'pressure_on_wall 0.0 'real #f) (rp-var-define 'explosion_time 0.0 'float #f) (define exploded #f) (define limit 100000) (define ts 50) (do ((i 1 (+ 1 i) ))((> i ts)) (ti-menu-load-string "solve dti 1 10") (cond((eq? exploded #f) (%udf-on-demand 'pres_check);### CHECK UDF NAME!!! ### (display "Limit Pressure Not Yet Reached") (cond((> (%rpgetvar 'pressure_on_wall) limit) (display "Limit Pressure Reached") (set! exploded #t) (rpsetvar 'explosion_time (%rpgetvar 'flow-time)) (ti-menu-load-string "def bc mz zt 6 pi");### CHECK ZONE ID ### (ti-menu-load-string "def bc pi 6 , , 300000 , , , , , , , , ,");### CHECK ZONE ID ### )) )) ) I hope this thread is useful to everyone. Regards, Juan |
|
June 25, 2018, 07:32 |
|
#6 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Hello World,
This is an old post, but it might be useful to see what changes are needed in that UDF code to make it work in parallel: Code:
#include "udf.h" #define FACE_ZONE_ID 6 DEFINE_ON_DEMAND(pres_check) { int ID; face_t f; real maxPressure; Thread *thread; Domain *d; maxPressure = -9.99e30; d = Get_Domain(1); thread = Lookup_Thread(d, FACE_ZONE_ID); begin_f_loop(f, thread) { if (F_P(f, thread) > maxPressure) maxPressure = F_P(f, thread); } end_f_loop(f, thread) /* In parallel, get the combined max pressure across all nodes: */ #if RP_NODE maxPressure = PRF_GRHIGH1(maxPressure); #endif Message0("\nMax Pressure = %f \n",maxPressure); /* In parallel, send the combined max pressure to the host: */ node_to_host_real_1(maxPressure); /* In parallel, only the host sets RP variables: */ #if !RP_NODE if(RP_Variable_Exists_P("pressure_on_wall")) { RP_Set_Real("pressure_on_wall",maxPressure); }else{ Message("\nThe UDF would like to set the RP-var 'pressure_on_wall\n"); Message("but this RP-var does not currently exist.\n"); } #endif } |
|
June 25, 2018, 08:10 |
|
#7 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Oh, and if your only reason for running this is to get the maximum pressure of a face zone called "wall_example" in a Scheme command, then you could do that directly in Scheme like this:
Code:
(pick-a-real "/rep/surf/facet-max (wall_example) pressure n") Code:
(define limit 100000) (if (not (rp-var-object 'explosion_time)) (rp-var-define 'explosion_time -999.9 'double #f) ()) (if (< (%rpgetvar 'explosion_time) 0.0) (if (> (pick-a-real "/rep/surf/facet-max (wall_example) pressure n") limit) (begin (display "Limit Pressure Reached. ") (rpsetvar 'explosion_time (%rpgetvar 'flow-time)) (ti-menu-load-string "/def/bc/mod-zones/zone-type wall_example pressure-inlet") (ti-menu-load-string "/def/bc/pressure-inlet wall_example , , 300000 , , , 300 , , , , , , , , , , , , , ,") ) (display "Limit Pressure Not Yet Reached. "))) ++ You can put face zone numbers into the /report/surface command... BUT, whatever numbers are used there, they are not the same numbers as zone ID numbers. (Yeah, I was surprised, too.) So I have avoided the zone ID altogether and used the name only. ++ My command for changing the pressure-inlet boundary condition is different from the previous one, because I have temperature and species in my test case. The conclusion is to remember that this command is strongly case-dependent. ++ You could put that longer set of Scheme commands into a file called check_pres.scm, and then run it with a TUI command /file/read-macro check_pres.scm. I cunningly made sure that the RP-variable is not re-defined every time. Enjoy! Ed |
|
October 1, 2018, 14:46 |
|
#8 |
Senior Member
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 14 |
Hi,
Thank you for providing good insights. I have one question - should the Scheme script be put in a so-called journal file? Thank you once again. |
|
October 4, 2018, 18:12 |
|
#9 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
Hi wc34071209,
No, Scheme commands belong in a .scm file. You can run a .scm file from Fluent's top menu File...Read Macro -- or see the TUI command that I mention in the final point of that previous post. Good luck! Ed |
|
October 5, 2018, 05:16 |
|
#10 |
Senior Member
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 14 |
Hi obscureed,
Thank you so much for your reply. I run Fluent on a cluster and give Fluent command through a journal file. I think I should use TUI command you mentioned to hook the Scheme commands. But I still have one question. Is the Scheme command executed every iteration/time step or is it run only once? |
|
October 5, 2018, 05:40 |
|
#11 | |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
Quote:
best regards |
||
October 5, 2018, 06:03 |
|
#12 |
Senior Member
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 14 |
||
October 5, 2018, 13:40 |
|
#13 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
You can put a TUI command in Calculation Activities...Execute Commands, to run at a specified frequency. I would recommend using a TUI command to access the Scheme file directly (for example "/file/read-macro check_pres.scm"), rather than going via a journal file. A journal file to read a Scheme file seems like a pointless extra level of bureaucracy. (Also, there is a restriction that you cannot read a journal file while writing a journal file.)
|
|
Tags |
scheme, udf and programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF to adjust pressure outlet | a.lynchy | FLUENT | 4 | February 15, 2021 01:50 |
Pressure Outlet Targeted Mass Flow Rate | LuckyTran | FLUENT | 1 | November 23, 2016 11:40 |
Pressure Outlet Guage pressure | Mohsin | FLUENT | 36 | April 29, 2016 18:16 |
Radiation interface | hinca | CFX | 15 | January 26, 2014 18:11 |
what the result is negatif pressure at inlet | chong chee nan | FLUENT | 0 | December 29, 2001 06:13 |