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

Quick Java problem. Please help!

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

Like Tree1Likes
  • 1 Post By abdul099

Reply
 
LinkBack Thread Tools Display Modes
Old   September 6, 2012, 13:27
Smile Quick Java problem. Please help!
  #1
New Member
 
Imran
Join Date: Oct 2010
Posts: 9
Rep Power: 6
Pleb is on a distinguished road
Hi, just a quick question regarding a Java problem i'm experiencing. I'm very much a novice with Java so i'm sure i've just made a stupid mistake but basically I want to export a table of data (velocity profile) after every timestep. The code I have compiled is below including the error I am recieving.

Any help very much appreciated!
Thanks


// STAR-CCM+ macro: Exportprofile1.java
package macro;
import java.util.*;
import star.common.*;
import star.base.neo.*;
public class Exportprofile1 extends StarMacro {
public void execute() {


Simulation simulation_0 =
getActiveSimulation();


int RunNum = 1;
//maximum number of steps
while(RunNum < 100){

//Step the simulation

simulation_0.getSimulationIterator().step(1);



//Generate Extracted Table Designation String Array and Format
String strExtractedTable[] = new String[RunNum];
strExtractedTable[(RunNum-1)] =
String.format("Profile%d",RunNum);

//Export table

XyzInternalTable xyzInternalTable_0 =
((XyzInternalTable) simulation_0.getTableManager().getTable("Profile") );
xyzInternalTable_0.extract();
xyzInternalTable_0.export(resolvePath("C:\\Users\\ 325074\\PhD\\STAR-CCM+\\LES\\Straight pipe\\Periodic Simulation\\Profile\\Profile.csv"), RunNum, strExtractedTable[(RunNum-1)]);



// Increment RunNum variable
RunNum = RunNum + 1;
}
}
}



Error:


Pleb is offline   Reply With Quote

Old   September 6, 2012, 13:28
Default
  #2
New Member
 
Imran
Join Date: Oct 2010
Posts: 9
Rep Power: 6
Pleb is on a distinguished road
P.S. line 57 starts with xyzInternalTable_0.export
Pleb is offline   Reply With Quote

Old   September 6, 2012, 16:28
Default
  #3
Senior Member
 
Join Date: Oct 2009
Location: Germany
Posts: 637
Rep Power: 12
abdul099 is on a distinguished road
The Star-CCM+ Java API is your friend, please have a look into it on star.common.Table. You can access the API through the help menu (help -> Java API).

The export method of "XyzInternalTable" is inherited from "star.common.Table", therefore you should follow this method's signature. The API tells you, the export method needs two strings: The first is the file name, the second one is the delimiter (like a comma, a semi-colon, a space etc.).

Your method call includes two strings plus an integer value. The integer value is unnecessary here! To be fair, there is a method expecting a string and an integer variable, but the integer should be the identifier for the delimiter - and in most cases, you don't know which integer is which delimiter, except by trial and error. So it's much easier to stick to the method using two strings.

Also I suspect you want to change the file name every time you try to export the table, so you should build the string before you call the export method (makes it easier to read the source code).

Additionally, the String array for the file name is as unnecessary as a ship on the seafloor. You're using only one field of this array since it is constructed in every loop iteration. It's a local variable, just existing inside the loop for only one loop iteration. A simple String is fine here and even more efficient. Efficiency will not be a big issue since you're running for only 100 steps, but it might cause performance issues when going for a more advanced macro or when you run for much more steps.

And another hint: Most Java programmers name classes with uppercase letters at the beginning of each word (e.g. class "ExportProfile") while variables are named with a lowercase letter at the beginning and an uppercase letter at the beginning of each word except the first one (e.g. int "runNum"). This is no strict rule and the macro will also work when you don't follow it. But it makes it easier for others to fix your code since it's the common style and easier to read to experienced Java programmers.


So what I would write is something like the following code snippet. Please note, I didn't check the code, I just edited your code snippet. Maybe there are still errors you need to fix.

// STAR-CCM+ macro: Exportprofile1.java
package macro;
import java.util.*;
import star.common.*;
import star.base.neo.*;
public class Exportprofile1 extends StarMacro {
public void execute() {

Simulation simulation_0 = getActiveSimulation();

int runNum = 1;
//maximum number of steps
while(runNum < 100){

//Step the simulation

simulation_0.getSimulationIterator().step(1);

//Generate Extracted Table Designation String and Format
String strExtractedTable = String.format("Profile%d",runNum);

// Append the formatted designation string to the path and append the file type to the end
String path = "C:\\Users\\ 325074\\PhD\\STAR-CCM+\\LES\\Straight pipe\\Periodic Simulation\\Profile\\".concat(strExtractedTable).c oncat(".csv");

// Define the delimiter here
String delimiter = ";";

//Export table
XyzInternalTable xyzInternalTable_0 =
((XyzInternalTable) simulation_0.getTableManager().getTable("Profile") );
xyzInternalTable_0.extract();

// Here you just put the two strings: The whole path, including the file name and file type; and the delimiter.
xyzInternalTable_0.export(resolvePath(path), delimiter);


// Increment RunNum variable (a shorter and more elegant way to increment a variable than you had, but your solution was also fine)
runNum++;
}
}
}
Pleb likes this.
__________________
We do three types of jobs here:
GOOD, FAST AND CHEAP
You may choose any two!
abdul099 is offline   Reply With Quote

Old   September 8, 2012, 16:07
Default
  #4
New Member
 
Imran
Join Date: Oct 2010
Posts: 9
Rep Power: 6
Pleb is on a distinguished road
Legend, thank you vey much for that detailed reply Looks like I've still go a lot to learn although I'm a little surprised I need to define the delimeter. I thought recording exporting a table macro would contain this info.

The revised macro you replied with works great after a couple of little tweaks. I will look into the Java API to get further understanding.

Thanks again!
Pleb is offline   Reply With Quote

Reply

Tags
java, profile

Thread Tools
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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
UDF compiling problem Wouter Fluent UDF and Scheme Programming 6 June 6, 2012 04:43
area does not match neighbour by ... % -- possible face ordering problem St.Pacholak OpenFOAM 9 November 22, 2011 11:02
Problem in implementing cht tilek CFX 3 May 8, 2011 08:39
natural convection problem for a CHT problem Se-Hee CFX 2 June 10, 2007 06:29
Adiabatic and Rotating wall (Convection problem) ParodDav CFX 5 April 29, 2007 19:13


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