def accept(self): if not self.ship: return False self.save() # Plot data mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QLineEdit, "Draft") form.trim = self.widget(QtGui.QLineEdit, "Trim") form.num = self.widget(QtGui.QSpinBox, "Num") draft = Units.parseQuantity(Locale.fromString(form.draft.text())) trim = Units.parseQuantity(Locale.fromString(form.trim.text())) num = form.num.value() 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, trim=trim) x = [] y = [] for i in range(0, len(data)): x.append(data[i][0].getValueAs("m").Value) y.append(data[i][1].getValueAs("m^2").Value) PlotAux.Plot(x, y, disp, xcb, self.ship) self.preview.clean() return True
def accept(self): if not self.ship: return False self.save() # Plot data mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QLineEdit, "Draft") form.trim = self.widget(QtGui.QLineEdit, "Trim") draft = Units.Quantity(form.draft.text()).getValueAs('m').Value trim = Units.Quantity(form.trim.text()).getValueAs('deg').Value data = Hydrostatics.displacement(self.ship, draft, 0.0, trim) disp = data[0] xcb = data[1].x data = Hydrostatics.areas(self.ship, draft, 0.0, trim) x = [] y = [] for i in range(0, len(data)): x.append(data[i][0]) y.append(data[i][1]) PlotAux.Plot(x, y, disp, xcb, self.ship) self.preview.clean() return True
def accept(self): if not self.ship: return False self.save() # Plot data mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft") form.trim = self.widget(QtGui.QDoubleSpinBox, "Trim") data = Hydrostatics.displacement(self.ship, form.draft.value(), 0.0, form.trim.value()) disp = data[0] xcb = data[1].x data = Hydrostatics.areas(self.ship, form.draft.value(), 0.0, form.trim.value()) x = [] y = [] for i in range(0, len(data)): x.append(data[i][0]) y.append(data[i][1]) PlotAux.Plot(x, y, disp, xcb, self.ship) self.preview.clean() return True
def accept(self): if not self.ship: return False self.save() # Plot data mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QLineEdit, "Draft") form.trim = self.widget(QtGui.QLineEdit, "Trim") draft = Units.Quantity(Locale.fromString( form.draft.text())).getValueAs('m').Value trim = Units.Quantity(Locale.fromString( form.trim.text())).getValueAs('deg').Value data = Hydrostatics.displacement(self.ship, draft, 0.0, trim) disp = data[0] xcb = data[1].x data = Hydrostatics.areas(self.ship, draft, 0.0, trim) x = [] y = [] for i in range(0, len(data)): x.append(data[i][0]) y.append(data[i][1]) PlotAux.Plot(x, y, disp, xcb, self.ship) self.preview.clean() return True
def weights(obj): """Returns the ship weights list. If weights has not been set this tool will generate the default ones. Keyword arguments: obj -- Ship inmstance object. """ # Test if is a ship instance props = obj.PropertiesList try: props.index("IsShip") except ValueError: return None if not obj.IsShip: return None # Test if properties already exist try: props.index("WeightNames") except ValueError: tooltip = str( QtGui.QApplication.translate("Ship", "Ship Weights names", None, QtGui.QApplication.UnicodeUTF8)) lighweight = str( QtGui.QApplication.translate("Ship", "Lightweight", None, QtGui.QApplication.UnicodeUTF8)) obj.addProperty("App::PropertyStringList", "WeightNames", "Ship", tooltip).WeightNames = [lighweight] try: props.index("WeightMass") except ValueError: # Compute a mass aproximation from shipHydrostatics import Tools disp = Tools.displacement(obj, obj.Draft) tooltip = str( QtGui.QApplication.translate("Ship", "Ship Weights masses [tons]", None, QtGui.QApplication.UnicodeUTF8)) obj.addProperty("App::PropertyFloatList", "WeightMass", "Ship", tooltip).WeightMass = [1000.0 * disp[0]] try: props.index("WeightPos") except ValueError: # Compute a CoG aproximation from shipHydrostatics import Tools disp = Tools.displacement(obj, obj.Draft) tooltip = str( QtGui.QApplication.translate("Ship", "Ship Weights centers of gravity", None, QtGui.QApplication.UnicodeUTF8)) obj.addProperty( "App::PropertyVectorList", "WeightPos", "Ship", tooltip).WeightPos = [Vector(disp[1].x, 0.0, obj.Draft)] # Setup the weights list weights = [] for i in range(len(obj.WeightNames)): weights.append( [obj.WeightNames[i], obj.WeightMass[i], obj.WeightPos[i]]) return weights
def weights(obj): """ Returns Ship weights list. If weights has not been sets, this tool creates it. @param obj Ship object @return Weights list. None if errors """ # Test if is a ship instance props = obj.PropertiesList try: props.index("IsShip") except ValueError: return None if not obj.IsShip: return None # Test if properties already exist try: props.index("WeightNames") except ValueError: obj.addProperty( "App::PropertyStringList", "WeightNames", "Ship", str(Translator.translate("Ship Weights names"))).WeightNames = [ Translator.translate("Lightweight").__str__() ] try: props.index("WeightMass") except ValueError: # Compute mass aproximation from shipHydrostatics import Tools disp = Tools.displacement(obj, obj.Draft) obj.addProperty( "App::PropertyFloatList", "WeightMass", "Ship", str(Translator.translate("Ship Weights masses"))).WeightMass = [ 1000.0 * disp[0] ] try: props.index("WeightPos") except ValueError: # Compute mass aproximation from shipHydrostatics import Tools disp = Tools.displacement(obj, obj.Draft) obj.addProperty( "App::PropertyVectorList", "WeightPos", "Ship", str(Translator.translate( "Ship Weights centers of gravity"))).WeightPos = [ Vector(disp[1].x, 0.0, obj.Draft) ] # Setup list weights = [] for i in range(0, len(obj.WeightNames)): weights.append( [obj.WeightNames[i], obj.WeightMass[i], obj.WeightPos[i]]) return weights
def onUpdate(self): """ Method called when update data request. """ if not self.ship: return # Calculate drafts angle = math.radians(self.form.trim.value()) L = self.ship.Length draftAP = self.form.draft.value() + 0.5 * L * math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = self.form.draft.value() - 0.5 * L * math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate hydrostatics involved data = Hydrostatics.displacement(self.ship, self.form.draft.value(), 0.0, 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) string = string + 'T = %g [m]<HR>' % (self.form.draft.value()) 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>' % (data[0]) string = string + 'XCB = %g [m]' % (data[1].x) # Set the document self.form.output.setHtml(string)
def onUpdate(self): """ Method called when update data request. """ if not self.ship: return # Calculate drafts angle = math.radians(self.form.trim.value()) L = self.ship.Length draftAP = self.form.draft.value() + 0.5*L*math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = self.form.draft.value() - 0.5*L*math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate hydrostatics involved data = Hydrostatics.displacement(self.ship,self.form.draft.value(),0.0,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) string = string + 'T = %g [m]<HR>' % (self.form.draft.value()) 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>' % (data[0]) string = string + 'XCB = %g [m]' % (data[1].x) # Set the document self.form.output.setHtml(string)
def onUpdate(self): """ Method called when the data update is requested. """ if not self.ship: return mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft") form.trim = self.widget(QtGui.QDoubleSpinBox, "Trim") form.output = self.widget(QtGui.QTextEdit, "OutputData") # Calculate the drafts at each perpendicular angle = math.radians(form.trim.value()) L = self.ship.Length.getValueAs('m').Value B = self.ship.Breadth.getValueAs('m').Value draftAP = form.draft.value() + 0.5 * L * math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = form.draft.value() - 0.5 * L * math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate the involved hydrostatics data = Hydrostatics.displacement(self.ship, form.draft.value(), 0.0, form.trim.value()) # 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(form.draft.value()) string = string + 'Trim = {0} [degrees]<BR>'.format(form.trim.value()) string = string + 'T<sub>AP</sub> = {0} [m]<BR>'.format(draftAP) string = string + 'T<sub>FP</sub> = {0} [m]<HR>'.format(draftFP) 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) form.output.setHtml(string)
def onUpdate(self): """ Method called when the data update is requested. """ if not self.ship: return mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QDoubleSpinBox, "Draft") form.trim = self.widget(QtGui.QDoubleSpinBox, "Trim") form.output = self.widget(QtGui.QTextEdit, "OutputData") # Calculate the drafts at each perpendicular angle = math.radians(form.trim.value()) L = self.ship.Length draftAP = form.draft.value() + 0.5 * L * math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = form.draft.value() - 0.5 * L * math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate the involved hydrostatics data = Hydrostatics.displacement(self.ship, form.draft.value(), 0.0, form.trim.value()) # Setup the html string string = "L = {0} [m]<BR>".format(self.ship.Length) string = string + "B = {0} [m]<BR>".format(self.ship.Breadth) string = string + "T = {0} [m]<HR>".format(form.draft.value()) string = string + "Trim = {0} [degrees]<BR>".format(form.trim.value()) string = string + "T<sub>AP</sub> = {0} [m]<BR>".format(draftAP) string = string + "T<sub>FP</sub> = {0} [m]<HR>".format(draftFP) 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) form.output.setHtml(string)
def accept(self): if not self.ship: return False self.save() # Plot data data = Hydrostatics.displacement(self.ship,self.form.draft.value(),0.0,self.form.trim.value()) disp = data[0] xcb = data[1].x data = Hydrostatics.areas(self.ship,self.form.draft.value(),0.0,self.form.trim.value()) x = [] y = [] for i in range(0,len(data)): x.append(data[i][0]) y.append(data[i][1]) PlotAux.Plot(x,y,disp,xcb, self.ship) self.preview.clean() return True
def accept(self): if not self.ship: return False self.save() # Plot data data = Hydrostatics.displacement(self.ship,self.form.draft.value(),0.0,self.form.trim.value()) disp = data[0] xcb = data[1].x data = Hydrostatics.areas(self.ship,self.form.draft.value(),0.0,self.form.trim.value()) x = [] y = [] for i in range(0,len(data)): x.append(data[i][0]) y.append(data[i][1]) Plot.Plot(x,y,disp,xcb, self.ship) self.preview.clean() return True
def onAutoTrim(self): """ Called when trim angle must be auto computed. """ # Start at null trim angle trim = 0.0 # Get center of gravity disp = self.computeDisplacement(trim) G = [disp[1], disp[2], disp[3]] disp = disp[0] # Get bouyancy center draft = self.computeDraft(disp) xcb = draft[1] draft = draft[0] KBT = Hydrostatics.KBT(self.ship, draft, trim) B = [xcb, KBT[0], KBT[1]] # Get stability initial condition BG = [G[0]-B[0], G[1]-B[1], G[2]-B[2]] x = BG[0]*math.cos(math.radians(trim)) - BG[2]*math.sin(math.radians(trim)) y = BG[1] z = BG[0]*math.sin(math.radians(trim)) + BG[2]*math.cos(math.radians(trim)) var = math.degrees(math.atan2(x,z)) # Iterate looking stability point dVar = math.copysign(0.0033, var) while True: if (dVar*math.copysign(dVar, var) < 0.0): break trim = trim - math.copysign(dVar, var) # Get center of gravity disp = self.computeDisplacement(trim) G = [disp[1], disp[2], disp[3]] disp = disp[0] # Get bouyancy center draft = self.computeDraft(disp, trim) xcb = draft[1] draft = draft[0] KBT = Hydrostatics.KBT(self.ship, draft, trim) B = [xcb, KBT[0], KBT[1]] # Get stability initial condition BG = [G[0]-B[0], G[1]-B[1], G[2]-B[2]] x = BG[0]*math.cos(math.radians(trim)) - BG[2]*math.sin(math.radians(trim)) y = BG[1] z = BG[0]*math.sin(math.radians(trim)) + BG[2]*math.cos(math.radians(trim)) var = math.degrees(math.atan2(x,z)) self.form.trim.setValue(trim)
def weights(obj): """ Returns Ship weights list. If weights has not been sets, this tool creates it. @param obj Ship object @return Weights list. None if errors """ # Test if is a ship instance props = obj.PropertiesList try: props.index("IsShip") except ValueError: return None if not obj.IsShip: return None # Test if properties already exist try: props.index("WeightNames") except ValueError: tooltip = str(QtGui.QApplication.translate("Ship","Ship Weights names",None,QtGui.QApplication.UnicodeUTF8)) lighweight = str(QtGui.QApplication.translate("Ship","Lightweight",None,QtGui.QApplication.UnicodeUTF8)) obj.addProperty("App::PropertyStringList","WeightNames","Ship", tooltip).WeightNames=[lighweight] try: props.index("WeightMass") except ValueError: # Compute mass aproximation from shipHydrostatics import Tools disp = Tools.displacement(obj,obj.Draft) tooltip = str(QtGui.QApplication.translate("Ship","Ship Weights masses",None,QtGui.QApplication.UnicodeUTF8)) obj.addProperty("App::PropertyFloatList","WeightMass","Ship", tooltip).WeightMass=[1000.0 * disp[0]] try: props.index("WeightPos") except ValueError: # Compute mass aproximation from shipHydrostatics import Tools disp = Tools.displacement(obj,obj.Draft) tooltip = str(QtGui.QApplication.translate("Ship","Ship Weights centers of gravity",None,QtGui.QApplication.UnicodeUTF8)) obj.addProperty("App::PropertyVectorList","WeightPos","Ship", tooltip).WeightPos=[Vector(disp[1].x,0.0,obj.Draft)] # Setup list weights = [] for i in range(0,len(obj.WeightNames)): weights.append([obj.WeightNames[i], obj.WeightMass[i], obj.WeightPos[i]]) return weights
def accept(self): if not self.ship: return False self.save() # Plot data data = Hydrostatics.Displacement(self.ship, self.form.draft.value(), self.form.trim.value()) x = self.ship.xSection[:] y = data[0] disp = data[1] xcb = data[2] Plot.Plot(x, y, disp, xcb, self.ship) self.preview.clean() return True
def onUpdate(self): """ Method called when the data update is requested. """ if not self.ship: return mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QLineEdit, "Draft") 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 # Calculate the drafts at each perpendicular angle = math.radians(trim) L = self.ship.Length.getValueAs('m').Value B = self.ship.Breadth.getValueAs('m').Value draftAP = draft + 0.5 * L * math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = draft - 0.5 * L * math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate the involved hydrostatics data = Hydrostatics.displacement(self.ship, draft, 0.0, trim) # 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) 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) form.output.setHtml(string)
def onUpdate(self): """ Method called when the data update is requested. """ if not self.ship: return mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QLineEdit, "Draft") form.trim = self.widget(QtGui.QLineEdit, "Trim") form.output = self.widget(QtGui.QTextEdit, "OutputData") draft = Units.parseQuantity(Locale.fromString(form.draft.text())) trim = Units.parseQuantity(Locale.fromString(form.trim.text())) # Calculate the drafts at each perpendicular angle = trim.getValueAs("rad").Value L = self.ship.Length.getValueAs('m').Value B = self.ship.Breadth.getValueAs('m').Value draftAP = draft + 0.5 * self.ship.Length * math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = draft - 0.5 * self.ship.Length * math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate the involved hydrostatics disp, B, _ = Hydrostatics.displacement(self.ship, draft, Units.parseQuantity("0 deg"), trim) xcb = Units.Quantity(B.x, Units.Length) # Setup the html string 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 += dispText + u' = {0}<BR>'.format(disp.UserString) string += u'XCB = {0}'.format(xcb.UserString) form.output.setHtml(string)
def computeGZ(self, draft, trim, roll): """ Compute GZ value. @param draft Ship draft. @param trim Ship trim angle [degrees]. @param roll Ship roll angle [degrees]. @return GZ value [m]. """ # Get center of gravity (x coordinate not relevant) disp = self.computeDisplacement(trim, roll) G = [disp[2], disp[3]] disp = disp[0] # Get bouyancy center (x coordinate not relevant) KBT = Hydrostatics.KBT(self.ship, draft, trim, roll) B = [KBT[0], KBT[1]] # GZ computation BG = [G[0] - B[0], G[1] - B[1]] y = BG[0]*math.cos(math.radians(-roll)) - BG[1]*math.sin(math.radians(-roll)) z = BG[0]*math.sin(math.radians(-roll)) + BG[1]*math.cos(math.radians(-roll)) return -y
def computeGZ(self, draft, trim, roll): """ Compute GZ value. @param draft Ship draft. @param trim Ship trim angle [degrees]. @param roll Ship roll angle [degrees]. @return GZ value [m]. """ # Get center of gravity (x coordinate not relevant) disp = self.computeDisplacement(trim, roll) G = [disp[2], disp[3]] disp = disp[0] # Get bouyancy center (x coordinate not relevant) disp = Hydrostatics.displacement(self.ship, draft, roll, trim, 0.0) B = [disp[1].y, disp[1].z] # GZ computation BG = [G[0] - B[0], G[1] - B[1]] y = BG[0] * math.cos(math.radians(roll)) - BG[1] * math.sin(math.radians(roll)) z = BG[0] * math.sin(math.radians(roll)) + BG[1] * math.cos(math.radians(roll)) return y
def onUpdate(self): """ Method called when the data update is requested. """ if not self.ship: return mw = self.getMainWindow() form = mw.findChild(QtGui.QWidget, "TaskPanel") form.draft = self.widget(QtGui.QLineEdit, "Draft") form.trim = self.widget(QtGui.QLineEdit, "Trim") form.output = self.widget(QtGui.QTextEdit, "OutputData") draft = Units.parseQuantity(Locale.fromString(form.draft.text())) trim = Units.parseQuantity(Locale.fromString(form.trim.text())) # Calculate the drafts at each perpendicular angle = trim.getValueAs("rad").Value L = self.ship.Length.getValueAs('m').Value B = self.ship.Breadth.getValueAs('m').Value draftAP = draft + 0.5 * self.ship.Length * math.tan(angle) if draftAP < 0.0: draftAP = 0.0 draftFP = draft - 0.5 * self.ship.Length * math.tan(angle) if draftFP < 0.0: draftFP = 0.0 # Calculate the involved hydrostatics disp, B, _ = Hydrostatics.displacement(self.ship, draft, Units.parseQuantity("0 deg"), trim) xcb = Units.Quantity(B.x, Units.Length) # Setup the html string 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 += dispText + u' = {0}<BR>'.format(disp.UserString) string += u'XCB = {0}'.format(xcb.UserString) form.output.setHtml(string)
def computeDraft(self, disp, trim=0.0): """ Computes ship draft. @param disp Ship displacement. @param trim Trim angle [degrees]. @return Ship draft, and bouyance center position. None if errors detected. """ if not self.ship: return None # Initial condition dens = 1025 bbox = self.ship.Shape.BoundBox draft = bbox.ZMin dx = bbox.XMax - bbox.XMin dy = bbox.YMax - bbox.YMin w = 0.0 xcb = 0.0 while (abs(disp - w) / disp > 0.01): draft = draft + (disp - w) / (dens * dx * dy) ww = Hydrostatics.displacement(self.ship, draft, 0.0, trim, 0.0) w = 1000.0 * ww[0] B = ww[1] return [draft, B]
def computeDraft(self, disp, trim=0.0): """ Computes ship draft. @param disp Ship displacement. @param trim Trim angle [degrees]. @return Ship draft, and bouyance center position. None if errors detected. """ if not self.ship: return None # Initial condition dens = 1025 bbox = self.ship.Shape.BoundBox draft = bbox.ZMin dx = bbox.XMax - bbox.XMin dy = bbox.YMax - bbox.YMin w = 0.0 xcb = 0.0 while abs(disp - w) / disp > 0.01: draft = draft + (disp - w) / (dens * dx * dy) ww = Hydrostatics.displacement(self.ship, draft, 0.0, trim, 0.0) w = 1000.0 * ww[0] B = ww[1] return [draft, B]
def solve_point(W, COG, TW, VOLS, ship, tanks, roll, var_trim=True): """ Compute the ship GZ value. @param W Empty ship weight. @param COG Empty ship Center of mass. @param TW Tanks weights. @param VOLS List of tank volumes. @param tanks Considered tanks. @param roll Roll angle. @param var_trim True if the trim angle should be recomputed at each roll angle, False otherwise. @return GZ value, equilibrium draft, and equilibrium trim angle (0 if variable trim has not been requested) """ # Look for the equilibrium draft (and eventually the trim angle too) max_draft = Units.Quantity(ship.Shape.BoundBox.ZMax, Units.Length) draft = ship.Draft max_disp = Units.Quantity(ship.Shape.Volume, Units.Volume) * DENS * G if max_disp < W + TW: msg = QtGui.QApplication.translate( "ship_console", "Too much weight! The ship will never displace water enough", None) App.Console.PrintError(msg + ' ({} vs. {})\n'.format( (max_disp / G).UserString, ((W + TW) / G).UserString)) return None trim = Units.parseQuantity("0 deg") for i in range(MAX_EQUILIBRIUM_ITERS): # Get the displacement, and the bouyance application point disp, B, _ = Hydrostatics.displacement(ship, draft, roll, trim) disp *= G # Add the tanks effect on the center of gravity mom_x = Units.Quantity(COG.x, Units.Length) * W mom_y = Units.Quantity(COG.y, Units.Length) * W mom_z = Units.Quantity(COG.z, Units.Length) * W for i, t in enumerate(tanks): tank_weight = VOLS[i] * t[1] * G tank_cog = t[0].Proxy.getCoG(t[0], VOLS[i], roll, trim) mom_x += Units.Quantity(tank_cog.x, Units.Length) * tank_weight mom_y += Units.Quantity(tank_cog.y, Units.Length) * tank_weight mom_z += Units.Quantity(tank_cog.z, Units.Length) * tank_weight cog_x = mom_x / (W + TW) cog_y = mom_y / (W + TW) cog_z = mom_z / (W + TW) # Compute the errors draft_error = -((disp - W - TW) / max_disp).Value R_x = cog_x - Units.Quantity(B.x, Units.Length) R_y = cog_y - Units.Quantity(B.y, Units.Length) R_z = cog_z - Units.Quantity(B.z, Units.Length) if not var_trim: trim_error = 0.0 else: trim_error = -TRIM_RELAX_FACTOR * R_x / ship.Length # Check if we can tolerate the errors if abs(draft_error) < 0.01 and abs(trim_error) < 0.1: break # Get the new draft and trim draft += draft_error * max_draft trim += trim_error * Units.Degree # GZ should be provided in the Free surface oriented frame of reference c = math.cos(roll.getValueAs('rad')) s = math.sin(roll.getValueAs('rad')) return c * R_y - s * R_z, draft, trim
def solve_point(W, COG, TW, VOLS, ship, tanks, roll, var_trim=True): """ Compute the ship GZ value. @param W Empty ship weight. @param COG Empty ship Center of mass. @param TW Tanks weights. @param VOLS List of tank volumes. @param tanks Considered tanks. @param roll Roll angle. @param var_trim True if the trim angle should be recomputed at each roll angle, False otherwise. @return GZ value, equilibrium draft, and equilibrium trim angle (0 if variable trim has not been requested) """ # Look for the equilibrium draft (and eventually the trim angle too) max_draft = Units.Quantity(ship.Shape.BoundBox.ZMax, Units.Length) draft = ship.Draft max_disp = Units.Quantity(ship.Shape.Volume, Units.Volume) * DENS * G if max_disp < W + TW: msg = QtGui.QApplication.translate( "ship_console", "Too much weight! The ship will never displace water enough", None) App.Console.PrintError(msg + ' ({} vs. {})\n'.format( (max_disp / G).UserString, ((W + TW) / G).UserString)) return None trim = Units.parseQuantity("0 deg") for i in range(MAX_EQUILIBRIUM_ITERS): # Get the displacement, and the bouyance application point disp, B, _ = Hydrostatics.displacement(ship, draft, roll, trim) disp *= G # Add the tanks effect on the center of gravity mom_x = Units.Quantity(COG.x, Units.Length) * W mom_y = Units.Quantity(COG.y, Units.Length) * W mom_z = Units.Quantity(COG.z, Units.Length) * W for i,t in enumerate(tanks): tank_weight = VOLS[i] * t[1] * G tank_cog = t[0].Proxy.getCoG(t[0], VOLS[i], roll, trim) mom_x += Units.Quantity(tank_cog.x, Units.Length) * tank_weight mom_y += Units.Quantity(tank_cog.y, Units.Length) * tank_weight mom_z += Units.Quantity(tank_cog.z, Units.Length) * tank_weight cog_x = mom_x / (W + TW) cog_y = mom_y / (W + TW) cog_z = mom_z / (W + TW) # Compute the errors draft_error = -((disp - W - TW) / max_disp).Value R_x = cog_x - Units.Quantity(B.x, Units.Length) R_y = cog_y - Units.Quantity(B.y, Units.Length) R_z = cog_z - Units.Quantity(B.z, Units.Length) if not var_trim: trim_error = 0.0 else: trim_error = -TRIM_RELAX_FACTOR * R_x / ship.Length # Check if we can tolerate the errors if abs(draft_error) < 0.01 and abs(trim_error) < 0.1: break # Get the new draft and trim draft += draft_error * max_draft trim += trim_error * Units.Degree # GZ should be provided in the Free surface oriented frame of reference c = math.cos(roll.getValueAs('rad')) s = math.sin(roll.getValueAs('rad')) return c * R_y - s * R_z, draft, trim