Ignore:
Timestamp:
Aug 28, 2010, 3:21:11 AM (15 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:
a6e6b5, f8982c
Parents:
2ad482 (diff), fd4905 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Frederik Heber <heber@…> (08/28/10 03:17:48)
git-committer:
Frederik Heber <heber@…> (08/28/10 03:21:11)
Message:

Merge branch 'StructureRefactoring' into Shapes

Conflicts:

src/Box.cpp
src/Box.hpp
src/Descriptors/AtomShapeDescriptor.cpp
src/Descriptors/AtomShapeDescriptor.hpp
src/Descriptors/AtomShapeDescriptor_impl.hpp
src/LinearAlgebra/Line.cpp
src/LinearAlgebra/Line.hpp
src/LinearAlgebra/Matrix.cpp
src/LinearAlgebra/Matrix.hpp
src/Makefile.am
src/Shapes/BaseShapes.cpp
src/Shapes/BaseShapes_impl.hpp
src/Shapes/Shape.cpp
src/Shapes/Shape.hpp
src/Shapes/ShapeOps_impl.hpp
src/Shapes/Shape_impl.hpp
src/unittests/ShapeUnittest.cpp

File:
1 moved

Legend:

Unmodified
Added
Removed
  • src/LinearAlgebra/Matrix.cpp

    r2ad482 r6c438f  
     1/*
     2 * Project: MoleCuilder
     3 * Description: creates and alters molecular systems
     4 * Copyright (C)  2010 University of Bonn. All rights reserved.
     5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
     6 */
     7
    18/*
    29 * Matrix.cpp
     
    613 */
    714
    8 #include "Matrix.hpp"
     15// include config.h
     16#ifdef HAVE_CONFIG_H
     17#include <config.h>
     18#endif
     19
     20#include "Helpers/MemDebug.hpp"
     21
     22#include "LinearAlgebra/Matrix.hpp"
    923#include "Helpers/Assert.hpp"
    1024#include "Exceptions/NotInvertibleException.hpp"
    1125#include "Helpers/fast_functions.hpp"
    1226#include "Helpers/Assert.hpp"
    13 #include "vector.hpp"
     27#include "LinearAlgebra/Vector.hpp"
    1428#include "VectorContent.hpp"
    1529#include "MatrixContent.hpp"
    1630
    1731#include <gsl/gsl_blas.h>
     32#include <gsl/gsl_eigen.h>
     33#include <gsl/gsl_matrix.h>
     34#include <gsl/gsl_multimin.h>
     35#include <gsl/gsl_vector.h>
    1836#include <cmath>
    1937#include <iostream>
     
    96114}
    97115
     116void Matrix::zero(){
     117  for(int i=NDIM;i--;){
     118    for(int j=NDIM;j--;){
     119      set(i,j,0.);
     120    }
     121  }
     122}
     123
     124void Matrix::rotation(const double x, const double y, const double z)
     125{
     126  set(0,0, cos(y)*cos(z));
     127  set(0,1, cos(z)*sin(x)*sin(y) - cos(x)*sin(z));
     128  set(0,2, cos(x)*cos(z)*sin(y) + sin(x) * sin(z));
     129  set(1,0, cos(y)*sin(z));
     130  set(1,1, cos(x)*cos(z) + sin(x)*sin(y)*sin(z));
     131  set(1,2, -cos(z)*sin(x) + cos(x)*sin(y)*sin(z));
     132  set(2,0, -sin(y));
     133  set(2,1, cos(y)*sin(x));
     134  set(2,2, cos(x)*cos(y));
     135}
     136
    98137Matrix &Matrix::operator=(const Matrix &src){
    99138  if(&src!=this){
     
    103142}
    104143
    105 Matrix &Matrix::operator+=(const Matrix &rhs){
     144const Matrix &Matrix::operator+=(const Matrix &rhs){
    106145  gsl_matrix_add(content->content, rhs.content->content);
    107146  return *this;
    108147}
    109148
    110 Matrix &Matrix::operator-=(const Matrix &rhs){
     149const Matrix &Matrix::operator-=(const Matrix &rhs){
    111150  gsl_matrix_sub(content->content, rhs.content->content);
    112151  return *this;
    113152}
    114153
    115 Matrix &Matrix::operator*=(const Matrix &rhs){
     154const Matrix &Matrix::operator*=(const Matrix &rhs){
    116155  (*this) = (*this)*rhs;
    117156  return *this;
    118157}
    119158
    120 Matrix Matrix::operator+(const Matrix &rhs) const{
     159const Matrix Matrix::operator+(const Matrix &rhs) const{
    121160  Matrix tmp = *this;
    122161  tmp+=rhs;
     
    124163}
    125164
    126 Matrix Matrix::operator-(const Matrix &rhs) const{
     165const Matrix Matrix::operator-(const Matrix &rhs) const{
    127166  Matrix tmp = *this;
    128167  tmp-=rhs;
     
    130169}
    131170
    132 Matrix Matrix::operator*(const Matrix &rhs) const{
     171const Matrix Matrix::operator*(const Matrix &rhs) const{
    133172  gsl_matrix *res = gsl_matrix_alloc(NDIM, NDIM);
    134173  gsl_blas_dgemm(CblasNoTrans, CblasNoTrans, 1.0, content->content, rhs.content->content, 0.0, res);
     
    192231       - at(2,2)*at(1,0)*at(0,1);
    193232}
     233
    194234
    195235Matrix Matrix::invert() const{
     
    215255Matrix Matrix::transpose() const{
    216256  MatrixContent *newContent = new MatrixContent();
     257  newContent->content = gsl_matrix_alloc(NDIM, NDIM);
    217258  gsl_matrix_transpose_memcpy(newContent->content, content->content);
    218259  Matrix res = Matrix(newContent);
     
    220261}
    221262
    222 Matrix &Matrix::operator*=(const double factor){
     263Matrix &Matrix::transpose()
     264{
     265  double tmp;
     266  for (int i=0;i<NDIM;i++)
     267    for (int j=i+1;j<NDIM;j++) {
     268      tmp = at(j,i);
     269      at(j,i) = at(i,j);
     270      at(i,j) = tmp;
     271    }
     272  return *this;
     273}
     274
     275
     276Vector Matrix::transformToEigenbasis()
     277{
     278  gsl_eigen_symmv_workspace *T = gsl_eigen_symmv_alloc(NDIM);
     279  gsl_vector *eval = gsl_vector_alloc(NDIM);
     280  gsl_matrix *evec = gsl_matrix_alloc(NDIM, NDIM);
     281  gsl_eigen_symmv(content->content, eval, evec, T);
     282  gsl_eigen_symmv_free(T);
     283  gsl_matrix_memcpy(content->content, evec);
     284  gsl_matrix_free(evec);
     285  Vector evalues(gsl_vector_get(eval,0), gsl_vector_get(eval,1), gsl_vector_get(eval,2));
     286  gsl_vector_free(eval);
     287  return evalues;
     288}
     289
     290const Matrix &Matrix::operator*=(const double factor){
    223291  gsl_matrix_scale(content->content, factor);
    224292  return *this;
    225293}
    226294
    227 Matrix operator*(const double factor,const Matrix& mat){
     295const Matrix operator*(const double factor,const Matrix& mat){
    228296  Matrix tmp = mat;
    229297  tmp*=factor;
     
    231299}
    232300
    233 Matrix operator*(const Matrix &mat,const double factor){
     301const Matrix operator*(const Matrix &mat,const double factor){
    234302  return factor*mat;
    235303}
     
    278346
    279347Vector operator*(const Matrix &mat,const Vector &vec){
    280   gsl_vector *res = gsl_vector_calloc(NDIM);
    281   gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content->content, vec.content->content, 0.0, res);
    282   VectorContent *content = new VectorContent();
    283   content->content = res;
    284   return Vector(content);
     348  Vector res;
     349  gsl_blas_dgemv( CblasNoTrans, 1.0, mat.content->content, vec.content->content, 0.0, res.content->content);
     350  return res;
    285351}
    286352
Note: See TracChangeset for help on using the changeset viewer.