source: src/LinearAlgebra/Subspace.cpp@ 586055

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since 586055 was 9c5296, checked in by Frederik Heber <heber@…>, 14 years ago

New classes Eigenspace and Subspace that contain eigen(sub)spaces.

  • also added new test to SubspaceFactorizerUnitTest::Subspacetext().
    • so far only constructs the full and nested sub spaces.
  • Property mode set to 100644
File size: 6.6 KB
Line 
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 * Subspace.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 <boost/shared_ptr.hpp>
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#include "Subspace.hpp"
31
32/** Constructor for class Subspace.
33 *
34 * @param _s indices that make up this subspace
35 * @param _FullSpace reference to the full eigenspace
36 */
37Subspace::Subspace(indexset & _s, Eigenspace &_FullSpace) :
38 Eigenspace(_s),
39 ProjectToSubspace(_s.size(), _FullSpace.getIndices().size()),
40 ProjectFromSubspace(_FullSpace.getIndices().size(), _s.size()),
41 FullSpace(_FullSpace)
42{}
43
44
45/** Destructor for class Subspace.
46 *
47 */
48Subspace::~Subspace()
49{}
50
51
52/** Diagonalizes the subspace matrix.
53 *
54 * @param fullmatrix full matrix to project into subspace and solve
55 */
56void Subspace::calculateEigenSubspace()
57{
58 getSubspacematrixFromBigmatrix(FullSpace.getEigenspaceMatrix());
59}
60
61
62/** Projects a given full matrix down into the subspace of this class.
63 *
64 * @param bigmatrix full matrix to project into subspace
65 */
66void Subspace::getSubspacematrixFromBigmatrix(const MatrixContent & bigmatrix)
67{
68 // check whether subsystem is big enough for both index sets
69 ASSERT(Indices.size() <= bigmatrix.getRows(),
70 "embedEigenspaceMatrix() - bigmatrix has less rows "+toString(bigmatrix.getRows())
71 +" than needed by index set "
72 +toString(Indices.size())+"!");
73 ASSERT(Indices.size() <= bigmatrix.getColumns(),
74 "embedEigenspaceMatrix() - bigmatrix has less columns "+toString(bigmatrix.getColumns())
75 +" than needed by index set "
76 +toString(Indices.size())+"!");
77
78 // construct small matrix
79 MatrixContent *subsystem = new MatrixContent(Indices.size(), Indices.size());
80 size_t localrow = 0; // local row indices for the subsystem
81 size_t localcolumn = 0;
82 BOOST_FOREACH( size_t rowindex, Indices) {
83 localcolumn = 0;
84 BOOST_FOREACH( size_t columnindex, Indices) {
85 ASSERT((rowindex < bigmatrix.getRows()) && (columnindex < bigmatrix.getColumns()),
86 "current index pair ("
87 +toString(rowindex)+","+toString(columnindex)
88 +") is out of bounds of bigmatrix ("
89 +toString(bigmatrix.getRows())+","+toString(bigmatrix.getColumns())
90 +")");
91 subsystem->at(localrow,localcolumn) = (*Eigenvectors[rowindex]) * (bigmatrix * (*Eigenvectors[columnindex]));
92 localcolumn++;
93 }
94 localrow++;
95 }
96}
97
98
99void Subspace::correctEigenvectorsFromSubIndices()
100{
101}
102
103
104/** Creates the inverse of LocalToGlobal.
105 * Mapping is one-to-one and onto, hence it's simply turning around the map.
106 */
107void Subspace::invertLocalToGlobalMapping()
108{
109 GlobalToLocal.clear();
110 for (mapping::const_iterator iter = LocalToGlobal.begin();
111 iter != LocalToGlobal.end();
112 ++iter) {
113 GlobalToLocal.insert( make_pair(iter->second, iter->first) );
114 }
115}
116
117
118/** Project calculated Eigenvectors into full space.
119 *
120 * @return set of projected eigenvectors.
121 */
122Eigenspace::eigenvectorset Subspace::getEigenvectorsInFullSpace()
123{
124 // check whether bigmatrix is at least as big as EigenspaceMatrix
125 ASSERT(Eigenvectors.size() > 0,
126 "embedEigenspaceMatrix() - no Eigenvectors given!");
127 ASSERT(EigenspaceMatrix.getRows() <= Eigenvectors[0]->getDimension(),
128 "embedEigenspaceMatrix() - EigenspaceMatrix has more rows "
129 +toString(EigenspaceMatrix.getRows())+" than eigenvectors "
130 +toString(Eigenvectors[0]->getDimension())+"!");
131 ASSERT(EigenspaceMatrix.getColumns() <= Eigenvectors.size(),
132 "embedEigenspaceMatrix() - EigenspaceMatrix has more columns "
133 +toString(EigenspaceMatrix.getColumns())+" than eigenvectors "
134 +toString(Eigenvectors.size())+"!");
135 // check whether EigenspaceMatrix is big enough for both index sets
136 ASSERT(EigenspaceMatrix.getColumns() == EigenspaceMatrix.getRows(),
137 "embedEigenspaceMatrix() - EigenspaceMatrix is not square "
138 +toString(EigenspaceMatrix.getRows())+" than needed by index set "
139 +toString(EigenspaceMatrix.getColumns())+"!");
140 ASSERT(Indices.size() == EigenspaceMatrix.getColumns(),
141 "embedEigenspaceMatrix() - EigenspaceMatrix has not the same number of columns "
142 +toString(EigenspaceMatrix.getColumns())+" compared to the index set "
143 +toString(Indices.size())+"!");
144
145 // construct intermediate matrix
146 MatrixContent *intermediatematrix = new MatrixContent(Eigenvectors[0]->getDimension(), Indices.size());
147 size_t localcolumn = 0;
148 BOOST_FOREACH(size_t columnindex, Indices) {
149 // create two vectors from each row and copy assign them
150 boost::shared_ptr<VectorContent> srceigenvector(Eigenvectors[columnindex]);
151 boost::shared_ptr<VectorContent> desteigenvector(intermediatematrix->getColumnVector(localcolumn));
152 *desteigenvector = *srceigenvector;
153 localcolumn++;
154 }
155 // matrix product with eigenbasis EigenspaceMatrix matrix
156 *intermediatematrix *= EigenspaceMatrix;
157
158 // and place at right columns into bigmatrix
159 MatrixContent *bigmatrix = new MatrixContent(Eigenvectors[0]->getDimension(), Eigenvectors.size());
160 bigmatrix->setZero();
161 localcolumn = 0;
162 BOOST_FOREACH(size_t columnindex, Indices) {
163 // create two vectors from each row and copy assign them
164 boost::shared_ptr<VectorContent> srceigenvector(intermediatematrix->getColumnVector(localcolumn));
165 boost::shared_ptr<VectorContent> desteigenvector(bigmatrix->getColumnVector(columnindex));
166 *desteigenvector = *srceigenvector;
167 localcolumn++;
168 }
169
170 return Eigenvectors;
171}
172
173
174/** Remove a subset of indices from the SubIndices.
175 *
176 * @param _s subset to remove
177 * @return true - removed, false - not found
178 */
179bool Subspace::removeSubset(boost::shared_ptr<Subspace> &_s)
180{
181 if (SubIndices.count(_s) != 0) {
182 SubIndices.erase(_s);
183 return true;
184 } else {
185 return false;
186 }
187}
188
189/** Add a subspace set to SubIndices.
190 *
191 * @param _s subset to add
192 * @return true - not present before, false - has already been present
193 */
194bool Subspace::addSubset(boost::shared_ptr<Subspace> & _s)
195{
196 if (SubIndices.count(_s) != 0)
197 return false;
198 else {
199 SubIndices.insert(_s);
200 return true;
201 }
202}
203
204
205/** Simply a getter for Eigenvectors, as they are stored as subspace eigenvectors.
206 *
207 * @return set of eigenvectors in subspace
208 */
209Eigenspace::eigenvectorset Subspace::getEigenvectorsInSubspace()
210{
211 return Eigenvectors;
212}
213
Note: See TracBrowser for help on using the repository browser.