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 (if not contributing author is listed, this file has been contributed
36 by the core developer)
37
38 Christoph Kloss (DCS Computing GmbH, Linz)
39 Christoph Kloss (JKU Linz)
40 Philippe Seil (JKU Linz)
41
42 Copyright 2012- DCS Computing GmbH, Linz
43 Copyright 2009-2012 JKU Linz
44 ------------------------------------------------------------------------- */
45
46 #ifndef LMP_CUSTOM_VALUE_TRACKER_I_H
47 #define LMP_CUSTOM_VALUE_TRACKER_I_H
48
49 /* ----------------------------------------------------------------------
50 add property
51 ------------------------------------------------------------------------- */
52
53 template<typename T>
addElementProperty(const char * _id,const char * _comm,const char * _ref,const char * _restart,int _scalePower,int _init_len,const char * _statistics,const double _weighting_factor,ScalarContainer<double> * const _scale,ScalarContainer<double> * const _scaleAvg,const bool _enable_favre)54 T* CustomValueTracker::addElementProperty(const char *_id,
55 const char* _comm,
56 const char* _ref,
57 const char *_restart,
58 int _scalePower,
59 int _init_len,
60 const char *_statistics,
61 const double _weighting_factor,
62 ScalarContainer<double> * const _scale,
63 ScalarContainer<double> * const _scaleAvg,
64 const bool _enable_favre)
65 {
66 // error if property exists already
67 if(elementProperties_.getPointerById<T>(_id))
68 {
69 char *errmsg = new char[strlen(_id)+200];
70 sprintf(errmsg,"Illegal command, features are incompatible - element property '%s' exists already",_id);
71 error->all(FLERR,errmsg);
72 delete []errmsg;
73 }
74
75 std::vector<std::string> id_list;
76 std::string id_string(_id);
77
78 // add property
79 ContainerBase * cb_new = elementProperties_.add<T>(_id,_comm,_ref,_restart,_scalePower);
80 id_list.push_back(id_string);
81
82 // check if properties were set correctly
83 // error here since ContainerBase not derived from Pointers
84 if(!elementProperties_.getPointerById<T>(_id)->propertiesSetCorrectly())
85 {
86 char *errmsg = new char[strlen(_id)+200];
87 sprintf(errmsg,"Illegal element property, comm or frame property not set correctly for property '%s'",_id);
88 error->all(FLERR,errmsg);
89 delete []errmsg;
90 }
91
92 // add to statistics if applicable
93 if(_statistics)
94 {
95 if(strstr(_statistics,ContainerBase::AVERAGESUFFIX))
96 {
97 std::string id_string_ave = id_string;
98 id_string_ave.append(ContainerBase::AVERAGESUFFIX);
99 T* cb_average = elementProperties_.add<T>(id_string_ave.c_str(),_comm,_ref,_restart,_scalePower);
100 cb_average->setContainerStatistics(_weighting_factor, cb_new, _scale, _scaleAvg, _enable_favre);
101 id_list.push_back(id_string_ave);
102
103 if(strstr(_statistics,"avgVar"))
104 {
105 // this one uses the average as reference field
106 // TODO: Hard-coded higher weighting factor for second stage statistics
107 std::string id_string_avg_avg = id_string_ave;
108 id_string_avg_avg.append(ContainerBase::AVERAGESUFFIX);
109 elementProperties_.add<T>(id_string_avg_avg.c_str(),_comm,_ref,_restart,_scalePower)->setContainerStatistics(5*_weighting_factor, cb_average,0,0,_enable_favre );
110 id_list.push_back(id_string_avg_avg);
111
112 std::string id_string_avg_mean_square = id_string_ave;
113 id_string_avg_mean_square.append(ContainerBase::MEANSQUARESUFFIX);
114 elementProperties_.add<T>(id_string_avg_mean_square.c_str(),_comm,_ref,_restart,_scalePower)->setContainerStatistics(5*_weighting_factor, cb_average,0,0,_enable_favre );
115 id_list.push_back(id_string_avg_mean_square);
116 }
117 }
118 if(strstr(_statistics,ContainerBase::MEANSQUARESUFFIX))
119 {
120 std::string id_string_mean_square = id_string;
121 id_string_mean_square.append(ContainerBase::MEANSQUARESUFFIX);
122 elementProperties_.add<T>(id_string_mean_square.c_str(),_comm,_ref,_restart,_scalePower)->setContainerStatistics(_weighting_factor, cb_new, _scale, _scaleAvg, _enable_favre );
123 id_list.push_back(id_string_mean_square);
124 }
125 }
126
127 // allocate memory and initialize
128
129 for(size_t inew = 0; inew < id_list.size(); inew++)
130 {
131 T * const idPtr = elementProperties_.getPointerById<T>(id_list[inew].c_str());
132 if(ownerMesh_)
133 idPtr->addUninitialized(ownerMesh_->sizeLocal()+ownerMesh_->sizeGhost());
134
135 if(_init_len > 0)
136 idPtr->addUninitialized(_init_len);
137
138 idPtr->setAll(0);
139 }
140
141 // return pointer
142 return elementProperties_.getPointerById<T>(_id);
143 }
144
145 template<typename T>
addGlobalProperty(const char * _id,const char * _comm,const char * _ref,const char * _restart,int _scalePower)146 T* CustomValueTracker::addGlobalProperty(const char *_id, const char* _comm, const char* _ref, const char *_restart, int _scalePower)
147 {
148 // error if property exists already
149 if(globalProperties_.getPointerById<T>(_id))
150 {
151 char *errmsg = new char[strlen(_id)+200];
152 sprintf(errmsg,"Illegal command, features are incompatible - global property '%s' already exists",_id);
153 error->all(FLERR,errmsg);
154 delete []errmsg;
155 }
156
157 // add property
158 globalProperties_.add<T>(_id,_comm,_ref,_restart,_scalePower);
159 globalProperties_orig_.add<T>(_id,_comm,_ref,_restart,_scalePower);
160
161 // check if properties were set correctly
162 // error here since ContainerBase not derived from Pointers
163 if(!globalProperties_.getPointerById<T>(_id)->propertiesSetCorrectly())
164 {
165 char *errmsg = new char[strlen(_id)+200];
166 sprintf(errmsg,"Illegal global property, comm or frame property not set correctly for property '%s'",_id);
167 error->all(FLERR,errmsg);
168 delete []errmsg;
169 }
170
171 // allocate memory
172 //globalProperties_.getPointerById<T>(_id)->addUninitialized(capacityElement_);
173
174 // return pointer
175 return globalProperties_.getPointerById<T>(_id);
176 }
177
178 /* ----------------------------------------------------------------------
179 get reference
180 ------------------------------------------------------------------------- */
181
182 template<typename T>
getElementProperty(const char * _id)183 T* CustomValueTracker::getElementProperty(const char *_id)
184 {
185 return elementProperties_.getPointerById<T>(_id);
186 }
187
188 template<typename T>
getElementProperty(int _i)189 T* CustomValueTracker::getElementProperty(int _i)
190 {
191 return elementProperties_.getPointerByIndex<T>(_i);
192 }
193
getElementPropertyBase(const char * _id)194 inline ContainerBase* CustomValueTracker::getElementPropertyBase(const char *_id)
195 {
196 return elementProperties_.getBasePointerById(_id);
197 }
198
getElementPropertyBase(int i)199 inline ContainerBase* CustomValueTracker::getElementPropertyBase(int i)
200 {
201 return elementProperties_.getBasePointerByIndex(i);
202 }
203
getElementPropertyIndex(const char * _id)204 inline int CustomValueTracker::getElementPropertyIndex(const char *_id)
205 {
206 return elementProperties_.idToIndex(_id);
207 }
208
209 template<typename T>
getGlobalProperty(const char * _id)210 T* CustomValueTracker::getGlobalProperty(const char *_id)
211 {
212 return globalProperties_.getPointerById<T>(_id);
213 }
214
215 template<typename T>
getAvgElementProperty(const char * _id)216 T* CustomValueTracker::getAvgElementProperty(const char *_id)
217 {
218 std::string id_string(_id);
219 id_string.append(ContainerBase::AVERAGESUFFIX);
220 return getElementProperty<T>(id_string.c_str());
221 }
222
223 template<typename T>
getMeanSquareElementProperty(const char * _id)224 T* CustomValueTracker::getMeanSquareElementProperty(const char *_id)
225 {
226 std::string id_string(_id);
227 id_string.append(ContainerBase::MEANSQUARESUFFIX);
228 return getElementProperty<T>(id_string.c_str());
229 }
230
231 template<typename T>
getAvgAvgElementProperty(const char * _id)232 T* CustomValueTracker::getAvgAvgElementProperty(const char *_id)
233 {
234 std::string id_string(_id);
235 id_string.append(ContainerBase::AVERAGESUFFIX).append(ContainerBase::AVERAGESUFFIX);
236 return getElementProperty<T>(id_string.c_str());
237 }
238
239 template<typename T>
getAvgMeanSquareElementProperty(const char * _id)240 T* CustomValueTracker::getAvgMeanSquareElementProperty(const char *_id)
241 {
242 std::string id_string(_id);
243 id_string.append(ContainerBase::AVERAGESUFFIX).append(ContainerBase::MEANSQUARESUFFIX);
244 return getElementProperty<T>(id_string.c_str());
245 }
246
247 /* ----------------------------------------------------------------------
248 set property
249 ------------------------------------------------------------------------- */
250
251 template<typename T, typename U>
setElementProperty(const char * _id,U def)252 void CustomValueTracker::setElementProperty(const char *_id, U def)
253 {
254 elementProperties_.getPointerById<T>(_id)->set(def);
255 }
256
257 template<typename T, typename U>
setGlobalProperty(const char * _id,U def)258 void CustomValueTracker::setGlobalProperty(const char *_id, U def)
259 {
260
261 if(globalProperties_.getPointerById<T>(_id)->size() == 0)
262 globalProperties_.getPointerById<T>(_id)->addUninitialized(1);
263 globalProperties_.getPointerById<T>(_id)->set(0,def);
264
265 if(globalProperties_orig_.getPointerById<T>(_id)->size() == 0)
266 globalProperties_orig_.getPointerById<T>(_id)->addUninitialized(1);
267 globalProperties_orig_.getPointerById<T>(_id)->set(0,def);
268 }
269
270 /* ----------------------------------------------------------------------
271 store global property orig - only needs to be done manually for
272 special cases, eg moving mesh ref points
273 ------------------------------------------------------------------------- */
274
storeGlobalPropOrig(const char * _id)275 inline void CustomValueTracker::storeGlobalPropOrig(const char *_id)
276 {
277 globalProperties_.storeOrig(_id,globalProperties_orig_);
278 }
279
280 /* ----------------------------------------------------------------------
281 reset global property to orig - only needs to be done manually for
282 special cases, eg moving mesh ref points
283 ------------------------------------------------------------------------- */
284
resetGlobalPropToOrig(const char * _id)285 inline void CustomValueTracker::resetGlobalPropToOrig(const char *_id)
286 {
287 globalProperties_.reset(_id,globalProperties_orig_);
288 }
289
290 /* ----------------------------------------------------------------------
291 copy data from element from to element to
292 ------------------------------------------------------------------------- */
293
copyElement(int from,int to)294 void CustomValueTracker::copyElement(int from, int to)
295 {
296 elementProperties_.copyElement(from,to);
297 }
298
299 /* ----------------------------------------------------------------------
300 add an element and initialize its properties with 0
301 ------------------------------------------------------------------------- */
302
addZeroElement()303 void CustomValueTracker::addZeroElement()
304 {
305 elementProperties_.addZeroElement();
306 }
307
308 /* ----------------------------------------------------------------------
309 add an uninitialized element
310 ------------------------------------------------------------------------- */
311
addUninitializedElement()312 void CustomValueTracker::addUninitializedElement()
313 {
314 elementProperties_.addUninitializedElement();
315 }
316
317 /* ----------------------------------------------------------------------
318 delete all elements
319 ------------------------------------------------------------------------- */
320
deleteAllElements()321 void CustomValueTracker::deleteAllElements()
322 {
323 elementProperties_.deleteAllElements();
324 }
325
326 /* ----------------------------------------------------------------------
327 delete all elements
328 ------------------------------------------------------------------------- */
329
deleteRestart(bool scale,bool translate,bool rotate)330 void CustomValueTracker::deleteRestart(bool scale,bool translate,bool rotate)
331 {
332 elementProperties_.deleteRestart(scale,translate,rotate);
333 }
334
335 /* ----------------------------------------------------------------------
336 delete element i
337 ------------------------------------------------------------------------- */
338
deleteElement(int i)339 void CustomValueTracker::deleteElement(int i)
340 {
341 elementProperties_.deleteElement(i);
342 }
343
344 /* ----------------------------------------------------------------------
345 delete forward comm properties of element i
346 ------------------------------------------------------------------------- */
347
deleteForwardElement(int i,bool scale,bool translate,bool rotate)348 void CustomValueTracker::deleteForwardElement(int i,bool scale,bool translate,bool rotate)
349 {
350 elementProperties_.deleteForwardElement(i,scale,translate,rotate);
351 }
352
353 /* ----------------------------------------------------------------------
354 delete restart properties of element i
355 ------------------------------------------------------------------------- */
356
deleteRestartElement(int i,bool scale,bool translate,bool rotate)357 void CustomValueTracker::deleteRestartElement(int i,bool scale,bool translate,bool rotate)
358 {
359 elementProperties_.deleteRestartElement(i,scale,translate,rotate);
360 }
361
362 /* ----------------------------------------------------------------------
363 delete global restart properties
364 ------------------------------------------------------------------------- */
365
deleteRestartGlobal(bool scale,bool translate,bool rotate)366 void CustomValueTracker::deleteRestartGlobal(bool scale,bool translate,bool rotate)
367 {
368 globalProperties_.deleteRestartGlobal(scale,translate,rotate);
369 globalProperties_orig_.deleteRestartGlobal(scale,translate,rotate);
370 }
371
372 /* ----------------------------------------------------------------------
373 move element i
374 ------------------------------------------------------------------------- */
375
moveElement(const int i,const double * const delta)376 void CustomValueTracker::moveElement(const int i, const double * const delta)
377 {
378 elementProperties_.moveElement(i,delta);
379 }
380
381 /* ----------------------------------------------------------------------
382 push / pop for all lements
383 ------------------------------------------------------------------------- */
384
allElemBufSize(int operation,bool scale,bool translate,bool rotate)385 int CustomValueTracker::allElemBufSize(int operation,bool scale,bool translate,bool rotate) const
386 {
387 return elementProperties_.bufSize(operation,scale,translate,rotate);
388 }
389
pushAllElemToBuffer(double * buf,int operation,bool scale,bool translate,bool rotate)390 int CustomValueTracker::pushAllElemToBuffer(double *buf, int operation,bool scale,bool translate, bool rotate)
391 {
392 return elementProperties_.pushToBuffer(buf,operation,scale,translate,rotate);
393 }
394
popAllElemFromBuffer(double * buf,int operation,bool scale,bool translate,bool rotate)395 int CustomValueTracker::popAllElemFromBuffer(double *buf, int operation,bool scale,bool translate, bool rotate)
396 {
397 return elementProperties_.popFromBuffer(buf, operation,scale,translate,rotate);
398 }
399
400 /* ----------------------------------------------------------------------
401 push / pop for list of elements
402 ------------------------------------------------------------------------- */
403
elemListBufSize(int n,int operation,bool scale,bool translate,bool rotate)404 int CustomValueTracker::elemListBufSize(int n,int operation,bool scale,bool translate,bool rotate)
405 {
406 return elementProperties_.elemListBufSize(n,operation,scale,translate,rotate);
407 }
408
pushElemListToBuffer(int n,int * list,int * wraplist,double * buf,int operation,std::list<std::string> * properties,double * dlo,double * dhi,bool scale,bool translate,bool rotate)409 int CustomValueTracker::pushElemListToBuffer(int n, int *list, int *wraplist, double *buf, int operation, std::list<std::string> * properties, double *dlo, double *dhi, bool scale,bool translate, bool rotate)
410 {
411 return elementProperties_.pushElemListToBuffer(n,list, wraplist, buf,operation, properties, dlo, dhi, scale,translate,rotate);
412 }
413
popElemListFromBuffer(int first,int n,double * buf,int operation,std::list<std::string> * properties,bool scale,bool translate,bool rotate)414 int CustomValueTracker::popElemListFromBuffer(int first, int n, double *buf, int operation, std::list<std::string> * properties, bool scale,bool translate, bool rotate)
415 {
416 return elementProperties_.popElemListFromBuffer(first,n,buf,operation, properties, scale,translate,rotate);
417 }
418
pushElemListToBufferReverse(int first,int n,double * buf,int operation,std::list<std::string> * properties,bool scale,bool translate,bool rotate)419 int CustomValueTracker::pushElemListToBufferReverse(int first, int n, double *buf, int operation, std::list<std::string> * properties, bool scale,bool translate, bool rotate)
420 {
421 return elementProperties_.pushElemListToBufferReverse(first,n,buf,operation, properties, scale,translate,rotate);
422 }
423
popElemListFromBufferReverse(int n,int * list,double * buf,int operation,std::list<std::string> * properties,bool scale,bool translate,bool rotate)424 int CustomValueTracker::popElemListFromBufferReverse(int n, int *list, double *buf, int operation, std::list<std::string> * properties, bool scale,bool translate, bool rotate)
425 {
426 return elementProperties_.popElemListFromBufferReverse(n,list,buf,operation, properties, scale,translate,rotate);
427 }
428
429 /* ----------------------------------------------------------------------
430 push / pop for element i
431 ------------------------------------------------------------------------- */
432
elemBufSize(int operation,std::list<std::string> * properties,bool scale,bool translate,bool rotate)433 int CustomValueTracker::elemBufSize(int operation, std::list<std::string> * properties, bool scale,bool translate,bool rotate)
434 {
435
436 return elementProperties_.elemBufSize(operation, properties, scale,translate,rotate);
437 }
438
pushElemToBuffer(int i,double * buf,int operation,bool scale,bool translate,bool rotate)439 int CustomValueTracker::pushElemToBuffer(int i, double *buf, int operation,bool scale,bool translate, bool rotate)
440 {
441 return elementProperties_.pushElemToBuffer(i,buf,operation,scale,translate,rotate);
442 }
443
popElemFromBuffer(double * buf,int operation,bool scale,bool translate,bool rotate)444 int CustomValueTracker::popElemFromBuffer(double *buf, int operation,bool scale,bool translate, bool rotate)
445 {
446 return elementProperties_.popElemFromBuffer(buf,operation,scale,translate,rotate);
447 }
448
449 /* ----------------------------------------------------------------------
450 push / pop for global properties
451 ------------------------------------------------------------------------- */
452
globalPropsBufSize(int operation,bool scale,bool translate,bool rotate)453 int CustomValueTracker::globalPropsBufSize(int operation,bool scale,bool translate,bool rotate)
454 {
455 int n = 0;
456 n += globalProperties_.bufSize(operation,scale,translate,rotate);
457 n += globalProperties_orig_.bufSize(operation,scale,translate,rotate);
458 return n;
459 }
460
pushGlobalPropsToBuffer(double * buf,int operation,bool scale,bool translate,bool rotate)461 int CustomValueTracker::pushGlobalPropsToBuffer(double *buf, int operation,bool scale,bool translate, bool rotate)
462 {
463 int n = 0;
464 n += globalProperties_.pushToBuffer(&(buf[n]),operation,scale,translate,rotate);
465 n += globalProperties_orig_.pushToBuffer(&(buf[n]),operation,scale,translate,rotate);
466 return n;
467 }
468
popGlobalPropsFromBuffer(double * buf,int operation,bool scale,bool translate,bool rotate)469 int CustomValueTracker::popGlobalPropsFromBuffer(double *buf, int operation,bool scale,bool translate, bool rotate)
470 {
471 int n = 0;
472 n += globalProperties_.popFromBuffer(&(buf[n]),operation,scale,translate,rotate);
473 n += globalProperties_orig_.popFromBuffer(&(buf[n]),operation,scale,translate,rotate);
474 return n;
475 }
476
477 #endif
478