Changeset fee079
- Timestamp:
- Jul 2, 2010, 3:11:22 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:
- 04ef48
- Parents:
- aafd77
- Location:
- src
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Matrix.cpp
raafd77 rfee079 13 13 #include "vector.hpp" 14 14 #include "VectorContent.hpp" 15 #include "MatrixContent.hpp" 15 16 16 17 #include <gsl/gsl_blas.h> … … 22 23 Matrix::Matrix() 23 24 { 24 content = gsl_matrix_calloc(NDIM, NDIM); 25 content = new MatrixContent(); 26 content->content = gsl_matrix_calloc(NDIM, NDIM); 25 27 } 26 28 27 29 Matrix::Matrix(const double* src){ 28 content = gsl_matrix_alloc(NDIM, NDIM); 30 content = new MatrixContent(); 31 content->content = gsl_matrix_alloc(NDIM, NDIM); 29 32 set(0,0, src[0]); 30 33 set(1,0, src[1]); … … 41 44 42 45 Matrix::Matrix(const Matrix &src){ 43 content = gsl_matrix_alloc(NDIM, NDIM); 44 gsl_matrix_memcpy(content,src.content); 45 } 46 47 Matrix::Matrix(gsl_matrix* _content) : 46 content = new MatrixContent(); 47 content->content = gsl_matrix_alloc(NDIM, NDIM); 48 gsl_matrix_memcpy(content->content,src.content->content); 49 } 50 51 Matrix::Matrix(MatrixContent* _content) : 48 52 content(_content) 49 53 {} … … 51 55 Matrix::~Matrix() 52 56 { 53 gsl_matrix_free(content); 57 gsl_matrix_free(content->content); 58 delete content; 54 59 } 55 60 56 61 void Matrix::one(){ 57 gsl_matrix_free(content );58 content = gsl_matrix_calloc(NDIM, NDIM);62 gsl_matrix_free(content->content); 63 content->content = gsl_matrix_calloc(NDIM, NDIM); 59 64 for(int i = NDIM;i--;){ 60 65 set(i,i,1.); … … 64 69 Matrix &Matrix::operator=(const Matrix &src){ 65 70 if(&src!=this){ 66 gsl_matrix_memcpy(content ,src.content);71 gsl_matrix_memcpy(content->content,src.content->content); 67 72 } 68 73 return *this; … … 70 75 71 76 Matrix &Matrix::operator+=(const Matrix &rhs){ 72 gsl_matrix_add(content , rhs.content);77 gsl_matrix_add(content->content, rhs.content->content); 73 78 return *this; 74 79 } 75 80 76 81 Matrix &Matrix::operator-=(const Matrix &rhs){ 77 gsl_matrix_sub(content , rhs.content);82 gsl_matrix_sub(content->content, rhs.content->content); 78 83 return *this; 79 84 } … … 98 103 Matrix Matrix::operator*(const Matrix &rhs) const{ 99 104 gsl_matrix *res = gsl_matrix_alloc(NDIM, NDIM); 100 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, this->content, rhs.content, 0.0, res); 101 return Matrix(res); 105 gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, content->content, rhs.content->content, 0.0, res); 106 MatrixContent *content= new MatrixContent(); 107 content->content = res; 108 return Matrix(content); 102 109 } 103 110 … … 105 112 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); 106 113 ASSERT(j>=0&&j<NDIM,"Index j for Matrix access out of range"); 107 return *gsl_matrix_ptr (content , i, j);114 return *gsl_matrix_ptr (content->content, i, j); 108 115 } 109 116 … … 111 118 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); 112 119 ASSERT(j>=0&&j<NDIM,"Index j for Matrix access out of range"); 113 return gsl_matrix_get(content , i, j);120 return gsl_matrix_get(content->content, i, j); 114 121 } 115 122 … … 117 124 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); 118 125 ASSERT(j>=0&&j<NDIM,"Index j for Matrix access out of range"); 119 gsl_matrix_set(content ,i,j,value);126 gsl_matrix_set(content->content,i,j,value); 120 127 } 121 128 … … 150 157 151 158 Matrix &Matrix::operator*=(const double factor){ 152 gsl_matrix_scale(content , factor);159 gsl_matrix_scale(content->content, factor); 153 160 return *this; 154 161 } … … 197 204 Vector operator*(const Matrix &mat,const Vector &vec){ 198 205 gsl_vector *res = gsl_vector_calloc(NDIM); 199 gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content , vec.content->content, 0.0, res);206 gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content->content, vec.content->content, 0.0, res); 200 207 VectorContent *content = new VectorContent(); 201 208 content->content = res; -
src/Matrix.hpp
raafd77 rfee079 9 9 #define MATRIX_HPP_ 10 10 11 #include <gsl/gsl_matrix.h>12 11 #include <iosfwd> 13 12 #include "defs.hpp" … … 18 17 19 18 class Vector; 19 class MatrixContent; 20 20 21 21 class Matrix … … 92 92 93 93 private: 94 Matrix( gsl_matrix*);95 gsl_matrix*content;94 Matrix(MatrixContent*); 95 MatrixContent *content; 96 96 }; 97 97
Note:
See TracChangeset
for help on using the changeset viewer.