Itasca C++ Interface
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
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 #pragma warning(push)
23 #pragma warning(disable:4251)
24 
25 namespace itasca {
26  class IProgram;
27 }
28 
29 
30 namespace cmodelsxd {
31  using namespace itasca;
32  using namespace itascaxd;
33  class ContactModelState;
34 
35  static const quint32 ACTIVE_IS = 0x000001; /* active */
36  static const quint32 ACTIVATED = 0x000002; /* activated */
37  static const quint32 ACTIVE_COULDBE = 0x000004; /* could be */
38 
44  public:
46  ContactModelState(): activeState_(0),trackEnergy_(false) { }
48  virtual ~ContactModelState() {};
50  virtual const IProgram * getProgram() const=0;
52  bool setActive(bool b=true) { if (b) activeState_ |= ACTIVE_IS; else activeState_ &=~ ACTIVE_IS; return isActive(); }
54  bool setCouldBeActive(bool b=true) { if (b) activeState_ |= ACTIVE_COULDBE; else activeState_ &=~ ACTIVE_COULDBE; return couldBeActive(); }
56  bool setActivated(bool b=true) { if (b) activeState_ |= ACTIVATED; else activeState_ &=~ ACTIVATED; return activated(); }
57 
59  bool isActive() const { return activeState_ & ACTIVE_IS; }
61  bool isInactive() const { return !isActive(); }
63  bool activated() const { return activeState_ & ACTIVATED; }
65  bool couldBeActive() const { return activeState_ & ACTIVE_COULDBE; }
66  quint32 activeState_;
67  bool trackEnergy_;
68  };
69 
74  class CONTACTMODEL_EXPORT ContactModel : public IContactModel
75  {
76  public:
78  ContactModel();
79 
81  virtual ~ContactModel();
82 
84  virtual ContactModel *clone() const=0;
85 
87  virtual bool isOKToDelete() const { return true; }
88 
90  virtual void archive(ArchiveStream &) {}
91 
93  virtual void copy(const ContactModel *cm) { cmEvents_ = cm->cmEvents_; }
94 
95  // IContactModel functions.
96 
98  virtual IContactModel * getContactModel() {return this;}
99 
101  virtual const IContactModel * getContactModel() const {return this;}
102  virtual QString getName() const=0;
103 
105  virtual QString getPluginName() const { return getName(); }
106 
108  virtual QString getProperties() const=0; // comma delimited
109 
114  virtual QVariant getProperty(uint i,const IContact *con=0) const=0;
115 
119  virtual bool getPropertyGlobal(uint ) const {return true;}
120 
123  virtual int isProperty(const QString &c,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const;
124 
130  virtual bool setProperty(uint i,const QVariant &v,IContact *con=0)=0;
131 
132  virtual bool getPropertyReadOnly(uint) const { return false; } // Base 1
133  virtual bool supportsInheritance(uint) const { return false; } // Base 1
134  virtual bool getInheritance(uint) const {return false;}
135  virtual void setInheritance(uint,bool) {}
136 
137  virtual QString getMethods() const {return QString();} // comma delimited
138 
140  virtual int isMethod(const QString &c,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const; // checks the list for a match, returns the integer (>0) if a match is found
141 
143  virtual QString getMethodArguments(uint) const {return QString();} // comma delimited
144 
146  virtual bool setMethod(uint,const QVector<QVariant> &,IContact*c=0) {c;return false;} // Base 1 - returns true if timestep contributions need to be updated
147 
149  virtual QString getEnergies() const {return QString();} // comma delimited
150 
152  virtual int isEnergy(const QString &c,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const; // checks the list for a match, returns the integer (>0) if a match is found
153 
155  virtual double getEnergy(uint ) const {return 0.0;} // Base 1
156 
158  virtual bool getEnergyAccumulate(uint ) const {return false;} // Base 1
159 
161  virtual void setEnergy(uint ,const double &) {} // Base 1
162 
164  virtual void activateEnergy() {}
165 
167  virtual bool getEnergyActivated() const {return false;} // Returns a boolean indicating if energies have been instanciated
168 
169  virtual uint getMinorVersion() const=0;
170  virtual void destroy() { delete this; }
171 
173  virtual void getSphereList(const IContact *con,std::vector<DVect> *pos,std::vector<double> *rad,std::vector<double> *val)=0;
174 #ifdef THREED
175  virtual void getDiskList(const IContact *con,std::vector<DVect> *pos,std::vector<DVect> *normal,std::vector<double> *radius,std::vector<double> *val)=0;
177 #endif
178  virtual void getCylinderList(const IContact *con,std::vector<DVect> *bot,std::vector<DVect> *top,std::vector<double> *radlow,std::vector<double> *radhi,std::vector<double> *val)=0;
180 
182  virtual QString getFishCallEvents() const {return QString();}; // comma delimited
183 
185  void setEventVal(int i,int j);
186 
188  void setFromParent(const ContactModel *cm);
189 
192  virtual void setNonForcePropsFrom(IContactModel *) { };
193 
196  uint getPropertyIndex(const QString &name,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const;// {name; cs; return 0;}
197 
199  QString getPropertyName(uint index) const;
200 
201  // Major version of the contact model
202  static UInt getMajorVersion();
203 
204  // Memory Allocation Customization
205  // Changing this is very dangerous, as the calling program will make assumptions about
206  // where memory has been allocated to and from.
207  void *operator new(size_t size);
208  void *operator new(size_t size,const char *name,const char *file,unsigned line);
209  void operator delete(void *v);
210  void operator delete(void *v,const char *name,const char *file,unsigned line);
211  typedef void *(*NewFunction)(size_t,const char *,const char *,unsigned);
212  typedef void (*DeleteFunction)(void *,const char *,const char *,unsigned);
213  typedef std::pair<NewFunction,DeleteFunction> AllocFunctions;
214  static AllocFunctions setAllocFunctions(AllocFunctions afunc);
215  static AllocFunctions getDefaultAllocFunctions();
216  static AllocFunctions getAllocFunctions() { return AllocFunctions(newFunc_,deleteFunc_); }
217 
218  protected:
219  static NewFunction newFunc_;
220  static DeleteFunction deleteFunc_;
221 
223  };
224 } // namespace cmodelsxd
225 
226 #pragma warning(pop)
227 
228 // EoF
virtual QString getMethodArguments(uint) const
Default implementation so that no methods must be defined.
Definition: contactmodel.h:143
bool activated() const
Returns true if the contact state is activated.
Definition: contactmodel.h:63
ContactModelState()
Constructor.
Definition: contactmodel.h:46
bool setActive(bool b=true)
Set the activity state of the contact.
Definition: contactmodel.h:52
namespace Itasca
Definition: basememory.cpp:9
The ContactModelState class holds necessary information to communicate back and forth between the cod...
Definition: contactmodel.h:43
quint32 activeState_
Current activity state flag.
Definition: contactmodel.h:66
virtual bool getEnergyAccumulate(uint) const
Default implementation so that no energies must be defined.
Definition: contactmodel.h:158
An array class that attempts to minimize unnecessary heap access.
EXPORT_TAG unsigned getMajorVersion()
Definition: fishexample.cpp:56
unsigned int UInt
unsigned 32 bit
Definition: basedef.h:31
bool trackEnergy_
indicate whether energy tracking is activated
Definition: contactmodel.h:67
virtual QString getPluginName() const
By default, the plugin name is the contact model name. Must be implemented in derived class.
Definition: contactmodel.h:105
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:222
virtual QString getEnergies() const
Default implementation so that no energies must be defined.
Definition: contactmodel.h:149
virtual IContactModel * getContactModel()
Return the IContactModel pointer.
Definition: contactmodel.h:98
virtual QString getFishCallEvents() const
Return a comma delimited liest of FISH callback events.
Definition: contactmodel.h:182
bool couldBeActive() const
Returns true if the contact could be activate in subsequent steps.
Definition: contactmodel.h:65
virtual const IContactModel * getContactModel() const
Return the const IContactModel pointer.
Definition: contactmodel.h:101
virtual bool isOKToDelete() const
Generic implementation - by default it is always OK to delete a contact.
Definition: contactmodel.h:87
virtual bool getPropertyGlobal(uint) const
Definition: contactmodel.h:119
virtual double getEnergy(uint) const
Default implementation so that no energies must be defined.
Definition: contactmodel.h:155
virtual bool setMethod(uint, const QVector< QVariant > &, IContact *c=0)
By default, no methods must be defined.
Definition: contactmodel.h:146
Itasca Library standard namespace, specific to 2D or 3D.
Definition: icontactmodule.h:4
bool isActive() const
Returns true if the contact state is active.
Definition: contactmodel.h:59
virtual void activateEnergy()
Default implementation so that no energies must be defined.
Definition: contactmodel.h:164
virtual void setEnergy(uint, const double &)
Default implementation so that no energies must be defined.
Definition: contactmodel.h:161
EXPORT_TAG const char * getName()
Definition: fishexample.cpp:43
bool setActivated(bool b=true)
Set the activity state of the contact.
Definition: contactmodel.h:56
virtual ~ContactModelState()
Destructor.
Definition: contactmodel.h:48
Contact class.
Definition: icontact.h:34
Contact model implementation.
Definition: contactmodel.h:74
The main program access point.
Definition: iprogram.h:37
virtual void archive(ArchiveStream &)
Used for save/restore. Important to implement.
Definition: contactmodel.h:90
bool isInactive() const
Returns true if the contact state is inactive.
Definition: contactmodel.h:61
virtual void setNonForcePropsFrom(IContactModel *)
Definition: contactmodel.h:192
EXPORT_TAG unsigned getMinorVersion()
Definition: fishexample.cpp:62
bool setCouldBeActive(bool b=true)
Set the activity state of the contact.
Definition: contactmodel.h:54
virtual bool getEnergyActivated() const
Default implementation so that no energies must be defined.
Definition: contactmodel.h:167
virtual void copy(const ContactModel *cm)
Copy the contact model from cm. Must be overridden in derived classes.
Definition: contactmodel.h:93