Changeset 3dbb9d


Ignore:
Timestamp:
Jul 7, 2010, 1:11:46 PM (14 years ago)
Author:
Tillmann Crueger <crueger@…>
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
Message:

Added methods to matrix to create vectors for rows and columns

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/Matrix.cpp

    r8e17d6 r3dbb9d  
    2525  content = new MatrixContent();
    2626  content->content = gsl_matrix_calloc(NDIM, NDIM);
     27  createViews();
    2728}
    2829
     
    4142  set(1,2, src[7]);
    4243  set(2,2, src[8]);
     44  createViews();
    4345}
    4446
     
    4749  content->content = gsl_matrix_alloc(NDIM, NDIM);
    4850  gsl_matrix_memcpy(content->content,src.content->content);
     51  createViews();
    4952}
    5053
    5154Matrix::Matrix(MatrixContent* _content) :
    5255  content(_content)
    53 {}
     56{
     57  createViews();
     58}
    5459
    5560Matrix::~Matrix()
    5661{
     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;
    5770  gsl_matrix_free(content->content);
    5871  delete content;
    5972}
    6073
     74void 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
    6190void 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    }
    6695  }
    6796}
     
    119148  ASSERT(j>=0&&j<NDIM,"Index j for Matrix access out of range");
    120149  return gsl_matrix_get(content->content, i, j);
     150}
     151
     152Vector &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
     157const 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
     162Vector &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
     167const 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
     172Vector &Matrix::diagonal(){
     173  return *diagonal_ptr;
     174}
     175
     176const Vector &Matrix::diagonal() const{
     177  return *diagonal_ptr;
    121178}
    122179
  • src/Matrix.hpp

    r8e17d6 r3dbb9d  
    6767
    6868  /**
     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  /**
    6987   * Calculate the determinant of the matrix
    7088   */
     
    93111private:
    94112  Matrix(MatrixContent*);
     113  void createViews();
    95114  MatrixContent *content;
    96115  // 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;
    100119};
    101120
  • src/VectorContent.hpp

    r8e17d6 r3dbb9d  
    2828  }
    2929  virtual ~VectorContent(){
    30     gsl_vector_free(content);
    31     content = 0;
     30    if(content){
     31      gsl_vector_free(content);
     32      content = 0;
     33    }
    3234  }
    3335  gsl_vector *content;
     
    4143    content=&view.vector;
    4244  }
    43   virtual ~VectorViewContent(){}
     45  virtual ~VectorViewContent(){
     46    content=0;
     47  }
    4448  gsl_vector_view view;
    4549};
Note: See TracChangeset for help on using the changeset viewer.