diff --git a/include/tug/Boundary.hpp b/include/tug/Boundary.hpp index 10b9460..b803e75 100644 --- a/include/tug/Boundary.hpp +++ b/include/tug/Boundary.hpp @@ -81,8 +81,8 @@ public: double getValue(); private: - BC_TYPE type; - double value; + BC_TYPE type{BC_TYPE_CLOSED}; + double value{-1}; }; /** diff --git a/src/Boundary.cpp b/src/Boundary.cpp index 083e802..def9bbd 100644 --- a/src/Boundary.cpp +++ b/src/Boundary.cpp @@ -1,20 +1,13 @@ #include "TugUtils.hpp" -#include -#include +#include #include #include -BoundaryElement::BoundaryElement() { +BoundaryElement::BoundaryElement() {} - this->type = BC_TYPE_CLOSED; - this->value = -1; // without meaning in closed case -} - -BoundaryElement::BoundaryElement(double value) { - this->type = BC_TYPE_CONSTANT; - this->value = value; -} +BoundaryElement::BoundaryElement(double _value) + : value(_value), type(BC_TYPE_CONSTANT) {} void BoundaryElement::setType(BC_TYPE type) { this->type = type; } @@ -64,12 +57,9 @@ void Boundary::setBoundarySideClosed(BC_SIDE side) { } } - int n; - if (side == BC_SIDE_LEFT || side == BC_SIDE_RIGHT) { - n = grid.getRow(); - } else { - n = grid.getCol(); - } + const bool is_vertical = side == BC_SIDE_LEFT || side == BC_SIDE_RIGHT; + const int n = is_vertical ? grid.getRow() : grid.getCol(); + this->boundaries[side] = std::vector(n, BoundaryElement()); } @@ -82,13 +72,11 @@ void Boundary::setBoundarySideConstant(BC_SIDE side, double value) { } } - int n; - if (side == BC_SIDE_LEFT || side == BC_SIDE_RIGHT) { - n = grid.getRow(); - } else { - n = grid.getCol(); - } - this->boundaries[side] = std::vector(n, BoundaryElement(value)); + const bool is_vertical = side == BC_SIDE_LEFT || side == BC_SIDE_RIGHT; + const int n = is_vertical ? grid.getRow() : grid.getCol(); + + this->boundaries[side] = + std::vector(n, BoundaryElement(value)); } void Boundary::setBoundaryElementClosed(BC_SIDE side, int index) { @@ -121,7 +109,7 @@ const std::vector Boundary::getBoundarySide(BC_SIDE side) { } Eigen::VectorXd Boundary::getBoundarySideValues(BC_SIDE side) { - int length = boundaries[side].size(); + const std::size_t length = boundaries[side].size(); Eigen::VectorXd values(length); for (int i = 0; i < length; i++) {