source: src/gslvector.cpp@ fc1b24

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
Last change on this file since fc1b24 was 2793ef, checked in by Frederik Heber <heber@…>, 15 years ago

FIX - GSLVector::Set() return value was double instead of void.

Signed-off-by: Frederik Heber <heber@tabletINS.(none)>

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*
2 * gslvector.cpp
3 *
4 * Created on: Jan 8, 2010
5 * Author: heber
6 */
7
8#include "gslvector.hpp"
9
10/** Constructor of class GSLVector.
11 * Allocates GSL structures
12 * \param m dimension of vector
13 */
14GSLVector::GSLVector(size_t m) : dimension(m)
15{
16 vector = gsl_vector_calloc(dimension);
17};
18
19/** Copy constructor of class GSLVector.
20 * Allocates GSL structures and copies components from \a *src.
21 * \param *src source vector
22 */
23GSLVector::GSLVector(const GSLVector * const src) : dimension(src->dimension)
24{
25 vector = gsl_vector_alloc(dimension);
26 gsl_vector_memcpy (vector, src->vector);
27};
28
29/** Destructor of class GSLVector.
30 * Frees GSL structures
31 */
32GSLVector::~GSLVector()
33{
34 gsl_vector_free(vector);
35 dimension = 0;
36};
37
38/* ============================ Accessing =============================== */
39/** This function sets the vector from a double array.
40 * Creates a vector view of the array and performs a memcopy.
41 * \param *x array of values (no dimension check is performed)
42 */
43void GSLVector::SetFromDoubleArray(double * x)
44{
45 gsl_vector_view m = gsl_vector_view_array (x, dimension);
46 gsl_vector_memcpy (vector, &m.vector);
47};
48
49/** This function returns the i-th element of a vector.
50 * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked and 0 is returned.
51 * \param m m-th element
52 * \return m-th element of vector
53 */
54double GSLVector::Get(size_t m)
55{
56 return gsl_vector_get (vector, m);
57};
58
59/** This function sets the value of the \a m -th element of a vector to \a x.
60 * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked.
61 * \param m-th element to set
62 * \param x value to set to
63 */
64void GSLVector::Set(size_t m, double x)
65{
66 gsl_vector_set (vector, m, x);
67};
68
69/** These functions return a pointer to the \a m-th element of a vector.
70 * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked and a null pointer is returned.
71 * \param m m-th element
72 * \return pointer to \a m-th element
73 */
74double *GSLVector::Pointer(size_t m)
75{
76 return gsl_vector_ptr (vector, m);
77};
78
79/** These functions return a constant pointer to the \a m-th element of a vector.
80 * If \a m lies outside the allowed range of 0 to GSLVector::dimension-1 then the error handler is invoked and a null pointer is returned.
81 * \param m m-th element
82 * \return const pointer to \a m-th element
83 */
84const double *GSLVector::const_Pointer(size_t m)
85{
86 return gsl_vector_const_ptr (vector, m);
87};
88
89/* ========================== Initializing =============================== */
90/** This function sets all the elements of the vector to the value \a x.
91 * \param *x
92 */
93void GSLVector::SetAll(double x)
94{
95 gsl_vector_set_all (vector, x);
96};
97
98/** This function sets all the elements of the vector to zero.
99 */
100void GSLVector::SetZero()
101{
102 gsl_vector_set_zero (vector);
103};
104
105/** 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.
106 * \param i i-th component to set to unity (all other to zero)
107 * \return vector set
108 */
109int GSLVector::SetBasis(size_t i)
110{
111 return gsl_vector_set_basis (vector, i);
112};
113
114/* ====================== Exchanging elements ============================ */
115/** This function exchanges the \a i-th and \a j-th elements of the vector in-place.
116 * \param i i-th element to swap with ...
117 * \param j ... j-th element to swap against
118 */
119int GSLVector::SwapElements(size_t i, size_t j)
120{
121 return gsl_vector_swap_elements (vector, i, j);
122};
123
124/** This function reverses the order of the elements of the vector.
125 */
126int GSLVector::Reverse()
127{
128 return gsl_vector_reverse (vector);
129};
Note: See TracBrowser for help on using the repository browser.