Merge branch 'poet' into 'main'

Add changes required for POET into main

See merge request naaice/tug!27
This commit is contained in:
Max Lübke 2024-04-04 13:09:28 +02:00
commit 2dc959b993
6 changed files with 67 additions and 19 deletions

@ -1 +0,0 @@
Subproject commit b7c21ec5ceeadb4951b00396fc1e4642dd347e5f

View File

@ -8,9 +8,11 @@
#define BOUNDARY_H_
#include "Grid.hpp"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <vector>
namespace tug {
@ -106,6 +108,22 @@ private:
*/
template <class T> class Boundary {
public:
/**
* @brief Creates a boundary object for a 1D grid
*
* @param length Length of the grid
*/
Boundary(std::uint32_t length) : Boundary(Grid<T>(length)){};
/**
* @brief Creates a boundary object for a 2D grid
*
* @param rows Number of rows of the grid
* @param cols Number of columns of the grid
*/
Boundary(std::uint32_t rows, std::uint32_t cols)
: Boundary(Grid<T>(rows, cols)){};
/**
* @brief Creates a boundary object based on the passed grid object and
* initializes the boundaries as closed.
@ -325,6 +343,38 @@ public:
return this->boundaries[side][index].getValue();
}
/**
* @brief Serializes the boundary conditions into a vector of BoundaryElement
* objects.
*
* @return Vector with BoundaryElement objects.
*/
std::vector<BoundaryElement<T>> serialize() const {
std::vector<BoundaryElement<T>> serialized;
for (std::size_t side = 0; side < boundaries.size(); side++) {
for (std::size_t index = 0; index < boundaries[side].size(); index++) {
serialized.push_back(boundaries[side][index]);
}
}
return serialized;
}
/**
* @brief Deserializes the boundary conditions from a vector of
* BoundaryElement objects.
*
* @param serialized Vector with BoundaryElement objects.
*/
void deserialize(const std::vector<BoundaryElement<T>> &serialized) {
std::size_t index = 0;
for (std::size_t side = 0; side < boundaries.size(); side++) {
for (std::size_t i = 0; i < boundaries[side].size(); i++) {
boundaries[side][i] = serialized[index];
index++;
}
}
}
private:
const std::uint8_t dim;
const std::uint32_t cols;

View File

@ -57,9 +57,9 @@ public:
*/
Grid(int _row, int _col)
: row(_row), col(_col), domainRow(_row), domainCol(_col) {
if (row <= 3 || col <= 3) {
if (row <= 1 || col <= 1) {
throw std::invalid_argument(
"Given grid dimensions too small. Must each be greater than 3.");
"At least one dimension is 1. Use 1D grid for better results.");
}
this->dim = 2;

View File

@ -1,18 +1,7 @@
find_library(DOCTEST_LIB doctest)
if(NOT DOCTEST_LIB)
include(FetchContent)
FetchContent_Declare(
DocTest
GIT_REPOSITORY https://github.com/doctest/doctest.git
GIT_TAG v2.4.9)
FetchContent_MakeAvailable(DocTest)
endif()
find_package(doctest REQUIRED)
add_executable(testTug setup.cpp testSimulation.cpp testGrid.cpp testFTCS.cpp testBoundary.cpp)
target_link_libraries(testTug doctest tug)
target_link_libraries(testTug doctest::doctest tug)
# get relative path of the CSV file
get_filename_component(testSimulationCSV "FTCS_11_11_7000.csv" REALPATH)

View File

@ -12,12 +12,12 @@ TEST_CASE("1D Grid, too small length") {
}
TEST_CASE("2D Grid64, too small side") {
int r = 2;
int r = 1;
int c = 4;
CHECK_THROWS(Grid64(r, c));
r = 4;
c = 2;
c = 1;
CHECK_THROWS(Grid64(r, c));
}

View File

@ -1,4 +1,14 @@
FROM alpine
MAINTAINER Max Luebke <mluebke@uni-potsdam.de>
LABEL maintainer="Max Luebke <mluebke@uni-potsdam.de"
RUN apk add --no-cache build-base openmp cmake git eigen-dev
RUN git clone https://github.com/doctest/doctest.git /doctest \
&& cd /doctest \
&& mkdir build \
&& cd build \
&& cmake .. \
&& make install \
&& cd / \
&& rm -rf /doctest