97 return std::sqrt((
a-
b)*(
a-
b));
101 template <
typename T>
102 inline double distance(std::complex<T>&
a, std::complex<T>&
b)
111 std::vector<double>
x;
112 std::vector<double>
w;
116 double p(
int i,
double t) {
117 double top=1.0, bot=1.0;
118 for (
int j=0; j<i; j++) {
122 for (
int j=i+1; j<=
NPT; j++) {
130 template <
typename uT>
131 uT
u(
double dt,
const std::vector<uT>&
v) {
133 for (
int i=1; i<=
NPT; i++) {
141 template <
typename uT,
typename expLT,
typename NT>
142 std::vector<uT>
solve(
double t,
double Delta,
const uT& u0,
const expLT&
expL,
const NT&
N,
const double eps,
bool doprint,
bool recurinit,
int& napp) {
144 std::vector<uT>
v(
NPT+1,u0);
146 if (!recurinit ||
NPT==1) {
148 for (
int i=1; i<=
NPT; i++) {
149 double dt =
x[i] -
x[i-1];
150 v[i] =
expL(dt*Delta,
v[i-1]);
151 v[i] +=
expL(Delta*dt,
N(t+Delta*
x[i-1],
v[i-1]))*(dt*Delta);
156 std::vector<uT> vx =
q->
solve(t, Delta, u0,
expL,
N, eps*10000.0, doprint, recurinit, napp);
157 for (
int i=1; i<=
NPT; i++) {
158 v[i] =
q->
u(
x[i],vx);
163 uT Gv0 =
expL((
x[1] -
x[0])*Delta,
v[0]); napp++;
167 bool converged =
false;
168 for (
int iter=0; iter<20; iter++) {
169 for (
int i=1; i<=
NPT; i++) {
170 double dt =
x[i] -
x[i-1];
171 uT vinew = (i==0) ? Gv0*1.0 :
expL(dt*Delta,
v[i-1]);
173 for (
int k=1;
k<=
NPT;
k++) {
174 double ddt =
x[i-1] + dt*
x[
k];
175 vinew +=
expL(dt*Delta*(1.0-
x[
k]),
N(t + Delta*ddt,
u(ddt,
v)))*(dt*Delta*
w[
k]); napp++;
181 if (doprint)
print(
"spectral",iter,err);
182 converged = (err < eps);
183 if (converged)
break;
185 if (!converged)
throw "spectral propagator failed to converge";
203 std::reverse(
x.begin()+1,
x.end());
204 std::reverse(
w.begin()+1,
w.end());
239 template <
typename uT,
typename expLT,
typename NT>
240 uT
step(
double t,
double Delta,
const uT& u0,
const expLT&
expL,
const NT&
N,
const double eps=1
e-12,
bool doprint=
false,
bool recurinit=
true) {
244 std::vector<uT>
v =
solve(t, Delta, u0,
expL,
N, eps, doprint, recurinit, napp);
247 double dt = 1.0 -
x[
NPT];
249 for (
int k=1;
k<=
NPT;
k++) {
250 double ddt =
x[
NPT] + dt*
x[
k];
251 vinew +=
expL(dt*Delta*(1.0-
x[
k]),
N(t + Delta*ddt,
u(ddt,
v)))*(dt*Delta*
w[
k]); napp++;
254 if (doprint)
print(
"number of operator applications", napp);
261 std::vector<double>
x;
262 std::vector<double>
w;
265 double p(
int i,
double t) {
266 double top=1.0, bot=1.0;
267 for (
int j=0; j<i; j++) {
271 for (
int j=i+1; j<
NPT; j++) {
278 template <
typename uT>
279 uT
u(
double dt,
const std::vector<uT>&
v) {
281 for (
int i=1; i<
NPT; i++) {
307 x[1] = 0.0;
w[1] = 4.0/3.0;
310 x[1] = -1.0/std::sqrt(5.0);
w[1] = 5.0/6.0;
311 x[2] = -
x[1];
w[2] =
w[1];
314 x[1] = -std::sqrt(3.0/7.0);
w[1] = 49.0/90.0;
315 x[2] = 0.0;
w[2] = 32.0/45.0;
316 x[3] = -
x[1];
w[3] =
w[1];
319 x[1] = -std::sqrt((7.0+2.0*std::sqrt(7.0))/21.0);
w[1] = (14.0-std::sqrt(7.0))/30.0;
320 x[2] = -std::sqrt((7.0-2.0*std::sqrt(7.0))/21.0);
w[2] = (14.0+std::sqrt(7.0))/30.0;
321 x[3] = -
x[2];
w[3] =
w[2];
322 x[4] = -
x[1];
w[4] =
w[1];
329 for (
int i=0; i<
NPT; i++) {
330 x[i] = 0.5*(1.0 +
x[i]);
335 template <
typename uT,
typename expLT,
typename NT>
336 uT
step(
double t,
double Delta,
const uT& u0,
const expLT&
expL,
const NT&
N,
const double eps=1
e-12,
bool doprint=
false) {
337 std::vector<uT>
v(
NPT,u0);
340 for (
int i=1; i<
NPT; i++) {
341 double dt =
x[i] -
x[i-1];
342 v[i] =
expL(dt*Delta,
v[i-1]);
343 v[i] +=
expL(Delta*dt,
N(t+Delta*
x[i-1],
v[i-1]))*(dt*Delta);
348 for (
int iter=0; iter<12; iter++) {
349 for (
int i=1; i<
NPT; i++) {
350 double dt =
x[i] -
x[i-1];
351 uT vinew =
expL(dt*Delta,
v[i-1]);
352 for (
int k=0;
k<
NPT;
k++) {
353 double ddt =
x[i-1] + dt*
x[
k];
354 vinew +=
expL(dt*Delta*(1.0-
x[
k]),
N(t + Delta*ddt,
u(ddt,
v)))*(dt*Delta*
w[
k]);
359 if (doprint)
print(
"hello",iter,err);
361 if (err < eps)
break;
Definition: spectralprop.h:259
uT u(double dt, const std::vector< uT > &v)
Definition: spectralprop.h:279
std::vector< double > x
Definition: spectralprop.h:261
uT step(double t, double Delta, const uT &u0, const expLT &expL, const NT &N, const double eps=1e-12, bool doprint=false)
Definition: spectralprop.h:336
double p(int i, double t)
Definition: spectralprop.h:265
const int NPT
Definition: spectralprop.h:260
std::vector< double > w
Definition: spectralprop.h:262
SpectralPropagatorGaussLobatto(int NPT)
Definition: spectralprop.h:296
Spectral propagtor in time. Refer to documentation of file spectralprop.h for math detail.
Definition: spectralprop.h:109
std::vector< uT > solve(double t, double Delta, const uT &u0, const expLT &expL, const NT &N, const double eps, bool doprint, bool recurinit, int &napp)
Definition: spectralprop.h:142
std::vector< double > x
Quadrature points on [0,1] with value 0 prepended.
Definition: spectralprop.h:111
double p(int i, double t)
Private: Makes interpolating polyn p[i](t), i=0..NPT.
Definition: spectralprop.h:116
SpectralPropagator(int NPT)
Construct propagator using NPT points.
Definition: spectralprop.h:192
uT u(double dt, const std::vector< uT > &v)
Private: Computes interpolated solution.
Definition: spectralprop.h:131
uT step(double t, double Delta, const uT &u0, const expLT &expL, const NT &N, const double eps=1e-12, bool doprint=false, bool recurinit=true)
Step forward in time from to .
Definition: spectralprop.h:240
~SpectralPropagator()
Definition: spectralprop.h:209
const int NPT
Number of quadrature points.
Definition: spectralprop.h:110
SpectralPropagator * q
Definition: spectralprop.h:113
std::vector< double > w
Quadrature weights on [0,1] with value 0 prepended.
Definition: spectralprop.h:112
static const double v
Definition: hatom_sf_dirac.cc:20
Defines madness::MadnessException for exception handling.
#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
double distance(const madness::coord_3d &a, const madness::coord_3d &b)
Definition: molecularmask.h:10
File holds all helper structures necessary for the CC_Operator and CC2 class.
Definition: DFParameters.h:10
double distance(double a, double b)
Default function for computing the distance between two doubles.
Definition: spectralprop.h:95
bool gauss_legendre(int n, double xlo, double xhi, double *x, double *w)
Definition: legendre.cc:226
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 long abs(long a)
Definition: tensor.h:218
static const double b
Definition: nonlinschro.cc:119
static const double a
Definition: nonlinschro.cc:118
static const long k
Definition: rk.cc:44
void e()
Definition: test_sig.cc:75
#define N
Definition: testconv.cc:37
Fred expL(double dt, const Fred &f)
Definition: testspectralprop.cc:98