MADNESS  version 0.9
funcdefaults.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 #ifndef MADNESS_MRA_FUNCDEFAULTS_H__INCLUDED
34 #define MADNESS_MRA_FUNCDEFAULTS_H__INCLUDED
35 
36 
40 
41 #include <madness/world/world.h>
42 #include <madness/world/array.h>
43 #include <madness/world/worlddc.h>
44 #include <madness/tensor/tensor.h>
45 #include <madness/mra/key.h>
46 
47 namespace madness {
48  template <typename T, std::size_t NDIM> class FunctionImpl;
49 
51  static const int MAXK = 30;
52 
54  static const int MAXLEVEL = 8*sizeof(Translation)-2;
55 
57 
71  template<std::size_t NDIM>
73  private:
74  // Used to use STL vector but static data on a MAC was
75  // causing problems.
76  BCType bc[NDIM*2];
77 
78  public:
81  {
82  for (std::size_t i=0; i<NDIM*2; ++i) bc[i] = code;
83  }
84 
87  {
88  *this = other;
89  }
90 
94  if (&other != this) {
95  for (std::size_t i=0; i<NDIM*2; ++i) bc[i] = other.bc[i];
96  }
97  return *this;
98  }
99 
101 
105  BCType operator()(std::size_t d, int i) const {
106  MADNESS_ASSERT(d<NDIM && i>=0 && i<2);
107  return bc[2*d+i];
108  }
109 
111 
115  BCType& operator()(std::size_t d, int i) {
116  MADNESS_ASSERT(d<NDIM && i>=0 && i<2);
117  return bc[2*d+i];
118  }
119 
120  template <typename Archive>
121  void serialize(const Archive& ar) {
122  ar & bc;
123  }
124 
126 
129  static const char* code_as_string(BCType code) {
130  static const char* codes[] = {"zero","periodic","free","Dirichlet","zero Neumann","Neumann"};
131  return codes[code];
132  }
133 
135 
137  std::vector<bool> is_periodic() const {
138  std::vector<bool> v(NDIM);
139  for (std::size_t d=0; d<NDIM; ++d)
140  v[d] = (bc[2*d]==BC_PERIODIC);
141  return v;
142  }
143  };
144 
145 
146 
147  template <std::size_t NDIM>
148  static
149  inline
150  std::ostream& operator << (std::ostream& s, const BoundaryConditions<NDIM>& bc) {
151  s << "BoundaryConditions(";
152  for (int d=0; d<NDIM; ++d) {
153  s << bc.code_as_string(bc(d,0)) << ":" << bc.code_as_string(bc(d,1));
154  if (d == NDIM-1)
155  s << ")";
156  else
157  s << ", ";
158  }
159  return s;
160  }
161 
162 
164 
174  template <std::size_t NDIM>
176  private:
177  static int k;
178  static double thresh;
179  static int initial_level;
180  static int max_refine_level;
181  static int truncate_mode;
182  static bool refine;
183  static bool autorefine;
184  static bool debug;
185  static bool truncate_on_project;
186  static bool apply_randomize;
187  static bool project_randomize;
188  static BoundaryConditions<NDIM> bc;
189  static Tensor<double> cell ;
190  static Tensor<double> cell_width;
191  static Tensor<double> rcell_width;
192  static double cell_volume;
193  static double cell_min_width;
194  static TensorType tt;
196 
197  static void recompute_cell_info() {
198  MADNESS_ASSERT(cell.dim(0)==NDIM && cell.dim(1)==2 && cell.ndim()==2);
199  cell_width = cell(_,1)-cell(_,0);
200  cell_volume = cell_width.product();
201  cell_min_width = cell_width.min();
202  rcell_width = copy(cell_width);
203  for (std::size_t i=0; i<NDIM; ++i) rcell_width(i) = 1.0/rcell_width(i);
204  }
205 
206  public:
207 
209  static void set_defaults(World& world);
210 
212  static int get_k() {
213  return k;
214  }
215 
217 
219  static void set_k(int value) {
220  k=value;
221  MADNESS_ASSERT(k>0 && k<=MAXK);
222  }
223 
225  static const double& get_thresh() {
226  return thresh;
227  }
228 
230 
232  static void set_thresh(double value) {
233  thresh=value;
234  }
235 
237  static int get_initial_level() {
238  return initial_level;
239  }
240 
242 
244  static void set_initial_level(int value) {
245  initial_level=value;
246  MADNESS_ASSERT(value>0 && value<MAXLEVEL);
247  }
248 
250  static int get_max_refine_level() {
251  return max_refine_level;
252  }
253 
255 
257  static void set_max_refine_level(int value) {
258  max_refine_level=value;
259  MADNESS_ASSERT(value>0 && value<MAXLEVEL);
260  }
261 
263  static int get_truncate_mode() {
264  return truncate_mode;
265  }
266 
268 
270  static void set_truncate_mode(int value) {
271  truncate_mode=value;
272  MADNESS_ASSERT(value>=0 && value<3);
273  }
274 
276  static bool get_refine() {
277  return refine;
278  }
279 
281 
283  static void set_refine(bool value) {
284  refine=value;
285  }
286 
288  static bool get_autorefine() {
289  return autorefine;
290  }
291 
293 
295  static void set_autorefine(bool value) {
296  autorefine=value;
297  }
298 
300  static bool get_debug() {
301  return debug;
302  }
303 
305 
307  static void set_debug(bool value) {
308  debug=value;
309  }
310 
312  static bool get_truncate_on_project() {
313  return truncate_on_project;
314  }
315 
317 
319  static void set_truncate_on_project(bool value) {
320  truncate_on_project=value;
321  }
322 
324  static bool get_apply_randomize() {
325  return apply_randomize;
326  }
327 
329  static void set_apply_randomize(bool value) {
330  apply_randomize=value;
331  }
332 
333 
335  static bool get_project_randomize() {
336  return project_randomize;
337  }
338 
340  static void set_project_randomize(bool value) {
341  project_randomize=value;
342  }
343 
346  return bc;
347  }
348 
350  static void set_bc(const BoundaryConditions<NDIM>& value) {
351  bc=value;
352  }
353 
356  return tt;
357  }
358 
360  static void set_tensor_type(const TensorType& t) {
361 #if HAVE_GENTENSOR
362  tt=t;
363 #else
364  tt=TT_FULL;
365 #endif
366  }
367 
369  static const Tensor<double>& get_cell() {
370  return cell;
371  }
372 
374 
376  static void set_cell(const Tensor<double>& value) {
377  cell=copy(value);
378  recompute_cell_info();
379  }
380 
382 
384  static void set_cubic_cell(double lo, double hi) {
385  cell(_,0)=lo;
386  cell(_,1)=hi;
387  recompute_cell_info();
388  }
389 
391  static const Tensor<double>& get_cell_width() {
392  return cell_width;
393  }
394 
396  static const Tensor<double>& get_rcell_width() {
397  return rcell_width;
398  }
399 
401  static double get_cell_min_width() {
402  return cell_min_width;
403  }
404 
406  static double get_cell_volume() {
407  return cell_volume;
408  }
409 
412  return pmap;
413  }
414 
416 
418  static void set_pmap(const std::shared_ptr< WorldDCPmapInterface< Key<NDIM> > >& value) {
419  pmap = value;
420  }
421 
423  static void redistribute(World& world, const std::shared_ptr< WorldDCPmapInterface< Key<NDIM> > >& newpmap) {
424  pmap->redistribute(world,newpmap);
425  pmap = newpmap;
426  }
427 
428  };
429 
430 
432  template <std::size_t NDIM>
433  static inline void user_to_sim(const Vector<double,NDIM>& xuser, Vector<double,NDIM>& xsim) {
434  for (std::size_t i=0; i<NDIM; ++i)
435  xsim[i] = (xuser[i] - FunctionDefaults<NDIM>::get_cell()(i,0)) * FunctionDefaults<NDIM>::get_rcell_width()[i];
436  }
437 
438 
440  template <std::size_t NDIM>
441  static void sim_to_user(const Vector<double,NDIM>& xsim, Vector<double,NDIM>& xuser) {
442  for (std::size_t i=0; i<NDIM; ++i)
443  xuser[i] = xsim[i]*FunctionDefaults<NDIM>::get_cell_width()[i] + FunctionDefaults<NDIM>::get_cell()(i,0);
444  }
445 
446 
447 }
448 #endif // MADNESS_MRA_FUNCDEFAULTS_H__INCLUDED
static const char * code_as_string(BCType code)
Translates code into human readable string.
Definition: funcdefaults.h:129
static bool get_truncate_on_project()
Gets the default truncate on project flag.
Definition: funcdefaults.h:312
Definition: shared_ptr_bits.h:38
BoundaryConditions(const BoundaryConditions< NDIM > &other)
Copy constructor is deep.
Definition: funcdefaults.h:86
FunctionDefaults holds default paramaters as static class members.
Definition: funcdefaults.h:175
static void set_bc(const BoundaryConditions< NDIM > &value)
Sets the default boundary conditions.
Definition: funcdefaults.h:350
static void set_autorefine(bool value)
Sets the default adaptive autorefinement flag.
Definition: funcdefaults.h:295
TensorType
low rank representations of tensors (see gentensor.h)
Definition: tensor.h:275
static double get_cell_min_width()
Returns the minimum width of any user cell dimension.
Definition: funcdefaults.h:401
const int NDIM
Definition: tdse1.cc:44
static void set_defaults(World &world)
Used to set defaults to k=7, thresh=1-5, for a unit cube [0,1].
Definition: mraimpl.h:3309
static void set_initial_level(int value)
Sets the default initial projection level.
Definition: funcdefaults.h:244
static void redistribute(World &world, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &newpmap)
Sets the default process map and redistributes all functions using the old map.
Definition: funcdefaults.h:423
static void set_truncate_on_project(bool value)
Sets the default truncate on project flag.
Definition: funcdefaults.h:319
static double get_cell_volume()
Returns the volume of the user cell.
Definition: funcdefaults.h:406
static void set_refine(bool value)
Sets the default adaptive refinement flag.
Definition: funcdefaults.h:283
Definition: funcdefaults.h:56
static const double & get_thresh()
Returns the default threshold.
Definition: funcdefaults.h:225
static bool get_apply_randomize()
Gets the random load balancing for integral operators flag.
Definition: funcdefaults.h:324
FunctionImpl holds all Function state to facilitate shallow copy semantics.
Definition: funcdefaults.h:48
static const Tensor< double > & get_cell()
Gets the user cell for the simulation.
Definition: funcdefaults.h:369
This header should include pretty much everything needed for the parallel runtime.
static bool get_debug()
Gets the default debug flag (is this used anymore?)
Definition: funcdefaults.h:300
static void set_project_randomize(bool value)
Sets the random load balancing for projection flag.
Definition: funcdefaults.h:340
Defines and implements most of Tensor.
static const BoundaryConditions< NDIM > & get_bc()
Returns the default boundary conditions.
Definition: funcdefaults.h:345
static void set_pmap(const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &value)
Sets the default process map (does not redistribute existing functions)
Definition: funcdefaults.h:418
static void set_cell(const Tensor< double > &value)
Gets the user cell for the simulation.
Definition: funcdefaults.h:376
static bool get_autorefine()
Gets the default adaptive autorefinement flag.
Definition: funcdefaults.h:288
static void set_truncate_mode(int value)
Sets the default truncation mode.
Definition: funcdefaults.h:270
std::vector< bool > is_periodic() const
Convenience for application of integral operators.
Definition: funcdefaults.h:137
BCType operator()(std::size_t d, int i) const
Returns value of boundary condition.
Definition: funcdefaults.h:105
static bool get_refine()
Gets the default adaptive refinement flag.
Definition: funcdefaults.h:276
static int get_k()
Returns the default wavelet order.
Definition: funcdefaults.h:212
Function< T, NDIM > copy(const Function< T, NDIM > &f, const std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > &pmap, bool fence=true)
Create a new copy of the function with different distribution and optional fence. ...
Definition: mra.h:1835
BoundaryConditions< NDIM > & operator=(const BoundaryConditions< NDIM > &other)
Assignment makes deep copy.
Definition: funcdefaults.h:93
This class is used to specify boundary conditions for all operatorsExterior boundary conditions (i...
Definition: funcdefaults.h:72
static void set_debug(bool value)
Sets the default debug flag (is this used anymore?)
Definition: funcdefaults.h:307
static TensorType get_tensor_type()
Returns the default tensor type.
Definition: funcdefaults.h:355
static void set_tensor_type(const TensorType &t)
Sets the default tensor type.
Definition: funcdefaults.h:360
BCType & operator()(std::size_t d, int i)
Returns reference to boundary condition.
Definition: funcdefaults.h:115
Definition: funcdefaults.h:56
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
static int get_initial_level()
Returns the default initial projection level.
Definition: funcdefaults.h:237
static std::shared_ptr< WorldDCPmapInterface< Key< NDIM > > > & get_pmap()
Returns the default process map.
Definition: funcdefaults.h:411
static void set_thresh(double value)
Sets the default threshold.
Definition: funcdefaults.h:232
static const Tensor< double > & get_rcell_width()
Returns the reciprocal of the width of each user cell dimension.
Definition: funcdefaults.h:396
void serialize(const Archive &ar)
Definition: funcdefaults.h:121
static int get_max_refine_level()
Gets the default maximum adaptive refinement level.
Definition: funcdefaults.h:250
static void set_max_refine_level(int value)
Sets the default maximum adaptive refinement level.
Definition: funcdefaults.h:257
static void set_apply_randomize(bool value)
Sets the random load balancing for integral operators flag.
Definition: funcdefaults.h:329
static const Tensor< double > & get_cell_width()
Returns the width of each user cell dimension.
Definition: funcdefaults.h:391
static void set_cubic_cell(double lo, double hi)
Sets the user cell to be cubic with each dimension having range [lo,hi].
Definition: funcdefaults.h:384
BCType
Definition: funcdefaults.h:56
Implements WorldContainer.
Definition: funcdefaults.h:56
Definition: funcdefaults.h:56
Interface to be provided by any process map.
Definition: worlddc.h:64
Definition: funcdefaults.h:56
static bool get_project_randomize()
Gets the random load balancing for projection flag.
Definition: funcdefaults.h:335
Multidimension Key for MRA tree and associated iterators.
static int get_truncate_mode()
Gets the default truncation mode.
Definition: funcdefaults.h:263
Definition: tensor.h:275
int64_t Translation
Definition: key.h:57
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
Definition: funcdefaults.h:56
Key is the index for a node of the 2^NDIM-tree.
Definition: key.h:69
static void set_k(int value)
Sets the default wavelet order.
Definition: funcdefaults.h:219
BoundaryConditions(BCType code=BC_FREE)
Constructor. Default boundary condition set to free space.
Definition: funcdefaults.h:80