Changeset a439e5


Ignore:
Timestamp:
Aug 6, 2010, 12:40:05 PM (14 years ago)
Author:
Frederik Heber <heber@…>
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:
6e5084
Parents:
311d688
git-author:
Frederik Heber <heber@…> (08/05/10 14:27:34)
git-committer:
Frederik Heber <heber@…> (08/06/10 12:40:05)
Message:

New functions vor class Vector and Matrix.

Matrix:

  • transpose() (returning copy and on itself)
  • zero() (initialize to zero)
  • transformToEigenbasis() (columns are eigenvectors, return value has eigenvalues)

Vector:

Location:
src/LinearAlgebra
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/LinearAlgebra/Line.cpp

    r311d688 ra439e5  
    1111
    1212#include <cmath>
     13#include <iostream>
    1314
    1415#include "LinearAlgebra/Vector.hpp"
  • src/LinearAlgebra/Matrix.cpp

    r311d688 ra439e5  
    1616
    1717#include <gsl/gsl_blas.h>
     18#include <gsl/gsl_eigen.h>
     19#include <gsl/gsl_matrix.h>
     20#include <gsl/gsl_multimin.h>
     21#include <gsl/gsl_vector.h>
    1822#include <cmath>
    1923#include <iostream>
     
    9296    for(int j=NDIM;j--;){
    9397      set(i,j,i==j);
     98    }
     99  }
     100}
     101
     102void Matrix::zero(){
     103  for(int i=NDIM;i--;){
     104    for(int j=NDIM;j--;){
     105      set(i,j,0.);
    94106    }
    95107  }
     
    192204       - at(2,2)*at(1,0)*at(0,1);
    193205}
     206
     207Matrix Matrix::transpose() const
     208{
     209  Matrix copy(*this);
     210  copy.transpose();
     211  return copy;
     212}
     213
     214
     215void Matrix::transpose()
     216{
     217  double tmp;
     218  for (int i=0;i<NDIM;i++)
     219    for (int j=i+1;j<NDIM;j++) {
     220      tmp = at(j,i);
     221      at(i,j) = tmp;
     222      at(j,i) = tmp;
     223    }
     224}
     225
    194226
    195227Matrix Matrix::invert() const{
     
    213245}
    214246
     247Vector Matrix::transformToEigenbasis()
     248{
     249  gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM);
     250  gsl_vector *eval = gsl_vector_alloc(NDIM);
     251  gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM);
     252  gsl_eigen_symmv(content->content, eval, evec, T);
     253  gsl_eigen_symmv_free(T);
     254  gsl_matrix_memcpy(content->content, evec);
     255  Vector evalues(gsl_vector_get(eval,0), gsl_vector_get(eval,1), gsl_vector_get(eval,2));
     256  return evalues;
     257}
     258
    215259Matrix &Matrix::operator*=(const double factor){
    216260  gsl_matrix_scale(content->content, factor);
  • src/LinearAlgebra/Matrix.hpp

    r311d688 ra439e5  
    5151
    5252  /**
     53   * Set all matrix entries to zero.
     54   */
     55  void zero();
     56
     57  /**
    5358   * Access the matrix at index (i,j)
    5459   */
     
    95100   */
    96101  Matrix invert() const;
     102
     103  /**
     104   * Diagonalizes a matrix and sets its rows to the resulting eigenvalues.
     105   * The eigenvalues are returned as a vector.
     106   *
     107   * Rather costly, so use precomputation as often as possible.
     108   */
     109  Vector transformToEigenbasis();
     110
     111  /**
     112   * Calculate the transpose of the matrix.
     113   */
     114  Matrix transpose() const;
     115  void transpose();
    97116
    98117  // operators
  • src/LinearAlgebra/Vector.cpp

    r311d688 ra439e5  
    1717#include <iostream>
    1818#include <gsl/gsl_blas.h>
     19#include <gsl/gsl_vector.h>
    1920
    2021
     
    9293  return (sqrt(DistanceSquared(y)));
    9394};
     95
     96size_t Vector::GreatestComponent() const
     97{
     98  int greatest = 0;
     99  for (int i=1;i<NDIM;i++) {
     100    if (at(i) > at(greatest))
     101      greatest = i;
     102  }
     103  return greatest;
     104}
     105
     106size_t Vector::SmallestComponent() const
     107{
     108  int smallest = 0;
     109  for (int i=1;i<NDIM;i++) {
     110    if (at(i) < at(smallest))
     111      smallest = i;
     112  }
     113  return smallest;
     114}
     115
    94116
    95117Vector Vector::getClosestPoint(const Vector &point) const{
  • src/LinearAlgebra/Vector.hpp

    r311d688 ra439e5  
    6363  std::pair<Vector,Vector> partition(const Vector&) const;
    6464  std::pair<pointset,Vector> partition(const pointset&) const;
     65  size_t GreatestComponent() const;
     66  size_t SmallestComponent() const;
    6567
    6668  // Accessors ussually come in pairs... and sometimes even more than that
Note: See TracChangeset for help on using the changeset viewer.