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

If model enabled, java macro

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By taillanm

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 7, 2016, 10:45
Default If model enabled, java macro
  #1
Member
 
Join Date: Nov 2015
Posts: 57
Rep Power: 11
taillanm is on a distinguished road
Hi all,

For postprocessing purposes of many cases I want to use one macro to extract information depending on certain conditions, here which physics model is used: inviscid or not.

At the moment my macro looks like:


if ( physicsContinuum_0.getModelManager().hasModel(Invi scidModel.class) = true) {

do stuff }

else { do stuff }

I have troubles debbugging the last method hasModel(..) and the true condition; replacing it by enabled didn't help..
In the case of ... = true the error says that i need a variable and not a value.

Did anyone come across something similar once?

Thanks
taillanm is offline   Reply With Quote

Old   November 7, 2016, 13:15
Default
  #2
New Member
 
Kevin
Join Date: Oct 2012
Posts: 29
Rep Power: 14
kirrer is on a distinguished road
There are a few ways (methods) to check whether the model is contained. First, a comment - inside the if statement, you need two equal signs to check whether two objects are the same. So if you wanted to check whether 2 is equal to 1+1, you need to write:
Code:
 if(2==(1+1))
Only 1 equal sign will attempt to assign one value to another - in this case, 2=(1+1) would attempt to assign the value of (1+1) to the integer 2, which does not make sense.

To address your question directly, many methods for checking what models exist return a Model object themselves. I would avoid those methods for the simpler .has() method, which lets you specify a string. This macro works to achieve what you want:
Code:
// STAR-CCM+ macro: CheckInviscidModel.java
// Written by STAR-CCM+ 10.06.010
package macro;

import star.common.*;

public class CheckInviscidModel extends StarMacro {

  public void execute() {
    execute0();
  }

  private void execute0() {

    Simulation simulation_0 = 
      getActiveSimulation();

    PhysicsContinuum physicsContinuum_0 = 
      ((PhysicsContinuum) simulation_0.getContinuumManager().getContinuum("Physics 1"));

    if(physicsContinuum_0.getModelManager().has("Inviscid")) {
        simulation_0.println("has inviscid model!");
    } else {
        simulation_0.println("does not have inviscid model!");
    }
  }
}
kirrer is offline   Reply With Quote

Old   November 8, 2016, 03:39
Default
  #3
Member
 
Join Date: Nov 2015
Posts: 57
Rep Power: 11
taillanm is on a distinguished road
[QUOTE=kirrer;624530] ".has() method "

Hi Kevin, many thanks for this post I will try it out now. Actually I tried also something else yesterday that works but is a bit longer:


Collection<Object> models = physicsContinuum.getModelManager().getChildren();
String Modelnames = models.toString();
Boolean Inviscid = Modelnames.contains("Inviscid");

if (Inviscid == true) {
// do stuff }


and Indeed as I am writing this, your line works well ;-)
kirrer likes this.
taillanm is offline   Reply With Quote

Reply

Tags
if condition, java macro


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
Error in Two phase (condensation) modeling adilsyyed CFX 15 June 24, 2015 20:42
manualInjection model in sprayFoam Mentalo OpenFOAM Running, Solving & CFD 1 April 2, 2014 10:29
Water subcooled boiling Attesz CFX 7 January 5, 2013 04:32
Problems bout CFD model of biomass gasification, Downdraft gasifier wanglong FLUENT 2 November 26, 2009 00:27


All times are GMT -4. The time now is 21:36.