style: Use enumerations for macros and use more useful function names
Update the pre-compiler macros defined by `BTCSBoundaryCondition` to enumerations. Update method names for getting row and column boundary conditions.
This commit is contained in:
parent
c4334164a3
commit
efed757a9e
@ -11,40 +11,20 @@ typedef uint8_t bctype;
|
||||
|
||||
namespace Diffusion {
|
||||
|
||||
/**
|
||||
* Defines a closed/Neumann boundary condition.
|
||||
*/
|
||||
static const bctype BC_TYPE_CLOSED = 0;
|
||||
enum {
|
||||
BC_TYPE_CLOSED, /**< Defines a closed/Neumann boundary condition. */
|
||||
BC_TYPE_FLUX, /**< Defines a flux/Cauchy boundary condition. */
|
||||
BC_TYPE_CONSTANT /**< Defines a constant/Dirichlet boundary condition. */
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines a flux/Cauchy boundary condition.
|
||||
enum {
|
||||
BC_SIDE_LEFT, /**< Defines boundary conditions for the left side of the grid.
|
||||
*/
|
||||
static const bctype BC_TYPE_FLUX = 1;
|
||||
|
||||
/**
|
||||
* Defines a constant/Dirichlet boundary condition.
|
||||
*/
|
||||
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;
|
||||
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. */
|
||||
BC_SIDE_BOTTOM /**< Defines boundary conditions for the bottom of the grid. */
|
||||
};
|
||||
|
||||
/**
|
||||
* Defines the boundary condition type and according value.
|
||||
@ -57,7 +37,7 @@ typedef struct boundary_condition_s {
|
||||
} boundary_condition;
|
||||
|
||||
/**
|
||||
* Internal use only.
|
||||
* Represents both boundary conditions of a row/column.
|
||||
*/
|
||||
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
|
||||
* 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).
|
||||
@ -139,7 +119,7 @@ public:
|
||||
* \returns Top and bottom boundary values as an array (defined as data
|
||||
* 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
|
||||
|
||||
@ -92,7 +92,7 @@ auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
||||
return out;
|
||||
}
|
||||
|
||||
auto Diffusion::BTCSBoundaryCondition::col(uint32_t i) const
|
||||
auto Diffusion::BTCSBoundaryCondition::col_boundary(uint32_t i) const
|
||||
-> Diffusion::bc_tuple {
|
||||
if (this->dim == 1) {
|
||||
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]};
|
||||
}
|
||||
|
||||
auto Diffusion::BTCSBoundaryCondition::row(uint32_t i) const
|
||||
auto Diffusion::BTCSBoundaryCondition::row_boundary(uint32_t i) const
|
||||
-> Diffusion::bc_tuple {
|
||||
if (i >= this->sizes[0]) {
|
||||
throw_out_of_range("Index out of range");
|
||||
|
||||
@ -129,7 +129,7 @@ void Diffusion::BTCSDiffusion::simulate1D(
|
||||
|
||||
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));
|
||||
|
||||
c.row(0) << input_field;
|
||||
@ -150,7 +150,7 @@ void Diffusion::BTCSDiffusion::simulate2D(
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int i = 0; i < n_rows; 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));
|
||||
c.row(i) << input_field;
|
||||
}
|
||||
@ -163,7 +163,7 @@ void Diffusion::BTCSDiffusion::simulate2D(
|
||||
#pragma omp parallel for schedule(dynamic)
|
||||
for (int i = 0; i < n_cols; 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));
|
||||
c.col(i) << input_field.transpose();
|
||||
}
|
||||
|
||||
@ -30,15 +30,15 @@ TEST_CASE("1D Boundary Condition") {
|
||||
|
||||
SUBCASE("valid row getter") {
|
||||
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[1].value, 0);
|
||||
}
|
||||
|
||||
SUBCASE("invalid row and col getter") {
|
||||
CHECK_THROWS(bc.row(1));
|
||||
CHECK_THROWS(bc.col(0));
|
||||
CHECK_THROWS(bc.row_boundary(1));
|
||||
CHECK_THROWS(bc.col_boundary(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user