Ignore:
Timestamp:
Dec 4, 2010, 11:54:32 PM (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, Candidate_v1.7.0, 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:
c134d9
Parents:
cca9ef
git-author:
Frederik Heber <heber@…> (11/15/10 14:02:38)
git-committer:
Frederik Heber <heber@…> (12/04/10 23:54:32)
Message:

Made gslmatrix obsolete.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/LinearAlgebra/MatrixContent.cpp

    rcca9ef r0d4424  
    2525#include <gsl/gsl_blas.h>
    2626#include <gsl/gsl_eigen.h>
     27#include <gsl/gsl_linalg.h>
    2728#include <gsl/gsl_matrix.h>
    2829#include <gsl/gsl_multimin.h>
     
    131132    for(int j=columns;j--;){
    132133      set(i,j,0.);
     134    }
     135  }
     136}
     137
     138/** Set all matrix components to a given value.
     139 * \param _value value to set each component to
     140 */
     141void MatrixContent::setValue(double _value)
     142{
     143  for(int i=rows;i--;){
     144    for(int j=columns;j--;){
     145      set(i,j,_value);
    133146    }
    134147  }
     
    196209}
    197210
     211/* ========================== Accessing =============================== */
     212
    198213/** Accessor for manipulating component (i,j).
    199214 * \param i row number
     
    224239}
    225240
     241/** These functions return a pointer to the \a m-th element of a matrix.
     242 *  If \a m or \a n lies outside the allowed range of 0 to GSLMatrix::dimension-1 then the error handler is invoked and a null pointer is returned.
     243 * \param m index
     244 * \return pointer to \a m-th element
     245 */
     246double *MatrixContent::Pointer(size_t m, size_t n)
     247{
     248  return gsl_matrix_ptr (content, m, n);
     249};
     250
     251/** These functions return a constant pointer to the \a m-th element of a matrix.
     252 *  If \a m or \a n lies outside the allowed range of 0 to GSLMatrix::dimension-1 then the error handler is invoked and a null pointer is returned.
     253 * \param m index
     254 * \return const pointer to \a m-th element
     255 */
     256const double *MatrixContent::const_Pointer(size_t m, size_t n) const
     257{
     258  return gsl_matrix_const_ptr (content, m, n);
     259};
     260
     261/* ========================== Initializing =============================== */
     262
    226263/** Setter for component (i,j).
    227264 * \param i row numbr
     
    238275}
    239276
     277/** This function sets the matrix from a double array.
     278 * Creates a matrix view of the array and performs a memcopy.
     279 * \param *x array of values (no dimension check is performed)
     280 */
     281void MatrixContent::setFromDoubleArray(double * x)
     282{
     283  gsl_matrix_view m = gsl_matrix_view_array (x, rows, columns);
     284  gsl_matrix_memcpy (content, &m.matrix);
     285};
     286
     287/* ====================== Exchanging elements ============================ */
     288/** This function exchanges the \a i-th and \a j-th row of the matrix in-place.
     289 * \param i i-th row to swap with ...
     290 * \param j ... j-th row to swap against
     291 */
     292bool MatrixContent::SwapRows(size_t i, size_t j)
     293{
     294  return (gsl_matrix_swap_rows (content, i, j) == GSL_SUCCESS);
     295};
     296
     297/** This function exchanges the \a i-th and \a j-th column of the matrix in-place.
     298 * \param i i-th column to swap with ...
     299 * \param j ... j-th column to swap against
     300 */
     301bool MatrixContent::SwapColumns(size_t i, size_t j)
     302{
     303  return (gsl_matrix_swap_columns (content, i, j) == GSL_SUCCESS);
     304};
     305
     306/** This function exchanges the \a i-th row and \a j-th column of the matrix in-place.
     307 * The matrix must be square for this operation to be possible.
     308 * \param i i-th row to swap with ...
     309 * \param j ... j-th column to swap against
     310 */
     311bool MatrixContent::SwapRowColumn(size_t i, size_t j)
     312{
     313  assert (rows == columns && "The matrix must be square for swapping row against column to be possible.");
     314  return (gsl_matrix_swap_rowcol (content, i, j) == GSL_SUCCESS);
     315};
     316
    240317/** Return transposed matrix.
    241318 * \return new matrix that is transposed of this.
     
    244321{
    245322  std::cout << "const MatrixContent::transpose()." << std::endl;
    246   gsl_matrix *res = gsl_matrix_alloc(rows, columns);
     323  gsl_matrix *res = gsl_matrix_alloc(columns, rows);  // column and row dimensions exchanged!
    247324  gsl_matrix_transpose_memcpy(res, content);
    248325  MatrixContent newContent(res);
     
    286363  return eval;
    287364}
     365
     366/* ============================ Properties ============================== */
     367/** Checks whether matrix' elements are strictly null.
     368 * \return true - is null, false - else
     369 */
     370bool MatrixContent::IsNull() const
     371{
     372  return gsl_matrix_isnull (content);
     373};
     374
     375/** Checks whether matrix' elements are strictly positive.
     376 * \return true - is positive, false - else
     377 */
     378bool MatrixContent::IsPositive() const
     379{
     380  return gsl_matrix_ispos (content);
     381};
     382
     383/** Checks whether matrix' elements are strictly negative.
     384 * \return true - is negative, false - else
     385 */
     386bool MatrixContent::IsNegative() const
     387{
     388  return gsl_matrix_isneg (content);
     389};
     390
     391/** Checks whether matrix' elements are strictly non-negative.
     392 * \return true - is non-negative, false - else
     393 */
     394bool MatrixContent::IsNonNegative() const
     395{
     396  return gsl_matrix_isnonneg (content);
     397};
     398
     399/** This function performs a Cholesky decomposition to determine whether matrix is positive definite.
     400 * We check whether GSL returns GSL_EDOM as error, indicating that decomposition failed due to matrix not being positive-definite.
     401 * \return true - matrix is positive-definite, false - else
     402 */
     403bool MatrixContent::IsPositiveDefinite() const
     404{
     405  if (rows != columns)  // only possible for square matrices.
     406    return false;
     407  else
     408    return (gsl_linalg_cholesky_decomp (content) != GSL_EDOM);
     409};
     410
     411
     412/** Calculates the determinant of the matrix.
     413 * if matrix is square, uses LU decomposition.
     414 */
     415double MatrixContent::Determinant() const
     416{
     417  int signum = 0;
     418  assert (rows == columns && "Determinant can only be calculated for square matrices.");
     419  gsl_permutation *p = gsl_permutation_alloc(rows);
     420  gsl_linalg_LU_decomp(content, p, &signum);
     421  gsl_permutation_free(p);
     422  return gsl_linalg_LU_det(content, signum);
     423};
     424
     425/* ============================= Operators =============================== */
    288426
    289427/** Scalar multiplication operator.
Note: See TracChangeset for help on using the changeset viewer.