1 // -*- C++ -*-
2 // SymTensor.h: Symmetric tensor objects (containing six doubles).
3 //
4 // Copyright (C) 2008 Jakob Schiotz and Center for Individual
5 // Nanoparticle Functionality, Department of Physics, Technical
6 // University of Denmark. Email: schiotz@fysik.dtu.dk
7 //
8 // This file is part of Asap version 3.
9 // Asap is released under the GNU Lesser Public License (LGPL) version 3.
10 // However, the parts of Asap distributed within the OpenKIM project
11 // (including this file) are also released under the Common Development
12 // and Distribution License (CDDL) version 1.0.
13 //
14 // This program is free software: you can redistribute it and/or
15 // modify it under the terms of the GNU Lesser General Public License
16 // version 3 as published by the Free Software Foundation. Permission
17 // to use other versions of the GNU Lesser General Public License may
18 // granted by Jakob Schiotz or the head of department of the
19 // Department of Physics, Technical University of Denmark, as
20 // described in section 14 of the GNU General Public License.
21 //
22 // This program is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 // GNU General Public License for more details.
26 //
27 // You should have received a copy of the GNU General Public License
28 // and the GNU Lesser Public License along with this program. If not,
29 // see <http://www.gnu.org/licenses/>.
30
31 #ifndef _SYMTENSOR_H
32 #define _SYMTENSOR_H
33
34 #include <iostream>
35 using std::istream;
36 using std::ostream;
37
38 namespace ASAPSPACE {
39
40 class SymTensor
41 {
42 public:
SymTensor()43 SymTensor() {};
44 /// Set to zero
45 void clear();
46 /// const indexing
47 double operator[](int n) const;
48 /// Non-const indexing
49 double& operator[](int n);
50 /// Add a SymTensor to this one.
51 SymTensor& operator+=(const SymTensor& v);
52 /// Multiply a SymTensor with a scalar.
53 SymTensor& operator*=(double x);
54 /// Print a SymTensor
55 friend ostream& operator<<(ostream& out, const SymTensor& v);
56
57 private:
58 double x[6]; ///< The actual data.
59 };
60
clear()61 inline void SymTensor::clear()
62 {
63 x[0] = x[1] = x[2] = x[3] = x[4] = x[5] = 0.0;
64 }
65
66 inline double SymTensor::operator[](int n) const
67 {
68 return x[n];
69 }
70
71 inline double& SymTensor::operator[](int n)
72 {
73 return x[n];
74 }
75
76 inline SymTensor& SymTensor::operator+=(const SymTensor& v)
77 {
78 x[0] += v.x[0]; x[1] += v.x[1]; x[2] += v.x[2];
79 x[3] += v.x[3]; x[4] += v.x[4]; x[5] += v.x[5];
80 return *this;
81 }
82
83 inline SymTensor& SymTensor::operator*=(double v)
84 {
85 x[0] *= v; x[1] *= v; x[2] *= v;
86 x[3] *= v; x[4] *= v; x[5] *= v;
87 return *this;
88 }
89
90 inline ostream& operator<<(ostream& out, const SymTensor& v)
91 {
92 out << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", "
93 << v[3] << ", " << v[4] << ", " << v[5] << ")";
94 return out;
95 }
96
97
98
99 } // end namespace
100
101 #endif // _SYMTENSOR_H
102