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 CHNODEXYZ_H 16 #define CHNODEXYZ_H 17 18 #include "chrono/physics/ChLoadable.h" 19 #include "chrono/physics/ChNodeBase.h" 20 #include "chrono/solver/ChVariablesBodyOwnMass.h" 21 #include "chrono/solver/ChVariablesNode.h" 22 23 namespace chrono { 24 25 /// Class for a single 'point' node, that has 3 DOF degrees of freedom and a mass. 26 27 class ChApi ChNodeXYZ : public virtual ChNodeBase, public ChLoadableUVW { 28 29 public: 30 ChNodeXYZ(); 31 ChNodeXYZ(const ChVector<>& initial_pos); 32 ChNodeXYZ(const ChNodeXYZ& other); ~ChNodeXYZ()33 virtual ~ChNodeXYZ() {} 34 35 ChNodeXYZ& operator=(const ChNodeXYZ& other); 36 37 // 38 // FUNCTIONS 39 // 40 41 // Access the xyz 'variables' of the node 42 virtual ChVariablesNode& Variables() = 0; 43 44 // Position of the node - in absolute csys. GetPos()45 const ChVector<>& GetPos() const { return pos; } 46 // Position of the node - in absolute csys. SetPos(const ChVector<> & mpos)47 void SetPos(const ChVector<>& mpos) { pos = mpos; } 48 49 // Velocity of the node - in absolute csys. GetPos_dt()50 const ChVector<>& GetPos_dt() const { return pos_dt; } 51 // Velocity of the node - in absolute csys. SetPos_dt(const ChVector<> & mposdt)52 void SetPos_dt(const ChVector<>& mposdt) { pos_dt = mposdt; } 53 54 // Acceleration of the node - in absolute csys. GetPos_dtdt()55 const ChVector<>& GetPos_dtdt() const { return pos_dtdt; } 56 // Acceleration of the node - in absolute csys. SetPos_dtdt(const ChVector<> & mposdtdt)57 void SetPos_dtdt(const ChVector<>& mposdtdt) { pos_dtdt = mposdtdt; } 58 59 // Get mass of the node. To be implemented in children classes 60 virtual double GetMass() const = 0; 61 // Set mass of the node. To be implemented in children classes 62 virtual void SetMass(double mm) = 0; 63 64 /// Get the number of degrees of freedom Get_ndof_x()65 virtual int Get_ndof_x() const override { return 3; } 66 67 // 68 // INTERFACE to ChLoadable 69 // 70 71 /// Gets the number of DOFs affected by this element (position part) LoadableGet_ndof_x()72 virtual int LoadableGet_ndof_x() override { return 3; } 73 74 /// Gets the number of DOFs affected by this element (speed part) LoadableGet_ndof_w()75 virtual int LoadableGet_ndof_w() override { return 3; } 76 77 /// Gets all the DOFs packed in a single vector (position part) LoadableGetStateBlock_x(int block_offset,ChState & mD)78 virtual void LoadableGetStateBlock_x(int block_offset, ChState& mD) override { 79 mD.segment(block_offset, 3) = pos.eigen(); 80 } 81 82 /// Gets all the DOFs packed in a single vector (speed part) LoadableGetStateBlock_w(int block_offset,ChStateDelta & mD)83 virtual void LoadableGetStateBlock_w(int block_offset, ChStateDelta& mD) override { 84 mD.segment(block_offset, 3) = pos_dt.eigen(); 85 } 86 87 /// Increment all DOFs using a delta. LoadableStateIncrement(const unsigned int off_x,ChState & x_new,const ChState & x,const unsigned int off_v,const ChStateDelta & Dv)88 virtual void LoadableStateIncrement(const unsigned int off_x, ChState& x_new, const ChState& x, const unsigned int off_v, const ChStateDelta& Dv) override { 89 NodeIntStateIncrement(off_x, x_new, x, off_v, Dv); 90 } 91 92 /// Number of coordinates in the interpolated field, ex=3 for a 93 /// tetrahedron finite element or a cable, etc. Here is 6: xyz displ + xyz rots Get_field_ncoords()94 virtual int Get_field_ncoords() override { return 3; } 95 96 /// Get the number of DOFs sub-blocks. GetSubBlocks()97 virtual int GetSubBlocks() override { return 1; } 98 99 /// Get the offset of the specified sub-block of DOFs in global vector. GetSubBlockOffset(int nblock)100 virtual unsigned int GetSubBlockOffset(int nblock) override { return NodeGetOffset_w(); } 101 102 /// Get the size of the specified sub-block of DOFs in global vector. GetSubBlockSize(int nblock)103 virtual unsigned int GetSubBlockSize(int nblock) override { return 3; } 104 105 /// Check if the specified sub-block of DOFs is active. IsSubBlockActive(int nblock)106 virtual bool IsSubBlockActive(int nblock) const override { return true; } 107 108 /// Get the pointers to the contained ChVariables, appending to the mvars vector. LoadableGetVariables(std::vector<ChVariables * > & mvars)109 virtual void LoadableGetVariables(std::vector<ChVariables*>& mvars) override { mvars.push_back(&Variables()); }; 110 111 /// Evaluate Q=N'*F , for Q generalized lagrangian load, where N is some type of matrix 112 /// evaluated at point P(U,V,W) assumed in absolute coordinates, and 113 /// F is a load assumed in absolute coordinates. 114 /// The det[J] is unused. 115 virtual void ComputeNF( 116 const double U, ///< x coordinate of application point in absolute space 117 const double V, ///< y coordinate of application point in absolute space 118 const double W, ///< z coordinate of application point in absolute space 119 ChVectorDynamic<>& Qi, ///< Return result of N'*F here, maybe with offset block_offset 120 double& detJ, ///< Return det[J] here 121 const ChVectorDynamic<>& F, ///< Input F vector, size is 3, it is Force x,y,z in absolute coords. 122 ChVectorDynamic<>* state_x, ///< if != 0, update state (pos. part) to this, then evaluate Q 123 ChVectorDynamic<>* state_w ///< if != 0, update state (speed part) to this, then evaluate Q 124 ) override; 125 126 /// This is not needed because not used in quadrature. GetDensity()127 virtual double GetDensity() override { return 1; } 128 129 // SERIALIZATION 130 131 virtual void ArchiveOUT(ChArchiveOut& marchive) override; 132 virtual void ArchiveIN(ChArchiveIn& marchive) override; 133 134 // 135 // DATA 136 // 137 138 ChVector<> pos; 139 ChVector<> pos_dt; 140 ChVector<> pos_dtdt; 141 }; 142 143 CH_CLASS_VERSION(ChNodeXYZ,0) 144 145 } // end namespace chrono 146 147 #endif 148