Changeset cca9ef for src/LinearAlgebra
- Timestamp:
- Dec 4, 2010, 11:54:32 PM (14 years ago)
- Branches:
- 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
- Children:
- 0d4424
- Parents:
- 3bc926
- git-author:
- Frederik Heber <heber@…> (11/15/10 12:58:27)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:54:32)
- Location:
- src/LinearAlgebra
- Files:
-
- 4 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
src/LinearAlgebra/Makefile.am
r3bc926 rcca9ef 18 18 LineSegmentSet.cpp \ 19 19 linearsystemofequations.cpp \ 20 Matrix.cpp \21 20 MatrixContent.cpp \ 22 21 Plane.cpp \ 22 RealSpaceMatrix.cpp \ 23 23 Space.cpp \ 24 24 vector_ops.cpp \ … … 34 34 LineSegmentSet.hpp \ 35 35 linearsystemofequations.hpp \ 36 Matrix.hpp \37 36 MatrixContent.hpp \ 37 RealSpaceMatrix.hpp \ 38 38 Plane.hpp \ 39 39 Space.hpp \ -
src/LinearAlgebra/MatrixContent.cpp
r3bc926 rcca9ef 14 14 #include "Helpers/MemDebug.hpp" 15 15 16 #include "LinearAlgebra/ Matrix.hpp"16 #include "LinearAlgebra/RealSpaceMatrix.hpp" 17 17 #include "Helpers/Assert.hpp" 18 18 #include "Exceptions/NotInvertibleException.hpp" -
src/LinearAlgebra/MatrixContent.hpp
r3bc926 rcca9ef 40 40 { 41 41 friend Vector operator*(const MatrixContent &mat,const Vector &vec); 42 friend class Matrix;42 friend class RealSpaceMatrix; 43 43 public: 44 44 MatrixContent(size_t rows, size_t columns); -
src/LinearAlgebra/RealSpaceMatrix.cpp
r3bc926 rcca9ef 7 7 8 8 /* 9 * Matrix.cpp9 * RealSpaceMatrix.cpp 10 10 * 11 11 * Created on: Jun 25, 2010 … … 20 20 #include "Helpers/MemDebug.hpp" 21 21 22 #include "LinearAlgebra/ Matrix.hpp"22 #include "LinearAlgebra/RealSpaceMatrix.hpp" 23 23 #include "Helpers/Assert.hpp" 24 24 #include "Exceptions/NotInvertibleException.hpp" … … 39 39 using namespace std; 40 40 41 Matrix::Matrix()41 RealSpaceMatrix::RealSpaceMatrix() 42 42 { 43 43 content = new MatrixContent(NDIM, NDIM); … … 45 45 } 46 46 47 Matrix::Matrix(const double* src)47 RealSpaceMatrix::RealSpaceMatrix(const double* src) 48 48 { 49 49 content = new MatrixContent(NDIM, NDIM, src); … … 51 51 } 52 52 53 Matrix::Matrix(constMatrix &src)53 RealSpaceMatrix::RealSpaceMatrix(const RealSpaceMatrix &src) 54 54 { 55 55 content = new MatrixContent(src.content); … … 57 57 } 58 58 59 Matrix::Matrix(const MatrixContent &src)59 RealSpaceMatrix::RealSpaceMatrix(const MatrixContent &src) 60 60 { 61 61 content = new MatrixContent(src); … … 63 63 } 64 64 65 Matrix::Matrix(MatrixContent* _content)65 RealSpaceMatrix::RealSpaceMatrix(MatrixContent* _content) 66 66 { 67 67 content = new MatrixContent(_content); … … 69 69 } 70 70 71 Matrix::~Matrix()71 RealSpaceMatrix::~RealSpaceMatrix() 72 72 { 73 73 // delete all views … … 82 82 } 83 83 84 void Matrix::createViews(){84 void RealSpaceMatrix::createViews(){ 85 85 // create row views 86 86 for(int i=NDIM;i--;){ … … 98 98 } 99 99 100 void Matrix::setIdentity(){100 void RealSpaceMatrix::setIdentity(){ 101 101 content->setIdentity(); 102 102 } 103 103 104 void Matrix::setZero(){104 void RealSpaceMatrix::setZero(){ 105 105 content->setZero(); 106 106 } 107 107 108 void Matrix::setRotation(const double x, const double y, const double z)108 void RealSpaceMatrix::setRotation(const double x, const double y, const double z) 109 109 { 110 110 set(0,0, cos(y)*cos(z)); … … 119 119 } 120 120 121 Matrix &Matrix::operator=(constMatrix &src)121 RealSpaceMatrix &RealSpaceMatrix::operator=(const RealSpaceMatrix &src) 122 122 { 123 123 // MatrixContent checks for self-assignment … … 126 126 } 127 127 128 const Matrix &Matrix::operator+=(constMatrix &rhs)128 const RealSpaceMatrix &RealSpaceMatrix::operator+=(const RealSpaceMatrix &rhs) 129 129 { 130 130 *content += *(rhs.content); … … 132 132 } 133 133 134 const Matrix &Matrix::operator-=(constMatrix &rhs)134 const RealSpaceMatrix &RealSpaceMatrix::operator-=(const RealSpaceMatrix &rhs) 135 135 { 136 136 *content -= *(rhs.content); … … 138 138 } 139 139 140 const Matrix &Matrix::operator*=(constMatrix &rhs)140 const RealSpaceMatrix &RealSpaceMatrix::operator*=(const RealSpaceMatrix &rhs) 141 141 { 142 142 (*content) *= (*rhs.content); … … 144 144 } 145 145 146 const Matrix Matrix::operator+(constMatrix &rhs) const147 { 148 Matrix tmp = *this;146 const RealSpaceMatrix RealSpaceMatrix::operator+(const RealSpaceMatrix &rhs) const 147 { 148 RealSpaceMatrix tmp = *this; 149 149 tmp+=rhs; 150 150 return tmp; 151 151 } 152 152 153 const Matrix Matrix::operator-(constMatrix &rhs) const154 { 155 Matrix tmp = *this;153 const RealSpaceMatrix RealSpaceMatrix::operator-(const RealSpaceMatrix &rhs) const 154 { 155 RealSpaceMatrix tmp = *this; 156 156 tmp-=rhs; 157 157 return tmp; 158 158 } 159 159 160 const Matrix Matrix::operator*(constMatrix &rhs) const161 { 162 Matrix tmp(content);160 const RealSpaceMatrix RealSpaceMatrix::operator*(const RealSpaceMatrix &rhs) const 161 { 162 RealSpaceMatrix tmp(content); 163 163 tmp *= rhs; 164 164 return tmp; 165 165 } 166 166 167 double & Matrix::at(size_t i, size_t j)167 double &RealSpaceMatrix::at(size_t i, size_t j) 168 168 { 169 169 return content->at(i,j); 170 170 } 171 171 172 const double Matrix::at(size_t i, size_t j) const172 const double RealSpaceMatrix::at(size_t i, size_t j) const 173 173 { 174 174 return content->at(i,j); 175 175 } 176 176 177 Vector & Matrix::row(size_t i)177 Vector &RealSpaceMatrix::row(size_t i) 178 178 { 179 179 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); … … 181 181 } 182 182 183 const Vector & Matrix::row(size_t i) const183 const Vector &RealSpaceMatrix::row(size_t i) const 184 184 { 185 185 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); … … 187 187 } 188 188 189 Vector & Matrix::column(size_t i)189 Vector &RealSpaceMatrix::column(size_t i) 190 190 { 191 191 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); … … 193 193 } 194 194 195 const Vector & Matrix::column(size_t i) const195 const Vector &RealSpaceMatrix::column(size_t i) const 196 196 { 197 197 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); … … 199 199 } 200 200 201 Vector & Matrix::diagonal()201 Vector &RealSpaceMatrix::diagonal() 202 202 { 203 203 return *diagonal_ptr; 204 204 } 205 205 206 const Vector & Matrix::diagonal() const206 const Vector &RealSpaceMatrix::diagonal() const 207 207 { 208 208 return *diagonal_ptr; 209 209 } 210 210 211 void Matrix::set(size_t i, size_t j, const double value)211 void RealSpaceMatrix::set(size_t i, size_t j, const double value) 212 212 { 213 213 content->set(i,j, value); 214 214 } 215 215 216 double Matrix::determinant() const{216 double RealSpaceMatrix::determinant() const{ 217 217 return at(0,0)*at(1,1)*at(2,2) 218 218 + at(0,1)*at(1,2)*at(2,0) … … 224 224 225 225 226 MatrixMatrix::invert() const{226 RealSpaceMatrix RealSpaceMatrix::invert() const{ 227 227 double det = determinant(); 228 228 if(fabs(det)<MYEPSILON){ … … 231 231 232 232 double detReci = 1./det; 233 Matrix res;233 RealSpaceMatrix res; 234 234 res.set(0,0, detReci*RDET2(at(1,1),at(2,1),at(1,2),at(2,2))); // A_11 235 235 res.set(1,0, -detReci*RDET2(at(1,0),at(2,0),at(1,2),at(2,2))); // A_21 … … 244 244 } 245 245 246 MatrixMatrix::transpose() const246 RealSpaceMatrix RealSpaceMatrix::transpose() const 247 247 { 248 248 std::cout << "const Matrix::transpose()." << std::endl; 249 Matrix res =Matrix(const_cast<const MatrixContent *>(content)->transpose());249 RealSpaceMatrix res = RealSpaceMatrix(const_cast<const MatrixContent *>(content)->transpose()); 250 250 return res; 251 251 } 252 252 253 Matrix &Matrix::transpose()253 RealSpaceMatrix &RealSpaceMatrix::transpose() 254 254 { 255 255 std::cout << "Matrix::transpose()." << std::endl; … … 258 258 } 259 259 260 Vector Matrix::transformToEigenbasis()260 Vector RealSpaceMatrix::transformToEigenbasis() 261 261 { 262 262 gsl_vector *eval = content->transformToEigenbasis(); … … 266 266 } 267 267 268 const Matrix &Matrix::operator*=(const double factor)268 const RealSpaceMatrix &RealSpaceMatrix::operator*=(const double factor) 269 269 { 270 270 *content *= factor; … … 272 272 } 273 273 274 const Matrix operator*(const double factor,constMatrix& mat)275 { 276 Matrix tmp = mat;274 const RealSpaceMatrix operator*(const double factor,const RealSpaceMatrix& mat) 275 { 276 RealSpaceMatrix tmp = mat; 277 277 return tmp *= factor; 278 278 } 279 279 280 const Matrix operator*(constMatrix &mat,const double factor)280 const RealSpaceMatrix operator*(const RealSpaceMatrix &mat,const double factor) 281 281 { 282 282 return factor*mat; 283 283 } 284 284 285 bool Matrix::operator==(constMatrix &rhs) const285 bool RealSpaceMatrix::operator==(const RealSpaceMatrix &rhs) const 286 286 { 287 287 return (*content == *(rhs.content)); … … 292 292 * \return allocated NDIM*NDIM array with the symmetric matrix 293 293 */ 294 Matrix ReturnFullMatrixforSymmetric(const double * const symm)295 { 296 Matrix matrix;294 RealSpaceMatrix ReturnFullMatrixforSymmetric(const double * const symm) 295 { 296 RealSpaceMatrix matrix; 297 297 matrix.set(0,0, symm[0]); 298 298 matrix.set(1,0, symm[1]); … … 307 307 }; 308 308 309 ostream &operator<<(ostream &ost,const Matrix &mat)309 ostream &operator<<(ostream &ost,const RealSpaceMatrix &mat) 310 310 { 311 311 for(int i = 0;i<NDIM;++i){ … … 320 320 } 321 321 322 Vector operator*(const Matrix &mat,const Vector &vec)322 Vector operator*(const RealSpaceMatrix &mat,const Vector &vec) 323 323 { 324 324 return (*mat.content) * vec; 325 325 } 326 326 327 Vector &operator*=(Vector& lhs,const Matrix &mat)327 Vector &operator*=(Vector& lhs,const RealSpaceMatrix &mat) 328 328 { 329 329 lhs = mat*lhs; -
src/LinearAlgebra/RealSpaceMatrix.hpp
r3bc926 rcca9ef 1 1 /* 2 * Matrix.hpp2 * RealSpaceMatrix.hpp 3 3 * 4 4 * Created on: Jun 25, 2010 … … 6 6 */ 7 7 8 #ifndef MATRIX_HPP_9 #define MATRIX_HPP_8 #ifndef REALSPACEMATRIX_HPP_ 9 #define REALSPACEMATRIX_HPP_ 10 10 11 11 #include <iosfwd> … … 19 19 class MatrixContent; 20 20 21 class Matrix 21 /** 3x3 Matrix class. 22 * This class has some specific features for 3D space such as rotations or 23 * hard-coded determinants. 24 */ 25 class RealSpaceMatrix 22 26 { 23 friend Vector operator*(const Matrix&,const Vector&);27 friend Vector operator*(const RealSpaceMatrix&,const Vector&); 24 28 public: 25 Matrix();29 RealSpaceMatrix(); 26 30 27 31 /** … … 41 45 * 42 46 */ 43 Matrix(const double*);44 Matrix(constMatrix&);45 Matrix(const MatrixContent&);46 virtual ~ Matrix();47 RealSpaceMatrix(const double*); 48 RealSpaceMatrix(const RealSpaceMatrix&); 49 RealSpaceMatrix(const MatrixContent&); 50 virtual ~RealSpaceMatrix(); 47 51 48 52 /** … … 107 111 * Rather costly, so use precomputation as often as possible. 108 112 */ 109 Matrix invert() const;113 RealSpaceMatrix invert() const; 110 114 111 115 /** … … 120 124 * Calculate the transpose of the matrix. 121 125 */ 122 Matrix transpose() const;123 Matrix &transpose();126 RealSpaceMatrix transpose() const; 127 RealSpaceMatrix &transpose(); 124 128 125 129 // operators 126 Matrix &operator=(constMatrix&);130 RealSpaceMatrix &operator=(const RealSpaceMatrix&); 127 131 128 const Matrix &operator+=(constMatrix&);129 const Matrix &operator-=(constMatrix&);130 const Matrix &operator*=(constMatrix&);132 const RealSpaceMatrix &operator+=(const RealSpaceMatrix&); 133 const RealSpaceMatrix &operator-=(const RealSpaceMatrix&); 134 const RealSpaceMatrix &operator*=(const RealSpaceMatrix&); 131 135 132 const Matrix &operator*=(const double);136 const RealSpaceMatrix &operator*=(const double); 133 137 134 const Matrix operator+(constMatrix&) const;135 const Matrix operator-(constMatrix&) const;136 const Matrix operator*(constMatrix&) const;138 const RealSpaceMatrix operator+(const RealSpaceMatrix&) const; 139 const RealSpaceMatrix operator-(const RealSpaceMatrix&) const; 140 const RealSpaceMatrix operator*(const RealSpaceMatrix&) const; 137 141 138 bool operator==(const Matrix&) const;142 bool operator==(const RealSpaceMatrix&) const; 139 143 140 144 private: 141 Matrix(MatrixContent*);145 RealSpaceMatrix(MatrixContent*); 142 146 void createViews(); 143 147 MatrixContent *content; … … 148 152 }; 149 153 150 const Matrix operator*(const double,constMatrix&);151 const Matrix operator*(constMatrix&,const double);154 const RealSpaceMatrix operator*(const double,const RealSpaceMatrix&); 155 const RealSpaceMatrix operator*(const RealSpaceMatrix&,const double); 152 156 153 157 /** … … 165 169 * 5 -> (2,2) 166 170 */ 167 Matrix ReturnFullMatrixforSymmetric(const double * const cell_size);171 RealSpaceMatrix ReturnFullMatrixforSymmetric(const double * const cell_size); 168 172 169 std::ostream &operator<<(std::ostream&,const Matrix&);170 Vector operator*(const Matrix&,const Vector&);171 Vector& operator*=(Vector&,const Matrix&);173 std::ostream &operator<<(std::ostream&,const RealSpaceMatrix&); 174 Vector operator*(const RealSpaceMatrix&,const Vector&); 175 Vector& operator*=(Vector&,const RealSpaceMatrix&); 172 176 173 #endif /* MATRIX_HPP_ */177 #endif /* REALSPACEMATRIX_HPP_ */ -
src/LinearAlgebra/Vector.hpp
r3bc926 rcca9ef 22 22 23 23 class Vector; 24 class Matrix;24 class RealSpaceMatrix; 25 25 class MatrixContent; 26 26 struct VectorContent; … … 33 33 class Vector : public Space{ 34 34 friend Vector operator*(const MatrixContent&,const Vector&); 35 friend class Matrix;35 friend class RealSpaceMatrix; 36 36 public: 37 37 Vector();
Note:
See TracChangeset
for help on using the changeset viewer.