refactor: implement coeff boundary functions as template constexpr

This commit is contained in:
Max Lübke 2023-09-14 16:21:45 +02:00
parent 819db24e18
commit 8e5c1ad035

View File

@ -118,54 +118,26 @@ createCoeffMatrix(Eigen::MatrixXd &alpha, std::vector<BoundaryElement> &bcLeft,
return cm; return cm;
} }
// calculates explicity concentration at top boundary in constant case // calculates explicit concentration at boundary in closed case
static inline double calcExplicitConcentrationsTopBoundaryConstant( template <typename T>
Eigen::MatrixXd &concentrations, Eigen::MatrixXd &alpha, constexpr T calcExplicitConcentrationsBoundaryClosed(T conc_center,
std::vector<BoundaryElement> &bcTop, int rowIndex, int i, double sy) { T alpha_center,
return sy * calcAlphaIntercell(alpha(rowIndex, i), alpha(rowIndex + 1, i)) * T alpha_neigbor, T sy) {
concentrations(rowIndex, i) + return sy * calcAlphaIntercell(alpha_center, alpha_neigbor) * conc_center +
(1 - (1 - sy * (calcAlphaIntercell(alpha_center, alpha_neigbor))) *
sy * (calcAlphaIntercell(alpha(rowIndex, i), alpha(rowIndex + 1, i)) + conc_center;
2 * alpha(rowIndex, i))) *
concentrations(rowIndex, i) +
sy * alpha(rowIndex, i) * bcTop[i].getValue();
} }
// calculates explicit concentration at top boundary in closed case // calculates explicity concentration at boundary in constant case
static inline double template <typename T>
calcExplicitConcentrationsTopBoundaryClosed(Eigen::MatrixXd &concentrations, constexpr T calcExplicitConcentrationsBoundaryConstant(T conc_center, T conc_bc,
Eigen::MatrixXd &alpha, T alpha_center,
int rowIndex, int i, double sy) { T alpha_neighbor, T sy) {
return sy * calcAlphaIntercell(alpha(rowIndex, i), alpha(rowIndex + 1, i)) * return sy * calcAlphaIntercell(alpha_center, alpha_neighbor) * conc_center +
concentrations(rowIndex, i) + (1 - sy * (calcAlphaIntercell(alpha_center, alpha_center) +
(1 - sy * (calcAlphaIntercell(alpha(rowIndex, i), 2 * alpha_center)) *
alpha(rowIndex + 1, i)))) * conc_center +
concentrations(rowIndex, i); sy * alpha_center * conc_bc;
}
// calculates explicit concentration at bottom boundary in constant case
static inline double calcExplicitConcentrationsBottomBoundaryConstant(
Eigen::MatrixXd &concentrations, Eigen::MatrixXd &alpha,
std::vector<BoundaryElement> &bcBottom, int rowIndex, int i, double sy) {
return sy * alpha(rowIndex, i) * bcBottom[i].getValue() +
(1 - sy * (2 * alpha(rowIndex, i) +
calcAlphaIntercell(alpha(rowIndex - 1, i),
alpha(rowIndex, i)))) *
concentrations(rowIndex, i) +
sy * calcAlphaIntercell(alpha(rowIndex - 1, i), alpha(rowIndex, i)) *
concentrations(rowIndex - 1, i);
}
// calculates explicit concentration at bottom boundary in closed case
static inline double
calcExplicitConcentrationsBottomBoundaryClosed(Eigen::MatrixXd &concentrations,
Eigen::MatrixXd &alpha,
int rowIndex, int i, double sy) {
return (1 - sy * (+calcAlphaIntercell(alpha(rowIndex - 1, i),
alpha(rowIndex, i)))) *
concentrations(rowIndex, i) +
sy * calcAlphaIntercell(alpha(rowIndex - 1, i), alpha(rowIndex, i)) *
concentrations(rowIndex - 1, i);
} }
// creates a solution vector for next time step from the current state of // creates a solution vector for next time step from the current state of
@ -203,13 +175,15 @@ static Eigen::VectorXd createSolutionVector(
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
switch (bcTop[i].getType()) { switch (bcTop[i].getType()) {
case BC_TYPE_CONSTANT: { case BC_TYPE_CONSTANT: {
sv(i) = calcExplicitConcentrationsTopBoundaryConstant( sv(i) = calcExplicitConcentrationsBoundaryConstant(
concentrations, alphaY, bcTop, rowIndex, i, sy); concentrations(rowIndex, i), bcTop[i].getValue(),
alphaY(rowIndex, i), alphaY(rowIndex + 1, i), sy);
break; break;
} }
case BC_TYPE_CLOSED: { case BC_TYPE_CLOSED: {
sv(i) = calcExplicitConcentrationsTopBoundaryClosed( sv(i) = calcExplicitConcentrationsBoundaryClosed(
concentrations, alphaY, rowIndex, i, sy); concentrations(rowIndex, i), alphaY(rowIndex, i),
alphaY(rowIndex + 1, i), sy);
break; break;
} }
default: default:
@ -224,13 +198,15 @@ static Eigen::VectorXd createSolutionVector(
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
switch (bcBottom[i].getType()) { switch (bcBottom[i].getType()) {
case BC_TYPE_CONSTANT: { case BC_TYPE_CONSTANT: {
sv(i) = calcExplicitConcentrationsBottomBoundaryConstant( sv(i) = calcExplicitConcentrationsBoundaryConstant(
concentrations, alphaY, bcBottom, rowIndex, i, sy); concentrations(rowIndex, i), bcBottom[i].getValue(),
alphaY(rowIndex, i), alphaY(rowIndex - 1, i), sy);
break; break;
} }
case BC_TYPE_CLOSED: { case BC_TYPE_CLOSED: {
sv(i) = calcExplicitConcentrationsBottomBoundaryClosed( sv(i) = calcExplicitConcentrationsBoundaryClosed(
concentrations, alphaY, rowIndex, i, sy); concentrations(rowIndex, i), alphaY(rowIndex, i),
alphaY(rowIndex - 1, i), sy);
break; break;
} }
default: default: