Using the command-line interface

The Ashes command-line interface (ashes-cli) allows you to run simulations from the command-line or from a Python script. This section will explain how to run a simple batch and then an example where ashes-cli is used in an optimization loop is shown.

1 Running a batch with ashes-cli

To run a batch, two files is needed: (1) An Ashes project file (.ash) containing your model, and (2) a batch CSV file defining your batch. The project file can be created by saving your model in Ashes to file, and the CSV file can be exported from the batch manager, see CSV file

The command to run the batch is
1
ashes-cli -runbatch -projectfile *pathtoprojectfile* -batchcsvfile *pathtocsvfile*

The ashes-cli is located in the Program Files folder (unless you installed it somewhere else). To run ashes-cli, you have to go to the installation folder first. Here is an example:

1
2
cd C:\Program Files\Ashes 3.20
ashes-cli -runbatch -projectfile "C:\Users\Per Ivar\Documents\Ashes 3.20\Onshore.ash" -batchcsvfile "C:\Users\Per Ivar\Documents\Ashes 3.20\Batch.csv"

The results from this batch will be saved in the folder C:\Users\Per Ivar\Documents\Ashes 3.20\Batch runs\Batch (replace with your own username).

2  Running ashes-cli from a Python script

The ashes-cli can easily be run from a Python script, using the subprocess module. Here is a Python script example for running a batch:
1
2
3
4
5
6
7
8
9
import subprocess

ashesExePath = "C:/Program Files/Ashes 3.20/ashes-cli.exe"
projectFilePath = "C:/Users/Per Ivar/Documents/Ashes 3.20/onshore.ash"
csvFilePath = "C:/Users/Per Ivar/Documents/Ashes 3.20/Batch.csv"

result = subprocess.run([ashesExePath, "-runbatch", "-projectfile", projectFilePath, "-batchcsvfile", csvFilePath])
print ("Return code: {}".format(result.returncode))

3  Example: Optimization loop in a Python script

In this example we will modify the tower thickness in the input CSV file, and gradually increase it until the maximum normal stress is lower than the yield stress of steel.

This example uses two files: Onshore.ash, the project file; and Batch.csv, the batch file. Both of these files are found in the Examples/Ashes-cli examples folder, which you can open by going to Help | Open examples folder. You also find the Python script itself there, called ashesCliOptimizationLoopExample.py.

This example uses the pandas module. You might have to install it by running pip install pandas in a command line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import subprocess
import shutil
import pandas as pd

# Change these paths
ashesExePath = "C:/Program Files/Ashes 3.19/ashes-cli.exe"
projectFilePath = "C:/Users/Per Ivar/Documents/Ashes 3.20/onshore.ash"
originalCsvFilePath = "C:/Users/Per Ivar/Documents/Ashes 3.20/Batch.csv"
batchResultsDir = "C:/Users/Per Ivar/Documents/Ashes 3.20/Batch runs"

initialThickness = 0.001 # 1 millimeter as initial tower thickness
thickness = initialThickness
deltaThickness = 0.0005     # Step 0.5 millimeter every iteration
yieldStrength = 355.0/1.25  # Yield strength of steel in MPa divided by safety factor
i = 1

while True:
# Make a copy of the csv file that we will modify
outDir = os.path.dirname(originalCsvFilePath)
batchName = "Optimization batch, t={}".format(thickness)
modifiedCsvFilePath = outDir + "/" + batchName + ".csv"
shutil.copyfile(originalCsvFilePath, modifiedCsvFilePath)
csv = csv.fillna("")
# Modify the tower thickness value and save file
csv.iat[4,10] = str(thickness)
# Run ashes-cli
result = subprocess.run([ashesExePath, "-runbatch", "-projectfile", projectFilePath, "-batchcsvfile", modifiedCsvFilePath])
if result.returncode != 0:
break   # Something went wrong, check console output.

sensorFilePath = batchResultsDir + "/" + batchName + "/Load case set 1/Load case 1/Time simulation/Sensor Beam element [Element 1 Tubular tower].txt"
i += 1