MADNESS  version 0.9
complexfun.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31  $Id$
32 */
33 /*
34  * complexfun.h
35  *
36  * Created on: Jan 28, 2009
37  * Author: eh7
38  */
39 
40 #ifndef COMPLEXFUN_H_
41 #define COMPLEXFUN_H_
42 
43 #include <madness/mra/mra.h>
44 
45 namespace madness {
46 
47 //***************************************************************************
48 double abs(double x) {return fabs(x);}
49 //***************************************************************************
50 
51 //***************************************************************************
52 double real(double x) {return x;}
53 //***************************************************************************
54 
55 //***************************************************************************
56 double imag(double x) {return 0.0;}
57 //***************************************************************************
58 
60 //double conj(double x) {return 0.0;}
62 
63 //***************************************************************************
64 template <typename Q>
65 Tensor< std::complex<Q> > tensor_real2complex(const Tensor<Q>& r)
66 {
67  Tensor< std::complex<Q> > c(r.ndim(), r.dims());
68  BINARY_OPTIMIZED_ITERATOR(const Q, r, std::complex<Q>, c, *_p1 = std::complex<Q>(*_p0,0.0););
69  return c;
70 }
71 //***************************************************************************
72 
73 //***************************************************************************
74 template <typename Q>
75 Tensor<Q> tensor_xreal(const Tensor< std::complex<Q> >& c)
76 {
77  Tensor<Q> r(c.ndim(), c.dims());
78  BINARY_OPTIMIZED_ITERATOR(Q, r, const std::complex<Q>, c, *_p0 = real(*_p1););
79  return r;
80 }
81 //***************************************************************************
82 
83 //***************************************************************************
84 template <typename Q>
85 Tensor<Q> tensor_ximag(const Tensor< std::complex<Q> >& c)
86 {
87  Tensor<Q> r(c.ndim(), c.dims());
88  BINARY_OPTIMIZED_ITERATOR(Q, r, const std::complex<Q>, c, *_p0 = imag(*_p1););
89  return r;
90 }
91 //***************************************************************************
92 
93 //***************************************************************************
94 template <typename Q>
95 Tensor<Q> tensor_abs(const Tensor< std::complex<Q> >& c)
96 {
97  Tensor<Q> r(c.ndim(), c.dims());
98  BINARY_OPTIMIZED_ITERATOR(Q, r, const std::complex<Q>, c, *_p0 = abs(*_p1););
99  return r;
100 }
101 //***************************************************************************
102 
103 //***************************************************************************
104 template <typename Q, int NDIM>
106 {
108  Tensor<resultT> operator()(const Key<NDIM>& key, const Tensor<Q>& t) const
109  {
110  Tensor<resultT> result(t.ndim(), t.dims());
111  BINARY_OPTIMIZED_ITERATOR(const Q, t, resultT, result, resultT d = abs(*_p0); *_p1 = d*d);
112  return result;
113  }
114  template <typename Archive>
115  void serialize(Archive& ar) {}
116 };
117 //***************************************************************************
118 
119 //***************************************************************************
120 template<typename Q, int NDIM>
122 {
123  return unary_op(func, abs_square_op<Q,NDIM>());
124 }
125 //***************************************************************************
126 
127 //***************************************************************************
128 template <typename Q, int NDIM>
129 struct real_op
130 {
132  Tensor<resultT> operator()(const Key<NDIM>& key, const Tensor<Q>& t) const
133  {
134  Tensor<resultT> result(t.ndim(), t.dims());
135  BINARY_OPTIMIZED_ITERATOR(const Q, t, resultT, result, *_p1 = real(*_p0););
136  return result;
137  }
138  template <typename Archive>
139  void serialize(Archive& ar) {}
140 };
141 //***************************************************************************
142 
143 //***************************************************************************
144 template<typename Q, int NDIM>
146 {
147  return unary_op_coeffs(func, real_op<Q,NDIM>());
148 }
149 //***************************************************************************
150 
151 //***************************************************************************
152 template <typename Q, int NDIM>
153 struct imag_op
154 {
156  Tensor<resultT> operator()(const Key<NDIM>& key, const Tensor<Q>& t) const
157  {
158  Tensor<resultT> result(t.ndim(), t.dims());
159  BINARY_OPTIMIZED_ITERATOR(const Q, t, resultT, result, *_p1 = imag(*_p0););
160  return result;
161  }
162  template <typename Archive>
163  void serialize(Archive& ar) {}
164 };
165 //***************************************************************************
166 
167 //***************************************************************************
168 template<typename Q, int NDIM>
170 {
171  return unary_op_coeffs(func, imag_op<Q,NDIM>());
172 }
173 //***************************************************************************
174 
175 //***************************************************************************
176 template <typename Q, int NDIM>
177 struct abs_op
178 {
180  Tensor<resultT> operator()(const Key<NDIM>& key, const Tensor<Q>& t) const
181  {
182  Tensor<resultT> result(t.ndim(), t.dims());
183  BINARY_OPTIMIZED_ITERATOR(const Q, t, resultT, result, *_p1 = abs(*_p0););
184  return result;
185  }
186  template <typename Archive>
187  void serialize(Archive& ar) {}
188 };
189 //***************************************************************************
190 
191 //***************************************************************************
192 template<typename Q, int NDIM>
194 {
195  return unary_op_coeffs(func, abs_op<Q,NDIM>());
196 }
197 //***************************************************************************
198 
199 //***************************************************************************
200 template <typename Q, int NDIM>
201 struct conj_op
202 {
203  typedef Q resultT;
204  Tensor<resultT> operator()(const Key<NDIM>& key, const Tensor<Q>& t) const
205  {
206  Tensor<resultT> result(t.ndim(), t.dims());
207  BINARY_OPTIMIZED_ITERATOR(const Q, t, resultT, result, *_p1 = conj(*_p0););
208  return result;
209  }
210  template <typename Archive>
211  void serialize(Archive& ar) {}
212 };
213 //***************************************************************************
214 
216 //template<typename Q, int NDIM>
217 //Function<Q,NDIM> conj(const Function<Q,NDIM>& func)
218 //{
219 // return unary_op_coeffs(func, conj_op<Q,NDIM>());
220 //}
222 
223 //***************************************************************************
224 template <typename Q, int NDIM>
226 {
227  typedef std::complex<Q> resultT;
228  Tensor<resultT> operator()(const Key<NDIM>& key, const Tensor<Q>& t) const
229  {
230  Tensor<resultT> result(t.ndim(), t.dims());
231  BINARY_OPTIMIZED_ITERATOR(const Q, t, resultT, result, *_p1 = resultT(*_p0,0.0););
232  return result;
233  }
234  template <typename Archive>
235  void serialize(Archive& ar) {}
236 };
237 //***************************************************************************
238 
239 //***************************************************************************
240 template <typename Q, int NDIM>
242 {
244 }
245 //***************************************************************************
246 
247 
249 //template <typename Q, int NDIM>
250 //bool is_real(const Function<std::complex<Q>,NDIM>& f)
251 //{
252 // Function<Q,NDIM> fim = imag(f);
253 // return (fim.norm2() < 1e-8) ? true : false;
254 //}
256 //
258 //template <typename Q, int NDIM>
259 //bool is_imag(const Function<std::complex<Q>,NDIM>& f)
260 //{
261 // Function<Q,NDIM> fre = real(f);
262 // return (fre.norm2() < 1e-8) ? true : false;
263 //}
265 
266 }
267 #endif /* COMPLEXFUN_H_ */
Tensor< Q > tensor_xreal(const Tensor< std::complex< Q > > &c)
Definition: complexfun.h:75
std::complex< double > func(int n, int t1, int t2, int t3, double xx, double yy, double zz)
Definition: wannier.cc:98
double imag(double x)
Definition: complexfun.h:56
Main include file for MADNESS and defines Function interface.
const int NDIM
Definition: tdse1.cc:44
Q resultT
Definition: complexfun.h:203
void serialize(Archive &ar)
Definition: complexfun.h:187
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:179
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:107
#define BINARY_OPTIMIZED_ITERATOR(X, x, Y, y, exp)
Definition: tensor_macros.h:701
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:132
Tensor< Q > tensor_abs(const Tensor< std::complex< Q > > &c)
Definition: complexfun.h:95
Definition: complexfun.h:177
Definition: complexfun.h:201
Function< typename TensorTypeData< Q >::scalar_type, NDIM > abs_square(const Function< Q, NDIM > &func)
Definition: complexfun.h:121
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:155
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:228
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:180
Function< typename opT::resultT, NDIM > unary_op_coeffs(const Function< Q, NDIM > &func, const opT &op, bool fence=true)
Out of place application of unary operation to scaling function coefficients with optional fence...
Definition: mra.h:1620
Definition: complexfun.h:225
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:204
void serialize(Archive &ar)
Definition: complexfun.h:211
A multiresolution adaptive numerical function.
Definition: derivative.h:61
void serialize(Archive &ar)
Definition: complexfun.h:139
void serialize(Archive &ar)
Definition: complexfun.h:163
Function< typename opT::resultT, NDIM > unary_op(const Function< Q, NDIM > &func, const opT &op, bool fence=true)
Out of place application of unary operation to function values with optional fence.
Definition: mra.h:1607
double real(double x)
Definition: complexfun.h:52
double abs(double x)
Definition: complexfun.h:48
Definition: complexfun.h:153
void serialize(Archive &ar)
Definition: complexfun.h:235
Tensor< std::complex< Q > > tensor_real2complex(const Tensor< Q > &r)
Definition: complexfun.h:65
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:108
Definition: complexfun.h:129
Definition: complexfun.h:105
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:131
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:156
const mpreal fabs(const mpreal &v, mp_rnd_t rnd_mode)
Definition: mpreal.h:2187
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Tensor< Q > tensor_ximag(const Tensor< std::complex< Q > > &c)
Definition: complexfun.h:85
const double c
Definition: gfit.cc:200
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
Function< std::complex< Q >, NDIM > function_real2complex(const Function< Q, NDIM > &r)
Definition: complexfun.h:241
Traits class to specify support of numeric types.
Definition: type_data.h:56
Function< T, NDIM > conj(const Function< T, NDIM > &f, bool fence=true)
Return the complex conjugate of the input function with the same distribution and optional fence...
Definition: mra.h:1879
std::complex< Q > resultT
Definition: complexfun.h:227
void serialize(Archive &ar)
Definition: complexfun.h:115