34#ifndef MADNESS_EXAMPLES_NONLINSOL_H__INCLUDED
35#define MADNESS_EXAMPLES_NONLINSOL_H__INCLUDED
72 if (
c.absmax()<cabsmax) {
74 }
else if(rcond < rcondtol){
75 if (do_print)
print(
"Increasing subspace singular value threshold ",
c[
m - 1], rcond);
78 if (do_print)
print(
"Forcing full step due to subspace malfunction");
101 const unsigned int tmp =
maxsub;
119 const double rcondtol=1
e-8,
const double cabsmax=1000.0) {
128 for (
int i=0; i<=iter; i++) {
145 for (
int i=0; i<=iter; i++) {
173 template<
typename T, std::
size_t NDIM>
184 return zero_functions<T, NDIM>(
world,
n);
206 template <
class T,
class C =
double,
class Alloc = default_allocator<T> >
253 T update(
const T&
u,
const T& r,
const double rcondtol=1
e-8,
const double cabsmax=1000.0) {
255 int iter =
ulist.size();
262 for (
int i=0; i<=iter; i++) {
274 for (
int i=0; i<=iter; i++) {
295 T update(
const T& u_preliminary,
const double rcondtol=1
e-8,
const double cabsmax=1000.0) {
296 if (
maxsub==1)
return u_preliminary;
302 auto get_operating_state = [](
const T&
v) {
313 TreeState operating_state = get_operating_state(u_preliminary);
315 int iter =
ulist.size()-1;
317 plist.push_back(u_preliminary);
325 for (
int i=0; i<=iter; i++) {
330 if constexpr (do_tree_states) {
343 for (
int i=0; i<=iter; i++) {
345 unew += (
plist[i+1])*
c[i];
349 ulist.push_back(unew);
362 ulist.push_back(u_initial);
369 template<
typename T, std::
size_t NDIM>
370 static inline XNonlinearSolver<std::vector<Function<T,NDIM>>,
T,vector_function_allocator<T,NDIM>>
FunctionFactory implements the named-parameter idiom for Function.
Definition function_factory.h:86
FunctionFactory & treestate(const TreeState state)
Definition function_factory.h:173
A multiresolution adaptive numerical function.
Definition mra.h:139
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:642
std::size_t size() const
Returns the number of coefficients in the function ... collective global sum.
Definition mra.h:573
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:1025
A simple Krylov-subspace nonlinear equation solver.
Definition nonlinsol.h:90
void set_maxsub(const unsigned int &new_maxsub)
Definition nonlinsol.h:97
real_tensor Q
Definition nonlinsol.h:94
bool do_print
Definition nonlinsol.h:104
std::vector< Function< double, NDIM > > ulist
Definition nonlinsol.h:93
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:118
unsigned int get_maxsub() const
Definition nonlinsol.h:100
NonlinearSolverND(unsigned int maxsub=10)
Definition nonlinsol.h:106
unsigned int maxsub
Maximum size of subspace dimension.
Definition nonlinsol.h:91
std::vector< Function< double, NDIM > > rlist
Definition nonlinsol.h:93
A slice defines a sub-range or patch of a dimension.
Definition slice.h:103
A tensor is a multidimensional array.
Definition tensor.h:317
A parallel world class.
Definition world.h:132
Generalized version of NonlinearSolver not limited to a single madness function.
Definition nonlinsol.h:207
void set_maxsub(int maxsub)
Definition nonlinsol.h:233
XNonlinearSolver(const Alloc &alloc=Alloc(), bool print=false)
Definition nonlinsol.h:216
void clear_subspace()
Definition nonlinsol.h:236
Tensor< C > c
coefficients for linear combination
Definition nonlinsol.h:212
void initialize(const T &u_initial)
Definition nonlinsol.h:360
Tensor< C > Q
Definition nonlinsol.h:211
std::vector< T > & get_rlist()
Definition nonlinsol.h:230
std::vector< T > ulist
Definition nonlinsol.h:210
Tensor< C > get_c() const
Definition nonlinsol.h:234
std::vector< T > & get_ulist()
Definition nonlinsol.h:229
std::vector< T > rlist
Definition nonlinsol.h:210
Alloc alloc
Definition nonlinsol.h:209
T update(const T &u_preliminary, const double rcondtol=1e-8, const double cabsmax=1000.0)
Computes next trial solution vector.
Definition nonlinsol.h:295
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:253
bool do_print
Definition nonlinsol.h:214
std::vector< T > plist
Subspace information.
Definition nonlinsol.h:210
XNonlinearSolver(const XNonlinearSolver &other)
Definition nonlinsol.h:222
unsigned int maxsub
Maximum size of subspace dimension.
Definition nonlinsol.h:208
std::vector< T > & get_plist()
Definition nonlinsol.h:231
char * p(char *buf, const char *name, int k, int initial_level, double thresh, int order)
Definition derivatives.cc:72
auto T(World &world, response_space &f) -> response_space
Definition global_functions.cc:34
static const double v
Definition hatom_sf_dirac.cc:20
static double u(double r, double c)
Definition he.cc:20
#define MADNESS_CHECK_THROW(condition, msg)
Check a condition — even in a release build the condition is always evaluated so it can have side eff...
Definition madness_exception.h:207
Main include file for MADNESS and defines Function interface.
Namespace for all elements and tools of MADNESS.
Definition DFParameters.h:10
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
NonlinearSolverND< 3 > NonlinearSolver
Definition nonlinsol.h:161
TreeState
Definition funcdefaults.h:59
@ reconstructed
s coeffs at the leaves only
Definition funcdefaults.h:60
@ unknown
Definition funcdefaults.h:68
@ compressed
d coeffs in internal nodes, s and d coeffs at the root
Definition funcdefaults.h:61
const std::vector< Function< T, NDIM > > & reconstruct(const std::vector< Function< T, NDIM > > &v)
reconstruct a vector of functions
Definition vmra.h:162
void check_linear_dependence(const Tensor< C > &Q, Tensor< C > &c, const double rcondtol, const double cabsmax, bool do_print=true)
check for subspace linear dependency
Definition nonlinsol.h:63
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
@ TT_FULL
Definition gentensor.h:120
const Function< T, NDIM > & change_tree_state(const Function< T, NDIM > &f, const TreeState finalstate, bool fence=true)
change tree state of a function
Definition mra.h:2807
XNonlinearSolver< std::vector< Function< double, 6 > >, double, vector_function_allocator< double, 6 > > NonlinearVectorSolver_6d
Definition nonlinsol.h:378
double inner(response_space &a, response_space &b)
Definition response_functions.h:442
XNonlinearSolver< std::vector< Function< double, 3 > >, double, vector_function_allocator< double, 3 > > NonlinearVectorSolver_3d
Definition nonlinsol.h:377
static XNonlinearSolver< std::vector< Function< T, NDIM > >, T, vector_function_allocator< T, NDIM > > nonlinear_vector_solver(World &world, const long nvec)
Definition nonlinsol.h:371
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:2066
double Q(double a)
Definition relops.cc:20
static const double c
Definition relops.cc:10
static const double m
Definition relops.cc:9
Defines interfaces for optimization and non-linear equation solvers.
Definition nonlinsol.h:165
T operator()()
Definition nonlinsol.h:166
Definition nonlinsol.h:174
const int n
Definition nonlinsol.h:176
World & world
Definition nonlinsol.h:175
vector_function_allocator(World &world, const int nn)
Definition nonlinsol.h:180
std::vector< Function< T, NDIM > > operator()()
allocate a vector of n empty functions
Definition nonlinsol.h:183
void e()
Definition test_sig.cc:75