First simulator draft version.
This commit is contained in:
parent
01e0eb33ed
commit
5bdbf47ccc
|
@ -45,6 +45,8 @@ SET(ShipIcons_SRCS
|
|||
Icons/SimRunIco.xpm
|
||||
Icons/SimStopIco.png
|
||||
Icons/SimStopIco.xpm
|
||||
Icons/SimPostIco.png
|
||||
Icons/SimPostIco.xpm
|
||||
Icons/Tank.png
|
||||
Icons/Tank.xcf
|
||||
Icons/Tank.xpm
|
||||
|
@ -156,7 +158,14 @@ SET(SimRun_SRCS
|
|||
)
|
||||
SOURCE_GROUP("simrun" FILES ${SimRun_SRCS})
|
||||
|
||||
SET(all_files ${ShipMain_SRCS} ${ShipIcons_SRCS} ${ShipExamples_SRCS} ${ShipLoadExample_SRCS} ${ShipCreateShip_SRCS} ${ShipOutlineDraw_SRCS} ${ShipAreasCurve_SRCS} ${ShipHydrostatics_SRCS} ${ShipUtils_SRCS} ${ShipWeights_SRCS} ${ShipCreateTank_SRCS} ${ShipGZ_SRCS} ${SimCreate_SRCS} ${SimRun_SRCS})
|
||||
SET(SimPost_SRCS
|
||||
simPost/__init__.py
|
||||
simPost/TaskPanel.py
|
||||
simPost/TaskPanel.ui
|
||||
)
|
||||
SOURCE_GROUP("simpost" FILES ${SimPost_SRCS})
|
||||
|
||||
SET(all_files ${ShipMain_SRCS} ${ShipIcons_SRCS} ${ShipExamples_SRCS} ${ShipLoadExample_SRCS} ${ShipCreateShip_SRCS} ${ShipOutlineDraw_SRCS} ${ShipAreasCurve_SRCS} ${ShipHydrostatics_SRCS} ${ShipUtils_SRCS} ${ShipWeights_SRCS} ${ShipCreateTank_SRCS} ${ShipGZ_SRCS} ${SimCreate_SRCS} ${SimRun_SRCS} ${SimPost_SRCS})
|
||||
|
||||
ADD_CUSTOM_TARGET(Ship ALL
|
||||
SOURCES ${all_files}
|
||||
|
@ -242,6 +251,12 @@ INSTALL(
|
|||
DESTINATION
|
||||
Mod/Ship/simRun
|
||||
)
|
||||
INSTALL(
|
||||
FILES
|
||||
${SimPost_SRCS}
|
||||
DESTINATION
|
||||
Mod/Ship/simPost
|
||||
)
|
||||
INSTALL(
|
||||
FILES
|
||||
${ShipMain_SRCS}
|
||||
|
|
Binary file not shown.
BIN
src/Mod/Ship/Icons/SimPostIco.png
Normal file
BIN
src/Mod/Ship/Icons/SimPostIco.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
2077
src/Mod/Ship/Icons/SimPostIco.xpm
Normal file
2077
src/Mod/Ship/Icons/SimPostIco.xpm
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -1,68 +1,68 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
class ShipWorkbench ( Workbench ):
|
||||
""" @brief Workbench of Ship design module. Here toolbars & icons are append. """
|
||||
from shipUtils import Paths, Translator
|
||||
import ShipGui
|
||||
|
||||
Icon = Paths.iconsPath() + "/Ico.png"
|
||||
MenuText = str(Translator.translate("Ship design"))
|
||||
ToolTip = str(Translator.translate("Ship design"))
|
||||
|
||||
def Initialize(self):
|
||||
from shipUtils import Translator
|
||||
# ToolBar
|
||||
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
|
||||
self.appendToolbar("Ship design",list)
|
||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||
self.appendToolbar("Weights",list)
|
||||
# Simulation stuff only if pyOpenCL & numpy are present
|
||||
hasOpenCL = True
|
||||
hasNumpy = True
|
||||
try:
|
||||
import pyopencl
|
||||
except ImportError:
|
||||
hasOpenCL = False
|
||||
msg = Translator.translate("pyOpenCL not installed, ship simulations disabled\n")
|
||||
App.Console.PrintWarning(msg)
|
||||
try:
|
||||
import numpy
|
||||
except ImportError:
|
||||
hasNumpy = False
|
||||
msg = Translator.translate("numpy not installed, ship simulations disabled\n")
|
||||
App.Console.PrintWarning(msg)
|
||||
if hasOpenCL and hasNumpy:
|
||||
list = ["Ship_CreateSim", "Ship_RunSim", "Ship_StopSim"]
|
||||
self.appendToolbar("Simulation",list)
|
||||
|
||||
# Menu
|
||||
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
|
||||
self.appendMenu("Ship design",list)
|
||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||
self.appendMenu("Weights",list)
|
||||
if hasOpenCL and hasNumpy:
|
||||
list = ["Ship_CreateSim", "Ship_RunSim", "Ship_StopSim"]
|
||||
self.appendMenu("Simulation",list)
|
||||
|
||||
Gui.addWorkbench(ShipWorkbench())
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
class ShipWorkbench ( Workbench ):
|
||||
""" @brief Workbench of Ship design module. Here toolbars & icons are append. """
|
||||
from shipUtils import Paths, Translator
|
||||
import ShipGui
|
||||
|
||||
Icon = Paths.iconsPath() + "/Ico.png"
|
||||
MenuText = str(Translator.translate("Ship design"))
|
||||
ToolTip = str(Translator.translate("Ship design"))
|
||||
|
||||
def Initialize(self):
|
||||
from shipUtils import Translator
|
||||
# ToolBar
|
||||
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
|
||||
self.appendToolbar("Ship design",list)
|
||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||
self.appendToolbar("Weights",list)
|
||||
# Simulation stuff only if pyOpenCL & numpy are present
|
||||
hasOpenCL = True
|
||||
hasNumpy = True
|
||||
try:
|
||||
import pyopencl
|
||||
except ImportError:
|
||||
hasOpenCL = False
|
||||
msg = Translator.translate("pyOpenCL not installed, ship simulations disabled\n")
|
||||
App.Console.PrintWarning(msg)
|
||||
try:
|
||||
import numpy
|
||||
except ImportError:
|
||||
hasNumpy = False
|
||||
msg = Translator.translate("numpy not installed, ship simulations disabled\n")
|
||||
App.Console.PrintWarning(msg)
|
||||
if hasOpenCL and hasNumpy:
|
||||
list = ["Ship_CreateSim", "Ship_RunSim", "Ship_StopSim", "Ship_TrackSim"]
|
||||
self.appendToolbar("Simulation",list)
|
||||
|
||||
# Menu
|
||||
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
|
||||
self.appendMenu("Ship design",list)
|
||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||
self.appendMenu("Weights",list)
|
||||
if hasOpenCL and hasNumpy:
|
||||
list = ["Ship_CreateSim", "Ship_RunSim", "Ship_StopSim", "Ship_TrackSim"]
|
||||
self.appendMenu("Simulation",list)
|
||||
|
||||
Gui.addWorkbench(ShipWorkbench())
|
||||
|
|
|
@ -46,6 +46,8 @@ nobase_data_DATA = \
|
|||
Icons/SimRunIco.xpm \
|
||||
Icons/SimStopIco.png \
|
||||
Icons/SimStopIco.xpm \
|
||||
Icons/SimPostIco.png \
|
||||
Icons/SimPostIco.xpm \
|
||||
Icons/Tank.png \
|
||||
Icons/Tank.xcf \
|
||||
Icons/Tank.xpm \
|
||||
|
@ -105,7 +107,10 @@ nobase_data_DATA = \
|
|||
simRun/Sim/initialization.py \
|
||||
simRun/Sim/matrixGen.py \
|
||||
simRun/Sim/computeSources.py \
|
||||
simRun/Sim/fsEvolution.py
|
||||
simRun/Sim/fsEvolution.py \
|
||||
simPost/__init__.py \
|
||||
simPost/TaskPanel.py \
|
||||
simPost/TaskPanel.ui
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
|
|
|
@ -1,169 +1,183 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
import FreeCAD, FreeCADGui, os
|
||||
|
||||
class LoadExample:
|
||||
def Activated(self):
|
||||
import shipLoadExample
|
||||
shipLoadExample.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/LoadIco.png"
|
||||
MenuText = str(Translator.translate('Load an example ship geometry'))
|
||||
ToolTip = str(Translator.translate('Load an example ship geometry able to be converted into a ship.'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class CreateShip:
|
||||
def Activated(self):
|
||||
import shipCreateShip
|
||||
shipCreateShip.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/Ico.png"
|
||||
MenuText = str(Translator.translate('Create a new ship'))
|
||||
ToolTip = str(Translator.translate('Create a new ship in order to work with them'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class OutlineDraw:
|
||||
def Activated(self):
|
||||
import shipOutlineDraw
|
||||
shipOutlineDraw.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/OutlineDrawIco.png"
|
||||
MenuText = str(Translator.translate('Outline draw'))
|
||||
ToolTip = str(Translator.translate('Plot ship outline draw'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class AreasCurve:
|
||||
def Activated(self):
|
||||
import shipAreasCurve
|
||||
shipAreasCurve.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/AreaCurveIco.png"
|
||||
MenuText = str(Translator.translate('Areas curve'))
|
||||
ToolTip = str(Translator.translate('Plot transversal areas curve'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class Hydrostatics:
|
||||
def Activated(self):
|
||||
import shipHydrostatics
|
||||
shipHydrostatics.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/HydrostaticsIco.png"
|
||||
MenuText = str(Translator.translate('Hydrostatics'))
|
||||
ToolTip = str(Translator.translate('Plot ship hydrostatics'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class SetWeights:
|
||||
def Activated(self):
|
||||
import tankWeights
|
||||
tankWeights.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/Weight.png"
|
||||
MenuText = str(Translator.translate('Set ship weights'))
|
||||
ToolTip = str(Translator.translate('Set ship weights, tanks must be added later'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class CreateTank:
|
||||
def Activated(self):
|
||||
import tankCreateTank
|
||||
tankCreateTank.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/Tank.png"
|
||||
MenuText = str(Translator.translate('Create a new tank'))
|
||||
ToolTip = str(Translator.translate('Create a new ship tank'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class GZ:
|
||||
def Activated(self):
|
||||
import tankGZ
|
||||
tankGZ.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/HydrostaticsIco.png"
|
||||
MenuText = str(Translator.translate('GZ curve'))
|
||||
ToolTip = str(Translator.translate('Transversal stability GZ curve computation'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class CreateSim:
|
||||
def Activated(self):
|
||||
import simCreate
|
||||
simCreate.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/SimCreateIco.png"
|
||||
MenuText = str(Translator.translate('Create a new simulation'))
|
||||
ToolTip = str(Translator.translate('Create a new simulation in order to process later'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class RunSim:
|
||||
def Activated(self):
|
||||
import simRun
|
||||
simRun.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/SimRunIco.png"
|
||||
MenuText = str(Translator.translate('Run a simulation'))
|
||||
ToolTip = str(Translator.translate('Run a simulation'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class StopSim:
|
||||
def Activated(self):
|
||||
import simRun
|
||||
simRun.stop()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/SimStopIco.png"
|
||||
MenuText = str(Translator.translate('Stop active simulation'))
|
||||
ToolTip = str(Translator.translate('Stop active simulation'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
FreeCADGui.addCommand('Ship_LoadExample', LoadExample())
|
||||
FreeCADGui.addCommand('Ship_CreateShip', CreateShip())
|
||||
FreeCADGui.addCommand('Ship_OutlineDraw', OutlineDraw())
|
||||
FreeCADGui.addCommand('Ship_AreasCurve', AreasCurve())
|
||||
FreeCADGui.addCommand('Ship_Hydrostatics', Hydrostatics())
|
||||
FreeCADGui.addCommand('Ship_Weights', SetWeights())
|
||||
FreeCADGui.addCommand('Ship_CreateTank', CreateTank())
|
||||
FreeCADGui.addCommand('Ship_GZ', GZ())
|
||||
FreeCADGui.addCommand('Ship_CreateSim', CreateSim())
|
||||
FreeCADGui.addCommand('Ship_RunSim', RunSim())
|
||||
FreeCADGui.addCommand('Ship_StopSim', StopSim())
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
import FreeCAD, FreeCADGui, os
|
||||
|
||||
class LoadExample:
|
||||
def Activated(self):
|
||||
import shipLoadExample
|
||||
shipLoadExample.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/LoadIco.png"
|
||||
MenuText = str(Translator.translate('Load an example ship geometry'))
|
||||
ToolTip = str(Translator.translate('Load an example ship geometry able to be converted into a ship.'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class CreateShip:
|
||||
def Activated(self):
|
||||
import shipCreateShip
|
||||
shipCreateShip.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/Ico.png"
|
||||
MenuText = str(Translator.translate('Create a new ship'))
|
||||
ToolTip = str(Translator.translate('Create a new ship in order to work with them'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class OutlineDraw:
|
||||
def Activated(self):
|
||||
import shipOutlineDraw
|
||||
shipOutlineDraw.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/OutlineDrawIco.png"
|
||||
MenuText = str(Translator.translate('Outline draw'))
|
||||
ToolTip = str(Translator.translate('Plot ship outline draw'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class AreasCurve:
|
||||
def Activated(self):
|
||||
import shipAreasCurve
|
||||
shipAreasCurve.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/AreaCurveIco.png"
|
||||
MenuText = str(Translator.translate('Areas curve'))
|
||||
ToolTip = str(Translator.translate('Plot transversal areas curve'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class Hydrostatics:
|
||||
def Activated(self):
|
||||
import shipHydrostatics
|
||||
shipHydrostatics.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/HydrostaticsIco.png"
|
||||
MenuText = str(Translator.translate('Hydrostatics'))
|
||||
ToolTip = str(Translator.translate('Plot ship hydrostatics'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class SetWeights:
|
||||
def Activated(self):
|
||||
import tankWeights
|
||||
tankWeights.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/Weight.png"
|
||||
MenuText = str(Translator.translate('Set ship weights'))
|
||||
ToolTip = str(Translator.translate('Set ship weights, tanks must be added later'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class CreateTank:
|
||||
def Activated(self):
|
||||
import tankCreateTank
|
||||
tankCreateTank.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/Tank.png"
|
||||
MenuText = str(Translator.translate('Create a new tank'))
|
||||
ToolTip = str(Translator.translate('Create a new ship tank'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class GZ:
|
||||
def Activated(self):
|
||||
import tankGZ
|
||||
tankGZ.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/HydrostaticsIco.png"
|
||||
MenuText = str(Translator.translate('GZ curve'))
|
||||
ToolTip = str(Translator.translate('Transversal stability GZ curve computation'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class CreateSim:
|
||||
def Activated(self):
|
||||
import simCreate
|
||||
simCreate.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/SimCreateIco.png"
|
||||
MenuText = str(Translator.translate('Create a new simulation'))
|
||||
ToolTip = str(Translator.translate('Create a new simulation in order to process later'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class RunSim:
|
||||
def Activated(self):
|
||||
import simRun
|
||||
simRun.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/SimRunIco.png"
|
||||
MenuText = str(Translator.translate('Run a simulation'))
|
||||
ToolTip = str(Translator.translate('Run a simulation'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class StopSim:
|
||||
def Activated(self):
|
||||
import simRun
|
||||
simRun.stop()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/SimStopIco.png"
|
||||
MenuText = str(Translator.translate('Stop active simulation'))
|
||||
ToolTip = str(Translator.translate('Stop active simulation'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
class TrackSim:
|
||||
def Activated(self):
|
||||
import simPost
|
||||
simPost.load()
|
||||
|
||||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
IconPath = Paths.iconsPath() + "/SimPostIco.png"
|
||||
MenuText = str(Translator.translate('Track simulation'))
|
||||
ToolTip = str(Translator.translate('Track simulation'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
|
||||
FreeCADGui.addCommand('Ship_LoadExample', LoadExample())
|
||||
FreeCADGui.addCommand('Ship_CreateShip', CreateShip())
|
||||
FreeCADGui.addCommand('Ship_OutlineDraw', OutlineDraw())
|
||||
FreeCADGui.addCommand('Ship_AreasCurve', AreasCurve())
|
||||
FreeCADGui.addCommand('Ship_Hydrostatics', Hydrostatics())
|
||||
FreeCADGui.addCommand('Ship_Weights', SetWeights())
|
||||
FreeCADGui.addCommand('Ship_CreateTank', CreateTank())
|
||||
FreeCADGui.addCommand('Ship_GZ', GZ())
|
||||
FreeCADGui.addCommand('Ship_CreateSim', CreateSim())
|
||||
FreeCADGui.addCommand('Ship_RunSim', RunSim())
|
||||
FreeCADGui.addCommand('Ship_StopSim', StopSim())
|
||||
FreeCADGui.addCommand('Ship_TrackSim', TrackSim())
|
||||
|
|
156
src/Mod/Ship/simPost/TaskPanel.py
Normal file
156
src/Mod/Ship/simPost/TaskPanel.py
Normal file
|
@ -0,0 +1,156 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# FreeCAD modules
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
# Qt library
|
||||
from PyQt4 import QtGui,QtCore
|
||||
# pyOpenCL
|
||||
import pyopencl as cl
|
||||
# Module
|
||||
import SimInstance
|
||||
from shipUtils import Paths, Translator
|
||||
from simRun import Simulation
|
||||
Sim = Simulation.FreeCADShipSimulation
|
||||
# from Simulation import FreeCADShipSimulation as Sim
|
||||
|
||||
class TaskPanel:
|
||||
def __init__(self):
|
||||
self.ui = Paths.modulePath() + "/simPost/TaskPanel.ui"
|
||||
|
||||
def accept(self):
|
||||
return True
|
||||
|
||||
def reject(self):
|
||||
return True
|
||||
|
||||
def clicked(self, index):
|
||||
pass
|
||||
|
||||
def open(self):
|
||||
pass
|
||||
|
||||
def needsFullSpace(self):
|
||||
return True
|
||||
|
||||
def isAllowedAlterSelection(self):
|
||||
return False
|
||||
|
||||
def isAllowedAlterView(self):
|
||||
return True
|
||||
|
||||
def isAllowedAlterDocument(self):
|
||||
return False
|
||||
|
||||
def helpRequested(self):
|
||||
pass
|
||||
|
||||
def setupUi(self):
|
||||
mw = self.getMainWindow()
|
||||
form = mw.findChild(QtGui.QWidget, "TaskPanel")
|
||||
form.time = form.findChild(QtGui.QLabel, "TimeLabel")
|
||||
form.first = form.findChild(QtGui.QPushButton, "First")
|
||||
form.prev = form.findChild(QtGui.QPushButton, "Prev")
|
||||
form.now = form.findChild(QtGui.QPushButton, "Now")
|
||||
form.next = form.findChild(QtGui.QPushButton, "Next")
|
||||
form.last = form.findChild(QtGui.QPushButton, "Last")
|
||||
self.form = form
|
||||
# Initial values
|
||||
if self.initValues():
|
||||
return True
|
||||
self.retranslateUi()
|
||||
# Connect Signals and Slots
|
||||
QtCore.QObject.connect(form.first, QtCore.SIGNAL("pressed()"), self.onFirst)
|
||||
QtCore.QObject.connect(form.prev, QtCore.SIGNAL("pressed()"), self.onPrev)
|
||||
QtCore.QObject.connect(form.now, QtCore.SIGNAL("pressed()"), self.onNow)
|
||||
QtCore.QObject.connect(form.next, QtCore.SIGNAL("pressed()"), self.onNext)
|
||||
QtCore.QObject.connect(form.last, QtCore.SIGNAL("pressed()"), self.onLast)
|
||||
|
||||
def getMainWindow(self):
|
||||
"returns the main window"
|
||||
# using QtGui.qApp.activeWindow() isn't very reliable because if another
|
||||
# widget than the mainwindow is active (e.g. a dialog) the wrong widget is
|
||||
# returned
|
||||
toplevel = QtGui.qApp.topLevelWidgets()
|
||||
for i in toplevel:
|
||||
if i.metaObject().className() == "Gui::MainWindow":
|
||||
return i
|
||||
raise Exception("No main window found")
|
||||
|
||||
def initValues(self):
|
||||
""" Set initial values for fields
|
||||
"""
|
||||
msg = Translator.translate("Ready to work\n")
|
||||
App.Console.PrintMessage(msg)
|
||||
return False
|
||||
|
||||
def retranslateUi(self):
|
||||
""" Set user interface locale strings.
|
||||
"""
|
||||
self.form.setWindowTitle(Translator.translate("Track simulation"))
|
||||
self.form.findChild(QtGui.QPushButton, "Now").setText(Translator.translate("Now"))
|
||||
|
||||
def onFirst(self):
|
||||
""" Called when first frame button is pressed.
|
||||
"""
|
||||
|
||||
def onPrev(self):
|
||||
""" Called when previous frame button is pressed.
|
||||
"""
|
||||
|
||||
def onNow(self):
|
||||
""" Called when actual frame button is pressed.
|
||||
"""
|
||||
sim = Sim()
|
||||
pos = sim.sim.FS_Position[:]
|
||||
nx = sim.FS['Nx']
|
||||
ny = sim.FS['Ny']
|
||||
for i in range(0, nx):
|
||||
for j in range(0, ny):
|
||||
pos[i*ny+j].z = float(sim.FS['pos'][i,j][2])
|
||||
sim.sim.FS_Position = pos[:]
|
||||
App.ActiveDocument.recompute()
|
||||
self.form.time.setText("t = %g s" % (sim.t))
|
||||
|
||||
def onNext(self):
|
||||
""" Called when next frame button is pressed.
|
||||
"""
|
||||
|
||||
def onLast(self):
|
||||
""" Called when last frame button is pressed.
|
||||
"""
|
||||
|
||||
def createTask():
|
||||
try:
|
||||
simulator = Sim()
|
||||
except:
|
||||
msg = Translator.translate("Can't find any active simulation!\n")
|
||||
App.Console.PrintError(msg)
|
||||
return
|
||||
panel = TaskPanel()
|
||||
Gui.Control.showDialog(panel)
|
||||
if panel.setupUi():
|
||||
Gui.Control.closeDialog(panel)
|
||||
return None
|
||||
return panel
|
81
src/Mod/Ship/simPost/TaskPanel.ui
Normal file
81
src/Mod/Ship/simPost/TaskPanel.ui
Normal file
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TaskPanel</class>
|
||||
<widget class="QWidget" name="TaskPanel">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<height>102</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>1</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Track simulation</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QPushButton" name="First">
|
||||
<property name="text">
|
||||
<string>|<</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QPushButton" name="Prev">
|
||||
<property name="text">
|
||||
<string><</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QPushButton" name="Next">
|
||||
<property name="text">
|
||||
<string>></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="4">
|
||||
<widget class="QPushButton" name="Last">
|
||||
<property name="text">
|
||||
<string>>|</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QPushButton" name="Now">
|
||||
<property name="text">
|
||||
<string>Now</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" colspan="5">
|
||||
<widget class="QLabel" name="TimeLabel">
|
||||
<property name="text">
|
||||
<string>t = 0 s</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
40
src/Mod/Ship/simPost/__init__.py
Normal file
40
src/Mod/Ship/simPost/__init__.py
Normal file
|
@ -0,0 +1,40 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* This program is free software; you can redistribute it and/or modify *
|
||||
#* it under the terms of the GNU Lesser General Public License (LGPL) *
|
||||
#* as published by the Free Software Foundation; either version 2 of *
|
||||
#* the License, or (at your option) any later version. *
|
||||
#* for detail see the LICENCE text file. *
|
||||
#* *
|
||||
#* This program is distributed in the hope that it will be useful, *
|
||||
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
#* GNU Library General Public License for more details. *
|
||||
#* *
|
||||
#* You should have received a copy of the GNU Library General Public *
|
||||
#* License along with this program; if not, write to the Free Software *
|
||||
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# FreeCAD modules
|
||||
import FreeCAD
|
||||
import FreeCADGui
|
||||
|
||||
# Qt libraries
|
||||
from PyQt4 import QtGui,QtCore
|
||||
|
||||
# Main object
|
||||
import TaskPanel
|
||||
|
||||
def load():
|
||||
""" Loads the tool """
|
||||
TaskPanel.createTask()
|
||||
|
||||
def stop():
|
||||
""" Stops the simulation """
|
||||
TaskPanel.stopSimulation()
|
|
@ -57,24 +57,47 @@ class simFSEvolution:
|
|||
# Get value at pos using characteristics method
|
||||
gradVal = np.dot(np.abs(grad[i*ny+j]),grad[i*ny+j])
|
||||
gradVal = np.copysign(np.sqrt(np.abs(gradVal)), gradVal)
|
||||
self.fs['pos'][i,j][2] = self.fs['pos'][i,j][2] + \
|
||||
dt*np.linalg.norm(grad[i*ny+j])
|
||||
# Free surface points position
|
||||
self.fs['pos'][i,j][2] = self.fs['pos'][i,j][2] + dt*grad[i*ny+j][2]
|
||||
self.fs['pos'][i,j][2] = self.fs['pos'][i,j][2] + dt*gradVal
|
||||
# Velocity potential
|
||||
self.fs['velPot'][i,j] = self.fs['velPot'][i,j] + \
|
||||
dt*self.fs['accPot'][i,j] - \
|
||||
0.5*dt*dt*grav*grad[i*ny+j][2]
|
||||
# Acceleration potential
|
||||
self.fs['accPot'][i,j] = self.fs['accPot'][i,j] - \
|
||||
dt*grav*grad[i*ny+j][2]
|
||||
# Force boundary conditions
|
||||
dt*self.fs['accPot'][i,j] + \
|
||||
0.5*dt*dt*grav*self.fs['pos'][i,j][2]
|
||||
# Acceleration potential. This is really hard to simulate
|
||||
# accurately due to numerical diffusion of the function, so
|
||||
# external waves, and diffracted waves will be computed
|
||||
# in two different ways:
|
||||
# * External waves will be considered analitically,
|
||||
# substracting waves at t, and adding waves at t+dt
|
||||
# * Second order waves will be computed substracting external
|
||||
# waves to free surface height, and then imposing boundary
|
||||
# condition.
|
||||
pos = np.copy(self.fs['pos'][i,j])
|
||||
for w in waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
# Substract external waves height in order to know second
|
||||
# order waves free surface amplitude.
|
||||
amp = A*np.sin(k*l - frec*(t+dt) + phase)
|
||||
pos[2] = pos[2] - amp
|
||||
# Compute analitic external waves acceleration potential
|
||||
amp0 = grav*A*np.cos(k*l - frec*t + phase)
|
||||
amp1 = grav*A*np.cos(k*l - frec*(t+dt) + phase)
|
||||
self.fs['accPot'][i,j] = self.fs['accPot'][i,j] - amp0 + amp1
|
||||
# Now impose free surface boundary condition
|
||||
# self.fs['accPot'][i,j] = self.fs['accPot'][i,j] + grav*pos[2]
|
||||
# Impose values at beach (far free surface)
|
||||
for i in range(0,nx):
|
||||
for j in [0,ny-1]:
|
||||
self.boundaryCondition(i,j, waves, dt, t)
|
||||
self.beach(i,j, waves, dt, t)
|
||||
for j in range(0,ny):
|
||||
for i in [0,nx-1]:
|
||||
self.boundaryCondition(i,j, waves, dt, t)
|
||||
self.beach(i,j, waves, dt, t)
|
||||
|
||||
def evaluateGradient(self):
|
||||
""" Evaluate potential gradients over free surface.
|
||||
|
@ -84,10 +107,15 @@ class simFSEvolution:
|
|||
ny = self.fs['Ny']
|
||||
nF = nx*ny
|
||||
grad = np.ndarray((nF,3), dtype=np.float32)
|
||||
FF = open('gradient', 'w')
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
pos = self.fs['pos'][i,j]
|
||||
grad[i*ny+j] = self.gradientphi(pos)
|
||||
gradVal = np.dot(np.abs(grad[i*ny+j]),grad[i*ny+j])
|
||||
gradVal = np.copysign(np.sqrt(np.abs(gradVal)), gradVal)
|
||||
FF.write('%g\t%g\n' % (pos[1], gradVal))
|
||||
FF.close()
|
||||
return grad
|
||||
|
||||
def gradientphi(self, pos):
|
||||
|
@ -112,9 +140,9 @@ class simFSEvolution:
|
|||
grad[2] = 0.
|
||||
return grad
|
||||
|
||||
def boundaryCondition(self, i,j, waves, dt, t):
|
||||
""" Compute free surface at boundaries, assuming that only
|
||||
incident wave can be taken into account.
|
||||
def beach(self, i,j, waves, dt, t):
|
||||
""" Compute far free surface where only
|
||||
incident waves can be taken into account.
|
||||
@param i First free surface cell index.
|
||||
@param j Second free surface cell index.
|
||||
@param waves Waves instance.
|
||||
|
@ -133,7 +161,6 @@ class simFSEvolution:
|
|||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
pos = self.fs['pos'][i,j]
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
amp = A*np.sin(k*l - frec*(t+dt) + phase)
|
||||
self.fs['pos'][i,j][2] = self.fs['pos'][i,j][2] + amp
|
||||
|
|
BIN
src/Mod/Ship/simRun/Sim/fsEvolution.pyc
Normal file
BIN
src/Mod/Ship/simRun/Sim/fsEvolution.pyc
Normal file
Binary file not shown.
|
@ -94,12 +94,14 @@ class FreeCADShipSimulation(threading.Thread):
|
|||
FS = init.fs
|
||||
waves = init.waves
|
||||
dt = init.dt
|
||||
t = 0.0
|
||||
self.t = 0.0
|
||||
self.FS = FS
|
||||
nx = FS['Nx']
|
||||
ny = FS['Ny']
|
||||
msg = Translator.translate("\t[Sim]: Iterating...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
while self.active and t < self.endTime:
|
||||
count = 0
|
||||
while self.active and self.t < self.endTime:
|
||||
msg = Translator.translate("\t\t[Sim]: Generating linear system matrix...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
matGen.execute(FS, A)
|
||||
|
@ -108,18 +110,16 @@ class FreeCADShipSimulation(threading.Thread):
|
|||
solver.execute(FS, A)
|
||||
msg = Translator.translate("\t\t[Sim]: Time integrating...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
fsEvol.execute(FS, waves, dt, t)
|
||||
t = t + dt
|
||||
FreeCAD.Console.PrintMessage('t = %g s\n' % (t))
|
||||
# Update FreeCAD
|
||||
"""
|
||||
pos = self.sim.FS_Position[:]
|
||||
for i in range(0, nx):
|
||||
for j in range(0, ny):
|
||||
pos[i*ny+j].z = float(FS['pos'][i,j][2])
|
||||
self.sim.FS_Position = pos[:]
|
||||
FreeCAD.ActiveDocument.recompute()
|
||||
"""
|
||||
fsEvol.execute(FS, waves, dt, self.t)
|
||||
self.t = self.t + dt
|
||||
FreeCAD.Console.PrintMessage('t = %g s\n' % (self.t))
|
||||
count = count+1
|
||||
FF = open('%d' % (count), 'w')
|
||||
i=1
|
||||
for j in range(0,ny):
|
||||
FF.write("%g\t%g\t%g\t%g\n" % (FS['pos'][i,j,1], FS['pos'][i,j,2],
|
||||
FS['velPot'][i,j], FS['accPot'][i,j]))
|
||||
FF.close()
|
||||
# Set thread as stopped (and prepare it to restarting)
|
||||
self.active = False
|
||||
threading.Event().set()
|
||||
|
|
BIN
src/Mod/Ship/simRun/Simulation.pyc
Normal file
BIN
src/Mod/Ship/simRun/Simulation.pyc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user