101 template <
typename T>
102 inline double distance(std::complex<T>&
a, std::complex<T>&
b)
104 return std::abs(a-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=1e-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];
248 uT vinew = expL(dt*Delta,v[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++) {
301 MADNESS_ASSERT(NPT>=2 && NPT<=6);
303 x[0] = -1.0; x[NPT-1] = 1.0; w[0] = w[NPT-1] = 2.0/(NPT*(NPT-1));
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];
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=1e-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;
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
SpectralPropagatorGaussLobatto(int NPT)
Definition: spectralprop.h:296
SpectralPropagator(int NPT)
Construct propagator using NPT points.
Definition: spectralprop.h:192
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
const int k
Definition: dielectric.cc:184
const double N
Definition: navstokes_cosines.cc:94
FLOAT a(int j, FLOAT z)
Definition: y1.cc:86
bool gauss_legendre(int n, double xlo, double xhi, double *x, double *w)
Definition: legendre.cc:231
Definition: spectralprop.h:259
tensorT sqrt(const tensorT &s, double tol=1e-8)
Computes matrix square root (not used any more?)
Definition: DFcode/moldft.cc:446
Spectral propagtor in time. Refer to documentation of file spectralprop.h for math detail...
Definition: spectralprop.h:109
~SpectralPropagator()
Definition: spectralprop.h:209
Implements MadnessException.
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
FLOAT b(int j, FLOAT z)
Definition: y1.cc:79
double distance(const madness::coord_3d &a, const madness::coord_3d &b)
Definition: molecularmask.h:10