Skip to content

Commit f80b9c0

Browse files
committed
Adding a write bathymetry feature that is used later to generate MD.out with the seafloor file in options
1 parent 599609a commit f80b9c0

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

famodel/project.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4147,7 +4147,7 @@ def extractFarmInfo(self, cmax=5, fmax=10/6, Cmeander=1.9):
41474147

41484148
return wts, yaw_init
41494149

4150-
def FFarmCompatibleMDOutput(self, filename, unrotateTurbines=True, renameBody=True, removeBody=True, MDoptionsDict={}):
4150+
def FFarmCompatibleMDOutput(self, filename, unrotateTurbines=True, renameBody=True, removeBody=True, MDoptionsDict={}, bathymetryFile=None):
41514151
'''
41524152
Function to create FFarm-compatible MoorDyn input file:
41534153
@@ -4218,7 +4218,22 @@ def FFarmCompatibleMDOutput(self, filename, unrotateTurbines=True, renameBody=Tr
42184218

42194219
with open(filename, 'w') as f:
42204220
f.writelines(newLines)
4221-
4221+
4222+
if bathymetryFile:
4223+
with open(filename, 'r') as f:
4224+
lines = f.readlines()
4225+
4226+
newLines = []
4227+
4228+
for i, line in enumerate(lines):
4229+
newLines.append(line)
4230+
if '---' in line and 'OPTIONS' in line.upper():
4231+
newLines.append(f" {bathymetryFile} Seafloor File\n")
4232+
4233+
4234+
with open(filename, 'w') as f:
4235+
f.writelines(newLines)
4236+
42224237
def resetArrayCenter(self, FOWTOnly=True):
42234238
'''
42244239
Function to reset array center such that the farm origin is the mid-point between all FOWT platforms:

famodel/seabed/seabed_tools.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,32 @@ def readBathymetryFile(filename, dtype=float):
4242

4343
return bathGrid_Xs, bathGrid_Ys, bathGrid
4444

45-
45+
def writeBathymetryFile(filename, grid_x, grid_y, grid_depth):
46+
"""
47+
Writes bathymetry data to a file in the format expected by readBathymetryFile.
48+
49+
Parameters:
50+
filename (str): The name of the file to write to.
51+
grid_x (list or np.ndarray): The X coordinates of the grid.
52+
grid_y (list or np.ndarray): The Y coordinates of the grid.
53+
grid_depth (np.ndarray): The bathymetry grid (depth values).
54+
"""
55+
with open(filename, 'w') as f:
56+
# Write a placeholder header
57+
f.write("Bathymetry Data File\n")
58+
59+
# Write the number of grid values in the x and y directions
60+
f.write(f"nGridX {len(grid_x)}\n")
61+
f.write(f"nGridY {len(grid_y)}\n")
62+
63+
# Write the X coordinates
64+
f.write(" ".join(map(str, grid_x)) + "\n")
65+
66+
# Write the Y coordinates and the bathymetry grid
67+
for i, y in enumerate(grid_y):
68+
row = [y] + list(grid_depth[i, :])
69+
f.write(" ".join(map(str, row)) + "\n")
70+
4671
def getSoilTypes(filename):
4772
'''function to read in a preliminary input text file format of soil type information'''
4873

0 commit comments

Comments
 (0)