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 40 Copyright 2012- DCS Computing GmbH, Linz 41 Copyright 2009-2012 JKU Linz 42 ------------------------------------------------------------------------- */ 43 44 #ifndef LMP_CONTAINER_BASE_H 45 #define LMP_CONTAINER_BASE_H 46 47 #include <string> 48 #include <list> 49 #include <string.h> 50 51 namespace LAMMPS_NS 52 { 53 // buffer operation types (for push and pop) 54 55 enum{ OPERATION_COMM_EXCHANGE, 56 OPERATION_COMM_BORDERS, 57 OPERATION_COMM_FORWARD, 58 OPERATION_COMM_REVERSE, 59 OPERATION_RESTART, 60 OPERATION_UNDEFINED}; 61 62 /* ---------------------------------------------------------------------- 63 definition of reference frames and comm types 64 ------------------------------------------------------------------------- */ 65 66 // reference frame types 67 // invariant: invariant to scaling, translation, rotation 68 // trans invariant: invariant to translation, not invariant to scaling, rotation 69 // trans+rot invariant: invariant to translation, rotation, not invariant to scaling 70 // general: not invariant to scaling, translation, rotation 71 72 enum{ REF_FRAME_UNDEFINED, 73 REF_FRAME_INVARIANT, 74 REF_FRAME_SCALE_TRANS_INVARIANT, 75 REF_FRAME_TRANS_ROT_INVARIANT, 76 REF_FRAME_TRANS_INVARIANT, 77 REF_FRAME_GENERAL}; 78 79 // communication types 80 81 enum{ // communication invoked manually 82 COMM_TYPE_MANUAL, 83 // only exchange and borders comm 84 COMM_EXCHANGE_BORDERS, 85 // forward comm every step 86 COMM_TYPE_FORWARD, 87 // forward comm based on reference frame setting 88 // ie if mesh rotates, egdeVecs are communicated 89 90 COMM_TYPE_FORWARD_FROM_FRAME, 91 // reverse comm every step 92 93 COMM_TYPE_REVERSE, 94 // reverse comm every step 95 96 COMM_TYPE_REVERSE_BITFIELD, 97 // no comm at all 98 99 COMM_TYPE_NONE, 100 // undefined state for error check 101 COMM_TYPE_UNDEFINED}; // communication types 102 103 // restart types 104 105 enum{ RESTART_TYPE_UNDEFINED, 106 RESTART_TYPE_YES, 107 RESTART_TYPE_NO}; 108 109 // return status of checkBorderElement{Left,Right} in multi_node_mesh_parallel 110 // also enables container properties to be wrapped around periodic boundaries 111 // e.g. node positions of triangles 112 enum 113 { 114 NOT_GHOST = 0, 115 IS_GHOST = 1<<0, 116 IS_GHOST_WRAP_DIM_0_NEG = 1<<1, 117 IS_GHOST_WRAP_DIM_0_POS = 1<<2, 118 IS_GHOST_WRAP_DIM_1_NEG = 1<<3, 119 IS_GHOST_WRAP_DIM_1_POS = 1<<4, 120 IS_GHOST_WRAP_DIM_2_NEG = 1<<5, 121 IS_GHOST_WRAP_DIM_2_POS = 1<<6 122 }; 123 124 /* ---------------------------------------------------------------------- 125 class definitions 126 ------------------------------------------------------------------------- */ 127 128 class ContainerBase 129 { 130 public: 131 132 ContainerBase(const char *_id); 133 134 virtual ~ContainerBase(); 135 136 void setProperties(const char *_id, const char* _comm, const char* _ref, const char *_restart,int _scalePower = 1); 137 bool propertiesSetCorrectly(); 138 139 void setContainerStatistics(const double _weighting_factor, class ContainerBase *_cb_stat, class ContainerBase * const _cb_scale, 140 class ContainerBase * const _cb_scale_avg = 0, const bool _enable_favre = false); 141 id()142 inline const char* id() 143 {return id_; } 144 setDoNotReset(bool _doNotReset)145 inline void setDoNotReset(bool _doNotReset) 146 { doNotReset_ = _doNotReset; } 147 doNotReset()148 inline bool doNotReset() 149 { return doNotReset_; } 150 setWrapPeriodic(bool wrap)151 inline void setWrapPeriodic(bool wrap) 152 { wrapPeriodic_ = wrap; } 153 wrapPeriodic()154 inline bool wrapPeriodic() 155 { return wrapPeriodic_; } 156 157 inline void id(char *_id); 158 inline bool matches_id(const char *_id); 159 inline bool matches_any_id(std::list<std::string> * ids); 160 161 virtual bool isDoubleData() = 0; 162 virtual bool isIntData() = 0; 163 164 virtual void addZero() = 0; 165 virtual void addUninitialized(int n) = 0; 166 virtual int size() const = 0; 167 virtual int capacity() const = 0; 168 virtual int nVec() const = 0; 169 virtual int lenVec() const = 0; 170 virtual void* begin_slow_dirty() = 0; 171 172 virtual void clearContainer() = 0; 173 174 virtual void copy(int from,int to) = 0; 175 virtual void del(int n) = 0; 176 virtual void delForward(int n,bool scale,bool translate,bool rotate) = 0; 177 virtual void delRestart(int n,bool scale,bool translate,bool rotate) = 0; 178 virtual void delRestart(bool scale,bool translate,bool rotate) = 0; 179 virtual void clearReverse(bool scale,bool translate,bool rotate) = 0; 180 181 virtual bool setFromContainer(ContainerBase *cont) = 0; 182 isStatisticsContainer()183 bool isStatisticsContainer() 184 { return (container_statistics_raw_data_!=0); } 185 bool calcStatistics(); 186 bool updateScalingContainer(); 187 virtual bool calcAvgFromContainer() = 0; 188 virtual bool calcMeanSquareFromContainer() = 0; 189 virtual bool calcSumFromContainer() = 0; 190 191 virtual void scale(double factor) = 0; 192 virtual void move(const double * const dx) = 0; 193 virtual void moveElement(const int i, const double * const dx) = 0; 194 virtual void rotate(const double * const dQ) = 0; 195 196 virtual void setToDefault(int n) = 0; 197 virtual void setAllToZero() = 0; 198 useDefault()199 inline bool useDefault() 200 { return useDefault_ ; } 201 getStatLevel()202 inline int getStatLevel() const 203 { return statLevel_; } 204 isScalingContainer()205 bool isScalingContainer() const 206 { return scalingContainer_; } 207 setScalingContainer(bool _value)208 void setScalingContainer(bool _value) 209 { scalingContainer_ = _value; } 210 setWeightingFactor(double _value)211 inline void setWeightingFactor(double _value) 212 { weighting_factor_ = _value; } 213 communicationType()214 inline int communicationType() const 215 { return communicationType_; } 216 217 // buffer functions for parallelization 218 219 virtual int bufSize(int operation = OPERATION_UNDEFINED, 220 bool scale=false,bool translate=false, bool rotate=false) const = 0; 221 virtual int popFromBuffer(double *buf,int operation, 222 bool scale=false,bool translate=false, bool rotate=false) = 0; 223 virtual int pushToBuffer(double *buf,int operation, 224 bool scale=false,bool translate=false, bool rotate=false) = 0; 225 226 virtual int elemListBufSize(int n, int operation = OPERATION_UNDEFINED, 227 bool scale=false,bool translate=false, bool rotate=false) = 0; 228 virtual int pushElemListToBuffer(int n, int *list, int *wraplist, double *buf, int operation, double *dlo, double *dhi, 229 bool scale=false,bool translate=false, bool rotate=false) = 0; 230 virtual int popElemListFromBuffer(int first, int n, double *buf, int operation, 231 bool scale=false,bool translate=false, bool rotate=false) = 0; 232 virtual int pushElemListToBufferReverse(int first, int n, double *buf, int operation, 233 bool scale=false,bool translate=false, bool rotate=false) = 0; 234 virtual int popElemListFromBufferReverse(int n, int *list, double *buf, int operation, 235 bool scale=false,bool translate=false, bool rotate=false) = 0; 236 237 virtual int elemBufSize(int operation = OPERATION_UNDEFINED, 238 bool scale=false,bool translate=false, bool rotate=false) = 0; 239 virtual int pushElemToBuffer(int n, double *buf,int operation, 240 bool scale=false,bool translate=false, bool rotate=false) = 0; 241 virtual int popElemFromBuffer(double *buf,int operation, 242 bool scale=false,bool translate=false, bool rotate=false) = 0; 243 244 // static elements 245 static const char * AVERAGESUFFIX; 246 static const char * MEANSQUARESUFFIX; 247 248 protected: 249 250 ContainerBase(const char *_id, const char* _comm, const char* _ref, const char *_restart,int _scalePower); 251 ContainerBase(ContainerBase const &orig); 252 253 inline bool isScaleInvariant() const; 254 inline bool isTranslationInvariant() const; 255 inline bool isRotationInvariant() const; 256 257 inline bool decidePackUnpackOperation(int operation,bool scale,bool translate, bool rotate) const; 258 259 inline bool decideCommOperation(int operation) const; 260 261 inline bool decideCreateNewElements(int operation); 262 263 char *id_; 264 int communicationType_; 265 int refFrame_; 266 int restartType_; 267 int scalePower_; 268 269 bool useDefault_; 270 271 bool doNotReset_; 272 273 class ContainerBase *container_statistics_raw_data_; 274 275 class ContainerBase *container_statistics_scale_data_; 276 class ContainerBase *container_statistics_scale_average_data_; 277 278 int statLevel_; 279 double weighting_factor_; 280 281 bool scalingContainer_; 282 283 // Enable favre averaged time averaging 284 bool enable_favre_; 285 286 // ignore zero values for averaging 287 // default is false 288 289 // Decides whether a property is shifted when a periodic boundary is encountered 290 // in pushElemListToBuffer 291 bool wrapPeriodic_; 292 293 private: 294 295 ContainerBase(); 296 }; 297 298 // ************************************* 299 #include "container_base_I.h" 300 // ************************************* 301 302 } /* LAMPPS_NS */ 303 #endif /* CONTAINERBASE_H_ */ 304