mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-14 09:58:22 +01:00
refactor: rename and expand namespace
This commit is contained in:
parent
46185571c0
commit
bdd56bec82
@ -13,7 +13,9 @@
|
|||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Diffusion {
|
namespace tug {
|
||||||
|
namespace diffusion {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Class implementing a solution for a 1/2/3D diffusion equation using backward
|
* Class implementing a solution for a 1/2/3D diffusion equation using backward
|
||||||
* euler.
|
* euler.
|
||||||
@ -97,7 +99,8 @@ public:
|
|||||||
*
|
*
|
||||||
* \return Time in seconds [s] used to simulate one iteration.
|
* \return Time in seconds [s] used to simulate one iteration.
|
||||||
*/
|
*/
|
||||||
auto simulate(double *c, double *alpha, const BTCSBoundaryCondition &bc)
|
auto simulate(double *c, double *alpha,
|
||||||
|
const tug::boundary_condition::BTCSBoundaryCondition &bc)
|
||||||
-> double;
|
-> double;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -113,42 +116,43 @@ private:
|
|||||||
typedef Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor>
|
typedef Eigen::Matrix<double, 1, Eigen::Dynamic, Eigen::RowMajor>
|
||||||
DVectorRowMajor;
|
DVectorRowMajor;
|
||||||
|
|
||||||
static void simulate_base(DVectorRowMajor &c, const bc_tuple &bc_ghosts,
|
static void simulate_base(DVectorRowMajor &c,
|
||||||
const bc_vec &bc_inner,
|
const tug::boundary_condition::bc_tuple &bc_ghosts,
|
||||||
|
const tug::boundary_condition::bc_vec &bc_inner,
|
||||||
const DVectorRowMajor &alpha, double dx,
|
const DVectorRowMajor &alpha, double dx,
|
||||||
double time_step, int size,
|
double time_step, int size,
|
||||||
const DVectorRowMajor &d_ortho);
|
const DVectorRowMajor &d_ortho);
|
||||||
|
|
||||||
void simulate1D(Eigen::Map<DVectorRowMajor> &c,
|
void simulate1D(Eigen::Map<DVectorRowMajor> &c,
|
||||||
Eigen::Map<const DVectorRowMajor> &alpha,
|
Eigen::Map<const DVectorRowMajor> &alpha,
|
||||||
const BTCSBoundaryCondition &bc);
|
const tug::boundary_condition::BTCSBoundaryCondition &bc);
|
||||||
|
|
||||||
void simulate2D(Eigen::Map<DMatrixRowMajor> &c,
|
void simulate2D(Eigen::Map<DMatrixRowMajor> &c,
|
||||||
Eigen::Map<const DMatrixRowMajor> &alpha,
|
Eigen::Map<const DMatrixRowMajor> &alpha,
|
||||||
const BTCSBoundaryCondition &bc);
|
const tug::boundary_condition::BTCSBoundaryCondition &bc);
|
||||||
|
|
||||||
static auto calc_d_ortho(const DMatrixRowMajor &c,
|
static auto
|
||||||
const DMatrixRowMajor &alpha,
|
calc_d_ortho(const DMatrixRowMajor &c, const DMatrixRowMajor &alpha,
|
||||||
const BTCSBoundaryCondition &bc, bool transposed,
|
const tug::boundary_condition::BTCSBoundaryCondition &bc,
|
||||||
double time_step, double dx) -> DMatrixRowMajor;
|
bool transposed, double time_step, double dx) -> DMatrixRowMajor;
|
||||||
|
|
||||||
static void fillMatrixFromRow(Eigen::SparseMatrix<double> &A_matrix,
|
static void fillMatrixFromRow(Eigen::SparseMatrix<double> &A_matrix,
|
||||||
const DVectorRowMajor &alpha,
|
const DVectorRowMajor &alpha,
|
||||||
const bc_vec &bc_inner, int size, double dx,
|
const tug::boundary_condition::bc_vec &bc_inner,
|
||||||
double time_step);
|
int size, double dx, double time_step);
|
||||||
|
|
||||||
static void fillVectorFromRow(Eigen::VectorXd &b_vector,
|
static void
|
||||||
const DVectorRowMajor &c,
|
fillVectorFromRow(Eigen::VectorXd &b_vector, const DVectorRowMajor &c,
|
||||||
const DVectorRowMajor &alpha,
|
const DVectorRowMajor &alpha,
|
||||||
const bc_tuple &bc_ghosts,
|
const tug::boundary_condition::bc_tuple &bc_ghosts,
|
||||||
const bc_vec &bc_inner,
|
const tug::boundary_condition::bc_vec &bc_inner,
|
||||||
const DVectorRowMajor &d_ortho, int size,
|
const DVectorRowMajor &d_ortho, int size, double dx,
|
||||||
double dx, double time_step);
|
double time_step);
|
||||||
void simulate3D(std::vector<double> &c);
|
void simulate3D(std::vector<double> &c);
|
||||||
|
|
||||||
inline static auto getBCFromFlux(Diffusion::boundary_condition bc,
|
inline static auto
|
||||||
double neighbor_c, double neighbor_alpha)
|
getBCFromFlux(tug::boundary_condition::boundary_condition bc,
|
||||||
-> double;
|
double neighbor_c, double neighbor_alpha) -> double;
|
||||||
|
|
||||||
void updateInternals();
|
void updateInternals();
|
||||||
|
|
||||||
@ -159,5 +163,6 @@ private:
|
|||||||
std::vector<double> domain_size;
|
std::vector<double> domain_size;
|
||||||
std::vector<double> deltas;
|
std::vector<double> deltas;
|
||||||
};
|
};
|
||||||
} // namespace Diffusion
|
} // namespace diffusion
|
||||||
|
} // namespace tug
|
||||||
#endif // BTCSDIFFUSION_H_
|
#endif // BTCSDIFFUSION_H_
|
||||||
|
|||||||
@ -9,7 +9,8 @@
|
|||||||
|
|
||||||
typedef uint8_t bctype;
|
typedef uint8_t bctype;
|
||||||
|
|
||||||
namespace Diffusion {
|
namespace tug {
|
||||||
|
namespace boundary_condition {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
BC_TYPE_CLOSED, /**< Defines a closed/Neumann boundary condition. */
|
BC_TYPE_CLOSED, /**< Defines a closed/Neumann boundary condition. */
|
||||||
@ -259,6 +260,6 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Diffusion
|
} // namespace boundary_condition
|
||||||
|
} // namespace tug
|
||||||
#endif // BOUNDARYCONDITION_H_
|
#endif // BOUNDARYCONDITION_H_
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
constexpr uint8_t DIM_1D = 2;
|
constexpr uint8_t DIM_1D = 2;
|
||||||
constexpr uint8_t DIM_2D = 4;
|
constexpr uint8_t DIM_2D = 4;
|
||||||
|
|
||||||
Diffusion::BTCSBoundaryCondition::BTCSBoundaryCondition(int x) {
|
tug::boundary_condition::BTCSBoundaryCondition::BTCSBoundaryCondition(int x) {
|
||||||
this->bc_internal.resize(DIM_1D, {0, 0});
|
this->bc_internal.resize(DIM_1D, {0, 0});
|
||||||
this->special_cells.resize(x, {BC_UNSET, 0});
|
this->special_cells.resize(x, {BC_UNSET, 0});
|
||||||
this->dim = 1;
|
this->dim = 1;
|
||||||
@ -21,7 +21,8 @@ Diffusion::BTCSBoundaryCondition::BTCSBoundaryCondition(int x) {
|
|||||||
this->maxindex = x - 1;
|
this->maxindex = x - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
Diffusion::BTCSBoundaryCondition::BTCSBoundaryCondition(int x, int y) {
|
tug::boundary_condition::BTCSBoundaryCondition::BTCSBoundaryCondition(int x,
|
||||||
|
int y) {
|
||||||
this->maxsize = (x >= y ? x : y);
|
this->maxsize = (x >= y ? x : y);
|
||||||
this->bc_internal.resize(DIM_2D * maxsize, {0, 0});
|
this->bc_internal.resize(DIM_2D * maxsize, {0, 0});
|
||||||
this->special_cells.resize(x * y, {BC_UNSET, 0});
|
this->special_cells.resize(x * y, {BC_UNSET, 0});
|
||||||
@ -33,8 +34,8 @@ Diffusion::BTCSBoundaryCondition::BTCSBoundaryCondition(int x, int y) {
|
|||||||
this->maxindex = (x * y) - 1;
|
this->maxindex = (x * y) - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSBoundaryCondition::setSide(
|
void tug::boundary_condition::BTCSBoundaryCondition::setSide(
|
||||||
uint8_t side, Diffusion::boundary_condition &input_bc) {
|
uint8_t side, tug::boundary_condition::boundary_condition &input_bc) {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw_invalid_argument("setSide requires at least a 2D grid");
|
throw_invalid_argument("setSide requires at least a 2D grid");
|
||||||
}
|
}
|
||||||
@ -42,18 +43,19 @@ void Diffusion::BTCSBoundaryCondition::setSide(
|
|||||||
throw_out_of_range("Invalid range for 2D grid");
|
throw_out_of_range("Invalid range for 2D grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size =
|
uint32_t size = (side == tug::boundary_condition::BC_SIDE_LEFT ||
|
||||||
(side == Diffusion::BC_SIDE_LEFT || side == Diffusion::BC_SIDE_RIGHT
|
side == tug::boundary_condition::BC_SIDE_RIGHT
|
||||||
? this->sizes[X_DIM]
|
? this->sizes[X_DIM]
|
||||||
: this->sizes[Y_DIM]);
|
: this->sizes[Y_DIM]);
|
||||||
|
|
||||||
for (uint32_t i = 0; i < size; i++) {
|
for (uint32_t i = 0; i < size; i++) {
|
||||||
this->bc_internal[side * maxsize + i] = input_bc;
|
this->bc_internal[side * maxsize + i] = input_bc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSBoundaryCondition::setSide(
|
void tug::boundary_condition::BTCSBoundaryCondition::setSide(
|
||||||
uint8_t side, std::vector<Diffusion::boundary_condition> &input_bc) {
|
uint8_t side,
|
||||||
|
std::vector<tug::boundary_condition::boundary_condition> &input_bc) {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw_invalid_argument("setSide requires at least a 2D grid");
|
throw_invalid_argument("setSide requires at least a 2D grid");
|
||||||
}
|
}
|
||||||
@ -61,10 +63,10 @@ void Diffusion::BTCSBoundaryCondition::setSide(
|
|||||||
throw_out_of_range("Invalid range for 2D grid");
|
throw_out_of_range("Invalid range for 2D grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size =
|
uint32_t size = (side == tug::boundary_condition::BC_SIDE_LEFT ||
|
||||||
(side == Diffusion::BC_SIDE_LEFT || side == Diffusion::BC_SIDE_RIGHT
|
side == tug::boundary_condition::BC_SIDE_RIGHT
|
||||||
? this->sizes[X_DIM]
|
? this->sizes[X_DIM]
|
||||||
: this->sizes[Y_DIM]);
|
: this->sizes[Y_DIM]);
|
||||||
|
|
||||||
if (input_bc.size() > size) {
|
if (input_bc.size() > size) {
|
||||||
throw_out_of_range("Input vector is greater than maximum excpected value");
|
throw_out_of_range("Input vector is greater than maximum excpected value");
|
||||||
@ -75,8 +77,8 @@ void Diffusion::BTCSBoundaryCondition::setSide(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
auto tug::boundary_condition::BTCSBoundaryCondition::getSide(uint8_t side)
|
||||||
-> std::vector<Diffusion::boundary_condition> {
|
-> std::vector<tug::boundary_condition::boundary_condition> {
|
||||||
if (this->dim == 1) {
|
if (this->dim == 1) {
|
||||||
throw_invalid_argument("getSide requires at least a 2D grid");
|
throw_invalid_argument("getSide requires at least a 2D grid");
|
||||||
}
|
}
|
||||||
@ -84,12 +86,12 @@ auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
|||||||
throw_out_of_range("Invalid range for 2D grid");
|
throw_out_of_range("Invalid range for 2D grid");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t size =
|
uint32_t size = (side == tug::boundary_condition::BC_SIDE_LEFT ||
|
||||||
(side == Diffusion::BC_SIDE_LEFT || side == Diffusion::BC_SIDE_RIGHT
|
side == tug::boundary_condition::BC_SIDE_RIGHT
|
||||||
? this->sizes[X_DIM]
|
? this->sizes[X_DIM]
|
||||||
: this->sizes[Y_DIM]);
|
: this->sizes[Y_DIM]);
|
||||||
|
|
||||||
std::vector<Diffusion::boundary_condition> out(size);
|
std::vector<tug::boundary_condition::boundary_condition> out(size);
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
out[i] = this->bc_internal[this->maxsize * side + i];
|
out[i] = this->bc_internal[this->maxsize * side + i];
|
||||||
@ -98,8 +100,8 @@ auto Diffusion::BTCSBoundaryCondition::getSide(uint8_t side)
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSBoundaryCondition::col_boundary(uint32_t i) const
|
auto tug::boundary_condition::BTCSBoundaryCondition::col_boundary(
|
||||||
-> Diffusion::bc_tuple {
|
uint32_t i) const -> tug::boundary_condition::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");
|
||||||
}
|
}
|
||||||
@ -111,8 +113,8 @@ auto Diffusion::BTCSBoundaryCondition::col_boundary(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_boundary(uint32_t i) const
|
auto tug::boundary_condition::BTCSBoundaryCondition::row_boundary(
|
||||||
-> Diffusion::bc_tuple {
|
uint32_t i) const -> tug::boundary_condition::bc_tuple {
|
||||||
if (i >= this->sizes[X_DIM]) {
|
if (i >= this->sizes[X_DIM]) {
|
||||||
throw_out_of_range("Index out of range");
|
throw_out_of_range("Index out of range");
|
||||||
}
|
}
|
||||||
@ -121,7 +123,8 @@ auto Diffusion::BTCSBoundaryCondition::row_boundary(uint32_t i) const
|
|||||||
this->bc_internal[BC_SIDE_RIGHT * this->maxsize + i]};
|
this->bc_internal[BC_SIDE_RIGHT * this->maxsize + i]};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSBoundaryCondition::getInnerRow(uint32_t i) const -> bc_vec {
|
auto tug::boundary_condition::BTCSBoundaryCondition::getInnerRow(
|
||||||
|
uint32_t i) const -> bc_vec {
|
||||||
if (i >= this->sizes[X_DIM]) {
|
if (i >= this->sizes[X_DIM]) {
|
||||||
throw_out_of_range("Index is out of range");
|
throw_out_of_range("Index is out of range");
|
||||||
}
|
}
|
||||||
@ -134,7 +137,8 @@ auto Diffusion::BTCSBoundaryCondition::getInnerRow(uint32_t i) const -> bc_vec {
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSBoundaryCondition::getInnerCol(uint32_t i) const -> bc_vec {
|
auto tug::boundary_condition::BTCSBoundaryCondition::getInnerCol(
|
||||||
|
uint32_t i) const -> bc_vec {
|
||||||
if (this->dim != 2) {
|
if (this->dim != 2) {
|
||||||
throw_invalid_argument("getInnerCol is only applicable for 2D grids");
|
throw_invalid_argument("getInnerCol is only applicable for 2D grids");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ constexpr double DOUBLE_MACHINE_EPSILON = 1.93e-34;
|
|||||||
|
|
||||||
constexpr int BTCS_MAX_DEP_PER_CELL = 3;
|
constexpr int BTCS_MAX_DEP_PER_CELL = 3;
|
||||||
constexpr int BTCS_2D_DT_SIZE = 2;
|
constexpr int BTCS_2D_DT_SIZE = 2;
|
||||||
Diffusion::BTCSDiffusion::BTCSDiffusion(unsigned int dim) : grid_dim(dim) {
|
tug::diffusion::BTCSDiffusion::BTCSDiffusion(unsigned int dim) : grid_dim(dim) {
|
||||||
|
|
||||||
grid_cells.resize(dim, 1);
|
grid_cells.resize(dim, 1);
|
||||||
domain_size.resize(dim, 1);
|
domain_size.resize(dim, 1);
|
||||||
@ -40,58 +40,59 @@ Diffusion::BTCSDiffusion::BTCSDiffusion(unsigned int dim) : grid_dim(dim) {
|
|||||||
this->time_step = 0;
|
this->time_step = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::setXDimensions(double domain_size,
|
void tug::diffusion::BTCSDiffusion::setXDimensions(double domain_size,
|
||||||
unsigned int n_grid_cells) {
|
unsigned int n_grid_cells) {
|
||||||
this->domain_size[0] = domain_size;
|
this->domain_size[0] = domain_size;
|
||||||
this->grid_cells[0] = n_grid_cells;
|
this->grid_cells[0] = n_grid_cells;
|
||||||
|
|
||||||
updateInternals();
|
updateInternals();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::setYDimensions(double domain_size,
|
void tug::diffusion::BTCSDiffusion::setYDimensions(double domain_size,
|
||||||
unsigned int n_grid_cells) {
|
unsigned int n_grid_cells) {
|
||||||
this->domain_size[1] = domain_size;
|
this->domain_size[1] = domain_size;
|
||||||
this->grid_cells[1] = n_grid_cells;
|
this->grid_cells[1] = n_grid_cells;
|
||||||
|
|
||||||
updateInternals();
|
updateInternals();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::setZDimensions(double domain_size,
|
void tug::diffusion::BTCSDiffusion::setZDimensions(double domain_size,
|
||||||
unsigned int n_grid_cells) {
|
unsigned int n_grid_cells) {
|
||||||
this->domain_size[2] = domain_size;
|
this->domain_size[2] = domain_size;
|
||||||
this->grid_cells[2] = n_grid_cells;
|
this->grid_cells[2] = n_grid_cells;
|
||||||
|
|
||||||
updateInternals();
|
updateInternals();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSDiffusion::getXGridCellsN() -> unsigned int {
|
auto tug::diffusion::BTCSDiffusion::getXGridCellsN() -> unsigned int {
|
||||||
return this->grid_cells[0];
|
return this->grid_cells[0];
|
||||||
}
|
}
|
||||||
auto Diffusion::BTCSDiffusion::getYGridCellsN() -> unsigned int {
|
auto tug::diffusion::BTCSDiffusion::getYGridCellsN() -> unsigned int {
|
||||||
return this->grid_cells[1];
|
return this->grid_cells[1];
|
||||||
}
|
}
|
||||||
auto Diffusion::BTCSDiffusion::getZGridCellsN() -> unsigned int {
|
auto tug::diffusion::BTCSDiffusion::getZGridCellsN() -> unsigned int {
|
||||||
return this->grid_cells[2];
|
return this->grid_cells[2];
|
||||||
}
|
}
|
||||||
auto Diffusion::BTCSDiffusion::getXDomainSize() -> double {
|
auto tug::diffusion::BTCSDiffusion::getXDomainSize() -> double {
|
||||||
return this->domain_size[0];
|
return this->domain_size[0];
|
||||||
}
|
}
|
||||||
auto Diffusion::BTCSDiffusion::getYDomainSize() -> double {
|
auto tug::diffusion::BTCSDiffusion::getYDomainSize() -> double {
|
||||||
return this->domain_size[1];
|
return this->domain_size[1];
|
||||||
}
|
}
|
||||||
auto Diffusion::BTCSDiffusion::getZDomainSize() -> double {
|
auto tug::diffusion::BTCSDiffusion::getZDomainSize() -> double {
|
||||||
return this->domain_size[2];
|
return this->domain_size[2];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::updateInternals() {
|
void tug::diffusion::BTCSDiffusion::updateInternals() {
|
||||||
for (int i = 0; i < grid_dim; i++) {
|
for (int i = 0; i < grid_dim; i++) {
|
||||||
deltas[i] = (double)domain_size[i] / grid_cells[i];
|
deltas[i] = (double)domain_size[i] / grid_cells[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Diffusion::BTCSDiffusion::simulate_base(
|
void tug::diffusion::BTCSDiffusion::simulate_base(
|
||||||
DVectorRowMajor &c, const Diffusion::bc_tuple &bc_ghosts,
|
DVectorRowMajor &c, const tug::boundary_condition::bc_tuple &bc_ghosts,
|
||||||
const Diffusion::bc_vec &bc_inner, const DVectorRowMajor &alpha, double dx,
|
const tug::boundary_condition::bc_vec &bc_inner,
|
||||||
double time_step, int size, const DVectorRowMajor &d_ortho) {
|
const DVectorRowMajor &alpha, double dx, double time_step, int size,
|
||||||
|
const DVectorRowMajor &d_ortho) {
|
||||||
|
|
||||||
Eigen::SparseMatrix<double> A_matrix;
|
Eigen::SparseMatrix<double> A_matrix;
|
||||||
Eigen::VectorXd b_vector;
|
Eigen::VectorXd b_vector;
|
||||||
@ -119,9 +120,9 @@ void Diffusion::BTCSDiffusion::simulate_base(
|
|||||||
c = x_vector.segment(1, size);
|
c = x_vector.segment(1, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::simulate1D(
|
void tug::diffusion::BTCSDiffusion::simulate1D(
|
||||||
Eigen::Map<DVectorRowMajor> &c, Eigen::Map<const DVectorRowMajor> &alpha,
|
Eigen::Map<DVectorRowMajor> &c, Eigen::Map<const DVectorRowMajor> &alpha,
|
||||||
const Diffusion::BTCSBoundaryCondition &bc) {
|
const tug::boundary_condition::BTCSBoundaryCondition &bc) {
|
||||||
|
|
||||||
int size = this->grid_cells[0];
|
int size = this->grid_cells[0];
|
||||||
double dx = this->deltas[0];
|
double dx = this->deltas[0];
|
||||||
@ -135,9 +136,9 @@ void Diffusion::BTCSDiffusion::simulate1D(
|
|||||||
c.row(0) << input_field;
|
c.row(0) << input_field;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::simulate2D(
|
void tug::diffusion::BTCSDiffusion::simulate2D(
|
||||||
Eigen::Map<DMatrixRowMajor> &c, Eigen::Map<const DMatrixRowMajor> &alpha,
|
Eigen::Map<DMatrixRowMajor> &c, Eigen::Map<const DMatrixRowMajor> &alpha,
|
||||||
const Diffusion::BTCSBoundaryCondition &bc) {
|
const tug::boundary_condition::BTCSBoundaryCondition &bc) {
|
||||||
|
|
||||||
int n_rows = this->grid_cells[1];
|
int n_rows = this->grid_cells[1];
|
||||||
int n_cols = this->grid_cells[0];
|
int n_cols = this->grid_cells[0];
|
||||||
@ -169,15 +170,15 @@ void Diffusion::BTCSDiffusion::simulate2D(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSDiffusion::calc_d_ortho(
|
auto tug::diffusion::BTCSDiffusion::calc_d_ortho(
|
||||||
const DMatrixRowMajor &c, const DMatrixRowMajor &alpha,
|
const DMatrixRowMajor &c, const DMatrixRowMajor &alpha,
|
||||||
const Diffusion::BTCSBoundaryCondition &bc, bool transposed,
|
const tug::boundary_condition::BTCSBoundaryCondition &bc, bool transposed,
|
||||||
double time_step, double dx) -> DMatrixRowMajor {
|
double time_step, double dx) -> DMatrixRowMajor {
|
||||||
|
|
||||||
uint8_t upper =
|
uint8_t upper = (transposed ? tug::boundary_condition::BC_SIDE_LEFT
|
||||||
(transposed ? Diffusion::BC_SIDE_LEFT : Diffusion::BC_SIDE_TOP);
|
: tug::boundary_condition::BC_SIDE_TOP);
|
||||||
uint8_t lower =
|
uint8_t lower = (transposed ? tug::boundary_condition::BC_SIDE_RIGHT
|
||||||
(transposed ? Diffusion::BC_SIDE_RIGHT : Diffusion::BC_SIDE_BOTTOM);
|
: tug::boundary_condition::BC_SIDE_BOTTOM);
|
||||||
|
|
||||||
int n_rows = c.rows();
|
int n_rows = c.rows();
|
||||||
int n_cols = c.cols();
|
int n_cols = c.cols();
|
||||||
@ -188,10 +189,10 @@ auto Diffusion::BTCSDiffusion::calc_d_ortho(
|
|||||||
|
|
||||||
// first, iterate over first row
|
// first, iterate over first row
|
||||||
for (int j = 0; j < n_cols; j++) {
|
for (int j = 0; j < n_cols; j++) {
|
||||||
boundary_condition tmp_bc = bc(upper, j);
|
tug::boundary_condition::boundary_condition tmp_bc = bc(upper, j);
|
||||||
double sy = (time_step * alpha(0, j)) / (dx * dx);
|
double sy = (time_step * alpha(0, j)) / (dx * dx);
|
||||||
|
|
||||||
y_values[0] = (tmp_bc.type == Diffusion::BC_TYPE_CONSTANT
|
y_values[0] = (tmp_bc.type == tug::boundary_condition::BC_TYPE_CONSTANT
|
||||||
? tmp_bc.value
|
? tmp_bc.value
|
||||||
: getBCFromFlux(tmp_bc, c(0, j), alpha(0, j)));
|
: getBCFromFlux(tmp_bc, c(0, j), alpha(0, j)));
|
||||||
y_values[1] = c(0, j);
|
y_values[1] = c(0, j);
|
||||||
@ -218,12 +219,12 @@ auto Diffusion::BTCSDiffusion::calc_d_ortho(
|
|||||||
|
|
||||||
// and finally over last row
|
// and finally over last row
|
||||||
for (int j = 0; j < n_cols; j++) {
|
for (int j = 0; j < n_cols; j++) {
|
||||||
boundary_condition tmp_bc = bc(lower, j);
|
tug::boundary_condition::boundary_condition tmp_bc = bc(lower, j);
|
||||||
double sy = (time_step * alpha(end, j)) / (dx * dx);
|
double sy = (time_step * alpha(end, j)) / (dx * dx);
|
||||||
|
|
||||||
y_values[0] = c(end - 1, j);
|
y_values[0] = c(end - 1, j);
|
||||||
y_values[1] = c(end, j);
|
y_values[1] = c(end, j);
|
||||||
y_values[2] = (tmp_bc.type == Diffusion::BC_TYPE_CONSTANT
|
y_values[2] = (tmp_bc.type == tug::boundary_condition::BC_TYPE_CONSTANT
|
||||||
? tmp_bc.value
|
? tmp_bc.value
|
||||||
: getBCFromFlux(tmp_bc, c(end, j), alpha(end, j)));
|
: getBCFromFlux(tmp_bc, c(end, j), alpha(end, j)));
|
||||||
|
|
||||||
@ -233,9 +234,10 @@ auto Diffusion::BTCSDiffusion::calc_d_ortho(
|
|||||||
return d_ortho;
|
return d_ortho;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::fillMatrixFromRow(
|
void tug::diffusion::BTCSDiffusion::fillMatrixFromRow(
|
||||||
Eigen::SparseMatrix<double> &A_matrix, const DVectorRowMajor &alpha,
|
Eigen::SparseMatrix<double> &A_matrix, const DVectorRowMajor &alpha,
|
||||||
const Diffusion::bc_vec &bc_inner, int size, double dx, double time_step) {
|
const tug::boundary_condition::bc_vec &bc_inner, int size, double dx,
|
||||||
|
double time_step) {
|
||||||
|
|
||||||
double sx = 0;
|
double sx = 0;
|
||||||
|
|
||||||
@ -243,8 +245,8 @@ void Diffusion::BTCSDiffusion::fillMatrixFromRow(
|
|||||||
|
|
||||||
A_matrix.insert(0, 0) = 1;
|
A_matrix.insert(0, 0) = 1;
|
||||||
|
|
||||||
if (bc_inner[0].type != BC_UNSET) {
|
if (bc_inner[0].type != tug::boundary_condition::BC_UNSET) {
|
||||||
if (bc_inner[0].type != BC_TYPE_CONSTANT) {
|
if (bc_inner[0].type != tug::boundary_condition::BC_TYPE_CONSTANT) {
|
||||||
throw_invalid_argument("Inner boundary conditions with other type than "
|
throw_invalid_argument("Inner boundary conditions with other type than "
|
||||||
"BC_TYPE_CONSTANT are currently not supported.");
|
"BC_TYPE_CONSTANT are currently not supported.");
|
||||||
}
|
}
|
||||||
@ -257,8 +259,8 @@ void Diffusion::BTCSDiffusion::fillMatrixFromRow(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 2, k = j - 1; k < size - 1; j++, k++) {
|
for (int j = 2, k = j - 1; k < size - 1; j++, k++) {
|
||||||
if (bc_inner[k].type != BC_UNSET) {
|
if (bc_inner[k].type != tug::boundary_condition::BC_UNSET) {
|
||||||
if (bc_inner[k].type != BC_TYPE_CONSTANT) {
|
if (bc_inner[k].type != tug::boundary_condition::BC_TYPE_CONSTANT) {
|
||||||
throw_invalid_argument("Inner boundary conditions with other type than "
|
throw_invalid_argument("Inner boundary conditions with other type than "
|
||||||
"BC_TYPE_CONSTANT are currently not supported.");
|
"BC_TYPE_CONSTANT are currently not supported.");
|
||||||
}
|
}
|
||||||
@ -272,8 +274,8 @@ void Diffusion::BTCSDiffusion::fillMatrixFromRow(
|
|||||||
A_matrix.insert(j, (j + 1)) = sx;
|
A_matrix.insert(j, (j + 1)) = sx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bc_inner[size - 1].type != BC_UNSET) {
|
if (bc_inner[size - 1].type != tug::boundary_condition::BC_UNSET) {
|
||||||
if (bc_inner[size - 1].type != BC_TYPE_CONSTANT) {
|
if (bc_inner[size - 1].type != tug::boundary_condition::BC_TYPE_CONSTANT) {
|
||||||
throw_invalid_argument("Inner boundary conditions with other type than "
|
throw_invalid_argument("Inner boundary conditions with other type than "
|
||||||
"BC_TYPE_CONSTANT are currently not supported.");
|
"BC_TYPE_CONSTANT are currently not supported.");
|
||||||
}
|
}
|
||||||
@ -288,23 +290,24 @@ void Diffusion::BTCSDiffusion::fillMatrixFromRow(
|
|||||||
A_matrix.insert(A_size - 1, A_size - 1) = 1;
|
A_matrix.insert(A_size - 1, A_size - 1) = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::fillVectorFromRow(
|
void tug::diffusion::BTCSDiffusion::fillVectorFromRow(
|
||||||
Eigen::VectorXd &b_vector, const DVectorRowMajor &c,
|
Eigen::VectorXd &b_vector, const DVectorRowMajor &c,
|
||||||
const DVectorRowMajor &alpha, const bc_tuple &bc,
|
const DVectorRowMajor &alpha, const tug::boundary_condition::bc_tuple &bc,
|
||||||
const Diffusion::bc_vec &bc_inner, const DVectorRowMajor &d_ortho, int size,
|
const tug::boundary_condition::bc_vec &bc_inner,
|
||||||
double dx, double time_step) {
|
const DVectorRowMajor &d_ortho, int size, double dx, double time_step) {
|
||||||
|
|
||||||
Diffusion::boundary_condition left = bc[0];
|
tug::boundary_condition::boundary_condition left = bc[0];
|
||||||
Diffusion::boundary_condition right = bc[1];
|
tug::boundary_condition::boundary_condition right = bc[1];
|
||||||
|
|
||||||
bool left_constant = (left.type == Diffusion::BC_TYPE_CONSTANT);
|
bool left_constant = (left.type == tug::boundary_condition::BC_TYPE_CONSTANT);
|
||||||
bool right_constant = (right.type == Diffusion::BC_TYPE_CONSTANT);
|
bool right_constant =
|
||||||
|
(right.type == tug::boundary_condition::BC_TYPE_CONSTANT);
|
||||||
|
|
||||||
int b_size = b_vector.size();
|
int b_size = b_vector.size();
|
||||||
|
|
||||||
for (int j = 0; j < size; j++) {
|
for (int j = 0; j < size; j++) {
|
||||||
if (bc_inner[j].type != BC_UNSET) {
|
if (bc_inner[j].type != tug::boundary_condition::BC_UNSET) {
|
||||||
if (bc_inner[j].type != BC_TYPE_CONSTANT)
|
if (bc_inner[j].type != tug::boundary_condition::BC_TYPE_CONSTANT)
|
||||||
throw_invalid_argument("Inner boundary conditions with other type than "
|
throw_invalid_argument("Inner boundary conditions with other type than "
|
||||||
"BC_TYPE_CONSTANT are currently not supported.");
|
"BC_TYPE_CONSTANT are currently not supported.");
|
||||||
b_vector[j + 1] = bc_inner[j].value;
|
b_vector[j + 1] = bc_inner[j].value;
|
||||||
@ -323,13 +326,13 @@ void Diffusion::BTCSDiffusion::fillVectorFromRow(
|
|||||||
: getBCFromFlux(right, c[size - 1], alpha[size - 1]));
|
: getBCFromFlux(right, c[size - 1], alpha[size - 1]));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Diffusion::BTCSDiffusion::setTimestep(double time_step) {
|
void tug::diffusion::BTCSDiffusion::setTimestep(double time_step) {
|
||||||
this->time_step = time_step;
|
this->time_step = time_step;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Diffusion::BTCSDiffusion::simulate(
|
auto tug::diffusion::BTCSDiffusion::simulate(
|
||||||
double *c, double *alpha, const Diffusion::BTCSBoundaryCondition &bc)
|
double *c, double *alpha,
|
||||||
-> double {
|
const tug::boundary_condition::BTCSBoundaryCondition &bc) -> double {
|
||||||
|
|
||||||
std::chrono::high_resolution_clock::time_point start =
|
std::chrono::high_resolution_clock::time_point start =
|
||||||
std::chrono::high_resolution_clock::now();
|
std::chrono::high_resolution_clock::now();
|
||||||
@ -359,16 +362,15 @@ auto Diffusion::BTCSDiffusion::simulate(
|
|||||||
return duration.count();
|
return duration.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline auto Diffusion::BTCSDiffusion::getBCFromFlux(boundary_condition bc,
|
inline auto tug::diffusion::BTCSDiffusion::getBCFromFlux(
|
||||||
double neighbor_c,
|
tug::boundary_condition::boundary_condition bc, double neighbor_c,
|
||||||
double neighbor_alpha)
|
double neighbor_alpha) -> double {
|
||||||
-> double {
|
|
||||||
|
|
||||||
double val = 0;
|
double val = 0;
|
||||||
|
|
||||||
if (bc.type == Diffusion::BC_TYPE_CLOSED) {
|
if (bc.type == tug::boundary_condition::BC_TYPE_CLOSED) {
|
||||||
val = neighbor_c;
|
val = neighbor_c;
|
||||||
} else if (bc.type == Diffusion::BC_TYPE_FLUX) {
|
} else if (bc.type == tug::boundary_condition::BC_TYPE_FLUX) {
|
||||||
// TODO
|
// TODO
|
||||||
// val = bc[index].value;
|
// val = bc[index].value;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
#include <grid/BTCSBoundaryCondition.hpp>
|
#include <grid/BTCSBoundaryCondition.hpp>
|
||||||
#include <doctest/doctest.h>
|
#include <doctest/doctest.h>
|
||||||
|
|
||||||
using namespace Diffusion;
|
using namespace tug::boundary_condition;
|
||||||
|
|
||||||
#define BC_CONST_VALUE 1e-5
|
#define BC_CONST_VALUE 1e-5
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,8 @@
|
|||||||
#include <grid/BTCSBoundaryCondition.hpp>
|
#include <grid/BTCSBoundaryCondition.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace Diffusion;
|
using namespace tug::boundary_condition;
|
||||||
|
using namespace tug::diffusion;
|
||||||
|
|
||||||
#define DIMENSION 2
|
#define DIMENSION 2
|
||||||
#define N 51
|
#define N 51
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user