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
45namespace madness {
46
47//***************************************************************************
48double abs(double x) {return fabs(x);}
49//***************************************************************************
50
51//***************************************************************************
52double real(double x) {return x;}
53//***************************************************************************
54
55//***************************************************************************
56double imag(double x) {return 0.0;}
57//***************************************************************************
58
59////***************************************************************************
60//double conj(double x) {return 0.0;}
61////***************************************************************************
62
63//***************************************************************************
64template <typename Q>
66{
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//***************************************************************************
74template <typename Q>
75Tensor<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//***************************************************************************
84template <typename Q>
85Tensor<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//***************************************************************************
94template <typename Q>
95Tensor<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//***************************************************************************
104template <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//***************************************************************************
120template<typename Q, int NDIM>
125//***************************************************************************
126
127//***************************************************************************
128template <typename Q, int NDIM>
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//***************************************************************************
144template<typename Q, int NDIM>
149//***************************************************************************
150
151//***************************************************************************
152template <typename Q, int NDIM>
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//***************************************************************************
168template<typename Q, int NDIM>
173//***************************************************************************
174
175//***************************************************************************
176template <typename Q, int NDIM>
177struct 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//***************************************************************************
192template<typename Q, int NDIM>
197//***************************************************************************
198
199//***************************************************************************
200template <typename Q, int NDIM>
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//***************************************************************************
224template <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//***************************************************************************
240template <typename Q, int NDIM>
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.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
double abs(double x)
Definition complexfun.h:48
Function< typename TensorTypeData< Q >::scalar_type, NDIM > abs_square(const Function< Q, NDIM > &func)
Definition complexfun.h:121
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< std::complex< Q >, NDIM > function_real2complex(const Function< Q, NDIM > &r)
Definition complexfun.h:241
Tensor< Q > tensor_abs(const Tensor< std::complex< Q > > &c)
Definition complexfun.h:95
std::shared_ptr< FunctionFunctorInterface< double, 3 > > func(new opT(g))
Tensor< std::complex< Q > > tensor_real2complex(const Tensor< Q > &r)
Definition complexfun.h:65
Tensor< Q > tensor_xreal(const Tensor< std::complex< Q > > &c)
Definition complexfun.h:75
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
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_ximag(const Tensor< std::complex< Q > > &c)
Definition complexfun.h:85
static const double d
Definition nonlinschro.cc:121
double Q(double a)
Definition relops.cc:20
static const double c
Definition relops.cc:10
Definition complexfun.h:178
TensorTypeData< Q >::scalar_type resultT
Definition complexfun.h:179
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition complexfun.h:180
void serialize(Archive &ar)
Definition complexfun.h:187
Definition complexfun.h:106
void serialize(Archive &ar)
Definition complexfun.h:115
TensorTypeData< Q >::scalar_type resultT
Definition complexfun.h:107
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition complexfun.h:108
Definition complexfun.h:202
Q resultT
Definition complexfun.h:203
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition complexfun.h:204
void serialize(Archive &ar)
Definition complexfun.h:211
Definition complexfun.h:226
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition complexfun.h:228
void serialize(Archive &ar)
Definition complexfun.h:235
std::complex< Q > resultT
Definition complexfun.h:227
Definition complexfun.h:154
Tensor< resultT > operator()(const Key< NDIM > &key, const Tensor< Q > &t) const
Definition complexfun.h:156
TensorTypeData< Q >::scalar_type resultT
Definition complexfun.h:155
void serialize(Archive &ar)
Definition complexfun.h:163
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
static const std::size_t NDIM
Definition testpdiff.cc:42