Linear systems solver developed (only fluid involved)
This commit is contained in:
parent
76c033593f
commit
d692491a75
|
@ -151,6 +151,7 @@ SET(SimRun_SRCS
|
|||
simRun/Sim/__init__.py
|
||||
simRun/Sim/initialization.py
|
||||
simRun/Sim/matrixGen.py
|
||||
simRun/Sim/computeSources.py
|
||||
)
|
||||
SOURCE_GROUP("simrun" FILES ${SimRun_SRCS})
|
||||
|
||||
|
|
|
@ -103,7 +103,8 @@ nobase_data_DATA = \
|
|||
simRun/clSim/Utils.py \
|
||||
simRun/Sim/__init__.py \
|
||||
simRun/Sim/initialization.py \
|
||||
simRun/Sim/matrixGen.py
|
||||
simRun/Sim/matrixGen.py \
|
||||
simRun/Sim/computeSources.py
|
||||
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
|
||||
|
|
|
@ -23,3 +23,4 @@
|
|||
|
||||
from initialization import *
|
||||
from matrixGen import *
|
||||
from computeSources import *
|
||||
|
|
69
src/Mod/Ship/simRun/Sim/computeSources.py
Normal file
69
src/Mod/Ship/simRun/Sim/computeSources.py
Normal file
|
@ -0,0 +1,69 @@
|
|||
#***************************************************************************
|
||||
#* *
|
||||
#* 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 simComputeSources:
|
||||
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, A):
|
||||
""" Compute potential sources (for velocity potential and
|
||||
acceleration potential).
|
||||
@param fs Free surface instance.
|
||||
@param A Linear system matrix.
|
||||
"""
|
||||
self.fs = fs
|
||||
# Allocate memory
|
||||
nx = self.fs['Nx']
|
||||
ny = self.fs['Ny']
|
||||
nF = nx*ny
|
||||
nB = 0 # No body for the moment
|
||||
N = nx*ny + nB
|
||||
b = np.ndarray(N, dtype=np.float32)
|
||||
bb = np.ndarray(N, dtype=np.float32)
|
||||
s = np.ndarray(N, dtype=np.float32)
|
||||
ss = np.ndarray(N, dtype=np.float32)
|
||||
# Create independent terms
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
b[i*ny+j] = self.fs['velPot'][i,j]
|
||||
bb[i*ny+j] = self.fs['accPot'][i,j]
|
||||
# Solve systems
|
||||
s = np.linalg.solve(A, b)
|
||||
ss = np.linalg.solve(A, bb)
|
||||
# Store sources
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
self.fs['velSrc'][i,j] = s[i*ny+j]
|
||||
self.fs['accSrc'][i,j] = ss[i*ny+j]
|
|
@ -57,6 +57,8 @@ class simInitialization:
|
|||
a = np.ndarray((nx,ny), dtype=np.float32)
|
||||
phi = np.ndarray((nx,ny), dtype=np.float32)
|
||||
Phi = np.ndarray((nx,ny), dtype=np.float32)
|
||||
s = np.ndarray((nx,ny), dtype=np.float32)
|
||||
ss = np.ndarray((nx,ny), dtype=np.float32)
|
||||
for i in range(0, nx):
|
||||
for j in range(0, ny):
|
||||
pos = FSmesh[i][j].pos
|
||||
|
@ -75,8 +77,13 @@ class simInitialization:
|
|||
n[i,j,1] = normal.y
|
||||
n[i,j,2] = normal.z
|
||||
a[i,j] = area
|
||||
phi[i,j] = 0.
|
||||
Phi[i,j] = 0.
|
||||
s[i,j] = 0.
|
||||
ss[i,j] = 0.
|
||||
self.fs = {'Nx':nx, 'Ny':ny, 'pos':p, 'vel':v, 'acc':f, \
|
||||
'normal':n, 'area':a, 'velPot':phi, 'accPot':Phi}
|
||||
'normal':n, 'area':a, 'velPot':phi, 'accPot':Phi, \
|
||||
'velSrc':s, 'accSrc':ss}
|
||||
# Waves data
|
||||
w = np.ndarray((nW, 4), dtype=np.float32)
|
||||
for i in range(0,nW):
|
||||
|
@ -85,6 +92,11 @@ class simInitialization:
|
|||
w[i,2] = waves[i][2]
|
||||
w[i,3] = waves[i][3]
|
||||
self.waves = {'N':nW, 'data':w}
|
||||
# Linear system matrix
|
||||
nF = nx*ny
|
||||
nB = 0 # No body for the moment
|
||||
N = nx*ny + nB
|
||||
self.A = np.ndarray((N, N), dtype=np.float32)
|
||||
|
||||
def execute(self):
|
||||
""" Compute initial conditions. """
|
||||
|
|
|
@ -37,19 +37,17 @@ class simMatrixGen:
|
|||
self.context = context
|
||||
self.queue = queue
|
||||
|
||||
def execute(self, fs):
|
||||
def execute(self, fs, A):
|
||||
""" Compute system matrix.
|
||||
@param fs Free surface instance.
|
||||
@return Linear system matrix.
|
||||
@param A 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):
|
||||
|
@ -58,7 +56,6 @@ class simMatrixGen:
|
|||
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
|
||||
|
|
|
@ -86,6 +86,8 @@ class FreeCADShipSimulation(threading.Thread):
|
|||
FreeCAD.Console.PrintMessage(msg)
|
||||
init = simInitialization(self.FSmesh,self.waves,self.context,self.queue)
|
||||
matGen = simMatrixGen(self.context,self.queue)
|
||||
solver = simComputeSources(self.context,self.queue)
|
||||
A = init.A
|
||||
FS = init.fs
|
||||
waves = init.waves
|
||||
msg = Translator.translate("\t[Sim]: Iterating...\n")
|
||||
|
@ -93,7 +95,10 @@ class FreeCADShipSimulation(threading.Thread):
|
|||
while self.active:
|
||||
msg = Translator.translate("\t\t[Sim]: Generating linear system matrix...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
A = matGen.execute(FS)
|
||||
matGen.execute(FS, A)
|
||||
msg = Translator.translate("\t\t[Sim]: Solving linear systems...\n")
|
||||
FreeCAD.Console.PrintMessage(msg)
|
||||
solver.execute(FS, A)
|
||||
# Set thread as stopped (and prepare it to restarting)
|
||||
self.active = False
|
||||
threading.Event().set()
|
||||
|
|
Loading…
Reference in New Issue
Block a user