1 // ============================================================================= 2 // PROJECT CHRONO - http://projectchrono.org 3 // 4 // Copyright (c) 2014 projectchrono.org 5 // All rights reserved. 6 // 7 // Use of this source code is governed by a BSD-style license that can be found 8 // in the LICENSE file at the top level of the distribution and at 9 // http://projectchrono.org/license-chrono.txt. 10 // 11 // ============================================================================= 12 // Authors: Alessandro Tasora, Radu Serban 13 // ============================================================================= 14 15 #ifndef CHSHAFTSCOUPLE_H 16 #define CHSHAFTSCOUPLE_H 17 18 #include "chrono/physics/ChShaft.h" 19 20 namespace chrono { 21 22 /// Base class for defining constraints between a couple of two one-degree-of-freedom 23 /// parts; i.e., shafts that can be used to build 1D models of powertrains. 24 25 class ChApi ChShaftsCouple : public ChPhysicsItem { 26 27 protected: 28 ChShaft* shaft1; ///< first shaft 29 ChShaft* shaft2; ///< second shaft 30 31 public: ChShaftsCouple()32 ChShaftsCouple() : shaft1(nullptr), shaft2(nullptr) {} ChShaftsCouple(const ChShaftsCouple & other)33 ChShaftsCouple(const ChShaftsCouple& other) : ChPhysicsItem(other) {} ~ChShaftsCouple()34 ~ChShaftsCouple() {} 35 36 /// "Virtual" copy constructor (covariant return type). Clone()37 virtual ChShaftsCouple* Clone() const override { return new ChShaftsCouple(*this); } 38 39 /// Get the number of scalar variables affected by constraints in this link GetNumCoords()40 virtual int GetNumCoords() { return 2; } 41 42 /// Use this function after gear creation, to initialize it, given two shafts to join. 43 /// Each shaft must belong to the same ChSystem. 44 /// Derived classes might overload this (here, basically it only sets the two pointers) Initialize(std::shared_ptr<ChShaft> mshaft1,std::shared_ptr<ChShaft> mshaft2)45 virtual bool Initialize(std::shared_ptr<ChShaft> mshaft1, ///< first shaft to join 46 std::shared_ptr<ChShaft> 47 mshaft2 ///< second shaft to join 48 ) { 49 ChShaft* mm1 = mshaft1.get(); 50 ChShaft* mm2 = mshaft2.get(); 51 assert(mm1 && mm2); 52 assert(mm1 != mm2); 53 assert(mm1->GetSystem() == mm2->GetSystem()); 54 shaft1 = mm1; 55 shaft2 = mm2; 56 SetSystem(shaft1->GetSystem()); 57 return true; 58 } 59 60 /// Get the first (input) shaft GetShaft1()61 ChShaft* GetShaft1() { return shaft1; } 62 /// Get the second (output) shaft GetShaft2()63 ChShaft* GetShaft2() { return shaft2; } 64 65 /// Get the reaction torque exchanged between the two shafts, 66 /// considered as applied to the 1st axis. 67 /// Children classes might overload this. GetTorqueReactionOn1()68 virtual double GetTorqueReactionOn1() const { return 0; } 69 70 /// Get the reaction torque exchanged between the two shafts, 71 /// considered as applied to the 2nd axis. 72 /// Children classes might overload this. GetTorqueReactionOn2()73 virtual double GetTorqueReactionOn2() const { return 0; } 74 75 /// Get the actual relative angle in terms of phase of shaft 1 respect to 2. GetRelativeRotation()76 double GetRelativeRotation() const { return (this->shaft1->GetPos() - this->shaft2->GetPos()); } 77 /// Get the actual relative speed in terms of speed of shaft 1 respect to 2. GetRelativeRotation_dt()78 double GetRelativeRotation_dt() const { return (this->shaft1->GetPos_dt() - this->shaft2->GetPos_dt()); } 79 /// Get the actual relative acceleration in terms of speed of shaft 1 respect to 2. GetRelativeRotation_dtdt()80 double GetRelativeRotation_dtdt() const { return (this->shaft1->GetPos_dtdt() - this->shaft2->GetPos_dtdt()); } 81 82 // 83 // SERIALIZATION 84 // 85 ArchiveOUT(ChArchiveOut & marchive)86 virtual void ArchiveOUT(ChArchiveOut& marchive) override { 87 // version number 88 marchive.VersionWrite<ChShaftsCouple>(); 89 90 // serialize parent class 91 ChPhysicsItem::ArchiveOUT(marchive); 92 93 // serialize all member data: 94 // marchive << CHNVP(shaft1); //***TODO*** serialize, with shared ptr 95 // marchive << CHNVP(shaft2); //***TODO*** serialize, with shared ptr 96 } 97 98 /// Method to allow de serialization of transient data from archives. ArchiveIN(ChArchiveIn & marchive)99 virtual void ArchiveIN(ChArchiveIn& marchive) override { 100 // version number 101 /*int version =*/ marchive.VersionRead<ChShaftsCouple>(); 102 103 // deserialize parent class: 104 ChPhysicsItem::ArchiveIN(marchive); 105 106 // deserialize all member data: 107 // marchive >> CHNVP(shaft1); //***TODO*** serialize, with shared ptr 108 // marchive >> CHNVP(shaft2); //***TODO*** serialize, with shared ptr 109 } 110 }; 111 112 CH_CLASS_VERSION(ChShaftsCouple,0) 113 114 } // end namespace chrono 115 116 #endif 117