MADNESS 0.10.1
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
39namespace madness {
40 /// FunctionCommonData holds all Function data common for given k
41
42 /// Since Function assignment and copy constructors are shallow it
43 /// greatly simplifies maintaining consistent state to have all
44 /// (permanent) state encapsulated in a single class. The state
45 /// is shared between instances using a shared_ptr. Also,
46 /// separating shared from instance specific state accelerates the
47 /// constructor, which is important for massive parallelism, and
48 /// permitting inexpensive use of temporaries. The default copy
49 /// constructor and assignment operator are used but are probably
50 /// never invoked.
51 template<typename T, std::size_t NDIM>
53 private:
55
56 /// Private. Initialize the twoscale coefficients
57 void
59
60 /// Private. Do first use initialization via get.
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
82 quad_phit);
83 }
84
85 public:
86 typedef Tensor<T> tensorT; ///< Type of tensor used to hold coeff
87
88 int k; ///< order of the wavelet
89 int npt; ///< no. of quadrature points
90 Slice s[4]; ///< s[0]=Slice(0,k-1), s[1]=Slice(k,2*k-1), etc.
91 std::vector<Slice> s0; ///< s[0] in each dimension to get scaling coeff
92 std::vector<Slice> sh; ///< Slice(0,(k-1)/2) in each dimension for autorefine test
93 std::vector<long> vk; ///< (k,...) used to initialize Tensors
94 std::vector<long> v2k; ///< (2k,...) used to initialize Tensors
95 std::vector<long> vq; ///< (npt,...) used to initialize Tensors
96
97 Key<NDIM> key0; ///< Key for root node
98
99 Tensor<double> quad_x; ///< quadrature points
100 Tensor<double> quad_w; ///< quadrature weights
101 Tensor<double> quad_phi; ///< quad_phi(i,j) = at x[i] value of phi[j]
102 Tensor<double> quad_phit; ///< transpose of quad_phi
103 Tensor<double> quad_phiw; ///< quad_phiw(i,j) = at x[i] value of w[i]*phi[j]
104
105 Tensor<double> h0, h1, g0, g1; ///< The separate blocks of twoscale coefficients
106 Tensor<double> h0T, h1T, g0T, g1T; ///< The separate blocks of twoscale coefficients
107 Tensor<double> hg, hgT; ///< The full twoscale coeff (2k,2k) and transpose
108 Tensor<double> hgsonly; ///< hg[0:k,:]
109
110 static const FunctionCommonData<T, NDIM>&
111 get(int k) {
112 MADNESS_ASSERT(k > 0 && k <= MAXK);
113
114 MADNESS_PRAGMA_CLANG(diagnostic push)
115 MADNESS_PRAGMA_CLANG(diagnostic ignored "-Wundefined-var-template")
116
117 if (!data[k-1]) data[k-1] = new FunctionCommonData<T,NDIM>(k);
118 return *(data[k-1]);
119
120 MADNESS_PRAGMA_CLANG(diagnostic pop)
121 }
122
123 /// Initialize the quadrature information
124
125 /// Made public with all arguments thru interface for reuse in FunctionImpl::err_box
126 static void
128 double>& quad_w, Tensor<double>& quad_phi,
130 };
131
132
133 /// collect common functionality does not need to be member function of funcimpl
134 template<typename T, std::size_t NDIM>
136 public:
137
141
142 GenTensor<T> coeffs2values(const Key<NDIM>& key, const GenTensor<T>& coeff) const {
143 double scale = pow(2.0,0.5*NDIM*key.level())/sqrt(FunctionDefaults<NDIM>::get_cell_volume());
144 return transform(coeff,cdata.quad_phit).scale(scale);
145 }
146
147 Tensor<T> coeffs2values(const Key<NDIM>& key, const Tensor<T>& coeff) const {
148 double scale = pow(2.0,0.5*NDIM*key.level())/sqrt(FunctionDefaults<NDIM>::get_cell_volume());
149 return transform(coeff,cdata.quad_phit).scale(scale);
150 }
151
152 /// Return the scaling function coeffs when given the function values at the quadrature points
153 /// @param[in] key the key of the function node (box)
154 /// @return function values for function node (box)
155 Tensor<T> values2coeffs(const Key<NDIM>& key, const Tensor<T>& values) const {
156 double scale = pow(0.5,0.5*NDIM*key.level())*sqrt(FunctionDefaults<NDIM>::get_cell_volume());
157 return transform(values,cdata.quad_phiw).scale(scale);
158 }
159
160 GenTensor<T> values2coeffs(const Key<NDIM>& key, const GenTensor<T>& values) const {
161 double scale = pow(0.5,0.5*NDIM*key.level())*sqrt(FunctionDefaults<NDIM>::get_cell_volume());
162 return transform(values,cdata.quad_phiw).scale(scale);
163 }
164
165 };
166
167
168
169 class Timer {
170
173
175 static const int itotal=-10;
176
177 public:
178 /// start timer
180 }
181
182 /// accumulate timer
183 void accumulate(const double time) const {
184
185 accessor acc;
186 map& map2=const_cast<map&>(data);
187 bool found=map2.find(acc, -10);
188 if (found) {
189 acc->second+=time;
190 } else {
191 [[maybe_unused]] auto&& [it, inserted] = map2.insert(std::pair<int,double>(-10,time));
192 }
193
194
195 int ilog=0;
196 if (time<0.1) ilog=-1;
197 else if (time<1.0) ilog=0;
198 else if (time<10.0) ilog=1;
199 else if (time<100.0) ilog=2;
200 else ilog=3;
201
202 found=map2.find(acc, ilog);
203 if (found) {
204 acc->second+=1.0;
205 } else {
206 [[maybe_unused]] auto&& [it, inserted] = map2.insert(std::pair<int,long>(ilog,1));
207 }
208 }
209
210 void reset() const {
211 map& map2=const_cast<map&>(data);
212 map2.clear();
213 }
214
215 /// print timer
216 void print(std::string line="") const {
217
218 madness::print("timing of ",line);
220 accessor acc;
221 bool found=data.find(acc, -10);
222 if (found) madness::print(" time spent in total ", acc->second);
223
224 found=data.find(acc, -1);
225 if (found) madness::print(" # tasks in <0.1s ", acc->second);
226 found=data.find(acc, 0);
227 if (found) madness::print(" # tasks in <1s ", acc->second);
228 found=data.find(acc, 1);
229 if (found) madness::print(" # tasks in <10s ", acc->second);
230 found=data.find(acc, 2);
231 if (found) madness::print(" # tasks in <100s ", acc->second);
232 found=data.find(acc, 3);
233 if (found) madness::print(" # tasks in <1000s ", acc->second);
234
235 }
236 };
237
238
239
240}
241
242
243#endif /* FUNCTIONCOMMONDATA_H_ */
Definition worldhashmap.h:396
std::pair< iterator, bool > insert(const datumT &datum)
Definition worldhashmap.h:468
iterator find(const keyT &key)
Definition worldhashmap.h:524
void clear()
Definition worldhashmap.h:556
FunctionCommonData holds all Function data common for given k.
Definition function_common_data.h:52
std::vector< Slice > sh
Slice(0,(k-1)/2) in each dimension for autorefine test.
Definition function_common_data.h:92
Tensor< double > g1
The separate blocks of twoscale coefficients.
Definition function_common_data.h:105
Tensor< double > quad_phit
transpose of quad_phi
Definition function_common_data.h:102
Tensor< double > quad_phi
quad_phi(i,j) = at x[i] value of phi[j]
Definition function_common_data.h:101
Tensor< double > h0T
Definition function_common_data.h:106
std::vector< long > v2k
(2k,...) used to initialize Tensors
Definition function_common_data.h:94
FunctionCommonData(int k)
Private. Do first use initialization via get.
Definition function_common_data.h:61
Tensor< double > quad_phiw
quad_phiw(i,j) = at x[i] value of w[i]*phi[j]
Definition function_common_data.h:103
std::vector< long > vk
(k,...) used to initialize Tensors
Definition function_common_data.h:93
Tensor< T > tensorT
Type of tensor used to hold coeff.
Definition function_common_data.h:86
int npt
no. of quadrature points
Definition function_common_data.h:89
Tensor< double > g0
Definition function_common_data.h:105
Tensor< double > g1T
The separate blocks of twoscale coefficients.
Definition function_common_data.h:106
Tensor< double > hgT
The full twoscale coeff (2k,2k) and transpose.
Definition function_common_data.h:107
Tensor< double > quad_w
quadrature weights
Definition function_common_data.h:100
std::vector< Slice > s0
s[0] in each dimension to get scaling coeff
Definition function_common_data.h:91
Slice s[4]
s[0]=Slice(0,k-1), s[1]=Slice(k,2*k-1), etc.
Definition function_common_data.h:90
Tensor< double > h0
Definition function_common_data.h:105
std::vector< long > vq
(npt,...) used to initialize Tensors
Definition function_common_data.h:95
int k
order of the wavelet
Definition function_common_data.h:88
static const FunctionCommonData< T, NDIM > & get(int k)
Definition function_common_data.h:111
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:88
Tensor< double > hg
Definition function_common_data.h:107
Key< NDIM > key0
Key for root node.
Definition function_common_data.h:97
Tensor< double > hgsonly
hg[0:k,:]
Definition function_common_data.h:108
Tensor< double > quad_x
quadrature points
Definition function_common_data.h:99
Tensor< double > h1T
Definition function_common_data.h:106
Tensor< double > g0T
Definition function_common_data.h:106
Tensor< double > h1
Definition function_common_data.h:105
void _init_twoscale()
Private. Initialize the twoscale coefficients.
Definition mraimpl.h:67
collect common functionality does not need to be member function of funcimpl
Definition function_common_data.h:135
GenTensor< T > values2coeffs(const Key< NDIM > &key, const GenTensor< T > &values) const
Definition function_common_data.h:160
const FunctionCommonData< T, NDIM > & cdata
Definition function_common_data.h:138
Tensor< T > coeffs2values(const Key< NDIM > &key, const Tensor< T > &coeff) const
Definition function_common_data.h:147
GenTensor< T > coeffs2values(const Key< NDIM > &key, const GenTensor< T > &coeff) const
Definition function_common_data.h:142
FunctionCommonFunctionality(const long k)
Definition function_common_data.h:140
Tensor< T > values2coeffs(const Key< NDIM > &key, const Tensor< T > &values) const
Definition function_common_data.h:155
FunctionCommonFunctionality(const FunctionCommonData< T, NDIM > &cdata)
Definition function_common_data.h:139
FunctionDefaults holds default paramaters as static class members.
Definition funcdefaults.h:204
Definition lowranktensor.h:59
Definition worldhashmap.h:330
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:66
Level level() const
Definition key.h:159
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
A tensor is a multidimension array.
Definition tensor.h:317
Definition function_common_data.h:169
Timer()
start timer
Definition function_common_data.h:179
void print(std::string line="") const
print timer
Definition function_common_data.h:216
map data
Definition function_common_data.h:174
void accumulate(const double time) const
accumulate timer
Definition function_common_data.h:183
ConcurrentHashMap< int, double > map
Definition function_common_data.h:171
void reset() const
Definition function_common_data.h:210
ConcurrentHashMap< int, double >::accessor accessor
Definition function_common_data.h:172
static const int itotal
Definition function_common_data.h:175
A simple, fixed dimension vector.
Definition vector.h:64
Provides FunctionDefaults and utilities for coordinate transformation.
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
static double pow(const double *a, const double *b)
Definition lda.h:74
#define MADNESS_PRAGMA_CLANG(x)
Definition madness_config.h:200
#define MADNESS_ASSERT(condition)
Assert a condition that should be free of side-effects since in release builds this might be a no-op.
Definition madness_exception.h:134
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
response_space scale(response_space a, double b)
std::vector< Function< TENSOR_RESULT_TYPE(T, R), NDIM > > transform(World &world, const std::vector< Function< T, NDIM > > &v, const Tensor< R > &c, bool fence=true)
Transforms a vector of functions according to new[i] = sum[j] old[j]*c[j,i].
Definition vmra.h:689
static double pop(std::vector< double > &v)
Definition SCF.cc:113
void print(const T &t, const Ts &... ts)
Print items to std::cout (items separated by spaces) and terminate with a new line.
Definition print.h:225
static const int MAXK
The maximum wavelet order presently supported.
Definition funcdefaults.h:51
static const long k
Definition rk.cc:44
Definition test_ccpairfunction.cc:22
static const std::size_t NDIM
Definition testpdiff.cc:42