1 /* ----------------------------------------------------------------------
2 This is the
3
4 ██╗ ██╗ ██████╗ ██████╗ ██████╗ ██╗ ██╗████████╗███████╗
5 ██║ ██║██╔════╝ ██╔════╝ ██╔════╝ ██║ ██║╚══██╔══╝██╔════╝
6 ██║ ██║██║ ███╗██║ ███╗██║ ███╗███████║ ██║ ███████╗
7 ██║ ██║██║ ██║██║ ██║██║ ██║██╔══██║ ██║ ╚════██║
8 ███████╗██║╚██████╔╝╚██████╔╝╚██████╔╝██║ ██║ ██║ ███████║
9 ╚══════╝╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝®
10
11 DEM simulation engine, released by
12 DCS Computing Gmbh, Linz, Austria
13 http://www.dcs-computing.com, office@dcs-computing.com
14
15 LIGGGHTS® is part of CFDEM®project:
16 http://www.liggghts.com | http://www.cfdem.com
17
18 Core developer and main author:
19 Christoph Kloss, christoph.kloss@dcs-computing.com
20
21 LIGGGHTS® is open-source, distributed under the terms of the GNU Public
22 License, version 2 or later. It is distributed in the hope that it will
23 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. You should have
25 received a copy of the GNU General Public License along with LIGGGHTS®.
26 If not, see http://www.gnu.org/licenses . See also top-level README
27 and LICENSE files.
28
29 LIGGGHTS® and CFDEM® are registered trade marks of DCS Computing GmbH,
30 the producer of the LIGGGHTS® software and the CFDEM®coupling software
31 See http://www.cfdem.com/terms-trademark-policy for details.
32
33 -------------------------------------------------------------------------
34 Contributing author and copyright for this file:
35
36 Christoph Kloss (DCS Computing GmbH, Linz)
37 Christoph Kloss (JKU Linz)
38 Philippe Seil (JKU Linz)
39 Andreas Aigner (DCS Computing GmbH, Linz)
40
41 Copyright 2012- DCS Computing GmbH, Linz
42 Copyright 2009-2012 JKU Linz
43 ------------------------------------------------------------------------- */
44
45 #ifndef LMP_GENERAL_CONTAINER
46 #define LMP_GENERAL_CONTAINER
47
48 #include "container_base.h"
49 #include "memory_ns.h"
50 #include "math_extra_liggghts.h"
51 #include "domain.h"
52 #include <limits>
53 #include <cmath>
54 #include <algorithm>
55
GROW_CONTAINER()56 inline int GROW_CONTAINER()
57 { return 10000; }
58
59 using namespace LAMMPS_MEMORY_NS;
60
61 namespace LAMMPS_NS
62 {
63
64 template<typename T, int NUM_VEC, int LEN_VEC>
65 class GeneralContainer : public ContainerBase
66 {
67 public:
68
69 bool isDoubleData();
70 bool isIntData();
71
72 bool subtract (GeneralContainer<T,NUM_VEC,LEN_VEC> const &A,
73 GeneralContainer<T,NUM_VEC,LEN_VEC> const &minusB);
74
75 void add(T** elem);
76 void addZero();
77
78 void copy(int from,int to);
79 void del(int n);
80 void delForward(int n,bool scale,bool translate,bool rotate);
81 void delRestart(int n,bool scale,bool translate,bool rotate);
82 void delRestart(bool scale,bool translate,bool rotate);
83 void clearReverse(bool scale,bool translate,bool rotate);
84
85 void get(int n, T** elem);
86
87 void setToDefault(int n);
88 void setAll(T def);
89 void setAll(int to, T def);
setAllToZero()90 void setAllToZero()
91 { setAll(static_cast<T>(0)); }
92
93 void set(int i, T** elem);
94 void set(int i, int j, T* elem);
95
96 bool setFromContainer(ContainerBase *cont);
97
98 bool calcAvgFromContainer();
99 bool calcMeanSquareFromContainer();
100 bool calcSumFromContainer();
101
102 T max_scalar();
103 T min_scalar();
104
105 T**& operator()(int n);
106 T** const& operator()(int n) const;
107 T*** begin();
108 virtual void* begin_slow_dirty();
109
110 inline void scale(double factor);
111 inline void move(const double * const dx);
112 inline void moveElement(const int i, const double * const dx);
113 inline void rotate(const double * const dQ);
114
115 // all push and pop functions return number of bytes taken from / added to buf
116 // all push and pop functions expect buf to point to first element with usable data
117
118 // push / pop all elements
119
120 inline int bufSize(int operation = OPERATION_UNDEFINED,
121 bool scale=false,bool translate=false, bool rotate=false) const;
122 inline int pushToBuffer(double *buf, int operation = OPERATION_UNDEFINED,
123 bool scale=false,bool translate=false, bool rotate=false);
124 inline int popFromBuffer(double *buf, int operation = OPERATION_UNDEFINED,
125 bool scale=false,bool translate=false, bool rotate=false);
126
127 // push / pop a list elements
128
129 inline int elemListBufSize(int n, int operation = OPERATION_UNDEFINED,
130 bool scale=false,bool translate=false, bool rotate=false);
131 inline int pushElemListToBuffer(int n, int *list, int *wraplist, double *buf, int operation, double *dlo, double *dhi,
132 bool scale=false,bool translate=false, bool rotate=false);
133 inline int popElemListFromBuffer(int first, int n, double *buf, int operation,
134 bool scale=false,bool translate=false, bool rotate=false);
135 inline int pushElemListToBufferReverse(int first, int n, double *buf, int operation,
136 bool scale=false,bool translate=false, bool rotate=false);
137 inline int popElemListFromBufferReverse(int n, int *list, double *buf, int operation,
138 bool scale=false,bool translate=false, bool rotate=false);
139
140 // push / pop one single element
141
142 inline int elemBufSize(int operation = OPERATION_UNDEFINED,
143 bool scale=false,bool translate=false, bool rotate=false);
144 inline int pushElemToBuffer(int i, double *buf, int operation,
145 bool scale=false,bool translate=false, bool rotate=false);
146 inline int popElemFromBuffer(double *buf, int operation,
147 bool scale=false,bool translate=false, bool rotate=false);
148
149 void addUninitialized(int n);
150
size()151 inline int size() const
152 { return numElem_; }
153
nVec()154 inline int nVec() const
155 { return NUM_VEC; }
156
lenVec()157 inline int lenVec() const
158 { return LEN_VEC; }
159
capacity()160 inline int capacity() const
161 { return maxElem_; }
162
clearContainer()163 inline void clearContainer()
164 { numElem_ = 0; }
165
setDefaultValue(T val)166 inline void setDefaultValue(T val)
167 { defaultValue_ = val; useDefault_ = true; }
168
169 protected:
170
171 GeneralContainer(const char *_id);
172 GeneralContainer(const char *_id, const char *_comm, const char *_ref, const char *_restart, int _scalePower = 1);
173 GeneralContainer(GeneralContainer<T,NUM_VEC,LEN_VEC> const &orig);
174 virtual ~GeneralContainer();
175
176 // shall return the size of an entry in bytes
177 int getElemSize();
178
179 int numElem_, maxElem_;
180
181 T*** arr_;
182
183 T defaultValue_;
184 };
185
186 // *************************************
187 #include "general_container_I.h"
188 // *************************************
189
190 } /* LAMPPS_NS */
191 #endif /* CONTAINERBASE_H_ */
192