Update getter/setters for grid specification

This commit is contained in:
Max Luebke 2022-01-27 10:11:47 +01:00
parent 38b4bd0fb2
commit 9bce8be092
3 changed files with 45 additions and 25 deletions

View File

@ -22,23 +22,40 @@ BTCSDiffusion::BTCSDiffusion(unsigned int dim) : grid_dim(dim) {
deltas.resize(dim, 1); deltas.resize(dim, 1);
} }
std::vector<int> BTCSDiffusion::getNumberOfGridCells() { void BTCSDiffusion::setXDimensions(unsigned int domain_size,
return this->grid_cells; unsigned int n_grid_cells) {
} assert(this->grid_dim > 0);
std::vector<int> BTCSDiffusion::getSpatialDiscretization() { this->domain_size[0] = domain_size;
return this->domain_size; this->grid_cells[0] = n_grid_cells;
}
void BTCSDiffusion::setNumberOfGridCells(std::vector<int> &n_grid) {
grid_cells = n_grid;
assert(grid_cells.size() == grid_dim);
updateInternals(); updateInternals();
} }
void BTCSDiffusion::setSpatialDiscretization(std::vector<int> &s_grid) {
domain_size = s_grid; void BTCSDiffusion::setYDimensions(unsigned int domain_size,
assert(domain_size.size() == grid_dim); unsigned int n_grid_cells) {
assert(this->grid_dim > 1);
this->domain_size[1] = domain_size;
this->grid_cells[1] = n_grid_cells;
updateInternals(); updateInternals();
} }
void BTCSDiffusion::setZDimensions(unsigned int domain_size,
unsigned int n_grid_cells) {
assert(this->grid_dim > 2);
this->domain_size[2] = domain_size;
this->grid_cells[2] = n_grid_cells;
updateInternals();
}
unsigned int BTCSDiffusion::getXGridCellsN() { return this->grid_cells[0]; }
unsigned int BTCSDiffusion::getYGridCellsN() { return this->grid_cells[1]; }
unsigned int BTCSDiffusion::getZGridCellsN() { return this->grid_cells[2]; }
unsigned int BTCSDiffusion::getXDomainSize() { return this->domain_size[0]; }
unsigned int BTCSDiffusion::getYDomainSize() { return this->domain_size[1]; }
unsigned int BTCSDiffusion::getZDomainSize() { return this->domain_size[2]; }
void BTCSDiffusion::updateInternals() { void 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];

View File

@ -3,6 +3,7 @@
#include <Eigen/Sparse> #include <Eigen/Sparse>
#include <tuple> #include <tuple>
#include <type_traits>
#include <vector> #include <vector>
/*! /*!
@ -70,11 +71,16 @@ public:
*/ */
BTCSDiffusion(unsigned int dim); BTCSDiffusion(unsigned int dim);
std::vector<int> getNumberOfGridCells(); void setXDimensions(unsigned int domain_size, unsigned int n_grid_cells);
std::vector<int> getSpatialDiscretization(); void setYDimensions(unsigned int domain_size, unsigned int n_grid_cells);
void setNumberOfGridCells(std::vector<int> &n_grid); void setZDimensions(unsigned int domain_size, unsigned int n_grid_cells);
void setSpatialDiscretization(std::vector<int> &s_grid);
unsigned int getXGridCellsN();
unsigned int getYGridCellsN();
unsigned int getZGridCellsN();
unsigned int getXDomainSize();
unsigned int getYDomainSize();
unsigned int getZDomainSize();
// /*! // /*!
// * Currently not implemented: Create 2D-diffusion module. // * Currently not implemented: Create 2D-diffusion module.
// * // *
@ -127,7 +133,8 @@ private:
void simulate2D(std::vector<double> &c); void simulate2D(std::vector<double> &c);
void simulate3D(std::vector<double> &c); void simulate3D(std::vector<double> &c);
inline double getBCFromFlux(boundary_condition bc, double nearest_value, double neighbor_alpha); inline double getBCFromFlux(boundary_condition bc, double nearest_value,
double neighbor_alpha);
void updateInternals(); void updateInternals();
@ -140,8 +147,8 @@ private:
double time_step; double time_step;
int grid_dim; int grid_dim;
std::vector<int> grid_cells; std::vector<unsigned int> grid_cells;
std::vector<int> domain_size; std::vector<unsigned int> domain_size;
std::vector<double> deltas; std::vector<double> deltas;
}; };

View File

@ -18,11 +18,7 @@ int main(int argc, char *argv[]) {
// create instance of diffusion module // create instance of diffusion module
BTCSDiffusion diffu(dim); BTCSDiffusion diffu(dim);
std::vector<int> vec_n = diffu.getNumberOfGridCells(); diffu.setXDimensions(1, n);
vec_n[0] = n;
diffu.setNumberOfGridCells(vec_n);
// set the boundary condition for the left ghost cell to dirichlet // set the boundary condition for the left ghost cell to dirichlet
diffu.setBoundaryCondition(0, 5. * std::pow(10, -6), diffu.setBoundaryCondition(0, 5. * std::pow(10, -6),