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

Simple Java question - close & save simulation

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 16, 2012, 08:58
Default Simple Java question - close & save simulation
  #1
Senior Member
 
Join Date: Dec 2010
Posts: 135
Rep Power: 15
eRzBeNgEl is on a distinguished road
hi guys

with which command can I tell Star-CCM+ to save and close a simulation file after doing some post processing actions?

Thanks
eRzBeNgEl is offline   Reply With Quote

Old   May 16, 2012, 11:07
Default
  #2
Senior Member
 
Ryne Whitehill
Join Date: Aug 2009
Posts: 312
Rep Power: 18
rwryne is on a distinguished road
Quote:
Originally Posted by eRzBeNgEl View Post
hi guys

with which command can I tell Star-CCM+ to save and close a simulation file after doing some post processing actions?

Thanks
Simulation sim = getActiveSimulation();
sim.saveState(resolvePath(simulationname+"_VMesh.s im"));


just two snippets from a macro I have
rwryne is offline   Reply With Quote

Old   May 16, 2012, 21:17
Default
  #3
Senior Member
 
Join Date: Oct 2009
Location: Germany
Posts: 636
Rep Power: 21
abdul099 is on a distinguished road
When running in batch mode, the simulation will be closed automatically when the end of the macro is reached. Therefore you need only to trigger the save on your own before the macro ends. rwryne already posted the solutution how to do that.

When running in server mode (opened the simulation via GUI or with the -server command line option), it will not be closed. Not sure if it can be done with a macro at all.
__________________
We do three types of jobs here:
GOOD, FAST AND CHEAP
You may choose any two!
abdul099 is offline   Reply With Quote

Old   May 17, 2012, 12:25
Default
  #4
Senior Member
 
Join Date: Dec 2010
Posts: 135
Rep Power: 15
eRzBeNgEl is on a distinguished road
Quote:
Simulation sim = getActiveSimulation();
sim.saveState(resolvePath(simulationname+"_VMesh.s im"));
Thanks, for the code, but is this one also for closing (in server mode) and not just for saving the file? As adbul099 told, i am not using the batch mode, so I have to close the star-ccm explicit by a java command.
eRzBeNgEl is offline   Reply With Quote

Old   May 18, 2012, 08:43
Default
  #5
Member
 
Ryan Coe
Join Date: Jun 2010
Location: Albuquerque, NM
Posts: 98
Rep Power: 15
ryancoe is on a distinguished road
Like abdul mentioned, those lines will not close the simulation. Is there some reason why you need the GUI and do not want to use batch mode? Unless you need the GUI open for some reason, just run the simulation in batch mode and it will close automatically. You can call the java macro directly from the run command (ie <folderpath>/starccm+ -batch <yourjavascript.java> <simulationname.sim>).
__________________
Ryan
ryancoe is offline   Reply With Quote

Old   May 21, 2012, 04:24
Default
  #6
New Member
 
Matthias Fitl
Join Date: Mar 2009
Location: Austria
Posts: 20
Rep Power: 17
MFitl is on a distinguished road
Quote:
Originally Posted by eRzBeNgEl View Post
hi guys

with which command can I tell Star-CCM+ to save and close a simulation file after doing some post processing actions?

Thanks

Macro RunModel.java

// STAR-CCM+ macro: start_ccm.java
package macro;

import java.util.*;

import star.common.*;
import star.base.neo.*;


public class RunModel extends StarMacro {

public void execute() {

Simulation simulation_0 =
getActiveSimulation();

simulation_0.getSimulationIterator().run(true);

simulation_0.saveState(getSimulation().getPresenta tionName()+".sim");
simulation_0.close(ServerConnection.CloseOption.Fo rceClose);

}
}

Runs, saves and forces the simulation to close.

Regards,
Matthias
MFitl is offline   Reply With Quote

Old   May 21, 2012, 05:37
Default
  #7
Senior Member
 
Join Date: Dec 2010
Posts: 135
Rep Power: 15
eRzBeNgEl is on a distinguished road
Yes, thatīs what I want, thank u!
eRzBeNgEl is offline   Reply With Quote

Old   May 30, 2012, 04:03
Default
  #8
Senior Member
 
Join Date: Dec 2010
Posts: 135
Rep Power: 15
eRzBeNgEl is on a distinguished road
Ok, i am having an issue again, i wanted to create a script which opens alls *.sim files in folders and subfolders, deletes mesh and solution data saves the files in the correct path in batch mode: The script is working and opening all *.sim files, btu jsut the first folder level is saved correctly without mesh and solution data. The *.sim files in the sub folders are not saved without mesh and solution data. Can u help me?

the Linux bash script:

Quote:
#!/bin/bash
find -type f -iname '*.sim' | while read input; do
starccm+ -batch del_solmeshdata.java -collab -on cluster01:12 $input
done
one part of the java script is shown here:
Quote:
......
MeshPipelineController meshPipelineController_0 =
simulation_0.get(MeshPipelineController.class);

meshPipelineController_0.clearGeneratedMeshes();


simulation_0.saveState(resolvePath(".\\"+(getSimul ation().getPresentationName()+".sim")));

//simulation_0.close(ServerConnection.CloseOption.Fo rceClose);

}
eRzBeNgEl is offline   Reply With Quote

Old   September 5, 2013, 09:45
Default
  #9
Member
 
Roman
Join Date: Mar 2011
Posts: 46
Rep Power: 15
Roman is on a distinguished road
I figure I will resurrect an old topic to post my solution to the problem.

Bash script is made for Linux systems, but feel free to use the java macro on Windows as well.


Bash script will recursively search for .sim files, reset the solution, remove the grid and save them. Afterwords, it will search through the folders again and delete .sim~, which are linux backup files.

Bash, recursive search

Quote:
#/bin/sh


# Remember "/" at the end of path example: "/home/user/Desktop/"

topfolder="/home/user/Desktop/"

PurgeJava="/oath/to/Purge.java"


# Purging of Solution and Grid, saving

for f in $(find $topfolder -name '*.sim');

do

DIR=$(dirname $f)
name=$(basename $f)

echo "Purging" $name
cd $DIR

cp $PurgeJava $DIR

starccm+ -batch Purge.java $name > /dev/null 2>&1 ;

rm Purge.java

done



# Delete ".sim~" files.
# Do not move this portion to the top, Linux autosaves ".sim~" for every ".sim" that is run #through purging percedure.

for f in $(find $topfolder -name '*.sim~');

do echo "Removing" $f

rm $f;

done
Purge.java
Quote:
// STAR-CCM+ macro: Purge.java
// Written by STAR-CCM+ 8.04.007
package macro;

import java.util.*;

import star.common.*;
import star.base.neo.*;
import star.meshing.*;

public class Purge extends StarMacro {

public void execute() {
execute0();
}

private void execute0() {

Simulation simulation_0 =
getActiveSimulation();

Solution solution_0 =
simulation_0.getSolution();

solution_0.clearSolution();

MeshPipelineController meshPipelineController_0 =
simulation_0.get(MeshPipelineController.class);

meshPipelineController_0.clearGeneratedMeshes();

String path = getActiveSimulation().getPresentationName();

simulation_0.saveState(resolvePath(path)+ ".sim");
}
}
Roman is offline   Reply With Quote

Reply


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
Very simple question Vashishth Patel CFX 10 November 8, 2011 04:26
[TGrid] Simple Question (Simple Answers?): Edge Length adjustment for tet mesh booz ANSYS Meshing & Geometry 0 August 29, 2010 12:39
Wall boundary condition (a very simple question) safa_c FLUENT 1 August 15, 2010 05:05
simple question about calculated bc hyperion OpenFOAM 0 August 14, 2010 14:05
A Simple Question Thomas P. Abraham Main CFD Forum 3 September 6, 1999 18:19


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