Changed (and accelerated) simulation creation process.
This commit is contained in:
parent
cc59edda71
commit
779f148b44
|
@ -21,7 +21,6 @@
|
||||||
#* *
|
#* *
|
||||||
#***************************************************************************
|
#***************************************************************************
|
||||||
|
|
||||||
import time
|
|
||||||
from math import *
|
from math import *
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
|
@ -71,6 +70,7 @@ class ShipSimulation:
|
||||||
obj.addProperty("App::PropertyBool","IsShipSimulation","ShipSimulation", str(Translator.translate("True if is a valid ship simulation instance"))).IsShipSimulation=True
|
obj.addProperty("App::PropertyBool","IsShipSimulation","ShipSimulation", str(Translator.translate("True if is a valid ship simulation instance"))).IsShipSimulation=True
|
||||||
# Compute free surface mesh
|
# Compute free surface mesh
|
||||||
self.createFSMesh(obj,fsMeshData)
|
self.createFSMesh(obj,fsMeshData)
|
||||||
|
self.computeWaves(obj,waves)
|
||||||
# Store waves
|
# Store waves
|
||||||
obj.addProperty("App::PropertyVectorList","Waves","ShipSimulation", str(Translator.translate("Waves (Amplitude,period,phase)"))).Waves=[]
|
obj.addProperty("App::PropertyVectorList","Waves","ShipSimulation", str(Translator.translate("Waves (Amplitude,period,phase)"))).Waves=[]
|
||||||
obj.addProperty("App::PropertyFloatList","Waves_Dir","ShipSimulation", str(Translator.translate("Waves direction (0 deg to stern waves)"))).Waves_Dir=[]
|
obj.addProperty("App::PropertyFloatList","Waves_Dir","ShipSimulation", str(Translator.translate("Waves direction (0 deg to stern waves)"))).Waves_Dir=[]
|
||||||
|
@ -163,35 +163,51 @@ class ShipSimulation:
|
||||||
obj.FS_Area = areas[:]
|
obj.FS_Area = areas[:]
|
||||||
obj.FS_Normal = normal[:]
|
obj.FS_Normal = normal[:]
|
||||||
|
|
||||||
|
def computeWaves(self, obj, waves):
|
||||||
|
""" Add waves effect to free surface mesh positions.
|
||||||
|
@param obj Created Part::FeaturePython object.
|
||||||
|
@param waves waves data [A,T,phase, heading].
|
||||||
|
"""
|
||||||
|
grav = 9.81
|
||||||
|
positions = obj.FS_Position[:]
|
||||||
|
for i in range(0, len(positions)):
|
||||||
|
for w in waves:
|
||||||
|
A = w[0]
|
||||||
|
T = w[1]
|
||||||
|
phase = w[2]
|
||||||
|
heading = pi*w[3]/180.0
|
||||||
|
wl = 0.5 * grav / pi * T*T
|
||||||
|
k = 2.0*pi/wl
|
||||||
|
frec = 2.0*pi/T
|
||||||
|
pos = obj.FS_Position[i]
|
||||||
|
l = pos.x*cos(heading) + pos.y*sin(heading)
|
||||||
|
amp = A*sin(k*l + phase)
|
||||||
|
positions[i].z = positions[i].z + amp
|
||||||
|
obj.FS_Position = positions[:]
|
||||||
|
|
||||||
def computeShape(self, obj):
|
def computeShape(self, obj):
|
||||||
""" Computes simulation involved shapes.
|
""" Computes simulation involved shapes.
|
||||||
@param obj Created Part::FeaturePython object.
|
@param obj Created Part::FeaturePython object.
|
||||||
@return Shape
|
@return Shape
|
||||||
"""
|
"""
|
||||||
print("[ShipSimulation] Computing mesh shape...")
|
|
||||||
nx = obj.FS_Nx
|
nx = obj.FS_Nx
|
||||||
ny = obj.FS_Ny
|
ny = obj.FS_Ny
|
||||||
mesh = FSMesh(obj)
|
mesh = FSMesh(obj)
|
||||||
planes = []
|
# Create BSpline surface
|
||||||
# Create planes
|
surf = Part.BSplineSurface()
|
||||||
Percentage = 0
|
|
||||||
Count = 0
|
|
||||||
print("0%")
|
|
||||||
for i in range(1,nx-1):
|
for i in range(1,nx-1):
|
||||||
for j in range(1,ny-1):
|
u = i / float(nx-1)
|
||||||
Count = Count+1
|
surf.insertUKnot(u,i,0.000001)
|
||||||
done = int(round(100 * Count / ((nx-2)*(ny-2))))
|
for i in range(1,ny-1):
|
||||||
if done != Percentage:
|
v = i / float(ny-1)
|
||||||
Percentage = done
|
surf.insertVKnot(v,i,0.000001)
|
||||||
print("%i%%" % (done))
|
for i in range(0,nx):
|
||||||
v0 = (mesh[i][j].pos + mesh[i-1][j].pos + mesh[i][j-1].pos + mesh[i-1][j-1].pos).multiply(0.25)
|
for j in range(0,ny):
|
||||||
v1 = (mesh[i][j].pos + mesh[i+1][j].pos + mesh[i][j-1].pos + mesh[i+1][j-1].pos).multiply(0.25)
|
u = i / float(nx-1)
|
||||||
v2 = (mesh[i][j].pos + mesh[i+1][j].pos + mesh[i][j+1].pos + mesh[i+1][j+1].pos).multiply(0.25)
|
v = j / float(ny-1)
|
||||||
v3 = (mesh[i][j].pos + mesh[i-1][j].pos + mesh[i][j+1].pos + mesh[i-1][j+1].pos).multiply(0.25)
|
point = mesh[i][j].pos
|
||||||
p = Part.makePolygon([v0,v1,v2,v3,v0])
|
surf.movePoint(u,v,point,i+1,i+1,j+1,j+1)
|
||||||
planes.append(Part.makeFilledFace(p.Edges))
|
return surf.toShape()
|
||||||
# Join into a compound
|
|
||||||
return Part.makeCompound(planes)
|
|
||||||
|
|
||||||
class ViewProviderShipSimulation:
|
class ViewProviderShipSimulation:
|
||||||
def __init__(self, obj):
|
def __init__(self, obj):
|
||||||
|
|
|
@ -149,10 +149,13 @@ class TaskPanel:
|
||||||
self.form.waves.removeRow(row)
|
self.form.waves.removeRow(row)
|
||||||
# Ensure that exist one empty item at the end
|
# Ensure that exist one empty item at the end
|
||||||
nRow = self.form.waves.rowCount()
|
nRow = self.form.waves.rowCount()
|
||||||
last = self.form.waves.item(nRow-1,0)
|
if not nRow:
|
||||||
if last:
|
self.form.waves.setRowCount(1)
|
||||||
if(last.text() != ''):
|
else:
|
||||||
self.form.waves.setRowCount(nRow+1)
|
last = self.form.waves.item(nRow-1,0)
|
||||||
|
if last:
|
||||||
|
if(last.text() != ''):
|
||||||
|
self.form.waves.setRowCount(nRow+1)
|
||||||
# Fields must be numbers
|
# Fields must be numbers
|
||||||
for i in range(0,self.form.waves.rowCount()-1): # Avoid last row
|
for i in range(0,self.form.waves.rowCount()-1): # Avoid last row
|
||||||
for j in range(0,self.form.waves.columnCount()): # Avoid name column
|
for j in range(0,self.form.waves.columnCount()): # Avoid name column
|
||||||
|
|
Loading…
Reference in New Issue
Block a user