CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Adjusting variables in java macro from command line/shell script

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 25, 2020, 10:53
Default Adjusting variables in java macro from command line/shell script
  #1
New Member
 
Join Date: Feb 2020
Posts: 3
Rep Power: 2
ta95 is on a distinguished road
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!
ta95 is offline   Reply With Quote

Old   February 26, 2020, 07:42
Default
  #2
Senior Member
 
Sebastian Engel
Join Date: Jun 2011
Location: Germany
Posts: 528
Rep Power: 17
bluebase will become famous soon enough
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
bluebase is offline   Reply With Quote

Old   February 28, 2020, 07:13
Default
  #3
New Member
 
Join Date: Feb 2020
Posts: 3
Rep Power: 2
ta95 is on a distinguished road
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!
ta95 is offline   Reply With Quote

Reply

Tags
java, macro, star ccm+

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[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


All times are GMT -4. The time now is 00:08.