~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/eltopo/common/newsparse/krylov_solvers.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef KRYLOV_SOLVERS_H
 
2
#define KRYLOV_SOLVERS_H
 
3
 
 
4
#include <linear_operator.h>
 
5
 
 
6
enum KrylovSolverStatus{
 
7
    KRYLOV_CONVERGED,
 
8
    KRYLOV_EXCEEDED_MAX_ITERATIONS,
 
9
    KRYLOV_BREAKDOWN
 
10
};
 
11
 
 
12
//============================================================================
 
13
// Only guaranteed for symmetric positive definite systems.
 
14
// Singular systems may be solved, but round-off error may cause problems,
 
15
// and if the system is inconsistent convergence will not be automatically detected.
 
16
struct CG_Solver
 
17
{
 
18
    double tolerance_factor;
 
19
    unsigned int max_iterations;
 
20
    double residual_norm; // we use the infinity norm
 
21
    unsigned int iteration;
 
22
    KrylovSolverStatus status;
 
23
    std::vector<double> r, z, s;
 
24
    
 
25
    CG_Solver(void)
 
26
    : tolerance_factor(1e-9), max_iterations(100), residual_norm(0), iteration(0), status(KRYLOV_CONVERGED), r(0), z(0), s(0)
 
27
    {}
 
28
    
 
29
    // Attempt to solve A*result=rhs for result.
 
30
    // Sets residual_norm, iteration, and status (and also returns status)
 
31
    // If optional preconditioner given, use it.
 
32
    // If "use_given_initial_guess" is false (default), take initial guess to be all zeros;
 
33
    //  if true, instead use whatever is in result at the moment. 
 
34
    KrylovSolverStatus solve(const LinearOperator &A, const double *rhs, double *result,
 
35
                             const LinearOperator *preconditioner=0, bool use_given_initial_guess=false);
 
36
};
 
37
 
 
38
//============================================================================
 
39
// MINRES using the Conjugate Residual (CR) algorithm.
 
40
// May work on symmetric indefinite problems, but is vulnerable to breakdown
 
41
// except in the positive definite case.
 
42
struct MINRES_CR_Solver
 
43
{
 
44
    double tolerance_factor;
 
45
    unsigned int max_iterations;
 
46
    double residual_norm; // we use the infinity norm
 
47
    unsigned int iteration;
 
48
    KrylovSolverStatus status;
 
49
    std::vector<double> r, z, q, s, t;
 
50
    
 
51
    MINRES_CR_Solver(void)
 
52
    : tolerance_factor(1e-9), max_iterations(100), residual_norm(0), iteration(0), status(KRYLOV_CONVERGED), r(0), z(0), q(0), s(0), t(0)
 
53
    {}
 
54
    
 
55
    // Attempt to solve A*result=rhs for result.
 
56
    // Sets residual_norm, iteration, and status (and also returns status)
 
57
    // If optional preconditioner given, use it.
 
58
    // If "use_given_initial_guess" is false (default), take initial guess to be all zeros;
 
59
    //  if true, instead use whatever is in result at the moment. 
 
60
    KrylovSolverStatus solve(const LinearOperator &A, const double *rhs, double *result,
 
61
                             const LinearOperator *preconditioner=0, bool use_given_initial_guess=false);
 
62
};
 
63
 
 
64
//============================================================================
 
65
// CGNR (Conjugate Gradient applied to the Normal Equations)
 
66
// Should be able to solve min ||b-Ax|| for A with full column rank,
 
67
// including the case Ax=b for general non-singular A. Rank-deficient problems
 
68
// may still work.
 
69
struct CGNR_Solver
 
70
{
 
71
    double tolerance_factor;
 
72
    unsigned int max_iterations;
 
73
    double residual_norm; // we use the infinity norm of the residual in the normal equations, A^T*(b-A*x)
 
74
    // Please note --- this is not the same as the residual of the original, b-A*x
 
75
    unsigned int iteration;
 
76
    KrylovSolverStatus status;
 
77
    std::vector<double> r, z, s, u;
 
78
    
 
79
    CGNR_Solver(void)
 
80
    : tolerance_factor(1e-9), max_iterations(100), residual_norm(0), iteration(0), status(KRYLOV_CONVERGED), r(0), z(0), s(0), u(0)
 
81
    {}
 
82
    
 
83
    // Attempt to solve min ||rhs-A*result|| (or A*result=rhs for nonsingular A) for result.
 
84
    // Sets residual_norm, iteration, and status (and also returns status)
 
85
    // If optional preconditioner given, use it; it should precondition A, so that A*M is close to orthogonal.
 
86
    // If "use_given_initial_guess" is false (default), take initial guess to be all zeros;
 
87
    //  if true, instead use whatever is in result at the moment. 
 
88
    KrylovSolverStatus solve(const LinearOperator &A, const double *rhs, double *result,
 
89
                             const LinearOperator *preconditioner=0, bool use_given_initial_guess=false);
 
90
};
 
91
 
 
92
#endif