Convert SG Data#

One of the main capabilities of SGIO is to convert SG data between different formats. This can be done using the sgio.convert() function (API) or the sgio convert command (CLI).

Overview#

SGIO supports conversion between:

  • VABSSwiftCompAbaqusGmsh

  • Mesh-only conversions for visualization

  • Format version conversions (e.g., VABS 4.0 → 4.1)

Basic Usage#

API Method#

import sgio

sgio.convert(
    file_name_in='input.inp',
    file_name_out='output.sg',
    file_format_in='abaqus',
    file_format_out='vabs',
    model_type='BM2'
)

CLI Method#

sgio convert input.inp output.sg -ff abaqus -tf vabs -m BM2

Common Parameters#

  • file_name_in: Input file path

  • file_name_out: Output file path

  • file_format_in: Input format (vabs, swiftcomp, abaqus, gmsh)

  • file_format_out: Output format

  • model_type: Structural model (BM1, BM2, PL1, PL2, SD1)

  • mesh_only: Convert mesh data only (default: False)

  • renum_node: Renumber nodes (default: False)

  • renum_elem: Renumber elements (default: False)

Common Conversion Scenarios#

Scenario 1: VABS to Gmsh for Visualization#

Convert a VABS cross-section to Gmsh format for visualization.

API:

"""Example: Convert VABS Mesh to Gmsh Format for Visualization

This example demonstrates how to convert a VABS cross-section file to
Gmsh format for visualization purposes.

The conversion extracts only the mesh data (nodes and elements) without
material properties, making it suitable for quick visualization.
"""
import sgio
from pathlib import Path

# Define file paths
files_dir = Path(__file__).parent / 'files'
input_file = files_dir / 'cs_box_t_vabs41.sg'
output_file = files_dir / 'cs_box_t_vabs41.msh'

# Check if input file exists
if not input_file.exists():
    print(f"Error: Input file not found: {input_file}")
    print("Please ensure the file exists in the examples/files/ directory")
    exit(1)

print("=" * 60)
print("Converting VABS Mesh to Gmsh Format")
print("=" * 60)
print(f"Input:  {input_file.name}")
print(f"Output: {output_file.name}")
print("=" * 60)

# Convert VABS file to Gmsh format

CLI:

sgio convert cs_box_t_vabs41.sg cs_box_t_vabs41.msh \
    -ff vabs -tf gmsh -m BM2 --mesh-only

Result:

Visualization of the box cross-section in Gmsh

Figure 1 Box cross-section visualized in Gmsh#

Scenario 2: Abaqus to VABS#

Convert an Abaqus cross-section model to VABS input format.

API:

import sgio

sgio.convert(
    'airfoil.inp',      # Abaqus input file
    'airfoil.sg',       # VABS output file
    'abaqus',           # Input format
    'vabs',             # Output format
    model_type='BM2'    # Timoshenko beam
)

CLI:

sgio convert airfoil.inp airfoil.sg -ff abaqus -tf vabs -m BM2

See examples/convert_abaqus_cs_to_vabs/ for a complete example.

Scenario 3: Abaqus to SwiftComp (3D)#

Convert a 3D Abaqus model to SwiftComp format.

API:

import sgio

sgio.convert(
    'cube.inp',         # Abaqus 3D model
    'cube.sg',          # SwiftComp output
    'abaqus',           # Input format
    'swiftcomp',        # Output format
    model_type='SD1',   # 3D solid model
    sgdim=3             # 3D structure gene
)

CLI:

sgio convert cube.inp cube.sg \
    -ff abaqus -tf swiftcomp -m SD1 --sgdim 3

See examples/convert_abaqus_sg3d_to_sc/ for a complete example.

Scenario 4: Format Version Conversion#

Convert between different versions of the same format.

VABS 4.0 to 4.1:

import sgio

sgio.convert(
    'old_format.sg',
    'new_format.sg',
    'vabs',
    'vabs',
    file_version_in='4.0',
    file_version_out='4.1',
    model_type='BM2'
)

Scenario 5: Two-Step Conversion#

For more control, use separate read and write operations:

import sgio

# Step 1: Read from Abaqus
sg = sgio.read('model.inp', 'abaqus', model_type='BM2')

# Inspect or modify the data
print(f"Nodes: {len(sg.mesh.points)}")
print(f"Elements: {len(sg.mesh.cells)}")

# Step 2: Write to VABS
sgio.write(sg, 'model.sg', 'vabs')

# Step 3: Also export for visualization
sgio.write(sg, 'model.msh', 'gmsh', mesh_only=True)

Advanced Options#

Element and Node Renumbering#

Renumber elements and nodes for cleaner output:

import sgio

sgio.convert(
    'input.sg',
    'output.sg',
    'vabs',
    'vabs',
    renum_node=True,      # Renumber nodes sequentially
    renum_elem=True,      # Renumber elements sequentially
    model_type='BM2'
)

Mesh-Only Conversion#

Convert only mesh data without materials:

import sgio

sgio.convert(
    'input.sg',
    'output.msh',
    'vabs',
    'gmsh',
    mesh_only=True,
    model_type='BM2'
)

Error Handling#

Always check for file existence and handle errors:

import sgio
from pathlib import Path

input_file = Path('input.inp')
output_file = Path('output.sg')

if not input_file.exists():
    print(f"Error: Input file not found: {input_file}")
    exit(1)

try:
    sgio.convert(
        str(input_file),
        str(output_file),
        'abaqus',
        'vabs',
        model_type='BM2'
    )
    print(f"✓ Conversion successful: {output_file}")
except Exception as e:
    print(f"✗ Conversion failed: {e}")

Tips and Best Practices#

  1. Always specify model_type: Required for proper data interpretation

  2. Use mesh_only for visualization: Faster and simpler for viewing geometry

  3. Check input files first: Verify files exist before conversion

  4. Use renumbering for clean output: Helps with debugging and analysis

  5. Test with small models first: Verify conversion works before processing large files

Troubleshooting#

Issue: “File not found” error
  • Check file path is correct (absolute or relative to working directory)

  • Verify file exists using Path(filename).exists()

Issue: “Unknown file format” error
  • Check format string is correct (vabs, swiftcomp, abaqus, gmsh)

  • Verify file extension matches format

Issue: Conversion produces empty file
  • Check model_type is specified correctly

  • Verify input file contains valid data

  • Try mesh_only=True to isolate material issues

Issue: Material properties lost
  • Don’t use mesh_only=True if you need materials

  • Some formats (Gmsh) don’t support full material data

See Also#

Notes#

Note

Gmsh and ParaView are not included in SGIO. Install them separately for visualization: