source: src/LinearAlgebra/VectorContent.hpp@ ad011c

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 ad011c was 14cce6, checked in by Frederik Heber <heber@…>, 14 years ago

New getter for VectorContent::dimension.

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[ce3d2b]1/*
2 * VectorContent.hpp
3 *
4 * Created on: Jul 2, 2010
5 * Author: crueger
6 */
7
8#ifndef VECTORCONTENT_HPP_
9#define VECTORCONTENT_HPP_
10
11/**
12 * !file
13 * The way GSL works does not allow for forward definitions of the structures.
14 * Because of this the pointer to the gsl_vector struct is wrapped inside another
[9d5ddf]15 * (dumb) object that allows for forward definitions.
[bc8a41]16 *
17 * DO NOT USE OUTSIDE OF VECTOR UNLESS YOU ABSOLUTELY HAVE TO AND KNOW WHAT YOU ARE DOING.
[ce3d2b]18 */
19
[bbf1bd]20#include <iosfwd>
21
[ce3d2b]22#include <gsl/gsl_vector.h>
23
[3da2fb]24#include "LinearAlgebra/MatrixVector_ops.hpp"
25
[bbf1bd]26class Vector;
[3da2fb]27class MatrixContent;
[bbf1bd]28
29/** Dummy structure to create a unique signature.
30 *
31 */
[8e9ce1]32struct VectorBaseCase{};
[8e17d6]33
[bbf1bd]34class VectorContent{
35 friend std::ostream & operator<< (std::ostream& ost, const VectorContent &m);
36 friend VectorContent const operator*(const VectorContent& a, const double m);
37 friend VectorContent const operator*(const double m, const VectorContent& a);
38 friend VectorContent const operator+(const VectorContent& a, const VectorContent& b);
39 friend VectorContent const operator-(const VectorContent& a, const VectorContent& b);
[8e17d6]40
[3da2fb]41 // matrix vector products
42 friend VectorContent const operator*(const VectorContent& vec, const MatrixContent& mat);
43 friend VectorContent const operator*(const MatrixContent& mat, const VectorContent& vec);
44
[bbf1bd]45public:
46 explicit VectorContent(size_t _dim);
[8e9ce1]47 VectorContent(VectorBaseCase);
[bbf1bd]48 VectorContent(const VectorContent * const src);
49 VectorContent(const VectorContent & src);
[f453d2]50 VectorContent(gsl_vector * _src);
[bbf1bd]51 virtual ~VectorContent();
52
53 // Accessing
54 double &at(size_t m);
55 const double at(size_t m) const;
56 double & operator[](size_t i);
57 const double operator[](size_t i) const;
58 double *Pointer(size_t m) const;
59 const double *const_Pointer(size_t m) const;
60
61 // Assignment operator
62 VectorContent &operator=(const VectorContent& src);
63
64 // Initializing
65 void setFromDoubleArray(double * x);
66 void setFromVector(Vector &v);
67 void setValue(double x);
68 void setZero();
69 int setBasis(size_t m);
70
71 // Exchanging elements
72 int SwapElements(size_t i, size_t j);
73 int Reverse();
74
75 // checking state
76 bool IsZero() const;
77 bool IsOne() const;
78
79 // properties
[3dd9c7]80 //bool IsNormalTo(const VectorContent &normal) const;
81 //bool IsEqualTo(const VectorContent &a) const;
82
83 // Norms
84 double Norm() const;
85 double NormSquared() const;
86 void Normalize();
87 VectorContent getNormalized() const;
[bbf1bd]88
89 // properties relative to another VectorContent
90 double DistanceSquared(const VectorContent &y) const;
91 double ScalarProduct(const VectorContent &y) const;
92 double Angle(const VectorContent &y) const;
93
94 // operators
95 bool operator==(const VectorContent& b) const;
96 const VectorContent& operator+=(const VectorContent& b);
97 const VectorContent& operator-=(const VectorContent& b);
98 const VectorContent& operator*=(const double m);
[3dd9c7]99 const double operator*(const VectorContent& b) const;
[bbf1bd]100
[14cce6]101 const size_t getDimension() const;
102
[bbf1bd]103 size_t dimension;
[ce3d2b]104 gsl_vector *content;
[bbf1bd]105private:
[ce3d2b]106};
107
[bbf1bd]108std::ostream & operator << (std::ostream& ost, const VectorContent &m);
109VectorContent const operator*(const VectorContent& a, const double m);
110VectorContent const operator*(const double m, const VectorContent& a);
111VectorContent const operator+(const VectorContent& a, const VectorContent& b);
112VectorContent const operator-(const VectorContent& a, const VectorContent& b);
113
114/** Vector view.
115 * Extension of VectorContent to contain not a gsl_vector but only a view on a
116 * gsl_vector (or row/column in a gsl_matrix).
117 *
[8e9ce1]118 * We need the above VectorBaseCase here:
[bbf1bd]119 * content, i.e. the gsl_vector, must not be allocated, as it is just a view
[8e9ce1]120 * with an internal gsl_vector_view. Hence, VectorBaseCase is just dummy class
121 * to give the constructor a unique signature.
[bbf1bd]122 */
123struct VectorViewContent : public VectorContent
124{
[8e17d6]125 VectorViewContent(gsl_vector_view _view) :
[8e9ce1]126 VectorContent(VectorBaseCase()),
[8e17d6]127 view(_view)
128 {
[bbf1bd]129 dimension = _view.vector.size;
[8e17d6]130 content=&view.vector;
131 }
[bbf1bd]132 ~VectorViewContent(){
[3dbb9d]133 content=0;
134 }
[8e17d6]135 gsl_vector_view view;
136};
137
[ce3d2b]138#endif /* VECTORCONTENT_HPP_ */
Note: See TracBrowser for help on using the repository browser.