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

Run macro for Multiple file

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

Reply
 
LinkBack Thread Tools Display Modes
Old   October 27, 2011, 12:15
Default Run macro for Multiple file
  #1
New Member
 
Francesco Furini
Join Date: Oct 2011
Posts: 3
Rep Power: 5
furione is on a distinguished road
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
furione is offline   Reply With Quote

Old   October 28, 2011, 00:44
Default
  #2
Senior Member
 
Join Date: Oct 2009
Location: Germany
Posts: 637
Rep Power: 12
abdul099 is on a distinguished road
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.
abdul099 is offline   Reply With Quote

Old   October 28, 2011, 05:02
Default
  #3
New Member
 
Francesco Furini
Join Date: Oct 2011
Posts: 3
Rep Power: 5
furione is on a distinguished road
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.
furione is offline   Reply With Quote

Old   October 29, 2011, 05:45
Default
  #4
Senior Member
 
Join Date: Oct 2009
Location: Germany
Posts: 637
Rep Power: 12
abdul099 is on a distinguished road
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.
abdul099 is offline   Reply With Quote

Old   October 29, 2011, 05:58
Default
  #5
New Member
 
Francesco Furini
Join Date: Oct 2011
Posts: 3
Rep Power: 5
furione is on a distinguished road
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
furione is offline   Reply With Quote

Old   October 29, 2011, 06:13
Default
  #6
Senior Member
 
Join Date: Oct 2009
Location: Germany
Posts: 637
Rep Power: 12
abdul099 is on a distinguished road
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.
abdul099 is offline   Reply With Quote

Old   November 28, 2011, 15:54
Default
  #7
Member
 
Join Date: May 2010
Posts: 38
Rep Power: 7
Ladnam is on a distinguished road
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.

Last edited by Ladnam; November 28, 2011 at 15:56. Reason: Links
Ladnam is offline   Reply With Quote

Reply

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
GroovyBC the dynamic cousin of funkySetFields that lives on the suburb of the mesh gschaider OpenFOAM 300 October 29, 2014 19:00
tecio compilation errors in latest 1.6.x rsamuel OpenFOAM Bugs 1 December 22, 2009 04:34
ParaView Compilation jakaranda OpenFOAM Installation 3 October 27, 2008 12:46
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 01:24
DecomposePar links against liblamso0 with OpenMPI jens_klostermann OpenFOAM Bugs 11 June 28, 2007 17:51


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