PSCF v1.1
IntVector.cpp
1/*
2* Util Package - C++ Utilities for Scientific Computation
3*
4* Copyright 2010 - 2017, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "IntVector.h"
9#include "Dimension.h"
10#include <util/global.h>
11
12#ifdef UTIL_MPI
13#include <util/mpi/MpiStructBuilder.h>
14#endif
15
16namespace Util
17{
18
19 // Define static Zero vector
20 const IntVector IntVector::Zero = IntVector(0);
21
22 // Equality operators
23
24 bool operator==(const IntVector& v1, const IntVector& v2)
25 {
26 for (int i=0; i < Dimension; ++i) {
27 if (v1.elem_[i] != v2.elem_[i]) {
28 return false;
29 }
30 }
31 return true;
32 }
33
34
35 bool operator==(const IntVector& v1, const int* v2)
36 {
37 for (int i=0; i < Dimension; ++i) {
38 if (v1.elem_[i] != v2[i]) {
39 return false;
40 }
41 }
42 return true;
43 }
44
45 bool operator==(const int* v1, const IntVector& v2)
46 { return (v2 == v1); }
47
48 // Inequality operators
49
50 bool operator!=(const IntVector& v1, const IntVector& v2)
51 { return !(v1 == v2); }
52
53
54 bool operator!=(const IntVector& v1, const int* v2)
55 { return !(v1 == v2); }
56
57
58 bool operator!=(const int* v1, const IntVector& v2)
59 { return !(v2 == v1); }
60
61 /*
62 * Input a IntVector from an istream, without line breaks.
63 */
64 std::istream& operator>>(std::istream& in, IntVector &vector)
65 {
66 for (int i=0; i < Dimension; ++i) {
67 in >> vector.elem_[i];
68 }
69 return in;
70 }
71
72 /*
73 * Output a IntVector to an ostream, without line breaks.
74 */
75 std::ostream& operator<<(std::ostream& out, const IntVector &vector)
76 {
77 for (int i=0; i < Dimension; ++i) {
78 out.width(IntVector::Width);
79 out << vector.elem_[i];
80 }
81 return out;
82 }
83
84 #ifdef UTIL_MPI
85 // Initialize MpiTraits<IntVector>
86 MPI::Datatype MpiTraits<IntVector>::type = MPI::BYTE;
88
89 /*
90 * Commit MPI Datatype.
91 */
93 {
95 MpiStructBuilder builder;
96 IntVector vector;
97 builder.setBase(&vector);
98 builder.addMember(&vector[0], MPI::INT);
99 builder.addMember(&vector[1], MPI::INT);
100 builder.addMember(&vector[2], MPI::INT);
103 }
104 }
105 #endif
106
107 /*
108 * This static method exists to guarantee initialization of static
109 * constants and variables defined in this file. Call it somewhere
110 * in the program to guarantee that the contents of this file will
111 * be linked, rather than optimized away. It may only be called once.
112 */
114 {
115 static int nCall = 0;
116 ++nCall;
117 }
118
119}
An IntVector is an integer Cartesian vector.
Definition: IntVector.h:74
static const IntVector Zero
Zero IntVector.
Definition: IntVector.h:364
static void initStatic()
Initialize static IntVector::Zero.
Definition: IntVector.cpp:113
static void commitMpiType()
Commit MPI datatype MpiTraits<IntVector>::type.
Definition: IntVector.cpp:92
A MpiStructBuilder objects is used to create an MPI Struct datatype.
void addMember(void *memberAddress, MPI::Datatype type, int count=1)
Add a new member variable to the type map.
void setBase(void *objectAddress)
Set address of an class instance.
void commit(MPI::Datatype &newType)
Build and commit a user-defined MPI Struct datatype.
Default MpiTraits class.
Definition: MpiTraits.h:40
File containing preprocessor macros for error handling.
const int Dimension
Dimensionality of space.
Definition: Dimension.h:19
Utility classes for scientific computation.
Definition: accumulators.mod:1
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