|
[Sponsors] |
Adjusting variables in java macro from command line/shell script |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 25, 2020, 10:53 |
Adjusting variables in java macro from command line/shell script
|
#1 |
New Member
Join Date: Feb 2020
Posts: 2
Rep Power: 0 |
I am running a geometry optimisation problem is STAR, where the optimisation is handled in python, and STAR with macro is called from a shell script. I want to be able to pass variables from python to the java macro. I am happy getting them to the shell script but cant figure out how to get values from there to inside the macro. I'm fairly new with java, so any advice would be much appreciated. Cheers!
|
|
February 26, 2020, 07:42 |
|
#2 |
Senior Member
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 567
Rep Power: 21 |
Hi ta95
there are many ways. For example your python/shell script could write a small file which your java macro needs to parse. You just need to learn a bit of java and use recipes from stackoverflow. Alternatively, your python script could create system environment variables. Such variables could then be read in the java macro via System.getenv("VARIABLENAME"). getenv returns a String. You'll then need to use respective parse methods to get a double, such as Double.parseDouble(String). The result of parseDouble can then be passed to a variable used in the macro. Another alternative is to have a macro template. The python/shell script copies the template, and replaces placeholder strings with the actual value. You can use "sed" in the command line or some lines of python with a regular expression. I guess the third method is the easiest for you, because you hardly need to modify the macro. You just replace the explicit value in the macro with a arbitrary but unique string such as PLACEHOLDERFORVAR. Then you copy that template and replace that exact string with the value from the optimizer and load starccm with the values-inserted macro. Best regards, Sebastian Last edited by bluebase; February 28, 2020 at 08:34. Reason: grammar |
|
February 28, 2020, 07:13 |
|
#3 |
New Member
Join Date: Feb 2020
Posts: 2
Rep Power: 0 |
Cheers, that's really helpful. I guess the advantage of having a template and replacing the unique variables is that I can also use the same method to adjust output filenames, as I'll be running several simulations in parallel on different NUMA nodes. Thanks for the suggestions!
|
|
Tags |
java, macro, star ccm+ |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[swak4Foam] How to define boundary condition variables by using previosly defined variables? | pawlo | OpenFOAM Community Contributions | 8 | September 13, 2020 12:37 |
How to pass variables from a workbench script into CFX CCL commands ?? | rl00100 | CFX | 0 | September 29, 2016 03:09 |
[General] Transfer variables into python script from bash-shell | cfdFreshman | ParaView | 0 | December 3, 2015 04:33 |
[General] Using variables defined in a Python script on a Paraview/Python Calculator | gafxian87 | ParaView | 0 | June 8, 2015 14:18 |
[swak4Foam] a script for changing variables in groovyBC in 0 folder | immortality | OpenFOAM Community Contributions | 38 | July 22, 2013 18:57 |