MADNESS 0.10.1
mw.h
Go to the documentation of this file.
1/*
2 This file is part of MADNESS.
3
4 Copyright (C) 2025 Virginia Tech
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
32
33#ifndef MADNESS_MRA_MW_H__INCLUDED
34#define MADNESS_MRA_MW_H__INCLUDED
35
40
41#include <array>
42#include <functional>
43#include <vector>
44
45namespace madness {
46
47/// this FunctionFunctorInterface evaluates Legendre scaling functions
48template <std::size_t NDIM, typename Enabler = void>
50
51// 1-d scaling function in {n,l} box on [-L,L]
52template <>
53struct ScalingFunctionFunctor<1> : public FunctionFunctorInterface<double, 1> {
54 double L = -1;
55 Level n = -1;
58 int k = -1;
60 double sqrt_twon;
63
65
67 : L(L), n(n), l(l), k(k), twon(1 << n), one_over_twon(1. / twon),
68 sqrt_twon(sqrt(twon)), one_over_twoL(0.5/L), one_over_sqrttwoL(sqrt(one_over_twoL)) {
70 MADNESS_ASSERT(n>=0);
71 MADNESS_ASSERT(l >= 0 && l < twon);
72 MADNESS_ASSERT(k>=0);
73 }
74 double operator()(const coord_1d &r) const final {
75 const auto x = (r[0] + L)/(2 * L);
76 double values[50];
77 if (x < l * one_over_twon || x > (l + 1) * one_over_twon)
78 return 0.;
79 else {
80 MADNESS_ASSERT(k < sizeof(values) / sizeof(double));
81 legendre_scaling_functions(twon * x - l, k+1, values);
82 }
83 return values[k] * sqrt_twon * one_over_sqrttwoL;
84 }
85
86 virtual Level special_level() const final {
87 return n;
88 }
89
90 virtual std::vector< Vector<double,1> > special_points() const final {
91 return std::vector< Vector<double,1> >(1, Vector<double,1>{-L + 2*L*std::max(l+0.5,0.) * one_over_twon});
92 }
93};
94
95template <std::size_t NDIM>
96struct ScalingFunctionFunctor<NDIM, std::enable_if_t<std::greater{}(NDIM,1)>> : public FunctionFunctorInterface<double, NDIM> {
97 std::array<double, NDIM> L;
99 std::array<int, NDIM> k;
100 std::array<ScalingFunctionFunctor<1>, NDIM> sf1;
101
102 ScalingFunctionFunctor(const std::array<double, NDIM>& L, const Key<NDIM>& key, const std::array<int, NDIM>& k)
103 : L(L), key(key), k(k) {
104 for (int d = 0; d != NDIM; ++d)
105 sf1[d] = ScalingFunctionFunctor<1>(L[d], key.level(), key[d], k.at(d));
106 }
107 double operator()(const Vector<double, NDIM> &r) const final {
108 double result = 1.0;
109 int d = 0;
110 while (result != 0. && d < NDIM) {
111 result *= sf1[d]({r[d]});
112 ++d;
113 }
114 return result;
115 }
116
117 virtual Level special_level() const final {
118 return key.level();
119 }
120
121 virtual std::vector< Vector<double,NDIM> > special_points() const final {
123 for (int d = 0; d != NDIM; ++d) {
124 r[d] = sf1[d].special_points().at(0)[0];
125 }
126 return std::vector<Vector<double, NDIM>>(1, r);
127 }
128};
129
130}
131
132#endif // MADNESS_MRA_MW_H__INCLUDED
Abstract base class interface required for functors used as input to Functions.
Definition function_interface.h:68
Key is the index for a node of the 2^NDIM-tree.
Definition key.h:68
Level level() const
Definition key.h:161
A simple, fixed dimension vector.
Definition vector.h:64
constexpr reference at(size_type i)
Access element i of the Vector with bounds checking.
Definition vector.h:324
Provides typedefs to hide use of templates and to increase interoperability.
#define final(a, b, c)
Definition lookup3.c:153
Macros and tools pertaining to the configuration of MADNESS.
#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
void legendre_scaling_functions(double x, long k, double *p)
Evaluate the first k Legendre scaling functions.
Definition legendre.cc:85
int64_t Translation
Definition key.h:56
int Level
Definition key.h:57
Definition mraimpl.h:50
static const double d
Definition nonlinschro.cc:121
static const double L
Definition rk.cc:46
static const long k
Definition rk.cc:44
Translation twon
Definition mw.h:57
virtual Level special_level() const final
Override this to change the minimum level of refinement at special points (default is 6)
Definition mw.h:86
Translation l
Definition mw.h:56
ScalingFunctionFunctor(double L, Level n, Translation l, int k)
Definition mw.h:66
virtual std::vector< Vector< double, 1 > > special_points() const final
Override this to return list of special points to be refined more deeply.
Definition mw.h:90
double one_over_twon
Definition mw.h:59
double operator()(const coord_1d &r) const final
Definition mw.h:74
double one_over_sqrttwoL
Definition mw.h:62
double sqrt_twon
Definition mw.h:60
double one_over_twoL
Definition mw.h:61
double operator()(const Vector< double, NDIM > &r) const final
You should implement this to return f(x)
Definition mw.h:107
virtual std::vector< Vector< double, NDIM > > special_points() const final
Override this to return list of special points to be refined more deeply.
Definition mw.h:121
ScalingFunctionFunctor(const std::array< double, NDIM > &L, const Key< NDIM > &key, const std::array< int, NDIM > &k)
Definition mw.h:102
virtual Level special_level() const final
Override this to change the minimum level of refinement at special points (default is 6)
Definition mw.h:117
std::array< ScalingFunctionFunctor< 1 >, NDIM > sf1
Definition mw.h:100
this FunctionFunctorInterface evaluates Legendre scaling functions
Definition mw.h:49
constexpr std::size_t NDIM
Definition testgconv.cc:54