Linear Contact Bond Model Implementation

See this file for the documentation of this contact model.

contactmodellinearcbond.h

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#pragma once
// contactmodellinearcbond.h

#include "contactmodel/src/contactmodelmechanical.h"

#ifdef LINEARCBOND_LIB
#  define LINEARCBOND_EXPORT EXPORT_TAG
#elif defined(NO_MODEL_IMPORT)
#  define LINEARCBOND_EXPORT
#else
#  define LINEARCBOND_EXPORT IMPORT_TAG
#endif

namespace cmodelsxd {
    using namespace itasca;

    class ContactModelLinearCBond : public ContactModelMechanical {
    public:
        LINEARCBOND_EXPORT ContactModelLinearCBond();
        LINEARCBOND_EXPORT virtual ~ContactModelLinearCBond();
        virtual void                     copy(const ContactModel *c);
        virtual void                     archive(ArchiveStream &); 

        virtual QString  getName() const { return "linearcbond"; }
        virtual void     setIndex(int i) { index_=i;}
        virtual int      getIndex() const {return index_;}

        enum PropertyKeys { 
              kwKn=1
            , kwKs                            
            , kwFric   
            , kwLinF
            , kwLinS
            , kwLinMode
            , kwRGap
            , kwEmod
            , kwKRatio
            , kwDpNRatio 
            , kwDpSRatio
            , kwDpMode 
            , kwDpF
            , kwCbState
            , kwCbTenF                        
            , kwCbShearF 
            , kwCbTStr                        
            , kwCbSStr 
        };
         
        virtual QString  getProperties() const {
            return "kn"
                   ",ks"
                   ",fric"
                   ",lin_force"
                   ",lin_slip"
                   ",lin_mode"
                   ",rgap"
                   ",emod"
                   ",kratio"
                   ",dp_nratio"
                   ",dp_sratio"
                   ",dp_mode"
                   ",dp_force"
                   ",cb_state"
                   ",cb_tenf"
                   ",cb_shearf"
                   ",cb_tens"
                   ",cb_shears";
        }

        enum EnergyKeys { kwEStrain=1,kwESlip,kwEDashpot};
        virtual QString  getEnergies() const { return "energy-strain,energy-slip,energy-dashpot";}
        virtual double   getEnergy(uint i) const;           // Base 1
        virtual bool     getEnergyAccumulate(uint i) const; // Base 1
        virtual void     setEnergy(uint i,const double &d); // Base 1
        virtual void     activateEnergy() { if (energies_) return; energies_ = NEWC(Energies());}
        virtual bool     getEnergyActivated() const {return (energies_ !=0);}

        enum FishCallEvents {fActivated=0,fBondBreak, fSlipChange };
        virtual QString  getFishCallEvents() const { return "contact_activated,bond_break,slip_change"; }
        virtual QVariant getProperty(uint i,const IContact *) const;
        virtual bool     getPropertyGlobal(uint i) const;
        virtual bool     setProperty(uint i,const QVariant &v,IContact *);
        virtual bool     getPropertyReadOnly(uint i) const;

        virtual bool     supportsInheritance(uint i) const; 
        virtual bool     getInheritance(uint i) const { assert(i<32); quint32 mask = to<quint32>(1 << i);  return (inheritanceField_ & mask) ? true : false; }
        virtual void     setInheritance(uint i,bool b) { assert(i<32); quint32 mask = to<quint32>(1 << i);  if (b) inheritanceField_ |= mask;  else inheritanceField_ &= ~mask; }

        enum MethodKeys { 
              kwDeformability=1
            , kwCbBond 
            , kwCbStrength
            , kwCbUnbond
        };

        virtual QString  getMethods() const { 
            return "deformability"
                   ",bond" 
                   ",cb_strength"
                   ",unbond";
        }

        virtual QString  getMethodArguments(uint i) const; 

        virtual bool     setMethod(uint i,const QVector<QVariant> &vl,IContact *con=0); // Base 1 - returns true if timestep contributions need to be updated

        virtual uint     getMinorVersion() const;

        virtual bool    validate(ContactModelMechanicalState *state,const double &timestep);
        virtual bool    endPropertyUpdated(const QString &name,const IContactMechanical *c);
        virtual bool    forceDisplacementLaw(ContactModelMechanicalState *state,const double &timestep);
        virtual DVect2  getEffectiveTranslationalStiffness() const { DVect2 ret = effectiveTranslationalStiffness_; return ret;}
        virtual DAVect  getEffectiveRotationalStiffness() const { return DAVect(0.0);}

        virtual ContactModelLinearCBond *clone() const { return NEWC(ContactModelLinearCBond()); }
        virtual double              getActivityDistance() const {return rgap_;}
        virtual bool                isOKToDelete() const { return !isBonded(); }
        virtual void                resetForcesAndMoments() { lin_F(DVect(0.0)); dp_F(DVect(0.0));  if (energies_) energies_->estrain_ = 0.0; }

        virtual bool     checkActivity(const double &gap) { return (gap <= rgap_ || isBonded()); }

        virtual bool     isSliding() const { return lin_S_; }
        virtual bool     isBonded() const { return (cb_state_==3); }
        virtual void     propagateStateInformation(IContactModelMechanical* oldCm,const CAxes &oldSystem=CAxes(),const CAxes &newSystem=CAxes());
        virtual void     setNonForcePropsFrom(IContactModel *oldCM);

        const double & kn() const {return kn_;}
        void           kn(const double &d) {kn_=d;}
        const double & ks() const {return ks_;}
        void           ks(const double &d) {ks_=d;}
        const double & fric() const {return fric_;}
        void           fric(const double &d) {fric_=d;}
        const DVect &  lin_F() const {return lin_F_;}
        void           lin_F(const DVect &f) { lin_F_=f;}
        bool           lin_S() const {return lin_S_;}
        void           lin_S(bool b) { lin_S_=b;}
        uint           lin_mode() const {return lin_mode_;}
        void           lin_mode(uint i) { lin_mode_=i;}
        const double & rgap() const {return rgap_;}
        void           rgap(const double &d) {rgap_=d;}
        uint           cb_state() const {return cb_state_;}
        void           cb_state(uint b) { cb_state_=b;}
        const double & cb_tenF() const {return cb_tenF_;}
        void           cb_tenF(const double &d) {cb_tenF_=d;}
        const double & cb_shearF() const {return cb_shearF_;}
        void           cb_shearF(const double &d) {cb_shearF_=d;}

        bool     hasDamping() const {return dpProps_ ? true : false;}
        double   dp_nratio() const {return (hasDamping() ? (dpProps_->dp_nratio_) : 0.0);}
        void     dp_nratio(const double &d) { if(!hasDamping()) return; dpProps_->dp_nratio_=d;}
        double   dp_sratio() const {return hasDamping() ? dpProps_->dp_sratio_: 0.0;}
        void     dp_sratio(const double &d) { if(!hasDamping()) return; dpProps_->dp_sratio_=d;}
        int      dp_mode() const {return hasDamping() ? dpProps_->dp_mode_: -1;}
        void     dp_mode(int i) { if(!hasDamping()) return; dpProps_->dp_mode_=i;}
        DVect    dp_F() const {return hasDamping() ? dpProps_->dp_F_: DVect(0.0);}
        void     dp_F(const DVect &f) { if(!hasDamping()) return; dpProps_->dp_F_=f;}

        bool    hasEnergies() const {return energies_ ? true:false;}
        double  estrain() const {return hasEnergies() ? energies_->estrain_: 0.0;}
        void    estrain(const double &d) { if(!hasEnergies()) return; energies_->estrain_=d;}
        double  eslip() const {return hasEnergies() ? energies_->eslip_: 0.0;}
        void    eslip(const double &d) { if(!hasEnergies()) return; energies_->eslip_=d;}
        double  edashpot() const {return hasEnergies() ? energies_->edashpot_: 0.0;}
        void    edashpot(const double &d) { if(!hasEnergies()) return; energies_->edashpot_=d;}

        uint inheritanceField() const {return inheritanceField_;}
        void inheritanceField(uint i) {inheritanceField_ = i;}

        const DVect2 & effectiveTranslationalStiffness()  const          {return effectiveTranslationalStiffness_;}
        void           effectiveTranslationalStiffness(const DVect2 &v ) {effectiveTranslationalStiffness_=v;}

    private:
        static int index_;

        struct Energies {
            Energies() : estrain_(0.0), eslip_(0.0),edashpot_(0.0) {}
            double estrain_;  // elastic energy stored in contact 
            double eslip_;    // work dissipated by friction 
            double edashpot_;    // work dissipated by dashpots
        };

        struct dpProps {
            dpProps() : dp_nratio_(0.0), dp_sratio_(0.0), dp_mode_(0), dp_F_(DVect(0.0)) {}
            double dp_nratio_;     // normal viscous critical damping ratio
            double dp_sratio_;     // shear  viscous critical damping ratio
            int    dp_mode_;      // for viscous mode (0-4) 0 = dashpots, 1 = tensile limit, 2 = shear limit, 3 = limit both
            DVect  dp_F_;  // Force in the dashpots
        };

        bool   updateKn(const IContactMechanical *con);
        bool   updateKs(const IContactMechanical *con);
        bool   updateFric(const IContactMechanical *con);

        void   updateEffectiveStiffness(ContactModelMechanicalState *state);

        void   setDampCoefficients(const double &mass,double *vcn,double *vcs);

        // inheritance fields
        quint32 inheritanceField_;

        // linear model
        double      kn_;        // normal stiffness
        double      ks_;        // shear stiffness
        double      fric_;      // Coulomb friction coefficient
        DVect       lin_F_;     // Force carried in the linear model
        bool        lin_S_;     // current slip state
        uint        lin_mode_;  // specifies incremental or absolute for the the linear part 
        double      rgap_;      // reference gap 

        uint        cb_state_;  // Bond state - 0 (NBNF), 1 (NBFT), 2 (NBFS), 3 (B)
        double      cb_tenF_;   
        double      cb_shearF_;

        dpProps *   dpProps_;    // The viscous properties

        Energies *   energies_;    // energies

        DVect2  effectiveTranslationalStiffness_;
         
    };
} // namespace itascaxd
// EoF

Top

contactmodellinearcbond.cpp

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
// contactmodellinearcbond.cpp
#include "contactmodellinearcbond.h"

#include "module/interface/icontactmechanical.h"
#include "module/interface/icontact.h"

#include "module/interface/ipiecemechanical.h"
#include "module/interface/ipiece.h"
#include "../version.txt"
#include "base/src/basetoqt.h"

#include "module/interface/ifishcalllist.h"
#include "utility/src/tptr.h"
#include "shared/src/mathutil.h"

#include "kernel/interface/iprogram.h"
#include "module/interface/icontactthermal.h"
#include "contactmodel/src/contactmodelthermal.h"

#ifdef LINEARCBOND_LIB
  int __stdcall DllMain(void *,unsigned, void *)
  {
    return 1;
  }

  extern "C" EXPORT_TAG const char *getName() 
  {
#if DIM==3
    return "contactmodelmechanical3dlinearcbond";
#else
    return "contactmodelmechanical2dlinearcbond";
#endif
  }

  extern "C" EXPORT_TAG unsigned getMajorVersion()
  {
    return MAJOR_VERSION;
  }

  extern "C" EXPORT_TAG unsigned getMinorVersion()
  {
    return MINOR_VERSION;
  }

  extern "C" EXPORT_TAG void *createInstance() 
  {
    cmodelsxd::ContactModelLinearCBond *m = NEWC(cmodelsxd::ContactModelLinearCBond());
    return (void *)m;
  }
#endif // LINEARCBOND_EXPORTS

namespace cmodelsxd {
    static const quint32 linKnMask      = 0x00002; // Base 1!
    static const quint32 linKsMask      = 0x00004;
    static const quint32 linFricMask    = 0x00008;

    using namespace itasca;

    int ContactModelLinearCBond::index_ = -1;
    UInt ContactModelLinearCBond::getMinorVersion() const { return MINOR_VERSION;}

    ContactModelLinearCBond::ContactModelLinearCBond() : inheritanceField_(linKnMask|linKsMask|linFricMask) 
                                                        , kn_(0.0)
                                                        , ks_(0.0)
                                                        , fric_(0.0)
                                                        , lin_F_(DVect(0.0))
                                                        , lin_S_(false)
                                                        , lin_mode_(0)
                                                        , rgap_(0.0)
                                                        , cb_state_(0)
                                                        , cb_tenF_(0.0)
                                                        , cb_shearF_(0.0)
                                                        , dpProps_(0)
                                                        , energies_(0)
                                                        , effectiveTranslationalStiffness_(DVect2(0.0)) {
//    setFromParent(ContactModelMechanicalList::instance()->find(getName()));
    }

    ContactModelLinearCBond::~ContactModelLinearCBond() {
        if (dpProps_)
            delete dpProps_;
        if (energies_)
            delete energies_;
    }

    void ContactModelLinearCBond::archive(ArchiveStream &stream) {
        stream & kn_;
        stream & ks_;
        stream & fric_;
        stream & lin_F_;
        stream & lin_S_;
        stream & lin_mode_;
        stream & cb_state_;
        stream & cb_tenF_;  
        stream & cb_shearF_;

        if (stream.getArchiveState()==ArchiveStream::Save) {
            bool b = false;
            if (dpProps_) {
                b = true;
                stream & b;
                stream & dpProps_->dp_nratio_; 
                stream & dpProps_->dp_sratio_; 
                stream & dpProps_->dp_mode_; 
                stream & dpProps_->dp_F_; 
            }
            else
                stream & b;

            b = false;
            if (energies_) {
                b = true;
                stream & b;
                stream & energies_->estrain_;
                stream & energies_->eslip_;
                stream & energies_->edashpot_;
            }
            else
                stream & b;
        } else {
            bool b(false);
            stream & b;
            if (b) {
                if (!dpProps_)
                    dpProps_ = NEWC(dpProps());
                stream & dpProps_->dp_nratio_; 
                stream & dpProps_->dp_sratio_; 
                stream & dpProps_->dp_mode_; 
                stream & dpProps_->dp_F_; 
            }
            stream & b;
            if (b) {
                if (!energies_)
                    energies_ = NEWC(Energies());
                stream & energies_->estrain_;
                stream & energies_->eslip_;
                stream & energies_->edashpot_;
            }
        }

        stream & inheritanceField_;
        stream & effectiveTranslationalStiffness_;

        if (stream.getArchiveState()==ArchiveStream::Save || stream.getRestoreVersion() == getMinorVersion())
            stream & rgap_;

    }

    void ContactModelLinearCBond::copy(const ContactModel *cm) {
        ContactModelMechanical::copy(cm);
        const ContactModelLinearCBond *in = dynamic_cast<const ContactModelLinearCBond*>(cm);
        if (!in) throw std::runtime_error("Internal error: contact model dynamic cast failed.");
        kn(in->kn());
        ks(in->ks());
        fric(in->fric());
        lin_F(in->lin_F());
        lin_S(in->lin_S());
        lin_mode(in->lin_mode());
        rgap(in->rgap());
        cb_state(in->cb_state());
        cb_tenF(in->cb_tenF());
        cb_shearF(in->cb_shearF());
        if (in->hasDamping()) {
            if (!dpProps_)
                dpProps_ = NEWC(dpProps());
            dp_nratio(in->dp_nratio()); 
            dp_sratio(in->dp_sratio()); 
            dp_mode(in->dp_mode()); 
            dp_F(in->dp_F()); 
        }
        if (in->hasEnergies()) {
            if (!energies_)
                energies_ = NEWC(Energies());
            estrain(in->estrain());
            eslip(in->eslip());
            edashpot(in->edashpot());
        }

        inheritanceField(in->inheritanceField());
        effectiveTranslationalStiffness(in->effectiveTranslationalStiffness());
    }

    QVariant ContactModelLinearCBond::getProperty(uint i,const IContact *con) const {
        QVariant var;
        bool nstr = false;
        switch (i) {
        case kwKn:        return kn_;
        case kwKs:        return ks_;
        case kwFric:      return fric_;
        case kwLinF:      var.setValue(lin_F_); return var;
        case kwLinS:      return lin_S_;
        case kwLinMode:   return lin_mode_;
        case kwRGap:      return rgap_;
        case kwEmod:      {
                               const IContactMechanical *c(convert_getcast<IContactMechanical>(con));
                               if (c ==nullptr) return 0.0;
                               double rsq(std::max(c->getEnd1Curvature().y(),c->getEnd2Curvature().y()));
                               double rsum(0.0);
                               if (c->getEnd1Curvature().y())
                                   rsum += 1.0/c->getEnd1Curvature().y();
                               if (c->getEnd2Curvature().y())
                                   rsum += 1.0/c->getEnd2Curvature().y();
#ifdef TWOD                    
                               return (kn_ * rsum * rsq / 2.0);
#else                          
                               return (kn_ * rsum * rsq * rsq) / dPi;
#endif                         
                          }
        case kwKRatio:    return (ks_ == 0.0) ? 0.0 : (kn_/ks_);
        case kwDpNRatio:  return dpProps_ ? dpProps_->dp_nratio_ : 0;
        case kwDpSRatio:  return dpProps_ ? dpProps_->dp_sratio_ : 0;
        case kwDpMode:    return dpProps_ ? dpProps_->dp_mode_ : 0;
        case kwDpF:       {
                               dpProps_ ? var.setValue(dpProps_->dp_F_) : var.setValue(DVect(0.0));
                               return var;
                          }
        case kwCbState:   return cb_state_;
        case kwCbTenF:    return cb_tenF_;
        case kwCbShearF:  return cb_shearF_;
        case kwCbTStr:    nstr = true;
        case kwCbSStr:    {
                               const IContactMechanical *c(convert_getcast<IContactMechanical>(con));
                               if (c ==nullptr) return 0.0;
                               double tmp(std::max(c->getEnd1Curvature().y(),c->getEnd2Curvature().y()));
                               if (nstr) {
#ifdef TWOD                  
                                   return (cb_tenF_ * tmp / 2.0);
#else
                                   return (cb_tenF_ * tmp * tmp / dPi);
#endif                    
                               } else {
#ifdef TWOD
                                   return (cb_shearF_ * tmp / 2.0);
#else                    
                                   return (cb_shearF_ * tmp * tmp / dPi);
#endif
                               }
                          }
        }
        assert(0);
        return QVariant();
    }

    bool ContactModelLinearCBond::getPropertyGlobal(uint i) const {
        switch (i) {
        case kwLinF:   
        case kwDpF:  
            return false;
        }
        return true;
    }

    bool ContactModelLinearCBond::setProperty(uint i,const QVariant &v,IContact *) {
        dpProps dp;
        switch (i) {
        case kwKn: {
                 if (!v.canConvert<double>())
                    throw Exception("kn must be a double.");
                double val(v.toDouble());
                if (val<0.0)
                    throw Exception("Negative kn not allowed.");
                kn_ = val;
                return true;
            }
        case kwKs: {
                 if (!v.canConvert<double>())
                    throw Exception("ks must be a double.");
                double val(v.toDouble());
                if (val<0.0)
                    throw Exception("Negative ks not allowed.");
                ks_ = val;  
                return true;
            }
        case kwFric: {
                 if (!v.canConvert<double>())
                    throw Exception("fric must be a double.");
                double val(v.toDouble());
                if (val<0.0)
                    throw Exception("Negative fric not allowed.");
                fric_ = val;  
                return false;
            }
        case kwCbTenF: {
                 if (!v.canConvert<double>())
                    throw Exception("cb_tenf must be a double.");
                double val(v.toDouble());
                if (val<0.0)
                    throw Exception("Negative cb_tenf not allowed.");
                cb_tenF_ = val;
                return false;
            }
        case kwCbShearF: {
                 if (!v.canConvert<double>())
                    throw Exception("cb_shearf must be a double.");
                double val(v.toDouble());
                if (val<0.0)
                    throw Exception("Negative cb_shearf not allowed.");
                cb_shearF_ = val;
                return false;
            }
        case kwLinF: {
                 if (!v.canConvert<DVect>())
                    throw Exception("lin_force must be a vector.");
                DVect val(v.value<DVect>());
                lin_F_ = val;
                return false;
            }
        case kwLinMode: {
                 if (!v.canConvert<uint>())
                    throw Exception("lin_mode must be 0 (absolute) or 1 (incremental).");
                uint val(v.toUInt());
                if (val>1)
                    throw Exception("lin_mode must be 0 (absolute) or 1 (incremental).");
                lin_mode_ = val;
                return false;
            }
        case kwRGap: {
                if (!v.canConvert<double>())
                    throw Exception("Reference gap must be a double.");
                double val(v.toDouble());
                rgap_ = val;  
                return false;
            }
        case kwDpNRatio: {
                 if (!v.canConvert<double>())
                    throw Exception("dp_nratio must be a double.");
                double val(v.toDouble());
                if (val<0.0)
                    throw Exception("Negative dp_nratio not allowed.");
                if (val == 0.0 && !dpProps_)
                    return false;
                if (!dpProps_)
                    dpProps_ = NEWC(dpProps());
                dpProps_->dp_nratio_ = val; 
                return true;
            }
        case kwDpSRatio: {
                 if (!v.canConvert<double>())
                    throw Exception("dp_sratio must be a double.");
                double val(v.toDouble());
                if (val<0.0)
                    throw Exception("Negative dp_sratio not allowed.");
                if (val == 0.0 && !dpProps_)
                    return false;
                if (!dpProps_)
                    dpProps_ = NEWC(dpProps());
                dpProps_->dp_sratio_ = val;
                return true;
            }
        case kwDpMode: {
                 if (!v.canConvert<int>())
                    throw Exception("The viscous mode dp_mode must be 0, 1, 2, or 3.");
               int val(v.toInt());
                if (val == 0 && !dpProps_)
                    return false;
                if (val < 0 || val > 3)
                    throw Exception("The dashpot mode dp_mode must be 0, 1, 2, or 3.");
                if (!dpProps_)
                    dpProps_ = NEWC(dpProps());
                dpProps_->dp_mode_ = val;
                return false;
            }
        case kwDpF: {
                 if (!v.canConvert<DVect>())
                    throw Exception("dp_force must be a vector.");
                DVect val(v.value<DVect>());
                if (val.fsum() == 0.0 && !dpProps_)
                    return false;
                if (!dpProps_)
                    dpProps_ = NEWC(dpProps());
                dpProps_->dp_F_ = val;
                return false;
            }
        }
        return false;
    }

    bool ContactModelLinearCBond::getPropertyReadOnly(uint i) const {
        switch (i) {
        case kwDpF:
        case kwLinS:
        case kwEmod:
        case kwKRatio:
        case kwCbState:
        case kwCbTStr:
        case kwCbSStr:
            return true;
        default:
            break;
        }
        return false;
    }

    bool ContactModelLinearCBond::supportsInheritance(uint i) const {
        switch (i) {
        case kwKn:
        case kwKs:
        case kwFric:
            return true;
        default:
            break;
        }
        return false;
    }

    QString  ContactModelLinearCBond::getMethodArguments(uint i) const {
        switch (i) {
        case kwCbBond: 
            return "gap";
        case kwDeformability:
            return "emod,kratio";
        case kwCbStrength: 
            return "tensile,shear";
        case kwCbUnbond: 
            return "gap";
        }
        assert(0);
        return "";
    }

    bool ContactModelLinearCBond::setMethod(uint i,const QVector<QVariant> &vl,IContact *con) {
        IContactMechanical *c(convert_getcast<IContactMechanical>(con));
        switch (i) {
        case kwCbBond: {
                if (cb_state_ == 3) return false;
                double mingap = -1.0 * limits<double>::max();
                double maxgap = 0;
                if (vl.at(0).canConvert<Double>()) 
                    maxgap = vl.at(0).toDouble();
                else if (vl.at(0).canConvert<DVect2>()) {
                    DVect2 value = vl.at(0).value<DVect2>();
                    mingap = value.minComp();
                    maxgap = value.maxComp();
                } else if (!vl.at(0).isNull())
                    throw Exception("gap value %1 not recognized in method bond in contact model %2.",vl.at(0),getName());

                double gap = c->getGap(); 
                if (  gap >= mingap && gap <= maxgap)
                    cb_state_ = 3;
                return false;
            }
        case kwCbUnbond: {
                if (cb_state_ == 0) return false;
                double mingap = -1.0 * limits<double>::max();
                double maxgap = 0;
                if (vl.at(0).canConvert<double>()) 
                    maxgap = vl.at(0).toDouble();
                else if (vl.at(0).canConvert<DVect2>()) {
                    DVect2 value = vl.at(0).value<DVect2>();
                    mingap = value.minComp();
                    maxgap = value.maxComp();
                }
                else if (!vl.at(0).isNull())
                    throw Exception("gap value %1 not recognized in method unbond in contact model %2.",vl.at(0),getName());

                double gap = c->getGap(); 
                if (  gap >= mingap && gap <= maxgap)
                    cb_state_ = 0;
                return false;
            }
        case kwDeformability: {
                double emod(0.0);
                double krat(0.0);
                if (vl.at(0).isNull()) 
                    throw Exception("Argument emod must be specified with method deformability in contact model %1.",getName());
                emod = vl.at(0).toDouble();
                if (emod<0.0)
                    throw Exception("Negative emod not allowed in contact model %1.",getName());
                if (vl.at(1).isNull()) 
                    throw Exception("Argument kratio must be specified with method deformability in contact model %1.",getName());
                krat = vl.at(1).toDouble();
                if (krat<0.0)
                    throw Exception("Negative linear stiffness ratio not allowed in contact model %1.",getName());
                double rsq(std::max(c->getEnd1Curvature().y(),c->getEnd2Curvature().y()));
                double rsum(0.0);
                if (c->getEnd1Curvature().y())
                    rsum += 1.0/c->getEnd1Curvature().y();
                if (c->getEnd2Curvature().y())
                    rsum += 1.0/c->getEnd2Curvature().y();
#ifdef TWOD
                kn_ = 2.0 * emod / (rsq * rsum);
#else
                kn_ = dPi * emod / (rsq * rsq * rsum);
#endif
                ks_ = (krat == 0.0) ? 0.0 : kn_ / krat;
                setInheritance(1,false);
                setInheritance(2,false);
                return true;
            }
        case kwCbStrength: {
                if (cb_state_ != 3) return false;
                double nval(0.0);
                double sval(0.0);
                if (vl.at(0).isNull()) 
                    throw Exception("tensile value must be specified with method cb_strength in contact model %1.",getName());
                nval = vl.at(0).toDouble();
                if (nval<0.0)
                    throw Exception("Negative tensile strength not allowed in contact model %1.",getName());
                if (vl.at(1).isNull()) 
                    throw Exception("shear value must be specified with method cb_strength in contact model %1.",getName());
                sval = vl.at(1).toDouble();
                if (sval<0.0)
                    throw Exception("Negative shear strength not allowed in contact model %1.",getName());
                double tmp(std::max(c->getEnd1Curvature().y(),c->getEnd2Curvature().y()));
#ifdef TWOD
                cb_tenF_   = nval * 2.0 / tmp;
                cb_shearF_ = sval * 2.0 / tmp;
#else
                cb_tenF_   = nval * dPi / ( tmp * tmp );
                cb_shearF_ = sval * dPi / (tmp * tmp);
#endif
                return false;
            }
        }
        return false;
    }

    double ContactModelLinearCBond::getEnergy(uint i) const {
        double ret(0.0);
        if (!energies_)
            return ret;
        switch (i) {
        case kwEStrain:  return energies_->estrain_;
        case kwESlip:    return energies_->eslip_;
        case kwEDashpot: return energies_->edashpot_;
        }
        assert(0);
        return ret;
    }

    bool ContactModelLinearCBond::getEnergyAccumulate(uint i) const {
        switch (i) {
        case kwEStrain:  return false;
        case kwESlip:    return true;
        case kwEDashpot: return true;
        }
        assert(0);
        return false;
    }

    void ContactModelLinearCBond::setEnergy(uint i,const double &d) {
        if (!energies_) return;
        switch (i) {
        case kwEStrain:  energies_->estrain_ = d; return;  
        case kwESlip:    energies_->eslip_   = d; return;
        case kwEDashpot: energies_->edashpot_= d; return;
        }
        assert(0);
        return;
    }

    bool ContactModelLinearCBond::validate(ContactModelMechanicalState *state,const double &) {
        assert(state);
        const IContactMechanical *c = state->getMechanicalContact(); 
        assert(c);

        if (state->trackEnergy_)
            activateEnergy();

        if (inheritanceField_ & linKnMask)
            updateKn(c);
        if (inheritanceField_ & linKsMask)
            updateKs(c);
        if (inheritanceField_ & linFricMask)
            updateFric(c);

        updateEffectiveStiffness(state);
        return checkActivity(state->gap_);
    }

    static const QString knstr("kn");
    bool ContactModelLinearCBond::updateKn(const IContactMechanical *con) {
        assert(con);
        QVariant v1 = con->getEnd1()->getProperty(knstr);
        QVariant v2 = con->getEnd2()->getProperty(knstr);
        if (!v1.isValid() || !v2.isValid())
            return false;
        double kn1 = v1.toDouble();
        double kn2 = v2.toDouble();
        double val = kn_;
        if (kn1 && kn2)
            kn_ = kn1*kn2/(kn1+kn2);
        else if (kn1)
            kn_ = kn1;
        else if (kn2)
            kn_ = kn2;
        return ( (kn_ != val) );
    }

    static const QString ksstr("ks");
    bool ContactModelLinearCBond::updateKs(const IContactMechanical *con) {
        assert(con);
        QVariant v1 = con->getEnd1()->getProperty(ksstr);
        QVariant v2 = con->getEnd2()->getProperty(ksstr);
        if (!v1.isValid() || !v2.isValid())
            return false;
        double ks1 = v1.toDouble();
        double ks2 = v2.toDouble();
        double val = ks_;
        if (ks1 && ks2)
            ks_ = ks1*ks2/(ks1+ks2);
        else if (ks1)
            ks_ = ks1;
        else if (ks2)
            ks_ = ks2;
        return ( (ks_ != val) );
    }

    static const QString fricstr("fric");
    bool ContactModelLinearCBond::updateFric(const IContactMechanical *con) {
        assert(con);
        QVariant v1 = con->getEnd1()->getProperty(fricstr);
        QVariant v2 = con->getEnd2()->getProperty(fricstr);
        if (!v1.isValid() || !v2.isValid())
            return false;
        double fric1 = std::max(0.0,v1.toDouble());
        double fric2 = std::max(0.0,v2.toDouble());
        double val = fric_;
        fric_ = std::min(fric1,fric2);
        return ( (fric_ != val) );
    }

    bool ContactModelLinearCBond::endPropertyUpdated(const QString &name,const IContactMechanical *c) {
        assert(c);
        QStringList availableProperties = getProperties().simplified().replace(" ","").split(",",QString::SkipEmptyParts);
        QRegExp rx(name,Qt::CaseInsensitive);
        int idx = availableProperties.indexOf(rx)+1;
        bool ret=false;

        if (idx<=0)
            return ret;
         
        switch(idx) {
        case kwKn:  { //kn
                if (inheritanceField_ & linKnMask)
                    ret = updateKn(c);
                break;
            }
        case kwKs:  { //ks
                if (inheritanceField_ & linKsMask)
                    ret =updateKs(c);
                break;
            }
        case kwFric:  { //fric
                if (inheritanceField_ & linFricMask)
                    updateFric(c);
                break;
            }
        }
        return ret;
    }

    void ContactModelLinearCBond::updateEffectiveStiffness(ContactModelMechanicalState *) {
        DVect2 ret(kn_,ks_);
        // correction if viscous damping active
        if (dpProps_) {
            DVect2 correct(1.0);
            if (dpProps_->dp_nratio_)
                correct.rx() = sqrt(1.0+dpProps_->dp_nratio_*dpProps_->dp_nratio_) - dpProps_->dp_nratio_;
            if (dpProps_->dp_sratio_)
                correct.ry() = sqrt(1.0+dpProps_->dp_sratio_*dpProps_->dp_sratio_) - dpProps_->dp_sratio_;
            ret /= (correct*correct);
        }
        effectiveTranslationalStiffness_ = ret;
    }
     
    bool ContactModelLinearCBond::forceDisplacementLaw(ContactModelMechanicalState *state,const double &timestep) {
        assert(state);

        double overlap = rgap_ - state->gap_;
        DVect trans = state->relativeTranslationalIncrement_;
        double correction = 1.0;

        if (state->activated()) {
            if (cmEvents_[fActivated] >= 0) {
                FArray<QVariant,2> arg;
                QVariant v;
                IContact * c = const_cast<IContact*>(state->getContact());
                TPtr<IThing> t(c->getIThing());
                v.setValue(t);
                arg.push_back(v);
                IFishCallList *fi = const_cast<IFishCallList*>(state->getProgram()->findInterface<IFishCallList>());
                fi->setCMFishCallArguments(c,arg,cmEvents_[fActivated]);
            }
            if (lin_mode_ == 0 && trans.x()) {
                correction = -1.0*overlap / trans.x();
                if (correction < 0)
                    correction = 1.0;
            }
        }

#ifdef THREED
        DVect norm(trans.x(),0.0,0.0);
#else
        DVect norm(trans.x(),0.0);
#endif
        DAVect ang  = state->relativeAngularIncrement_;
        DVect lin_F_old = lin_F_;

        if (lin_mode_ == 0)
            lin_F_.rx() = overlap * kn_;
        else
          lin_F_.rx() -= correction * norm.x() * kn_;

        DVect u_s = trans;
        u_s.rx() = 0.0;
        DVect sforce = lin_F_ - u_s * ks_ * correction;
        sforce.rx() = 0.0;

        // Resolve failure (contact bonds and friction)
        if (state->canFail_) {
            // Resolve contact bond failure - done first so that this way, even if breaks, one can ensure a valid sliding state
            if (cb_state_ == 3)  { // bonded - Note: this means that isSliding is false!
                if (lin_F_.x() <= -cb_tenF_) {
                    // Broke in tension
                    cb_state_ = 1;
                    if (cmEvents_[fBondBreak] >= 0) {
                        FArray<QVariant,3> arg;
                        QVariant p1;
                        IContact * c = const_cast<IContact*>(state->getContact());
                        TPtr<IThing> t(c->getIThing());
                        p1.setValue(t);
                        arg.push_back(p1);
                        p1.setValue(cb_state_);
                        arg.push_back(p1);
                        p1.setValue(cb_tenF_);
                        arg.push_back(p1);
                        IFishCallList *fi = const_cast<IFishCallList*>(state->getProgram()->findInterface<IFishCallList>());
                        fi->setCMFishCallArguments(c,arg,cmEvents_[fBondBreak]);
                    }
                } else if (sforce.mag() >= cb_shearF_) {
                    // Broke in shear
                    cb_state_ = 2;
                    if (cmEvents_[fBondBreak] >= 0) {
                        FArray<QVariant,3> arg;
                        QVariant p1;
                        IContact * c = const_cast<IContact*>(state->getContact());
                        TPtr<IThing> t(c->getIThing());
                        p1.setValue(t);
                        arg.push_back(p1);
                        p1.setValue(cb_state_);
                        arg.push_back(p1);
                        p1.setValue(cb_shearF_);
                        arg.push_back(p1);
                        IFishCallList *fi = const_cast<IFishCallList*>(state->getProgram()->findInterface<IFishCallList>());
                        fi->setCMFishCallArguments(c,arg,cmEvents_[fBondBreak]);
                    }
                }
            }

            // 2) Resolve sliding if no contact bond exists
            if (cb_state_ < 3) {
                // No contact bond - normal force is positive only
                lin_F_.rx() = std::max(0.0,lin_F_.x());
                // No contact bond - sliding can occur
                double crit = lin_F_.x() * fric_;
                double sfmag = sforce.mag();
                if (sfmag > crit) {
                    double rat = crit / sfmag;
                    sforce *= rat;
                    if (!lin_S_ && cmEvents_[fSlipChange] >= 0) {
                        FArray<QVariant,3> arg;
                        QVariant p1;
                        IContact * c = const_cast<IContact*>(state->getContact());
                        TPtr<IThing> t(c->getIThing());
                        p1.setValue(t);
                        arg.push_back(p1);
                        p1.setValue(0);
                        arg.push_back(p1);
                        IFishCallList *fi = const_cast<IFishCallList*>(state->getProgram()->findInterface<IFishCallList>());
                        fi->setCMFishCallArguments(c,arg,cmEvents_[fSlipChange]);
                    }
                    lin_S_ = true;
                } else {
                    if (lin_S_) {
                        if (cmEvents_[fSlipChange] >= 0) {
                            FArray<QVariant,3> arg;
                            QVariant p1;
                            IContact * c = const_cast<IContact*>(state->getContact());
                            TPtr<IThing> t(c->getIThing());
                            p1.setValue(t);
                            arg.push_back(p1);
                            p1.setValue(1);
                            arg.push_back(p1);
                            IFishCallList *fi = const_cast<IFishCallList*>(state->getProgram()->findInterface<IFishCallList>());
                            fi->setCMFishCallArguments(c,arg,cmEvents_[fSlipChange]);
                        }
                        lin_S_ = false;
                    }
                }
            }
        }

        sforce.rx() = lin_F_.x();
        lin_F_ = sforce;          // total force in linear contact model
        state->force_  = lin_F_;
         
        // 3) Account for dashpot forces
        if (dpProps_) {
            dpProps_->dp_F_.fill(0.0);
            double vcn(0.0), vcs(0.0);
            setDampCoefficients(state->inertialMass_,&vcn,&vcs);
            // First damp all components
            dpProps_->dp_F_ = u_s * (-1.0* vcs) / timestep; // shear component   
            dpProps_->dp_F_ -= norm * vcn / timestep;       // normal component
            // Need to change behavior based on the dp_mode
            if (cb_state_ !=3 && (dpProps_->dp_mode_ == 1 || dpProps_->dp_mode_ == 3))  { // limit the tensile if not bonded
                if (dpProps_->dp_F_.x() + lin_F_.x() < 0)
                    dpProps_->dp_F_.rx() = - lin_F_.rx();
            }
            if (lin_S_ && dpProps_->dp_mode_ > 1)  { // limit the shear if not sliding
                double dfn = dpProps_->dp_F_.rx();
                dpProps_->dp_F_.fill(0.0); 
                dpProps_->dp_F_.rx() = dfn; 
            }
            state->force_ += dpProps_->dp_F_;
        }

        // 5) Compute energies
        if (state->trackEnergy_) {
            assert(energies_);
            energies_->estrain_ =  0.0;
            if (kn_)
                energies_->estrain_ = 0.5*lin_F_.x()*lin_F_.x()/kn_;
            if (ks_) {
                DVect s = lin_F_;
                s.rx() = 0.0;
                double smag2 = s.mag2();
                energies_->estrain_ += 0.5*smag2 / ks_;

                if (lin_S_) {
                    lin_F_old.rx() = 0.0;
                    DVect avg_F_s = (s + lin_F_old)*0.5;
                    DVect u_s_el =  (s - lin_F_old) / ks_;
                    energies_->eslip_ -= std::min(0.0,(avg_F_s | (u_s + u_s_el)));
                }
            }
            if (dpProps_) {
                energies_->edashpot_ -= dpProps_->dp_F_ | trans;
            }
        }

        state->momentOn1_.fill(0.0);
        state->momentOn2_.fill(0.0);
        // The state force has been updated - update the state with the resulting torques
        state->getMechanicalContact()->updateResultingTorquesLocal(state->force_,&state->momentOn1_,&state->momentOn2_);

        assert(lin_F_ == lin_F_);
        return checkActivity(state->gap_);
    }

    void ContactModelLinearCBond::propagateStateInformation(IContactModelMechanical* old,const CAxes &oldSystem,const CAxes &newSystem) {
        // Only do something if the contact model is of the same type
        if (old->getContactModel()->getName().compare("linearcbond",Qt::CaseInsensitive) == 0 && !isBonded()) {
            ContactModelLinearCBond *oldCm = (ContactModelLinearCBond *)old;
#ifdef THREED
            // Need to rotate just the shear component from oldSystem to newSystem

            // Step 1 - rotate oldSystem so that the normal is the same as the normal of newSystem
            DVect axis = oldSystem.e1() & newSystem.e1();
            double c, ang, s;
            DVect re2;
            if (!checktol(axis.abs().maxComp(),0.0,1.0,1000)) {
                axis = axis.unit();
                c = oldSystem.e1()|newSystem.e1();
                if (c > 0)
                    c = std::min(c,1.0);
                else
                    c = std::max(c,-1.0);
                ang = acos(c);
                s = sin(ang);
                double t = 1. - c;
                DMatrix<3,3> rm;
                rm.get(0,0) = t*axis.x()*axis.x() + c;
                rm.get(0,1) = t*axis.x()*axis.y() - axis.z()*s;
                rm.get(0,2) = t*axis.x()*axis.z() + axis.y()*s;
                rm.get(1,0) = t*axis.x()*axis.y() + axis.z()*s;
                rm.get(1,1) = t*axis.y()*axis.y() + c;
                rm.get(1,2) = t*axis.y()*axis.z() - axis.x()*s;
                rm.get(2,0) = t*axis.x()*axis.z() - axis.y()*s;
                rm.get(2,1) = t*axis.y()*axis.z() + axis.x()*s;
                rm.get(2,2) = t*axis.z()*axis.z() + c;
                re2 = rm*oldSystem.e2();
            }
            else
                re2 = oldSystem.e2();
            // Step 2 - get the angle between the oldSystem rotated shear and newSystem shear
            axis = re2 & newSystem.e2();
            DVect2 tpf;
            DMatrix<2,2> m;
            if (!checktol(axis.abs().maxComp(),0.0,1.0,1000)) {
                axis = axis.unit();
                c = re2|newSystem.e2();
                if (c > 0)
                    c = std::min(c,1.0);
                else
                    c = std::max(c,-1.0);
                ang = acos(c);
                if (!checktol(axis.x(),newSystem.e1().x(),1.0,100))
                    ang *= -1;
                s = sin(ang);
                m.get(0,0) = c;
                m.get(1,0) = s;
                m.get(0,1) = -m.get(1,0);
                m.get(1,1) = m.get(0,0);
                tpf = m*DVect2(oldCm->lin_F_.y(),oldCm->lin_F_.z());
            } else {
                m.get(0,0) = 1.;
                m.get(0,1) = 0.;
                m.get(1,0) = 0.;
                m.get(1,1) = 1.;
                tpf = DVect2(oldCm->lin_F_.y(),oldCm->lin_F_.z());
            }
            DVect pforce = DVect(0,tpf.x(),tpf.y());
#else
            oldSystem;
            newSystem;
            DVect pforce = DVect(0,oldCm->lin_F_.y());
#endif
            for (int i=1; i<dim; ++i)
                lin_F_.rdof(i) += pforce.dof(i);
            oldCm->lin_F_ = DVect(0.0);
            if (dpProps_ && oldCm->dpProps_) {
#ifdef THREED
                tpf = m*DVect2(oldCm->dpProps_->dp_F_.y(),oldCm->dpProps_->dp_F_.z());
                pforce = DVect(oldCm->dpProps_->dp_F_.x(),tpf.x(),tpf.y());
#else
                pforce = oldCm->dpProps_->dp_F_;
#endif
                dpProps_->dp_F_ += pforce;
                oldCm->dpProps_->dp_F_ = DVect(0.0);
            }
            if(oldCm->getEnergyActivated()) {
                activateEnergy();
                energies_->estrain_  = oldCm->energies_->estrain_;
                energies_->eslip_    = oldCm->energies_->eslip_;
                energies_->edashpot_ = oldCm->energies_->edashpot_;
                oldCm->energies_->estrain_ = 0.0;
                oldCm->energies_->edashpot_ = 0.0;
                oldCm->energies_->eslip_ = 0.0;
            }
            rgap_ = oldCm->rgap_;
        }
        assert(lin_F_ == lin_F_);
    }

    void ContactModelLinearCBond::setNonForcePropsFrom(IContactModel *old) {
        // Only do something if the contact model is of the same type
        if (old->getName().compare("linearcbond",Qt::CaseInsensitive) == 0 && !isBonded()) {
            ContactModelLinearCBond *oldCm = (ContactModelLinearCBond *)old;
            kn_ = oldCm->kn_;
            ks_ = oldCm->ks_;
            fric_ = oldCm->fric_;
            lin_mode_ = oldCm->lin_mode_;
            rgap_ = oldCm->rgap_;

            if (oldCm->dpProps_) {
                if (!dpProps_)
                    dpProps_ = NEWC(dpProps());
                dpProps_->dp_nratio_ = oldCm->dpProps_->dp_nratio_;
                dpProps_->dp_sratio_ = oldCm->dpProps_->dp_sratio_;
                dpProps_->dp_mode_ = oldCm->dpProps_->dp_mode_;
            }
        }
    }

    void ContactModelLinearCBond::setDampCoefficients(const double &mass,double *vcn,double *vcs) {
        *vcn = dpProps_->dp_nratio_ * 2.0 * sqrt(mass*(kn_));
        *vcs = dpProps_->dp_sratio_ * 2.0 * sqrt(mass*(ks_));
    }

} // namespace itascaxd
// EoF

Top