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 #include "custom_value_tracker.h"
45 
46 using namespace LAMMPS_NS;
47 
48   /* ----------------------------------------------------------------------
49    constructor, destructor
50   ------------------------------------------------------------------------- */
51 
CustomValueTracker(LAMMPS * lmp,AbstractMesh * _ownerMesh)52   CustomValueTracker::CustomValueTracker(LAMMPS *lmp,AbstractMesh *_ownerMesh)
53    : Pointers(lmp),
54      ownerMesh_(_ownerMesh),
55      capacityElement_(GROW_CONTAINER())
56   {
57   }
58 
CustomValueTracker(LAMMPS * lmp)59   CustomValueTracker::CustomValueTracker(LAMMPS *lmp)
60    : Pointers(lmp),
61      ownerMesh_(NULL),
62      capacityElement_(0)
63   {
64   }
65 
~CustomValueTracker()66   CustomValueTracker::~CustomValueTracker()
67   {
68   }
69 
70   /* ----------------------------------------------------------------------
71    check if all containers have same length
72   ------------------------------------------------------------------------- */
73 
check_element_property_consistency(int _len)74   void CustomValueTracker::check_element_property_consistency(int _len)
75   {
76     if (!elementProperties_.sameLength(_len))
77     {
78          error->one(FLERR,"all element properties must have the same length.\n"
79                           "For meshes, all elem properties with restart must be added in post_create_pre_restart().\n"
80                           "For meshes, all elem properties without restart must be added after the constructor()\n");
81     }
82   }
83 
84   /* ----------------------------------------------------------------------
85    remove property
86   ------------------------------------------------------------------------- */
87 
removeElementProperty(const char * _id)88   void CustomValueTracker::removeElementProperty(const char *_id)
89   {
90      elementProperties_.remove(_id);
91   }
92 
removeGlobalProperty(const char * _id)93   void CustomValueTracker::removeGlobalProperty(const char *_id)
94   {
95      globalProperties_.remove(_id);
96      globalProperties_orig_.remove(_id);
97   }
98 
99   /* ----------------------------------------------------------------------
100    store current values of global properties as orig
101   ------------------------------------------------------------------------- */
102 
storeOrig()103   void CustomValueTracker::storeOrig()
104   {
105 
106       globalProperties_.storeOrig(globalProperties_orig_);
107 
108   }
109 
110   /* ----------------------------------------------------------------------
111    reset global properties to orig
112   ------------------------------------------------------------------------- */
113 
resetToOrig()114   void CustomValueTracker::resetToOrig()
115   {
116 
117       globalProperties_.reset(globalProperties_orig_);
118 
119   }
120 
121   /* ----------------------------------------------------------------------
122    calc statistics (averages, mean square)
123   ------------------------------------------------------------------------- */
124 
calcStatistics()125   bool CustomValueTracker::calcStatistics()
126   {
127       return elementProperties_.calcStatistics();
128   }
129 
setWeightingFactor(double _weighting_factor)130   void CustomValueTracker::setWeightingFactor(double _weighting_factor)
131   {
132       for (int i=0; i < elementProperties_.size(); ++i)
133       {
134           ContainerBase* iElem = elementProperties_.getBasePointerByIndex(i);
135           if (iElem->getStatLevel() < 2)
136               iElem->setWeightingFactor(_weighting_factor);
137           else
138               //TODO: hard coded different weighting factor for higher statistics level
139               // compare with CustomValueTracker::addElementProperty
140               iElem->setWeightingFactor(5*_weighting_factor);
141       }
142   }
143 
144   /* ----------------------------------------------------------------------
145    rotate all properties, applies to vector and multivector only
146   ------------------------------------------------------------------------- */
147 
rotate(const double * const totalQ,const double * const dQ)148   void CustomValueTracker::rotate(const double * const totalQ, const double * const dQ)
149   {
150 
151       elementProperties_.rotate(dQ);
152       globalProperties_.rotate(totalQ);
153   }
154 
rotate(const double * const dQ)155   void CustomValueTracker::rotate(const double * const dQ)
156   {
157 
158       elementProperties_.rotate(dQ);
159       globalProperties_.rotate(dQ);
160   }
161 
162   /* ----------------------------------------------------------------------
163    scale all properties, applies to vectors and multivectors only
164   ------------------------------------------------------------------------- */
165 
scale(double factor)166   void CustomValueTracker::scale(double factor)
167   {
168 
169       elementProperties_.scale(factor);
170       globalProperties_.scale(factor);
171   }
172 
173   /* ----------------------------------------------------------------------
174    move all properties
175   ------------------------------------------------------------------------- */
176 
move(const double * const vecTotal,const double * const vecIncremental)177   void CustomValueTracker::move(const double * const vecTotal, const double * const vecIncremental)
178   {
179 
180       elementProperties_.move(vecIncremental);
181       globalProperties_.move(vecTotal);
182   }
183 
move(const double * const vecIncremental)184   void CustomValueTracker::move(const double * const vecIncremental)
185   {
186 
187       elementProperties_.move(vecIncremental);
188       globalProperties_.move(vecIncremental);
189   }
190 
191   /* ----------------------------------------------------------------------
192    clear reverse properties, i.e. reset all of them to 0
193   ------------------------------------------------------------------------- */
194 
clearReverse(bool scale,bool translate,bool rotate)195   void CustomValueTracker::clearReverse(bool scale,bool translate,bool rotate)
196   {
197 
198       elementProperties_.clearReverse(scale,translate,rotate);
199   }
200