3.3 Implementation of hydrodynamic force models
3.3.2 Features of the UiS-Aqua numerical module
This newly developed module mainly includes the three submodules:
enviromentModules, hydroModules and meshModules. Figure 3-8 shows the main contents of this module in a tree-like format. This module is written in Python programing language with many advanced features.
3.3 Implementation of hydrodynamic force models
86 3.3.2.1 Modularity
The UiS-Aqua is developed in a modular style with the goal of minimizing dependencies. The code is split into different files and submodules based on the corresponding functionalities, as shown in Figure 3-8.
src
├── enviromentModules
│ ├── Airywave.py
│ ├── init .py
│ ├── irregularwaves.py
│ └── wave_spectrum.py
├── hydroModules
│ ├── aster.py
│ ├── init .py
│ ├── one_dimensional.py
│ ├── two_dimensional.py
│ └── wake_effect.py
└── meshModules
├── CCT.py
├── CCS.py
├── CSM.py
├── CSM.py
└── SSM.py
Figure 3-8. Contents of the UiS-Aqua numerical module in a tree-like format.
In hydroModules, a wide range of hydrodynamic force models are provided for different nets in dynamic analyses of aquaculture structures.
The flow velocity reduction due to wake effects is also included in this submodule. Besides, a template for the user-defined hydrodynamic force model is also provided for the study of new nets in the future. In
3 Structural modelling of marine aquaculture structures
import numpy as np
from . import Airywave as wave
class summation:
"""
Irregular random waves, representing a real sea state, can be modelled as a summation of sinusoidal wave components.
DNV-RP-C205, Section 3.3.2.1
"""
def init (self, waveSpectrum, water_depth, wave_direction):
"""
Parameters
waveSpectrum: A n*2 array list of wave spectrum, the first column is w, the second is the S(w)
water_depth: water depth of the sea, assume flat sea floor. A position number | float | Unit [m]
wave_direction: direction of wave propagation. | float | Unit [degree]
"""
self.water_depth = water_depth self.list_of_waves = []
enviromentModules, various wave models, such as Airy waves, Stokes 2nd order waves and irregular waves, are provided. In meshModules, the numerical models for commonly used traditional fish cages can be easily built up based on the main design parameters.
Moreover, the submodules can be imported to different projects or other modules. As shown in Figure 3-9, “irregularwaves.py” imports
“Airywave.py” for the irregular random waves, based on the summation of sinusoidal wave components. Thus, the code is readable, reliable and maintainable without too much effort.
3.3 Implementation of hydrodynamic force models
88
Figure 3-9. A piece of code in irregularwaves.py
3.3.2.2 Embeddability
Due to the embeddability feature of the Python programing language, the UiS-Aqua can be embedded with the Code_Aster, which is written using the Fortran programming language. With the UiS-Aqua, Code_Aster can be applied to computationally efficient decoupled simulations to analyze the dynamic responses of fish cages. Moreover, UiS-Aqua can also be invoked in other open-source programs for different purposes, e.g., the two-way coupled simulations with OpenFOAM in Chapter 4 for the complex FSI problem in marine aquaculture structures.
3.3.2.3 Vectorization
Usually, processing a large array of data using Python can be slow as compared to other programming languages, e.g., C/C++. The main reason for this slow computation is due to the dynamic nature of Python and the lack of compiler-level optimizations. In UiS-Aqua, a vectorization technique from Numpy module is implemented to deal with a large array of data. The functions defined by Numpy module are highly optimized that can significantly reduce the elapsed time of code.
d_fre = abs(waveSpectrum[1, 0]-waveSpectrum[0, 0]) for each in waveSpectrum:
xi = np.sqrt(2 * d_fre * each[1]) wave_period = 2 * np.pi / each[0]
self.list_of_waves.append(wave.Airywave(
xi * 2, wave_period, water_depth, wave_direction, np.random.uniform(0, 360)))
3 Structural modelling of marine aquaculture structures
import numpy as np from timeit import Timer
time_list = np.arange(0, 3600, 1) n_wave = 3000
n_time = len(time_list)
waves_velocities = np.zeros((n_wave, len(time_list), 3)) for i in range(n_wave):
waves_velocities[i] = np.random.rand(n_time, 3)
def sum_using_forloop():
velocity_with_time = np.zeros((n_time, 3)) for i in range(n_time):
for j in range(n_wave):
velocity_with_time[i] += waves_velocities[j, i]
def sum_using_numpy():
velocity_with_time = np.zeros((n_time, 3))
velocity_with_time = np.sum(waves_velocities, axis=0)
time_forloop = Timer(sum_using_forloop).timeit(1) time_numpy = Timer(sum_using_numpy).timeit(1)
An example shown in Figure 3-10 illustrates the significant speed- up of the vectorization technique. This example mimics a function inside of “irregularwaves.py”. This function can return a time-series wave particle velocity (ux, uy, uz) at one position based on the summation of the velocity from sinusoidal wave components. In this example, the first function uses the Python for-loop to do the summation and the second function uses the vectorized array operation with Numpy module. The results show that the vectorized array operation can be 1 284 times faster than the pure Python equivalents.
3.3 Implementation of hydrodynamic force models
90
Figure 3-10. Compare the performance of a non-vectorized summation to a vectorized one.
output:
Summing elements takes 26.986129200 units using for loop Summing elements takes 0.021073700 units using numpy
print("Summing elements takes %0.9f units using for loop" % time_forloop) print("Summing elements takes %0.9f units using numpy" % time_numpy)
3 Structural modelling of marine aquaculture structures