Skip to content

Commit

Permalink
Merge pull request #11 from RubendeBruin/lid
Browse files Browse the repository at this point in the history
Added triangulation of bow and stern if needed (instead of added a vertex at the center) Added some convenience methods for working on frames (x,y, scaled)
  • Loading branch information
RubendeBruin authored Feb 13, 2025
2 parents ad10ec8 + faa6b7e commit 99709b6
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 224 deletions.
149 changes: 53 additions & 96 deletions guis/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</property>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="Mesh">
<attribute name="title">
Expand Down Expand Up @@ -299,23 +299,6 @@ B for box
<string>Capytaine</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
<item row="15" column="1" colspan="2">
<widget class="QLineEdit" name="teOutputFile">
<property name="text">
<string>my_model</string>
</property>
</widget>
</item>
<item row="26" column="0">
<widget class="QPushButton" name="pbRunCapytaine">
<property name="text">
<string>Go!</string>
</property>
</widget>
</item>
<item row="19" column="2">
<widget class="QLineEdit" name="teHydOrigin"/>
</item>
<item row="7" column="2">
<widget class="QLabel" name="lblHeading">
<property name="text">
Expand All @@ -326,20 +309,16 @@ B for box
</property>
</widget>
</item>
<item row="18" column="1">
<widget class="QCheckBox" name="cbMakeDaveModel">
<property name="text">
<string>Make DAVE model</string>
<item row="8" column="2">
<widget class="QDoubleSpinBox" name="teWaterdepth">
<property name="minimum">
<double>0.010000000000000</double>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="lblPeriods">
<property name="text">
<string>TextLabel</string>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
<property name="wordWrap">
<bool>true</bool>
<property name="value">
<double>100.000000000000000</double>
</property>
</widget>
</item>
Expand All @@ -350,72 +329,62 @@ B for box
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<item row="5" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Periods [s]</string>
<string>Headings [degrees]</string>
</property>
</widget>
</item>
<item row="19" column="1">
<widget class="QLabel" name="label_16">
<item row="1" column="0">
<widget class="QLabel" name="label_20">
<property name="text">
<string>hyd origin</string>
<string>Output file names</string>
</property>
</widget>
</item>
<item row="13" column="0" colspan="3">
<widget class="QCheckBox" name="cbSymmetry">
<item row="9" column="0" colspan="3">
<widget class="QCheckBox" name="cbLid">
<property name="text">
<string>Symmetry in XZ</string>
<string>Add lid at z=-0.01m (can not be used together with symmetry)</string>
</property>
</widget>
</item>
<item row="21" column="1">
<widget class="QLabel" name="label_17">
<item row="15" column="0" colspan="3">
<widget class="QCheckBox" name="cbSymmetryHeadings">
<property name="text">
<string>shape file for buoyancy</string>
<string>Use symmetry in XY for output (only headings 0...180 defined)</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<item row="4" column="2">
<widget class="QLabel" name="lblPeriods">
<property name="text">
<string>Body name [str]</string>
<string>TextLabel</string>
</property>
</widget>
</item>
<item row="21" column="2">
<widget class="QLineEdit" name="teShapeFile"/>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="teHeading">
<property name="text">
<string>np.linspace(0, 180, 9)</string>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="15" column="0">
<widget class="QLabel" name="label_20">
<item row="2" column="2">
<widget class="QLineEdit" name="tePeriods">
<property name="text">
<string>Output file names</string>
<string>[*np.linspace(0.5,10,num=20), 11,12,14,16,20]</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLineEdit" name="teMeshFile"/>
</item>
<item row="14" column="0" colspan="3">
<item row="16" column="0">
<widget class="QPushButton" name="pbShowMesh">
<property name="text">
<string>Show mesh</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_13">
<item row="2" column="0">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Headings [degrees]</string>
<string>Periods [s]</string>
</property>
</widget>
</item>
Expand All @@ -426,53 +395,41 @@ B for box
</property>
</widget>
</item>
<item row="25" column="2">
<widget class="QLineEdit" name="teCogZ"/>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="teName"/>
</item>
<item row="25" column="1">
<widget class="QLabel" name="label_19">
<item row="8" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>cog z</string>
<string>Waterdepth [m]</string>
</property>
</widget>
</item>
<item row="23" column="1">
<widget class="QLabel" name="label_18">
<item row="13" column="0" colspan="3">
<widget class="QCheckBox" name="cbSymmetryMesh">
<property name="text">
<string>Radii of gyration</string>
<string>Use symmetry in XZ for mesh (only half of mesh defined)</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_15">
<item row="21" column="0">
<widget class="QPushButton" name="pbRunCapytaine">
<property name="text">
<string>Waterdepth [m]</string>
<string>Go!</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="tePeriods">
<item row="0" column="2">
<widget class="QLineEdit" name="teMeshFile"/>
</item>
<item row="5" column="2">
<widget class="QLineEdit" name="teHeading">
<property name="text">
<string>[*np.linspace(0.5,10,num=20), 11,12,14,16,20]</string>
<string>np.linspace(0, 180, 9)</string>
</property>
</widget>
</item>
<item row="23" column="2">
<widget class="QLineEdit" name="teRadii"/>
</item>
<item row="8" column="2">
<widget class="QDoubleSpinBox" name="teWaterdepth">
<property name="minimum">
<double>0.010000000000000</double>
</property>
<property name="maximum">
<double>9999999.000000000000000</double>
</property>
<property name="value">
<double>100.000000000000000</double>
<item row="1" column="2">
<widget class="QLineEdit" name="teOutputFile">
<property name="text">
<string>my_model</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -557,7 +514,7 @@ B for box
<rect>
<x>0</x>
<y>0</y>
<width>232</width>
<width>250</width>
<height>932</height>
</rect>
</property>
Expand Down
50 changes: 35 additions & 15 deletions src/pymeshup/gui/capytaine_runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import warnings

import netCDF4 # required for saving - fallback to scipy.io.netcdf causes issues

Expand Down Expand Up @@ -33,29 +34,48 @@ def make_database(body, omegas, wave_directions, waterdepth=0):

return dataset

def run_capytaine(name: str, # name of the body eg "boat"
file_grid : str, # input file, e.g. grid.stl
periods : np.array, # periods in seconds
def run_capytaine(file_grid : str, # input file, e.g. grid.stl
periods : np.array, # periods in seconds
directions_deg : np.array,
waterdepth : float = None, # waterdepth
symmetry : bool = False, # symmetry in XZ plane
show_only : bool = False # show only the mesh
waterdepth : float = None, # waterdepth
grid_symmetry : bool = False, # symmetry in XZ plane
heading_symmetry : bool = False, # symmetry in YZ plane
show_only : bool = False, # show only the mesh
lid : bool = True, # add a lid
outfile : str = None # output file
):

name = file_grid[:-4]

if grid_symmetry and not heading_symmetry:
warnings.warn('Grid symmetry requires heading symmetry')

periods = np.array(periods)
directions = np.array(directions_deg) * pi / 180

file_out_nc = file_grid[:-4] + '.nc'
outfile = "{}.dhyd".format(file_grid[:-4])
file_out_nc = outfile + '.nc'
outfile_dhyd = outfile + '.dhyd'


omega = 2 * np.pi / periods

boat = cpt.FloatingBody.from_file(file_grid, file_format="stl", name=name)
# load and create mesh
hull_mesh = cpt.load_mesh(file_grid, file_format="stl")

# generate lid
if lid:
lid_mesh = hull_mesh.generate_lid(z=-0.01)
else:
lid_mesh = None


if grid_symmetry:
if lid:
raise ValueError('Symmetry and lid are not compatible')

hull_mesh = ReflectionSymmetricMesh(hull_mesh, plane=xOz_Plane, name=f"{name}_mesh")

if symmetry:
mesh = ReflectionSymmetricMesh(boat.mesh, plane=xOz_Plane, name=f"{name}_mesh")
boat = cpt.FloatingBody(mesh=mesh)
boat = cpt.FloatingBody(mesh=hull_mesh, lid_mesh=lid_mesh)

boat.add_all_rigid_body_dofs()
boat.keep_immersed_part()
Expand All @@ -79,12 +99,12 @@ def run_capytaine(name: str, # name of the body eg "boat"
print(f'saved NC results as {file_out_nc}')

hyd = Hyddb1.create_from_capytaine(filename=file_out_nc)
if symmetry:
if heading_symmetry:
hyd.symmetry = mafredo.Symmetry.XZ
else:
hyd.symmetry = mafredo.Symmetry.No


hyd.save_as(outfile)
print(f'Saved as: {outfile}')
hyd.save_as(outfile_dhyd)
print(f'Saved as: {outfile_dhyd}')
hyd.plot(do_show=True)
47 changes: 47 additions & 0 deletions src/pymeshup/gui/examples/sailboat.pym
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Example of a pontoon shaped barge
# created from Frames

width = 30.48
height = 6.114
fr = 100.6 / 55 # frame

stern = Frame(0,4.284,
width/2, 4.284,
width/2, height).autocomplete()

end_of_skeg = Frame(0,0,
width/2, 0,
width/2, height).autocomplete()

main = Frame(0,0,
width/2, 0,
width/2, height).autocomplete()

half_bow = Frame(0,1.5,
width/2, 1.5,
width/2, height).autocomplete()


bow = stern.copy()


Barge = Hull(
0, bow,
6*fr, end_of_skeg,
47*fr, main,
53*fr, half_bow,
55*fr, bow
)


# Add skegs

skeg = Box(0, 8.9,
-0.2, 0.2,
0, 6)
skegPS = skeg.move(y=8)
skegSB = skeg.move(y=-8)

Hull_K10031 = Barge.add(skegPS).add(skegSB)

del skegPS, skegSB, skeg, Barge
Loading

0 comments on commit 99709b6

Please sign in to comment.