source: src/LinearAlgebra/MatrixContent.hpp@ d766b5

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 d766b5 was e828c0, checked in by Frederik Heber <heber@…>, 14 years ago

SubspaceFactorizer is now hierarchical.

  • higher order subspace matrices are only corrections to lower order ones.
  • i.e. eigenvectors obtained from there have all lower ones projected and substracted.
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * MatrixContent.hpp
3 *
4 * Created on: Jul 2, 2010
5 * Author: crueger
6 */
7
8#ifndef MATRIXCONTENT_HPP_
9#define MATRIXCONTENT_HPP_
10
11/** MatrixContent is a wrapper for gsl_matrix.
12 *
13 * The GNU Scientific Library contaisn some very well written routines for
14 * linear algebra problems. However, it's syntax is C and hence it does not
15 * lend itself to readable written code, i.e. C = A * B, where A, B, and C
16 * are all matrices. Writing code this way is very convenient, concise and
17 * also in the same manner as one would type in MatLab.
18 * However, with C++ and its feature to overload functions and its operator
19 * functions such syntax is easy to create.
20 *
21 * Hence, this class is a C++ wrapper to gsl_matrix. There already some other
22 * libraries, however they fall short for the following reasons:
23 * -# gslwrap: not very well written and uses floats instead of doubles
24 * -# gslcpp: last change is from 2007 and only very few commits
25 * -# o2scl: basically, the same functionality as gsl only written in C++,
26 * however it uses GPLv3 license which is inconvenient for MoleCuilder.
27 *
28 * <h1>Howto use MatrixContent</h1>
29 *
30 * One should not use MatrixContent directly but either have it as a member
31 * variable in a specialized class or inherit from it.
32 *
33 */
34
35#include <gsl/gsl_matrix.h>
36
37#include <iosfwd>
38
39#include "LinearAlgebra/MatrixVector_ops.hpp"
40
41class VectorContent;
42
43/** Dummy structure to create a unique signature.
44 *
45 */
46struct MatrixBaseCase{};
47
48class MatrixContent
49{
50 friend std::ostream & operator<<(std::ostream &ost, const MatrixContent &mat);
51 friend class RealSpaceMatrix;
52 friend class LinearSystemOfEquations;
53
54 // matrix vector products
55 friend VectorContent const operator*(const VectorContent& vec, const MatrixContent& mat);
56 friend VectorContent const operator*(const MatrixContent& mat, const VectorContent& vec);
57
58 // unit tests
59 friend class MatrixContentTest;
60 friend class MatrixContentSymmetricTest;
61public:
62 MatrixContent(size_t rows, size_t columns);
63 MatrixContent(size_t _rows, size_t _columns, MatrixBaseCase);
64 MatrixContent(size_t rows, size_t columns, const double *src);
65 MatrixContent(gsl_matrix *&src);
66 MatrixContent(const MatrixContent &src);
67 MatrixContent(const MatrixContent *src);
68 virtual ~MatrixContent();
69
70 // Accessing
71 double &at(size_t i, size_t j);
72 const double at(size_t i, size_t j) const;
73 void set(size_t i, size_t j, const double value);
74
75 // Initializing
76 void setFromDoubleArray(double * x);
77 void setIdentity();
78 void setValue(double _value);
79 void setZero();
80
81 // Exchanging elements
82 bool SwapRows(size_t i, size_t j);
83 bool SwapColumns(size_t i, size_t j);
84 bool SwapRowColumn(size_t i, size_t j);
85
86 // Transformations
87 MatrixContent transpose() const;
88 MatrixContent &transpose();
89 gsl_vector* transformToEigenbasis();
90 void sortEigenbasis(gsl_vector *eigenvalues);
91
92 // Properties
93 bool IsNull() const;
94 bool IsPositive() const;
95 bool IsNegative() const;
96 bool IsNonNegative() const;
97 bool IsPositiveDefinite() const;
98 double Determinant() const;
99
100 // Operators
101 MatrixContent &operator=(const MatrixContent &src);
102 const MatrixContent &operator+=(const MatrixContent &rhs);
103 const MatrixContent &operator-=(const MatrixContent &rhs);
104 const MatrixContent &operator*=(const MatrixContent &rhs);
105 const MatrixContent operator*(const MatrixContent &rhs) const;
106 const MatrixContent &operator&=(const MatrixContent &rhs);
107 const MatrixContent operator&(const MatrixContent &rhs) const;
108 const MatrixContent &operator*=(const double factor);
109 bool operator==(const MatrixContent &rhs) const;
110
111 const size_t getRows() const;
112 const size_t getColumns() const;
113
114 VectorContent *getColumnVector(size_t column) const;
115 VectorContent *getRowVector(size_t row) const;
116 VectorContent *getDiagonalVector() const;
117
118protected:
119 double *Pointer(size_t m, size_t n);
120 const double *const_Pointer(size_t m, size_t n) const;
121
122 gsl_matrix * content;
123 const size_t rows; // store for internal purposes
124 const size_t columns; // store for internal purposes
125
126private:
127};
128
129const MatrixContent operator*(const double factor,const MatrixContent& mat);
130const MatrixContent operator*(const MatrixContent &mat,const double factor);
131std::ostream & operator<<(std::ostream &ost, const MatrixContent &mat);
132
133/** Matrix view.
134 * Extension of MatrixContent to contain not a gsl_matrix but only a view on a
135 * gsl_matrix
136 *
137 * We need the above MatrixBaseCase here:
138 * content, i.e. the gsl_matrix, must not be allocated, as it is just a view
139 * with an internal gsl_matrix_view. Hence, MatrixBaseCase is just dummy class
140 * to give the constructor a unique signature.
141 */
142struct MatrixViewContent : public MatrixContent
143{
144 MatrixViewContent(gsl_matrix_view _view) :
145 MatrixContent(_view.matrix.size1, _view.matrix.size2, MatrixBaseCase()),
146 view(_view)
147 {
148 content = &view.matrix;
149 }
150 ~MatrixViewContent(){
151 content=0;
152 }
153 gsl_matrix_view view;
154};
155
156#endif /* MATRIXCONTENT_HPP_ */
Note: See TracBrowser for help on using the repository browser.