CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   Star-CCM+ Macro - Loop over just wall boundary conditions (https://www.cfd-online.com/Forums/star-ccm/198754-star-ccm-macro-loop-over-just-wall-boundary-conditions.html)

jbatchel February 16, 2018 10:31

Star-CCM+ Macro - Loop over just wall boundary conditions
 
I'm trying to loop over just the wall boundaries in my macro. I know I can use a Collection and getObjectsOf(ForceReport.class) to loop over just the force reports. But I think I'm missing something simple when it comes to automating this loop over getObjectsOf(WallBoundary.class).

I am not a Java programmer, so forgive me if this is a simple question. I boiled down the part I'm struggling with to the code below. As you can see I have it creating a collection of force reports then looping over those and just printing the name of the reports. It fails when trying to create the collection of wall boundaries.

I'm running on:
Red Hat Enterprise Linux Server release 6.8

And installed java version:
java version "1.6.0_41"
OpenJDK Runtime Environment (IcedTea6 1.13.13) (rhel-1.13.13.1.el6_8-x86_64)
OpenJDK 64-Bit Server VM (build 23.41-b41, mixed mode)


Code:

package macro;

import java.util.*;
import java.lang.Math;

import star.common.*;
import star.base.neo.*;
import star.base.report.*;
import star.turbulence.*;
import star.flow.*;
import star.vis.*;
import star.meshing.*;

public class testing extends StarMacro {

  public void execute() {
       
        // get model variables
    Simulation simulation_1 = getActiveSimulation();       
       
        // get collection of report names
    Collection<ForceReport> forceReports = simulation_1.getReportManager().getObjectsOf(ForceReport.class);
    // loop through all the reports and give feedback
    for (ForceReport thisReport : forceReports) {
      simulation_1.println("Found Report:  " + thisReport.getPresentationName());
    }
       
    Region region_0 = simulation_1.getRegionManager().getRegion("Region 1");
        Collection<WallBoundary> mybounds = region_0.getBoundaryManager().getObjectsOf(WallBoundary.class);
        // loop through all the walls and give feedback
        for (WallBoundary thisBoundary : mybounds) {
                simulation_1.println("Found Wall:  " + thisBoundary.getPresentationName());
        }
   
   
  }
}


Here's the error I get:
Code:

Playing macro testing.java
error: testing.java:30: error: method getObjectsOf in class star.base.neo.ClientServerObjectManager<T> cannot be applied to given types;
        Collection<WallBoundary> mybounds = region_0.getBoundaryManager().getObjectsOf(WallBoundary.class);
                                                                        ^
  required: java.lang.Class<X>
  found: java.lang.Class<star.common.WallBoundary>
  reason: inference variable X has incompatible bounds
    equality constraints: star.common.WallBoundary
    upper bounds: star.common.Boundary


Thank you for any help!!
Jason

taillanm February 19, 2018 02:44

Hello,

I got around this by creating an "if condition" :

String compare = "Wall";
Collection<Boundary> MyBoundaries = region_0.getBoundaryManager().getBoundaries();
List<Boundary> MyFilteredBoundaries = new ArrayList();

for (Boundary WallTypeBoundaries : MyBoundaries) {
if (WallTypeBoundaries.getBoundaryType().toString().c ontains(compare)) {
MyFilteredBoundaries.add(WallTypeBoundaries);
}
}

and then go on with your Macro, extracting / looping over MyFilteredBoundaries.

tisa February 19, 2018 06:09

First, I highly recommend to use an IDE like Netbeans. Makes it easier.

I don't know a way for not using an if condition, but you can use another way for your comparison, without using a String:

for (Boundary currentBoundary: simulation_1.getRegionManager().getRegion("Region 1").getBoundaryManager().getBoundaries()) {
if (currentBoundary.getBoundaryType() == simulation_1.get(ConditionTypeManager.class).get(W allBoundary.class)) {
simulation_1.println("Found Wall: " + currentBoundary.getPresentationName());
}
}


Quote:

Originally Posted by taillanm (Post 682007)
Hello,

I got around this by creating an "if condition" :

String compare = "Wall";
Collection<Boundary> MyBoundaries = region_0.getBoundaryManager().getBoundaries();
List<Boundary> MyFilteredBoundaries = new ArrayList();

for (Boundary WallTypeBoundaries : MyBoundaries) {
if (WallTypeBoundaries.getBoundaryType().toString().c ontains(compare)) {
MyFilteredBoundaries.add(WallTypeBoundaries);
}
}

and then go on with your Macro, extracting / looping over MyFilteredBoundaries.


me3840 February 20, 2018 23:02

You can trade the line:

if (currentBoundary.getBoundaryType() == simulation_1.get(ConditionTypeManager.class).get(W allBoundary.class)) {

for:
if (currentBoundary.getBoundaryType() instanceof WallBoundary) {

tisa February 21, 2018 04:00

Quote:

Originally Posted by me3840 (Post 682312)
You can trade the line:

if (currentBoundary.getBoundaryType() == simulation_1.get(ConditionTypeManager.class).get(W allBoundary.class)) {

for:
if (currentBoundary.getBoundaryType() instanceof WallBoundary) {

Totally forgot about that. Much better and shorter :D

jbatchel March 2, 2018 14:42

Thanks!
 
I apologize for not getting back sooner. All of these options work, so just wanted to thank everyone for the help! I've added this to my little macro library for future use.

Thanks again,
Jason


All times are GMT -4. The time now is 12:03.