feat: add helper functions to TugInput struct

This commit is contained in:
Max Lübke 2022-08-24 09:28:54 +02:00 committed by Max Luebke
parent e482d71779
commit 02a9531544
2 changed files with 73 additions and 17 deletions

View File

@ -2,6 +2,7 @@
#define DIFFUSION_H_ #define DIFFUSION_H_
#include "BoundaryCondition.hpp" #include "BoundaryCondition.hpp"
#include "Solver.hpp"
#include <Eigen/Dense> #include <Eigen/Dense>
#include <Eigen/Sparse> #include <Eigen/Sparse>
#include <array> #include <array>
@ -15,19 +16,80 @@ namespace diffusion {
* Defines grid dimensions and boundary conditions. * Defines grid dimensions and boundary conditions.
*/ */
typedef struct { typedef struct {
uint32_t grid_cells[3]; uint32_t
double domain_size[3]; grid_cells[3]; /**< Count of grid cells in each of the 3 directions.*/
bc::BoundaryCondition *bc; double domain_size[3]; /**< Domain sizes in each of the 3 directions.*/
bc::BoundaryCondition *bc; /**< Boundary conditions for the grid.*/
} TugGrid; } TugGrid;
/** /**
* Besides containing the grid structure it holds also information about the * Besides containing the grid structure it holds also information about the
* desired time step to simulate and which solver to use. * desired time step to simulate and which solver to use.
*/ */
typedef struct { typedef struct tug_input_s {
double time_step; double time_step; /**< Time step which should be simulated by diffusion.*/
Eigen::VectorXd (*solver)(Eigen::SparseMatrix<double>, Eigen::VectorXd); Eigen::VectorXd (*solver)(Eigen::SparseMatrix<double>, Eigen::VectorXd) =
TugGrid grid; tug::solver::ThomasAlgorithm; /**< Solver function to use.*/
TugGrid grid; /**< Grid specification.*/
/**
* Set the desired time step for diffusion simulation.
*
* \param dt Time step in seconds.
*/
void setTimestep(double dt) { time_step = dt; }
/**
* Set the count of grid cells in each dimension.
*
* \param x Count of grid cells in x direction.
* \param y Count of grid cells in y direction.
* \param z Count of grid cells in z direction.
*/
void setGridCellN(uint32_t x, uint32_t y = 0, uint32_t z = 0) {
grid.grid_cells[0] = x;
grid.grid_cells[1] = y;
grid.grid_cells[2] = z;
}
/**
* Set the domain size of the grid in each direction.
* \param Domain size in x direction.
* \param Domain size in y direction.
* \param Domain size in z direction.
*/
void setDomainSize(double x, double y = 0, double z = 0) {
grid.domain_size[0] = x;
grid.domain_size[1] = y;
grid.domain_size[2] = z;
}
/**
* Set boundary conditions for grid instance.
*
* \param bc Boundary conditions to be set.
*/
void setBoundaryCondition(bc::BoundaryCondition &bc) { grid.bc = &bc; }
/**
* Retrieve the set boundary condition from grid instance.
*
* \return Boundary condition object if boundary conditions were set,
* otherwise NULL.
*/
auto getBoundaryCondition() -> bc::BoundaryCondition { return *(grid.bc); }
/**
* Set the solver function.
*
* \param f_in Pointer to function which takes a sparse matrix and a vector as
* input and returns another vector.
*/
void setSolverFunction(Eigen::VectorXd (*f_in)(Eigen::SparseMatrix<double>,
Eigen::VectorXd)) {
solver = f_in;
}
} TugInput; } TugInput;
/** /**

View File

@ -18,16 +18,10 @@ static std::vector<double> alpha(N *M, 1e-3);
static TugInput setupDiffu(BoundaryCondition &bc) { static TugInput setupDiffu(BoundaryCondition &bc) {
TugInput diffu; TugInput diffu;
diffu.time_step = 1.; diffu.setTimestep(1);
diffu.solver = tug::solver::ThomasAlgorithm; diffu.setGridCellN(N, M);
diffu.setDomainSize(N, M);
diffu.grid.grid_cells[0] = N; diffu.setBoundaryCondition(bc);
diffu.grid.grid_cells[1] = M;
diffu.grid.domain_size[0] = N;
diffu.grid.domain_size[1] = M;
diffu.grid.bc = &bc;
return diffu; return diffu;
} }