|
| 1 | +from itertools import product |
| 2 | +import os |
| 3 | +from dataclasses import dataclass |
| 4 | + |
| 5 | +"""Simple script for generating a bunch of model files for benchmarking purposes. |
| 6 | +
|
| 7 | +Just needs basic python (tested for version >=3.8). |
| 8 | +""" |
| 9 | + |
| 10 | + |
| 11 | +@dataclass |
| 12 | +class BenchmarkParams: |
| 13 | + num_lines: int |
| 14 | + num_segments: int |
| 15 | + |
| 16 | + |
| 17 | +def generate_benchmark(base_output_folder, params: BenchmarkParams): |
| 18 | + """Generate a single benchmark model file. |
| 19 | +
|
| 20 | + The model has a user defined number of lines that each share a fixed top |
| 21 | + point, and have their own bottom point. |
| 22 | + They start off at a 10 degree angle from vertical. |
| 23 | + """ |
| 24 | + points = "\n".join( |
| 25 | + f"{i + 2} free 34.20201433256687 0.0 -93.96926207859084 0 0 0 0 -" |
| 26 | + for i in range(params.num_lines) |
| 27 | + ) |
| 28 | + line_length = 100.0 |
| 29 | + lines = "\n".join( |
| 30 | + f"{i+1} chain 1 {i + 2} {line_length} {params.num_segments} p,t" |
| 31 | + for i in range(params.num_lines) |
| 32 | + ) |
| 33 | + |
| 34 | + file_str = f"""--------------------- MoorDyn Input File ------------------------------------------------------- |
| 35 | +Output from generate_cases.py |
| 36 | +----------------------- LINE TYPES -------------------------------------------------------------- |
| 37 | +TypeName Diam Mass/m EA BA/-zeta EI Cd Ca CdAx CaAx |
| 38 | +(name) (m) (kg/m) (N) (N-s/-) (N-m^2) (-) (-) (-) (-) |
| 39 | +chain 0.252 390 16000000.0 -0.3 0.0 1.37 0.64 1.0 0.0 |
| 40 | +----------------------- POINTS ------------------------------------------------------------------- |
| 41 | +Node Type X Y Z M V CdA CA |
| 42 | +(-) (-) (m) (m) (m) (kg) (m^3) (m^2) (-) |
| 43 | +1 free 0.0 0.0 0.0 0 0 0 0 - |
| 44 | +{points} |
| 45 | +-------------------------- LINES ----------------------------------------------------------------- |
| 46 | +Line LineType NodeA NodeB UnstrLen NumSegs Flags/Outputs |
| 47 | +(-) (-) (-) (-) (m) (-) (-) |
| 48 | +{lines} |
| 49 | +-------------------------- SOLVER OPTIONS--------------------------- |
| 50 | +0 writeLog - Write a log file |
| 51 | +0.001 dtM - time step to use in mooring integration |
| 52 | +rk4 tScheme |
| 53 | +3000000.0 kb - bottom stiffness |
| 54 | +300000.0 cb - bottom damping |
| 55 | +200.0 WtrDpth - water depth |
| 56 | +4.0 ICDfac - factor to scale drag coeff during IC |
| 57 | +1.5e-06 threshIC - threshold for IC convergence |
| 58 | +0.0 TmaxIC - threshold for IC convergence |
| 59 | +1e-05 dtIC - Time lapse between convergence tests (s) |
| 60 | +9.81 g - gravitational force constant |
| 61 | +1025 rho - water density |
| 62 | +0 WaveKin - waves mode |
| 63 | +0 Currents - current mode |
| 64 | +------------------------- need this line -------------------------------------- |
| 65 | +""" |
| 66 | + |
| 67 | + folder_name = f"{params.num_lines}_lines_{params.num_segments}_segs" |
| 68 | + |
| 69 | + output_folder = os.path.join(base_output_folder, folder_name) |
| 70 | + try: |
| 71 | + os.mkdir(output_folder) |
| 72 | + except FileExistsError: |
| 73 | + pass |
| 74 | + |
| 75 | + out_path = os.path.join(output_folder, "lines.txt") |
| 76 | + |
| 77 | + with open(out_path, "w") as f: |
| 78 | + f.write(file_str) |
| 79 | + |
| 80 | + |
| 81 | +def main(): |
| 82 | + |
| 83 | + number_of_lines = [2**n for n in range(7)] |
| 84 | + number_of_segments = [2**n for n in range(7)] |
| 85 | + |
| 86 | + for vals in product(number_of_lines, number_of_segments): |
| 87 | + params = BenchmarkParams(*vals) |
| 88 | + generate_benchmark("./", params) |
| 89 | + |
| 90 | + |
| 91 | +if __name__ == "__main__": |
| 92 | + main() |
0 commit comments