Changeset 54a746 for src


Ignore:
Timestamp:
Aug 18, 2009, 8:48:06 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:
658efb
Parents:
093645
git-author:
Frederik Heber <heber@…> (08/18/09 08:38:46)
git-committer:
Frederik Heber <heber@…> (08/18/09 08:48:06)
Message:

Incorporation of Unit test on class Vector.

  • new file leastsquaremin.[ch]pp has least square minimisation which is otherwise unclean between classes molecules and Vector

Unit test (later tests rely on good results of earlier ones)

changes to class Vector:

  • Vector::IsNull() -> IsZero()
  • new function Vector::IsOne() similar to IsZero()
  • BUGFIX: Vector::IsNULL() (thx to unit test :)
  • Tesselation::getAngle() changed due to above rename
Location:
src
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/Makefile.am

    r093645 r54a746  
    1 SOURCE = atom.cpp bond.cpp boundary.cpp builder.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
    2 HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     1SOURCE = atom.cpp bond.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp moleculelist.cpp molecules.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
     2HEADER = atom.hpp bond.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp molecules.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
    33
    4 bin_PROGRAMS = molecuilder joiner analyzer
     4bin_PROGRAMS = molecuilder joiner analyzer VectorUnitTest
    55molecuilderdir = ${bindir}
    66molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
    7 molecuilder_SOURCES =  ${SOURCE} ${HEADER}
     7molecuilder_SOURCES =  ${SOURCE} builder.cpp  ${HEADER}
    88joiner_SOURCES = joiner.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp
    99analyzer_SOURCES = analyzer.cpp datacreator.cpp element.cpp helpers.cpp periodentafel.cpp parser.cpp verbose.cpp helpers.hpp periodentafel.hpp parser.hpp datacreator.hpp
    1010
     11TESTS = VectorUnitTest
     12check_PROGRAMS = $(TESTS)
     13VectorUnitTest_SOURCES = defs.hpp helpers.cpp helpers.hpp leastsquaremin.cpp leastsquaremin.hpp vectorunittest.cpp vectorunittest.hpp vector.cpp vector.hpp verbose.cpp verbose.hpp
     14VectorUnitTest_CXXFLAGS = $(CPPUNIT_CFLAGS)
     15VectorUnitTest_LDFLAGS = $(CPPUNIT_LIBS) -ldl
    1116
    1217EXTRA_DIST = ${molecuilder_DATA}
  • src/molecules.cpp

    r093645 r54a746  
    77#include "config.hpp"
    88#include "molecules.hpp"
    9 
    10 /************************************* Other Functions *************************************/
    11 
    12 /** Determines sum of squared distances of \a X to all \a **vectors.
    13  * \param *x reference vector
    14  * \param *params
    15  * \return sum of square distances
    16  */
    17 double LSQ (const gsl_vector * x, void * params)
    18 {
    19   double sum = 0.;
    20   struct LSQ_params *par = (struct LSQ_params *)params;
    21   Vector **vectors = par->vectors;
    22   int num = par->num;
    23 
    24   for (int i=num;i--;) {
    25     for(int j=NDIM;j--;)
    26       sum += (gsl_vector_get(x,j) - (vectors[i])->x[j])*(gsl_vector_get(x,j) - (vectors[i])->x[j]);
    27   }
    28 
    29   return sum;
    30 };
    319
    3210/************************************* Functions for class molecule *********************************/
  • src/molecules.hpp

    r093645 r54a746  
    2828#include "bond.hpp"
    2929#include "element.hpp"
     30#include "leastsquaremin.hpp"
    3031#include "linkedcell.hpp"
    3132#include "parser.hpp"
     
    8384
    8485
    85 // some algebraic matrix stuff
    86 #define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix
    87 #define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
    88 
    89 
    90 /** Parameter structure for least square minimsation.
    91  */
    92 struct LSQ_params {
    93   Vector **vectors;
    94   int num;
    95 };
    96 
    97 double LSQ(const gsl_vector * x, void * params);
    98 
    99 /** Parameter structure for least square minimsation.
    100  */
    101 struct lsq_params {
    102   gsl_vector *x;
    103   const molecule *mol;
    104   element *type;
    105 };
    10686
    10787#define MaxThermostats 6      //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
  • src/tesselation.cpp

    r093645 r54a746  
    29382938double getAngle(const Vector &point, const Vector &reference, const Vector OrthogonalVector)
    29392939{
    2940   if (reference.IsNull())
     2940  if (reference.IsZero())
    29412941    return M_PI;
    29422942
    29432943  // calculate both angles and correct with in-plane vector
    2944   if (point.IsNull())
     2944  if (point.IsZero())
    29452945    return M_PI;
    29462946  double phi = point.Angle(&reference);
  • src/vector.cpp

    r093645 r54a746  
    66
    77
    8 #include "molecules.hpp"
    9 
     8#include "defs.hpp"
     9#include "helpers.hpp"
     10#include "leastsquaremin.hpp"
     11#include "vector.hpp"
     12#include "verbose.hpp"
    1013
    1114/************************************ Functions for class vector ************************************/
     
    247250
    248251/** Calculates the intersection of the two lines that are both on the same plane.
    249  * Note that we do not check whether they are on the same plane.
     252 * Note that we do not check whether they are on the same plane. Vector is calculated with respecy to second line.
    250253 * \param *out output stream for debugging
    251254 * \param *Line1a first vector of first line
     
    276279  *out << Verbose(3) << "INFO: Normal of plane is " << *Normal << "." << endl;
    277280
    278   // create normal vector to one line
    279   Line.CopyVector(Line1b);
    280   Line.SubtractVector(Line1a);
    281   LineNormal.MakeNormalVector(&Line, Normal);
    282   *out << Verbose(3) << "INFO: Normal of first line is " << LineNormal << "." << endl;
    283 
    284281  // check if lines are parallel
    285282  helper.CopyVector(Line2b);
    286283  helper.SubtractVector(Line2a);
    287   if (fabs(helper.ScalarProduct(&LineNormal)) < MYEPSILON) {
     284  if (fabs(helper.ScalarProduct(Normal)) < MYEPSILON) {
    288285    *out << Verbose(1) << "Lines " << helper << " and " << Line << " are parallel, no cross point!" << endl;
    289286    result = false;
     
    291288    helper.CopyVector(Line2a);
    292289    helper.SubtractVector(Line1a);
    293     factor1 = helper.ScalarProduct(&LineNormal);
     290    factor1 = helper.ScalarProduct(Normal);
    294291    helper.CopyVector(Line2b);
    295292    helper.SubtractVector(Line1a);
    296     factor2 = helper.ScalarProduct(&LineNormal);
     293    factor2 = helper.ScalarProduct(Normal);
    297294    if (fabs(factor2) > MYEPSILON) {
    298295      CopyVector(Line2a);
     
    380377 * @return true - vector is zero, false - vector is not
    381378 */
    382 bool Vector::IsNull() const
    383 {
    384   return (fabs(x[0]+x[1]+x[2]) < MYEPSILON);
     379bool Vector::IsZero() const
     380{
     381  return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);
     382};
     383
     384/** Checks whether vector has length of 1.
     385 * @return true - vector is normalized, false - vector is not
     386 */
     387bool Vector::IsOne() const
     388{
     389  return (fabs(Norm() - 1.) < MYEPSILON);
    385390};
    386391
     
    437442  return a;
    438443};
     444
     445/** Subtracts vector \a from this lhs component-wise.
     446 * \param a base vector
     447 * \param b vector components to add
     448 * \return lhs - a
     449 */
     450Vector& operator-=(Vector& a, const Vector& b)
     451{
     452  a.SubtractVector(&b);
     453  return a;
     454};
     455
    439456/** factor each component of \a a times a double \a m.
    440457 * \param a base vector
     
    461478};
    462479
     480/** Subtracts vector \a from \b component-wise.
     481 * \param a first vector
     482 * \param b second vector
     483 * \return a - b
     484 */
     485Vector& operator-(const Vector& a, const Vector& b)
     486{
     487  Vector *x = new Vector;
     488  x->CopyVector(&a);
     489  x->SubtractVector(&b);
     490  return *x;
     491};
     492
    463493/** Factors given vector \a a times \a m.
    464494 * \param a vector
    465495 * \param m factor
    466  * \return a + b
     496 * \return m * a
    467497 */
    468498Vector& operator*(const Vector& a, const double m)
     499{
     500  Vector *x = new Vector;
     501  x->CopyVector(&a);
     502  x->Scale(m);
     503  return *x;
     504};
     505
     506/** Factors given vector \a a times \a m.
     507 * \param m factor
     508 * \param a vector
     509 * \return m * a
     510 */
     511Vector& operator*(const double m, const Vector& a )
    469512{
    470513  Vector *x = new Vector;
  • src/vector.hpp

    r093645 r54a746  
    55
    66#include "helpers.hpp"
     7
     8#include <gsl/gsl_vector.h>
     9#include <gsl/gsl_multimin.h>
    710
    811class Vector;
     
    2831  double NormSquared() const;
    2932  double Angle(const Vector *y) const;
    30   bool IsNull() const;
     33  bool IsZero() const;
     34  bool IsOne() const;
    3135
    3236  void AddVector(const Vector *y);
     
    6468
    6569ostream & operator << (ostream& ost, const Vector &m);
    66 //Vector& operator+=(Vector& a, const Vector& b);
    67 //Vector& operator*=(Vector& a, const double m);
    68 //Vector& operator*(const Vector& a, const double m);
    69 //Vector& operator+(const Vector& a, const Vector& b);
     70Vector& operator+=(Vector& a, const Vector& b);
     71Vector& operator-=(Vector& a, const Vector& b);
     72Vector& operator*=(Vector& a, const double m);
     73Vector& operator*(const Vector& a, const double m);
     74Vector& operator*(const double m, const Vector& a);
     75Vector& operator+(const Vector& a, const Vector& b);
     76Vector& operator-(const Vector& a, const Vector& b);
     77
     78// some algebraic matrix stuff
     79#define RDET3(a) ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3])  //!< hard-coded determinant of a 3x3 matrix
     80#define RDET2(a0,a1,a2,a3) ((a0)*(a3)-(a1)*(a2))                      //!< hard-coded determinant of a 2x2 matrix
     81
     82
    7083
    7184#endif /*VECTOR_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.