mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-14 09:58:22 +01:00
Merge branch 'update-bc-style' into 'main'
Update bc style See merge request sec34/btcsdiffusion!36
This commit is contained in:
commit
2e2ba6cd82
@ -11,40 +11,20 @@ typedef uint8_t bctype;
|
|||||||
|
|
||||||
namespace Diffusion {
|
namespace Diffusion {
|
||||||
|
|
||||||
/**
|
enum {
|
||||||
* Defines a closed/Neumann boundary condition.
|
BC_TYPE_CLOSED, /**< Defines a closed/Neumann boundary condition. */
|
||||||
*/
|
BC_TYPE_FLUX, /**< Defines a flux/Cauchy boundary condition. */
|
||||||
static const bctype BC_TYPE_CLOSED = 0;
|
BC_TYPE_CONSTANT /**< Defines a constant/Dirichlet boundary condition. */
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
enum {
|
||||||
* Defines a flux/Cauchy boundary condition.
|
BC_SIDE_LEFT, /**< Defines boundary conditions for the left side of the grid.
|
||||||
*/
|
*/
|
||||||
static const bctype BC_TYPE_FLUX = 1;
|
BC_SIDE_RIGHT, /**< Defines boundary conditions for the right side of the
|
||||||
|
grid. */
|
||||||
/**
|
BC_SIDE_TOP, /**< Defines boundary conditions for the top of the grid. */
|
||||||
* Defines a constant/Dirichlet boundary condition.
|
BC_SIDE_BOTTOM /**< Defines boundary conditions for the bottom of the grid. */
|
||||||
*/
|
};
|
||||||
static const bctype BC_TYPE_CONSTANT = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines boundary conditions for the left side of the grid.
|
|
||||||
*/
|
|
||||||
static const uint8_t BC_SIDE_LEFT = 0;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines boundary conditions for the right side of the grid.
|
|
||||||
*/
|
|
||||||
static const uint8_t BC_SIDE_RIGHT = 1;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines boundary conditions for the top of the grid.
|
|
||||||
*/
|
|
||||||
static const uint8_t BC_SIDE_TOP = 2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines boundary conditions for the bottom of the grid.
|
|
||||||
*/
|
|
||||||
static const uint8_t BC_SIDE_BOTTOM = 3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the boundary condition type and according value.
|
* Defines the boundary condition type and according value.
|
||||||
@ -57,7 +37,7 @@ typedef struct boundary_condition_s {
|
|||||||
} boundary_condition;
|
} boundary_condition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal use only.
|
* Represents both boundary conditions of a row/column.
|
||||||
*/
|
*/
|
||||||
typedef std::array<boundary_condition, 2> bc_tuple;
|
typedef std::array<boundary_condition, 2> bc_tuple;
|
||||||
|
|
||||||
@ -129,7 +109,7 @@ public:
|
|||||||
* \returns Left and right boundary values as an array (defined as data
|
* \returns Left and right boundary values as an array (defined as data
|
||||||
* type bc_tuple).
|
* type bc_tuple).
|
||||||
*/
|
*/
|
||||||
auto row(uint32_t i) const -> bc_tuple;
|
auto row_boundary(uint32_t i) const -> bc_tuple;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get both boundary conditions of a given column (top and bottom).
|
* Get both boundary conditions of a given column (top and bottom).
|
||||||
@ -139,7 +119,7 @@ public:
|
|||||||
* \returns Top and bottom boundary values as an array (defined as data
|
* \returns Top and bottom boundary values as an array (defined as data
|
||||||
* type bc_tuple).
|
* type bc_tuple).
|
||||||
*/
|
*/
|
||||||
auto col(uint32_t i) const -> bc_tuple;
|
auto col_boundary(uint32_t i) const -> bc_tuple;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of boundary_condition data type. Can be seen as a helper
|
* Create an instance of boundary_condition data type. Can be seen as a helper
|
||||||
|
|||||||
@ -92,7 +92,7 @@ auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSBoundaryCondition::col(uint32_t i) const
|
auto Diffusion::BTCSBoundaryCondition::col_boundary(uint32_t i) const
|
||||||
-> Diffusion::bc_tuple {
|
-> Diffusion::bc_tuple {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw_invalid_argument("Access of column requires at least 2D grid");
|
throw_invalid_argument("Access of column requires at least 2D grid");
|
||||||
@ -105,7 +105,7 @@ auto Diffusion::BTCSBoundaryCondition::col(uint32_t i) const
|
|||||||
this->bc_internal[BC_SIDE_BOTTOM * this->maxsize + i]};
|
this->bc_internal[BC_SIDE_BOTTOM * this->maxsize + i]};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSBoundaryCondition::row(uint32_t i) const
|
auto Diffusion::BTCSBoundaryCondition::row_boundary(uint32_t i) const
|
||||||
-> Diffusion::bc_tuple {
|
-> Diffusion::bc_tuple {
|
||||||
if (i >= this->sizes[0]) {
|
if (i >= this->sizes[0]) {
|
||||||
throw_out_of_range("Index out of range");
|
throw_out_of_range("Index out of range");
|
||||||
|
|||||||
@ -129,7 +129,7 @@ void Diffusion::BTCSDiffusion::simulate1D(
|
|||||||
|
|
||||||
DVectorRowMajor input_field = c.row(0);
|
DVectorRowMajor input_field = c.row(0);
|
||||||
|
|
||||||
simulate_base(input_field, bc.row(0), alpha, dx, time_step, size,
|
simulate_base(input_field, bc.row_boundary(0), alpha, dx, time_step, size,
|
||||||
Eigen::VectorXd::Constant(size, 0));
|
Eigen::VectorXd::Constant(size, 0));
|
||||||
|
|
||||||
c.row(0) << input_field;
|
c.row(0) << input_field;
|
||||||
@ -150,7 +150,7 @@ void Diffusion::BTCSDiffusion::simulate2D(
|
|||||||
#pragma omp parallel for schedule(dynamic)
|
#pragma omp parallel for schedule(dynamic)
|
||||||
for (int i = 0; i < n_rows; i++) {
|
for (int i = 0; i < n_rows; i++) {
|
||||||
DVectorRowMajor input_field = c.row(i);
|
DVectorRowMajor input_field = c.row(i);
|
||||||
simulate_base(input_field, bc.row(i), alpha.row(i), dx, local_dt, n_cols,
|
simulate_base(input_field, bc.row_boundary(i), alpha.row(i), dx, local_dt, n_cols,
|
||||||
d_ortho.row(i));
|
d_ortho.row(i));
|
||||||
c.row(i) << input_field;
|
c.row(i) << input_field;
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ void Diffusion::BTCSDiffusion::simulate2D(
|
|||||||
#pragma omp parallel for schedule(dynamic)
|
#pragma omp parallel for schedule(dynamic)
|
||||||
for (int i = 0; i < n_cols; i++) {
|
for (int i = 0; i < n_cols; i++) {
|
||||||
DVectorRowMajor input_field = c.col(i);
|
DVectorRowMajor input_field = c.col(i);
|
||||||
simulate_base(input_field, bc.col(i), alpha.col(i), dx, local_dt, n_rows,
|
simulate_base(input_field, bc.col_boundary(i), alpha.col(i), dx, local_dt, n_rows,
|
||||||
d_ortho.row(i));
|
d_ortho.row(i));
|
||||||
c.col(i) << input_field.transpose();
|
c.col(i) << input_field.transpose();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,15 +30,15 @@ TEST_CASE("1D Boundary Condition") {
|
|||||||
|
|
||||||
SUBCASE("valid row getter") {
|
SUBCASE("valid row getter") {
|
||||||
bc(BC_SIDE_LEFT) = bc_set;
|
bc(BC_SIDE_LEFT) = bc_set;
|
||||||
bc_tuple tup = bc.row(0);
|
bc_tuple tup = bc.row_boundary(0);
|
||||||
|
|
||||||
CHECK_EQ(tup[0].value, BC_CONST_VALUE);
|
CHECK_EQ(tup[0].value, BC_CONST_VALUE);
|
||||||
CHECK_EQ(tup[1].value, 0);
|
CHECK_EQ(tup[1].value, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SUBCASE("invalid row and col getter") {
|
SUBCASE("invalid row and col getter") {
|
||||||
CHECK_THROWS(bc.row(1));
|
CHECK_THROWS(bc.row_boundary(1));
|
||||||
CHECK_THROWS(bc.col(0));
|
CHECK_THROWS(bc.col_boundary(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user