# Algorithmic Design of an FPGA-Based Calculator for Fast Evaluation of Tsunami Wave Danger

^{1}

^{2}

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Materials and Methods

#### 2.1. Problem Statement

Listing 1. Reference implementation of the convolutional filter. |

void filter (const Pixel * input, int width, int height, Coeff kernel[KERNELSIZE][KERNELSIZE], Pixel * output) { for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Pixel result = 0.0; for (int ky = 0; ky < KERNELSIZE; ky++) { for (int kx = 0; kx < KERNELSIZE; kx++) { result += getPixel(input, width, height, x, y, kx, ky) * kernel[ky * KERNELSIZE + kx]; } } output[y * width + x] = result; } } } |

Listing 2. Pixel sampling. |

inline Pixel getPixel (const Pixel * input, int width, int height, int x, int y, int kx, int ky) { int ix = x + kx − KERNELSIZE/2; int iy = y + ky − KERNELSIZE/2; ix = (ix < 0) ? 0: ((ix ≥ width) ? (width-1): ix); iy = (iy < 0) ? 0: ((iy ≥ height) ? (height-1): iy); return input[iy * width + ix]; } |

#### 2.2. Pipeline (Stream) Algorithm

Listing 3. Stream-based convolutional filter. |

void filter(std::istream & input, int width, int height, Coeff kernel[KERNELSIZE][KERNELSIZE], std::ostream & output){ int ox = -KERNELSIZE/2, oy = -KERNELSIZE/2; int ix = 0, iy = 0; Pixel stencil[KERNELSIZE][MAXWIDTH]; for(int i = 0; i < width*(height + KERNELSIZE/2) + KERNELSIZE/2; i++) { if (iy < height) stencil[iy % KERNELSIZE][ix] = readPixel (input); if ((ox ≥ 0) && (oy ≥ 0)) { Pixel result = 0.0; for (int ky = 0; ky < KERNELSIZE; ky++) { for (int kx = 0; kx < KERNELSIZE; kx++) { int sx = ox + kx − KERNELSIZE/2; int sy = oy + ky − KERNELSIZE/2; sx = (sx < 0) ? 0: ((sx ≥ width) ? (width-1): sx); sy = ((sy < 0) ? 0: ((sy ≥ height) ? (height-1): sy)) %KERNELSIZE; result += stencil[sy][sx] * kernel[ky][kx]; } } WritePixel (output, result); } bool ixend = (ix == width − 1); ix = ixend ? 0: ix + 1; iy = ixend ? (iy + 1): iy; bool oxend = (ox == width − 1); ox = oxend ? 0: ox + 1; oy = oxend ? (oy + 1): oy; } } |

#### 2.3. HLS-Based Algorithm Porting

Listing 4. Vitis HLS pipelining. |

for (int i = 0; i < width*(height + KERNELSIZE/2) + KERNELSIZE/2; i++) { #pragma HLS PIPELINE
…} |

Listing 5. Convolutional filter with array partitioning. |

… Pixel stencil[KERNELSIZE-1][MAXWIDTH]; #pragma HLS ARRAYPARTITION dim = 1 type = complete variable = stencilPixel pixels[KERNELSIZE][KERNELSIZE]; #pragma HLS ARRAYPARTITION dim = 1 type = complete variable = pixels #pragma HLS ARRAYPARTITION dim = 2 type = complete variable = pixels for (int i = 0; i < width*(height + KERNELSIZE/2) + KERNELSIZE/2; i++) { #pragma HLS PIPELINE Pixel cur = 0.0f; if (iy < height) cur = input.read(); for (int ky = 0; ky < KERNELSIZE; ky++) { #pragma HLS UNROLL for (int kx = 0; kx < KERNELSIZE-1; kx++) { #pragma HLS UNROLL pixels[ky][kx] = pixels[ky][kx + 1]; } if (ky != KERNELSIZE-1) pixels[ky][KERNELSIZE-1]= stencil[(iy + ky)%(KERNELSIZE-1)][ix]; else pixels[ky][KERNELSIZE-1] = cur; } stencil[iy % (KERNELSIZE-1)][ix] = cur; if ((ox ≥ 0) && (oy ≥ 0)) { Pixel result = 0.0; for (int ky = 0; ky < KERNELSIZE; ky++) { #pragma HLS UNROLL for (int kx = 0; kx < KERNELSIZE; kx++) { #pragma HLS UNROLL int sx = ox + kx − KERNELSIZE/2; int sy = oy + ky − KERNELSIZE/2; sx = (sx < 0) ? (KERNELSIZE/2-ox): ((sx ≥ width) ? (width-1 + KERNELSIZE/2-ox): kx); sy = (sy < 0) ? (KERNELSIZE/2-oy): ((sy ≥ height) ? (height-1 + KERNELSIZE/2-oy): ky); result += pixels[sy][sx] * kernel[ky][kx]; } } output. write (result); } … |

#### 2.4. Comparison to Verolog Realization

#### 2.5. Tsunami Math Model and Numerical Scheme

^{n}

_{ij}, u

^{n}

_{ij}, and v

^{n}

_{ij}are the gridded variables that correspond to the H, u, and v functions, respectively, in Differential System (1). The parameters τ, Δx, and Δy are the time step and spatial steps of the computational grid. In order to account for the spherical shape of the Earth, we used a decreasing grid step with respect to longitude for larger values of latitude. The notation ${F}_{ij}^{n}$ represents variables at time layer n, ${\stackrel{\u2322}{F}}_{ij}^{n+1}$ represents intermediate values, and ${F}_{ij}^{n+1}$ corresponds to the variables at time layer n + 1.

_{ij}, u

_{ij}and v

_{ij}for the time step n + 1 along the line j = 2 of the gridded arrays, we need the data from the time step n along the lines j = 1,2,3. Wave parameters along the line j = 1 are obtained using the boundary conditions. When the wave parameters for the time step n + 1 are already calculated for at least 3 neighboring lines j = 2,3,4, the calculator #3 can start working to obtain the wave parameters for the time step n + 2 along the line j = 3, and so on (Figure 1). All 8 calculators work simultaneously on wave parameters for 8 time layers. The inner memory of each calculator keeps all data (wave parameters and bathymetry) for one time layer.

## 3. Results

#### 3.1. Numerical Tests at Model Bathymetry

^{2}), where the parameter y represents the distance from the rectilinear coastline. With the spatial steps of the grid in both directions equal to 1000 m, the coefficient k was chosen so that the depth varied from 0 m at the lower boundary (coastline) to 10,000 m at the upper boundary of the computation domain (see Figure 2).

_{0}= 50 km, with the center located at a distance of 300 km from the coastline, and at the same distance from the lateral boundaries of the region. In Figure 2, the area of the initial displacement of the water surface is filled with yellow. The vertical displacement of the water surface in the source was given by the following formula:

_{0}). In Figure 2a,b, showing the results of testing on model bottom reliefs, the upward direction coincides with the offshore direction. The propagation of the wave generated by the described round-shaped source was simulated using MOST software, and by the MacCormack difference scheme implemented on an FPGA. According to the results of calculations for each of the schemes, isolines of distributions of wave height’s maxima over the sloping bottom (Figure 2a) and at the parabolic bottom topography (Figure 2b) were visualized.

#### 3.2. Numerical Results

## 4. Discussion

## Author Contributions

## Funding

## Institutional Review Board Statement

## Informed Consent Statement

## Data Availability Statement

## Conflicts of Interest

## References

- Lavrentiev, M.; Lysakov, K.; Marchuk, A.; Oblaukhov, K.; Shadrin, M. Hardware Acceleration of Tsunami Wave Propagation Modeling in the Southern Part of Japan. Appl. Sci.
**2020**, 10, 4159. [Google Scholar] [CrossRef] - IEEE 1364-2001—IEEE Standard Verilog Hardware Description Language. Available online: https://standards.ieee.org/standard/1364-2001.html (accessed on 20 November 2021).
- MacCormack, R.W.; Paullay, A.J. Computational Efficiency Achieved by Time Splitting of Finite–Difference Operators. In Proceedings of the 10th Aerospace Sciences Meeting, San Diego, CA, USA, 17–19 January 1972; AIAA Paper. pp. 72–154. [Google Scholar]
- Shokin, Y.; Babailov, V.; Beisel, S.; Chubarov, L.; Eletsky, S.; Fedotova, Z.; Gusiakov, V. Mathematical Modeling in Application to Regional Tsunami Warning Systems Operations. In Computational Science and High Performance Computing III: The 3rd Russian-German Advanced Research Workshop; Krause, E., Shokin, Y., Shokina, N., Eds.; Springer Science & Business Media: Berlin, Germany, 2008; pp. 52–68. [Google Scholar]
- Vitis High-Level Synthesis User Guide. Available online: https://www.xilinx.com/support/documentation/sw_manuals/xilinx2021_1/ug1399-vitis-hls.pdf (accessed on 20 November 2021).
- Marchuk, A.G. Estimating Tsunami Wave Height over a Sloping Bottom in the Ray Approximation. Numer. Anal. Appl.
**2015**, 8, 304–313. [Google Scholar] [CrossRef] - Marchuk, A.G. Benchmark solutions for tsunami wave fronts and rays. Part 2: Parabolic bottom topography. Sci. Tsunami Hazards
**2017**, 36, 70–85. [Google Scholar] - Titov, V.V.; Gonzalez, F.I. Implementation and Testing of the Method of Splitting Tsunami (MOST) Model; NOAA Technical Memorandum ERL PMEL-112; Pacific Marine Environmental Laboratory: Seattle, WA, USA, 1997. [Google Scholar]
- Stoker, J.J. Water Waves. The Mathematical Theory with Applications; Interscience publishers: New York, NY, USA, 1957. [Google Scholar]
- JODC 500 m Gridded Bathymetry Data. Available online: https://jdoss1.jodc.go.jp/vpage/depth500_file.html (accessed on 20 November 2021).
- Wei, Y.; Chamberlin, C.; Titov, V.V.; Tang, L.; Bernard, E.N. Modeling of the 2011 Japan Tsunami: Lessons for Near-Field Forecast. Pure Appl. Geophys.
**2013**, 170, 1309–1331. [Google Scholar] [CrossRef] - Grilli, S.T.; Harris, J.C.; Bakhsh, T.T.; Kirby, J.T.; Shi, F.; Masterlark, T.L.; Kyriakopoulos, C. Numerical simulation of the 2011 Tohoku tsunami: Comparison with field observations and sensitivity to model parameters. In Proceedings of the Twenty-second (2012) International Offshore and Polar Engineering Conference, Rhodes, Greece, 17–22 June 2012. [Google Scholar]

**Figure 2.**Comparison of the wave height maxima distributions for the exact solution (green); results obtained via the proposed FPGA-based method (red dashed lines) and MOST single-precision results (blue). (

**a**) The comparison results for sloping bottom topography; (

**b**) the comparison results for the parabolic bottom topography.

**Figure 3.**Digital bathymetry and tsunami source of the 11 March 2011 event. The isolines of the field of vertical elevation of the water surface at an interval of 1 m are drawn in white, and the isolines of the initial abatement of water level are drawn in black. The source is outlined by ±0.05 m level lines. The maximum elevation in the source is limited to +9 m, and the lowest value is equal to −4 m.

**Figure 4.**Distribution of the tsunami height maxima in the entire computational domain, obtained via numerical modeling using the proposed approach.

Implementation | Lines of Code | Maximum Frequency | Number of LUTs | Number of Flip-Flops | Number of BRAMs (36 K) | Number of DSP Blocks |
---|---|---|---|---|---|---|

Naïve HLS | ~40 | 308 MHz | 7364 | 7467 | 198 | 48 |

HLS (148.5 MHz) | ~60 | 308 MHz | 4575 | 5100 | 15 | 39 |

HLS (400 MHz) | ~60 | 637 MHz | 6145 | 9717 | 16 | 30 |

HLS half (400 MHz) | ~60 | 514 MHz | 2875 | 4261 | 8 | 30 |

Verilog | ~280 | 374 MHz | 4302 | 6709 | 15 | 34 |

Implementation | Lines of Code | Maximum Frequency | Number of LUTs | Number of Flip-Flops | Number of BRAMs (36 K) | Number of DSP Blocks |
---|---|---|---|---|---|---|

MacCormack | ~280 | 462 MHz | 29,242 | 49,520 | 64 | 189 |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Lavrentiev, M.; Lysakov, K.; Marchuk, A.; Oblaukhov, K.; Shadrin, M.
Algorithmic Design of an FPGA-Based Calculator for Fast Evaluation of Tsunami Wave Danger. *Algorithms* **2021**, *14*, 343.
https://doi.org/10.3390/a14120343

**AMA Style**

Lavrentiev M, Lysakov K, Marchuk A, Oblaukhov K, Shadrin M.
Algorithmic Design of an FPGA-Based Calculator for Fast Evaluation of Tsunami Wave Danger. *Algorithms*. 2021; 14(12):343.
https://doi.org/10.3390/a14120343

**Chicago/Turabian Style**

Lavrentiev, Mikhail, Konstantin Lysakov, Andrey Marchuk, Konstantin Oblaukhov, and Mikhail Shadrin.
2021. "Algorithmic Design of an FPGA-Based Calculator for Fast Evaluation of Tsunami Wave Danger" *Algorithms* 14, no. 12: 343.
https://doi.org/10.3390/a14120343