Skip to content
This repository was archived by the owner on Jul 12, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bemio/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from __version__ import base, full
from __future__ import absolute_import
from .__version__ import base, full
32 changes: 16 additions & 16 deletions bemio/data_structures/bem.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import division

from __future__ import division
import numpy as np

import os
Expand Down Expand Up @@ -266,9 +266,9 @@ def calc_irf_excitation(self, t_end=100.0, n_t=1001, n_w=1001, w_min=None, w_max
count = 1
for t_ind, t in enumerate(self.ex.irf.t):

for i in xrange(self.ex.mag.shape[0]):
for i in range(self.ex.mag.shape[0]):

for j in xrange(self.ex.mag.shape[1]):
for j in range(self.ex.mag.shape[1]):
tmp = ex_re_interp[i, j, :] * np.cos(self.ex.irf.w * t) - ex_im_interp[i, j, :] * np.sin(self.ex.irf.w * t)
tmp *= 1. / np.pi
self.ex.irf.f[i, j, t_ind] = np.trapz(y=tmp, x=self.ex.irf.w)
Expand Down Expand Up @@ -353,9 +353,9 @@ def calc_irf_radiation(self, t_end=100., n_t=1001, n_w=1001, w_min=None, w_max=N
count = 1
for t_ind, t in enumerate(self.rd.irf.t):

for i in xrange(self.rd.all.shape[0]):
for i in range(self.rd.all.shape[0]):

for j in xrange(self.rd.all.shape[1]):
for j in range(self.rd.all.shape[1]):
# Radiation damping calculation method
tmpL = 2. / np.pi * rd_interp[i, j, :] * np.sin(self.rd.irf.w * t)
tmpK = 2. / np.pi * rd_interp[i, j, :] * np.cos(self.rd.irf.w * t)
Expand Down Expand Up @@ -426,9 +426,9 @@ def calc_ss_radiation(self, max_order=10, r2_thresh=0.95):

pbar = ProgressBar(widgets=['Radiation damping state space realization for ' + self.name + ':', Percentage(), Bar()], maxval=self.am.inf.shape[0] * self.am.inf.shape[1]).start()
count = 0
for i in xrange(self.am.inf.shape[0]):
for i in range(self.am.inf.shape[0]):

for j in xrange(self.am.inf.shape[1]):
for j in range(self.am.inf.shape[1]):

r2bt = np.linalg.norm(
self.rd.irf.K[i, j, :] - self.rd.irf.K.mean(axis=2)[i, j])
Expand Down Expand Up @@ -472,7 +472,7 @@ def calc_ss_radiation(self, max_order=10, r2_thresh=0.95):
# D - T/2C (2/T(I + A)^{-1})B = D - C(I + A)^{-1})B
dc = d + CoeC * np.dot(np.dot(c, iidd), b)

for jj in xrange(self.rd.irf.t.size):
for jj in range(self.rd.irf.t.size):

# Calculate impulse response function from state space
# approximation
Expand Down Expand Up @@ -549,11 +549,11 @@ def scale(self, scale=None):
self.scale = scale

if self.scale is True and self.scaled is False:
print '\tScaling hydro coefficients for body ' + self.name + ' by rho, g, and w...'
print('\tScaling hydro coefficients for body ' + self.name + ' by rho, g, and w...')
try:
self.k *= self.rho * self.g
except:
print '\t\tSpring stiffness not scaled'
print('\t\tSpring stiffness not scaled')

self.am.all *= self.rho
self.am.inf *= self.rho
Expand All @@ -575,18 +575,18 @@ def scale(self, scale=None):
self.ex.fk.im *= self.rho * self.g


for j in xrange(self.rd.all.shape[2]):
for j in range(self.rd.all.shape[2]):

self.rd.all[:, :, j] = self.rd.all[:, :, j] * self.rho * self.w[j]

self.scaled = True

elif self.scale is False and self.scaled is True:
print '\tUn-scaling hydro coefficients for body ' + self.name + ' by rho, g, and w...'
print('\tUn-scaling hydro coefficients for body ' + self.name + ' by rho, g, and w...')
try:
self.k /= (self.rho * self.g)
except:
print '\t\tSpring stiffness not un-scaled'
print('\t\tSpring stiffness not un-scaled')
self.am.all /= self.rho
self.am.inf /= self.rho
if hasattr(self.am,'zero') is True:
Expand All @@ -606,7 +606,7 @@ def scale(self, scale=None):
self.ex.fk.re /= (self.rho * self.g)
self.ex.fk.im /= (self.rho * self.g)

for j in xrange(self.rd.all.shape[2]):
for j in range(self.rd.all.shape[2]):

self.rd.all[:, :, j] = self.rd.all[:, :, j] / (self.rho * self.w[j])

Expand All @@ -630,9 +630,9 @@ def _interpolate_for_irf(w_orig, w_interp, mat_in):

w_tmp = w_orig

for i in xrange(mat_in.shape[0]):
for i in range(mat_in.shape[0]):

for j in xrange(mat_in.shape[1]):
for j in range(mat_in.shape[1]):

if flip is True:

Expand Down
2 changes: 1 addition & 1 deletion bemio/data_structures/wave_excitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def _excitation_convolution(self):
irf_interp = interpolate.interp1d(x=self.irf.t, y=self.irf.f, bounds_error=False, fill_value=0.)

# Interpolate the IRF to the dt as the wave elevation data
irf = irf_interp(np.linspace(self.irf.t.min(),self.irf.t.max(),(self.irf.t.max()-self.irf.t.min())/self.wave_elevation.dt+1))
irf = irf_interp(np.arange(self.irf.t.min(),self.irf.t.max(),(self.irf.t.max()-self.irf.t.min())/self.wave_elevation.dt+1))

# Assume that the IRF dt is used unless specified by the user
# if self.excitation_force.dt is None:
Expand Down
14 changes: 7 additions & 7 deletions bemio/io/aqwa.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
import numpy as np

from bemio.data_structures import bem

from math import ceil
Expand All @@ -40,7 +40,7 @@ class AqwaOutput(object):
'''
def __init__(self, hydro_file, list_file, scale=False):

print '\nReading the AQWA results in the ' + hydro_file + ' file'
print('\nReading the AQWA results in the ' + hydro_file + ' file')

self.files = bem.generate_file_names(hydro_file)
self.scaled_at_read = scale
Expand Down Expand Up @@ -194,10 +194,10 @@ def _read(self,list_file):
bod_count += 1


for i in xrange(num_bodies):
for i in range(num_bodies):


print 'body' + str(i+1) + ':'
print('body' + str(i+1) + ':')

self.body[i] = bem.HydrodynamicData()
self.body[i].scaled = self.scaled
Expand All @@ -224,14 +224,14 @@ def _read(self,list_file):
self.body[i].bem_raw_data = raw

self.body[i].am.all = np.copy(added_mass[i+1])
print ' * Setting added mass at infinite frequency to added mass at omega = ' + str(frequencies[-1])
print(' * Setting added mass at infinite frequency to added mass at omega = ' + str(frequencies[-1]))
self.body[i].am.inf = np.copy(added_mass[i+1][:,:,-1])
print ' * Setting added mass at zero frequency to added mass at omega = ' + str(frequencies[0])
print(' * Setting added mass at zero frequency to added mass at omega = ' + str(frequencies[0]))
self.body[i].am.zero = np.copy(added_mass[i+1][:,:,0])
self.body[i].rd.all = radiation_damping[i+1]
self.body[i].ex.mag = excitation_magnitude[i+1]
self.body[i].ex.phase = excitation_phase[i+1]
print ' * Calculating real and imaginary excitation components.'
print(' * Calculating real and imaginary excitation components.')
self.body[i].ex.re = self.body[i].ex.mag * np.cos(self.body[i].ex.phase*np.pi/180.)
self.body[i].ex.im = self.body[i].ex.mag * np.sin(self.body[i].ex.phase*np.pi/180.)

Expand Down
34 changes: 18 additions & 16 deletions bemio/io/nemoh.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import print_function
from __future__ import division

import os
Expand Down Expand Up @@ -60,7 +62,7 @@ def __init__(self, sim_dir='./', cal_file='Nemoh.cal', results_dir = 'Results',
self.scaled = True
self.dir = os.path.abspath(sim_dir)

print '\nReading NEMOH output in the ' + self.dir + ' directory'
print('\nReading NEMOH output in the ' + self.dir + ' directory')

self.files = bem.generate_file_names(os.path.join(self.dir,cal_file))
self.files['Nemoh'] = os.path.join(self.dir,cal_file)
Expand All @@ -75,7 +77,7 @@ def __init__(self, sim_dir='./', cal_file='Nemoh.cal', results_dir = 'Results',
try:
self.files['IRF'] = os.path.join(self.dir,results_dir,'IRF.tec')
except:
print '\tNo IRF forces or infinite frequency added mass forces read because the ' + self.files['IRF'] + ' was not found'
print('\tNo IRF forces or infinite frequency added mass forces read because the ' + self.files['IRF'] + ' was not found')

# Initialize data ovject
self.body = {}
Expand Down Expand Up @@ -110,7 +112,7 @@ def _create_and_load_hydro_data_obj(self):
'''
Function to load hydrodynamic data into HydrodynamicData object
'''
for i in xrange(self.cal.n_bods):
for i in range(self.cal.n_bods):
self.body[i] = bem.HydrodynamicData()
self.body[i].am.all = self.am[0+6*i:6+6*i,:]
self.body[i].rd.all = self.rd[0+6*i:6+6*i,:]
Expand Down Expand Up @@ -168,7 +170,7 @@ def _read_cal(self):

# Read wave directions
temp = cal[-6]
self.cal.wave_dir_n = np.float(temp.split()[0])
self.cal.wave_dir_n = np.int32(temp.split()[0])
self.cal.wave_dir_start = np.float(temp.split()[1])
self.cal.wave_dir_end = np.float(temp.split()[2])
self.cal.wave_dir = np.linspace(self.cal.wave_dir_start,self.cal.wave_dir_end,self.cal.wave_dir_n)
Expand All @@ -189,28 +191,28 @@ def _read_cal(self):
self.cal.add_lines = {}
self.cal.cg = {}
line_count = 0
for i in xrange(self.cal.n_bods):
for i in range(self.cal.n_bods):
name_with_path = cal[8+line_count].split()[0]
self.cal.name[i] = os.path.splitext(os.path.basename(name_with_path))[0]
self.cal.points_panels[i] = cal[9+line_count].split()[0:2]
self.cal.n_dof[i] = int(cal[10+line_count].split()[0])
self.cal.dof[i] = []
self.cal.forces[i] = []
self.cal.add_lines[i] = []
for j in xrange(self.cal.n_dof[i]):
for j in range(self.cal.n_dof[i]):
self.cal.dof[i].append(cal[11+line_count+j])

if int(self.cal.dof[i][-1].split()[0]) == 2:
self.cal.cg[i] = np.array(self.cal.dof[i][-1].split()[4:7],dtype=float)

self.cal.n_forces[i] = int(cal[10+line_count+self.cal.n_dof[i]+1].split()[0])

for j in xrange(self.cal.n_forces[i]):
for j in range(self.cal.n_forces[i]):
self.cal.forces[i].append(cal[11+line_count+j+self.cal.n_dof[i]+1])

self.cal.n_add_lines[i] = int(cal[10 + line_count + self.cal.n_dof[i] + self.cal.n_forces[i] + 2].split()[0])

for j in xrange(self.cal.n_add_lines[i]):
for j in range(self.cal.n_add_lines[i]):
self.cal.add_lines[i].append(cal[11+line_count+j+self.cal.n_dof[i]+self.cal.n_forces[i]+1])

line_count += self.cal.n_dof[i] + self.cal.n_forces[i] + self.cal.n_add_lines[i] + 6
Expand Down Expand Up @@ -247,7 +249,7 @@ def read_kh(self, file, body_num):

if self.body[body_num].scaled is False:
self.body[body_num].k /= (self.body[body_num].rho * self.body[body_num].g)
print '\tSpring stiffness for body ' + self.body[body_num].name + ' scaled by read_kh method'
print('\tSpring stiffness for body ' + self.body[body_num].name + ' scaled by read_kh method')

def read_hydrostatics(self, file, body_num):
'''
Expand Down Expand Up @@ -326,7 +328,7 @@ def _read_tec(file, data_type):


# Sort the zones from the .tec file
zones = proc.keys()
zones = list(proc)
zones.sort()

# Set the frequencies and calculate number of freqs
Expand All @@ -342,13 +344,13 @@ def _read_tec(file, data_type):
b = []

if data_type == 1:
for j in xrange(n_vars):
for j in range(n_vars):
a[j,0,:] = proc[zones[-1]].field(1+j*2)
b[j,0,:] = proc[zones[-1]].field(2+j*2)

if data_type == 2:
for i, zone in enumerate(zones):
for j in xrange(n_vars):
for j in range(n_vars):
a[i,j] = proc[zone].field(1+j*2)[0]

return (a, b, w, raw)
Expand Down Expand Up @@ -379,7 +381,7 @@ def _read_radiation(file, ):


# Sort the zones from the .tec file
zones = proc.keys()
zones = list(proc.keys())
zones.sort()

# Set the frequencies and calculate number of freqs
Expand All @@ -392,7 +394,7 @@ def _read_radiation(file, ):

# Populate matrices
for i, zone in enumerate(zones):
for j in xrange(n_vars):
for j in range(n_vars):
a[i,j,:] = proc[zone].field(1+j*2)
b[i,j,:] = proc[zone].field(2+j*2)

Expand Down Expand Up @@ -433,7 +435,7 @@ def _read_excitation(file, ):


# Sort the zones from the .tec file
zones = proc.keys()
zones = list(proc.keys())
zones.sort()

# Set the frequencies and calculate number of freqs
Expand All @@ -446,7 +448,7 @@ def _read_excitation(file, ):

# Populate matrices
for i, zone in enumerate(zones):
for j in xrange(n_vars):
for j in range(n_vars):
a[j,i,:] = proc[zone].field(1+j*2)
b[j,i,:] = proc[zone].field(2+j*2)

Expand Down
Loading