Skip to main content
`Ctrl`+`K`

# SCons Quickstart

Note

Unlike the Quickstart: Abaqus, this tutorial will use native SCons code without the WAVES extensions and builders. This tutorial is included as an example for using native SCons techniques when WAVES does not support required third-party software, such as numeric solvers, or for when a modsim project requires unique builder behavior. You can learn more about writing your own SCons Builders in the SCons user manual [32] and Tutorial: Writing Builders.

This quickstart will create a pure SCons, minimal, two file project configuration matching the tutorials listed below.

- Tutorial 00: SConstruct

- Tutorial 01: Geometry

- Tutorial 02: Partition and Mesh

- Tutorial 03: SolverPrep

- Tutorial 04: Simulation

The tutorials above and this quickstart describe the computational engineering workflow through simulation execution. This quickstart uses a separate, standalone subdirectory to avoid file name clashes with the full tutorial files. The quickstart also uses a flat directory structure to simplify the project configuration. Larger projects, like the ModSim Templates, may require a hierarchical directory structure to separate files with identical basenames.

## References

- SCons Builders [32]

## Environment

SCons can be installed in a Conda environment with the Conda package manager. See the Conda installation and Conda environment management documentation for more details about using Conda.

Note

While the files in this tutorial don’t use WAVES, the package will still be used to fetch necessary tutorial directories and files. If you don’t have access to WAVES, the relevant WAVES tutorials abaqus source files may be found in the GitHub repository

1. Create the environment if it doesn’t exist

       $ conda create --name waves-tutorial-env --channel conda-forge 'scons>=4.6' waves

2. Activate the environment

       $ conda activate waves-tutorial-env

## Directory Structure

3. Create the project directory structure and copy the SCons quickstart source files into the `~/waves-tutorials/scons_quickstart` sub-directory with the WAVES Command-Line Utility fetch subcommand.

    $ waves fetch tutorials/scons_quickstart --destination ~/waves-tutorials/scons_quickstart
    WAVES fetch
    Destination directory: '/home/roppenheimer/waves-tutorials/scons_quickstart'
    $ cd ~/waves-tutorials/scons_quickstart
    $ pwd
    /home/roppenheimer/waves-tutorials/scons_quickstart

## SConscript

For this quickstart, we will not discuss the main SCons configuration file, named `SConstruct`, which contains project setup boilerplate. Tutorial 00: SConstruct has a more complete discussion about the contents of the `SConstruct` file.

The `SConscript` file below contains the workflow task definitions. Review the source and target files defining the workflow tasks. As discussed in Build System, a task definition also requires an action.

scons_quickstart/SConscript

     1Import("env")
     2
     3# Write project builders for re-use in task definitions
     4abaqus_journal = Builder(
     5    action=[
     6        (
     7            "cd ${TARGET.dir.abspath} && ${ABAQUS_PROGRAM} cae -noGui ${SOURCE.abspath} ${abaqus_options} "
     8            "-- ${journal_options}"
     9        )
    10    ]
    11)
    12
    13abaqus_solver = Builder(
    14    action=[
    15        (
    16            "cd ${TARGET.dir.abspath} && ${ABAQUS_PROGRAM} -job ${job} -input ${SOURCE.filebase} "
    17            "${abaqus_options} -interactive -ask_delete no"
    18        )
    19    ]
    20)
    21
    22# Add builders and pseudo-builders
    23env.Append(
    24    BUILDERS={
    25        "AbaqusJournal": abaqus_journal,
    26        "AbaqusSolver": abaqus_solver,
    27    }
    28)
    29
    30# Geometry
    31env.AbaqusJournal(
    32    target=["rectangle_geometry.cae"],
    33    source=["rectangle_geometry.py"],
    34)
    35
    36# Partition
    37env.AbaqusJournal(
    38    target=["rectangle_partition.cae"],
    39    source=["rectangle_partition.py", "rectangle_geometry.cae"],
    40)
    41
    42# Mesh
    43env.AbaqusJournal(
    44    target=["rectangle_mesh.inp", "rectangle_mesh.cae"],
    45    source=["rectangle_mesh.py", "rectangle_partition.cae", "abaqus_utilities.py"],
    46)
    47
    48# Abaqus Solve
    49solve_sources = [
    50    "rectangle_compression.inp",
    51    "rectangle_mesh.inp",
    52]
    53
    54solve_targets = [
    55    "rectangle_compression.odb",
    56    "rectangle_compression.dat",
    57    "rectangle_compression.msg",
    58    "rectangle_compression.com",
    59    "rectangle_compression.prt",
    60    "rectangle_compression.sta",
    61]
    62
    63target = env.AbaqusSolver(
    64    target=solve_targets,
    65    source=solve_sources,
    66    job="rectangle_compression",
    67    program_options="-double both",
    68)
    69
    70# Collector alias named after the model simulation
    71env.Alias("rectangle", target)
    72
    73if not env["unconditional_build"] and not env["ABAQUS_PROGRAM"]:
    74    print(f"Program 'abaqus' was not found in construction environment. Ignoring 'rectangle' target(s)")
    75    Ignore([".", "rectangle"], target)

## Building targets

    $ pwd
    /home/roppenheimer/waves-tutorials/scons_quickstart
    $ scons rectangle

## Output Files

    $ pwd
    /home/roppenheimer/waves-tutorials/scons_quickstart
    $ tree build/
    build/
    |-- SConscript
    |-- abaqus.rpy
    |-- abaqus.rpy.1
    |-- abaqus.rpy.2
    |-- abaqus_utilities.py
    |-- abaqus_utilities.pyc
    |-- rectangle_compression.com
    |-- rectangle_compression.dat
    |-- rectangle_compression.inp
    |-- rectangle_compression.msg
    |-- rectangle_compression.odb
    |-- rectangle_compression.prt
    |-- rectangle_compression.sta
    |-- rectangle_geometry.cae
    |-- rectangle_geometry.jnl
    |-- rectangle_geometry.py
    |-- rectangle_mesh.cae
    |-- rectangle_mesh.inp
    |-- rectangle_mesh.jnl
    |-- rectangle_mesh.py
    |-- rectangle_partition.cae
    |-- rectangle_partition.jnl
    `-- rectangle_partition.py

    0 directories, 23 files

## Workflow Visualization

While SCons is a powerful build automation tool, it does not come with a built-in visualization feature for displaying your build workflow. To address this limitation, the WAVES visualize command can be used.

    $ pwd
    /home/roppenheimer/waves-tutorials/scons_quickstart
    $ waves visualize rectangle --output-file scons_quickstart.png --width=28 --height=6