MADNESS  version 0.9
function_common_data.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 
35 
36 #ifndef FUNCTIONCOMMONDATA_H_
37 #define FUNCTIONCOMMONDATA_H_
38 
39 namespace madness {
41 
51  template<typename T, std::size_t NDIM>
53  private:
54  static const FunctionCommonData<T, NDIM>* data[MAXK];
55 
57  void
58  _init_twoscale();
59 
61  FunctionCommonData(int k) {
62  this->k = k;
63  npt = k;
64  for (int i = 0; i < 4; ++i)
65  s[i] = Slice(i * k, (i + 1) * k - 1);
66  s0 = std::vector<Slice>(NDIM);
67  sh = std::vector<Slice>(NDIM);
68  vk = std::vector<long>(NDIM);
69  vq = std::vector<long>(NDIM);
70  v2k = std::vector<long>(NDIM);
71  for (std::size_t i = 0; i < NDIM; ++i) {
72  s0[i] = s[0];
73  sh[i] = Slice(0, (k - 1) / 2);
74  vk[i] = k;
75  vq[i] = npt;
76  v2k[i] = 2 * k;
77  }
79 
80  _init_twoscale();
82  quad_phit);
83  }
84 
85  public:
86  typedef Tensor<T> tensorT;
87 
88  int k;
89  int npt;
90  Slice s[4];
91  std::vector<Slice> s0;
92  std::vector<Slice> sh;
93  std::vector<long> vk;
94  std::vector<long> v2k;
95  std::vector<long> vq;
96 
98 
99  Tensor<double> quad_x;
100  Tensor<double> quad_w;
101  Tensor<double> quad_phi;
102  Tensor<double> quad_phit;
103  Tensor<double> quad_phiw;
104 
105  Tensor<double> h0, h1, g0, g1;
106  Tensor<double> h0T, h1T, g0T, g1T;
107  Tensor<double> hg, hgT;
108  Tensor<double> hgsonly;
109 
110  static const FunctionCommonData<T, NDIM>&
111  get(int k) {
112  MADNESS_ASSERT(k > 0 && k <= MAXK);
113  if (!data[k-1]) data[k-1] = new FunctionCommonData<T,NDIM>(k);
114  return *(data[k-1]);
115  }
116 
118 
120  static void
121  _init_quadrature(int k, int npt, Tensor<double>& quad_x, Tensor<
122  double>& quad_w, Tensor<double>& quad_phi,
123  Tensor<double>& quad_phiw, Tensor<double>& quad_phit);
124  };
125 
126 
127  class Timer {
128 
131 
132  map data;
133  static const int itotal=-10;
134 
135  public:
137  Timer() {
138  }
139 
141  void accumulate(const double time) const {
142 
143  accessor acc;
144  map& map2=const_cast<map&>(data);
145  bool found=map2.find(acc, -10);
146  if (found) {
147  acc->second+=time;
148  } else {
149  map2.insert(std::pair<int,double>(-10,time));
150  }
151 
152 
153  int ilog=0;
154  if (time<0.1) ilog=-1;
155  else if (time<1.0) ilog=0;
156  else if (time<10.0) ilog=1;
157  else if (time<100.0) ilog=2;
158  else ilog=3;
159 
160  found=map2.find(acc, ilog);
161  if (found) {
162  acc->second+=1.0;
163  } else {
164  map2.insert(std::pair<int,long>(ilog,1));
165  }
166  }
167 
168  void reset() const {
169  map& map2=const_cast<map&>(data);
170  map2.clear();
171  }
172 
174  void print(std::string line="") const {
175 
176  madness::print("timing of ",line);
178  accessor acc;
179  for (int ilog=-10; ilog<4; ++ilog) {
180  const bool found=data.find(acc, ilog);
181  if (found) madness::print(" time spent in log(10) ", acc->first, acc->second);
182  }
183  }
184  };
185 
186 
187 
188 }
189 
190 
191 #endif /* FUNCTIONCOMMONDATA_H_ */
Tensor< double > g1T
The separate blocks of twoscale coefficients.
Definition: function_common_data.h:106
Tensor< double > h1
Definition: function_common_data.h:105
Tensor< double > hgT
The full twoscale coeff (2k,2k) and transpose.
Definition: function_common_data.h:107
static void _init_quadrature(int k, int npt, Tensor< double > &quad_x, Tensor< double > &quad_w, Tensor< double > &quad_phi, Tensor< double > &quad_phiw, Tensor< double > &quad_phit)
Initialize the quadrature information.
Definition: mraimpl.h:83
Tensor< double > g0
Definition: function_common_data.h:105
const int NDIM
Definition: tdse1.cc:44
std::vector< long > v2k
(2k,...) used to initialize Tensors
Definition: function_common_data.h:94
void clear()
Definition: worldhashmap.h:556
::std::string string
Definition: gtest-port.h:872
std::vector< long > vq
(npt,...) used to initialize Tensors
Definition: function_common_data.h:95
Tensor< double > g0T
Definition: function_common_data.h:106
Tensor< T > tensorT
Type of tensor used to hold coeff.
Definition: function_common_data.h:86
Provides FunctionDefaults and utilities for coordinate transformation.
Tensor< double > h1T
Definition: function_common_data.h:106
void print(std::string line="") const
print timer
Definition: function_common_data.h:174
int k
order of the wavelet
Definition: function_common_data.h:88
std::vector< long > vk
(k,...) used to initialize Tensors
Definition: function_common_data.h:93
Tensor< double > h0T
Definition: function_common_data.h:106
Tensor< double > quad_x
quadrature points
Definition: function_common_data.h:99
std::vector< Slice > s0
s[0] in each dimension to get scaling coeff
Definition: function_common_data.h:91
Definition: function_common_data.h:127
void accumulate(const double time) const
accumulate timer
Definition: function_common_data.h:141
std::pair< iterator, bool > insert(const datumT &datum)
Definition: worldhashmap.h:469
std::vector< Slice > sh
Slice(0,(k-1)/2) in each dimension for autorefine test.
Definition: function_common_data.h:92
Tensor< double > hgsonly
hg[0:k,:]
Definition: function_common_data.h:108
Tensor< double > g1
The separate blocks of twoscale coefficients.
Definition: function_common_data.h:105
Tensor< double > quad_w
quadrature weights
Definition: function_common_data.h:100
Tensor< double > hg
Definition: function_common_data.h:107
void reset() const
Definition: function_common_data.h:168
Slice s[4]
s[0]=Slice(0,k-1), s[1]=Slice(k,2*k-1), etc.
Definition: function_common_data.h:90
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
FunctionCommonData holds all Function data common for given k.
Definition: function_common_data.h:52
int npt
no. of quadrature points
Definition: function_common_data.h:89
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
iterator find(const keyT &key)
Definition: worldhashmap.h:524
Timer()
start timer
Definition: function_common_data.h:137
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Key< NDIM > key0
Key for root node.
Definition: function_common_data.h:97
Tensor< double > quad_phi
quad_phi(i,j) = at x[i] value of phi[j]
Definition: function_common_data.h:101
Tensor< double > quad_phit
transpose of quad_phi
Definition: function_common_data.h:102
Tensor< double > quad_phiw
quad_phiw(i,j) = at x[i] value of w[i]*phi[j]
Definition: function_common_data.h:103
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
Tensor< double > h0
Definition: function_common_data.h:105