mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-14 01:48: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 <Eigen/SparseLU>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@ -12,26 +13,58 @@ const int BTCSDiffusion::BC_CONSTANT = 0;
|
|||||||
const int BTCSDiffusion::BC_CLOSED = 1;
|
const int BTCSDiffusion::BC_CLOSED = 1;
|
||||||
const int BTCSDiffusion::BC_FLUX = 2;
|
const int BTCSDiffusion::BC_FLUX = 2;
|
||||||
|
|
||||||
BTCSDiffusion::BTCSDiffusion(int x) : n_x(x) {
|
BTCSDiffusion::BTCSDiffusion(unsigned int dim) : grid_dim(dim) {
|
||||||
this->grid_dim = 1;
|
assert(dim <= 3);
|
||||||
this->dx = 1. / (x - 1);
|
|
||||||
|
|
||||||
// per default use Neumann condition with gradient of 0 at the end of the grid
|
grid_cells.resize(dim, 1);
|
||||||
this->bc.resize(2, std::tuple<bctype, double>(BTCSDiffusion::BC_CONSTANT, 0.));
|
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;
|
std::vector<int> BTCSDiffusion::getNumberOfGridCells() {
|
||||||
|
return this->grid_cells;
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
|
||||||
// this->bc.reserve(x * 2 + y * 2);
|
|
||||||
// // per default use Neumann condition with gradient of 0 at the end of the
|
// // per default use Neumann condition with gradient of 0 at the end of the
|
||||||
// grid std::fill(this->bc.begin(), this->bc.end(), -1);
|
// grid this->bc.resize(2, std::tuple<bctype,
|
||||||
}
|
// double>(BTCSDiffusion::BC_CONSTANT, 0.));
|
||||||
BTCSDiffusion::BTCSDiffusion(int x, int y, int z) : n_x(x), n_y(y), n_z(z) {
|
// }
|
||||||
|
// BTCSDiffusion::BTCSDiffusion(int x, int y) : n_x(x), n_y(y) {
|
||||||
|
|
||||||
// this->grid_dim = 3;
|
// // this->grid_dim = 2;
|
||||||
// TODO: reserve memory for boundary conditions
|
|
||||||
}
|
// // 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,
|
void BTCSDiffusion::simulate1D(std::vector<double> &c, double bc_left,
|
||||||
double bc_right,
|
double bc_right,
|
||||||
|
|||||||
@ -54,24 +54,29 @@ public:
|
|||||||
*
|
*
|
||||||
* @param x Count of cells in x direction.
|
* @param x Count of cells in x direction.
|
||||||
*/
|
*/
|
||||||
explicit BTCSDiffusion(int x);
|
BTCSDiffusion(unsigned int dim);
|
||||||
|
|
||||||
/*!
|
std::vector<int> getNumberOfGridCells();
|
||||||
* Currently not implemented: Create 2D-diffusion module.
|
std::vector<int> getSpatialDiscretization();
|
||||||
*
|
void setNumberOfGridCells(std::vector<int> &n_grid);
|
||||||
* @param x Count of cells in x direction.
|
void setSpatialDiscretization(std::vector<int> &s_grid);
|
||||||
* @param y Count of cells in y direction.
|
|
||||||
*/
|
|
||||||
explicit BTCSDiffusion(int x, int y);
|
|
||||||
|
|
||||||
/*!
|
// /*!
|
||||||
* Currently not implemented: Create 3D-diffusion module.
|
// * Currently not implemented: Create 2D-diffusion module.
|
||||||
*
|
// *
|
||||||
* @param x Count of cells in x direction.
|
// * @param x Count of cells in x direction.
|
||||||
* @param y Count of cells in y direction.
|
// * @param y Count of cells in y direction.
|
||||||
* @param z Count of cells in z direction.
|
// */
|
||||||
*/
|
// explicit BTCSDiffusion(int x, int y);
|
||||||
explicit BTCSDiffusion(int x, int y, int z);
|
|
||||||
|
// /*!
|
||||||
|
// * 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.
|
* 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);
|
double getBCFromTuple(int index, double nearest_value, double neighbor_alpha);
|
||||||
|
|
||||||
|
void updateDeltas();
|
||||||
|
|
||||||
boundary_condition bc;
|
boundary_condition bc;
|
||||||
|
|
||||||
Eigen::SparseMatrix<double> A_matrix;
|
Eigen::SparseMatrix<double> A_matrix;
|
||||||
@ -118,12 +125,9 @@ private:
|
|||||||
double time_step;
|
double time_step;
|
||||||
|
|
||||||
int grid_dim;
|
int grid_dim;
|
||||||
int n_x;
|
std::vector<int> grid_cells;
|
||||||
double dx;
|
std::vector<int> spatial_discretization;
|
||||||
int n_y;
|
std::vector<double> deltas;
|
||||||
double dy;
|
|
||||||
int n_z;
|
|
||||||
double dz;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BTCSDIFFUSION_H_
|
#endif // BTCSDIFFUSION_H_
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user