|
[Sponsors] |
November 7, 2016, 10:45 |
If model enabled, java macro
|
#1 |
Member
Join Date: Nov 2015
Posts: 57
Rep Power: 11 |
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 |
|
November 7, 2016, 13:15 |
|
#2 |
New Member
Kevin
Join Date: Oct 2012
Posts: 29
Rep Power: 14 |
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)) 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!"); } } } |
|
November 8, 2016, 03:39 |
|
#3 |
Member
Join Date: Nov 2015
Posts: 57
Rep Power: 11 |
[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 ;-) |
|
Tags |
if condition, java macro |
|
|
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 |