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

Execute a scheme script each time step

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 2 Post By obscureed
  • 2 Post By `e`

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 21, 2018, 01:03
Default Execute a scheme script each time step
  #1
New Member
 
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8
Noix_V is on a distinguished road
Hello.

I have a scheme (.scm) script which I would like to run at the end of each calculated time-step. I know I can do this using the "Execute Commands" option, however I don't know how to name the script and the documentation is rather scarse...

If I use the "Read" option it justs executes the script right away, isn't there a way to make it run only when the end of a time-step is met?

Thanks a lot.
Noix_V is offline   Reply With Quote

Old   June 21, 2018, 05:35
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Noix_V,

If executing the .scm file does what you want, then you can put a TUI command in Execute Commands that executes the .scm file: for example
Code:
/file/read-macro "example.scm"
It does not matter whether the .scm file does or does not define macros -- this is a suitable TUI command either way.

Another approach is to write your .scm file so that it defines a function but does not execute it. You read in the Scheme file at any convenient moment. Then, in Execute Commands, you execute the already-read Scheme function. The difference between the two Scheme files is that, in this second approach, you insert lines at the start and finish
Code:
(define (do-stuff)
   (existing-command1)
   (existing-command2)
    ;;; etc
)
Then the line in Execute Commands is
Code:
(do-stuff)
The second approach is probably a more "Scheme-like" way of working. However, I often prefer the first approach for three reasons: (1) The first approach allows you to reopen the same .cas in a new Fluent session without needing to update. In the second approach, the Scheme function will be forgotten in the new session, so you must remember to re-read the .scm file before proceeding. (2) When the Execute Commands explicitly reads the .scm file every time, this makes it clear where the command is located/documented. (3) When the Execute Commands explicitly reads the .scm file every time, you have the opportunity to tweak the .scm in the middle of a run without interrupting Fluent. OK, so documentation and recorded history becomes messy, but this is often very handy.

You can combine the two approaches: make the .scm file define a function, and then read and execute in Execute Commands:
Code:
/file/read-macro "do-stuff_v001.scm"  (do-stuff)
And now you get the benefits I mentioned, but you can also run (do-stuff) at other moments.

As you say, documentation is sparse, so it would be useful if you could post a working example when you have one.

Good luck!
Ed
sadjad.s and Noix_V like this.
obscureed is offline   Reply With Quote

Old   June 22, 2018, 21:15
Default
  #3
New Member
 
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8
Noix_V is on a distinguished road
Ed:

Thanks a lot for your quick response! I haven't been able to test my .scm yet because of another problem in my UDF, regardless of that I'm trying to do a boundary change condition based on an UDF trigger, like in this thread: Is it possible? Changing BC from wall to pressure-outlet with an UDF trigger

If I get it to work I'll be sure to post my final versions. But I have one question, the path
Code:
/file/read-macro "example.scm"
Must be exactly the same as the working folder? or it has to start from the C: drive? What I mean, if my simulation is called "Test" would this be acceptable?
Code:
/Test_files/user_files/read-macro "example.scm"
Thanks a lot for your time.
Noix_V is offline   Reply With Quote

Old   June 23, 2018, 01:50
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The /file/read-macro is the command for the TUI, and "example.scm" is the filename of your Scheme script within your Fluent folder.

If you were reading a Scheme script from another location on your computer, then you could use an absolute path such as:

Code:
/file/read-macro "C:\Users\Noix\Documents\Scripts\Fluent_Scheme_Script.scm"
`e` is offline   Reply With Quote

Old   June 23, 2018, 07:46
Default
  #5
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
I agree with 'e'. Well, except that I think that using full paths can sometimes bring unwelcome surprises: you move the project to a different computer, and things stop working; or you duplicate the project on the same computer, and the new project uses the old Scheme file. So, in general, I try to keep .scm files in the working directory, and if not to use paths relative to the working directory.

Oh, and the backslashes make me nervous. Should they be escaped\\doubled inside quotes? I have a vague memory that Fluent will sometimes accept Unix-style forward slashes and replace them with backslashes if required by the operating system at the time.
obscureed is offline   Reply With Quote

Old   June 23, 2018, 08:38
Default
  #6
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
True, a local path would be easier for loading the script on another computer. But either way, you have the option of either specifying a local or global path in the TUI.

In Microsoft Windows, the folder location of the script can be copied and pasted from the file explorer which provides this format. Executing the TUI with the format of these backslashes worked for me. A Unix-like system uses forward slashes instead. If the file is not found by Fluent then checking the filepath would be a good place to start troubleshooting.
obscureed and Noix_V like this.
`e` is offline   Reply With Quote

Old   June 24, 2018, 01:10
Default
  #7
New Member
 
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8
Noix_V is on a distinguished road
Edit: Nevermind this post, Fluent was crashing on me since I was searching for an ID that didn't exist. Still working on this!
Noix_V is offline   Reply With Quote

Old   June 24, 2018, 02:09
Default
  #8
New Member
 
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8
Noix_V is on a distinguished road
Okay, now I have a real problem.


As I said before, I'm trying to run the scripts in this thread: Is it possible? Changing BC from wall to pressure-outlet with an UDF trigger (last post)


However, the value set on Fluent ("pressure_on_wall") does not seem to be updating with each time step.


I believe this may be due to me using a Paralell solver. I know there are some commands like host_to_node to send info, how can I use them? Or is that not my problem?


Thanks a lot for your time.
Noix_V is offline   Reply With Quote

Old   June 25, 2018, 01:58
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
DEFINE_ON_DEMAND macro works only when you manually click it to be executed

Use, for instance, DEFINE_EXECUTE_AT_END instead.

logic you should release in parallel code:
1. find max pressure on computational nodes
2. send pressure data from node_to_host
3. send max_pressure from host to scheme

You may use Ansys Fluent Customization manual for more details

best regards
AlexanderZ is offline   Reply With Quote

Old   June 25, 2018, 07:35
Default
  #10
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Noix_V,


It is certainly true that the code you linked to will not work as desired in parallel. AlexanderZ has outlined the steps. I'm in a helpful mood, so I have suggested a parallel version of the code: Is it possible? Changing BC from wall to pressure-outlet with an UDF trigger


Good luck!

Ed
obscureed is offline   Reply With Quote

Old   June 25, 2018, 19:59
Default
  #11
New Member
 
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8
Noix_V is on a distinguished road
Alexander: thanks!

Ed: wow, your help has been amazing! Just one more thing tho, I already tried the host_to_node command before, but I'm getting a rather undocumented error on two lines:

Code:
line xxx: mpnode_to_host_double_1: no function prototype
line xxx: MPT_gdhigh1: no function prototype
Needless to say, I didn't change the name on any of those functions and they also have their semicolon ( ; ) after them. Any ideas to why may that happen?


Edit: It seems to be because I need to compile my UDF rather than Interpret it. Any tips how to do this? I've never done it before...


Edit2: I'm downloading Visual Studio to compile UDF's.
Noix_V is offline   Reply With Quote

Old   June 25, 2018, 23:43
Default
  #12
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
I suggest you to use google, type there:

"how to compile udf in fluent"

best regards
AlexanderZ 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
AMI speed performance danny123 OpenFOAM 21 October 24, 2020 05:13
Transient simulation not converging skabilan OpenFOAM Running, Solving & CFD 14 December 17, 2019 00:12
pimpleDyMFoam computation randomly stops babapeti OpenFOAM Running, Solving & CFD 5 January 24, 2018 06:28
Extrusion with OpenFoam problem No. Iterations 0 Lord Kelvin OpenFOAM Running, Solving & CFD 8 March 28, 2016 12:08
Stuck in a Rut- interDyMFoam! xoitx OpenFOAM Running, Solving & CFD 14 March 25, 2016 08:09


All times are GMT -4. The time now is 13:53.