SCons Quickstart#

Note

Unlike the Quickstart, 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, single file project configuration matching the tutorials listed below.

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#

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#

  1. 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    abaqus_program=env["ABAQUS_PROGRAM"],
35)
36
37# Partition
38env.AbaqusJournal(
39    target=["rectangle_partition.cae"],
40    source=["rectangle_partition.py", "rectangle_geometry.cae"],
41    abaqus_program=env["ABAQUS_PROGRAM"],
42)
43
44# Mesh
45env.AbaqusJournal(
46    target=["rectangle_mesh.inp", "rectangle_mesh.cae"],
47    source=["rectangle_mesh.py", "rectangle_partition.cae", "abaqus_utilities.py"],
48    abaqus_program=env["ABAQUS_PROGRAM"],
49)
50
51# Abaqus Solve
52solve_sources = [
53    "rectangle_compression.inp",
54    "rectangle_mesh.inp",
55]
56
57solve_targets = [
58    "rectangle_compression.odb",
59    "rectangle_compression.dat",
60    "rectangle_compression.msg",
61    "rectangle_compression.com",
62    "rectangle_compression.prt",
63    "rectangle_compression.sta",
64]
65
66target = env.AbaqusSolver(
67    target=solve_targets,
68    source=solve_sources,
69    abaqus_program=env["ABAQUS_PROGRAM"],
70    job="rectangle_compression",
71    program_options="-double both",
72)
73
74# Collector alias named after the model simulation
75env.Alias("rectangle", target)
76
77if not env["unconditional_build"] and not env["ABAQUS_PROGRAM"]:
78    print(f"Program 'abaqus' was not found in construction environment. Ignoring 'rectangle' target(s)")
79    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
_images/scons_quickstart.png