Changeset b11d3b
- Timestamp:
- Mar 1, 2010, 8:28:00 PM (15 years ago)
- 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:
- 821907
- Parents:
- 775d133
- git-author:
- Frederik Heber <heber@…> (03/01/10 20:24:45)
- git-committer:
- Frederik Heber <heber@…> (03/01/10 20:28:00)
- Location:
- src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/gslvector.cpp ¶
r775d133 rb11d3b 6 6 */ 7 7 8 #include <cassert> 9 #include <cmath> 10 8 11 #include "gslvector.hpp" 12 #include "defs.hpp" 9 13 10 14 /** Constructor of class GSLVector. … … 27 31 }; 28 32 33 /** Copy constructor of class GSLVector. 34 * Allocates GSL structures and copies components from \a *src. 35 * \param *src source vector 36 */ 37 GSLVector::GSLVector(const GSLVector & src) : dimension(src.dimension) 38 { 39 vector = gsl_vector_alloc(dimension); 40 gsl_vector_memcpy (vector, src.vector); 41 }; 42 29 43 /** Destructor of class GSLVector. 30 44 * Frees GSL structures … … 33 47 { 34 48 gsl_vector_free(vector); 35 dimension = 0;36 49 }; 37 50 … … 52 65 * \return m-th element of vector 53 66 */ 54 double GSLVector::Get(size_t m) 67 double GSLVector::Get(size_t m) const 55 68 { 56 69 return gsl_vector_get (vector, m); … … 72 85 * \return pointer to \a m-th element 73 86 */ 74 double *GSLVector::Pointer(size_t m) 87 double *GSLVector::Pointer(size_t m) const 75 88 { 76 89 return gsl_vector_ptr (vector, m); … … 82 95 * \return const pointer to \a m-th element 83 96 */ 84 const double *GSLVector::const_Pointer(size_t m) 97 const double *GSLVector::const_Pointer(size_t m) const 85 98 { 86 99 return gsl_vector_const_ptr (vector, m); 100 }; 101 102 /** Returns the dimension of the vector. 103 * \return dimension of vector 104 */ 105 #ifdef HAVE_INLINE 106 inline 107 #endif 108 size_t GSLVector::GetDimension() const 109 { 110 return dimension; 87 111 }; 88 112 … … 128 152 return gsl_vector_reverse (vector); 129 153 }; 154 155 156 /* ========================== Operators =============================== */ 157 /** Compares GSLVector \a to GSLVector \a b component-wise. 158 * \param a base GSLVector 159 * \param b GSLVector components to add 160 * \return a == b 161 */ 162 bool operator==(const GSLVector& a, const GSLVector& b) 163 { 164 bool status = true; 165 assert(a.GetDimension() == b.GetDimension() && "Dimenions of GSLVectors to compare differ"); 166 for (size_t i=0;i<a.GetDimension();i++) 167 status = status && (fabs(a.Get(i) - b.Get(i)) < MYEPSILON); 168 return status; 169 }; 170 171 /** Sums GSLVector \a to this lhs component-wise. 172 * \param a base GSLVector 173 * \param b GSLVector components to add 174 * \return lhs + a 175 */ 176 const GSLVector& operator+=(GSLVector& a, const GSLVector& b) 177 { 178 assert(a.GetDimension() == b.GetDimension() && "Dimenions of GSLVectors to compare differ"); 179 for (size_t i=0;i<a.GetDimension();i++) 180 a.Set(i,a.Get(i)+b.Get(i)); 181 return a; 182 }; 183 184 /** Subtracts GSLVector \a from this lhs component-wise. 185 * \param a base GSLVector 186 * \param b GSLVector components to add 187 * \return lhs - a 188 */ 189 const GSLVector& operator-=(GSLVector& a, const GSLVector& b) 190 { 191 assert(a.GetDimension() == b.GetDimension() && "Dimenions of GSLVectors to compare differ"); 192 for (size_t i=0;i<a.GetDimension();i++) 193 a.Set(i,a.Get(i)-b.Get(i)); 194 return a; 195 }; 196 197 /** factor each component of \a a times a double \a m. 198 * \param a base GSLVector 199 * \param m factor 200 * \return lhs.Get(i) * m 201 */ 202 const GSLVector& operator*=(GSLVector& a, const double m) 203 { 204 for (size_t i=0;i<a.GetDimension();i++) 205 a.Set(i,a.Get(i)*m); 206 return a; 207 }; 208 209 /** Sums two GSLVectors \a and \b component-wise. 210 * \param a first GSLVector 211 * \param b second GSLVector 212 * \return a + b 213 */ 214 GSLVector const operator+(const GSLVector& a, const GSLVector& b) 215 { 216 GSLVector x(a); 217 for (size_t i=0;i<a.GetDimension();i++) 218 x.Set(i,a.Get(i)+b.Get(i)); 219 return x; 220 }; 221 222 /** Subtracts GSLVector \a from \b component-wise. 223 * \param a first GSLVector 224 * \param b second GSLVector 225 * \return a - b 226 */ 227 GSLVector const operator-(const GSLVector& a, const GSLVector& b) 228 { 229 assert(a.GetDimension() == b.GetDimension() && "Dimenions of GSLVectors to compare differ"); 230 GSLVector x(a); 231 for (size_t i=0;i<a.GetDimension();i++) 232 x.Set(i,a.Get(i)-b.Get(i)); 233 return x; 234 }; 235 236 /** Factors given GSLVector \a a times \a m. 237 * \param a GSLVector 238 * \param m factor 239 * \return m * a 240 */ 241 GSLVector const operator*(const GSLVector& a, const double m) 242 { 243 GSLVector x(a); 244 for (size_t i=0;i<a.GetDimension();i++) 245 x.Set(i,a.Get(i)*m); 246 return x; 247 }; 248 249 /** Factors given GSLVector \a a times \a m. 250 * \param m factor 251 * \param a GSLVector 252 * \return m * a 253 */ 254 GSLVector const operator*(const double m, const GSLVector& a ) 255 { 256 GSLVector x(a); 257 for (size_t i=0;i<a.GetDimension();i++) 258 x.Set(i,a.Get(i)*m); 259 return x; 260 }; 261 262 ostream& operator<<(ostream& ost, const GSLVector& m) 263 { 264 ost << "("; 265 for (size_t i=0;i<m.GetDimension();i++) { 266 ost << m.Get(i); 267 if (i != 2) 268 ost << ","; 269 } 270 ost << ")"; 271 return ost; 272 }; 273 274 /* ====================== Checking State ============================ */ 275 /** Checks whether vector has all components zero. 276 * @return true - vector is zero, false - vector is not 277 */ 278 bool GSLVector::IsZero() const 279 { 280 return (fabs(Get(0))+fabs(Get(1))+fabs(Get(2)) < MYEPSILON); 281 }; 282 283 /** Checks whether vector has length of 1. 284 * @return true - vector is normalized, false - vector is not 285 */ 286 bool GSLVector::IsOne() const 287 { 288 double NormValue = 0.; 289 for (size_t i=dimension;--i;) 290 NormValue += Get(i)*Get(i); 291 return (fabs(NormValue - 1.) < MYEPSILON); 292 }; 293 -
TabularUnified src/gslvector.hpp ¶
r775d133 rb11d3b 18 18 #endif 19 19 20 #include <iostream> 20 21 #include <gsl/gsl_vector.h> 21 22 … … 32 33 GSLVector(size_t m); 33 34 GSLVector(const GSLVector * const src); 35 GSLVector(const GSLVector & src); 34 36 ~GSLVector(); 35 37 36 38 // Accessing 37 39 void SetFromDoubleArray(double *x); 38 double Get(size_t m) ;40 double Get(size_t m) const; 39 41 void Set(size_t m, double x); 40 double *Pointer(size_t m); 41 const double *const_Pointer(size_t m); 42 double *Pointer(size_t m) const; 43 const double *const_Pointer(size_t m) const; 44 size_t GetDimension() const; 42 45 43 46 // Initializing … … 50 53 int Reverse(); 51 54 55 // checking state 56 bool IsZero() const; 57 bool IsOne() const; 58 52 59 private: 53 60 gsl_vector *vector; 54 61 55 size_t dimension;62 const size_t dimension; 56 63 }; 64 65 ostream & operator << (ostream& ost, const GSLVector &m); 66 bool operator==(const GSLVector& a, const GSLVector& b); 67 const GSLVector& operator+=(GSLVector& a, const GSLVector& b); 68 const GSLVector& operator-=(GSLVector& a, const GSLVector& b); 69 const GSLVector& operator*=(GSLVector& a, const double m); 70 GSLVector const operator*(const GSLVector& a, const double m); 71 GSLVector const operator*(const double m, const GSLVector& a); 72 GSLVector const operator+(const GSLVector& a, const GSLVector& b); 73 GSLVector const operator-(const GSLVector& a, const GSLVector& b); 74 57 75 58 76 -
TabularUnified src/unittests/gslvectorunittest.cpp ¶
r775d133 rb11d3b 115 115 116 116 117 /** UnitTest for operators. 118 */ 119 void GSLVectorTest::OperatorIsTest() 120 { 121 GSLVector zero(3); 122 GSLVector unit(3); 123 zero.SetZero(); 124 unit.SetZero(); 125 unit.Set(1,1.); 126 // summation and scaling 127 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() ); 128 CPPUNIT_ASSERT_EQUAL( false, zero.IsOne() ); 129 CPPUNIT_ASSERT_EQUAL( false, unit.IsZero() ); 130 CPPUNIT_ASSERT_EQUAL( true, zero.IsZero() ); 131 }; 132 133 /** UnitTest for operators. 134 */ 135 void GSLVectorTest::OperatorAlgebraTest() 136 { 137 GSLVector zero(3); 138 GSLVector unit(3); 139 zero.SetZero(); 140 unit.SetZero(); 141 unit.Set(1,1.); 142 // summation and scaling 143 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() ); 144 CPPUNIT_ASSERT_EQUAL( true, (zero+unit).IsOne() ); 145 CPPUNIT_ASSERT_EQUAL( true, (zero-unit).IsOne() ); 146 CPPUNIT_ASSERT_EQUAL( false, (zero-unit).IsZero() ); 147 CPPUNIT_ASSERT_EQUAL( true, (zero+zero).IsZero() ); 148 CPPUNIT_ASSERT_EQUAL( false, (unit*0.98).IsOne() ); 149 CPPUNIT_ASSERT_EQUAL( false, (0.98*unit).IsOne() ); 150 CPPUNIT_ASSERT_EQUAL( true, (unit*1.).IsOne() ); 151 CPPUNIT_ASSERT_EQUAL( true, (1.*unit).IsOne() ); 152 153 CPPUNIT_ASSERT_EQUAL( unit, (zero+unit) ); 154 CPPUNIT_ASSERT_EQUAL( zero, (zero+zero) ); 155 CPPUNIT_ASSERT_EQUAL( unit, (unit+zero) ); 156 157 unit += zero; 158 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() ); 159 unit *= 1.; 160 CPPUNIT_ASSERT_EQUAL( true, unit.IsOne() ); 161 }; 162 117 163 /********************************************** Main routine **************************************/ 118 164 -
TabularUnified src/unittests/gslvectorunittest.hpp ¶
r775d133 rb11d3b 22 22 CPPUNIT_TEST (CopyTest ); 23 23 CPPUNIT_TEST (ExchangeTest ); 24 CPPUNIT_TEST (OperatorAlgebraTest ); 25 CPPUNIT_TEST (OperatorIsTest ); 24 26 CPPUNIT_TEST_SUITE_END(); 25 27 … … 32 34 void CopyTest(); 33 35 void ExchangeTest(); 36 void OperatorIsTest(); 37 void OperatorAlgebraTest(); 34 38 35 39 private:
Note:
See TracChangeset
for help on using the changeset viewer.