|
[Sponsors] |
June 21, 2018, 01:03 |
Execute a scheme script each time step
|
#1 |
New Member
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8 |
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. |
|
June 21, 2018, 05:35 |
|
#2 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
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" 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 ) Code:
(do-stuff) 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) 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 |
|
June 22, 2018, 21:15 |
|
#3 |
New Member
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8 |
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" Code:
/Test_files/user_files/read-macro "example.scm" |
|
June 23, 2018, 01:50 |
|
#4 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
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" |
|
June 23, 2018, 07:46 |
|
#5 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
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. |
|
June 23, 2018, 08:38 |
|
#6 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
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. |
|
June 24, 2018, 01:10 |
|
#7 |
New Member
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8 |
Edit: Nevermind this post, Fluent was crashing on me since I was searching for an ID that didn't exist. Still working on this!
|
|
June 24, 2018, 02:09 |
|
#8 |
New Member
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8 |
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. |
|
June 25, 2018, 01:58 |
|
#9 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
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 |
|
June 25, 2018, 07:35 |
|
#10 |
Senior Member
Join Date: Sep 2017
Posts: 246
Rep Power: 12 |
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 |
|
June 25, 2018, 19:59 |
|
#11 |
New Member
Noix
Join Date: May 2018
Posts: 13
Rep Power: 8 |
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 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. |
|
June 25, 2018, 23:43 |
|
#12 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
I suggest you to use google, type there:
"how to compile udf in fluent" best regards |
|
|
|
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 |