Itasca C++ Interface
Loading...
Searching...
No Matches
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
27namespace itasca {
28 class IProgram;
29}
30
31
32namespace 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
46 public:
50 virtual ~ContactModelState() {};
52 virtual const IProgram * getProgram() const=0;
54 bool setActive(bool b=true) { if (b) activeState_ |= ACTIVE_IS; else activeState_ &= ~ACTIVE_IS; return isActive(); }
56 bool setCouldBeActive(bool b=true) { if (b) activeState_ |= ACTIVE_COULDBE; else activeState_ &= ~ACTIVE_COULDBE; return couldBeActive(); }
58 bool setActivated(bool b=true) { if (b) activeState_ |= ACTIVATED; else activeState_ &= ~ACTIVATED; return activated(); }
59
61 bool isActive() const { return activeState_ & ACTIVE_IS; }
63 bool isInactive() const { return !isActive(); }
65 bool activated() const { return activeState_ & ACTIVATED; }
67 bool couldBeActive() const { return activeState_ & ACTIVE_COULDBE; }
68 quint32 activeState_ = 0;
69 bool trackEnergy_ = false;
70 };
71
76 class CONTACTMODEL_EXPORT ContactModel : public IContactModel
77 {
78 public:
81
83 virtual ~ContactModel();
84
86 virtual ContactModel *clone() const=0;
87
89 virtual bool isOKToDelete() const { return true; }
90
92 virtual void archive(ArchiveStream &) {}
93
95 virtual void copy(const ContactModel *cm) { cmEvents_ = cm->cmEvents_; }
96
97 // IContactModel functions.
98
100 IContactModel * getContactModel() override {return this;}
101
103 const IContactModel * getContactModel() const override {return this;}
104 QString getName() const override =0;
105
107 virtual QString getPluginName() const { return getName(); }
108
110 QString getProperties() const override =0; // comma delimited
111
116 QVariant getProperty(uint i,const IContact *con=0) const override =0;
117
121 bool getPropertyGlobal(uint ) const override {return true;}
122
125 int isProperty(const QString &c,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const override;
126
132 bool setProperty(uint i,const QVariant &v,IContact *con=0) override =0;
133
134 bool getPropertyReadOnly(uint) const override { return false; } // Base 1
135 bool supportsInheritance(uint) const override { return false; } // Base 1
136 bool getInheritance(uint) const override {return false;}
137 void setInheritance(uint,bool) override {}
138
139 QString getMethods() const override {return QString();} // comma delimited
140
142 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
143
145 QString getMethodArguments(uint) const override {return QString();} // comma delimited
146
148 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
149
151 QString getEnergies() const override {return QString();} // comma delimited
152
154 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
155
157 double getEnergy(uint ) const override {return 0.0;} // Base 1
158
160 bool getEnergyAccumulate(uint ) const override {return false;} // Base 1
161
163 void setEnergy(uint ,const double &) override {} // Base 1
164
166 void activateEnergy() override {}
167
169 virtual bool getEnergyActivated() const {return false;} // Returns a boolean indicating if energies have been instanciated
170
171 uint getMinorVersion() const override =0;
172 void destroy() override { delete this; }
173
175 void getSphereList(const IContact *con,std::vector<DVect> *pos,std::vector<double> *rad,std::vector<double> *val) override =0;
176#ifdef THREED
178 void getDiskList(const IContact *con,std::vector<DVect> *pos,std::vector<DVect> *normal,std::vector<double> *radius,std::vector<double> *val) override =0;
179#endif
181 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) override =0;
182
184 virtual QString getFishCallEvents() const {return QString();}; // comma delimited
185
187 void setEventVal(int i,int j);
188
190 void setFromParent(const ContactModel *cm);
191
194 void setNonForcePropsFrom(IContactModel *) override { };
195
198 uint getPropertyIndex(const QString &name,Qt::CaseSensitivity cs=Qt::CaseInsensitive) const;// {name; cs; return 0;}
199
201 QString getPropertyName(uint index) const;
202
203 // Major version of the contact model
204 static uint32 getMajorVersion();
205
206 // Memory Allocation Customization
207 // Changing this is very dangerous, as the calling program will make assumptions about
208 // where memory has been allocated to and from.
209 void *operator new(size_t size);
210 void *operator new(size_t size,const char *file,unsigned line);
211 void operator delete(void *v);
212 void operator delete(void *v,const char *file,unsigned line);
213 typedef void *(*NewFunction)(size_t,const char *,unsigned);
214 typedef void (*DeleteFunction)(void *,const char *,unsigned);
215 typedef std::pair<NewFunction,DeleteFunction> AllocFunctions;
216 static AllocFunctions setAllocFunctions(AllocFunctions afunc);
217 static AllocFunctions getDefaultAllocFunctions();
218 static AllocFunctions getAllocFunctions() { return AllocFunctions(newFunc_,deleteFunc_); }
219
220 protected:
221 static NewFunction newFunc_;
222 static DeleteFunction deleteFunc_;
223
225 };
226} // namespace cmodelsxd
227
228#ifndef __GNUC__
229#pragma warning(pop)
230#endif
231
232// EoF
An array class that attempts to minimize unnecessary heap access.
Definition farray.h:25
Contact model implementation.
Definition contactmodel.h:77
virtual bool isOKToDelete() const
Generic implementation - by default it is always OK to delete a contact.
Definition contactmodel.h:89
virtual void archive(ArchiveStream &)
Used for save/restore. Important to implement.
Definition contactmodel.h:92
bool getEnergyAccumulate(uint) const override
Default implementation so that no energies must be defined.
Definition contactmodel.h:160
bool setProperty(uint i, const QVariant &v, IContact *con=0) override=0
void setEnergy(uint, const double &) override
Default implementation so that no energies must be defined.
Definition contactmodel.h:163
void activateEnergy() override
Default implementation so that no energies must be defined.
Definition contactmodel.h:166
void getSphereList(const IContact *con, std::vector< DVect > *pos, std::vector< double > *rad, std::vector< double > *val) override=0
For contact specific plotting.
double getEnergy(uint) const override
Default implementation so that no energies must be defined.
Definition contactmodel.h:157
bool setMethod(uint, const QVector< QVariant > &, IContact *c=0) override
By default, no methods must be defined.
Definition contactmodel.h:148
virtual QString getFishCallEvents() const
Return a comma delimited liest of FISH callback events.
Definition contactmodel.h:184
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:224
virtual QString getPluginName() const
By default, the plugin name is the contact model name. Must be implemented in derived class.
Definition contactmodel.h:107
QString getMethodArguments(uint) const override
Default implementation so that no methods must be defined.
Definition contactmodel.h:145
QString getProperties() const override=0
Returns a comma delimited string that lists the contact model properies. Must be implemented in deriv...
QVariant getProperty(uint i, const IContact *con=0) const override=0
IContactModel * getContactModel() override
Return the IContactModel pointer.
Definition contactmodel.h:100
bool getPropertyGlobal(uint) const override
Definition contactmodel.h:121
void setNonForcePropsFrom(IContactModel *) override
Definition contactmodel.h:194
virtual ContactModel * clone() const =0
Make a clone of this contact model. Must be implemeted.
QString getEnergies() const override
Default implementation so that no energies must be defined.
Definition contactmodel.h:151
virtual void copy(const ContactModel *cm)
Copy the contact model from cm. Must be overridden in derived classes.
Definition contactmodel.h:95
virtual bool getEnergyActivated() const
Default implementation so that no energies must be defined.
Definition contactmodel.h:169
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) override=0
For contact specific plotting.
const IContactModel * getContactModel() const override
Return the const IContactModel pointer.
Definition contactmodel.h:103
The ContactModelState class holds necessary information to communicate back and forth between the cod...
Definition contactmodel.h:45
bool couldBeActive() const
Returns true if the contact could be activate in subsequent steps.
Definition contactmodel.h:67
ContactModelState()
Constructor.
Definition contactmodel.h:48
bool setActivated(bool b=true)
Set the activity state of the contact.
Definition contactmodel.h:58
virtual const IProgram * getProgram() const =0
Return a const pointer to the IPrgram interface.
bool isInactive() const
Returns true if the contact state is inactive.
Definition contactmodel.h:63
bool isActive() const
Returns true if the contact state is active.
Definition contactmodel.h:61
bool setActive(bool b=true)
Set the activity state of the contact.
Definition contactmodel.h:54
bool trackEnergy_
indicate whether energy tracking is activated
Definition contactmodel.h:69
virtual ~ContactModelState()
Destructor.
Definition contactmodel.h:50
bool setCouldBeActive(bool b=true)
Set the activity state of the contact.
Definition contactmodel.h:56
quint32 activeState_
Current activity state flag.
Definition contactmodel.h:68
bool activated() const
Returns true if the contact state is activated.
Definition contactmodel.h:65
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:14
Itasca Library standard namespace, specific to 2D or 3D.
Definition icontactmodule.h:4