Linear system matrix generation developed (only fluid involved for the moment)
This commit is contained in:
parent
81c839059a
commit
36e48afce1
|
@ -150,6 +150,7 @@ SET(SimRun_SRCS
|
|||
simRun/clSim/Utils.py
|
||||
simRun/Sim/__init__.py
|
||||
simRun/Sim/initialization.py
|
||||
simRun/Sim/matrixGen.py
|
||||
)
|
||||
SOURCE_GROUP("simrun" FILES ${SimRun_SRCS})
|
||||
|
||||
|
|
|
@ -102,7 +102,8 @@ nobase_data_DATA = \
|
|||
simRun/clSim/initialization.py \
|
||||
simRun/clSim/Utils.py \
|
||||
simRun/Sim/__init__.py \
|
||||
simRun/Sim/initialization.py
|
||||
simRun/Sim/initialization.py \
|
||||
simRun/Sim/matrixGen.py
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
|
|
|
@ -21,4 +21,5 @@
|
|||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import initialization
|
||||
from initialization import *
|
||||
from matrixGen import *
|
||||
|
|
|
@ -26,9 +26,9 @@ import numpy as np
|
|||
|
||||
grav=9.81
|
||||
|
||||
class perform:
|
||||
class simInitialization:
|
||||
def __init__(self, FSmesh, waves, context=None, queue=None):
|
||||
""" Constructor, includes program loading.
|
||||
""" Constructor.
|
||||
@param FSmesh Initial free surface mesh.
|
||||
@param waves Considered simulation waves (A,T,phi,heading).
|
||||
@param context OpenCL context where apply. Only for compatibility,
|
||||
|
@ -54,9 +54,9 @@ class perform:
|
|||
v = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
f = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
n = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
a = np.ndarray((nx,ny, 1), dtype=np.float32)
|
||||
phi = np.ndarray((nx,ny, 1), dtype=np.float32)
|
||||
Phi = np.ndarray((nx,ny, 1), dtype=np.float32)
|
||||
a = np.ndarray((nx,ny), dtype=np.float32)
|
||||
phi = np.ndarray((nx,ny), dtype=np.float32)
|
||||
Phi = np.ndarray((nx,ny), dtype=np.float32)
|
||||
for i in range(0, nx):
|
||||
for j in range(0, ny):
|
||||
pos = FSmesh[i][j].pos
|
||||
|
|
82
src/Mod/Ship/simRun/Sim/matrixGen.py
Normal file
82
src/Mod/Ship/simRun/Sim/matrixGen.py
Normal file
|
@ -0,0 +1,82 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* 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 *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# numpy
|
||||
import numpy as np
|
||||
|
||||
grav=9.81
|
||||
|
||||
class simMatrixGen:
|
||||
def __init__(self, context=None, queue=None):
|
||||
""" Constructor.
|
||||
@param context OpenCL context where apply. Only for compatibility,
|
||||
must be None.
|
||||
@param queue OpenCL command queue. Only for compatibility,
|
||||
must be None.
|
||||
"""
|
||||
self.context = context
|
||||
self.queue = queue
|
||||
|
||||
def execute(self, fs):
|
||||
""" Compute system matrix.
|
||||
@param fs Free surface instance.
|
||||
@return Linear system matrix.
|
||||
"""
|
||||
self.fs = fs
|
||||
nx = self.fs['Nx']
|
||||
ny = self.fs['Ny']
|
||||
nF = nx*ny
|
||||
nB = 0 # No body for the moment
|
||||
# Allocate matrix
|
||||
N = nx*ny + nB
|
||||
A = np.ndarray((N, N), dtype=np.float32)
|
||||
# Fluid sources rows
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
# Append fluid effect
|
||||
pos = self.fs['pos'][i,j]
|
||||
A[i*ny+j,0:nF] = self.fluidEffect(pos)
|
||||
# Append body effect
|
||||
# ...
|
||||
return A
|
||||
|
||||
def fluidEffect(self, pos):
|
||||
""" Compute fluid effect terms over desired position. Desingularized
|
||||
sources must taken into account.
|
||||
@param pos Point to evaluate.
|
||||
@return Fluid effect row.
|
||||
"""
|
||||
nx = self.fs['Nx']
|
||||
ny = self.fs['Ny']
|
||||
nF = nx*ny
|
||||
row = np.ndarray(nF, dtype=np.float32)
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
# Get source position (desingularized)
|
||||
source = np.copy(self.fs['pos'][i,j])
|
||||
area = self.fs['area'][i,j]
|
||||
source[2] = source[2] + np.sqrt(area)
|
||||
# Get distance between points
|
||||
d = np.linalg.norm(pos-source)
|
||||
row[i*ny+j] = np.log(d)*area
|
||||
return row
|
|
@ -21,7 +21,6 @@
|
|||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import time
|
||||
from math import *
|
||||
import threading
|
||||
|
||||
|
@ -80,19 +79,21 @@ class FreeCADShipSimulation(threading.Thread):
|
|||
self.active = True
|
||||
# Simulation stuff
|
||||
if self.device == None:
|
||||
from Sim import initialization
|
||||
from Sim import *
|
||||
else:
|
||||
from clSim import initialization
|
||||
msg = Translator.translate("\t[Sim]: Initializating OpenCL...\n")
|
||||
from clSim import *
|
||||
msg = Translator.translate("\t[Sim]: Initializating...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
init = initialization.perform(self.FSmesh,self.waves,self.context,self.queue)
|
||||
msg = Translator.translate("\t[Sim]: Iterating (outputs will be noticed)...\n")
|
||||
init = simInitialization(self.FSmesh,self.waves,self.context,self.queue)
|
||||
matGen = simMatrixGen(self.context,self.queue)
|
||||
FS = init.fs
|
||||
waves = init.waves
|
||||
msg = Translator.translate("\t[Sim]: Iterating...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
while self.active:
|
||||
print("Im thread, Im running...")
|
||||
time.sleep(1)
|
||||
# ...
|
||||
print("Im thread, step done!")
|
||||
msg = Translator.translate("\t\t[Sim]: Generating linear system matrix...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
A = matGen.execute(FS)
|
||||
# Set thread as stopped (and prepare it to restarting)
|
||||
self.active = False
|
||||
threading.Event().set()
|
||||
|
|
Loading…
Reference in New Issue
Block a user