Octopus 16.0
real-space, real-time, TDDFT code
anygrid.hpp
Go to the documentation of this file.
1#ifndef PSEUDO_ANYGRID_HPP
2#define PSEUDO_ANYGRID_HPP
3
4/*
5 Copyright (C) 2018 Xavier Andrade
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#include "base.hpp"
23#include "spline.h"
24#include <string>
25#include <vector>
26
27namespace pseudopotential {
28
30
31public:
32 anygrid(bool uniform_grid) : uniform_grid_(uniform_grid) {}
33
34 double mesh_spacing() const { return 0.01; }
35
36 int mesh_size() const {
37 if (uniform_grid_) {
38 return mesh_size_;
39 } else {
40 return grid_.size();
41 }
42 }
43
44 virtual void grid(std::vector<double> &val) const {
45 if (uniform_grid_) {
47 } else {
48 val = grid_;
49 }
50 }
51
52 virtual void grid_weights(std::vector<double> &val) const {
53 if (uniform_grid_) {
55 } else {
57 }
58 }
59
60protected:
61 void interpolate(std::vector<double> &function) const {
62 if (!uniform_grid_)
63 return;
64
65 std::vector<double> function_in_grid = function;
66
67 assert(function.size() == grid_.size());
68
69 Spline function_spline;
70 function_spline.fit(grid_.data(), function_in_grid.data(),
71 function_in_grid.size(), SPLINE_FLAT_BC,
73
74 function.clear();
75 for (double rr = 0.0; rr <= grid_[grid_.size() - 1]; rr += mesh_spacing()) {
76 function.push_back(function_spline.value(rr));
77 }
78 }
79
81 std::vector<double> grid_;
82 std::vector<double> grid_weights_;
84};
85
86} // namespace pseudopotential
87
88#endif
Definition: spline.h:46
void fit(const double *x, double *y, int n, double yp1, double ypn)
Definition: spline.h:51
double value(const double &x) const
Definition: spline.h:63
Definition: anygrid.hpp:29
std::vector< double > grid_
Definition: anygrid.hpp:81
virtual void grid_weights(std::vector< double > &val) const
Definition: anygrid.hpp:52
virtual void grid(std::vector< double > &val) const
Definition: anygrid.hpp:44
double mesh_spacing() const
Definition: anygrid.hpp:34
bool uniform_grid_
Definition: anygrid.hpp:80
int mesh_size_
Definition: anygrid.hpp:83
std::vector< double > grid_weights_
Definition: anygrid.hpp:82
int mesh_size() const
Definition: anygrid.hpp:36
anygrid(bool uniform_grid)
Definition: anygrid.hpp:32
void interpolate(std::vector< double > &function) const
Definition: anygrid.hpp:61
Definition: base.hpp:86
virtual void grid(std::vector< double > &val) const
Definition: base.hpp:114
void const fint const fint * val
Definition: iihash_low.cc:41
Definition: anygrid.hpp:27
#define SPLINE_NATURAL_BC
Definition: spline.h:37
#define SPLINE_FLAT_BC
Definition: spline.h:36