Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-02 08:48:23

0001 /*
0002  * VectorComplexD.h
0003  *
0004  *  Created on: Jan 16, 2016
0005  *      Author: Pawel Sznajder (IPNO)
0006  */
0007 
0008 #ifndef VECTORCOMPLEXD_H_
0009 #define VECTORCOMPLEXD_H_
0010 
0011 #include <complex>
0012 #include <vector>
0013 
0014 namespace NumA {
0015 
0016 /**
0017  * @class VectorComplexD
0018  *
0019  * @brief Vector of complex numbers of undefined size.
0020  *
0021  * This class represents a vector of complex double precision numbers. The size of this vector should be defined by the user.
0022  */
0023 class VectorComplexD {
0024 
0025 public:
0026 
0027     /**
0028      * Default constructor.
0029      */
0030     VectorComplexD();
0031 
0032     /**
0033      * Assignment constructor.
0034      * Elements will be initialized with `std::complex<double>(0., 0.).`
0035      * @param n Number of elements to be set.
0036      */
0037     VectorComplexD(const unsigned int n);
0038 
0039     /**
0040      * Copy constructor.
0041      * @param v Object to be copied.
0042      */
0043     VectorComplexD(const VectorComplexD& v);
0044 
0045     /**
0046      * Destructor.
0047      */
0048     virtual ~VectorComplexD();
0049 
0050     /**
0051      * Get magnitude of vector.
0052      * Return: \f$\sqrt{f \cdot f^{*}}\f$.
0053      */
0054     double Mag() const;
0055 
0056     /**
0057      * Get conjunction of vector.
0058      * Return: \f$f^{*}\f$.
0059      */
0060     VectorComplexD Conjunct() const;
0061 
0062     /**
0063      * Scalar product of this and other vector.
0064      * Return: \f$f \cdot g\f$.
0065      * @param v Other vector.
0066      */
0067     std::complex<double> Dot(const VectorComplexD& v) const;
0068 
0069     /**
0070      * Clear vector (set `std::complex<double>(0., 0.)` to all elements).
0071      */
0072     void Clear();
0073 
0074     /**
0075      * Operator =.
0076      */
0077      void operator=(const VectorComplexD& rhs);
0078 
0079     /**
0080      * Operator +.
0081      */
0082      VectorComplexD operator+(const VectorComplexD& rhs);
0083 
0084     /**
0085      * Operator -.
0086      */
0087      VectorComplexD operator-(const VectorComplexD& rhs);
0088 
0089     /**
0090      * Operator * by real number (rhs).
0091      */
0092      VectorComplexD operator*(const double& rhs);
0093 
0094     /**
0095      * Operator * by real number (lhs).
0096      */
0097     friend VectorComplexD operator*(const double& lhs, VectorComplexD& rhs);
0098 
0099     /**
0100      * Operator * by complex number (rhs).
0101      */
0102      VectorComplexD operator*(const std::complex<double>& rhs);
0103 
0104     /**
0105      * Operator * by complex number (lhs).
0106      */
0107     friend VectorComplexD operator*(const std::complex<double>& lhs,
0108             VectorComplexD& rhs);
0109 
0110     /**
0111      * Get number of elements.
0112      */
0113     unsigned int GetNElements() const;
0114 
0115     /**
0116      * Set element.
0117      * @param i Index of element to be set.
0118      * @param value Value to be set.
0119      */
0120     void SetElement(const unsigned int i, const std::complex<double>& value);
0121 
0122     /**
0123      * Get element.
0124      * @param i Index of element to be retrieved.
0125      */
0126     std::complex<double> GetElement(unsigned int i) const;
0127 
0128 private:
0129 
0130     /**
0131      * Compare number of elements of this and other vector. Throw `std::runtime_error` if the numbers are not equal.
0132      * @param v Other vector.
0133      */
0134     void CompareNElements(const VectorComplexD& v) const;
0135 
0136     /**
0137      * Number of elements.
0138      */
0139     unsigned int m_n;
0140 
0141     /**
0142      * Elements.
0143      */
0144     std::vector<std::complex<double> > m_elements;
0145 };
0146 
0147 } /* namespace NumA */
0148 
0149 #endif /* VECTORCOMPLEXD_H_ */