34 #ifndef MADNESS_EXAMPLES_NONLINSOL_H__INCLUDED
35 #define MADNESS_EXAMPLES_NONLINSOL_H__INCLUDED
73 if (c.absmax()<cabsmax) {
75 }
else if(rcond < rcondtol){
76 print(
"Increasing subspace singular value threshold ", c[m - 1], rcond);
79 print(
"Forcing full step due to subspace malfunction");
92 const unsigned int maxsub;
93 std::vector<Function<double,NDIM> > ulist, rlist;
112 const double rcondtol=1e-8,
const double cabsmax=1000.0) {
113 if (maxsub==1)
return u-r;
114 int iter = ulist.
size();
120 if (iter>0) Qnew(
Slice(0,-2),
Slice(0,-2)) = Q;
121 for (
int i=0; i<=iter; i++) {
122 Qnew(i,iter) =
inner(ulist[i],rlist[iter]);
123 Qnew(iter,i) =
inner(ulist[iter],rlist[i]);
128 if (do_print)
print(
"subspace solution",c);
132 if (ulist[0].is_compressed()) unew.
compress();
133 for (
int i=0; i<=iter; i++) {
134 unew.
gaxpy(1.0,ulist[i], c[i]);
135 unew.
gaxpy(1.0,rlist[i],-c[i]);
139 if (ulist.size() == maxsub) {
140 ulist.erase(ulist.begin());
141 rlist.erase(rlist.begin());
173 template <
class T,
class C =
double,
class Alloc = default_allocator<T> >
177 std::vector<T> ulist, rlist;
189 : maxsub(other.maxsub)
210 T update(
const T& u,
const T& r,
const double rcondtol=1e-8,
const double cabsmax=1000.0) {
211 if (maxsub==1)
return u-r;
212 int iter = ulist.size();
217 Tensor<C> Qnew(iter+1,iter+1);
218 if (iter>0) Qnew(
Slice(0,-2),
Slice(0,-2)) = Q;
219 for (
int i=0; i<=iter; i++) {
220 Qnew(i,iter) =
inner(ulist[i],rlist[iter]);
221 Qnew(iter,i) =
inner(ulist[iter],rlist[i]);
224 Tensor<C>
c =
KAIN(Q);
227 if (do_print)
print(
"subspace solution",c);
231 for (
int i=0; i<=iter; i++) {
232 unew += (ulist[i] - rlist[i])*c[i];
235 if (ulist.size() == maxsub) {
236 ulist.erase(ulist.begin());
237 rlist.erase(rlist.begin());
A simple Krylov-subspace nonlinear equation solver.
Definition: nonlinsol.h:91
Main include file for MADNESS and defines Function interface.
Function< T, NDIM > & truncate(double tol=0.0, bool fence=true)
Truncate the function with optional fence. Compresses with fence if not compressed.
Definition: mra.h:577
XNonlinearSolver(const XNonlinearSolver &other)
Definition: nonlinsol.h:188
const Function< T, NDIM > & compress(bool fence=true) const
Compresses the function, transforming into wavelet basis. Possible non-blocking comm.
Definition: mra.h:683
bool do_print
Definition: nonlinsol.h:97
Defines interfaces for optimization and non-linear equation solvers.
Definition: nonlinsol.h:153
T inner(const vecfunc< T, NDIM > &a, const vecfunc< T, NDIM > &b)
the non-linear solver requires an inner product
Definition: nemo.h:112
World & world() const
Returns the world.
Definition: mra.h:622
const T1 &f1 return GTEST_2_TUPLE_() T(f0, f1)
NonlinearSolverND(unsigned int maxsub=10)
Definition: nonlinsol.h:99
Function< double, NDIM > update(const Function< double, NDIM > &u, const Function< double, NDIM > &r, const double rcondtol=1e-8, const double cabsmax=1000.0)
Computes next trial solution vector.
Definition: nonlinsol.h:111
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
Generalized version of NonlinearSolver not limited to a single madness function.
Definition: nonlinsol.h:174
bool do_print
Definition: nonlinsol.h:180
void set_maxsub(int maxsub)
Definition: nonlinsol.h:198
std::vector< T > & get_rlist()
Definition: nonlinsol.h:196
Tensor< double > real_tensor
Definition: functypedefs.h:40
void check_linear_dependence(const Tensor< C > &Q, Tensor< C > &c, const double rcondtol, const double cabsmax)
check for subspace linear dependency
Definition: nonlinsol.h:65
XNonlinearSolver(const Alloc &alloc=Alloc())
Definition: nonlinsol.h:182
const double m
Definition: gfit.cc:199
NonlinearSolverND< 3 > NonlinearSolver
Definition: nonlinsol.h:149
std::size_t size() const
Returns the number of coefficients in the function ... collective global sum.
Definition: mra.h:515
Function< T, NDIM > & gaxpy(const T &alpha, const Function< Q, NDIM > &other, const R &beta, bool fence=true)
Inplace, general bi-linear operation in wavelet basis. No communication except for optional fence...
Definition: mra.h:924
void print(const A &a)
Print a single item to std::cout terminating with new line.
Definition: print.h:122
A slice defines a sub-range or patch of a dimension.
Definition: slice.h:103
FunctionFactory implements the named-parameter idiom for Function.
Definition: funcimpl.h:70
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45
const double c
Definition: gfit.cc:200
T update(const T &u, const T &r, const double rcondtol=1e-8, const double cabsmax=1000.0)
Computes next trial solution vector.
Definition: nonlinsol.h:210
Tensor< T > KAIN(const Tensor< T > &Q, double rcond=1e-12)
Solves non-linear equation using KAIN (returns coefficients to compute next vector) ...
Definition: solvers.h:98
T operator()()
Definition: nonlinsol.h:154
std::vector< T > & get_ulist()
Definition: nonlinsol.h:195