|
[Sponsors] |
Star-CCM+ Macro - Loop over just wall boundary conditions |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
February 16, 2018, 10:31 |
Star-CCM+ Macro - Loop over just wall boundary conditions
|
#1 |
New Member
NH
Join Date: Jun 2013
Posts: 2
Rep Power: 0 |
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 |
|
February 19, 2018, 02:44 |
|
#2 |
Member
Join Date: Nov 2015
Posts: 57
Rep Power: 11 |
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. |
|
February 19, 2018, 06:09 |
|
#3 | |
Member
Join Date: Dec 2017
Posts: 44
Rep Power: 9 |
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:
Last edited by tisa; February 20, 2018 at 07:04. Reason: correction |
||
February 20, 2018, 23:02 |
|
#4 |
Senior Member
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 25 |
You can trade the line:
if (currentBoundary.getBoundaryType() == simulation_1.get(ConditionTypeManager.class).get(W allBoundary.class)) { for: if (currentBoundary.getBoundaryType() instanceof WallBoundary) { |
|
February 21, 2018, 04:00 |
|
#5 |
Member
Join Date: Dec 2017
Posts: 44
Rep Power: 9 |
||
March 2, 2018, 14:42 |
Thanks!
|
#6 |
New Member
NH
Join Date: Jun 2013
Posts: 2
Rep Power: 0 |
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 |
|
Tags |
java, macro, starccm+ |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Wind turbine simulation | Saturn | CFX | 60 | July 17, 2024 06:45 |
Radiation in semi-transparent media with surface-to-surface model? | mpeppels | CFX | 11 | August 22, 2019 08:30 |
Question about adaptive timestepping | Guille1811 | CFX | 25 | November 12, 2017 18:38 |
Wrong flow in ratating domain problem | Sanyo | CFX | 17 | August 15, 2015 07:20 |
Multicomponent fluid | Andrea | CFX | 2 | October 11, 2004 06:12 |