Skip to content

Commit

Permalink
switched boundary condition type from boolean to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
xLPMG committed Nov 30, 2023
1 parent fe43386 commit 766ed34
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 67 deletions.
14 changes: 12 additions & 2 deletions src/io/Station.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "../patches/WavePropagation1d.h"
#include "../patches/WavePropagation2d.h"

using Boundary = tsunami_lab::patches::WavePropagation::Boundary;

TEST_CASE("1D test of the station implementation", "[Station], [WavePropagation1d]")
{
/*
Expand All @@ -31,7 +33,10 @@ TEST_CASE("1D test of the station implementation", "[Station], [WavePropagation1
*/

std::vector<tsunami_lab::io::Station *> m_stations;
tsunami_lab::patches::WavePropagation1d m_waveProp(100, "fwave", false, false);
tsunami_lab::patches::WavePropagation1d m_waveProp(100,
"fwave",
Boundary::OUTFLOW,
Boundary::OUTFLOW);

for (std::size_t l_ce = 0; l_ce < 50; l_ce++)
{
Expand Down Expand Up @@ -121,7 +126,12 @@ TEST_CASE("2D test of the station implementation", "[Station],[WavePropagation2d

// construct solver and setup a dambreak problem
std::vector<tsunami_lab::io::Station *> m_stations;
tsunami_lab::patches::WavePropagation2d m_waveProp(100, 100, false, false, false, false);
tsunami_lab::patches::WavePropagation2d m_waveProp(100,
100,
Boundary::OUTFLOW,
Boundary::OUTFLOW,
Boundary::OUTFLOW,
Boundary::OUTFLOW);

for (std::size_t l_ce = 0; l_ce < 50; l_ce++)
{
Expand Down
60 changes: 42 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <netcdf.h>

using json = nlohmann::json;
using Boundary = tsunami_lab::patches::WavePropagation::Boundary;

bool endsWith(std::string const &str, std::string const &suffix)
{
Expand Down Expand Up @@ -86,10 +87,11 @@ int main(int i_argc,
tsunami_lab::t_real l_dy = 1;
// solver default
std::string l_solver = "";
bool l_hasBoundaryL = false;
bool l_hasBoundaryR = false;
bool l_hasBoundaryT = false;
bool l_hasBoundaryB = false;
// boundary conditions
Boundary l_boundaryL = Boundary::OUTFLOW;
Boundary l_boundaryR = Boundary::OUTFLOW;
Boundary l_boundaryT = Boundary::OUTFLOW;
Boundary l_boundaryB = Boundary::OUTFLOW;
// input file paths
std::string l_bathymetryFilePath = "";
std::string l_displacementFilePath = "";
Expand Down Expand Up @@ -122,19 +124,42 @@ int main(int i_argc,

l_setupChoice = l_configData.value("setup", "CIRCULARDAMBREAK2D");
l_solver = l_configData.value("solver", "fwave");
// read size config
l_nx = l_configData.value("nx", 1);
l_ny = l_configData.value("ny", 1);
l_simulationSizeX = l_configData.value("simulationSizeX", 1);
l_simulationSizeY = l_configData.value("simulationSizeY", 1);
l_offsetX = l_configData.value("offsetX", 0);
l_offsetY = l_configData.value("offsetY", 0);
l_hasBoundaryL = l_configData.value("hasBoundaryL", false);
l_hasBoundaryR = l_configData.value("hasBoundaryR", false);
l_hasBoundaryT = l_configData.value("hasBoundaryT", false);
l_hasBoundaryB = l_configData.value("hasBoundaryB", false);
l_endTime = l_configData.value("endTime", 20);
// read boundary config
std::string l_boundaryStringL = l_configData.value("boundaryL", "outflow");
if (l_boundaryStringL == "outflow" || l_boundaryStringL == "OUTFLOW")
l_boundaryL = Boundary::OUTFLOW;
else if (l_boundaryStringL == "wall" || l_boundaryStringL == "WALL")
l_boundaryL = Boundary::WALL;

std::string l_boundaryStringR = l_configData.value("boundaryR", "outflow");
if (l_boundaryStringR == "outflow" || l_boundaryStringR == "OUTFLOW")
l_boundaryR = Boundary::OUTFLOW;
else if (l_boundaryStringR == "wall" || l_boundaryStringR == "WALL")
l_boundaryR = Boundary::WALL;

std::string l_boundaryStringT = l_configData.value("boundaryT", "outflow");
if (l_boundaryStringT == "outflow" || l_boundaryStringT == "OUTFLOW")
l_boundaryT = Boundary::OUTFLOW;
else if (l_boundaryStringT == "wall" || l_boundaryStringT == "WALL")
l_boundaryT = Boundary::WALL;

std::string l_boundaryStringB = l_configData.value("boundaryB", "outflow");
if (l_boundaryStringB == "outflow" || l_boundaryStringB == "OUTFLOW")
l_boundaryB = Boundary::OUTFLOW;
else if (l_boundaryStringB == "wall" || l_boundaryStringB == "WALL")
l_boundaryB = Boundary::WALL;
// read file paths from config
l_bathymetryFilePath = l_configData.value("bathymetry", "");
l_displacementFilePath = l_configData.value("displacement", "");
l_endTime = l_configData.value("endTime", 20);
// read station data
l_stationFrequency = l_configData.value("stationFrequency", 1);
std::string l_outputMethod = l_configData.value("outputMethod", "netcdf");
if (l_outputMethod == "netcdf" || l_outputMethod == "NETCDF")
Expand Down Expand Up @@ -243,17 +268,17 @@ int main(int i_argc,
{
l_waveProp = new tsunami_lab::patches::WavePropagation1d(l_nx,
l_solver,
l_hasBoundaryL,
l_hasBoundaryR);
l_boundaryL,
l_boundaryR);
}
else
{
l_waveProp = new tsunami_lab::patches::WavePropagation2d(l_nx,
l_ny,
l_hasBoundaryL,
l_hasBoundaryR,
l_hasBoundaryT,
l_hasBoundaryB);
l_boundaryL,
l_boundaryR,
l_boundaryT,
l_boundaryB);
}

// set up stations
Expand Down Expand Up @@ -387,7 +412,7 @@ int main(int i_argc,
else
{
l_dt = 0.45 * std::min(l_dx, l_dy) / l_speedMax;
l_dt *= 0.5;
// l_dt *= 0.5;
}

// derive scaling for a time step
Expand All @@ -399,8 +424,7 @@ int main(int i_argc,
tsunami_lab::t_idx l_nOut = 0;
tsunami_lab::t_real l_simTime = 0;
tsunami_lab::t_idx l_captureCount = 0;
tsunami_lab::t_idx l_writingFrequency = (l_endTime * 0.04) + 50;
l_writingFrequency = (l_endTime / 4) < l_writingFrequency ? (l_endTime / 4) : l_writingFrequency;
tsunami_lab::t_idx l_writingFrequency = 100;
std::cout << "Writing every " << l_writingFrequency << " time steps" << std::endl;
std::cout << "entering time loop" << std::endl;

Expand Down
6 changes: 6 additions & 0 deletions src/patches/WavePropagation.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ namespace tsunami_lab
class tsunami_lab::patches::WavePropagation
{
public:
enum Boundary
{
OUTFLOW = 0,
WALL = 1
};

/**
* Virtual destructor for base class.
**/
Expand Down
12 changes: 6 additions & 6 deletions src/patches/WavePropagation1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@

tsunami_lab::patches::WavePropagation1d::WavePropagation1d(t_idx i_nCells,
const std::string &i_solver,
bool i_hasBoundaryL,
bool i_hasBoundaryR)
Boundary i_boundaryL,
Boundary i_boundaryR)
{
m_nCells = i_nCells;
m_solver = i_solver;
m_hasBoundaryL = i_hasBoundaryL;
m_hasBoundaryR = i_hasBoundaryR;
m_boundaryL = i_boundaryL;
m_boundaryR = i_boundaryR;

// allocate memory including a single ghost cell on each side
for (unsigned short l_st = 0; l_st < 2; l_st++)
Expand Down Expand Up @@ -146,7 +146,7 @@ void tsunami_lab::patches::WavePropagation1d::setGhostOutflow()
t_real *l_b = m_b;

// left boundary
if (m_hasBoundaryL)
if (m_boundaryL == WALL)
{
l_h[0] = 0;
}
Expand All @@ -157,7 +157,7 @@ void tsunami_lab::patches::WavePropagation1d::setGhostOutflow()
l_b[0] = l_b[1];
}
// right boundary
if (m_hasBoundaryR)
if (m_boundaryR == WALL)
{
l_h[m_nCells + 1] = 0;
}
Expand Down
16 changes: 8 additions & 8 deletions src/patches/WavePropagation1d.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ class tsunami_lab::patches::WavePropagation1d : public WavePropagation
//! selected solver (roe or fwave)
std::string m_solver = "";

//! true if there is a boundary on the left side
bool m_hasBoundaryL = false;
//! boundary condition on the left side
Boundary m_boundaryL = OUTFLOW;

//! true if there is a boundary on the right side
bool m_hasBoundaryR = false;
//! boundary condition on the right side
Boundary m_boundaryR = OUTFLOW;

/**
* Compute the reflection effect
Expand Down Expand Up @@ -76,13 +76,13 @@ class tsunami_lab::patches::WavePropagation1d : public WavePropagation
*
* @param i_nCells number of cells.
* @param i_solver selected solver.
* @param i_hasBoundaryL true if there is a reflecting boundary on the left side
* @param i_hasBoundaryR true if there is a reflecting boundary on the right side
* @param i_boundaryL boundary condition on the left side
* @param i_boundaryR boundary condition on the right side
**/
WavePropagation1d(t_idx i_nCells,
const std::string &i_solver,
bool i_hasBoundaryL,
bool i_hasBoundaryR);
Boundary i_boundaryL,
Boundary i_boundaryR);

/**
* Destructor which frees all allocated memory.
Expand Down
12 changes: 10 additions & 2 deletions src/patches/WavePropagation1d.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "WavePropagation1d.h"
#include "../io/Csv.h"

using Boundary = tsunami_lab::patches::WavePropagation::Boundary;

TEST_CASE("Test the 1d wave propagation solver using roe.", "[WaveProp1d],[Roe]")
{
/*
Expand All @@ -28,7 +30,10 @@ TEST_CASE("Test the 1d wave propagation solver using roe.", "[WaveProp1d],[Roe]"
*/

// construct solver and setup a dambreak problem
tsunami_lab::patches::WavePropagation1d m_waveProp(100, "roe", false, false);
tsunami_lab::patches::WavePropagation1d m_waveProp(100,
"roe",
Boundary::OUTFLOW,
Boundary::OUTFLOW);

for (std::size_t l_ce = 0; l_ce < 50; l_ce++)
{
Expand Down Expand Up @@ -97,7 +102,10 @@ TEST_CASE("Test the 1d wave propagation solver using fwave.", "[WaveProp1d],[Fwa
*/

// construct solver and setup a dambreak problem
tsunami_lab::patches::WavePropagation1d m_waveProp(100, "fwave", false, false);
tsunami_lab::patches::WavePropagation1d m_waveProp(100,
"fwave",
Boundary::OUTFLOW,
Boundary::OUTFLOW);

for (std::size_t l_ce = 0; l_ce < 50; l_ce++)
{
Expand Down
24 changes: 12 additions & 12 deletions src/patches/WavePropagation2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@

tsunami_lab::patches::WavePropagation2d::WavePropagation2d(t_idx i_nCellsX,
t_idx i_nCellsY,
bool i_hasBoundaryL,
bool i_hasBoundaryR,
bool i_hasBoundaryT,
bool i_hasBoundaryB)
Boundary i_boundaryL,
Boundary i_boundaryR,
Boundary i_boundaryT,
Boundary i_boundaryB)
{
m_nCellsX = i_nCellsX;
m_nCellsY = i_nCellsY;
m_hasBoundaryL = i_hasBoundaryL;
m_hasBoundaryR = i_hasBoundaryR;
m_hasBoundaryT = i_hasBoundaryT;
m_hasBoundaryB = i_hasBoundaryB;
m_boundaryL = i_boundaryL;
m_boundaryR = i_boundaryR;
m_boundaryT = i_boundaryT;
m_boundaryB = i_boundaryB;

// allocate memory including a single ghost cell on each side
t_idx l_totalCells = (m_nCellsX + 2) * (m_nCellsY + 2);
Expand Down Expand Up @@ -223,12 +223,12 @@ void tsunami_lab::patches::WavePropagation2d::setGhostOutflow()
t_idx ceL = getStride() * i;
t_idx ceR = ceL + m_nCellsX + 1;
// left column
l_h[ceL] = m_hasBoundaryL ? 0 : l_h[ceL + 1];
l_h[ceL] = m_boundaryL ? OUTFLOW : l_h[ceL + 1];
l_huX[ceL] = l_huX[ceL + 1];
l_huY[ceL] = l_huY[ceL + 1];
l_b[ceL] = l_b[ceL + 1];
// right column
l_h[ceR] = m_hasBoundaryR ? 0 : l_h[ceR - 1];
l_h[ceR] = m_boundaryR ? OUTFLOW : l_h[ceR - 1];
l_huX[ceR] = l_huX[ceR - 1];
l_huY[ceR] = l_huY[ceR - 1];
l_b[ceR] = l_b[ceR - 1];
Expand All @@ -238,12 +238,12 @@ void tsunami_lab::patches::WavePropagation2d::setGhostOutflow()
t_idx ceB = i;
t_idx ceT = i + (m_nCellsY + 1) * getStride();
// bottom row
l_h[ceB] = m_hasBoundaryB ? 0 : l_h[ceB + getStride()];
l_h[ceB] = m_boundaryB ? OUTFLOW : l_h[ceB + getStride()];
l_huX[ceB] = l_huX[ceB + getStride()];
l_huY[ceB] = l_huY[ceB + getStride()];
l_b[ceB] = l_b[ceB + getStride()];
// top row
l_h[ceT] = m_hasBoundaryT ? 0 : l_h[ceT - getStride()];
l_h[ceT] = m_boundaryT ? OUTFLOW : l_h[ceT - getStride()];
l_huX[ceT] = l_huX[ceT - getStride()];
l_huY[ceT] = l_huY[ceT - getStride()];
l_b[ceT] = l_b[ceT - getStride()];
Expand Down
32 changes: 16 additions & 16 deletions src/patches/WavePropagation2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ class tsunami_lab::patches::WavePropagation2d : public WavePropagation
//! bathymetry
t_real *m_b = nullptr;

//! true if there is a boundary on the left side
bool m_hasBoundaryL = false;
//! boundary condition on the left side
Boundary m_boundaryL = OUTFLOW;

//! true if there is a boundary on the right side
bool m_hasBoundaryR = false;
//! boundary condition on the right side
Boundary m_boundaryR = OUTFLOW;

//! true if there is a boundary on the top side
bool m_hasBoundaryT = false;
//! boundary condition on the top side
Boundary m_boundaryT = OUTFLOW;

//! true if there is a boundary on the bottom side
bool m_hasBoundaryB = false;
//! boundary condition on the bottom side
Boundary m_boundaryB = OUTFLOW;

/**
* Compute the reflection effect
Expand Down Expand Up @@ -84,17 +84,17 @@ class tsunami_lab::patches::WavePropagation2d : public WavePropagation
*
* @param i_nCellsX number of cells in x direction.
* @param i_nCellsY number of cells in y direction.
* @param i_hasBoundaryL has boundary on the left side
* @param i_hasBoundaryR has boundary on the left side
* @param i_hasBoundaryT has boundary on the top side
* @param i_hasBoundaryB has boundary on the bottom side
* @param i_boundaryL boundary condition on the left side
* @param i_boundaryR boundary condition on the left side
* @param i_boundaryT boundary condition on the top side
* @param i_boundaryB boundary condition on the bottom side
**/
WavePropagation2d(t_idx i_nCellsX,
t_idx i_nCellsY,
bool i_hasBoundaryL,
bool i_hasBoundaryR,
bool i_hasBoundaryT,
bool i_hasBoundaryB);
Boundary i_boundaryL,
Boundary i_boundaryR,
Boundary i_boundaryT,
Boundary i_boundaryB);

/**
* Destructor which frees all allocated memory.
Expand Down
9 changes: 8 additions & 1 deletion src/patches/WavePropagation2d.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <catch2/catch.hpp>
#include "WavePropagation2d.h"

using Boundary = tsunami_lab::patches::WavePropagation::Boundary;

TEST_CASE("Test the 2d wave propagation solver using fwave.", "[WaveProp2d]")
{
/*
Expand All @@ -27,7 +29,12 @@ TEST_CASE("Test the 2d wave propagation solver using fwave.", "[WaveProp2d]")
*/

// construct solver and setup a dambreak problem
tsunami_lab::patches::WavePropagation2d m_waveProp(100, 100, false, false, true, true);
tsunami_lab::patches::WavePropagation2d m_waveProp(100,
100,
Boundary::OUTFLOW,
Boundary::OUTFLOW,
Boundary::OUTFLOW,
Boundary::OUTFLOW);

std::size_t stride = 100 + 2;

Expand Down
Loading

0 comments on commit 766ed34

Please sign in to comment.