source: src/LinearAlgebra/MatrixContent.hpp@ 9df680

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 9df680 was 56f73b, checked in by Frederik Heber <heber@…>, 14 years ago

Added config.h also to all header files, code check test ascertain this in the future.

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