PSCF v1.1
RealVec.h
1#ifndef PSCF_REAL_VEC_H
2#define PSCF_REAL_VEC_H
3
4/*
5* PSCF - Polymer Self-Consistent Field Theory
6*
7* Copyright 2016 - 2022, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include "Vec.h"
12
13#include <iostream>
14#include <util/global.h>
15
16namespace Pscf
17{
18
26 template <int D, typename T = double>
27 class RealVec : public Vec<D, T>
28 {
29
30 public:
31
33
34
39 : Vec<D, T>()
40 {}
41
48 : Vec<D, T>(v)
49 {}
50
56 RealVec<D, T>(T const * v)
57 : Vec<D, T>(v)
58 {}
59
65 explicit RealVec<D, T>(T s)
66 : Vec<D, T>(s)
67 {}
68
70 static const int Width = 25;
71
73 static const int Precision = 17;
74
75 };
76
77 // Friend functions and operators
78
88 template <int D, typename T>
89 std::istream& operator >> (std::istream& in, RealVec<D, T> &vector)
90 {
91 for (int i = 0; i < D; ++i) {
92 in >> vector[i];
93 }
94 return in;
95 }
96
107 template <int D, typename T>
108 std::ostream& operator << (std::ostream& out, const RealVec<D, T> &vector)
109 {
110 for (int i = 0; i < D; ++i) {
111 out.setf(std::ios::scientific);
112 out.width(RealVec<D>::Width);
113 out.precision(RealVec<D>::Precision);
114 out << vector[i];
115 }
116 return out;
117 }
118
119 // Equality operators
120
121 #define PSCF_REALVEC_EPSILON 1.0E-8
122
123 template <int D, typename T>
124 bool operator==(const RealVec<D, T>& v1, const RealVec<D, T>& v2)
125 {
126 for (int i = 0; i < D; ++i) {
127 if ( fabs(v1[i] - v2[i]) > PSCF_REALVEC_EPSILON) {
128 return false;
129 }
130 }
131 return true;
132 }
133 #undef PSCF_REALVEC_EPSILON
134
135 template <int D, typename T>
136 bool operator!=(const RealVec<D, T>& v1, const RealVec<D, T>& v2)
137 { return !(v1 == v2); }
138
139}
140#endif
A RealVec<D, T> is D-component vector with elements of floating type T.
Definition: RealVec.h:28
static const int Width
Width of field per Cartesian coordinate in stream IO.
Definition: RealVec.h:70
static const int Precision
Precision in stream IO of RealVec<D, T> coordinates.
Definition: RealVec.h:73
A Vec<D, T><D,T> is a D-component vector with elements of type T.
Definition: Vec.h:66
File containing preprocessor macros for error handling.
C++ namespace for polymer self-consistent field theory (PSCF).
bool operator==(Polynomial< T > const &a, Polynomial< T > const &b)
Equality operator for polynomials.
Definition: Polynomial.h:675
std::istream & operator>>(std::istream &in, Pair< Data > &pair)
Input a Pair from an istream.
Definition: Pair.h:44
std::ostream & operator<<(std::ostream &out, const Pair< Data > &pair)
Output a Pair to an ostream, without line breaks.
Definition: Pair.h:57
bool operator!=(Polynomial< T > const &a, Polynomial< T > const &b)
Inequality operator for polynomials.
Definition: Polynomial.h:694