Skip to content

Commit

Permalink
Added all the Hydrostatics to the console interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sanguinariojoe committed Jan 22, 2016
1 parent c65dbe1 commit 0a4a819
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 438 deletions.
3 changes: 2 additions & 1 deletion src/Mod/Ship/Ship.py
Expand Up @@ -30,4 +30,5 @@
" Architecture computations"

from shipCreateShip.Tools import createShip
from shipHydrostatics.Tools import areas
from shipHydrostatics.Tools import areas, displacement, wettedArea, moment,
floatingArea, BMT, mainFrameCoeff
4 changes: 2 additions & 2 deletions src/Mod/Ship/shipAreasCurve/PlotAux.py
Expand Up @@ -89,9 +89,9 @@ def plot(self, x, y, disp, xcb, ship):
addInfo = ("$XCB = {0} \\; \\mathrm{{m}}$\n"
"$Area_{{max}} = {1} \\; \\mathrm{{m}}^2$\n"
"$\\bigtriangleup = {2} \\; \\mathrm{{tons}}$".format(
xcb,
xcb.getValueAs("m").Value,
maxArea,
disp))
disp.getValueAs("kg").Value / 1000.0))
ax.text(0.0,
0.01 * maxArea,
addInfo,
Expand Down
6 changes: 3 additions & 3 deletions src/Mod/Ship/shipAreasCurve/Preview.py
Expand Up @@ -55,11 +55,11 @@ def update(self, draft, trim, ship):
point = Base.Vector(x, y, 0.0)
plane = Part.makePlane(L, B, point, Base.Vector(0, 0, 1))
plane.rotate(Base.Vector(0, 0, 0), Base.Vector(0, 1, 0), trim)
plane.translate(Base.Vector(0, 0, draft * Units.Metre.Value))
plane.translate(Base.Vector(0, 0, draft))
Part.show(plane)
objs = FreeCAD.ActiveDocument.Objects
self.obj = objs[len(objs) - 1]
self.obj.Label = 'FreeSurface'
self.obj.Label = 'FreeSurfaceHelper'
guiObj = FreeCADGui.ActiveDocument.getObject(self.obj.Name)
guiObj.ShapeColor = (0.4, 0.8, 0.85)
guiObj.Transparency = 50
Expand All @@ -69,4 +69,4 @@ def clean(self):
if not self.obj:
return
FreeCAD.ActiveDocument.removeObject(self.obj.Name)
self.obj = None
self.obj = None
111 changes: 43 additions & 68 deletions src/Mod/Ship/shipAreasCurve/TaskPanel.py
Expand Up @@ -55,12 +55,11 @@ def accept(self):
trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
num = form.num.value()

data = Hydrostatics.displacement(self.ship,
draft.getValueAs("m").Value,
0.0,
trim.getValueAs("deg").Value)
disp = data[0]
xcb = data[1].x
disp, B, _ = Hydrostatics.displacement(self.ship,
draft,
Units.parseQuantity("0 deg"),
trim)
xcb = Units.Quantity(B.x, Units.Length)
data = Hydrostatics.areas(self.ship,
num,
draft=draft,
Expand Down Expand Up @@ -245,24 +244,11 @@ def retranslateUi(self):
None,
QtGui.QApplication.UnicodeUTF8))

def clampLength(self, widget, val_min, val_max, val):
if val >= val_min and val <= val_max:
def clampValue(self, widget, val_min, val_max, val):
if val_min <= val <= val_max:
return val
input_format = USys.getLengthFormat()
val = min(val_max, max(val_min, val))
qty = Units.Quantity('{} m'.format(val))
widget.setText(Locale.toString(input_format.format(
qty.getValueAs(USys.getLengthUnits()).Value)))
return val

def clampAngle(self, widget, val_min, val_max, val):
if val >= val_min and val <= val_max:
return val
input_format = USys.getAngleFormat()
val = min(val_max, max(val_min, val))
qty = Units.Quantity('{} deg'.format(val))
widget.setText(Locale.toString(input_format.format(
qty.getValueAs(USys.getLengthUnits()).Value)))
widget.setText(val.UserString)
return val

def onData(self, value):
Expand All @@ -279,32 +265,24 @@ def onData(self, value):

# Get the values (or fix them in bad setting case)
try:
draft = Units.Quantity(Locale.fromString(
form.draft.text())).getValueAs('m').Value
draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
except:
draft = self.ship.Draft.getValueAs(USys.getLengthUnits()).Value
input_format = USys.getLengthFormat()
qty = Units.Quantity('{} m'.format(draft))
widget.setText(Locale.toString(input_format.format(
qty.getValueAs(USys.getLengthUnits()).Value)))
draft = self.ship.Draft
form.draft.setText(draft.UserString)
try:
trim = Units.Quantity(Locale.fromString(
form.trim.text())).getValueAs('deg').Value
trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
except:
trim = 0.0
input_format = USys.getAngleFormat()
qty = Units.Quantity('{} deg'.format(trim))
widget.setText(Locale.toString(input_format.format(
qty.getValueAs(USys.getLengthUnits()).Value)))
trim = Units.parseQuantity("0 deg")
form.trim.setText(trim.UserString)

bbox = self.ship.Shape.BoundBox
draft_min = bbox.ZMin / Units.Metre.Value
draft_max = bbox.ZMax / Units.Metre.Value
draft = self.clampLength(form.draft, draft_min, draft_max, draft)
draft_min = Units.Quantity(bbox.ZMin, Units.Length)
draft_max = Units.Quantity(bbox.ZMax, Units.Length)
draft = self.clampValue(form.draft, draft_min, draft_max, draft)

trim_min = -180.0
trim_max = 180.0
trim = self.clampAngle(form.trim, trim_min, trim_max, trim)
trim_min = Units.parseQuantity("-180 deg")
trim_max = Units.parseQuantity("180 deg")
trim = self.clampValue(form.trim, trim_min, trim_max, trim)

self.onUpdate()
self.preview.update(draft, trim, self.ship)
Expand All @@ -319,40 +297,39 @@ def onUpdate(self):
form.trim = self.widget(QtGui.QLineEdit, "Trim")
form.output = self.widget(QtGui.QTextEdit, "OutputData")

draft = Units.Quantity(Locale.fromString(
form.draft.text())).getValueAs('m').Value
trim = Units.Quantity(Locale.fromString(
form.trim.text())).getValueAs('deg').Value
draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
trim = Units.parseQuantity(Locale.fromString(form.trim.text()))

# Calculate the drafts at each perpendicular
angle = math.radians(trim)
angle = trim.getValueAs("rad").Value
L = self.ship.Length.getValueAs('m').Value
B = self.ship.Breadth.getValueAs('m').Value
draftAP = draft + 0.5 * L * math.tan(angle)
draftAP = draft + 0.5 * self.ship.Length * math.tan(angle)
if draftAP < 0.0:
draftAP = 0.0
draftFP = draft - 0.5 * L * math.tan(angle)
draftFP = draft - 0.5 * self.ship.Length * math.tan(angle)
if draftFP < 0.0:
draftFP = 0.0
# Calculate the involved hydrostatics
data = Hydrostatics.displacement(self.ship,
draft,
0.0,
trim)
disp, B, _ = Hydrostatics.displacement(self.ship,
draft,
Units.parseQuantity("0 deg"),
trim)
xcb = Units.Quantity(B.x, Units.Length)
# Setup the html string
string = 'L = {0} [m]<BR>'.format(L)
string = string + 'B = {0} [m]<BR>'.format(B)
string = string + 'T = {0} [m]<HR>'.format(draft)
string = string + 'Trim = {0} [degrees]<BR>'.format(trim)
string = string + 'T<sub>AP</sub> = {0} [m]<BR>'.format(draftAP)
string = string + 'T<sub>FP</sub> = {0} [m]<HR>'.format(draftFP)
string = u'L = {0}<BR>'.format(self.ship.Length.UserString)
string += u'B = {0}<BR>'.format(self.ship.Breadth.UserString)
string += u'T = {0}<HR>'.format(draft.UserString)
string += u'Trim = {0}<BR>'.format(trim.UserString)
string += u'T<sub>AP</sub> = {0}<BR>'.format(draftAP.UserString)
string += u'T<sub>FP</sub> = {0}<HR>'.format(draftFP.UserString)
dispText = QtGui.QApplication.translate(
"ship_areas",
'Displacement',
None,
QtGui.QApplication.UnicodeUTF8)
string = string + dispText + ' = {0} [ton]<BR>'.format(data[0])
string = string + 'XCB = {0} [m]'.format(data[1].x)
string += dispText + u' = {0}<BR>'.format(disp.UserString)
string += u'XCB = {0}'.format(xcb.UserString)
form.output.setHtml(string)

def save(self):
Expand All @@ -363,10 +340,8 @@ def save(self):
form.trim = self.widget(QtGui.QLineEdit, "Trim")
form.num = self.widget(QtGui.QSpinBox, "Num")

draft = Units.Quantity(Locale.fromString(
form.draft.text())).getValueAs('m').Value
trim = Units.Quantity(Locale.fromString(
form.trim.text())).getValueAs('deg').Value
draft = Units.parseQuantity(Locale.fromString(form.draft.text()))
trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
num = form.num.value()

props = self.ship.PropertiesList
Expand All @@ -385,7 +360,7 @@ def save(self):
"AreaCurveDraft",
"Ship",
tooltip)
self.ship.AreaCurveDraft = '{} m'.format(draft)
self.ship.AreaCurveDraft = draft
try:
props.index("AreaCurveTrim")
except ValueError:
Expand All @@ -401,7 +376,7 @@ def save(self):
"AreaCurveTrim",
"Ship",
tooltip)
self.ship.AreaCurveTrim = '{} deg'.format(trim)
self.ship.AreaCurveTrim = trim
try:
props.index("AreaCurveNum")
except ValueError:
Expand All @@ -426,4 +401,4 @@ def createTask():
if panel.setupUi():
Gui.Control.closeDialog(panel)
return None
return panel
return panel
8 changes: 6 additions & 2 deletions src/Mod/Ship/shipGZ/Tools.py
Expand Up @@ -121,8 +121,12 @@ def solve_point(W, COG, TW, VOLS, ship, tanks, roll, var_trim=True):

for i in range(MAX_EQUILIBRIUM_ITERS):
# Get the displacement, and the bouyance application point
disp, B, Cb = Hydrostatics.displacement(ship, draft, roll, trim)
disp *= 1000.0 * G
disp, B, _ = Hydrostatics.displacement(ship,
draft * Units.Metre,
roll * Units.Degree,
trim * Units.Degree)
disp = disp.getValueAs("kg").Value * G
B.multiply(1.0 / Units.Metre.Value)
# Add the tanks effect on the center of gravity
cog = Vector(COG.x * W, COG.y * W, COG.z * W)
for i,t in enumerate(tanks):
Expand Down
57 changes: 34 additions & 23 deletions src/Mod/Ship/shipHydrostatics/PlotAux.py
Expand Up @@ -84,11 +84,11 @@ def plotVolume(self):
t1cm = []
xcb = []
for i in range(len(self.points)):
disp.append(self.points[i].disp)
draft.append(self.points[i].draft)
warea.append(self.points[i].wet)
t1cm.append(self.points[i].mom)
xcb.append(self.points[i].xcb)
disp.append(self.points[i].disp.getValueAs("kg").Value / 1000.0)
draft.append(self.points[i].draft.getValueAs("m").Value)
warea.append(self.points[i].wet.getValueAs("m^2").Value)
t1cm.append(self.points[i].mom.getValueAs("kg*m").Value / 1000.0)
xcb.append(self.points[i].xcb.getValueAs("m").Value)

axes = Plot.axesList()
for ax in axes:
Expand Down Expand Up @@ -166,11 +166,11 @@ def plotStability(self):
kbt = []
bmt = []
for i in range(len(self.points)):
disp.append(self.points[i].disp)
draft.append(self.points[i].draft)
farea.append(self.points[i].farea)
kbt.append(self.points[i].KBt)
bmt.append(self.points[i].BMt)
disp.append(self.points[i].disp.getValueAs("kg").Value / 1000.0)
draft.append(self.points[i].draft.getValueAs("m").Value)
farea.append(self.points[i].farea.getValueAs("m^2").Value)
kbt.append(self.points[i].KBt.getValueAs("m").Value)
bmt.append(self.points[i].BMt.getValueAs("m").Value)

axes = Plot.axesList()
for ax in axes:
Expand Down Expand Up @@ -248,8 +248,8 @@ def plotCoeffs(self):
cf = []
cm = []
for i in range(len(self.points)):
disp.append(self.points[i].disp)
draft.append(self.points[i].draft)
disp.append(self.points[i].disp.getValueAs("kg").Value / 1000.0)
draft.append(self.points[i].draft.getValueAs("m").Value)
cb.append(self.points[i].Cb)
cf.append(self.points[i].Cf)
cm.append(self.points[i].Cm)
Expand Down Expand Up @@ -322,17 +322,28 @@ def spreadSheet(self, ship, trim):
# Print the data
for i in range(len(self.points)):
point = self.points[i]
s.set("A{}".format(i + 2), str(point.disp))
s.set("B{}".format(i + 2), str(point.draft))
s.set("C{}".format(i + 2), str(point.wet))
s.set("D{}".format(i + 2), str(point.mom))
s.set("E{}".format(i + 2), str(point.farea))
s.set("F{}".format(i + 2), str(point.xcb))
s.set("G{}".format(i + 2), str(point.KBt))
s.set("H{}".format(i + 2), str(point.BMt))
s.set("I{}".format(i + 2), str(point.Cb))
s.set("J{}".format(i + 2), str(point.Cf))
s.set("K{}".format(i + 2), str(point.Cm))
s.set("A{}".format(i + 2),
str(point.disp.getValueAs("kg").Value / 1000.0))
s.set("B{}".format(i + 2),
str(point.draft.getValueAs("m").Value))
s.set("C{}".format(i + 2),
str(point.wet.getValueAs("m^2").Value))
s.set("D{}".format(i + 2),
str(point.mom.getValueAs("kg*m").Value / 1000.0))
s.set("E{}".format(i + 2),
str(point.farea.getValueAs("m^2").Value))
s.set("F{}".format(i + 2),
str(point.xcb.getValueAs("m").Value))
s.set("G{}".format(i + 2),
str(point.KBt.getValueAs("m").Value))
s.set("H{}".format(i + 2),
str(point.BMt.getValueAs("m").Value))
s.set("I{}".format(i + 2),
str(point.Cb))
s.set("J{}".format(i + 2),
str(point.Cf))
s.set("K{}".format(i + 2),
str(point.Cm))

# Recompute
FreeCAD.activeDocument().recompute()
11 changes: 4 additions & 7 deletions src/Mod/Ship/shipHydrostatics/TaskPanel.py
Expand Up @@ -57,12 +57,9 @@ def accept(self):
form.maxDraft = self.widget(QtGui.QLineEdit, "MaxDraft")
form.nDraft = self.widget(QtGui.QSpinBox, "NDraft")

trim = Units.Quantity(Locale.fromString(
form.trim.text())).getValueAs('deg').Value
min_draft = Units.Quantity(Locale.fromString(
form.minDraft.text())).getValueAs('m').Value
max_draft = Units.Quantity(Locale.fromString(
form.maxDraft.text())).getValueAs('m').Value
trim = Units.parseQuantity(Locale.fromString(form.trim.text()))
min_draft = Units.parseQuantity(Locale.fromString(form.minDraft.text()))
max_draft = Units.parseQuantity(Locale.fromString(form.maxDraft.text()))
n_draft = form.nDraft.value()

draft = min_draft
Expand All @@ -72,7 +69,6 @@ def accept(self):
draft = draft + dDraft
drafts.append(draft)

# Compute data
# Get external faces
self.loop = QtCore.QEventLoop()
self.timer = QtCore.QTimer()
Expand All @@ -94,6 +90,7 @@ def accept(self):
App.Console.PrintError(msg + '\n')
return False
faces = Part.makeShell(faces)

# Get the hydrostatics
msg = QtGui.QApplication.translate(
"ship_console",
Expand Down

0 comments on commit 0a4a819

Please sign in to comment.