StarCCM Macro to export to Ensight

About

This macro exports StarCCM results into the Ensight Gold format. It will write the results in the subdirectory ensight.
This subdirectory will be put in the same directory as the simulation file. It selects all regions, and all boundaries within those regions to be exported.
Derived Parts are not exported by default. The corresponding line has to be commented in to include such parts.

Additional Field Functions can be added quickly by name.

Macro

export2Ensight.java
import java.io.File;
import java.util.*;
 
import star.common.*;
import star.base.neo.*;
 
/**
 * Script exports all regions and ascociated boundaries.
 * Add required field functions within the macro.
 * @author sengel
 */
public class export2Ensight extends StarMacro {
 
    String sep = System.getProperty("file.separator"); //get the right separator for your operative system
 
    public void execute() {
 
 
 
        Simulation sim = getActiveSimulation();
        sim.println("The macro export2Ensight is running now.");
 
        String exportDir = sim.getSessionDir() + sep + "ensight";
        String exportName = sim.getPresentationName() + ".case";
 
        // *********************************************************************  
        // Which Field Functions to export
        // *********************************************************************        
        Collection<FieldFunction> scalarFieldFunctions = new ArrayList<>();
        Collection<FieldFunction> vectorFieldFunctions = new ArrayList<>();
        FieldFunctionManager ffmng = sim.getFieldFunctionManager();
 
        scalarFieldFunctions.add(ffmng.getFunction("Pressure"));
        //scalarFieldFunctions.add(ffmng.getFunction("Temperature"));
 
        vectorFieldFunctions.add(ffmng.getFunction("Velocity"));       
 
        // *********************************************************************  
        // Collect all Regions and Boundaries
        // *********************************************************************    
        Collection<Region> regions = sim.getRegionManager().getRegions();
        Collection<Boundary> boundaries = new ArrayList<>();
        for (Region reg : regions) {
            boundaries.addAll(reg.getBoundaryManager().getBoundaries());
        }
 
 
        Collection<Part> parts = new ArrayList<>();
        // remove comment of the next line to add derived Parts
        // parts.addAll(sim.getPartManager().getObjects());
 
 
        // *********************************************************************              
        // Initiate Manager
        ImportManager importManager_0 = sim.getImportManager();
 
        // Save location
        String exportPath = exportDir + sep + exportName;
        // create Directory if not already exist
        File dir = new File(exportDir);
        if (!dir.exists()) {
            dir.mkdirs();
            sim.println("Created the export directory: " + exportDir);
        }
 
        importManager_0.setExportPath(exportPath);
 
        // Set Export Entities
        importManager_0.setExportRegions(new NeoObjectVector(regions.toArray()));
        importManager_0.setExportBoundaries(new NeoObjectVector(boundaries.toArray()));
        // Set Export Field Functions
        importManager_0.setExportScalars(new NeoObjectVector(scalarFieldFunctions.toArray()));
        importManager_0.setExportVectors(new NeoObjectVector(vectorFieldFunctions.toArray()));
 
        // Other Export Settings
        importManager_0.setFormatType(SolutionExportFormat.Type.CASE);
        importManager_0.setExportParts(new NeoObjectVector(new Object[]{}));
        importManager_0.setExportPartSurfaces(new NeoObjectVector(new Object[]{}));
        importManager_0.setExportOptionAppendToFile(false);
        importManager_0.setExportOptionDataAtVerts(false);
        importManager_0.setExportOptionSolutionOnly(false);
 
        // Combine Collections of FieldFunctions
        Collection<FieldFunction> fieldFunctions = new ArrayList<>();       
        fieldFunctions.addAll(scalarFieldFunctions);
        fieldFunctions.addAll(vectorFieldFunctions);
 
 
        // Export.  
        // The Boolean variables are 1.)AppendDataToExistingFile, 2.)exportDataOnVertices
        importManager_0.export(exportPath, regions, boundaries, parts, fieldFunctions, false, false);
        sim.println("Macro export2Ensight has finished.");
    }
 
}
guide/starccm/ensight_export_macro.txt · Last modified: 2019/02/11 10:55 by seengel
Back to top
CC Attribution-Share Alike 3.0 Unported
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0