-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding WW3 mesh writer #117
Comments
From @yunfangsun:
|
@SorooshMani-NOAA Hi Soroosh, I have made some modifications for WW3_mesh_write_from_object, could you please make a correction for it: import numpy as np
import matplotlib.pyplot as plt
def WW3_mesh_write_from_object(mesh, filename, plott=False):
# Extract the node (vertex) data from the mesh object
x = mesh.x
y = mesh.y
z = mesh.values # Assuming 'values' stores the depth. Adjust this if it's different.
# Extract the element (triangle) data from the mesh object
triangles = mesh.triangles # Assuming triangles provides (n x 3) array of vertex indices
# It's not clear how open boundary nodes are represented in `triangular_mesh4`
# For now, I'll omit that from the function. You may need to add that if it's provided in the mesh object.
OB_ID=mesh.boundaries.open.index_id
OB_ID_flattened = np.unique(np.concatenate(OB_ID.values))
with open(filename, 'w') as f:
f.write('$MeshFormat\n')
f.write('2 0 8\n')
f.write('$EndMeshFormat\n')
f.write('$Nodes\n')
f.write(f'{len(x)}\n')
for i in range(len(x)):
f.write(f'{i+1} {x[i]:.5f} {y[i]:.5f} {z[i]:.5f}\n')
f.write('$EndNodes\n')
f.write('$Elements\n')
f.write(f'{len(triangles)+ len(OB_ID_flattened)}\n')
# for i, tri in enumerate(triangles):
# f.write(f'{i+1} 2 3 0 {i+1} 0 {tri[0]+1} {tri[1]+1} {tri[2]+1}\n')
m = 0
for ob_id in OB_ID_flattened:
m += 1
f.write(f'{m} 15 2 0 0 {ob_id}\n')
for i, elem in enumerate(triangles, start=m+1):
f.write(f'{i} 2 3 0 {i-m} 0 {elem[0]+1} {elem[1]+1} {elem[2]+1}\n')
f.write('$EndElements\n')
if plott:
plt.figure(figsize=(11, 8))
avg_z_values = np.mean(z[triangles], axis=1)
plt.tripcolor(x, y, triangles, facecolors=avg_z_values, edgecolors='k')
plt.colorbar(label='Depth (m)')
plt.xlabel('Longitude')
plt.ylabel('Latitude')
plt.title('WW3 Grid - Depth [m]')
plt.tight_layout()
plt.savefig(filename + '.png', dpi=300)
plt.show()
# Example Usage:
WW3_mesh_write_from_object(hgrid, 'atlantic1.msh', plott=True) Thank you very much! |
@yunfangsun , @SorooshMani-NOAA I have the complete matlab script: adcirc2ww3_mesh.m on hera at: /scratch2/STI/coastal_temp/save/Panagiotis.Velissariou/data_FlSaLaMa. |
Based on the work done by @yunfangsun, add the writer for WW3 mesh file format.
The text was updated successfully, but these errors were encountered: