[c74fdb] | 1 | /*
|
---|
| 2 | * Fragment.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: Aug 8, 2012
|
---|
| 5 | * Author: heber
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef FRAGMENT_HPP_
|
---|
| 9 | #define FRAGMENT_HPP_
|
---|
| 10 |
|
---|
| 11 |
|
---|
| 12 | // include config.h
|
---|
| 13 | #ifdef HAVE_CONFIG_H
|
---|
| 14 | #include <config.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[a576eb] | 17 | #include <boost/serialization/export.hpp>
|
---|
| 18 | #include <boost/serialization/vector.hpp>
|
---|
| 19 | #include <boost/serialization/utility.hpp>
|
---|
| 20 |
|
---|
[184943] | 21 | #include <iosfwd>
|
---|
[c74fdb] | 22 | #include <vector>
|
---|
| 23 |
|
---|
[f3bc5f] | 24 | class FragmentTest;
|
---|
| 25 |
|
---|
[c74fdb] | 26 | class Fragment {
|
---|
[184943] | 27 | //!> grant ostream operator access
|
---|
| 28 | friend std::ostream & operator<<(std::ostream &ost, const Fragment &f);
|
---|
[f3bc5f] | 29 | //!> grant unit test access
|
---|
| 30 | friend class FragmentTest;
|
---|
[c74fdb] | 31 | public:
|
---|
[f3bc5f] | 32 | typedef std::vector<double> position_t;
|
---|
| 33 | typedef std::vector< position_t > positions_t;
|
---|
[4a77be7] | 34 | typedef double charge_t;
|
---|
| 35 | typedef std::vector< charge_t > charges_t;
|
---|
| 36 | typedef std::pair< position_t, charge_t> nucleus_t;
|
---|
[c74fdb] | 37 | typedef std::vector< nucleus_t > nuclei_t;
|
---|
| 38 |
|
---|
| 39 | /** Default constructor of class Fragment.
|
---|
| 40 | *
|
---|
| 41 | */
|
---|
| 42 | Fragment();
|
---|
| 43 |
|
---|
| 44 | /** Default constructor of class Fragment.
|
---|
| 45 | *
|
---|
| 46 | */
|
---|
| 47 | Fragment(const nuclei_t &_nuclei) :
|
---|
| 48 | nuclei(_nuclei)
|
---|
| 49 | {}
|
---|
| 50 |
|
---|
| 51 | /** Constructor of class Fragment.
|
---|
| 52 | *
|
---|
| 53 | * @param _positions given positions
|
---|
| 54 | * @param _charges given charges
|
---|
| 55 | */
|
---|
[f3bc5f] | 56 | Fragment(const positions_t &_positions, const charges_t &_charges);
|
---|
[c74fdb] | 57 |
|
---|
| 58 | /** Adding another fragment onto this one.
|
---|
| 59 | *
|
---|
| 60 | * \note The operation is area-conserving, i.e. the new area is the sum of
|
---|
| 61 | * both areas.
|
---|
| 62 | *
|
---|
| 63 | * @param other other fragment
|
---|
| 64 | * @return ref to this instance
|
---|
| 65 | */
|
---|
| 66 | Fragment& operator+=(const Fragment &other);
|
---|
| 67 |
|
---|
| 68 | /** Assignment operator.
|
---|
| 69 | *
|
---|
| 70 | * @param other other fragment to make ourselves equal to
|
---|
| 71 | * @return ref to this instance
|
---|
| 72 | */
|
---|
| 73 | Fragment& operator=(const Fragment &other);
|
---|
| 74 |
|
---|
| 75 | /** Subtracting another fragment from this one.
|
---|
| 76 | *
|
---|
| 77 | * @param other other fragment
|
---|
| 78 | * @return ref to this instance
|
---|
| 79 | */
|
---|
| 80 | Fragment& operator-=(const Fragment &other);
|
---|
| 81 |
|
---|
[184943] | 82 | /** Getter for all stored positions.
|
---|
| 83 | *
|
---|
| 84 | * @return vector of positions
|
---|
| 85 | */
|
---|
| 86 | positions_t getPositions() const;
|
---|
| 87 |
|
---|
| 88 | /** Getter for all stored charges.
|
---|
| 89 | *
|
---|
| 90 | * @return vector of charges
|
---|
| 91 | */
|
---|
| 92 | charges_t getCharges() const;
|
---|
| 93 |
|
---|
[f3bc5f] | 94 | /** Equality operator.
|
---|
| 95 | *
|
---|
| 96 | * @param other other instance to check against
|
---|
| 97 | * @return true - both are equal, false - some nucleus_t differ
|
---|
| 98 | */
|
---|
| 99 | bool operator==(const Fragment& other) const;
|
---|
| 100 |
|
---|
| 101 | bool operator!=(const Fragment& other) const
|
---|
| 102 | {
|
---|
| 103 | return (!(*this == other));
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /** Creates type nucleus_t from given \a position and \a charge.
|
---|
| 107 | *
|
---|
| 108 | * @param position position of nucleus to create
|
---|
| 109 | * @param charge charge of nucleus to create
|
---|
| 110 | * @return nucleus with given \a position and \a charge
|
---|
| 111 | */
|
---|
| 112 | static nucleus_t createNucleus(const position_t &position, const double charge);
|
---|
| 113 |
|
---|
| 114 | /** Helper function to check whether two positions are equal.
|
---|
| 115 | *
|
---|
| 116 | * @param a first position
|
---|
| 117 | * @param b second position
|
---|
| 118 | * @return a equals b within numerical precision
|
---|
| 119 | */
|
---|
| 120 | static bool isPositionEqual(const position_t &a, const position_t &b);
|
---|
| 121 |
|
---|
[c74fdb] | 122 | private:
|
---|
[f3bc5f] | 123 | /** Helper function that checks whether this nuclei \b position is present.
|
---|
[c74fdb] | 124 | *
|
---|
| 125 | * This operation is \f${\cal O}(n)\f$
|
---|
| 126 | *
|
---|
| 127 | * @param n nuclei to check
|
---|
| 128 | * @return true - is contained, false - is not contained
|
---|
| 129 | */
|
---|
| 130 | bool containsNuclei(const nucleus_t &n) const;
|
---|
| 131 |
|
---|
[f3bc5f] | 132 | /** Seeks through all nuclei and removes one with matching \b position if found.
|
---|
[c74fdb] | 133 | *
|
---|
| 134 | * @param n nuclei to remove
|
---|
| 135 | */
|
---|
| 136 | void removeNuclei(const nucleus_t &n);
|
---|
| 137 |
|
---|
| 138 | private:
|
---|
| 139 | nuclei_t nuclei;
|
---|
[a576eb] | 140 |
|
---|
| 141 | private:
|
---|
| 142 | friend class boost::serialization::access;
|
---|
| 143 | // serialization
|
---|
| 144 | template <typename Archive>
|
---|
| 145 | void serialize(Archive& ar, const unsigned int version)
|
---|
| 146 | {
|
---|
| 147 | ar & nuclei;
|
---|
| 148 | }
|
---|
[c74fdb] | 149 | };
|
---|
| 150 |
|
---|
[a576eb] | 151 | // we need to give this class a unique key for serialization
|
---|
| 152 | BOOST_CLASS_EXPORT_KEY(Fragment)
|
---|
| 153 |
|
---|
[f3bc5f] | 154 | /** Equality operator for two nuclei.
|
---|
| 155 | *
|
---|
| 156 | * @param a first nuclei
|
---|
| 157 | * @param b second nuclei
|
---|
| 158 | * @return true - both have same position and charge, false - either charge or position is different
|
---|
| 159 | */
|
---|
| 160 | bool operator==(const Fragment::nucleus_t &a, const Fragment::nucleus_t &b);
|
---|
| 161 |
|
---|
| 162 | std::ostream & operator<<(std::ostream &ost, const Fragment::nucleus_t &n);
|
---|
| 163 |
|
---|
[184943] | 164 | std::ostream & operator<<(std::ostream &ost, const Fragment &f);
|
---|
| 165 |
|
---|
[c74fdb] | 166 | template<typename T> T ZeroInstance();
|
---|
| 167 | template<> Fragment ZeroInstance<Fragment>();
|
---|
| 168 |
|
---|
| 169 | #endif /* FRAGMENT_HPP_ */
|
---|