CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   java macro to set angle of attack (https://www.cfd-online.com/Forums/star-ccm/236282-java-macro-set-angle-attack.html)

kiteguy May 22, 2021 17:11

java macro to set angle of attack
 
Hi everyone,

I am trying to script a macro that lets me set the angle of attack in my simulation through the command line before running it, but I am struggling to wrap my head around the -jvmargs option.

To be precise, I would like to change the value 14.0 in the following line of the macro to an arbitrary value that I can input from the command line
-> scalarGlobalParameter_0.getQuantity().setValue(14. 0);

Would this be the proper way to parse a "newaoa" value of 10 deg to the macro?
-> starccm+ -power -batch change_aoa.java -jvmargs -Dnewaoa=10.0 -np 1 testsim.sim

And how would I need to change the line from the macro to use that new aoa?

Does anybody here have some experience with similar cases? I would really appreciate the help :)

BR!

kiteguy May 23, 2021 09:16

fixed it
 
I figured it out now and thought I'd post a minimum working example for anyone stumbling over the same problem in the future:

Code:

// Simcenter STAR-CCM+ macro: change_aoa.java
// Written by Simcenter STAR-CCM+ 16.02.009
package macro;

import java.util.*;

import star.common.*;
import star.base.neo.*;

public class change_aoa extends StarMacro {

  public void execute() {
    execute0();
  }

  private void execute0() {
       
    Simulation simulation_0 =
      getActiveSimulation();

    ScalarGlobalParameter scalarGlobalParameter_0 =
      ((ScalarGlobalParameter) simulation_0.get(GlobalParameterManager.class).getObject("aoa"));

        String newaoa = System.getProperty("newaoa");

        Double x =        Double.parseDouble(newaoa);

    scalarGlobalParameter_0.getQuantity().setValue(x);

    Units units_0 = ((Units) simulation_0.getUnitsManager().getObject("deg"));

    scalarGlobalParameter_0.getQuantity().setUnits(units_0);
  }
}

the syntax to input the angle of attack from the command line is:

Code:

starccm+ -power -podkey <podkey> -licpath <licpath> -batch change_aoa.java -jvmargs -Dnewaoa=8 testsim.sim


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