1 | /*
|
---|
2 | * Project: MoleCuilder
|
---|
3 | * Description: creates and alters molecular systems
|
---|
4 | * Copyright (C) 2010 University of Bonn. All rights reserved.
|
---|
5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Eigenspace.cpp
|
---|
10 | *
|
---|
11 | * Created on: Nov 22, 2010
|
---|
12 | * Author: heber
|
---|
13 | */
|
---|
14 |
|
---|
15 | // include config.h
|
---|
16 | #ifdef HAVE_CONFIG_H
|
---|
17 | #include <config.h>
|
---|
18 | #endif
|
---|
19 |
|
---|
20 | #include "Helpers/MemDebug.hpp"
|
---|
21 |
|
---|
22 | #include <iostream>
|
---|
23 | #include <boost/foreach.hpp>
|
---|
24 |
|
---|
25 | #include "Helpers/Assert.hpp"
|
---|
26 | #include "Helpers/Log.hpp"
|
---|
27 | #include "Helpers/Verbose.hpp"
|
---|
28 |
|
---|
29 | #include "Eigenspace.hpp"
|
---|
30 |
|
---|
31 |
|
---|
32 | /** Constructor for Eigenspace.
|
---|
33 | * @param _Indices index set for columns and rows of EigenspaceMatrix.
|
---|
34 | */
|
---|
35 | Eigenspace::Eigenspace(const indexset &_Indices) :
|
---|
36 | Indices(_Indices),
|
---|
37 | EigenspaceMatrix(_Indices.size(),_Indices.size()),
|
---|
38 | EigenvectorMatrix(_Indices.size(),_Indices.size())
|
---|
39 | {
|
---|
40 | createEigenvectorViews();
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | /** Constructor for Eigenspace.
|
---|
45 | * @param _Indices index set for columns and rows of EigenspaceMatrix.
|
---|
46 | * @param _matrix matrix to use
|
---|
47 | */
|
---|
48 | Eigenspace::Eigenspace(const indexset &_Indices, const MatrixContent &_matrix) :
|
---|
49 | Indices(_Indices),
|
---|
50 | EigenspaceMatrix(_matrix),
|
---|
51 | EigenvectorMatrix(_matrix.getRows(), _matrix.getColumns())
|
---|
52 | {
|
---|
53 | ASSERT(_Indices.size() == _matrix.getRows(),
|
---|
54 | "Eigenspace::Eigenspace() - number of indices "+toString(_Indices.size())
|
---|
55 | +" and row dimension of matrix "+toString(_matrix.getRows())+" don't match!");
|
---|
56 | ASSERT(_Indices.size() == _matrix.getColumns(),
|
---|
57 | "Eigenspace::Eigenspace() - number of indices "+toString(_Indices.size())
|
---|
58 | +" and column dimension of matrix "+toString(_matrix.getColumns())+" don't match!");
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | /** Destructor for Eigenspace.
|
---|
63 | *
|
---|
64 | */
|
---|
65 | Eigenspace::~Eigenspace()
|
---|
66 | {}
|
---|
67 |
|
---|
68 |
|
---|
69 | /** Create a number of eigenvectors in Eigenspace::Eigenvectors.
|
---|
70 | * These are views on the resepctive column vectors in
|
---|
71 | * Eigenspace::EigenvectorMatrix.
|
---|
72 | */
|
---|
73 | void Eigenspace::createEigenvectorViews()
|
---|
74 | {
|
---|
75 | const size_t ColumnCount = EigenspaceMatrix.getColumns();
|
---|
76 | for (size_t iter = 0; iter < ColumnCount; ++iter) {
|
---|
77 | boost::shared_ptr<VectorContent> ev(EigenspaceMatrix.getColumnVector(iter));
|
---|
78 | Eigenvectors.push_back( ev );
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | /** Obtains the eigenvectors to Eigenspace::EigenspaceMatrix.
|
---|
84 | * We diagonalize the matrix and set the Eigenspace::Eigenvectors and
|
---|
85 | * Eigenspace::Eigenvalues.
|
---|
86 | */
|
---|
87 | void Eigenspace::calculateEigenSubspace()
|
---|
88 | {
|
---|
89 | EigenvectorMatrix = EigenspaceMatrix;
|
---|
90 | VectorContent *Eigenvalues = new VectorContent(EigenvectorMatrix.transformToEigenbasis());
|
---|
91 | Log() << Verbose(2) << "Eigenvector matrix is " << EigenvectorMatrix << std::endl;
|
---|
92 | Log() << Verbose(2) << "Eigenvalues are " << *Eigenvalues << std::endl;
|
---|
93 | }
|
---|
94 |
|
---|
95 |
|
---|
96 | /** Getter for constant reference to Eigenspace::EigenspaceMatrix.
|
---|
97 | *
|
---|
98 | * @return Eigenspace::EigenspaceMatrix
|
---|
99 | */
|
---|
100 | const MatrixContent & Eigenspace::getEigenspaceMatrix() const
|
---|
101 | {
|
---|
102 | return EigenspaceMatrix;
|
---|
103 | }
|
---|
104 |
|
---|
105 |
|
---|
106 | /** Setter for Eigenspace::EigenspaceMatrix.
|
---|
107 | *
|
---|
108 | * @param _content matrix to use
|
---|
109 | */
|
---|
110 | void Eigenspace::setEigenspaceMatrix(const MatrixContent &_content)
|
---|
111 | {
|
---|
112 | EigenspaceMatrix = _content;
|
---|
113 | EigenvectorMatrix.setZero();
|
---|
114 | }
|
---|
115 |
|
---|
116 | /** Checks whether each index of _indexset is contained in this subspace:Indices.
|
---|
117 | *
|
---|
118 | * @param _subspace subspace set to check
|
---|
119 | * @return true - _index is contained, false - at least index is not contained
|
---|
120 | */
|
---|
121 | bool Eigenspace::contains(const Eigenspace &_subspace)
|
---|
122 | {
|
---|
123 | BOOST_FOREACH(size_t iter, _subspace.getIndices()) {
|
---|
124 | if (Indices.count(iter) == 0) { // index not present, then not contained
|
---|
125 | return false;
|
---|
126 | }
|
---|
127 | }
|
---|
128 | return true;
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | /** Getter for Eigenspace::Indices.
|
---|
133 | *
|
---|
134 | * @return indexset of this eigenspace
|
---|
135 | */
|
---|
136 | const Eigenspace::indexset & Eigenspace::getIndices() const
|
---|
137 | {
|
---|
138 | return Indices;
|
---|
139 | }
|
---|
140 |
|
---|
141 | std::ostream & operator<<(std::ostream &ost, const Eigenspace &_s)
|
---|
142 | {
|
---|
143 | BOOST_FOREACH(size_t iter, _s.getIndices()) {
|
---|
144 | ost << iter << " ";
|
---|
145 | }
|
---|
146 | return ost;
|
---|
147 | }
|
---|