Changeset 3dbb9d
- Timestamp:
- Jul 7, 2010, 1:11:46 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:
- 0eb2dc
- Parents:
- 8e17d6
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Matrix.cpp
r8e17d6 r3dbb9d 25 25 content = new MatrixContent(); 26 26 content->content = gsl_matrix_calloc(NDIM, NDIM); 27 createViews(); 27 28 } 28 29 … … 41 42 set(1,2, src[7]); 42 43 set(2,2, src[8]); 44 createViews(); 43 45 } 44 46 … … 47 49 content->content = gsl_matrix_alloc(NDIM, NDIM); 48 50 gsl_matrix_memcpy(content->content,src.content->content); 51 createViews(); 49 52 } 50 53 51 54 Matrix::Matrix(MatrixContent* _content) : 52 55 content(_content) 53 {} 56 { 57 createViews(); 58 } 54 59 55 60 Matrix::~Matrix() 56 61 { 62 // delete all views 63 for(int i=NDIM;i--;){ 64 delete rows_ptr[i]; 65 } 66 for(int i=NDIM;i--;){ 67 delete columns_ptr[i]; 68 } 69 delete diagonal_ptr; 57 70 gsl_matrix_free(content->content); 58 71 delete content; 59 72 } 60 73 74 void Matrix::createViews(){ 75 // create row views 76 for(int i=NDIM;i--;){ 77 VectorContent *rowContent = new VectorViewContent(gsl_matrix_row(content->content,i)); 78 rows_ptr[i] = new Vector(rowContent); 79 } 80 // create column views 81 for(int i=NDIM;i--;){ 82 VectorContent *columnContent = new VectorViewContent(gsl_matrix_column(content->content,i)); 83 columns_ptr[i] = new Vector(columnContent); 84 } 85 // create diagonal view 86 VectorContent *diagonalContent = new VectorViewContent(gsl_matrix_diagonal(content->content)); 87 diagonal_ptr = new Vector(diagonalContent); 88 } 89 61 90 void Matrix::one(){ 62 gsl_matrix_free(content->content);63 content->content = gsl_matrix_calloc(NDIM, NDIM);64 for(int i = NDIM;i--;){65 set(i,i,1.);91 for(int i=NDIM;i--;){ 92 for(int j=NDIM;j--;){ 93 set(i,j,i==j); 94 } 66 95 } 67 96 } … … 119 148 ASSERT(j>=0&&j<NDIM,"Index j for Matrix access out of range"); 120 149 return gsl_matrix_get(content->content, i, j); 150 } 151 152 Vector &Matrix::row(size_t i){ 153 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); 154 return *rows_ptr[i]; 155 } 156 157 const Vector &Matrix::row(size_t i) const{ 158 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); 159 return *rows_ptr[i]; 160 } 161 162 Vector &Matrix::column(size_t i){ 163 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); 164 return *columns_ptr[i]; 165 } 166 167 const Vector &Matrix::column(size_t i) const{ 168 ASSERT(i>=0&&i<NDIM,"Index i for Matrix access out of range"); 169 return *columns_ptr[i]; 170 } 171 172 Vector &Matrix::diagonal(){ 173 return *diagonal_ptr; 174 } 175 176 const Vector &Matrix::diagonal() const{ 177 return *diagonal_ptr; 121 178 } 122 179 -
src/Matrix.hpp
r8e17d6 r3dbb9d 67 67 68 68 /** 69 * get the ith row of the matrix as a vector 70 */ 71 Vector &row(size_t); 72 const Vector &row(size_t) const; 73 74 /** 75 * get the ith column of the matrix as a vector 76 */ 77 Vector &column(size_t); 78 const Vector &column(size_t) const; 79 80 /** 81 * get the diagonal of the matrix as a vector 82 */ 83 Vector &diagonal(); 84 const Vector &diagonal() const; 85 86 /** 69 87 * Calculate the determinant of the matrix 70 88 */ … … 93 111 private: 94 112 Matrix(MatrixContent*); 113 void createViews(); 95 114 MatrixContent *content; 96 115 // we keep around some Vector views of the matrix, to return references 97 Vector* rows [NDIM];98 Vector* columns [NDIM];99 Vector* diagonal ;116 Vector* rows_ptr[NDIM]; 117 Vector* columns_ptr[NDIM]; 118 Vector* diagonal_ptr; 100 119 }; 101 120 -
src/VectorContent.hpp
r8e17d6 r3dbb9d 28 28 } 29 29 virtual ~VectorContent(){ 30 gsl_vector_free(content); 31 content = 0; 30 if(content){ 31 gsl_vector_free(content); 32 content = 0; 33 } 32 34 } 33 35 gsl_vector *content; … … 41 43 content=&view.vector; 42 44 } 43 virtual ~VectorViewContent(){} 45 virtual ~VectorViewContent(){ 46 content=0; 47 } 44 48 gsl_vector_view view; 45 49 };
Note:
See TracChangeset
for help on using the changeset viewer.