MADNESS  0.10.1
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 
59 ////***************************************************************************
60 //double conj(double x) {return 0.0;}
61 ////***************************************************************************
62 
63 //***************************************************************************
64 template <typename Q>
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 {
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 {
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 {
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 {
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 
215 ////***************************************************************************
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 //}
221 ////***************************************************************************
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 
248 ////***************************************************************************
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 //}
255 ////***************************************************************************
256 //
257 ////***************************************************************************
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 //}
264 ////***************************************************************************
265 
266 }
267 #endif /* COMPLEXFUN_H_ */
const long * dims() const
Returns the array of tensor dimensions.
Definition: basetensor.h:153
long ndim() const
Returns the number of dimensions in the tensor.
Definition: basetensor.h:144
A multiresolution adaptive numerical function.
Definition: mra.h:122
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:66
Traits class to specify support of numeric types.
Definition: type_data.h:56
A tensor is a multidimension array.
Definition: tensor.h:317
Main include file for MADNESS and defines Function interface.
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
Tensor< Q > tensor_abs(const Tensor< std::complex< Q > > &c)
Definition: complexfun.h:95
double abs(double x)
Definition: complexfun.h:48
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:2046
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:1793
Function< typename TensorTypeData< Q >::scalar_type, NDIM > abs_square(const Function< Q, NDIM > &func)
Definition: complexfun.h:121
Tensor< std::complex< Q > > tensor_real2complex(const Tensor< Q > &r)
Definition: complexfun.h:65
Tensor< Q > tensor_ximag(const Tensor< std::complex< Q > > &c)
Definition: complexfun.h:85
Function< std::complex< Q >, NDIM > function_real2complex(const Function< Q, NDIM > &r)
Definition: complexfun.h:241
std::shared_ptr< FunctionFunctorInterface< double, 3 > > func(new opT(g))
double imag(double x)
Definition: complexfun.h:56
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:1780
double real(double x)
Definition: complexfun.h:52
Tensor< Q > tensor_xreal(const Tensor< std::complex< Q > > &c)
Definition: complexfun.h:75
double Q(double a)
Definition: relops.cc:20
static const double c
Definition: relops.cc:10
Definition: complexfun.h:178
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:180
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:179
void serialize(Archive &ar)
Definition: complexfun.h:187
Definition: complexfun.h:106
void serialize(Archive &ar)
Definition: complexfun.h:115
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:108
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:107
Definition: complexfun.h:202
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:204
Q resultT
Definition: complexfun.h:203
void serialize(Archive &ar)
Definition: complexfun.h:211
Definition: complexfun.h:226
void serialize(Archive &ar)
Definition: complexfun.h:235
std::complex< Q > resultT
Definition: complexfun.h:227
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:228
Definition: complexfun.h:154
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:155
void serialize(Archive &ar)
Definition: complexfun.h:163
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:156
Definition: complexfun.h:130
TensorTypeData< Q >::scalar_type resultT
Definition: complexfun.h:131
void serialize(Archive &ar)
Definition: complexfun.h:139
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition: complexfun.h:132
#define BINARY_OPTIMIZED_ITERATOR(X, x, Y, y, exp)
Definition: tensor_macros.h:701
void d()
Definition: test_sig.cc:79
static const std::size_t NDIM
Definition: testpdiff.cc:42