Skip to content

Commit 205ec04

Browse files
committed
ensure example is run
1 parent 1f00510 commit 205ec04

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

.github/workflows/CI_RAFT.yml

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ jobs:
4040
run: |
4141
pip install -e .
4242
43+
- name: Example run
44+
run: |
45+
cd examples
46+
python example_from_yaml.py false
47+
4348
- name: Test run
4449
run: |
4550
cd tests

examples/example_from_yaml.py

+31-17
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,44 @@
11
# example script for running RAFT from a YAML input file
22

3-
import numpy as np
3+
import sys
44
import matplotlib.pyplot as plt
55
import yaml
66
import raft
77

8-
# open the design YAML file and parse it into a dictionary for passing to raft
9-
with open('VolturnUS-S_example.yaml') as file:
10-
design = yaml.load(file, Loader=yaml.FullLoader)
8+
def run_example(plot_flag = False):
9+
# open the design YAML file and parse it into a dictionary for passing to raft
10+
with open('VolturnUS-S_example.yaml') as file:
11+
design = yaml.load(file, Loader=yaml.FullLoader)
1112

12-
# Create the RAFT model (will set up all model objects based on the design dict)
13-
model = raft.Model(design)
13+
# Create the RAFT model (will set up all model objects based on the design dict)
14+
model = raft.Model(design)
1415

15-
# Evaluate the system properties and equilibrium position before loads are applied
16-
model.analyzeUnloaded()
16+
# Evaluate the system properties and equilibrium position before loads are applied
17+
model.analyzeUnloaded()
1718

18-
# Compute natural frequencie
19-
model.solveEigen()
19+
# Compute natural frequencie
20+
model.solveEigen()
2021

21-
# Simule the different load cases
22-
model.analyzeCases(display=1)
22+
# Simule the different load cases
23+
model.analyzeCases(display=1)
2324

24-
# Plot the power spectral densities from the load cases
25-
model.plotResponses()
25+
if plot_flag:
26+
# Plot the power spectral densities from the load cases
27+
model.plotResponses()
2628

27-
# Visualize the system in its most recently evaluated mean offset position
28-
model.plot(hideGrid=True)
29+
# Visualize the system in its most recently evaluated mean offset position
30+
model.plot()
2931

30-
plt.show()
32+
plt.show()
33+
34+
if __name__ == "__main__":
35+
if len(sys.argv) == 2:
36+
plot_flag = sys.argv[1].lower() in ["1", "t", "true", "y", "yes", 1, True]
37+
elif len(sys.argv) == 1:
38+
plot_flag = True
39+
else:
40+
print("Usage: python example_from_yaml.py <True/False>")
41+
print(" The last argument is an optional declaration to show or suppress the plots (default is True)")
42+
43+
run_example(plot_flag = plot_flag)
44+

0 commit comments

Comments
 (0)