Imported pyOpenCL library
This commit is contained in:
parent
6aef063c3c
commit
a455cf6fa8
|
@ -36,15 +36,26 @@ class ShipWorkbench ( Workbench ):
|
||||||
self.appendToolbar("Ship design",list)
|
self.appendToolbar("Ship design",list)
|
||||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||||
self.appendToolbar("Weights",list)
|
self.appendToolbar("Weights",list)
|
||||||
list = ["Ship_CreateSim", "Ship_RunSim"]
|
try:
|
||||||
self.appendToolbar("Simulation",list)
|
import pyopencl
|
||||||
|
except ImportError:
|
||||||
|
msg = Translator.translate("pyOpenCL not installed, ship simulations disabled\n")
|
||||||
|
App.Console.PrintWarning(msg)
|
||||||
|
else:
|
||||||
|
list = ["Ship_CreateSim", "Ship_RunSim"]
|
||||||
|
self.appendToolbar("Simulation",list)
|
||||||
|
|
||||||
# Menu
|
# Menu
|
||||||
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
|
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
|
||||||
self.appendMenu("Ship design",list)
|
self.appendMenu("Ship design",list)
|
||||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||||
self.appendToolbar("Weights",list)
|
self.appendToolbar("Weights",list)
|
||||||
list = ["Ship_CreateSim", "Ship_RunSim"]
|
try:
|
||||||
self.appendToolbar("Simulation",list)
|
import pyopencl
|
||||||
|
except ImportError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
list = ["Ship_CreateSim", "Ship_RunSim"]
|
||||||
|
self.appendToolbar("Simulation",list)
|
||||||
|
|
||||||
Gui.addWorkbench(ShipWorkbench())
|
Gui.addWorkbench(ShipWorkbench())
|
||||||
|
|
|
@ -140,7 +140,7 @@ class RunSim:
|
||||||
def GetResources(self):
|
def GetResources(self):
|
||||||
from shipUtils import Paths, Translator
|
from shipUtils import Paths, Translator
|
||||||
IconPath = Paths.iconsPath() + "/SimRunIco.png"
|
IconPath = Paths.iconsPath() + "/SimRunIco.png"
|
||||||
MenuText = str(Translator.translate('Run a simulation'))
|
MenuText = str(Translator.translate('Run a simulation'))
|
||||||
ToolTip = str(Translator.translate('Run a simulation'))
|
ToolTip = str(Translator.translate('Run a simulation'))
|
||||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@ import time
|
||||||
from math import *
|
from math import *
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
# pyOpenCL
|
||||||
|
import pyopencl as cl
|
||||||
|
|
||||||
# FreeCAD
|
# FreeCAD
|
||||||
import FreeCAD,FreeCADGui
|
import FreeCAD,FreeCADGui
|
||||||
from FreeCAD import Part, Base, Vector
|
from FreeCAD import Part, Base, Vector
|
||||||
|
@ -33,14 +36,20 @@ from FreeCAD import Part, Base, Vector
|
||||||
from shipUtils import Paths, Translator, Math
|
from shipUtils import Paths, Translator, Math
|
||||||
|
|
||||||
class FreeCADShipSimulation(threading.Thread):
|
class FreeCADShipSimulation(threading.Thread):
|
||||||
def __init__ (self, endTime, output, FSmesh, waves):
|
def __init__ (self, device, endTime, output, FSmesh, waves):
|
||||||
""" Thread constructor.
|
""" Thread constructor.
|
||||||
|
@param device Device to use.
|
||||||
@param endTime Maximum simulation time.
|
@param endTime Maximum simulation time.
|
||||||
@param output [Rate,Type] Output rate, Type=0 if FPS, 1 if IPF.
|
@param output [Rate,Type] Output rate, Type=0 if FPS, 1 if IPF.
|
||||||
@param FSmesh Free surface mesh faces.
|
@param FSmesh Free surface mesh faces.
|
||||||
@param waves Waves parameters (A,T,phi,heading)
|
@param waves Waves parameters (A,T,phi,heading)
|
||||||
"""
|
"""
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
|
# Build OpenCL context and command queue
|
||||||
|
self.device = device
|
||||||
|
self.context = cl.Context(devices=[self.device])
|
||||||
|
self.queue = cl.CommandQueue(self.context)
|
||||||
|
# Storage data
|
||||||
self.endTime = endTime
|
self.endTime = endTime
|
||||||
self.output = output
|
self.output = output
|
||||||
self.FSmesh = FSmesh
|
self.FSmesh = FSmesh
|
||||||
|
|
|
@ -26,6 +26,8 @@ import FreeCAD as App
|
||||||
import FreeCADGui as Gui
|
import FreeCADGui as Gui
|
||||||
# Qt library
|
# Qt library
|
||||||
from PyQt4 import QtGui,QtCore
|
from PyQt4 import QtGui,QtCore
|
||||||
|
# pyOpenCL
|
||||||
|
import pyopencl as cl
|
||||||
# Module
|
# Module
|
||||||
import SimInstance
|
import SimInstance
|
||||||
from shipUtils import Paths, Translator
|
from shipUtils import Paths, Translator
|
||||||
|
@ -37,8 +39,6 @@ class TaskPanel:
|
||||||
self.sim = False
|
self.sim = False
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
if not self.sim:
|
|
||||||
return False
|
|
||||||
msg = Translator.translate("Building data...\n")
|
msg = Translator.translate("Building data...\n")
|
||||||
App.Console.PrintMessage(msg)
|
App.Console.PrintMessage(msg)
|
||||||
# Get GUI data
|
# Get GUI data
|
||||||
|
@ -46,6 +46,16 @@ class TaskPanel:
|
||||||
output = []
|
output = []
|
||||||
output.append(self.form.output.value())
|
output.append(self.form.output.value())
|
||||||
output.append(self.form.outputType.currentIndex())
|
output.append(self.form.outputType.currentIndex())
|
||||||
|
devId = self.form.device.currentIndex()
|
||||||
|
# Get OpenCL device
|
||||||
|
count = 0
|
||||||
|
platforms = cl.get_platforms()
|
||||||
|
for p in platforms:
|
||||||
|
devs = p.get_devices()
|
||||||
|
for d in devs:
|
||||||
|
if count == devId:
|
||||||
|
device = d
|
||||||
|
count = count + 1
|
||||||
# Get free surfaces data
|
# Get free surfaces data
|
||||||
FSMesh = SimInstance.FSMesh(self.sim)
|
FSMesh = SimInstance.FSMesh(self.sim)
|
||||||
wData = self.sim.Waves
|
wData = self.sim.Waves
|
||||||
|
@ -56,8 +66,8 @@ class TaskPanel:
|
||||||
msg = Translator.translate("Launching simulation...\n")
|
msg = Translator.translate("Launching simulation...\n")
|
||||||
App.Console.PrintMessage(msg)
|
App.Console.PrintMessage(msg)
|
||||||
# Build simulation thread
|
# Build simulation thread
|
||||||
t = Sim(endTime, output, FSMesh, waves)
|
simulator = Sim(device, endTime, output, FSMesh, waves)
|
||||||
t.start()
|
simulator.start()
|
||||||
msg = Translator.translate("Done!\n")
|
msg = Translator.translate("Done!\n")
|
||||||
App.Console.PrintMessage(msg)
|
App.Console.PrintMessage(msg)
|
||||||
return True
|
return True
|
||||||
|
@ -92,6 +102,7 @@ class TaskPanel:
|
||||||
form.time = form.findChild(QtGui.QDoubleSpinBox, "SimTime")
|
form.time = form.findChild(QtGui.QDoubleSpinBox, "SimTime")
|
||||||
form.output = form.findChild(QtGui.QDoubleSpinBox, "Output")
|
form.output = form.findChild(QtGui.QDoubleSpinBox, "Output")
|
||||||
form.outputType = form.findChild(QtGui.QComboBox, "OutputType")
|
form.outputType = form.findChild(QtGui.QComboBox, "OutputType")
|
||||||
|
form.device = form.findChild(QtGui.QComboBox, "Device")
|
||||||
self.form = form
|
self.form = form
|
||||||
# Initial values
|
# Initial values
|
||||||
if self.initValues():
|
if self.initValues():
|
||||||
|
@ -140,6 +151,20 @@ class TaskPanel:
|
||||||
msg = Translator.translate("Ship simulation instance must be selected (no valid simulation found at selected objects)\n")
|
msg = Translator.translate("Ship simulation instance must be selected (no valid simulation found at selected objects)\n")
|
||||||
App.Console.PrintError(msg)
|
App.Console.PrintError(msg)
|
||||||
return True
|
return True
|
||||||
|
# Get the list of devices
|
||||||
|
devices = []
|
||||||
|
platforms = cl.get_platforms()
|
||||||
|
for p in platforms:
|
||||||
|
devs = p.get_devices()
|
||||||
|
for d in devs:
|
||||||
|
devices.append([p,d])
|
||||||
|
dname = d.get_info(cl.device_info.NAME)
|
||||||
|
pname = p.get_info(cl.platform_info.NAME)
|
||||||
|
self.form.device.addItem(dname + " (" + pname + ")")
|
||||||
|
if not len(devices):
|
||||||
|
msg = Translator.translate("This tool requires an active OpenCL context to work\n")
|
||||||
|
App.Console.PrintError(msg)
|
||||||
|
return True
|
||||||
msg = Translator.translate("Ready to work\n")
|
msg = Translator.translate("Ready to work\n")
|
||||||
App.Console.PrintMessage(msg)
|
App.Console.PrintMessage(msg)
|
||||||
return False
|
return False
|
||||||
|
@ -150,6 +175,7 @@ class TaskPanel:
|
||||||
self.form.setWindowTitle(Translator.translate("Run the simulation"))
|
self.form.setWindowTitle(Translator.translate("Run the simulation"))
|
||||||
self.form.findChild(QtGui.QLabel, "SimTimeLabel").setText(Translator.translate("Simulation time"))
|
self.form.findChild(QtGui.QLabel, "SimTimeLabel").setText(Translator.translate("Simulation time"))
|
||||||
self.form.findChild(QtGui.QLabel, "OutputLabel").setText(Translator.translate("Output"))
|
self.form.findChild(QtGui.QLabel, "OutputLabel").setText(Translator.translate("Output"))
|
||||||
|
self.form.findChild(QtGui.QLabel, "DeviceLabel").setText(Translator.translate("OpenCL device"))
|
||||||
|
|
||||||
def createTask():
|
def createTask():
|
||||||
panel = TaskPanel()
|
panel = TaskPanel()
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>292</width>
|
<width>300</width>
|
||||||
<height>72</height>
|
<height>102</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
@ -19,7 +19,13 @@
|
||||||
<property name="minimumSize">
|
<property name="minimumSize">
|
||||||
<size>
|
<size>
|
||||||
<width>0</width>
|
<width>0</width>
|
||||||
<height>72</height>
|
<height>100</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>300</width>
|
||||||
|
<height>16777215</height>
|
||||||
</size>
|
</size>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -108,6 +114,16 @@
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="DeviceLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>OpenCL device</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1" colspan="2">
|
||||||
|
<widget class="QComboBox" name="Device"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user