Itasca C++ Interface
conmodel.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "conmodelbase.h"
4 #include "state.h"
5 #include "base/src/property.h"
6 #include <vector>
7 #include <iostream>
8 #include "shared/src/vector.h"
9 
19 namespace models {
20 
21  struct State;
22 
24 
33  class CONMODEL_EXPORT ConstitutiveModel {
34  public:
41  virtual string getName() const { throw std::runtime_error("Base method called."); }
43  virtual string getPluginName() const { return getName(); }
50  virtual string getFullName() const { throw std::runtime_error("Base method called."); }
52  virtual bool isNull() const { return false; }
55  virtual bool isModelAdvanced() const { return false; }
57  virtual bool isKGEv() const { return false; }
59  virtual bool isOriented() const { return false; }
62  virtual bool isCreep() const { return false; }
64  virtual bool isLiquefaction() const { return false; }
69  virtual uint32 getMinorVersion() const;
75  virtual string getProperties() const { throw std::runtime_error("Base method called."); } // comma delimited
82  virtual string getStates() const { throw std::runtime_error("Base method called."); }
88  virtual base::Property getProperty(uint32) const { throw std::runtime_error("Base method called."); }
98  virtual void setProperty(uint32,const base::Property &,uint32=0) { setValid(0); }
102  virtual bool isPropertyReadOnly(uint32) const { return false; }
105  virtual bool isPropertyAdvanced(uint32) const { return false; }
109  virtual void save(std::ostream &o) const;
111  virtual void restore(std::istream &i,uint32 restoreVersion);
115  virtual ConstitutiveModel *clone() const { throw std::runtime_error("Base method called."); }
120  virtual double getConfinedModulus() const { throw std::runtime_error("Base method called."); }
124  virtual double getShearModulus() const { throw std::runtime_error("Base method called."); }
127  virtual double getBulkModulus() const { throw std::runtime_error("Base method called."); }
133  virtual void copy(const ConstitutiveModel *mod);
135  virtual bool performMixing() const { return false; }
137  virtual void mixStrain(uint32,State *,SymTensor *,double *) { }
146  virtual void run(uint32 d,State *s) { if (!isValid(d)) initialize(d,s); }
148  virtual void mixStress(uint32,State *,SymTensor *,double *) { }
160  virtual void initialize(uint32 d,State *) { setValid(d); }
165  virtual double getStrengthStressRatio(const SymTensor &) const { return 10.0; }
171  virtual void scaleProperties(const double &,const std::vector<uint32> &) { throw std::logic_error("Does not support property scaling"); }
173  virtual bool supportsHystereticDamping() const { return false; }
175  virtual bool supportsStrengthStressRatio() const { return false; }
177  virtual bool supportsPropertyScaling() const { return false; }
180  virtual bool supportsSmallStrainEffect() const { return false; }
182  virtual bool supportsPlaneStress() const { return false; }
184  virtual bool supportsUniaxial() const { return false; }
186  virtual void destroy() { delete this; }
187 
189  ConstitutiveModel(unsigned short option=0);
191  ConstitutiveModel(const ConstitutiveModel &) noexcept;
193  const ConstitutiveModel & operator=(const ConstitutiveModel &);
195  virtual ~ConstitutiveModel();
197  virtual void addToStorage(poly::vector<ConstitutiveModel> *,int = -1) { throw std::runtime_error("Base method called."); }
201  static uint32 getLibraryMinorVersion();
203  bool isValid(uint32 d) const { return valid_==to<int8>(d); }
205  void setValid(uint32 d) { valid_ = to<int8>(d); }
208  bool canFail() const { return canFail_; }
210  void setIfCanFail(bool b) { canFail_ = b; }
212  std::vector<unsigned short> gEOB() const;
214  void sEOB(const std::vector<unsigned short> &reply);
216  bool cEOB() const;
217 
218 #ifndef DOXYGEN
219  // Memory Allocation Customization
220  // Changing this is very dangerous, as the calling program will make assumptions about
221  // where memory has been allocated to and from.
222  void *operator new(size_t size);
223  void *operator new(size_t size,const char *name,const char *file,unsigned line);
224  void operator delete(void *v);
225  void operator delete(void *v,const char *name,const char *file,unsigned line);
226  using NewFunction = void *(*)(size_t, const char *, const char *, unsigned);
227  using DeleteFunction = void (*)(void *, const char *, const char *, unsigned);
228  typedef std::pair<NewFunction,DeleteFunction> MemoryAllocationFunctions;
229  static MemoryAllocationFunctions setMemoryAllocationFunctions(MemoryAllocationFunctions afunc);
230  static MemoryAllocationFunctions getDefaultMemoryAllocationFunctions();
231  static MemoryAllocationFunctions getMemoryAllocationFunctions() { return MemoryAllocationFunctions(newFunc_,deleteFunc_); }
232 #endif
233 
234  bool isD0(const double& a) const { return std::abs(a) <= limits<double>::epsilon(); }
235 
236  private:
237 
238  static NewFunction newFunc_;
239  static DeleteFunction deleteFunc_;
240 
241  int8 valid_ = 0;
242  bool canFail_ = true;
243  uint16 option_ = 0;
244 
245  public:
246  // ensure the same bits for all models
247  static const uint32 shear_now = 0x001;
248  static const uint32 tension_now = 0x002;
249  static const uint32 shear_past = 0x004;
250  static const uint32 tension_past = 0x008;
251  static const uint32 joint_shear_now = 0x010;
252  static const uint32 joint_tension_now = 0x020;
253  static const uint32 joint_shear_past = 0x040;
254  static const uint32 joint_tension_past = 0x080;
255  static const uint32 volume_now = 0x100;
256  static const uint32 volume_past = 0x200;
257  // shared frequently used constants
258  static constexpr double pi = 3.14159265358979323846264338327950;
259  static constexpr double degrad = 0.01745329251994329576923690768488;
260  static constexpr double d1d3 = 0.33333333333333333333333333333333;
261  static constexpr double d2d3 = 0.66666666666666666666666666666667;
262  static constexpr double d4d3 = 1.33333333333333333333333333333333;
263  static constexpr double rt6 = 2.44948974278317809819728407470589; // sqrt(6.0)
264  };
265 
266 # define C_M ConstitutiveModel
267 } // namespace models
268 
270 // EoF
Definition: property.h:20
debug checked shorthand for std::numeric_limits<T>::
Definition: limit.h:25
The base class for constitutive model plug-ins.
Definition: conmodel.h:33
virtual bool supportsStrengthStressRatio() const
Returns true if strength-stress ratio calculations are supported via getStrengthStressRatio().
Definition: conmodel.h:175
virtual void setProperty(uint32, const base::Property &, uint32=0)
Sets the value of the property with index i (base 1).
Definition: conmodel.h:98
virtual void initialize(uint32 d, State *)
Initializes the constitutive model in preparation for calls to run().
Definition: conmodel.h:160
virtual ConstitutiveModel * clone() const
Returns an instance this class.
Definition: conmodel.h:115
virtual string getProperties() const
Returns a string containing the names of model properties.
Definition: conmodel.h:75
virtual bool isKGEv() const
Return TRUE if the model can input (bulk,shear) or (young,poisson).
Definition: conmodel.h:57
virtual bool supportsSmallStrainEffect() const
Definition: conmodel.h:180
virtual string getPluginName() const
There should be no reason for an implementation to override the default behavior of this function.
Definition: conmodel.h:43
virtual string getFullName() const
The full name of the model.
Definition: conmodel.h:50
virtual bool supportsPropertyScaling() const
Returns true if property scaling is supported for factor-of-safety calculations via scaleProperties()...
Definition: conmodel.h:177
bool isValid(uint32 d) const
Indicates whether initializion is necessary - by dimension.
Definition: conmodel.h:203
virtual bool isPropertyReadOnly(uint32) const
Definition: conmodel.h:102
virtual void mixStrain(uint32, State *, SymTensor *, double *)
User defined strain mixing technique. .
Definition: conmodel.h:137
virtual bool isModelAdvanced() const
Definition: conmodel.h:55
virtual double getStrengthStressRatio(const SymTensor &) const
Returns the ratio of the stress tensor to the current yield strength.
Definition: conmodel.h:165
virtual void addToStorage(poly::vector< ConstitutiveModel > *, int=-1)
For polymorphic container access.
Definition: conmodel.h:197
virtual void scaleProperties(const double &, const std::vector< uint32 > &)
Scales failure property indices v by the factor f.
Definition: conmodel.h:171
virtual string getName() const
Must be unique, used to identify model in save/restore, on command line, filename.
Definition: conmodel.h:41
virtual double getConfinedModulus() const
Return estimate of maximum confined modulus.
Definition: conmodel.h:120
virtual bool isOriented() const
Return TRUE if the model can input (dip, dip-direction) or (norm).
Definition: conmodel.h:59
void setIfCanFail(bool b)
Specifies whether or not "failure" is being allowed for this instanced of the constitutive model.
Definition: conmodel.h:210
virtual void run(uint32 d, State *s)
Calculate stress increment given a strain increment.
Definition: conmodel.h:146
virtual bool supportsPlaneStress() const
Returns true if 2D plane-stress is supported by run().
Definition: conmodel.h:182
virtual void mixStress(uint32, State *, SymTensor *, double *)
User defined stress mixing technique. .
Definition: conmodel.h:148
virtual base::Property getProperty(uint32) const
Return the value of the property of that index (base 1).
Definition: conmodel.h:88
virtual bool isNull() const
Returns true if this model represents a NULL material. Only the NULL model should return true.
Definition: conmodel.h:52
bool canFail() const
Definition: conmodel.h:208
virtual double getShearModulus() const
Return estimate of tangent shear-modulus.
Definition: conmodel.h:124
virtual void destroy()
There should be no reason for an implementation to change the default behavior of this function.
Definition: conmodel.h:186
virtual bool supportsUniaxial() const
Returns true if 1D uniaxial is supported by run().
Definition: conmodel.h:184
virtual bool isPropertyAdvanced(uint32) const
Definition: conmodel.h:105
virtual string getStates() const
Returns a string containing state names.
Definition: conmodel.h:82
virtual bool isCreep() const
Definition: conmodel.h:62
virtual double getBulkModulus() const
Return estimate of tangent bulk-modulus.
Definition: conmodel.h:127
void setValid(uint32 d)
Sets the current valid state to dimension dim.
Definition: conmodel.h:205
virtual bool isLiquefaction() const
Return TRUE if the model should be considered "Liquefaction" model.
Definition: conmodel.h:64
virtual bool supportsHystereticDamping() const
Returns true if hysteretic damping is supported by run(). See State::hysteretic_damping_.
Definition: conmodel.h:173
virtual bool performMixing() const
Set true if an alternative mixing technqiue rather than the default one in the code is used....
Definition: conmodel.h:135
EXPORT_TAG unsigned getMinorVersion()
Definition: fishexample.cpp:62
EXPORT_TAG const char * getName()
Definition: fishexample.cpp:43
The base class for constitutive model plug-ins.
The Constitutive Model interface library.
Definition: conmodel.cpp:7
The structure used to pass information to the constitutive model.
Definition: state.h:32