Changeset 6c438f for src/LinearAlgebra/Matrix.cpp
- Timestamp:
- Aug 28, 2010, 3:21:11 AM (15 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:
- a6e6b5, f8982c
- Parents:
- 2ad482 (diff), fd4905 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Frederik Heber <heber@…> (08/28/10 03:17:48)
- git-committer:
- Frederik Heber <heber@…> (08/28/10 03:21:11)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/LinearAlgebra/Matrix.cpp
r2ad482 r6c438f 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 1 8 /* 2 9 * Matrix.cpp … … 6 13 */ 7 14 8 #include "Matrix.hpp" 15 // include config.h 16 #ifdef HAVE_CONFIG_H 17 #include <config.h> 18 #endif 19 20 #include "Helpers/MemDebug.hpp" 21 22 #include "LinearAlgebra/Matrix.hpp" 9 23 #include "Helpers/Assert.hpp" 10 24 #include "Exceptions/NotInvertibleException.hpp" 11 25 #include "Helpers/fast_functions.hpp" 12 26 #include "Helpers/Assert.hpp" 13 #include " vector.hpp"27 #include "LinearAlgebra/Vector.hpp" 14 28 #include "VectorContent.hpp" 15 29 #include "MatrixContent.hpp" 16 30 17 31 #include <gsl/gsl_blas.h> 32 #include <gsl/gsl_eigen.h> 33 #include <gsl/gsl_matrix.h> 34 #include <gsl/gsl_multimin.h> 35 #include <gsl/gsl_vector.h> 18 36 #include <cmath> 19 37 #include <iostream> … … 96 114 } 97 115 116 void Matrix::zero(){ 117 for(int i=NDIM;i--;){ 118 for(int j=NDIM;j--;){ 119 set(i,j,0.); 120 } 121 } 122 } 123 124 void Matrix::rotation(const double x, const double y, const double z) 125 { 126 set(0,0, cos(y)*cos(z)); 127 set(0,1, cos(z)*sin(x)*sin(y) - cos(x)*sin(z)); 128 set(0,2, cos(x)*cos(z)*sin(y) + sin(x) * sin(z)); 129 set(1,0, cos(y)*sin(z)); 130 set(1,1, cos(x)*cos(z) + sin(x)*sin(y)*sin(z)); 131 set(1,2, -cos(z)*sin(x) + cos(x)*sin(y)*sin(z)); 132 set(2,0, -sin(y)); 133 set(2,1, cos(y)*sin(x)); 134 set(2,2, cos(x)*cos(y)); 135 } 136 98 137 Matrix &Matrix::operator=(const Matrix &src){ 99 138 if(&src!=this){ … … 103 142 } 104 143 105 Matrix &Matrix::operator+=(const Matrix &rhs){144 const Matrix &Matrix::operator+=(const Matrix &rhs){ 106 145 gsl_matrix_add(content->content, rhs.content->content); 107 146 return *this; 108 147 } 109 148 110 Matrix &Matrix::operator-=(const Matrix &rhs){149 const Matrix &Matrix::operator-=(const Matrix &rhs){ 111 150 gsl_matrix_sub(content->content, rhs.content->content); 112 151 return *this; 113 152 } 114 153 115 Matrix &Matrix::operator*=(const Matrix &rhs){154 const Matrix &Matrix::operator*=(const Matrix &rhs){ 116 155 (*this) = (*this)*rhs; 117 156 return *this; 118 157 } 119 158 120 Matrix Matrix::operator+(const Matrix &rhs) const{159 const Matrix Matrix::operator+(const Matrix &rhs) const{ 121 160 Matrix tmp = *this; 122 161 tmp+=rhs; … … 124 163 } 125 164 126 Matrix Matrix::operator-(const Matrix &rhs) const{165 const Matrix Matrix::operator-(const Matrix &rhs) const{ 127 166 Matrix tmp = *this; 128 167 tmp-=rhs; … … 130 169 } 131 170 132 Matrix Matrix::operator*(const Matrix &rhs) const{171 const Matrix Matrix::operator*(const Matrix &rhs) const{ 133 172 gsl_matrix *res = gsl_matrix_alloc(NDIM, NDIM); 134 173 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, content->content, rhs.content->content, 0.0, res); … … 192 231 - at(2,2)*at(1,0)*at(0,1); 193 232 } 233 194 234 195 235 Matrix Matrix::invert() const{ … … 215 255 Matrix Matrix::transpose() const{ 216 256 MatrixContent *newContent = new MatrixContent(); 257 newContent->content = gsl_matrix_alloc(NDIM, NDIM); 217 258 gsl_matrix_transpose_memcpy(newContent->content, content->content); 218 259 Matrix res = Matrix(newContent); … … 220 261 } 221 262 222 Matrix &Matrix::operator*=(const double factor){ 263 Matrix &Matrix::transpose() 264 { 265 double tmp; 266 for (int i=0;i<NDIM;i++) 267 for (int j=i+1;j<NDIM;j++) { 268 tmp = at(j,i); 269 at(j,i) = at(i,j); 270 at(i,j) = tmp; 271 } 272 return *this; 273 } 274 275 276 Vector Matrix::transformToEigenbasis() 277 { 278 gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM); 279 gsl_vector *eval = gsl_vector_alloc(NDIM); 280 gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM); 281 gsl_eigen_symmv(content->content, eval, evec, T); 282 gsl_eigen_symmv_free(T); 283 gsl_matrix_memcpy(content->content, evec); 284 gsl_matrix_free(evec); 285 Vector evalues(gsl_vector_get(eval,0), gsl_vector_get(eval,1), gsl_vector_get(eval,2)); 286 gsl_vector_free(eval); 287 return evalues; 288 } 289 290 const Matrix &Matrix::operator*=(const double factor){ 223 291 gsl_matrix_scale(content->content, factor); 224 292 return *this; 225 293 } 226 294 227 Matrix operator*(const double factor,const Matrix& mat){295 const Matrix operator*(const double factor,const Matrix& mat){ 228 296 Matrix tmp = mat; 229 297 tmp*=factor; … … 231 299 } 232 300 233 Matrix operator*(const Matrix &mat,const double factor){301 const Matrix operator*(const Matrix &mat,const double factor){ 234 302 return factor*mat; 235 303 } … … 278 346 279 347 Vector operator*(const Matrix &mat,const Vector &vec){ 280 gsl_vector *res = gsl_vector_calloc(NDIM); 281 gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content->content, vec.content->content, 0.0, res); 282 VectorContent *content = new VectorContent(); 283 content->content = res; 284 return Vector(content); 348 Vector res; 349 gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content->content, vec.content->content, 0.0, res.content->content); 350 return res; 285 351 } 286 352
Note:
See TracChangeset
for help on using the changeset viewer.