FCostCell.hpp 2.55 KB
Newer Older
1 2 3 4 5 6 7
// ==== CMAKE ====
// Keep in private GIT
// @SCALFMM_PRIVATE

#ifndef _FCOSTCELL_HPP_
#define _FCOSTCELL_HPP_

8 9
#include <type_traits>

10 11 12 13 14 15 16 17 18 19 20

/** 
 * \brief Empty trait class.
 * \author Quentin Khan
 *
 * This class is used to check whether a cell class has FCostCell in its
 * inheritance tree.
 */
class FCostCellTypeTrait {};


21 22 23 24 25 26 27 28
/**
 * \brief Cell with a cost memory for balance computations.
 * \author Quentin Khan
 *
 * This class extends BaseClass to add simple computation cost memory.
 *
 * \tparam BaseClass The base cell class to extend. The constructors are
 * inherited automatically.
29
 * \tparam CostType The type to use in order to store the cost. Defaults to FSize.
30 31
 */
template<typename BaseClass, typename CostType = FSize>
32
class FCostCell : public BaseClass, virtual public FCostCellTypeTrait {
33 34 35 36 37
    static_assert(std::is_arithmetic<CostType>::value,
                  "The cell cost type must be an arithmetic type.");

    /// The far-field cost of the cell.
    /** Declared mutable because the existing algorithms use const cells.*/
38
    mutable CostType _cost = 0;
39 40 41 42 43

    /// The near-field cost of the cell.
    /** Declared mutable because the existing algorithms use const cells.*/
    mutable CostType _leafCost = 0;

44
public:
45 46 47
    /// Type definition that can be retrieved by other classes
    using costtype = CostType;

48 49 50 51 52 53
    using BaseClass::BaseClass;

    /// Debug member, used to check whether the cell was already visited.
    bool _visited = false;

    /**
54 55
     * \brief Gets the far-field cost of the cell.
     * \return The far-field cost of the cell
56 57 58 59 60
     */
    CostType getCost() const {
        return _cost;
    }

61 62 63 64 65 66 67 68
    /**
     * \brief Gets the near-field cost of the cell.
     * \return The near-field cost of the cell
     */
    CostType getNearCost() const {
        return _leafCost;
    }

69 70 71 72 73 74 75
    /**
     * \brief Sets the cost of the cell.
     */
    void setCost(CostType newCost) {
        _cost = newCost;
    }

76 77 78 79 80 81 82
    /**
     * \brief Sets the near-field cost of the cell.
     */
    void setNearCost(CostType newCost) {
        _leafCost = newCost;
    }

83
    /** 
84
     * \brief Add a far-field cost to the cell.
85 86 87 88 89 90 91
     * \return The cost of the cell
     * \warning Can be used on const cells !
     */
    CostType addCost(CostType cost) const {
        _cost += cost;
        return _cost;
    }
92 93 94 95 96 97 98 99 100 101

    /** 
     * \brief Add a near-field cost to the cell.
     * \return The cost of the cell
     * \warning Can be used on const cells !
     */
    CostType addNearCost(CostType cost) const {
        _leafCost += cost;
        return _leafCost;
    }
102 103 104
};

#endif