/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * VectorContent.cpp * * Created on: Nov 15, 2010 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "Helpers/MemDebug.hpp" #include #include #include #include "Helpers/Assert.hpp" #include "LinearAlgebra/Vector.hpp" #include "LinearAlgebra/VectorContent.hpp" /** Constructor of class VectorContent. * Allocates GSL structures * \param _dim number of components */ VectorContent::VectorContent(size_t _dim) : dimension(_dim) { content = gsl_vector_calloc(dimension); } /** Constructor of class VectorContent. * We need this BaseCase for the VectorContentView class. * There no content should be allocated, as it is just a view with an internal * gsl_vector_view. Hence, BaseCase is just dummy class to give the constructor * a unique signature. * \param BaseCase */ VectorContent::VectorContent(BaseCase) {} /** Copy constructor of class VectorContent. * Allocates GSL structures and copies components from \a *src. * \param *src source vector */ VectorContent::VectorContent(const VectorContent * const src) : dimension(src->dimension) { content = gsl_vector_alloc(dimension); gsl_vector_memcpy (content, src->content); }; /** Copy constructor of class VectorContent. * Allocates GSL structures and copies components from \a *src. * \param *src source vector */ VectorContent::VectorContent(const VectorContent & src) : dimension(src.dimension) { content = gsl_vector_alloc(dimension); gsl_vector_memcpy (content, src.content); }; /** Destructor of class VectorContent. * Frees GSL structures */ VectorContent::~VectorContent() { if(content != NULL){ gsl_vector_free(content); content = NULL; } } /* ============================ Accessing =============================== */ /** Accessor for manipulating component (i). * \param i component number * \return reference to component (i) */ double &VectorContent::at(size_t i) { ASSERT((i>=0) && (i=0) && (icontent); } /** This function sets all the elements of the vector to zero. */ void VectorContent::setZero() { gsl_vector_set_zero (content); }; /** This function makes a basis vector by setting all the elements of the vector to zero except for the i-th element which is set to one. * \param i i-th component to set to unity (all other to zero) * \return vector set */ int VectorContent::setBasis(size_t i) { return gsl_vector_set_basis (content, i); }; /* ====================== Exchanging elements ============================ */ /** This function exchanges the \a i-th and \a j-th elements of the vector in-place. * \param i i-th element to swap with ... * \param j ... j-th element to swap against */ int VectorContent::SwapElements(size_t i, size_t j) { return gsl_vector_swap_elements (content, i, j); }; /** This function reverses the order of the elements of the vector. */ int VectorContent::Reverse() { return gsl_vector_reverse (content); }; /* ========================== Operators =============================== */ /** Accessor for manipulating component (i). * \param i component number * \return reference to component (i) */ double &VectorContent::operator[](size_t i) { ASSERT((i>=0) && (i=0) && (i