14 #include "exceptions.hpp" 15 #include "shared_ptr.hpp" 17 typedef std::complex<double> complex;
18 typedef std::vector<complex> Vector;
20 typedef STD_TR1::shared_ptr<Vector> Vector_ref;
37 size_t get()
const {
return cc;};
38 void set(
size_t c) {cc = c;};
43 selector tmp(cc); ++cc;
return tmp;};
47 selector tmp(cc); --cc;
return tmp;};
53 cc += c;
return *
this;};
55 cc -= c;
return *
this;};
56 bool operator==(
const selector c)
const {
57 return (cc == c.cc);};
58 bool operator!=(
const selector c)
const {
59 return (cc != c.cc);};
84 virtual ~
Matrix()
throw() {};
100 size_t num_of_rows()
const {
return num_rows();};
104 size_t num_of_cols()
const {
return num_cols();};
107 void add_diagonal( complex e );
109 void insert_diagonal( complex e );
111 void multiply_by_number( complex v);
113 void print(std::ostream&)
const;
114 void formatted_print(std::ostream&)
const;
116 bool check_hermitian()
const;
117 bool check_realsymmetric()
const;
121 virtual void insert(
row r,
column c, complex v) = 0;
122 virtual void add(
row r,
column c, complex v) = 0;
123 virtual complex
get(
row r,
column c)
const = 0;
129 virtual size_t num_rows()
const = 0;
130 virtual size_t num_cols()
const = 0;
133 std::ostream& operator<<(std::ostream&,
const Matrix&);
148 myM(&t), my_c(c), my_r(r) {};
160 myM->
Insert(r + my_r,c + my_c,v);
164 myM->
Add(r + my_r,c + my_c,v);
168 return myM->
Get(r + my_r,c + my_c);
171 size_t num_rows()
const {
return myM->num_of_rows() - my_r.get();};
172 size_t num_cols()
const {
return myM->num_of_cols() - my_c.get();};
186 bool operator==(
const row_iterator& ri){
return ri.r == r;};
187 bool operator!=(
const row_iterator& ri){
return ri.r != r;};
189 std::complex<double> operator*(){
return m->Get(r,c);};
223 size_t num_rows()
const {
return myM->num_of_cols();};
224 size_t num_cols()
const {
return myM->num_of_rows();};
254 size_t num_rows()
const {
return myM->num_of_cols();};
255 size_t num_cols()
const {
return myM->num_of_rows();};
284 size_t num_rows()
const {
return myM->num_of_rows();};
285 size_t num_cols()
const {
return myM->num_of_cols();};
312 size_t num_rows()
const {
return myM->num_of_cols();};
313 size_t num_cols()
const {
return myM->num_of_rows();};
325 typedef STD_TR1::shared_ptr<calculation_Matrix> ref;
326 typedef STD_TR1::shared_ptr<const calculation_Matrix> const_ref;
332 complex* result)
const { apply_two(phi, result);};
334 void Apply(
const Vector& phi,
335 Vector& result)
const;
338 void Apply(complex* phi)
const { apply_one(phi);};
340 void Apply(Vector& phi)
const;
349 void apply_two(
const complex* phi,
350 complex* result)
const = 0;
352 void apply_one(complex* phi)
const;
355 void scale(complex v) = 0;
373 myM(&t),orbitals_to_drop(orbitals_to_drop)
375 size = myM->num_of_cols()<myM->num_of_rows() ? myM->num_of_cols() : myM->num_of_rows();
376 correspondence_list = create_correspondence_list(orbitals_to_drop,size);
389 static std::vector<int> create_correspondence_list(std::vector<int> orbitals_to_drop,
int n);
397 if (correspondence_list[r.get()]==-1 || correspondence_list[c.get()]==-1)
return;
398 else myM->
Insert(
row(correspondence_list[r.get()]),
column(correspondence_list[c.get()]) ,v);
402 if (correspondence_list[r.get()]==-1 || correspondence_list[c.get()]==-1)
return;
403 else myM->
Add(
row(correspondence_list[r.get()]),
column(correspondence_list[c.get()]) ,v);
407 if (correspondence_list[r.get()]==-1 || correspondence_list[c.get()]==-1)
409 std::cout <<
"orbital_dropper_Matrix: get() of a nonexisting (dropped) item was attempted (this should not happen!). 0 was returned.";
412 else return myM->
Get(r,c);
415 std::vector<int> orbitals_to_drop;
416 std::vector<int> correspondence_list;
420 size_t num_rows()
const {
return size;};
421 size_t num_cols()
const {
return size;};
Definition: matrix.hpp:262
correct_transpose_Matrix(Matrix *m)
Construct a transposed Matrix out of a normal one.
Definition: matrix.hpp:236
void Scale(complex v)
Scale the entire matrix by a complex constant.
Definition: matrix.hpp:343
column ncols() const
Number of Columns.
Definition: matrix.hpp:103
Definition: matrix.hpp:175
void Apply(complex *phi) const
Overload of Apply to directly overwrite the input vector.
Definition: matrix.hpp:338
Access a Matrix by transposed indices.
Definition: matrix.hpp:233
void Insert(row r, column c, complex v)
Insert an element at a given position (overwritten if already there)
Definition: matrix.hpp:92
scaled_Matrix(complex s, Matrix *m)
Construct a transposed Matrix out of a normal one.
Definition: matrix.hpp:265
Simulate a larger square matrix and ignore accesses to given rows and columns.
Definition: matrix.hpp:369
Access a Matrix by transposed indices.
Definition: matrix.hpp:291
sub_Matrix(Matrix &t, row r, column c)
Construct a sub_Matrix from a Matrix, where the sub_Matrix starts at given Position.
Definition: matrix.hpp:147
complex Get(row r, column c) const
Obtain an element at a given position.
Definition: matrix.hpp:96
transpose_Matrix(Matrix *m)
Construct a transposed Matrix out of a normal one.
Definition: matrix.hpp:205
Obtain a part of a larger Matrix as sub-Matrix that can be accessed like a Matrix.
Definition: matrix.hpp:143
Access a Matrix by transposed indices.
Definition: matrix.hpp:202
Helper object for indexed access of matrices.
Definition: matrix.hpp:30
Base Matrix class for access to 2D number grids.
Definition: matrix.hpp:82
void Apply(const complex *phi, complex *result) const
Apply a vector (stored in a pointer, for legacy code only!) to the matrix.
Definition: matrix.hpp:331
row nrows() const
Number of rows.
Definition: matrix.hpp:99
conjugate_transpose_Matrix(Matrix *m)
Construct a transposed Matrix out ofa normal one.
Definition: matrix.hpp:294
Definition: exceptions.hpp:153
This Base-Class offers Matrix-Vector multiplication and scaling.
Definition: matrix.hpp:322
void Add(row r, column c, complex v)
Add an element at a given position.
Definition: matrix.hpp:94