source: src/LinearAlgebra/VectorContent.hpp@ 0275ad

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 0275ad was 56f73b, checked in by Frederik Heber <heber@…>, 14 years ago

Added config.h also to all header files, code check test ascertain this in the future.

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