Imported pyOpenCL library
This commit is contained in:
parent
a933c93269
commit
6de9fd5791
|
@ -36,15 +36,26 @@ class ShipWorkbench ( Workbench ):
|
|||
self.appendToolbar("Ship design",list)
|
||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||
self.appendToolbar("Weights",list)
|
||||
list = ["Ship_CreateSim", "Ship_RunSim"]
|
||||
self.appendToolbar("Simulation",list)
|
||||
try:
|
||||
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
|
||||
list = ["Ship_LoadExample", "Ship_CreateShip", "Ship_OutlineDraw", "Ship_AreasCurve", "Ship_Hydrostatics"]
|
||||
self.appendMenu("Ship design",list)
|
||||
list = ["Ship_Weights", "Ship_CreateTank", "Ship_GZ"]
|
||||
self.appendToolbar("Weights",list)
|
||||
list = ["Ship_CreateSim", "Ship_RunSim"]
|
||||
self.appendToolbar("Simulation",list)
|
||||
try:
|
||||
import pyopencl
|
||||
except ImportError:
|
||||
pass
|
||||
else:
|
||||
list = ["Ship_CreateSim", "Ship_RunSim"]
|
||||
self.appendToolbar("Simulation",list)
|
||||
|
||||
Gui.addWorkbench(ShipWorkbench())
|
||||
|
|
|
@ -140,7 +140,7 @@ class RunSim:
|
|||
def GetResources(self):
|
||||
from shipUtils import Paths, Translator
|
||||
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'))
|
||||
return {'Pixmap' : IconPath, 'MenuText': MenuText, 'ToolTip': ToolTip}
|
||||
|
||||
|
|
|
@ -25,6 +25,9 @@ import time
|
|||
from math import *
|
||||
import threading
|
||||
|
||||
# pyOpenCL
|
||||
import pyopencl as cl
|
||||
|
||||
# FreeCAD
|
||||
import FreeCAD,FreeCADGui
|
||||
from FreeCAD import Part, Base, Vector
|
||||
|
@ -33,14 +36,20 @@ from FreeCAD import Part, Base, Vector
|
|||
from shipUtils import Paths, Translator, Math
|
||||
|
||||
class FreeCADShipSimulation(threading.Thread):
|
||||
def __init__ (self, endTime, output, FSmesh, waves):
|
||||
def __init__ (self, device, endTime, output, FSmesh, waves):
|
||||
""" Thread constructor.
|
||||
@param device Device to use.
|
||||
@param endTime Maximum simulation time.
|
||||
@param output [Rate,Type] Output rate, Type=0 if FPS, 1 if IPF.
|
||||
@param FSmesh Free surface mesh faces.
|
||||
@param waves Waves parameters (A,T,phi,heading)
|
||||
"""
|
||||
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.output = output
|
||||
self.FSmesh = FSmesh
|
||||
|
|
|
@ -26,6 +26,8 @@ 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
|
||||
|
@ -37,8 +39,6 @@ class TaskPanel:
|
|||
self.sim = False
|
||||
|
||||
def accept(self):
|
||||
if not self.sim:
|
||||
return False
|
||||
msg = Translator.translate("Building data...\n")
|
||||
App.Console.PrintMessage(msg)
|
||||
# Get GUI data
|
||||
|
@ -46,6 +46,16 @@ class TaskPanel:
|
|||
output = []
|
||||
output.append(self.form.output.value())
|
||||
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
|
||||
FSMesh = SimInstance.FSMesh(self.sim)
|
||||
wData = self.sim.Waves
|
||||
|
@ -56,8 +66,8 @@ class TaskPanel:
|
|||
msg = Translator.translate("Launching simulation...\n")
|
||||
App.Console.PrintMessage(msg)
|
||||
# Build simulation thread
|
||||
t = Sim(endTime, output, FSMesh, waves)
|
||||
t.start()
|
||||
simulator = Sim(device, endTime, output, FSMesh, waves)
|
||||
simulator.start()
|
||||
msg = Translator.translate("Done!\n")
|
||||
App.Console.PrintMessage(msg)
|
||||
return True
|
||||
|
@ -92,6 +102,7 @@ class TaskPanel:
|
|||
form.time = form.findChild(QtGui.QDoubleSpinBox, "SimTime")
|
||||
form.output = form.findChild(QtGui.QDoubleSpinBox, "Output")
|
||||
form.outputType = form.findChild(QtGui.QComboBox, "OutputType")
|
||||
form.device = form.findChild(QtGui.QComboBox, "Device")
|
||||
self.form = form
|
||||
# Initial values
|
||||
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")
|
||||
App.Console.PrintError(msg)
|
||||
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")
|
||||
App.Console.PrintMessage(msg)
|
||||
return False
|
||||
|
@ -150,6 +175,7 @@ class TaskPanel:
|
|||
self.form.setWindowTitle(Translator.translate("Run the simulation"))
|
||||
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, "DeviceLabel").setText(Translator.translate("OpenCL device"))
|
||||
|
||||
def createTask():
|
||||
panel = TaskPanel()
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>292</width>
|
||||
<height>72</height>
|
||||
<width>300</width>
|
||||
<height>102</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
|
@ -19,7 +19,13 @@
|
|||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>72</height>
|
||||
<height>100</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -108,6 +114,16 @@
|
|||
</item>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<resources/>
|
||||
|
|
Loading…
Reference in New Issue
Block a user