source: ThirdParty/LinearAlgebra/src/LinearAlgebra/VectorContent.hpp@ 4ecb2d

Action_Thermostats Add_AtomRandomPerturbation Add_RotateAroundBondAction Add_SelectAtomByNameAction Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChronosMutex Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids_IntegrationTest JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since 4ecb2d was 4ecb2d, checked in by Frederik Heber <heber@…>, 8 years ago

Moved LinearAlgebra sub-package into ThirdParty folder.

  • needed to adapt location of libLinearAlgebra.la in all Makefile.am's.
  • relinked m4 subfolder, relinked am_doxygen_include.am. Both point to those present in molecuilder parent folder.
  • adapted configure.ac's:
  • Property mode set to 100644
File size: 6.4 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#include "CodePatterns/Assert.hpp"
17
18#include <boost/serialization/array.hpp>
19#include <boost/serialization/split_member.hpp>
20
21/**
22 * !file
23 * The way GSL works does not allow for forward definitions of the structures.
24 * Because of this the pointer to the gsl_vector struct is wrapped inside another
25 * (dumb) object that allows for forward definitions.
26 *
27 * DO NOT USE OUTSIDE OF VECTOR UNLESS YOU ABSOLUTELY HAVE TO AND KNOW WHAT YOU ARE DOING.
28 */
29
30#include <iosfwd>
31
32#include <gsl/gsl_vector.h>
33
34#include "MatrixVector_ops.hpp"
35
36class Vector;
37class MatrixContent;
38struct VectorViewContent;
39namespace boost {
40 namespace serialization {
41 class access;
42 }
43}
44
45/** This class safely stores vector dimension away.
46 *
47 * This way we simulate const-ness of the dimension while still allowing
48 * serialization to modify them.
49 *
50 */
51struct VectorDimension {
52 friend struct VectorViewContent;
53public:
54 VectorDimension(size_t _dimension) : dimension(_dimension) {}
55
56 size_t getDimension() const {return dimension;}
57
58private:
59 void setDim(size_t _dimension) {dimension = _dimension;}
60
61 friend class boost::serialization::access;
62 // serialization (due to gsl_vector separate versions needed)
63 template<class Archive>
64 void serialize(Archive & ar, const unsigned int version)
65 {
66 ar & dimension;
67 }
68
69private:
70 size_t dimension; // store for internal purposes
71};
72
73/** Dummy structure to create a unique signature.
74 *
75 */
76struct VectorBaseCase{};
77
78class VectorContent : public VectorDimension
79{
80 friend std::ostream & operator<< (std::ostream& ost, const VectorContent &m);
81 friend VectorContent const operator*(const VectorContent& a, const double m);
82 friend VectorContent const operator*(const double m, const VectorContent& a);
83 friend VectorContent const operator+(const VectorContent& a, const VectorContent& b);
84 friend VectorContent const operator-(const VectorContent& a, const VectorContent& b);
85
86 // matrix vector products
87 friend VectorContent const operator*(const VectorContent& vec, const MatrixContent& mat);
88 friend VectorContent const operator*(const MatrixContent& mat, const VectorContent& vec);
89
90public:
91 explicit VectorContent(size_t _dim);
92 VectorContent(VectorBaseCase);
93 VectorContent(const VectorContent * const src);
94 VectorContent(const VectorContent & src);
95 VectorContent(gsl_vector * _src, bool _free_content_on_exit = false);
96 VectorContent(const size_t _dimension, std::istream &inputstream);
97 virtual ~VectorContent();
98
99 static size_t preparseVectorDimensions(std::istream &inputstream);
100
101 // Accessing
102 double &at(size_t m);
103 const double at(size_t m) const;
104 double & operator[](size_t i);
105 const double operator[](size_t i) const;
106 double *Pointer(size_t m) const;
107 const double *const_Pointer(size_t m) const;
108 void write(std::ostream &ost) const;
109
110 // Assignment operator
111 VectorContent &operator=(const VectorContent& src);
112
113 // Initializing
114 void setFromDoubleArray(double * x);
115 void setFromVector(Vector &v);
116 void setValue(double x);
117 void setZero();
118 int setBasis(size_t m);
119
120 // Exchanging elements
121 int SwapElements(size_t i, size_t j);
122 int Reverse();
123
124 // checking state
125 bool IsZero() const;
126 bool IsOne() const;
127
128 // properties
129 //bool IsNormalTo(const VectorContent &normal) const;
130 //bool IsEqualTo(const VectorContent &a) const;
131
132 // Norms
133 double Norm() const;
134 double NormSquared() const;
135 void Normalize();
136 VectorContent getNormalized() const;
137
138 // properties relative to another VectorContent
139 double DistanceSquared(const VectorContent &y) const;
140 double ScalarProduct(const VectorContent &y) const;
141 double Angle(const VectorContent &y) const;
142
143 // operators
144 bool operator==(const VectorContent& b) const;
145 const VectorContent& operator+=(const VectorContent& b);
146 const VectorContent& operator-=(const VectorContent& b);
147 const VectorContent& operator*=(const double m);
148 const double operator*(const VectorContent& b) const;
149
150 bool operator!=(const VectorContent &other) const {
151 return !(*this == other);
152 }
153
154private:
155 VectorContent();
156 friend class boost::serialization::access;
157 // serialization (due to gsl_vector separate versions needed)
158 template<class Archive>
159 void save(Archive & ar, const unsigned int version) const
160 {
161 ar & boost::serialization::base_object<VectorDimension>(*this);
162 ar & content->size;
163 ar & content->stride;
164 ar & boost::serialization::make_array<double>(content->data, content->size);
165 }
166 template<class Archive>
167 void load(Archive & ar, const unsigned int version)
168 {
169 ar & boost::serialization::base_object<VectorDimension>(*this);
170 content = gsl_vector_calloc(getDimension());
171 ar & content->size;
172 ASSERT(getDimension() == content->size,
173 "MatrixContent::load() - dimension mismatch: "
174 +toString(getDimension())+" != "+toString(content->size)+".");
175 ar & content->stride;
176 ar & boost::serialization::make_array<double>(content->data, content->size);
177 // this is always a copy, hence always free
178 free_content_on_exit = true;
179 }
180 BOOST_SERIALIZATION_SPLIT_MEMBER()
181
182public:
183 gsl_vector *content;
184private:
185 bool free_content_on_exit;
186};
187//BOOST_CLASS_EXPORT_GUID(VectorContent, "VectorContent")
188
189
190std::ostream & operator << (std::ostream& ost, const VectorContent &m);
191VectorContent const operator*(const VectorContent& a, const double m);
192VectorContent const operator*(const double m, const VectorContent& a);
193VectorContent const operator+(const VectorContent& a, const VectorContent& b);
194VectorContent const operator-(const VectorContent& a, const VectorContent& b);
195
196/** Vector view.
197 * Extension of VectorContent to contain not a gsl_vector but only a view on a
198 * gsl_vector (or row/column in a gsl_matrix).
199 *
200 * We need the above VectorBaseCase here:
201 * content, i.e. the gsl_vector, must not be allocated, as it is just a view
202 * with an internal gsl_vector_view. Hence, VectorBaseCase is just dummy class
203 * to give the constructor a unique signature.
204 */
205struct VectorViewContent : public VectorContent
206{
207 VectorViewContent(gsl_vector_view _view) :
208 VectorContent(VectorBaseCase()),
209 view(_view)
210 {
211 dimension = _view.vector.size;
212 content=&view.vector;
213 }
214 ~VectorViewContent(){
215 content=0;
216 }
217 gsl_vector_view view;
218};
219
220#endif /* VECTORCONTENT_HPP_ */
Note: See TracBrowser for help on using the repository browser.