Changeset bbf1bd 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:
- 6e06bd, b4cf2b
- Parents:
- 5ada94
- git-author:
- Frederik Heber <heber@…> (11/15/10 20:00:30)
- git-committer:
- Frederik Heber <heber@…> (12/04/10 23:54:32)
- Location:
- src/LinearAlgebra
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
src/LinearAlgebra/Makefile.am
r5ada94 rbbf1bd 23 23 vector_ops.cpp \ 24 24 Vector.cpp \ 25 VectorContent.cpp \ 25 26 VectorInterface.cpp 26 27 -
src/LinearAlgebra/MatrixContent.cpp
r5ada94 rbbf1bd 475 475 Vector operator*(const MatrixContent &mat,const Vector &vec) 476 476 { 477 Vector res ;478 gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content, vec.content->content, 0.0, res .content->content);479 return res ;480 } 477 Vector result; 478 gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content, vec.content->content, 0.0, result.content->content); 479 return result; 480 } -
src/LinearAlgebra/MatrixContent.hpp
r5ada94 rbbf1bd 57 57 const double at(size_t i, size_t j) const; 58 58 void set(size_t i, size_t j, const double value); 59 60 // Initializing 59 61 void setFromDoubleArray(double * x); 62 void setIdentity(); 63 void setValue(double _value); 64 void setZero(); 60 65 61 66 // Exchanging elements … … 76 81 bool IsPositiveDefinite() const; 77 82 double Determinant() const; 78 79 // Initializing80 void setIdentity();81 void setZero();82 void setValue(double _value);83 83 84 84 // Operators -
src/LinearAlgebra/RealSpaceMatrix.cpp
r5ada94 rbbf1bd 87 87 VectorContent *rowContent = new VectorViewContent(gsl_matrix_row(content->content,i)); 88 88 rows_ptr[i] = new Vector(rowContent); 89 ASSERT(rowContent == NULL, "RealSpaceMatrix::createViews() - rowContent was not taken over as supposed to happen!"); 89 90 } 90 91 // create column views … … 92 93 VectorContent *columnContent = new VectorViewContent(gsl_matrix_column(content->content,i)); 93 94 columns_ptr[i] = new Vector(columnContent); 95 ASSERT(columnContent == NULL, "RealSpaceMatrix::createViews() - columnContent was not taken over as supposed to happen!"); 94 96 } 95 97 // create diagonal view 96 98 VectorContent *diagonalContent = new VectorViewContent(gsl_matrix_diagonal(content->content)); 97 99 diagonal_ptr = new Vector(diagonalContent); 100 ASSERT(diagonalContent == NULL, "RealSpaceMatrix::createViews() - diagonalContent was not taken over as supposed to happen!"); 98 101 } 99 102 -
src/LinearAlgebra/Vector.cpp
r5ada94 rbbf1bd 41 41 Vector::Vector() 42 42 { 43 content = new VectorContent(); 44 }; 45 46 /** 47 * Copy constructor 48 */ 49 43 content = new VectorContent((size_t) NDIM); 44 }; 45 46 /** Copy constructor. 47 * \param &src source Vector reference 48 */ 50 49 Vector::Vector(const Vector& src) 51 50 { 52 content = new VectorContent(); 53 gsl_vector_memcpy(content->content, src.content->content); 51 content = new VectorContent(*(src.content)); 54 52 } 55 53 56 54 /** Constructor of class vector. 55 * \param x1 first component 56 * \param x2 second component 57 * \param x3 third component 57 58 */ 58 59 Vector::Vector(const double x1, const double x2, const double x3) 59 60 { 60 content = new VectorContent( );61 gsl_vector_set(content->content,0,x1);62 gsl_vector_set(content->content,1,x2);63 gsl_vector_set(content->content,2,x3);61 content = new VectorContent((size_t) NDIM); 62 content->at(0) = x1; 63 content->at(1) = x2; 64 content->at(2) = x3; 64 65 }; 65 66 66 67 /** Constructor of class vector. 68 * \param x[3] three values to initialize Vector with 67 69 */ 68 70 Vector::Vector(const double x[3]) 69 71 { 70 content = new VectorContent(); 71 gsl_vector_set(content->content,0,x[0]); 72 gsl_vector_set(content->content,1,x[1]); 73 gsl_vector_set(content->content,2,x[2]); 74 }; 75 76 Vector::Vector(VectorContent *_content) : 77 content(_content) 78 {} 79 80 /** 81 * Assignment operator 72 content = new VectorContent((size_t) NDIM); 73 for (size_t i = NDIM; i--; ) 74 content->at(i) = x[i]; 75 }; 76 77 /** Copy constructor of class vector from VectorContent. 78 * \note This is destructive, i.e. we take over _content. 79 */ 80 Vector::Vector(VectorContent *&_content) : 81 content(_content) 82 { 83 _content = NULL; 84 } 85 86 /** Copy constructor of class vector from VectorContent. 87 * \note This is non-destructive, i.e. _content is copied. 88 */ 89 Vector::Vector(VectorContent &_content) 90 { 91 content = new VectorContent(_content); 92 } 93 94 /** Assignment operator. 95 * \param &src source vector to assign \a *this to 96 * \return reference to \a *this 82 97 */ 83 98 Vector& Vector::operator=(const Vector& src){ 84 99 // check for self assignment 85 100 if(&src!=this){ 86 gsl_vector_memcpy(content->content, src.content->content);101 *content = *(src.content); 87 102 } 88 103 return *this; … … 90 105 91 106 /** Desctructor of class vector. 107 * Vector::content is deleted. 92 108 */ 93 109 Vector::~Vector() { -
src/LinearAlgebra/Vector.hpp
r5ada94 rbbf1bd 33 33 class Vector : public Space{ 34 34 friend Vector operator*(const MatrixContent&,const Vector&); 35 friend class RealSpaceMatrix; 35 friend class RealSpaceMatrix; // needs access to Vector(VectorContent*&) due to views 36 36 public: 37 37 Vector(); … … 104 104 105 105 private: 106 Vector(VectorContent *); 106 explicit Vector(VectorContent *&); 107 explicit Vector(VectorContent &_content); 107 108 VectorContent *content; 108 109 -
src/LinearAlgebra/VectorContent.hpp
r5ada94 rbbf1bd 18 18 */ 19 19 20 #include <iosfwd> 21 20 22 #include <gsl/gsl_vector.h> 21 23 24 class Vector; 25 26 /** Dummy structure to create a unique signature. 27 * 28 */ 22 29 struct BaseCase{}; 23 30 24 struct VectorContent{ 25 VectorContent(){ 26 content = gsl_vector_calloc (NDIM); 27 } 28 VectorContent(BaseCase){ 31 class VectorContent{ 32 friend std::ostream & operator<< (std::ostream& ost, const VectorContent &m); 33 friend VectorContent const operator*(const VectorContent& a, const double m); 34 friend VectorContent const operator*(const double m, const VectorContent& a); 35 friend VectorContent const operator+(const VectorContent& a, const VectorContent& b); 36 friend VectorContent const operator-(const VectorContent& a, const VectorContent& b); 29 37 30 } 31 virtual ~VectorContent(){ 32 if(content){ 33 gsl_vector_free(content); 34 content = 0; 35 } 36 } 38 public: 39 explicit VectorContent(size_t _dim); 40 VectorContent(BaseCase); 41 VectorContent(const VectorContent * const src); 42 VectorContent(const VectorContent & src); 43 virtual ~VectorContent(); 44 45 // Accessing 46 double &at(size_t m); 47 const double at(size_t m) const; 48 double & operator[](size_t i); 49 const double operator[](size_t i) const; 50 double *Pointer(size_t m) const; 51 const double *const_Pointer(size_t m) const; 52 53 // Assignment operator 54 VectorContent &operator=(const VectorContent& src); 55 56 // Initializing 57 void setFromDoubleArray(double * x); 58 void setFromVector(Vector &v); 59 void setValue(double x); 60 void setZero(); 61 int setBasis(size_t m); 62 63 // Exchanging elements 64 int SwapElements(size_t i, size_t j); 65 int Reverse(); 66 67 // checking state 68 bool IsZero() const; 69 bool IsOne() const; 70 71 // properties 72 bool IsNormalTo(const Vector &normal) const; 73 bool IsEqualTo(const Vector &a) const; 74 75 // properties relative to another VectorContent 76 double DistanceSquared(const VectorContent &y) const; 77 double ScalarProduct(const VectorContent &y) const; 78 double Angle(const VectorContent &y) const; 79 80 // operators 81 bool operator==(const VectorContent& b) const; 82 const VectorContent& operator+=(const VectorContent& b); 83 const VectorContent& operator-=(const VectorContent& b); 84 const VectorContent& operator*=(const double m); 85 86 size_t dimension; 37 87 gsl_vector *content; 88 private: 38 89 }; 39 90 40 struct VectorViewContent : public VectorContent{ 91 std::ostream & operator << (std::ostream& ost, const VectorContent &m); 92 VectorContent const operator*(const VectorContent& a, const double m); 93 VectorContent const operator*(const double m, const VectorContent& a); 94 VectorContent const operator+(const VectorContent& a, const VectorContent& b); 95 VectorContent const operator-(const VectorContent& a, const VectorContent& b); 96 97 /** Vector view. 98 * Extension of VectorContent to contain not a gsl_vector but only a view on a 99 * gsl_vector (or row/column in a gsl_matrix). 100 * 101 * We need the above BaseCase here: 102 * content, i.e. the gsl_vector, must not be allocated, as it is just a view 103 * with an internal gsl_vector_view. Hence, BaseCase is just dummy class to 104 * give the constructor a unique signature. 105 */ 106 struct VectorViewContent : public VectorContent 107 { 41 108 VectorViewContent(gsl_vector_view _view) : 42 109 VectorContent(BaseCase()), 43 110 view(_view) 44 111 { 112 dimension = _view.vector.size; 45 113 content=&view.vector; 46 114 } 47 virtual~VectorViewContent(){115 ~VectorViewContent(){ 48 116 content=0; 49 117 } -
src/LinearAlgebra/linearsystemofequations.cpp
r5ada94 rbbf1bd 22 22 #include "defs.hpp" 23 23 #include "LinearAlgebra/MatrixContent.hpp" 24 #include "LinearAlgebra/ gslvector.hpp"24 #include "LinearAlgebra/VectorContent.hpp" 25 25 #include "LinearAlgebra/linearsystemofequations.hpp" 26 #include "Helpers/Assert.hpp" 26 27 #include "Helpers/logger.hpp" 27 28 #include "LinearAlgebra/Vector.hpp" 28 29 29 #include <cassert>30 30 #include <gsl/gsl_permutation.h> 31 31 … … 38 38 { 39 39 A = new MatrixContent(m, n); 40 b = new GSLVector(m);41 x = new GSLVector(n);40 b = new VectorContent(m); 41 x = new VectorContent(n); 42 42 }; 43 43 … … 58 58 bool LinearSystemOfEquations::SetSymmetric(bool symmetric) 59 59 { 60 assert (rows == columns &&"Rows and columns don't have equal size! Setting symmetric not possible.");60 ASSERT (rows == columns, "Rows and columns don't have equal size! Setting symmetric not possible."); 61 61 return (IsSymmetric = symmetric); 62 62 }; … … 67 67 void LinearSystemOfEquations::Setb(Vector *x) 68 68 { 69 assert ( columns == NDIM &&"Vector class is always three-dimensional, unlike this LEqS!");70 b-> SetFromVector(*x);69 ASSERT ( columns == NDIM, "Vector class is always three-dimensional, unlike this LEqS!"); 70 b->setFromVector(*x); 71 71 }; 72 72 … … 76 76 void LinearSystemOfEquations::Setb(double *x) 77 77 { 78 b-> SetFromDoubleArray(x);78 b->setFromDoubleArray(x); 79 79 }; 80 80 … … 98 98 // copy solution 99 99 for (size_t i=0;i<x->dimension;i++) { 100 array[i] = x-> Get(i);100 array[i] = x->at(i); 101 101 } 102 102 return status; … … 109 109 bool LinearSystemOfEquations::GetSolutionAsVector(Vector &v) 110 110 { 111 assert(rows == NDIM &&"Solution can only be returned as vector if number of columns is NDIM.");111 ASSERT (rows == NDIM, "Solution can only be returned as vector if number of columns is NDIM."); 112 112 bool status = Solve(); 113 113 114 114 // copy solution 115 115 for (size_t i=0;i<x->dimension;i++) 116 v[i] = x-> Get(i);116 v[i] = x->at(i); 117 117 return status; 118 118 }; … … 130 130 gsl_permutation * p = gsl_permutation_alloc (x->dimension); 131 131 gsl_linalg_LU_decomp (A->content, p, &s); 132 gsl_linalg_LU_solve (A->content, p, b-> vector, x->vector);132 gsl_linalg_LU_solve (A->content, p, b->content, x->content); 133 133 gsl_permutation_free (p); 134 134 } else { // use Householder 135 135 //MatrixContent *backup = new MatrixContent(rows,columns); 136 136 //*backup = *A; 137 gsl_linalg_HH_solve (A->content, b-> vector, x->vector);137 gsl_linalg_HH_solve (A->content, b->content, x->content); 138 138 //*A = *backup; 139 139 //delete(backup); -
src/LinearAlgebra/linearsystemofequations.hpp
r5ada94 rbbf1bd 22 22 class Vector; 23 23 class MatrixContent; 24 class GSLVector;24 class VectorContent; 25 25 26 26 /********************************************** declarations *******************************/ … … 44 44 bool GetSolutionAsVector(Vector &v); 45 45 46 GSLVector*b;47 GSLVector*x;46 VectorContent *b; 47 VectorContent *x; 48 48 MatrixContent *A; 49 49
Note:
See TracChangeset
for help on using the changeset viewer.