Itasca C++ Interface
contactmodel.h
Go to the documentation of this file.
1 #pragma once
2 // contactmodel.h
3 
4 #include "contactmodel/interface/icontactmodel.h"
5 #include "contactmodel_global.h"
6 
7 #include "base/src/farray.h"
8 #include "shared/src/archivestream.h"
9 // contactmodel.h
16 #if DIM==2
17  #define cmodelsxd cmodels2d
18 #else
19  #define cmodelsxd cmodels3d
20 #endif
21 
22 #ifndef __GNUC__
23 #pragma warning(push)
24 #pragma warning(disable:4251)
25 #endif
26 
27 namespace itasca {
28  class IProgram;
29 }
30 
31 
32 namespace cmodelsxd {
33  using namespace itasca;
34  using namespace itascaxd;
35  class ContactModelState;
36 
37  static const quint32 ACTIVE_IS = 0x000001; /* active */
38  static const quint32 ACTIVATED = 0x000002; /* activated */
39  static const quint32 ACTIVE_COULDBE = 0x000004; /* could be */
40 
41  // Enumerator for the model information system
42  enum InfoTypes {ScalarInfo=1,TextInfo,VectorInfo};
43 
49  public:
53  virtual ~ContactModelState() {};
55  virtual const IProgram * getProgram() const=0;
57  bool setActive(bool b=true) { if (b) activeState_ |= ACTIVE_IS; else activeState_ &=~ ACTIVE_IS; return isActive(); }
59  bool setCouldBeActive(bool b=true) { if (b) activeState_ |= ACTIVE_COULDBE; else activeState_ &=~ ACTIVE_COULDBE; return couldBeActive(); }
61  bool setActivated(bool b=true) { if (b) activeState_ |= ACTIVATED; else activeState_ &=~ ACTIVATED; return activated(); }
62 
64  bool isActive() const { return activeState_ & ACTIVE_IS; }
66  bool isInactive() const { return !isActive(); }
68  bool activated() const { return activeState_ & ACTIVATED; }
70  bool couldBeActive() const { return activeState_ & ACTIVE_COULDBE; }
71  quint32 activeState_ = 0;
72  bool trackEnergy_ = false;
73  };
74 
79  class CONTACTMODEL_EXPORT ContactModel : public IContactModel
80  {
81  public:
83  ContactModel();
84 
86  virtual ~ContactModel();
87 
89  virtual ContactModel *clone() const { throw Exception("Not at this level"); }
90 
92  virtual bool isOKToDelete() const { return true; }
93 
95  virtual void archive(ArchiveStream &) {}
96 
98  virtual void copy(const ContactModel *cm) { cmEvents_ = cm->cmEvents_; }
99 
100  // IContactModel functions.
101 
103  IContactModel * getContactModel() override {return this;}
104 
106  const IContactModel * getContactModel() const override {return this;}
107  QString getName() const override { throw Exception("Not at this level"); }
108 
110  virtual QString getPluginName() const { return getName(); }
111 
113  QString getProperties() const override { throw Exception("Not at this level"); } // comma delimited
114 
119  QVariant getProperty([[maybe_unused]]uint i,[[maybe_unused]]const IContact *con=0) const override { throw Exception("Not at this level"); }
120 
124  bool getPropertyGlobal(uint ) const override {return true;}
125 
128  int isProperty(const QString &c,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const override;
129 
135  bool setProperty([[maybe_unused]]uint i,[[maybe_unused]]const QVariant &v,[[maybe_unused]]IContact *con=0) override { throw Exception("Not at this level"); }
136 
137  bool getPropertyReadOnly(uint) const override { return false; } // Base 1
138  bool supportsInheritance(uint) const override { return false; } // Base 1
139  bool getInheritance(uint) const override {return false;}
140  void setInheritance(uint,bool) override {}
141 
142  QString getMethods() const override {return QString();} // comma delimited
143 
145  int isMethod(const QString &c,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const override; // checks the list for a match, returns the integer (>0) if a match is found
146 
148  QString getMethodArguments(uint) const override {return QString();} // comma delimited
149 
151  bool setMethod(uint,const QVector<QVariant> &,[[maybe_unused]] IContact*c=0) override {return false;} // Base 1 - returns true if timestep contributions need to be updated
152 
154  QString getEnergies() const override {return QString();} // comma delimited
155 
157  int isEnergy(const QString &c,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const override; // checks the list for a match, returns the integer (>0) if a match is found
158 
160  double getEnergy(uint ) const override {return 0.0;} // Base 1
161 
163  bool getEnergyAccumulate(uint ) const override {return false;} // Base 1
164 
166  void setEnergy(uint ,const double &) override {} // Base 1
167 
169  void activateEnergy() override {}
170 
172  virtual bool getEnergyActivated() const {return false;} // Returns a boolean indicating if energies have been instanciated
173 
174  uint getMinorVersion() const override { throw Exception("Not at this level"); }
175  void destroy() override { delete this; }
176 
178  void getSphereList(const IContact *,std::vector<DVect> *,std::vector<double> *,std::vector<double> *) override { throw Exception("Not at this level"); }
179 #ifdef THREED
181  void getDiskList(const IContact *,std::vector<DVect> *,std::vector<DVect> *,std::vector<double> *,std::vector<double> *) override { throw Exception("Not at this level"); }
182 #endif
184  void getCylinderList(const IContact *,std::vector<DVect> *,std::vector<DVect> *,std::vector<double> *,std::vector<double> *,std::vector<double> *) override { throw Exception("Not at this level"); }
185 
187  virtual QString getFishCallEvents() const {return QString();}; // comma delimited
188 
190  void setEventVal(int i,int j);
191 
193  void setFromParent(const ContactModel *cm);
194 
197  void setNonForcePropsFrom(IContactModel *) override { };
198 
201  uint getPropertyIndex(const QString &name,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const;// {name; cs; return 0;}
202 
204  QString getPropertyName(uint index) const;
205 
206  // Major version of the contact model
207  static uint32 getMajorVersion();
208 
209  // Memory Allocation Customization
210  // Changing this is very dangerous, as the calling program will make assumptions about
211  // where memory has been allocated to and from.
212  void *operator new(size_t size);
213  void *operator new(size_t size,const char *name,const char *file,unsigned line);
214  void operator delete(void *v);
215  void operator delete(void *v,const char *name,const char *file,unsigned line);
216  typedef void *(*NewFunction)(size_t,const char *,const char *,unsigned);
217  typedef void (*DeleteFunction)(void *,const char *,const char *,unsigned);
218  typedef std::pair<NewFunction,DeleteFunction> AllocFunctions;
219  static AllocFunctions setAllocFunctions(AllocFunctions afunc);
220  static AllocFunctions getDefaultAllocFunctions();
221  static AllocFunctions getAllocFunctions() { return AllocFunctions(newFunc_,deleteFunc_); }
222 
223  // Used to efficiently get properties from the contact model for the object pane.
224  // List of properties for the object pane, comma separated.
225  // All properties will be cast to doubles for comparison. No other comparisons
226  // are supported. This may not be the same as the entire property list.
227  // Return property name and type for plotting.
228  virtual void objectPropsTypes(std::vector<std::pair<QString,InfoTypes>> *) const { }
229  // All properties cast to doubles - this is what can be compared.
230  virtual void objectPropValues(std::vector<double> *,const IContact *) const { }
231 
232  protected:
233  static NewFunction newFunc_;
234  static DeleteFunction deleteFunc_;
235 
237  };
238 } // namespace cmodelsxd
239 
240 #ifndef __GNUC__
241 #pragma warning(pop)
242 #endif
243 
244 // EoF
Base exception class for all Itasca code.
Definition: baseexception.h:10
Definition: idef.h:20
Contact model implementation.
Definition: contactmodel.h:80
virtual bool isOKToDelete() const
Generic implementation - by default it is always OK to delete a contact.
Definition: contactmodel.h:92
IContactModel * getContactModel() override
Return the IContactModel pointer.
Definition: contactmodel.h:103
virtual void archive(ArchiveStream &)
Used for save/restore. Important to implement.
Definition: contactmodel.h:95
bool getEnergyAccumulate(uint) const override
Default implementation so that no energies must be defined.
Definition: contactmodel.h:163
void getSphereList(const IContact *, std::vector< DVect > *, std::vector< double > *, std::vector< double > *) override
For contact specific plotting.
Definition: contactmodel.h:178
void setEnergy(uint, const double &) override
Default implementation so that no energies must be defined.
Definition: contactmodel.h:166
void activateEnergy() override
Default implementation so that no energies must be defined.
Definition: contactmodel.h:169
double getEnergy(uint) const override
Default implementation so that no energies must be defined.
Definition: contactmodel.h:160
virtual QString getFishCallEvents() const
Return a comma delimited liest of FISH callback events.
Definition: contactmodel.h:187
FArray< int, 5 > cmEvents_
Set of events as defined in a specified order. The int refers to the location of the event in the Con...
Definition: contactmodel.h:236
virtual QString getPluginName() const
By default, the plugin name is the contact model name. Must be implemented in derived class.
Definition: contactmodel.h:110
QString getMethodArguments(uint) const override
Default implementation so that no methods must be defined.
Definition: contactmodel.h:148
QVariant getProperty([[maybe_unused]]uint i,[[maybe_unused]]const IContact *con=0) const override
Definition: contactmodel.h:119
bool setMethod(uint, const QVector< QVariant > &,[[maybe_unused]] IContact *c=0) override
By default, no methods must be defined.
Definition: contactmodel.h:151
bool setProperty([[maybe_unused]]uint i,[[maybe_unused]]const QVariant &v,[[maybe_unused]]IContact *con=0) override
Definition: contactmodel.h:135
const IContactModel * getContactModel() const override
Return the const IContactModel pointer.
Definition: contactmodel.h:106
bool getPropertyGlobal(uint) const override
Definition: contactmodel.h:124
void setNonForcePropsFrom(IContactModel *) override
Definition: contactmodel.h:197
QString getProperties() const override
Returns a comma delimited string that lists the contact model properies. Must be implemented in deriv...
Definition: contactmodel.h:113
QString getEnergies() const override
Default implementation so that no energies must be defined.
Definition: contactmodel.h:154
virtual void copy(const ContactModel *cm)
Copy the contact model from cm. Must be overridden in derived classes.
Definition: contactmodel.h:98
virtual bool getEnergyActivated() const
Default implementation so that no energies must be defined.
Definition: contactmodel.h:172
virtual ContactModel * clone() const
Make a clone of this contact model. Must be implemeted.
Definition: contactmodel.h:89
void getCylinderList(const IContact *, std::vector< DVect > *, std::vector< DVect > *, std::vector< double > *, std::vector< double > *, std::vector< double > *) override
For contact specific plotting.
Definition: contactmodel.h:184
The ContactModelState class holds necessary information to communicate back and forth between the cod...
Definition: contactmodel.h:48
bool couldBeActive() const
Returns true if the contact could be activate in subsequent steps.
Definition: contactmodel.h:70
ContactModelState()
Constructor.
Definition: contactmodel.h:51
virtual const IProgram * getProgram() const =0
Return a const pointer to the IPrgram interface.
bool setActivated(bool b=true)
Set the activity state of the contact.
Definition: contactmodel.h:61
bool isInactive() const
Returns true if the contact state is inactive.
Definition: contactmodel.h:66
bool isActive() const
Returns true if the contact state is active.
Definition: contactmodel.h:64
bool setActive(bool b=true)
Set the activity state of the contact.
Definition: contactmodel.h:57
virtual ~ContactModelState()
Destructor.
Definition: contactmodel.h:53
bool setCouldBeActive(bool b=true)
Set the activity state of the contact.
Definition: contactmodel.h:59
bool activated() const
Returns true if the contact state is activated.
Definition: contactmodel.h:68
The main program access point.
Definition: iprogram.h:37
Contact class.
Definition: icontact.h:33
An array class that attempts to minimize unnecessary heap access.
EXPORT_TAG unsigned getMinorVersion()
Definition: fishexample.cpp:62
EXPORT_TAG unsigned getMajorVersion()
Definition: fishexample.cpp:56
EXPORT_TAG const char * getName()
Definition: fishexample.cpp:43
namespace Itasca
Definition: basememory.cpp:10
Itasca Library standard namespace, specific to 2D or 3D.
Definition: icontactmodule.h:4