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
13 // =============================================================================
14 
15 #ifndef CHLINKBEAMIGASLIDER_H
16 #define CHLINKBEAMIGASLIDER_H
17 
18 #include "chrono/physics/ChBodyFrame.h"
19 #include "chrono/physics/ChLinkBase.h"
20 #include "chrono/solver/ChConstraintNgeneric.h"
21 
22 #include "chrono/fea/ChElementBeamIGA.h"
23 #include "chrono/fea/ChNodeFEAxyzrot.h"
24 
25 namespace chrono {
26 
27 class ChIndexedNodes;  // forward ref
28 
29 namespace fea {
30 
31 /// @addtogroup fea_constraints
32 /// @{
33 
34 /// Class for allowin an IGA beam to slide inside a 'outlet' represented
35 /// by the x axis of a coordinate system floating with a ChBodyFrame.
36 /// The parameteric coordinate of the point of the spline that correspond
37 /// to the outlet is automatically updated during the sliding motion.
38 
39 class ChApi ChLinkBeamIGAslider : public ChLinkBase {
40   private:
41     ChVector<> m_react;
42 
43     // used as an interface to the solver.
44     // ChConstraintNgeneric constraint1;
45     ChConstraintNgeneric constraint2;
46     ChConstraintNgeneric constraint3;
47 
48     std::vector<std::shared_ptr<fea::ChElementBeamIGA>> m_beams;
49     std::shared_ptr<ChBodyFrame> m_body;
50 
51     std::vector<std::shared_ptr<ChNodeFEAxyzrot>> m_nodes;
52 
53     int order;
54     size_t active_element;
55     double tau;
56 
57     // Coordinate system, attached to the body, whose origin is
58     // constrained to coincide with the node's position.
59     ChCoordsys<> m_csys;
60 
61   public:
62     ChLinkBeamIGAslider();
63     ChLinkBeamIGAslider(const ChLinkBeamIGAslider& other);
~ChLinkBeamIGAslider()64     ~ChLinkBeamIGAslider() {}
65 
66     /// "Virtual" copy constructor (covariant return type).
Clone()67     virtual ChLinkBeamIGAslider* Clone() const override { return new ChLinkBeamIGAslider(*this); }
68 
69     /// Get the number of scalar variables affected by constraints in this link
GetNumCoords()70     virtual int GetNumCoords() override { return (int)m_nodes.size() * 3 + 7; }
71 
72     /// Number of scalar constraints.
GetDOC_c()73     virtual int GetDOC_c() override { return 2; }
74 
75     /// Reaction force on the body, at the attachment point, expressed in the link coordinate frame.
Get_react_force()76     virtual ChVector<> Get_react_force() override { return GetReactionOnBody(); }
77 
78     //
79     // STATE FUNCTIONS
80     //
81 
82     // (override/implement interfaces for global state vectors, see ChPhysicsItem for comments.)
83     virtual void IntStateGatherReactions(const unsigned int off_L, ChVectorDynamic<>& L) override;
84     virtual void IntStateScatterReactions(const unsigned int off_L, const ChVectorDynamic<>& L) override;
85     virtual void IntLoadResidual_CqL(const unsigned int off_L,
86                                      ChVectorDynamic<>& R,
87                                      const ChVectorDynamic<>& L,
88                                      const double c) override;
89     virtual void IntLoadConstraint_C(const unsigned int off,
90                                      ChVectorDynamic<>& Qc,
91                                      const double c,
92                                      bool do_clamp,
93                                      double recovery_clamp) override;
94     virtual void IntToDescriptor(const unsigned int off_v,
95                                  const ChStateDelta& v,
96                                  const ChVectorDynamic<>& R,
97                                  const unsigned int off_L,
98                                  const ChVectorDynamic<>& L,
99                                  const ChVectorDynamic<>& Qc) override;
100     virtual void IntFromDescriptor(const unsigned int off_v,
101                                    ChStateDelta& v,
102                                    const unsigned int off_L,
103                                    ChVectorDynamic<>& L) override;
104 
105     // Override/implement system functions of ChPhysicsItem
106     // (to assemble/manage data for system solver)
107 
108     virtual void InjectConstraints(ChSystemDescriptor& mdescriptor) override;
109     virtual void ConstraintsBiReset() override;
110     virtual void ConstraintsBiLoad_C(double factor = 1, double recovery_clamp = 0.1, bool do_clamp = false) override;
111     virtual void ConstraintsBiLoad_Ct(double factor = 1) override;
112     virtual void ConstraintsLoadJacobians() override;
113     virtual void ConstraintsFetch_react(double factor = 1) override;
114 
115     // Other functions
116 
117     virtual ChCoordsys<> GetLinkAbsoluteCoords() override;
118 
119     /// Initialize this constraint, given the node and element(s).
120     /// The attachment position is the actual position of the node (unless
121     /// otherwise defined, using the optional 'pos' parameter).
122     /// Note: the node and body must belong to the same ChSystem.
123     virtual int Initialize(
124         std::vector<std::shared_ptr<fea::ChElementBeamIGA>>& melements,  ///< elements that must slide
125         std::shared_ptr<ChBodyFrame> body,  ///< body (frame) representing the slider outlet
126         ChVector<>* pos = 0                 ///< attachment position in absolute coordinates (X axis is outlet dir)
127     );
128 
129     /// Get the connected elements
GetConstrainedElements()130     std::vector<std::shared_ptr<ChElementBeamIGA>>& GetConstrainedElements() { return m_beams; }
131 
132     /// Get the connected body (frame).
GetConstrainedBodyFrame()133     std::shared_ptr<ChBodyFrame> GetConstrainedBodyFrame() { return m_body; }
134 
135     /// Get the attachment position, in the coordinates of the body.
GetAttachPosition()136     const ChVector<>& GetAttachPosition() const { return m_csys.pos; }
137 
138     /// Get the attachment reference, in the coordinates of the body.
GetAttachReference()139     const ChCoordsys<>& GetAttachReference() const { return m_csys; }
140 
141     /// Set the attachment position, expressed in the coordinates of the body.
142     /// This function may be called only after initialization.
SetAttachPositionInBodyCoords(const ChVector<> & pos_loc)143     void SetAttachPositionInBodyCoords(const ChVector<>& pos_loc) { m_csys.pos = pos_loc; }
144 
145     /// Set the attachment position, expressed in absolute coordinates.
146     /// This function may be called only after initialization.
SetAttachPositionInAbsoluteCoords(const ChVector<> & pos_abs)147     void SetAttachPositionInAbsoluteCoords(const ChVector<>& pos_abs) {
148         m_csys.pos = m_body->TransformPointParentToLocal(pos_abs);
149     }
150 
151     /// Set the attachment reference, expressed in the coordinates of the body.
152     /// This function may be called only after initialization.
SetAttachReferenceInBodyCoords(const ChCoordsys<> & csys_loc)153     void SetAttachReferenceInBodyCoords(const ChCoordsys<>& csys_loc) { m_csys = csys_loc; }
154 
155     /// Set the attachment position, expressed in absolute coordinates.
156     /// This function may be called only after initialization.
SetAttachReferenceInAbsoluteCoords(const ChCoordsys<> & csys_abs)157     void SetAttachReferenceInAbsoluteCoords(const ChCoordsys<>& csys_abs) {
158         m_csys = m_body->coord.TransformParentToLocal(csys_abs);
159     }
160 
161     /// Get the reaction force on the node, expressed in the link coordinate system.
GetReactionOnSpline()162     ChVector<> GetReactionOnSpline() const { return m_react; }
163 
164     /// Get the reaction force on the body, at the attachment point, expressed in the link coordinate system.
GetReactionOnBody()165     ChVector<> GetReactionOnBody() const { return -m_react; }
166 
167     //
168     // UPDATE FUNCTIONS
169     //
170 
171     /// Update all auxiliary data of the gear transmission at given time
172     virtual void Update(double mytime, bool update_assets = true) override;
173 
174     //
175     // STREAMING
176     //
177 
178     /// Method to allow serialization of transient data to archives.
179     virtual void ArchiveOUT(ChArchiveOut& marchive) override;
180 
181     /// Method to allow deserialization of transient data from archives.
182     virtual void ArchiveIN(ChArchiveIn& marchive) override;
183 
184   private:
185     virtual void UpdateNodes();
186 };
187 
188 /// @} fea_constraints
189 
190 }  // end namespace fea
191 }  // end namespace chrono
192 
193 #endif
194