rewrite some function signatures and scopes (NOT RUNNABLE)

This commit is contained in:
Max Luebke 2021-12-06 13:48:27 +01:00
parent ef831a2cd4
commit f5c926e08d
2 changed files with 17 additions and 39 deletions

View File

@ -16,37 +16,32 @@
#include <algorithm> #include <algorithm>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <tuple>
const BCSide BTCSDiffusion::LEFT = 0; const int BTCSDiffusion::BC_NEUMANN = 0;
const BCSide BTCSDiffusion::RIGHT = 1; const int BTCSDiffusion::BC_DIRICHLET = 1;
BTCSDiffusion::BTCSDiffusion(int x) : dim_x(x) { BTCSDiffusion::BTCSDiffusion(int x) : dim_x(x) {
this->grid_dim = 1; this->grid_dim = 1;
// per default use Neumann condition with gradient of 0 at the end of the grid // per default use Neumann condition with gradient of 0 at the end of the grid
this->bc.resize(2, -1); this->bc.resize(2, std::tuple<int, double>(0,0.));
} }
BTCSDiffusion::BTCSDiffusion(int x, int y) : dim_x(x), dim_y(y) { BTCSDiffusion::BTCSDiffusion(int x, int y) : dim_x(x), dim_y(y) {
this->grid_dim = 2; // this->grid_dim = 2;
this->bc.reserve(x * 2 + y * 2); // this->bc.reserve(x * 2 + y * 2);
// per default use Neumann condition with gradient of 0 at the end of the grid // // 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::fill(this->bc.begin(), this->bc.end(), -1);
} }
BTCSDiffusion::BTCSDiffusion(int x, int y, int z) BTCSDiffusion::BTCSDiffusion(int x, int y, int z)
: dim_x(x), dim_y(y), dim_z(z) { : dim_x(x), dim_y(y), dim_z(z) {
this->grid_dim = 3; // this->grid_dim = 3;
// TODO: reserve memory for boundary conditions // TODO: reserve memory for boundary conditions
} }
void BTCSDiffusion::setBoundaryCondition(std::vector<double> input,
BCSide side) {
if (this->grid_dim == 1) {
bc[side] = input[0];
}
}
void BTCSDiffusion::simulate(std::vector<double> &c, std::vector<double> &alpha, void BTCSDiffusion::simulate(std::vector<double> &c, std::vector<double> &alpha,
double timestep) { double timestep) {
// calculate dx // calculate dx

View File

@ -2,19 +2,17 @@
#define BTCSDIFFUSION_H_ #define BTCSDIFFUSION_H_
#include <Eigen/Sparse> #include <Eigen/Sparse>
#include <tuple>
#include <vector> #include <vector>
/*!
* Type defining the side of given boundary condition.
*/
typedef int BCSide;
/*! /*!
* Datatype to fill the sparse matrix which is used to solve the equation * Datatype to fill the sparse matrix which is used to solve the equation
* system. * system.
*/ */
typedef Eigen::Triplet<double> T; typedef Eigen::Triplet<double> T;
typedef std::vector<std::tuple<int,double>> boundary_condition;
/*! /*!
* 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.
@ -22,15 +20,9 @@ typedef Eigen::Triplet<double> T;
class BTCSDiffusion { class BTCSDiffusion {
public: public:
/*!
* Set left boundary condition.
*/
static const BCSide LEFT;
/*! static const int BC_NEUMANN;
* Set right boundary condition. static const int BC_DIRICHLET;
*/
static const BCSide RIGHT;
/*! /*!
* Create 1D-diffusion module. * Create 1D-diffusion module.
@ -56,17 +48,6 @@ public:
*/ */
BTCSDiffusion(int x, int y, int z); BTCSDiffusion(int x, int y, int z);
/*!
* Sets internal boundary condition at the end of the grid/ghost zones.
* Currently only implemented for 1D diffusion.
*
* @param input Vector containing all the values to initialize the ghost
* zones.
* @param side Sets the side of the boundary condition. See BCSide for more
* information.
*/
void setBoundaryCondition(std::vector<double> input, BCSide side);
/*! /*!
* With given ghost zones simulate diffusion. Only 1D allowed at this moment. * With given ghost zones simulate diffusion. Only 1D allowed at this moment.
* *
@ -79,7 +60,9 @@ public:
double timestep); double timestep);
private: private:
std::vector<double> bc;
boundary_condition bc;
int grid_dim; int grid_dim;
int dim_x; int dim_x;
int dim_y; int dim_y;