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

Star-CCM+ Macro - Loop over just wall boundary conditions

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By me3840

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 16, 2018, 10:31
Default Star-CCM+ Macro - Loop over just wall boundary conditions
  #1
New Member
 
NH
Join Date: Jun 2013
Posts: 2
Rep Power: 0
jbatchel is on a distinguished road
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
jbatchel is offline   Reply With Quote

Old   February 19, 2018, 02:44
Default
  #2
Member
 
Join Date: Nov 2015
Posts: 57
Rep Power: 10
taillanm is on a distinguished road
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.
taillanm is offline   Reply With Quote

Old   February 19, 2018, 06:09
Default
  #3
Member
 
Join Date: Dec 2017
Posts: 44
Rep Power: 8
tisa is on a distinguished road
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 View Post
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.

Last edited by tisa; February 20, 2018 at 07:04. Reason: correction
tisa is offline   Reply With Quote

Old   February 20, 2018, 23:02
Default
  #4
Senior Member
 
Join Date: Nov 2010
Location: USA
Posts: 1,232
Rep Power: 24
me3840 is on a distinguished road
You can trade the line:

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

for:
if (currentBoundary.getBoundaryType() instanceof WallBoundary) {
bluebase likes this.
me3840 is offline   Reply With Quote

Old   February 21, 2018, 04:00
Default
  #5
Member
 
Join Date: Dec 2017
Posts: 44
Rep Power: 8
tisa is on a distinguished road
Quote:
Originally Posted by me3840 View Post
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
tisa is offline   Reply With Quote

Old   March 2, 2018, 14:42
Default Thanks!
  #6
New Member
 
NH
Join Date: Jun 2013
Posts: 2
Rep Power: 0
jbatchel is on a distinguished road
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
jbatchel is offline   Reply With Quote

Reply

Tags
java, macro, starccm+

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Wind turbine simulation Saturn CFX 58 July 3, 2020 02:13
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


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