CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   STAR-CCM+ (http://www.cfd-online.com/Forums/star-ccm/)
-   -   Run macro for Multiple file (http://www.cfd-online.com/Forums/star-ccm/93831-run-macro-multiple-file.html)

furione October 27, 2011 12:15

Run macro for Multiple file
 
Hi, unfortunately at now i am only a beginner of Star CCM +. I want get the WSS tecplot (.plt) solution from 160 simulation files. It's a big work, so I created a macro that can be run by a batch file, with 160 lines.

Code:

// STAR-CCM+ macro: export.java

package macro;

import java.util.*;

import star.common.*;
import star.base.neo.*;
import star.vis.*;
import star.flow.*;
import java.io.File;

public class export extends StarMacro {
 
static final String PLT = ".plt";
 
  public void execute() {
 
    Simulation simulation_0 = getActiveSimulation();
    Region region_0 = simulation_0.getRegionManager().getRegion("Body_1");
    Solution solution_0 = simulation_0.getSolution();
       
    // 2) Impostazione Nome Simulazione x Export
    final File MySimFile = new File(simulation_0.getSessionPath());
    final String SimName = MySimFile.getName();
    final String SimTitle = SimName.substring(0, SimName.lastIndexOf("."));
    final String SimPath = MySimFile.separator;
   
    ImportManager importManager_0 = simulation_0.getImportManager();
    importManager_0.setExportParts(new NeoObjectVector(new Object[] {}));
    importManager_0.setExportBoundaries(new NeoObjectVector(new Object[] {}));
    importManager_0.setExportRegions(new NeoObjectVector(new Object[] {region_0}));

    PrimitiveFieldFunction primitiveFieldFunction_0 =
      ((PrimitiveFieldFunction) simulation_0.getFieldFunctionManager().getFunction("WallShearStress"));

    VectorMagnitudeFieldFunction vectorMagnitudeFieldFunction_0 =
      simulation_0.getFieldFunctionManager().getVectorMagnitudeFunction(primitiveFieldFunction_0);

    importManager_0.setExportScalars(new NeoObjectVector(new Object[] {vectorMagnitudeFieldFunction_0}));

    importManager_0.setExportVectors(new NeoObjectVector(new Object[] {}));

    importManager_0.setExportOptionAppendToFile(false);

    importManager_0.setExportOptionSolutionOnly(false);
   
    String Fname23 = SimTitle + PLT;

    importManager_0.export(resolvePath(Fname23), new NeoObjectVector(new Object[] {region_0}), new NeoObjectVector(new Object[] {}), new NeoObjectVector(new Object[] {}), new NeoObjectVector(new Object[] {vectorMagnitudeFieldFunction_0}), false);

  }
}

I want to ask if it's possibile to automate this one, in order to run only a macro, that work with 160 files simultaneously.
I hope that it's all clear.
Thank you in advance

abdul099 October 28, 2011 00:44

It's no good idea to run 160 files simultaneously. I assume, we aren't talking about exporting models with 500 cells, so keep the available ressources in mind!
What you want to do would require 160 licenses, 160 CPU-cores, enough memory for all 160 processes, enough memory bandwith to prevent the processes from blocking each other and the hard disk would be excited to read and write 160 files at the same time.
When the job is small, it shouldn't harm to do it serial. When the job is big, you have to do it serial.

To run it, I would just write a shell script or a few lines in awk which executes this macro on all 160 sim-files. Something like you already did, is this right?
When you've got enough computational ressources, you might split it up to 2 or more shell scripts, each handling 80 (or less) sim-files. But don't try to do more jobs at the same time than you've got CPU-cores available on the machine.

furione October 28, 2011 05:02

Yes excuse me, my bad English.
I used a wrong word, exactly I wanted to say one by one.
ok?
I want to avoid a batch with 160 macro request, so I asked if it's possible to modify my macro, in order to automate the export process for all my files, NOT SIMOULTANEOUSLY (excuse me), but ONE BY ONE.

abdul099 October 29, 2011 05:45

Okay, in this case sorry for the misunderstanding.

You CAN do it by modifying the macro. But I recommend to do it via batch script. It will finish one run and start the next, exactly like you want it. And it's easier to do it this way, because otherway you would have to open one simulation to executes the macro and opens another one. That can get tricky and is more prone to errors.

Do you know how to run a simulation in batch mode? With a command like

starccm+ -batch #yourMacro.java #yourSimFile
(there might be additional commands like number of CPU's, remote shell etc, depending on your system)

Now you don't run it by typing the command by hand, but just put it in a shell script which executes the command line above on several sim-files.
On Monday I can post an example how I did this on our cluster, it's essentially only a shell script (on a Linux system). But on a windows system it's pretty much the same.

furione October 29, 2011 05:58

Thank you Abdul, I just knew about macro in batch mode,but my problem is that I have hundreds of files that need hundreds of batch rows :(.
Today I will write the batch, only for don't waste the time.

I thank you another time Abdul for you availability

abdul099 October 29, 2011 06:13

Well, when there's a naming convention like simFile001.sim, simFile002.sim etc it should be easy to write the shell script. Otherwise you might just get every file in a specified directory and pass it to the command line.

On Monday I could maybe provide you with some awk lines. I used it to convert hundreds of pictures, but in principle it's similar to your problem: Get a file and pass it's name as argument to a command line.

When you would like to modify the java macro, you also would need some referene to the sim-file. Maybe it can be done with a collection of all files in a directory. Then use a short for-loop iterating over the collection to load the sim-files...

The command in the macro to load a simulation from an existing sim-file should be

Simulation xxl = new Simulation(PathToSimFile);

with xxl as simulation reference. I haven't tried it, so you have to try on your own if it works.

Ladnam November 28, 2011 15:54

An example of how to run multiple simulation files consecutively using a macro is given in the help files. Just search for it. However, it will not work as it is if you only got a single license because it will try to start two servers.
You have to add
Simulation sim = getActiveSimulation();
sim.kill();
at the beginning of the startAndRun function.


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