Regenerated branch
This commit is contained in:
55
src/Mod/Ship/simRun/Sim/BEMsolver.py
Normal file
55
src/Mod/Ship/simRun/Sim/BEMsolver.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* 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
|
||||
import scipy.linalg as la
|
||||
import FreeCAD
|
||||
|
||||
grav=9.81
|
||||
|
||||
class simBEMSolver:
|
||||
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, bem):
|
||||
""" Compute potential unknow data (gradients for free surface, and
|
||||
potentials for the other ones).
|
||||
@param bem Boundary Element Method instance.
|
||||
"""
|
||||
[bem['Ap'], residues, rank, s] = la.lstsq(bem['A'], bem['B'])
|
||||
if(rank < bem['N']):
|
||||
FreeCAD.Console.PrintError("\t\t[Sim]: Solving velocity potentials.\n")
|
||||
FreeCAD.Console.PrintError("\t\t\tEffective rank of linear system matrix is %i (N = %i)\n" % (rank, bem['N']))
|
||||
[bem['Adp'], residues, rank, s] = la.lstsq(bem['A'], bem['dB'])
|
||||
if(rank < bem['N']):
|
||||
FreeCAD.Console.PrintError("\t\t[Sim]: Solving acceleration potentials.\n")
|
||||
FreeCAD.Console.PrintError("\t\t\tEffective rank of linear system matrix is %i (N = %i)\n" % (rank, bem['N']))
|
||||
|
||||
@@ -23,5 +23,5 @@
|
||||
|
||||
from initialization import *
|
||||
from matrixGen import *
|
||||
from computeSources import *
|
||||
from fsEvolution import *
|
||||
from BEMsolver import *
|
||||
from evolution import *
|
||||
|
||||
304
src/Mod/Ship/simRun/Sim/evolution.py
Normal file
304
src/Mod/Ship/simRun/Sim/evolution.py
Normal file
@@ -0,0 +1,304 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* 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 simEvolution:
|
||||
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 executeRK4(self, x, dx, p, dp, pos, vel, phi, dphi, fs, sea, body, waves, dt, t, stage):
|
||||
""" Compute free surface RK4 stage evolution process (valid for stages 1,2 and 3).
|
||||
@param x Output free surface z coordinates.
|
||||
@param dx Output free surface z coordinates variation (dz/dt).
|
||||
@param p Output potentials.
|
||||
@param dp Output potentials variation (dphi/dt).
|
||||
@param pos Input free surface positions.
|
||||
@param vel Input free surface velocities.
|
||||
@param phi Input potentials.
|
||||
@param dphi Input potentials variation (dphi/dt).
|
||||
@param fs Free surface instance.
|
||||
@param sea Sea instance.
|
||||
@param body Body instance.
|
||||
@param waves Waves instance.
|
||||
@param dt Time step.
|
||||
@param t Actual time (without adding dt).
|
||||
@param stage Runge-Kutta4 stage.
|
||||
@return Input variables evoluted one time step.
|
||||
"""
|
||||
# --------------------------------------------
|
||||
# Only free surface
|
||||
# --------------------------------------------
|
||||
h = fs['h']
|
||||
nx = fs['Nx']
|
||||
ny = fs['Ny']
|
||||
nF = nx*ny
|
||||
factor = 0.5
|
||||
if stage > 2:
|
||||
factor = 1.
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
x[i,j] = np.copy(pos[i,j][2])
|
||||
dx[i,j] = np.copy(vel[i,j][2])
|
||||
x[i,j] = x[i,j] + factor*dt*dx[i,j]
|
||||
p[i*ny+j] = np.copy(phi[i*ny+j])
|
||||
dp[i*ny+j] = np.copy(dphi[i*ny+j])
|
||||
p[i*ny+j] = p[i*ny+j] + factor*dt*dp[i*ny+j]
|
||||
# Impose values at beach (far free surface)
|
||||
nbx = fs['Beachx']
|
||||
nby = fs['Beachy']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,nby) + range(ny-nby,ny):
|
||||
[x[i,j],dx[i,j],p[i*ny+j],dp[i*ny+j]] = self.beach(pos[i,j], waves, factor*dt, t)
|
||||
for j in range(0,ny):
|
||||
for i in range(0,nbx) + range(nx-nbx,nx):
|
||||
[x[i,j],dx[i,j],p[i*ny+j],dp[i*ny+j]] = self.beach(pos[i,j], waves, factor*dt, t)
|
||||
# --------------------------------------------
|
||||
# Sea boundaries, where potentials are fixed.
|
||||
# We use the gradient projected over normal,
|
||||
# see initialization for more details about
|
||||
# this.
|
||||
# --------------------------------------------
|
||||
ids = ['front','back','left','right','bottom']
|
||||
i0 = fs['N']
|
||||
for index in ids:
|
||||
s = sea[index]
|
||||
nx = s['Nx']
|
||||
ny = s['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
p[i0 + i*ny+j] = 0.
|
||||
dp[i0 + i*ny+j] = 0.
|
||||
for w in waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
pos = s['pos'][i,j]
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
normal = s['normal'][i,j]
|
||||
hfact = np.cosh(k*(pos[2]+h)) / np.cosh(k*h)
|
||||
factor = np.dot(normal,np.array([np.cos(heading), np.sin(heading), 0.]))
|
||||
amp = frec*A*np.sin(k*l - frec*(t+factor*dt) + phase)*hfact
|
||||
p[i0 + i*ny+j] = p[i0 + i*ny+j] + factor*amp
|
||||
amp = - grav*A*k*np.cos(k*l - frec*(t+factor*dt) + phase)*hfact
|
||||
dp[i0 + i*ny+j] = dp[i0 + i*ny+j] + factor*amp
|
||||
i0 = i0 + s['N']
|
||||
|
||||
def execute(self, dx1, dx2, dx3, dp1, dp2, dp3, fs, sea, body, waves, bem, dt, t):
|
||||
""" Compute free surface evolution process (execute it on RK4 last stage).
|
||||
@param dx1 Input free surface positions variation on stage 1.
|
||||
@param dx2 Input free surface positions variation on stage 2.
|
||||
@param dx3 Input free surface positions variation on stage 3.
|
||||
@param dp1 Input free surface potentials variation on stage 1.
|
||||
@param dp2 Input free surface potentials variation on stage 2.
|
||||
@param dp3 Input free surface potentials variation on stage 3.
|
||||
@param fs Free surface instance.
|
||||
@param sea Sea instance.
|
||||
@param body Body instance.
|
||||
@param waves Waves instance.
|
||||
@param bem Boundary Element Method instance.
|
||||
@param dt Time step.
|
||||
@param t Actual time (without adding dt).
|
||||
@param stage Runge-Kutta4 stage.
|
||||
@return Input variables evoluted one time step.
|
||||
"""
|
||||
h = fs['h']
|
||||
nx = fs['Nx']
|
||||
ny = fs['Ny']
|
||||
nF = nx*ny
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
# In this stage dx4 and dp4 are directly known from the previous
|
||||
# stage.
|
||||
dx4 = fs['vel'][i,j][2]
|
||||
dp4 = bem['dp4'][i*ny+j]
|
||||
# And we only need to apply the integration scheme
|
||||
fs['pos'][i,j][2] = fs['pos'][i,j][2] + dt/6. * (dx1[i,j] + 2.*dx2[i,j] + 2.*dx3[i,j] + dx4)
|
||||
bem['p4'][i*ny+j] = bem['p4'][i*ny+j] + dt/6. * (dp1[i*ny+j] + 2.*dp2[i*ny+j] + 2.*dp3[i*ny+j] + dp4)
|
||||
# In order to can apply the boundary condition at the free surface
|
||||
# at the end of this RK4 stage, we need to store eta in a variable.
|
||||
# x1 is safe because will be over written at the start of next
|
||||
# time step.
|
||||
fs['x1'][i,j] = fs['pos'][i,j][2]
|
||||
# Impose values at beach (far free surface)
|
||||
nbx = fs['Beachx']
|
||||
nby = fs['Beachy']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,nby) + range(ny-nby,ny):
|
||||
[x,dummy,p,dummy] = self.beach(fs['pos'][i,j], waves, dt, t)
|
||||
fs['pos'][i,j][2] = x
|
||||
bem['p4'][i*ny+j] = p
|
||||
fs['x1'][i,j] = fs['pos'][i,j][2]
|
||||
for j in range(0,ny):
|
||||
for i in range(0,nbx) + range(nx-nbx,nx):
|
||||
[x,dummy,p,dummy] = self.beach(fs['pos'][i,j], waves, dt, t)
|
||||
fs['pos'][i,j][2] = x
|
||||
bem['p4'][i*ny+j] = p
|
||||
fs['x1'][i,j] = fs['pos'][i,j][2]
|
||||
# --------------------------------------------
|
||||
# Sea boundaries, where potentials are fixed.
|
||||
# We use the gradient projected over normal,
|
||||
# see initialization for more details about
|
||||
# this.
|
||||
# --------------------------------------------
|
||||
ids = ['front','back','left','right','bottom']
|
||||
i0 = fs['N']
|
||||
p = bem['p4']
|
||||
dp = bem['dp4']
|
||||
for index in ids:
|
||||
s = sea[index]
|
||||
nx = s['Nx']
|
||||
ny = s['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
p[i0 + i*ny+j] = 0.
|
||||
dp[i0 + i*ny+j] = 0.
|
||||
for w in waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
pos = s['pos'][i,j]
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
normal = s['normal'][i,j]
|
||||
hfact = np.cosh(k*(pos[2]+h)) / np.cosh(k*h)
|
||||
factor = np.dot(normal,np.array([np.cos(heading), np.sin(heading), 0.]))
|
||||
amp = frec*A*np.sin(k*l - frec*(t+factor*dt) + phase)*hfact
|
||||
p[i0 + i*ny+j] = p[i0 + i*ny+j] + factor*amp
|
||||
amp = - grav*A*k*np.cos(k*l - frec*(t+factor*dt) + phase)*hfact
|
||||
dp[i0 + i*ny+j] = dp[i0 + i*ny+j] + factor*amp
|
||||
i0 = i0 + s['N']
|
||||
|
||||
def executeFSBC(self, x, fs, sea, body, waves, bem, dt, t, stage):
|
||||
""" Compute free surface boundary conditions in order to get
|
||||
free surface points velocity and potentials acceleration for
|
||||
the next RK4 stage.
|
||||
@param x Free surface z coordinates.
|
||||
@param fs Free surface instance.
|
||||
@param sea Sea boundaries instance.
|
||||
@param body Body instance.
|
||||
@param waves Waves instance.
|
||||
@param bem Boundary Element Method instance.
|
||||
@param dt Time step.
|
||||
@param t Actual time (without adding dt).
|
||||
"""
|
||||
nx = fs['Nx']
|
||||
ny = fs['Ny']
|
||||
nF = nx*ny
|
||||
factor = 0.5
|
||||
if stage > 2:
|
||||
factor = 1.
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
pos = np.copy(fs['pos'][i,j])
|
||||
pos[2] = x[i,j]
|
||||
gradVal = bem['Ap'][i*ny+j]
|
||||
normal = fs['normal'][i,j]
|
||||
# v_z = dphi/dz - grad(phi)*grad(z) - U*dz/dx
|
||||
dzdt = gradVal*normal[2]
|
||||
# dphi/dt = - rho*g*z - 0.5*grad(phi)^2 + v_z*dphi/dz - p_0 - U*dphi/dx - dU/dt*x
|
||||
dphidt = -grav*pos[2] - 0.5*np.dot(gradVal,gradVal) # + dzdt*gradVal*normal[2]
|
||||
# We need to preserve data on free surface global
|
||||
# velocity and potential values in order to use as
|
||||
# input of the next RK4 stage
|
||||
fs['vel'][i,j][2] = dzdt
|
||||
bem['dp4'][i*ny+j] = dphidt
|
||||
# Impose values at beach (far free surface)
|
||||
nbx = fs['Beachx']
|
||||
nby = fs['Beachy']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,nby) + range(ny-nby,ny):
|
||||
[dummy,dx,dummy,dp] = self.beach(fs['pos'][i,j], waves, factor*dt, t)
|
||||
fs['vel'][i,j][2] = dx
|
||||
bem['dp4'][i*ny+j] = dp
|
||||
for j in range(0,ny):
|
||||
for i in range(0,nbx) + range(nx-nbx,nx):
|
||||
[dummy,dx,dummy,dp] = self.beach(fs['pos'][i,j], waves, factor*dt, t)
|
||||
fs['vel'][i,j][2] = dx
|
||||
bem['dp4'][i*ny+j] = dp
|
||||
|
||||
def beach(self, pos, waves, dt, t):
|
||||
""" Compute far free surface where only
|
||||
incident waves can be taken into account.
|
||||
@param pos Free surface position.
|
||||
@param waves Waves instance.
|
||||
@param dt Time step.
|
||||
@param t Actual time (without adding dt).
|
||||
@return Position, velocity, potential and potential acceleration
|
||||
"""
|
||||
h = waves['h']
|
||||
x = 0.
|
||||
dx = 0.
|
||||
p = 0.
|
||||
dp = 0.
|
||||
# Since values of the potencial, and this acceleration,
|
||||
# depends on z, we need to compute first the positions.
|
||||
for w in waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
# hfact = np.sinh(k*(pos[2]+h)) / np.cosh(k*h)
|
||||
hfact = 1.0
|
||||
amp = A*np.sin(k*l - frec*(t+dt) + phase)*hfact
|
||||
x = x + amp
|
||||
amp = - A*frec*np.cos(k*l - frec*(t+dt) + phase)*hfact
|
||||
dx = dx + amp
|
||||
# And now we can compute potentials.
|
||||
for w in waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
hfact = np.cosh(k*(x+h)) / np.cosh(k*h)
|
||||
amp = - grav/frec*A*np.sin(k*l - frec*(t+dt) + phase)*hfact
|
||||
p = p + amp
|
||||
amp = grav*A*np.cos(k*l - frec*(t+dt) + phase)*hfact
|
||||
dp = dp + amp
|
||||
return [x,dx,p,dp]
|
||||
|
||||
@@ -1,119 +1,327 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* 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 *
|
||||
#* *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# numpy
|
||||
import numpy as np
|
||||
import FreeCAD
|
||||
|
||||
grav=9.81
|
||||
|
||||
class simInitialization:
|
||||
def __init__(self, FSmesh, waves, context=None, queue=None):
|
||||
""" 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,
|
||||
must be None.
|
||||
@param queue OpenCL command queue. Only for compatibility,
|
||||
must be None.
|
||||
"""
|
||||
self.context = context
|
||||
self.queue = queue
|
||||
self.loadData(FSmesh, waves)
|
||||
self.execute()
|
||||
# Compute time step
|
||||
self.dt = 0.1
|
||||
for w in self.waves['data']:
|
||||
if(self.dt > w[1]/200.0):
|
||||
self.dt = w[1]/200.0
|
||||
def __init__(self, h, FSMesh, SeaMesh, waves, context=None, queue=None):
|
||||
""" Constructor.
|
||||
@param h Water height.
|
||||
@param FSMesh Initial free surface mesh.
|
||||
@param waves Considered simulation waves (A,T,phi,heading).
|
||||
@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
|
||||
self.loadData(h, FSMesh, SeaMesh, waves)
|
||||
self.execute()
|
||||
# Compute time step
|
||||
self.dt = 0.1
|
||||
for w in self.waves['data']:
|
||||
if(self.dt > w[1]/200.0):
|
||||
self.dt = w[1]/200.0
|
||||
|
||||
def loadData(self, FSmesh, waves):
|
||||
""" Convert data to numpy format.
|
||||
@param FSmesh Initial free surface mesh.
|
||||
@param waves Considered simulation waves (A,T,phi,heading).
|
||||
"""
|
||||
nx = len(FSmesh)
|
||||
ny = len(FSmesh[0])
|
||||
nW = len(waves)
|
||||
# Mesh data
|
||||
p = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
n = np.ndarray((nx,ny, 3), 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)
|
||||
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
|
||||
normal = FSmesh[i][j].normal
|
||||
area = FSmesh[i][j].area
|
||||
p[i,j,0] = pos.x
|
||||
p[i,j,1] = pos.y
|
||||
p[i,j,2] = pos.z
|
||||
n[i,j,0] = normal.x
|
||||
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, '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):
|
||||
w[i,0] = waves[i][0]
|
||||
w[i,1] = waves[i][1]
|
||||
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 loadData(self, h, FSMesh, SeaMesh, waves):
|
||||
""" Convert data to numpy format.
|
||||
@param FSMesh Initial free surface mesh.
|
||||
@param waves Considered simulation waves (A,T,phi,heading).
|
||||
"""
|
||||
# Data will classified in four groups:
|
||||
# Free surface:
|
||||
# Is a key part of the simulation, so is
|
||||
# separated from the rest of water involved
|
||||
# elements.
|
||||
# Sea:
|
||||
# BEM method required a closed domain, so
|
||||
# water floor and sides must be append, but
|
||||
# are not a key objective of the simulation.
|
||||
# Body:
|
||||
# Is the main objective of the simulation.
|
||||
# Waves:
|
||||
# Data that is append as boundary condition.
|
||||
# BEM:
|
||||
# Used to solve the BEM problem and evolution.
|
||||
|
||||
# --------------------------------------------
|
||||
# Free surface data
|
||||
# N, Nx, Ny = Number of points in each
|
||||
# direction
|
||||
# pos = Positions
|
||||
# vel = Velocities
|
||||
# n = Normals
|
||||
# area = Areas
|
||||
# --------------------------------------------
|
||||
nx = len(FSMesh)
|
||||
ny = len(FSMesh[0])
|
||||
p = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
V = np.zeros((nx,ny, 3), dtype=np.float32)
|
||||
n = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
a = np.ndarray((nx,ny), dtype=np.float32)
|
||||
x1 = np.zeros((nx,ny), dtype=np.float32)
|
||||
x2 = np.zeros((nx,ny), dtype=np.float32)
|
||||
x3 = np.zeros((nx,ny), dtype=np.float32)
|
||||
dx1 = np.zeros((nx,ny), dtype=np.float32)
|
||||
dx2 = np.zeros((nx,ny), dtype=np.float32)
|
||||
dx3 = np.zeros((nx,ny), dtype=np.float32)
|
||||
for i in range(0, nx):
|
||||
for j in range(0, ny):
|
||||
pos = FSMesh[i][j].pos
|
||||
normal = FSMesh[i][j].normal
|
||||
area = FSMesh[i][j].area
|
||||
p[i,j,0] = pos.x
|
||||
p[i,j,1] = pos.y
|
||||
p[i,j,2] = pos.z
|
||||
n[i,j,0] = normal.x
|
||||
n[i,j,1] = normal.y
|
||||
n[i,j,2] = normal.z
|
||||
a[i,j] = area
|
||||
self.fs = {'h': h, 'N':nx*ny, 'Nx':nx, 'Ny':ny, \
|
||||
'pos':p, 'vel':V, 'normal':n, 'area':a, \
|
||||
'x1':x1, 'x2':x2, 'x3':x3,\
|
||||
'dx1':dx1, 'dx2':dx2, 'dx3':dx3}
|
||||
# --------------------------------------------
|
||||
# Sea data (dictionary with components
|
||||
# ['front','back','left','right','bottom'])
|
||||
# N, Nx, Ny = Number of points in each
|
||||
# direction
|
||||
# pos = Positions
|
||||
# vel = Velocities
|
||||
# n = Normals
|
||||
# area = Areas
|
||||
# --------------------------------------------
|
||||
self.sea = {'ids':['front','back','left','right','bottom']}
|
||||
N = 0
|
||||
for index in self.sea['ids']:
|
||||
mesh = SeaMesh[index]
|
||||
nx = len(mesh)
|
||||
ny = len(mesh[0])
|
||||
p = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
V = np.zeros((nx,ny, 3), dtype=np.float32)
|
||||
n = np.ndarray((nx,ny, 3), dtype=np.float32)
|
||||
a = np.ndarray((nx,ny), dtype=np.float32)
|
||||
for i in range(0, nx):
|
||||
for j in range(0, ny):
|
||||
pos = mesh[i][j].pos
|
||||
normal = mesh[i][j].normal
|
||||
area = mesh[i][j].area
|
||||
p[i,j,0] = pos.x
|
||||
p[i,j,1] = pos.y
|
||||
p[i,j,2] = pos.z
|
||||
n[i,j,0] = normal.x
|
||||
n[i,j,1] = normal.y
|
||||
n[i,j,2] = normal.z
|
||||
a[i,j] = area
|
||||
d = {'N':nx*ny, 'Nx':nx, 'Ny':ny, 'pos':p, 'vel':V, 'normal':n, 'area':a}
|
||||
self.sea[index] = d
|
||||
N = N + nx*ny
|
||||
self.sea['N'] = N
|
||||
self.sea['h'] = h
|
||||
# --------------------------------------------
|
||||
# Body data
|
||||
# N, Nx, Ny = Number of points in each
|
||||
# direction
|
||||
# pos = Positions
|
||||
# vel = Velocities
|
||||
# n = Normals
|
||||
# area = Areas
|
||||
# --------------------------------------------
|
||||
self.b = {'N':0, 'pos':None, 'vel':None, 'normal':None, 'area':None}
|
||||
# --------------------------------------------
|
||||
# Waves data
|
||||
# N = Number of waves
|
||||
# data = Waves data
|
||||
# --------------------------------------------
|
||||
nW = len(waves)
|
||||
w = np.ndarray((nW, 4), dtype=np.float32)
|
||||
for i in range(0,nW):
|
||||
w[i,0] = waves[i][0]
|
||||
w[i,1] = waves[i][1]
|
||||
w[i,2] = waves[i][2]
|
||||
w[i,3] = waves[i][3]
|
||||
self.waves = {'h':h, 'N':nW, 'data':w}
|
||||
# --------------------------------------------
|
||||
# BEM data
|
||||
# N = nFS + nSea + nB
|
||||
# A,B,dB = Linear system matrix and vectors
|
||||
# p1,... = Velocity potentials (phi) for
|
||||
# each RK4 step. In reallity are
|
||||
# the independent term of the
|
||||
# BEM linear system, so is the
|
||||
# potential for the free surface,
|
||||
# and the gradient projected over
|
||||
# the normal along all other terms.
|
||||
# dp1,... = Acceleration potentials
|
||||
# (dphi/dt) for each RK4 step.
|
||||
# In reallity are the
|
||||
# independent term of the BEM
|
||||
# linear system, so is the
|
||||
# potential for the free surface,
|
||||
# and the gradient projected over
|
||||
# the normal along all other terms.
|
||||
# Ap,Adp = BEM solution vectors, that
|
||||
# contains the potential gradients
|
||||
# on free surface, and the potential
|
||||
# along all toher surfaces.
|
||||
# --------------------------------------------
|
||||
nFS = self.fs['N']
|
||||
nSea = self.sea['N']
|
||||
nB = self.b['N']
|
||||
N = nFS + nSea + nB
|
||||
A = np.zeros((N, N), dtype=np.float32)
|
||||
B = np.zeros((N), dtype=np.float32)
|
||||
dB = np.zeros((N), dtype=np.float32)
|
||||
p1 = np.zeros((N), dtype=np.float32)
|
||||
p2 = np.zeros((N), dtype=np.float32)
|
||||
p3 = np.zeros((N), dtype=np.float32)
|
||||
p4 = np.zeros((N), dtype=np.float32)
|
||||
Ap = np.zeros((N), dtype=np.float32)
|
||||
dp1 = np.zeros((N), dtype=np.float32)
|
||||
dp2 = np.zeros((N), dtype=np.float32)
|
||||
dp3 = np.zeros((N), dtype=np.float32)
|
||||
dp4 = np.zeros((N), dtype=np.float32)
|
||||
Adp = np.zeros((N), dtype=np.float32)
|
||||
self.bem = {'N':N, 'A':A, 'B':B, 'dB':dB, \
|
||||
'p1':p1, 'p2':p2, 'p3':p3, 'p4':p4, 'Ap':Ap, \
|
||||
'dp1':dp1, 'dp2':dp2, 'dp3':dp3, 'dp4':dp4, 'Adp':Adp }
|
||||
|
||||
def execute(self):
|
||||
""" Compute initial conditions. """
|
||||
# --------------------------------------------
|
||||
# Free surface beach nodes.
|
||||
# Beach nodes are the nodes of the free
|
||||
# surface where the waves are imposed. All
|
||||
# the other nodes are computed allowing non
|
||||
# linear waves due to the ship interaction.
|
||||
# The beach will have enough dimension to
|
||||
# control at least half wave length
|
||||
# --------------------------------------------
|
||||
# Get maximum wave length
|
||||
wl = 0.0
|
||||
for w in self.waves['data']:
|
||||
T = w[1]
|
||||
wl = max(wl, 0.5 * grav / np.pi * T*T)
|
||||
# Get nodes dimensions
|
||||
nx = self.fs['Nx']
|
||||
ny = self.fs['Ny']
|
||||
lx = self.fs['pos'][nx-1,0][0] - self.fs['pos'][0,0][0]
|
||||
ly = self.fs['pos'][0,ny-1][1] - self.fs['pos'][0,0][1]
|
||||
dx = lx / nx
|
||||
dy = ly / ny
|
||||
# Get number of nodes involved
|
||||
wnx = max(1, int(round(0.5*wl / dx)))
|
||||
wny = max(1, int(round(0.5*wl / dy)))
|
||||
wnx = min(wnx, nx)
|
||||
wny = min(wny, ny)
|
||||
self.fs['Beachx'] = wnx
|
||||
self.fs['Beachy'] = wny
|
||||
# --------------------------------------------
|
||||
# Free surface initial condition.
|
||||
# Since RK4 scheme starts on the end of
|
||||
# previous step, we only write on last
|
||||
# stage value (p4 and dp4)
|
||||
# --------------------------------------------
|
||||
nx = self.fs['Nx']
|
||||
ny = self.fs['Ny']
|
||||
h = self.fs['h']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
# Since initial values of the potencial, and this acceleration,
|
||||
# depends on z, we need to compute first the positions.
|
||||
self.fs['pos'][i,j][2] = 0.
|
||||
for w in self.waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
pos = self.fs['pos'][i,j]
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
# hfact = np.sinh(k*(pos[2]+h)) / np.cosh(k*h)
|
||||
hfact = 1.0
|
||||
amp = A*np.sin(k*l + phase)*hfact
|
||||
self.fs['pos'][i,j][2] = self.fs['pos'][i,j][2] + amp
|
||||
amp = - A*frec*np.cos(k*l + phase)*hfact
|
||||
self.fs['vel'][i,j][2] = self.fs['vel'][i,j][2] + amp
|
||||
# And now we can compute potentials.
|
||||
for w in self.waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
pos = self.fs['pos'][i,j]
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
hfact = np.cosh(k*(pos[2]+h)) / np.cosh(k*h)
|
||||
amp = - grav/frec*A*np.cos(k*l + phase)*hfact
|
||||
self.bem['p4'][i*ny+j] = self.bem['p4'][i*ny+j] + amp
|
||||
amp = - grav*A*np.sin(k*l + phase)*hfact
|
||||
self.bem['dp4'][i*ny+j] = self.bem['dp4'][i*ny+j] + amp
|
||||
# --------------------------------------------
|
||||
# Sea initial condition on sides.
|
||||
# 1. Since RK4 scheme starts on the end of
|
||||
# previous step, we only write on last
|
||||
# stage value (p4 and dp4)
|
||||
# 2. In the sea boundaries we are
|
||||
# interested on the gradient of the
|
||||
# potentials projected over the normal,
|
||||
# so we really store this value.
|
||||
# 3. In the floor this value is ever null.
|
||||
# --------------------------------------------
|
||||
ids = ['front','back','left','right','bottom']
|
||||
i0 = self.fs['N']
|
||||
for index in ids:
|
||||
sea = self.sea[index]
|
||||
nx = sea['Nx']
|
||||
ny = sea['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
for w in self.waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
pos = sea['pos'][i,j]
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
normal = sea['normal'][i,j]
|
||||
hfact = np.cosh(k*(pos[2]+h)) / np.cosh(k*h)
|
||||
factor = np.dot(normal,np.array([np.cos(heading), np.sin(heading), 0.]))
|
||||
amp = frec*A*np.sin(k*l + phase)*hfact
|
||||
self.bem['p4'][i0 + i*ny+j] = self.bem['p4'][i*ny+j] + factor*amp
|
||||
amp = - grav*A*k*np.cos(k*l + phase)*hfact
|
||||
self.bem['dp4'][i0 + i*ny+j] = self.bem['dp4'][i*ny+j] + factor*amp
|
||||
i0 = i0 + sea['N']
|
||||
|
||||
def execute(self):
|
||||
""" Compute initial conditions. """
|
||||
nx = self.fs['Nx']
|
||||
ny = self.fs['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
self.fs['pos'][i,j][2] = 0.
|
||||
for w in self.waves['data']:
|
||||
A = w[0]
|
||||
T = w[1]
|
||||
phase = w[2]
|
||||
heading = np.pi*w[3]/180.0
|
||||
wl = 0.5 * grav / np.pi * T*T
|
||||
k = 2.0*np.pi/wl
|
||||
frec = 2.0*np.pi/T
|
||||
pos = self.fs['pos'][i,j]
|
||||
l = pos[0]*np.cos(heading) + pos[1]*np.sin(heading)
|
||||
amp = A*np.sin(k*l + phase)
|
||||
self.fs['pos'][i,j][2] = self.fs['pos'][i,j][2] + amp
|
||||
amp = - grav/frec*A*np.sin(k*l + phase)
|
||||
self.fs['velPot'][i,j] = self.fs['velPot'][i,j] + amp
|
||||
amp = grav*A*np.cos(k*l + phase)
|
||||
self.fs['accPot'][i,j] = self.fs['accPot'][i,j] + amp
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#***************************************************************************
|
||||
#* *
|
||||
#* Copyright (c) 2011, 2012 *
|
||||
#* Jose Luis Cercos Pita <jlcercos@gmail.com> *
|
||||
#* *
|
||||
#* *
|
||||
#* 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 *
|
||||
#* 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 *
|
||||
#* *
|
||||
#* USA *
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
# numpy
|
||||
@@ -27,53 +27,197 @@ 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 __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 system matrix.
|
||||
@param fs Free surface instance.
|
||||
@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
|
||||
N = nx*ny + nB
|
||||
# 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
|
||||
# ...
|
||||
def execute(self, x, p, dp, fs, sea, bem, body):
|
||||
""" Compute system matrix.
|
||||
@param x Free surface z coordinates.
|
||||
@param fs Free surface instance.
|
||||
@param sea Sea boundary instance.
|
||||
@param bem Boundary Element Method instance.
|
||||
@param body Body instance.
|
||||
"""
|
||||
nFS = fs['N']
|
||||
nSea = sea['N']
|
||||
nB = body['N']
|
||||
n = nFS + nSea + nB
|
||||
A = bem['A']
|
||||
B = bem['B']
|
||||
dB = bem['dB']
|
||||
# Free surface sources rows
|
||||
nx = fs['Nx']
|
||||
ny = fs['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
pos = np.copy(fs['pos'][i,j])
|
||||
pos[2] = x[i,j]
|
||||
# Compute G terms
|
||||
fsG = self.fsG(x, pos, fs)
|
||||
seaG = self.seaG(pos, sea)
|
||||
# Compute H terms
|
||||
fsH = self.fsH(i*ny+j, x, pos, fs)
|
||||
seaH = self.seaH(i*ny+j, pos, fs, sea)
|
||||
# Append terms to linear system matrix
|
||||
A[i*ny+j,0:nFS] = fsG
|
||||
A[i*ny+j,nFS:n] = seaH
|
||||
# Set independent terms
|
||||
B[i*ny+j] = np.dot(fsH, p[0:nFS]) + np.dot(seaG, p[nFS:nFS+nSea])
|
||||
dB[i*ny+j] = np.dot(fsH, dp[0:nFS]) + np.dot(seaG, dp[nFS:nFS+nSea])
|
||||
# Append body effect
|
||||
# ...
|
||||
# Sea sources rows
|
||||
ids = ['front','back','left','right','bottom']
|
||||
count = 0
|
||||
for index in ids:
|
||||
s = sea[index]
|
||||
nx = s['Nx']
|
||||
ny = s['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
pos = np.copy(s['pos'][i,j])
|
||||
# Compute G terms
|
||||
fsG = self.fsG(x, pos, fs)
|
||||
seaG = self.seaG(pos, sea)
|
||||
# Compute H terms
|
||||
fsH = self.fsH(nFS+count, x, pos, fs)
|
||||
seaH = self.seaH(nFS+count, pos, fs, sea)
|
||||
# Append terms to linear system matrix
|
||||
A[nFS+count, 0:nFS] = fsG
|
||||
A[nFS+count, nFS:n] = seaH
|
||||
# Set independent terms
|
||||
B[nFS+count] = np.dot(fsH, p[0:nFS]) + np.dot(seaG, p[nFS:nFS+nSea])
|
||||
dB[nFS+count] = np.dot(fsH, dp[0:nFS]) + np.dot(seaG, dp[nFS:nFS+nSea])
|
||||
# Append body effect
|
||||
# ...
|
||||
count = count + 1
|
||||
# Solid sources rows
|
||||
# ...
|
||||
|
||||
def fsG(self, x, pos, fs):
|
||||
r""" Compute free surface terms potential effect over desired position. Desingularized
|
||||
sources must taken into account.
|
||||
\$ G_{ij} = \sum_{j=0}^{n_{FS}-1} \log(\mathbf{r}_{ij}) \$
|
||||
@param x Free surface z coordinates.
|
||||
@param pos Point to evaluate.
|
||||
@param fs Free surface instance.
|
||||
@return Free surface effect row.
|
||||
"""
|
||||
nx = fs['Nx']
|
||||
ny = 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(fs['pos'][i,j])
|
||||
source[2] = x[i,j]
|
||||
area = fs['area'][i,j]
|
||||
normal = fs['normal'][i,j]
|
||||
source = source + np.sqrt(area)*normal
|
||||
# Get union vector between points
|
||||
r = pos-source
|
||||
row[i*ny+j] = area * 0.5*np.log(np.dot(r,r))
|
||||
return row
|
||||
|
||||
def fsH(self, index, x, pos, fs):
|
||||
r""" Compute free surface terms potential gradient effect over desired position. Desingularized
|
||||
sources must taken into account.
|
||||
\$ H_{ij} = \sum_{j=0}^{n_{FS}-1} \frac{\mathbf{r}_{ij}}{\vert \mathbf{r}_{ij} \vert^2} \$
|
||||
When the point effect over himself is considered, -1/2 must be append.
|
||||
@param index Potential point index.
|
||||
@param x Free surface z coordinates.
|
||||
@param pos Point to evaluate.
|
||||
@param fs Free surface instance.
|
||||
@return Free surface effect row.
|
||||
"""
|
||||
nx = fs['Nx']
|
||||
ny = 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(fs['pos'][i,j])
|
||||
source[2] = x[i,j]
|
||||
area = fs['area'][i,j]
|
||||
normal = fs['normal'][i,j]
|
||||
source = source + np.sqrt(area)*normal
|
||||
# Get union vector between points
|
||||
r = pos-source
|
||||
row[i*ny+j] = area * np.dot(r,normal) / np.dot(r,r)
|
||||
# If effect over himslef is considered, apply the correction
|
||||
if(index == i*ny+j):
|
||||
row[i*ny+j] = row[i*ny+j] - 0.5
|
||||
return row
|
||||
|
||||
def seaG(self, pos, sea):
|
||||
r""" Compute sea boundary terms potential effect over desired position. Desingularized
|
||||
sources must taken into account.
|
||||
\$ G_{ij} = \sum_{j=0}^{n_{FS}-1} \log(\mathbf{r}_{ij}) \$
|
||||
@param pos Point to evaluate.
|
||||
@param sea Sea boundaries instance.
|
||||
@return Sea boundaries effect row.
|
||||
"""
|
||||
ids = ['front','back','left','right','bottom']
|
||||
count = 0
|
||||
row = np.ndarray(sea['N'], dtype=np.float32)
|
||||
for index in ids:
|
||||
s = sea[index]
|
||||
nx = s['Nx']
|
||||
ny = s['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
# Get source position (desingularized)
|
||||
source = np.copy(s['pos'][i,j])
|
||||
area = s['area'][i,j]
|
||||
normal = s['normal'][i,j]
|
||||
source = source + np.sqrt(area)*normal
|
||||
# Get distance between points
|
||||
r = pos-source
|
||||
row[count] = area * 0.5*np.log(np.dot(r,r))
|
||||
count = count + 1
|
||||
return row
|
||||
|
||||
def seaH(self, index, pos, fs, sea):
|
||||
r""" Compute sea boundary terms potential gradient effect over desired position. Desingularized
|
||||
sources must taken into account.
|
||||
\$ H_{ij} = \sum_{j=0}^{n_{FS}-1} \frac{\mathbf{r}_{ij}}{\vert \mathbf{r}_{ij} \vert^2} \$
|
||||
When the point effect over himself is considered, -1/2 must be append.
|
||||
@param index Potential point index.
|
||||
@param pos Point to evaluate.
|
||||
@param fs Free surface instance.
|
||||
@param sea Sea boundaries instance.
|
||||
@return Sea boundaries effect row.
|
||||
"""
|
||||
nF = fs['N']
|
||||
ids = ['front','back','left','right','bottom']
|
||||
count = 0
|
||||
row = np.ndarray(sea['N'], dtype=np.float32)
|
||||
for index in ids:
|
||||
s = sea[index]
|
||||
nx = s['Nx']
|
||||
ny = s['Ny']
|
||||
for i in range(0,nx):
|
||||
for j in range(0,ny):
|
||||
# Get source position (desingularized)
|
||||
source = np.copy(s['pos'][i,j])
|
||||
area = s['area'][i,j]
|
||||
normal = s['normal'][i,j]
|
||||
source = source + np.sqrt(area)*normal
|
||||
# Get distance between points
|
||||
r = pos-source
|
||||
row[count] = area * np.dot(r,normal) / np.dot(r,r)
|
||||
# If effect over himslef is considered, apply the correction
|
||||
if(index == count+nF):
|
||||
row[count] = row[count] - 0.5
|
||||
count = count + 1
|
||||
return row
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user