11#ifndef MATHZONE_H
22#define MATHZONE_H
33
4- #include " realarray.h"
5- #include " matrix3.h"
64#include " global_function.h"
7- #include < vector>
8- #include < map>
5+ #include " matrix3.h"
6+ #include " realarray.h"
7+
98#include < cassert>
109#include < complex>
10+ #include < map>
11+ #include < vector>
1112namespace ModuleBase
1213{
1314
15+ /* *
16+ * @brief atomic coordinates conversion functions
17+ *
18+ */
1419class Mathzone
1520{
16- public:
17-
21+ public:
1822 Mathzone ();
1923 ~Mathzone ();
2024
21- template <class T >
22- static T Max3 (const T &a,const T &b,const T &c)
25+ public:
26+ /* *
27+ * @brief Pointwise product of two vectors with same size
28+ *
29+ * @tparam Type
30+ * @param[in] f1
31+ * @param[in] f2
32+ * @return std::vector<Type>
33+ * @author Peize Lin (2016-08-03)
34+ */
35+ template <typename Type>
36+ static std::vector<Type> Pointwise_Product (const std::vector<Type> &f1, const std::vector<Type> &f2)
2337 {
24- if (a>=b && a>=c) return a;
25- else if (b>=a && b>=c) return b;
26- else if (c>=a && c>=b) return c;
27- else throw std::runtime_error (ModuleBase::GlobalFunc::TO_STRING (__FILE__)+" line " +ModuleBase::GlobalFunc::TO_STRING (__LINE__));
38+ assert (f1.size () == f2.size ());
39+ std::vector<Type> f (f1.size ());
40+ for (int ir = 0 ; ir != f.size (); ++ir)
41+ f[ir] = f1[ir] * f2[ir];
42+ return f;
2843 }
2944
30- // be careful, this can only be used for plane wave
31- // during parallel calculation
32-
33- public:
34-
35-
36-
37- // Peize Lin add 2016-08-03
38- template < typename Type >
39- static std::vector<Type> Pointwise_Product ( const std::vector<Type> &f1, const std::vector<Type> &f2 )
40- {
41- assert (f1.size ()==f2.size ());
42- std::vector<Type> f (f1.size ());
43- for ( int ir=0 ; ir!=f.size (); ++ir )
44- f[ir] = f1[ir] * f2[ir];
45- return f;
46- }
47-
48- // ==========================================================
49- // MEMBER FUNCTION :
50- // NAME : Direct_to_Cartesian
51- // use lattice vector matrix R
52- // change the direct std::vector (dx,dy,dz) to cartesuab vectir
53- // (cx,cy,cz)
54- // (dx,dy,dz) = (cx,cy,cz) * R
55- //
56- // NAME : Cartesian_to_Direct
57- // the same as above
58- // (cx,cy,cz) = (dx,dy,dz) * R^(-1)
59- // ==========================================================
60- static inline void Direct_to_Cartesian
61- (
62- const double &dx,const double &dy,const double &dz,
63- const double &R11,const double &R12,const double &R13,
64- const double &R21,const double &R22,const double &R23,
65- const double &R31,const double &R32,const double &R33,
66- double &cx,double &cy,double &cz)
45+ /* *
46+ * @brief change direct coordinate (dx,dy,dz) to
47+ * Cartesian coordinate (cx,cy,cz), (dx,dy,dz) = (cx,cy,cz) * R
48+ *
49+ * @param[in] dx Direct coordinats
50+ * @param[in] dy
51+ * @param[in] dz
52+ * @param[in] R11 Lattice vector matrix R_ij: i_row, j_column
53+ * @param[in] R12
54+ * @param[in] R13
55+ * @param[in] R21
56+ * @param[in] R22
57+ * @param[in] R23
58+ * @param[in] R31
59+ * @param[in] R32
60+ * @param[in] R33
61+ * @param[out] cx Cartesian coordinats
62+ * @param[out] cy
63+ * @param[out] cz
64+ */
65+ static inline void Direct_to_Cartesian (const double &dx,
66+ const double &dy,
67+ const double &dz,
68+ const double &R11,
69+ const double &R12,
70+ const double &R13,
71+ const double &R21,
72+ const double &R22,
73+ const double &R23,
74+ const double &R31,
75+ const double &R32,
76+ const double &R33,
77+ double &cx,
78+ double &cy,
79+ double &cz)
6780 {
6881 static ModuleBase::Matrix3 lattice_vector;
6982 static ModuleBase::Vector3<double > direct_vec, cartesian_vec;
@@ -88,13 +101,41 @@ class Mathzone
88101 return ;
89102 }
90103
91- static inline void Cartesian_to_Direct
92- (
93- const double &cx,const double &cy,const double &cz,
94- const double &R11,const double &R12,const double &R13,
95- const double &R21,const double &R22,const double &R23,
96- const double &R31,const double &R32,const double &R33,
97- double &dx,double &dy,double &dz)
104+ /* *
105+ * @brief Change Cartesian coordinate (cx,cy,cz) to
106+ * direct coordinate (dx,dy,dz), (cx,cy,cz) = (dx,dy,dz) * R^(-1)
107+ *
108+ * @param[in] cx Cartesian coordinats
109+ * @param[in] cy
110+ * @param[in] cz
111+ * @param[in] R11 Lattice vector matrix R_ij: i_row, j_column
112+ * @param[in] R12
113+ * @param[in] R13
114+ * @param[in] R21
115+ * @param[in] R22
116+ * @param[in] R23
117+ * @param[in] R31
118+ * @param[in] R32
119+ * @param[in] R33
120+ * @param[out] dx Direct coordinats
121+ * @param[out] dy
122+ * @param[out] dz
123+ */
124+ static inline void Cartesian_to_Direct (const double &cx,
125+ const double &cy,
126+ const double &cz,
127+ const double &R11,
128+ const double &R12,
129+ const double &R13,
130+ const double &R21,
131+ const double &R22,
132+ const double &R23,
133+ const double &R31,
134+ const double &R32,
135+ const double &R33,
136+ double &dx,
137+ double &dy,
138+ double &dz)
98139 {
99140 static ModuleBase::Matrix3 lattice_vector, inv_lat;
100141 lattice_vector.e11 = R11;
@@ -120,45 +161,17 @@ class Mathzone
120161 return ;
121162 }
122163
123-
124- static void To_Polar_Coordinate
164+ void To_Polar_Coordinate
125165 (
126- const double &x_cartesian,
127- const double &y_cartesian,
128- const double &z_cartesian,
129- double &r,
130- double &theta,
131- double &phi
132- );
133-
134-
135- // coeff1 * x1 + (1-coeff1) * x2
136- // Peize Lin add 2017-08-09
137- template < typename T, typename T_coeff >
138- static T Linear_Mixing ( const T & x1, const T & x2, const T_coeff & coeff1 )
139- {
140- return coeff1 * x1 + (1 -coeff1) * x2;
141- }
142- template < typename T, typename T_coeff >
143- static std::vector<T> Linear_Mixing ( const std::vector<T> & x1, const std::vector<T> & x2, const T_coeff & coeff1 )
144- {
145- assert (x1.size ()==x2.size ());
146- std::vector<T> x;
147- for ( size_t i=0 ; i!=x1.size (); ++i )
148- x.push_back ( Linear_Mixing ( x1[i], x2[i], coeff1 ) );
149- return x;
150- }
151- template < typename T1, typename T2, typename T_coeff >
152- static std::map<T1,T2> Linear_Mixing ( const std::map<T1,T2> & x1, const std::map<T1,T2> & x2, const T_coeff & coeff1 )
153- {
154- std::map<T1,T2> x;
155- for ( const auto & x1i : x1 )
156- x.insert ( make_pair ( x1i.first , Linear_Mixing ( x1i.second , x2.at (x1i.first ), coeff1 ) ) );
157- return x;
158- }
166+ const double &x_cartesian,
167+ const double &y_cartesian,
168+ const double &z_cartesian,
169+ double &r,
170+ double &theta,
171+ double &phi);
159172
160173};
161174
162- }
175+ } // namespace ModuleBase
163176
164177#endif
0 commit comments