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

Is it possible? Changing BC from wall to pressure-outlet with an UDF trigger

Register Blogs Community New Posts Updated Threads Search

Like Tree19Likes
  • 1 Post By jayemes
  • 2 Post By `e`
  • 4 Post By `e`
  • 8 Post By jayemes
  • 1 Post By obscureed
  • 1 Post By obscureed
  • 2 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 2, 2015, 15:06
Question 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: 10
jayemes is on a distinguished road
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");
    }
}
I hope you can help me

Juan
bhwcs likes this.
jayemes is offline   Reply With Quote

Old   June 2, 2015, 18:12
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
wc34071209 and jayemes like this.
`e` is offline   Reply With Quote

Old   June 3, 2015, 15:54
Default
  #3
New Member
 
Juan Man
Join Date: Apr 2015
Posts: 6
Rep Power: 10
jayemes is on a distinguished road
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.
jayemes is offline   Reply With Quote

Old   June 3, 2015, 18:59
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   June 8, 2015, 13:00
Default Did it!
  #5
New Member
 
Juan Man
Join Date: Apr 2015
Posts: 6
Rep Power: 10
jayemes is on a distinguished road
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);

}
I interpreted or compiled it and then I run this Scheme script:

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 ###
		))
	))

)
It works great, though it's a bit slow when evaluating the UDF
I hope this thread is useful to everyone.
Regards,
Juan
jayemes is offline   Reply With Quote

Old   June 25, 2018, 06:32
Default
  #6
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
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

}
wc34071209 likes this.
obscureed is offline   Reply With Quote

Old   June 25, 2018, 07:10
Default
  #7
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
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")
For example:
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.  ")))
Some things to note:
++ 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
wc34071209 likes this.
obscureed is offline   Reply With Quote

Old   October 1, 2018, 13:46
Default
  #8
Senior Member
 
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 13
wc34071209 is on a distinguished road
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.
wc34071209 is offline   Reply With Quote

Old   October 4, 2018, 17:12
Default
  #9
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
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

wc34071209 and bruce lee like this.
obscureed is offline   Reply With Quote

Old   October 5, 2018, 04:16
Default
  #10
Senior Member
 
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 13
wc34071209 is on a distinguished road
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?
wc34071209 is offline   Reply With Quote

Old   October 5, 2018, 04:40
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by wc34071209 View Post
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?
it runs once

best regards
AlexanderZ is offline   Reply With Quote

Old   October 5, 2018, 05:03
Default
  #12
Senior Member
 
Yuehan
Join Date: Nov 2012
Posts: 142
Rep Power: 13
wc34071209 is on a distinguished road
Hi Alexander,

Thank you very much for your kind reply. Do you know how to make it to run every iteration/time-step?

Best,
Yuehan

Quote:
Originally Posted by AlexanderZ View Post
it runs once

best regards
wc34071209 is offline   Reply With Quote

Old   October 5, 2018, 12:40
Default
  #13
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 11
obscureed is on a distinguished road
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.)
obscureed is offline   Reply With Quote

Reply

Tags
scheme, udf and programming


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
UDF to adjust pressure outlet a.lynchy FLUENT 4 February 15, 2021 00:50
Pressure Outlet Targeted Mass Flow Rate LuckyTran FLUENT 1 November 23, 2016 10:40
Pressure Outlet Guage pressure Mohsin FLUENT 36 April 29, 2016 17:16
Radiation interface hinca CFX 15 January 26, 2014 17:11
what the result is negatif pressure at inlet chong chee nan FLUENT 0 December 29, 2001 05:13


All times are GMT -4. The time now is 10:35.