mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 17:38:23 +01:00
rewrite initialization of module
ATTENTION: code will throw errors on compilation!
This commit is contained in:
parent
e8dae917d5
commit
29fc70ce1a
@ -3,6 +3,7 @@
|
||||
#include <Eigen/SparseLU>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
@ -12,26 +13,58 @@ const int BTCSDiffusion::BC_CONSTANT = 0;
|
||||
const int BTCSDiffusion::BC_CLOSED = 1;
|
||||
const int BTCSDiffusion::BC_FLUX = 2;
|
||||
|
||||
BTCSDiffusion::BTCSDiffusion(int x) : n_x(x) {
|
||||
this->grid_dim = 1;
|
||||
this->dx = 1. / (x - 1);
|
||||
BTCSDiffusion::BTCSDiffusion(unsigned int dim) : grid_dim(dim) {
|
||||
assert(dim <= 3);
|
||||
|
||||
// per default use Neumann condition with gradient of 0 at the end of the grid
|
||||
this->bc.resize(2, std::tuple<bctype, double>(BTCSDiffusion::BC_CONSTANT, 0.));
|
||||
grid_cells.resize(dim, 1);
|
||||
spatial_discretization.resize(dim, 1);
|
||||
deltas.resize(dim, 1);
|
||||
}
|
||||
BTCSDiffusion::BTCSDiffusion(int x, int y) : n_x(x), n_y(y) {
|
||||
|
||||
// this->grid_dim = 2;
|
||||
|
||||
// this->bc.reserve(x * 2 + y * 2);
|
||||
// // per default use Neumann condition with gradient of 0 at the end of the
|
||||
// grid std::fill(this->bc.begin(), this->bc.end(), -1);
|
||||
std::vector<int> BTCSDiffusion::getNumberOfGridCells() {
|
||||
return this->grid_cells;
|
||||
}
|
||||
BTCSDiffusion::BTCSDiffusion(int x, int y, int z) : n_x(x), n_y(y), n_z(z) {
|
||||
|
||||
// this->grid_dim = 3;
|
||||
// TODO: reserve memory for boundary conditions
|
||||
std::vector<int> BTCSDiffusion::getSpatialDiscretization() {
|
||||
return this->spatial_discretization;
|
||||
}
|
||||
void BTCSDiffusion::setNumberOfGridCells(std::vector<int> &n_grid) {
|
||||
grid_cells = n_grid;
|
||||
assert(grid_cells.size() == grid_dim);
|
||||
updateDeltas();
|
||||
}
|
||||
void BTCSDiffusion::setSpatialDiscretization(std::vector<int> &s_grid) {
|
||||
spatial_discretization = s_grid;
|
||||
assert(spatial_discretization.size() == grid_dim);
|
||||
updateDeltas();
|
||||
}
|
||||
|
||||
void BTCSDiffusion::updateDeltas() {
|
||||
for (int i = 0; i < grid_dim; i++) {
|
||||
deltas[i] = (double)spatial_discretization[i] / grid_cells[i];
|
||||
}
|
||||
}
|
||||
// BTCSDiffusion::BTCSDiffusion(int x) : n_x(x) {
|
||||
// this->grid_dim = 1;
|
||||
// this->dx = 1. / (x - 1);
|
||||
|
||||
// // per default use Neumann condition with gradient of 0 at the end of the
|
||||
// grid this->bc.resize(2, std::tuple<bctype,
|
||||
// double>(BTCSDiffusion::BC_CONSTANT, 0.));
|
||||
// }
|
||||
// BTCSDiffusion::BTCSDiffusion(int x, int y) : n_x(x), n_y(y) {
|
||||
|
||||
// // this->grid_dim = 2;
|
||||
|
||||
// // this->bc.reserve(x * 2 + y * 2);
|
||||
// // // per default use Neumann condition with gradient of 0 at the end of
|
||||
// the
|
||||
// // grid std::fill(this->bc.begin(), this->bc.end(), -1);
|
||||
// }
|
||||
// BTCSDiffusion::BTCSDiffusion(int x, int y, int z) : n_x(x), n_y(y), n_z(z) {
|
||||
|
||||
// // this->grid_dim = 3;
|
||||
// // TODO: reserve memory for boundary conditions
|
||||
// }
|
||||
|
||||
void BTCSDiffusion::simulate1D(std::vector<double> &c, double bc_left,
|
||||
double bc_right,
|
||||
|
||||
@ -42,36 +42,41 @@ public:
|
||||
/*!
|
||||
* Defines a closed/Neumann boundary condition.
|
||||
*/
|
||||
static const int BC_CLOSED;
|
||||
static const int BC_CLOSED;
|
||||
|
||||
/*!
|
||||
* Defines a flux/Cauchy boundary condition.
|
||||
*/
|
||||
static const int BC_FLUX;
|
||||
/*!
|
||||
* Defines a flux/Cauchy boundary condition.
|
||||
*/
|
||||
static const int BC_FLUX;
|
||||
|
||||
/*!
|
||||
* Create 1D-diffusion module.
|
||||
*
|
||||
* @param x Count of cells in x direction.
|
||||
*/
|
||||
explicit BTCSDiffusion(int x);
|
||||
BTCSDiffusion(unsigned int dim);
|
||||
|
||||
/*!
|
||||
* Currently not implemented: Create 2D-diffusion module.
|
||||
*
|
||||
* @param x Count of cells in x direction.
|
||||
* @param y Count of cells in y direction.
|
||||
*/
|
||||
explicit BTCSDiffusion(int x, int y);
|
||||
std::vector<int> getNumberOfGridCells();
|
||||
std::vector<int> getSpatialDiscretization();
|
||||
void setNumberOfGridCells(std::vector<int> &n_grid);
|
||||
void setSpatialDiscretization(std::vector<int> &s_grid);
|
||||
|
||||
/*!
|
||||
* Currently not implemented: Create 3D-diffusion module.
|
||||
*
|
||||
* @param x Count of cells in x direction.
|
||||
* @param y Count of cells in y direction.
|
||||
* @param z Count of cells in z direction.
|
||||
*/
|
||||
explicit BTCSDiffusion(int x, int y, int z);
|
||||
// /*!
|
||||
// * Currently not implemented: Create 2D-diffusion module.
|
||||
// *
|
||||
// * @param x Count of cells in x direction.
|
||||
// * @param y Count of cells in y direction.
|
||||
// */
|
||||
// explicit BTCSDiffusion(int x, int y);
|
||||
|
||||
// /*!
|
||||
// * Currently not implemented: Create 3D-diffusion module.
|
||||
// *
|
||||
// * @param x Count of cells in x direction.
|
||||
// * @param y Count of cells in y direction.
|
||||
// * @param z Count of cells in z direction.
|
||||
// */
|
||||
// explicit BTCSDiffusion(int x, int y, int z);
|
||||
|
||||
/*!
|
||||
* With given ghost zones simulate diffusion. Only 1D allowed at this moment.
|
||||
@ -109,6 +114,8 @@ private:
|
||||
|
||||
double getBCFromTuple(int index, double nearest_value, double neighbor_alpha);
|
||||
|
||||
void updateDeltas();
|
||||
|
||||
boundary_condition bc;
|
||||
|
||||
Eigen::SparseMatrix<double> A_matrix;
|
||||
@ -118,12 +125,9 @@ private:
|
||||
double time_step;
|
||||
|
||||
int grid_dim;
|
||||
int n_x;
|
||||
double dx;
|
||||
int n_y;
|
||||
double dy;
|
||||
int n_z;
|
||||
double dz;
|
||||
std::vector<int> grid_cells;
|
||||
std::vector<int> spatial_discretization;
|
||||
std::vector<double> deltas;
|
||||
};
|
||||
|
||||
#endif // BTCSDIFFUSION_H_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user