3
0
mirror of https://github.com/triqs/dft_tools synced 2024-12-26 06:14:14 +01:00

Merge pull request #41 from lmessio/master

Changes in the doc and one bug removed in det_manip
This commit is contained in:
Olivier Parcollet 2013-12-21 04:43:50 -08:00
commit c185be83c0
11 changed files with 286 additions and 95 deletions

View File

@ -10,7 +10,6 @@ Multidimensional arrays
.. toctree:: .. toctree::
:maxdepth: 1 :maxdepth: 1
:numbered:
introduction introduction
concepts concepts
@ -35,4 +34,4 @@ Multidimensional arrays
multithreading multithreading
FAQ FAQ
implementation_notes/contents implementation_notes/contents
./../../../tutorials/c++/array_tutorial

View File

@ -39,4 +39,4 @@ This class implements these general operations. It contains :
det_manip det_manip
behind behind
cookbook/contents ./../../../tutorials/c++/det_manip_tutorial

View File

@ -1,68 +0,0 @@
Basics
------
Here, an exemple of creation of a class det_manip, of use of insert and remove.
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
//gives the coefficients of the matrix
double operator()(double x, double y) const {
return(x-y);
}
};
int main() {
//creation of the class det_manip
fun f;
int init_size=100;
triqs::det_manip::det_manip<fun> D(f,init_size);
//the initial matrix is empty:
std::cout<<std::endl<<"After construction: D.matrix()="<<D.matrix()<<std::endl<<std::endl;
double detratio;
//insertion of a line and a column at position (1,1) in the matrix, with x[i]=x, y[j]=y.
double x=2, y=9;
int i=0, j=0;
detratio = D.try_insert(i,j,x,y);
D.complete_operation();
std::cout<<"We add a line and a column for i="<<i<<", j="<<j<<", x="<<x<<", y="<<y<<" (f(x,y)="<<f(x,y)<<")."<<std::endl;
std::cout<<"D.matrix()="<<D.matrix()<<std::endl<<std::endl;
x=3; y=4; i=0; j=0;
detratio = D.try_insert(i,j,x,y);
D.complete_operation();
std::cout<<"We add a line and a column for i="<<i<<", j="<<j<<", x="<<x<<", y="<<y<<" (f(x,y)="<<f(x,y)<<")."<<std::endl;
std::cout<<"D.matrix()="<<D.matrix()<<std::endl;
std::cout<<"The determinant is "<<D.determinant()<<std::endl;
std::cout<<"The inverse matrix is"<<D.inverse_matrix()<< std::endl<<std::endl;
x=-7; y=1; i=1; j=2;
detratio = D.try_insert(i,j,x,y);
D.complete_operation();
std::cout<<"We add a line and a column for i="<<i<<", j="<<j<<", x="<<x<<", y="<<y<<" (f(x,y)="<<f(x,y)<<")."<<std::endl;
std::cout<<"D.matrix()="<<D.matrix()<<std::endl<<std::endl;
std::cout<<"The size of the matrix is now "<<D.size()<<std::endl;
std::cout<<"The value of the parameters for coefficient (i,j)=(0,2) is (x,y)=("<<D.get_x(0)<<","<<D.get_y(2)<<") (f("<<D.get_x(0)<<","<<D.get_y(2)<<")="<<f(D.get_x(0),D.get_y(2))<<")."<<std::endl<<std::endl;
i=0; j=1;
detratio = D.try_remove(i,j);
D.complete_operation();
std::cout<<"We remove a line and a column for i="<<i<<", j="<<j<<"."<<std::endl;
std::cout<<"D.matrix()="<<D.matrix()<<std::endl;
std::cout<<"The determinant is "<<D.determinant()<<std::endl;
std::cout<<"The inverse matrix is"<<D.inverse_matrix()<< std::endl<<std::endl;
}
Learn more in the full reference, see :ref:`det_manip`

View File

@ -1,9 +0,0 @@
.. highlight:: c
Det_manip cookbook
===================
.. toctree::
:maxdepth: 2
basic

View File

@ -79,9 +79,11 @@ Doxygen documentation
The :doxy:`full C++ documentation<triqs::det_manip::det_manip>` is available here. The :doxy:`full C++ documentation<triqs::det_manip::det_manip>` is available here.
Example Example
------------- ---------
.. code-block:: c .. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun { struct fun {
@ -89,7 +91,7 @@ Example
typedef double argument_type; typedef double argument_type;
double operator()(double x, double y) const { double operator()(double x, double y) const {
const double pi = acos(-1); const double pi = acos(-1.);
const double beta = 10.0; const double beta = 10.0;
const double epsi = 0.1; const double epsi = 0.1;
double tau = x-y; double tau = x-y;
@ -103,14 +105,18 @@ Example
int main() { int main() {
fun f; fun f;
triqs::det_manip::det_manip<fun> D; triqs::det_manip::det_manip<fun> D(f,100);
/// .... /// insertions of 3 lines and 3 columns
double x=2, y=9, detratio; double x=2., y=9., detratio;
detratio = D.try_insert(1,3, x,y); detratio = D.try_insert(0, 0, x, y );
D.complete_operation();
detratio = D.try_insert(0, 1, 2., 3.);
D.complete_operation();
detratio = D.try_insert(0, 0, 4., 5.);
D.complete_operation(); D.complete_operation();
///... /// removal of a line (the 3rd) and a column (the 2nd)
detratio = D.try_remove(2,1); detratio = D.try_remove(2,1);
D.complete_operation(); D.complete_operation();
} }

View File

@ -183,7 +183,7 @@ behaves like
.. math:: .. math::
g(z) \sim ... + M_{-1} z + M_0 + \frac{M_1}{z} + \frac{M_2}{z} + ... g(z) \sim ... + M_{-1} z + M_0 + \frac{M_1}{z} + \frac{M_2}{z^2} + ...
where :math:`M_i` are matrices with the same dimensions as :math:`g`. where :math:`M_i` are matrices with the same dimensions as :math:`g`.

View File

@ -1,9 +1,14 @@
Using arrays Examples of use of arrays
=============== ==========================
.. highlight:: c .. highlight:: c
TRIQS comes with a library of multidimensional arrays. This library, among others, allows for easy slicing, archiving and algebraic manipulations of multidimensional arrays. Here are a couple of simple examples showing the basic use of this class. .. toctree::
:maxdepth: 1
TRIQS comes with a library of multidimensional arrays.
This library, among others, allows for easy slicing, archiving and algebraic manipulations of multidimensional arrays.
Here are a couple of simple examples showing the basic use of this class.
Declaring and printing an array Declaring and printing an array
@ -173,4 +178,4 @@ Map and fold
std::cout << "F(2*A) = "<<C<<std::endl; std::cout << "F(2*A) = "<<C<<std::endl;
} }
The full reference of the array library can be found :doc:`here: <../../reference/c++/arrays/contents>` The full reference of the array library can be found :doc:`here <../../reference/c++/arrays/contents>`

View File

@ -9,6 +9,6 @@ C++ libraries
:maxdepth: 1 :maxdepth: 1
array_tutorial array_tutorial
det_manip_tutorial
.. ..

View File

@ -0,0 +1,227 @@
Det_manip cookbook
===================
.. highlight:: c
.. toctree::
:maxdepth: 1
TRIQS comes with a class called det_manip to easily perform operations on a special type of matrices
(see :doc:`here <../../reference/c++/det_manip/contents>`).
This library, among others, allows to easily add or remove lines or columns to the matrix, to calculate the determinant and the inverse.
Here are a couple of simple examples showing the basic use of this class.
Creation of an empty det_manip class
-------------------------------------
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
//gives the coefficients of the matrix (function F of the documentation)
double operator()(double x, double y) const {
return(x-y);
}
};
int main() {
fun f;
int init_size = 100; // maximum size of the matrix before a resize
//creation of a class det_manip
triqs::det_manip::det_manip<fun> D(f, init_size);
//the initial matrix is empty:
std::cout<<std::endl<< "After construction: D.matrix()=" << D.matrix()<<std::endl<<std::endl;
}
Creation of a non empty det_manip class
----------------------------------------
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
//gives the coefficients of the matrix (function F of the documentation)
double operator()(double x, double y) const {
return(x-y);
}
};
int main() {
fun f;
std::vector<double> initial_x{1,2}, initial_y{3,4};
//creation of a class det_manip with a 2 by 2 matrix
triqs::det_manip::det_manip<fun> D(f, initial_x, initial_y);
//the initial matrix:
std::cout<<std::endl<< "After construction: D.matrix()=" << D.matrix()<<std::endl<<std::endl;
}
Get informations about a det_manip class
-----------------------------------------
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
double operator()(double x, double y) const { return(x-y); }
};
int main() {
fun f;
int i=0, j=1;
std::vector<double> initial_x{1,2}, initial_y{3,4};
triqs::det_manip::det_manip<fun> D(f, initial_x, initial_y);
std::cout<<std::endl<<"D.matrix()=" << D.matrix() <<std::endl<<std::endl;
std::cout<<"The size of the matrix is "<< D.size() <<std::endl<<std::endl;
std::cout<<"The determinant is "<< D.determinant() <<std::endl<<std::endl;
std::cout<<"The inverse matrix is"<< D.inverse_matrix() << std::endl<<std::endl;
std::cout<<"The value of the parameters for coefficient (i,j)=("<<i<<","<<j<<") is (x,y)=("
<<D.get_x(i)<<","<<D.get_y(j)<<")"<<std::endl<<std::endl;
}
Add a line and a column
-------------------------
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
double operator()(double x, double y) const { return(exp(x)-y*y); }
};
int main() {
triqs::det_manip::det_manip<fun> D(fun(), std::vector<double>{1,2,2.5}, std::vector<double>{3,4,9});
std::cout<<std::endl<<"After construction, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
double x0 = 2.1, y0 = 7;
int i = 2, j = 0; // number of the added line and column
std::cout<<"We want to add a line and a column for i="<<i<<", j="<<j
<<", x="<<x0<<", y="<<y0<<"."<<std::endl;
// (try of) insertion of a line and a column at position (3,1) in the matrix
// with x[i]=x0, y[j]=y0.
double detratio = D.try_insert(i, j, x0, y0); // the ratio between new and old determinants
// while the operation is not complete, the matrix stays unchanged
std::cout<<"After try_insert, D.matrix()="<<D.matrix()<<std::endl;
// here we validate the insertion: the (inverse) matrix and determinant are updated
D.complete_operation();
std::cout<<"After complete_operation, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
}
Remove a line and a column
---------------------------
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
double operator()(double x, double y) const { return(exp(x)-y*y); }
};
int main() {
triqs::det_manip::det_manip<fun> D(fun(), std::vector<double>{1,2,2.5}, std::vector<double>{3,4,9});
std::cout<<std::endl<<"After construction, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
int i = 1, j = 0; // number of the removed line and column
std::cout<<"We want to remove a line and a column for i="<<i<<", j="<<j<<"."<<std::endl;
// (try of) removal of a line and a column at position (1,0) in the matrix.
double detratio = D.try_remove(i, j); // the ratio between new and old determinants
// while the operation is not complete, the matrix stays unchanged
std::cout<<"After try_remove, D.matrix()="<<D.matrix()<<std::endl;
// here we validate the removal: the (inverse) matrix and determinant are updated
D.complete_operation();
std::cout<<"After complete_operation, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
}
Add two lines and two columns
------------------------------
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
double operator()(double x, double y) const { return(exp(x)-y*y); }
};
int main() {
triqs::det_manip::det_manip<fun> D(fun(), std::vector<double>{1,2,2.5}, std::vector<double>{3,4,9});
std::cout<<std::endl<<"After construction, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
double x0 = 2.1, y0 = 7, x1 = 3.5, y1 = 5;
int i0 = 2, i1 = 1, j0 = 0, j1 = 3; // number of the added lines and columns
std::cout<<"We want to add a line and a column for i0="<<i0<<", j0="<<j0<<", i1="<<i1<<", j1="<<j1
<<", x0="<<x0<<", y0="<<y0<<", x1="<<x1<<", y1="<<y1<<")."<<std::endl;
// (try of) insertion of 2 lines and 2 columns in the matrix
double detratio = D.try_insert2 (i0, i1, j0, j1, x0, x1, y0, y1); // the ratio between new and old determinants
// while the operation is not complete, the matrix stays unchanged
std::cout<<"After try_insert2, D.matrix()="<<D.matrix()<<std::endl;
// here we validate the insertion: the (inverse) matrix and determinant are updated
D.complete_operation();
std::cout<<"After complete_operation, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
}
Remove two lines and two columns
--------------------------------
.. compileblock::
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
double operator()(double x, double y) const { return(exp(x)-y*y); }
};
int main() {
triqs::det_manip::det_manip<fun> D(fun(), std::vector<double>{1,2,2.5}, std::vector<double>{3,4,9});
std::cout<<std::endl<<"After construction, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
int i0 = 2, i1 = 1, j0 = 0, j1 = 1; // number of the removed lines and columns
std::cout<<"We want to remove 2 lines and 2 columns for i0="
<<i0<<", j0="<<j0<<", i1="<<i1<<", j1="<<j1<<"."<<std::endl;
// (try of) removal of a line and a column at position (1,0) in the matrix.
double detratio = D.try_remove2(i0, i1, j0, j1); // the ratio between new and old determinants
// while the operation is not complete, the matrix stays unchanged
std::cout<<"After try_remove2, D.matrix()="<<D.matrix()<<std::endl;
// here we validate the removal: the (inverse) matrix and determinant are updated
D.complete_operation();
std::cout<<"After complete_operation, D.matrix()="<<D.matrix()<<std::endl<<std::endl;
}
Learn more in the full reference, see :ref:`det_manip`

View File

@ -0,0 +1,31 @@
#include <triqs/det_manip/det_manip.hpp>
struct fun {
typedef double result_type;
typedef double argument_type;
//gives the coefficients of the matrix (function F of the documentation)
double operator()(double x, double y) const {
return(x-y);
}
};
int main() {
fun f;
int init_size=10;
std::vector<double> initial_x{1,2,2.5}, initial_y{3,4,9};
//creation of an empty class det_manip
triqs::det_manip::det_manip<fun> D1(f, init_size);
//creation of a class det_manip with a 3 by 3 matrix
triqs::det_manip::det_manip<fun> D2(f, initial_x, initial_y);
//the initial matrix:
std::cout<<std::endl<< "After construction: D.matrix()=" << D1.matrix()<<std::endl;
std::cout<<std::endl<< "After construction: D.matrix()=" << D2.matrix()<<std::endl;
}

View File

@ -206,7 +206,7 @@ namespace triqs { namespace det_manip {
* \param X, Y : container for X,Y. * \param X, Y : container for X,Y.
*/ */
template<typename ArgumentContainer1, typename ArgumentContainer2> template<typename ArgumentContainer1, typename ArgumentContainer2>
det_manip(FunctionType F, ArgumentContainer1 const & X, ArgumentContainer2 const & Y) : f(std::move(F)) { det_manip(FunctionType F, ArgumentContainer1 const & X, ArgumentContainer2 const & Y) : f(std::move(F)), Nmax(0) {
if (X.size() != Y.size()) TRIQS_RUNTIME_ERROR<< " X.size != Y.size"; if (X.size() != Y.size()) TRIQS_RUNTIME_ERROR<< " X.size != Y.size";
_construct_common(); _construct_common();
N =X.size(); N =X.size();