|
1 | 1 | # example script for running RAFT from a YAML input file
|
2 | 2 |
|
3 |
| -import numpy as np |
| 3 | +import sys |
4 | 4 | import matplotlib.pyplot as plt
|
5 | 5 | import yaml
|
6 | 6 | import raft
|
7 | 7 |
|
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) |
11 | 12 |
|
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) |
14 | 15 |
|
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() |
17 | 18 |
|
18 |
| -# Compute natural frequencie |
19 |
| -model.solveEigen() |
| 19 | + # Compute natural frequencie |
| 20 | + model.solveEigen() |
20 | 21 |
|
21 |
| -# Simule the different load cases |
22 |
| -model.analyzeCases(display=1) |
| 22 | + # Simule the different load cases |
| 23 | + model.analyzeCases(display=1) |
23 | 24 |
|
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() |
26 | 28 |
|
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() |
29 | 31 |
|
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