diff --git a/docs/source/api/cell.rst b/docs/source/api/cell.rst index 7c221a1ff..d1d06cac9 100644 --- a/docs/source/api/cell.rst +++ b/docs/source/api/cell.rst @@ -1,6 +1,5 @@ Cell class ========== -.. doxygenclass:: samurai::Cell +.. doxygenfile:: cell.hpp :project: samurai - :members: diff --git a/include/samurai/box.hpp b/include/samurai/box.hpp index 27f9cb693..1083ab672 100644 --- a/include/samurai/box.hpp +++ b/include/samurai/box.hpp @@ -55,7 +55,7 @@ namespace samurai //////////////////////// /** - * Construction of a bounded box. + * @brief Construction of a bounded box. * * @param min_corner The vertex with the minimum coordinates * @param max_corner The vertex with the maximum coordinates @@ -68,7 +68,7 @@ namespace samurai } /** - * Return the min corner of the box. + * @brief Return the min corner of the box. */ template inline auto Box::min_corner() const -> const point_t& @@ -77,7 +77,7 @@ namespace samurai } /** - * Return the min corner of the box. + * @brief Return the min corner of the box. */ template inline auto Box::min_corner() -> point_t& @@ -86,7 +86,7 @@ namespace samurai } /** - * Return the max corner of the box. + * @brief Return the max corner of the box. */ template inline auto Box::max_corner() const -> const point_t& @@ -95,7 +95,7 @@ namespace samurai } /** - * Return the max corner of the box. + * @brief Return the max corner of the box. */ template inline auto Box::max_corner() -> point_t& @@ -104,7 +104,7 @@ namespace samurai } /** - * Return the length of the box. + * @brief Return the length of the box. */ template inline auto Box::length() const @@ -113,7 +113,7 @@ namespace samurai } /** - * Return the minimum length of the box. + * @brief Return the minimum length of the box. */ template inline auto Box::min_length() const @@ -122,7 +122,7 @@ namespace samurai } /** - * Check if the box is valid. + * @brief Check if the box is valid. */ template inline bool Box::is_valid() const @@ -130,6 +130,11 @@ namespace samurai return xt::all(m_min_corner < m_max_corner); } + /** + * @brief Inplace homothety operator of ratio v. + * + * @param v Ratio of homothety. + */ template inline auto Box::operator*=(value_t v) -> Box& { @@ -138,6 +143,12 @@ namespace samurai return *this; } + /** + * @brief Homothety operator of ratio v. + * + * @param box Box to dilate. + * @param v Ratio of homothety. + */ template inline auto operator*(const Box& box, value_t v) { @@ -145,6 +156,12 @@ namespace samurai return that *= v; } + /** + * @brief Homothety operator of ratio v. + * + * @param v Ratio of homothety. + * @param box Box to dilate. + */ template inline auto operator*(value_t v, const Box& box) { @@ -152,6 +169,9 @@ namespace samurai return that *= v; } + /** + * @brief Insert formatted box into an output stream. + */ template inline std::ostream& operator<<(std::ostream& out, const Box& box) { @@ -159,6 +179,13 @@ namespace samurai return out; } + /** + * @brief Return approximate box with given subdivision length with a tolerance. + * + * @param box Box to approximate. + * @param tol Tolerance for approximate box if subdivision isn't given. + * @param subdivision_length Length of subdivision (modified if is 0 to the approximate box with given tolerance). + */ template Box approximate_box(const Box& box, double tol, double& subdivision_length) { diff --git a/include/samurai/cell.hpp b/include/samurai/cell.hpp index 5783ad905..828a1f86a 100644 --- a/include/samurai/cell.hpp +++ b/include/samurai/cell.hpp @@ -11,10 +11,16 @@ namespace samurai { + /** + * @brief Return length (\f$\Delta x\f$) of a cell on a specific level with a specific scaling factor + * + * @param scaling_factor Scaling factor of the box. + * @param level Level of cell. + */ template ::value, bool> = true> inline double cell_length(double scaling_factor, LevelType level) { - return scaling_factor / (1 << level); + return scaling_factor / static_cast(1 << level); } /** @class Cell @@ -29,12 +35,12 @@ namespace samurai template struct Cell { - static constexpr std::size_t dim = dim_; - using interval_t = TInterval; - using value_t = typename interval_t::value_t; - using index_t = typename interval_t::index_t; - using indices_t = xt::xtensor_fixed>; - using coords_t = xt::xtensor_fixed>; + static constexpr std::size_t dim = dim_; ///< The dimension of the cell. + using interval_t = TInterval; ///< Type of interval. + using value_t = typename interval_t::value_t; ///< Type of value stored in interval. + using index_t = typename interval_t::index_t; ///< Type of index stored in interval. + using indices_t = xt::xtensor_fixed>; ///< Type of indices to access to field data. + using coords_t = xt::xtensor_fixed>; ///< Type of coordinates. Cell() = default; @@ -46,14 +52,15 @@ namespace samurai const xt::xtensor_fixed> others, index_t index); + // The minimum corner of the cell. coords_t corner() const; double corner(std::size_t i) const; - /// The center of the cell. + // The center of the cell. coords_t center() const; double center(std::size_t i) const; - /// The center of the face in the requested Cartesian direction. + // The center of the face in the requested Cartesian direction. template coords_t face_center(const Vector& direction) const; @@ -74,6 +81,15 @@ namespace samurai double length = 0; }; + /** + * @brief Construct a new Cell::Cell object + * + * @param origin_point_ + * @param scaling_factor + * @param level_ + * @param indices_ + * @param index_ + */ template inline Cell::Cell(const coords_t& origin_point_, double scaling_factor, @@ -88,6 +104,16 @@ namespace samurai { } + /** + * @brief Construct a new Cell::Cell object + * + * @param origin_point_ + * @param scaling_factor + * @param level_ + * @param i + * @param others + * @param index_ + */ template inline Cell::Cell(const coords_t& origin_point_, double scaling_factor, @@ -107,7 +133,7 @@ namespace samurai } /** - * The minimum corner of the cell. + * @brief The minimum corner of the cell. */ template inline auto Cell::corner() const -> coords_t @@ -115,6 +141,11 @@ namespace samurai return origin_point + length * indices; } + /** + * @brief The ith coordinate of minimum corner of the cell. + * + * @param i Component number. + */ template inline double Cell::corner(std::size_t i) const { @@ -122,7 +153,7 @@ namespace samurai } /** - * The minimum corner of the cell. + * @brief The center of the cell. */ template inline auto Cell::center() const -> coords_t @@ -130,12 +161,23 @@ namespace samurai return origin_point + length * (indices + 0.5); } + /** + * @brief The ith coordinate of center of the cell. + * + * @param i Component number. + */ template inline double Cell::center(std::size_t i) const { return origin_point[i] + length * (indices[i] + 0.5); } + /** + * @brief The center of the face in the requested Cartesian direction. + * + * @tparam Vector Type of direction, must be addable with a `coords_t`. + * @param direction Cartesian unit vector of direction where we request center. + */ template template inline auto Cell::face_center(const Vector& direction) const -> coords_t @@ -144,12 +186,20 @@ namespace samurai return center() + (length / 2) * direction; } + /** + * @brief Insert formatted cell into an output stream. + * + * @param os output stream + */ template inline void Cell::to_stream(std::ostream& os) const { os << "Cell -> level: " << level << " indices: " << indices << " center: " << center() << " index: " << index; } + /** + * @brief Insert formatted cell into an output stream. + */ template inline std::ostream& operator<<(std::ostream& out, const Cell& cell) { @@ -157,12 +207,18 @@ namespace samurai return out; } + /** + * @brief Test equality between cells. + */ template inline bool operator==(const Cell& c1, const Cell& c2) { return !(c1.level != c2.level || c1.indices != c2.indices || c1.index != c2.index || c1.length != c2.length); } + /** + * @brief Test inequality between cells. + */ template inline bool operator!=(const Cell& c1, const Cell& c2) {