Added Draft, displacement and XCB widget indicator
This commit is contained in:
parent
475eb283f9
commit
a2a467e00d
|
@ -98,7 +98,6 @@ class Ship:
|
|||
@param nS Number of sections
|
||||
@param nP Number of points per section
|
||||
"""
|
||||
print(nS,nP)
|
||||
self.obj.addProperty("App::PropertyInteger","nSections","Ship", str(Translator.translate("Number of sections"))).nSections=nS
|
||||
self.obj.addProperty("App::PropertyIntegerList","nPoints","Ship", str(Translator.translate("List of number of points per sections (accumulated histogram)"))).nPoints=[0]
|
||||
self.obj.addProperty("App::PropertyFloatList","xSection","Ship", str(Translator.translate("List of sections x coordinate"))).xSection=[]
|
||||
|
@ -168,6 +167,8 @@ class Ship:
|
|||
for j in range(0,len(section)):
|
||||
mSections.append(section[j])
|
||||
# Save data
|
||||
for i in range(1,len(nPoints)):
|
||||
nPoints[i] = nPoints[i] + nPoints[i-1]
|
||||
self.obj.nPoints = nPoints[:]
|
||||
self.obj.xSection = xSection[:]
|
||||
self.obj.mSections = mSections[:]
|
||||
|
@ -661,10 +662,8 @@ def sections(obj):
|
|||
histogram = obj.nPoints[:]
|
||||
points = obj.mSections[:]
|
||||
sections = []
|
||||
print(histogram)
|
||||
for i in range(0, len(histogram) - 1):
|
||||
sections.append([])
|
||||
print(histogram[i],histogram[i+1])
|
||||
for j in range(histogram[i],histogram[i+1]):
|
||||
sections[i].append(points[j])
|
||||
return sections
|
||||
|
|
|
@ -181,14 +181,14 @@ class TaskPanel:
|
|||
# Calculate drafts
|
||||
angle = math.radians(self.form.trim.value())
|
||||
L = self.ship.Length
|
||||
draftAP = self.form.trim.value() + 0.5*L*math.tan(angle)
|
||||
draftAP = self.form.draft.value() + 0.5*L*math.tan(angle)
|
||||
if draftAP < 0.0:
|
||||
draftAP = 0.0
|
||||
draftFP = self.form.trim.value() - 0.5*L*math.tan(angle)
|
||||
draftFP = self.form.draft.value() - 0.5*L*math.tan(angle)
|
||||
if draftFP < 0.0:
|
||||
draftFP = 0.0
|
||||
# Calculate hydrostatics involved
|
||||
disp = Hydrostatics.Displacement(self.ship,self.form.draft.value(),self.form.trim.value())
|
||||
data = Hydrostatics.Displacement(self.ship,self.form.draft.value(),self.form.trim.value())
|
||||
# Prepare the string in html format
|
||||
string = 'L = %g [m]<BR>' % (self.ship.Length)
|
||||
string = string + 'B = %g [m]<BR>' % (self.ship.Beam)
|
||||
|
@ -196,8 +196,8 @@ class TaskPanel:
|
|||
string = string + 'Trim = %g [degrees]<BR>' % (self.form.trim.value())
|
||||
string = string + 'T<sub>AP</sub> = %g [m]<BR>' % (draftAP)
|
||||
string = string + 'T<sub>FP</sub> = %g [m]<HR>' % (draftFP)
|
||||
string = string + Translator.translate('Displacement') + ' = %g [ton]<BR>' % (disp[0])
|
||||
string = string + 'XCB = %g [m]' % (disp[0])
|
||||
string = string + Translator.translate('Displacement') + ' = %g [ton]<BR>' % (data[1])
|
||||
string = string + 'XCB = %g [m]' % (data[2])
|
||||
# Set the document
|
||||
self.form.output.setHtml(string)
|
||||
|
||||
|
|
|
@ -25,12 +25,80 @@ import math
|
|||
# FreeCAD modules
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
# Module
|
||||
import Instance
|
||||
|
||||
def Displacement(ship, draft, trim):
|
||||
""" Calculate ship displacement.
|
||||
@param ship Selected ship instance
|
||||
@param traft Draft.
|
||||
@param trim Trim in degrees.
|
||||
@return Ship displacement, also X bouyance center coordinate is provided.
|
||||
@return [areas,disp,xcb]: \n
|
||||
areas : Area of each section \n
|
||||
disp: Ship displacement \n
|
||||
xcb: X bouyance center coordinate
|
||||
"""
|
||||
return [0.0, 0.0]
|
||||
angle = math.radians(trim)
|
||||
sections = Instance.sections(ship)
|
||||
xCoord = ship.xSection[:]
|
||||
areas = []
|
||||
vol = 0.0
|
||||
moment = 0.0
|
||||
if not sections:
|
||||
return [[],0.0,0.0]
|
||||
for i in range(0, len(sections)):
|
||||
# Get the section
|
||||
section = sections[i]
|
||||
if len(section) < 2: # Empty section
|
||||
areas.append(0.0)
|
||||
continue
|
||||
# Get the position of the section
|
||||
x = xCoord[i]
|
||||
# Get the maximum Z value
|
||||
Z = draft - x*math.tan(angle)
|
||||
# Count the number of valid points
|
||||
n = 0
|
||||
for j in range(0,len(section)):
|
||||
z = section[j].z
|
||||
if z > Z:
|
||||
break
|
||||
n = n+1
|
||||
# Discard invalid sections
|
||||
if n == 0:
|
||||
areas.append(0.0)
|
||||
continue
|
||||
# Truncate only valid points
|
||||
points = section[0:n]
|
||||
# Study if additional point is needed
|
||||
if n < len(section):
|
||||
y0 = section[n-1].y
|
||||
z0 = section[n-1].z
|
||||
y1 = section[n].y
|
||||
z1 = section[n].z
|
||||
factor = (Z - z0) / (z1 - z0)
|
||||
y = y0 + factor*(y1 - y0)
|
||||
points.append(App.Base.Vector(x,y,Z))
|
||||
# Integrate area
|
||||
area = 0.0
|
||||
for j in range(0, len(points)-1):
|
||||
y0 = abs(points[j].y)
|
||||
z0 = points[j].z
|
||||
y1 = abs(points[j+1].y)
|
||||
z1 = points[j+1].z
|
||||
y = 0.5 * (y0 + y1)
|
||||
dz = z1 - z0
|
||||
area = area + 2.0*y*dz # 2x because only half ship is represented
|
||||
areas.append(area)
|
||||
# Add volume & moment if proceed
|
||||
if i > 0:
|
||||
dx = xCoord[i] - xCoord[i-1]
|
||||
x = 0.5*(xCoord[i] + xCoord[i-1])
|
||||
area = 0.5*(areas[i] + areas[i-1])
|
||||
vol = vol + area*dx
|
||||
moment = moment + area*dx*x
|
||||
# Compute displacement and xcb
|
||||
disp = vol / 1.025 # rho = 1.025 ton/m3 (salt water density)
|
||||
xcb = 0.0
|
||||
if vol > 0.0:
|
||||
xcb = moment / vol
|
||||
return [areas,disp,xcb]
|
||||
|
|
Loading…
Reference in New Issue
Block a user