Changeset cca9ef for src/LinearAlgebra/RealSpaceMatrix.cpp
- 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)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.