CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   STAR-CCM+ (http://www.cfd-online.com/Forums/star-ccm/)
-   -   Simple Java question - close & save simulation (http://www.cfd-online.com/Forums/star-ccm/101887-simple-java-question-close-save-simulation.html)

eRzBeNgEl May 16, 2012 08:58

Simple Java question - close & save simulation
 
hi guys

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

Thanks

rwryne May 16, 2012 11:07

Quote:

Originally Posted by eRzBeNgEl (Post 361418)
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

abdul099 May 16, 2012 21:17

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.

eRzBeNgEl May 17, 2012 12:25

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.

ryancoe May 18, 2012 08:43

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>).

MFitl May 21, 2012 04:24

Quote:

Originally Posted by eRzBeNgEl (Post 361418)
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

eRzBeNgEl May 21, 2012 05:37

Yes, thatīs what I want, thank u!

eRzBeNgEl May 30, 2012 04:03

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);

}

Roman September 5, 2013 09:45

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");
}
}


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