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: Andrea Favali, Alessandro Tasora, Radu Serban
13 // =============================================================================
14 
15 #include "chrono/fea/ChNodeFEAxyzP.h"
16 
17 namespace chrono {
18 namespace fea {
19 
ChNodeFEAxyzP(ChVector<> initial_pos)20 ChNodeFEAxyzP::ChNodeFEAxyzP(ChVector<> initial_pos) : pos(initial_pos), P(0), P_dt(0), F(0) {
21     variables.GetMass()(0) = 0;
22 }
23 
ChNodeFEAxyzP(const ChNodeFEAxyzP & other)24 ChNodeFEAxyzP::ChNodeFEAxyzP(const ChNodeFEAxyzP& other) : ChNodeFEAbase(other) {
25     pos = other.pos;
26     P = other.P;
27     P_dt = other.P_dt;
28     F = other.F;
29     variables = other.variables;
30 }
31 
32 // -----------------------------------------------------------------------------
33 
operator =(const ChNodeFEAxyzP & other)34 ChNodeFEAxyzP& ChNodeFEAxyzP::operator=(const ChNodeFEAxyzP& other) {
35     if (&other == this)
36         return *this;
37 
38     ChNodeFEAbase::operator=(other);
39 
40     pos = other.pos;
41     P = other.P;
42     P_dt = other.P_dt;
43     F = other.F;
44     variables = other.variables;
45     return *this;
46 }
47 
48 // -----------------------------------------------------------------------------
49 
Relax()50 void ChNodeFEAxyzP::Relax() {
51     // no special effect here, just resets scalar field.
52     P = 0;
53     P_dt = 0;
54 }
55 
56 // -----------------------------------------------------------------------------
57 
NodeIntStateGather(const unsigned int off_x,ChState & x,const unsigned int off_v,ChStateDelta & v,double & T)58 void ChNodeFEAxyzP::NodeIntStateGather(const unsigned int off_x,
59                                        ChState& x,
60                                        const unsigned int off_v,
61                                        ChStateDelta& v,
62                                        double& T) {
63     x(off_x) = P;
64     v(off_v) = P_dt;
65 }
66 
NodeIntStateScatter(const unsigned int off_x,const ChState & x,const unsigned int off_v,const ChStateDelta & v,const double T)67 void ChNodeFEAxyzP::NodeIntStateScatter(const unsigned int off_x,
68                                         const ChState& x,
69                                         const unsigned int off_v,
70                                         const ChStateDelta& v,
71                                         const double T) {
72     P = x(off_x);
73     P_dt = v(off_v);
74 }
75 
NodeIntStateGatherAcceleration(const unsigned int off_a,ChStateDelta & a)76 void ChNodeFEAxyzP::NodeIntStateGatherAcceleration(const unsigned int off_a, ChStateDelta& a) {
77     // a(off_a) = P_dtdt; // NOT NEEDED?
78 }
79 
NodeIntStateScatterAcceleration(const unsigned int off_a,const ChStateDelta & a)80 void ChNodeFEAxyzP::NodeIntStateScatterAcceleration(const unsigned int off_a, const ChStateDelta& a) {
81     // P_dtdt = (a(off_a)); // NOT NEEDED?
82 }
83 
NodeIntLoadResidual_F(const unsigned int off,ChVectorDynamic<> & R,const double c)84 void ChNodeFEAxyzP::NodeIntLoadResidual_F(const unsigned int off, ChVectorDynamic<>& R, const double c) {
85     R(off) += F * c;
86 }
87 
NodeIntLoadResidual_Mv(const unsigned int off,ChVectorDynamic<> & R,const ChVectorDynamic<> & w,const double c)88 void ChNodeFEAxyzP::NodeIntLoadResidual_Mv(const unsigned int off,
89                                            ChVectorDynamic<>& R,
90                                            const ChVectorDynamic<>& w,
91                                            const double c) {
92     R(off) += c * GetMass() * w(off);
93 }
94 
NodeIntToDescriptor(const unsigned int off_v,const ChStateDelta & v,const ChVectorDynamic<> & R)95 void ChNodeFEAxyzP::NodeIntToDescriptor(const unsigned int off_v, const ChStateDelta& v, const ChVectorDynamic<>& R) {
96     variables.Get_qb()(0) = v(off_v);
97     variables.Get_fb()(0) = R(off_v);
98 }
99 
NodeIntFromDescriptor(const unsigned int off_v,ChStateDelta & v)100 void ChNodeFEAxyzP::NodeIntFromDescriptor(const unsigned int off_v, ChStateDelta& v) {
101     v(off_v) = variables.Get_qb()(0);
102 }
103 
104 // -----------------------------------------------------------------------------
105 
InjectVariables(ChSystemDescriptor & mdescriptor)106 void ChNodeFEAxyzP::InjectVariables(ChSystemDescriptor& mdescriptor) {
107     mdescriptor.InsertVariables(&variables);
108 }
109 
VariablesFbReset()110 void ChNodeFEAxyzP::VariablesFbReset() {
111     variables.Get_fb()(0) = 0;
112 }
113 
VariablesFbLoadForces(double factor)114 void ChNodeFEAxyzP::VariablesFbLoadForces(double factor) {
115     if (variables.IsDisabled())
116         return;
117     variables.Get_fb()(0) += F * factor;
118 }
119 
VariablesQbLoadSpeed()120 void ChNodeFEAxyzP::VariablesQbLoadSpeed() {
121     if (variables.IsDisabled())
122         return;
123     // not really a 'speed', just the field derivative (may be used in incremental solver)
124     variables.Get_qb()(0) = P_dt;
125 }
126 
VariablesQbSetSpeed(double step)127 void ChNodeFEAxyzP::VariablesQbSetSpeed(double step) {
128     if (variables.IsDisabled())
129         return;
130     // not really a 'speed', just the field derivative (may be used in incremental solver)
131     P_dt = variables.Get_qb()(0);
132 }
133 
VariablesFbIncrementMq()134 void ChNodeFEAxyzP::VariablesFbIncrementMq() {
135     if (variables.IsDisabled())
136         return;
137     variables.Compute_inc_Mb_v(variables.Get_fb(), variables.Get_qb());
138 }
139 
VariablesQbIncrementPosition(double step)140 void ChNodeFEAxyzP::VariablesQbIncrementPosition(double step) {
141     if (variables.IsDisabled())
142         return;
143 
144     double pseudospeed = variables.Get_qb()(0);
145 
146     // ADVANCE FIELD: pos' = pos + dt * vel
147     P = P + pseudospeed * step;
148 }
149 
150 // -----------------------------------------------------------------------------
151 
ArchiveOUT(ChArchiveOut & marchive)152 void ChNodeFEAxyzP::ArchiveOUT(ChArchiveOut& marchive) {
153     // version number
154     marchive.VersionWrite<ChNodeFEAxyzP>();
155     // serialize parent class
156     ChNodeFEAbase::ArchiveOUT(marchive);
157     // serialize all member data:
158     marchive << CHNVP(P);
159     marchive << CHNVP(P_dt);
160     marchive << CHNVP(F);
161 }
162 
ArchiveIN(ChArchiveIn & marchive)163 void ChNodeFEAxyzP::ArchiveIN(ChArchiveIn& marchive) {
164     // version number
165     /*int version =*/ marchive.VersionRead<ChNodeFEAxyzP>();
166     // deserialize parent class
167     ChNodeFEAbase::ArchiveIN(marchive);
168     // stream in all member data:
169     marchive >> CHNVP(P);
170     marchive >> CHNVP(P_dt);
171     marchive >> CHNVP(F);
172 }
173 
174 }  // end namespace fea
175 }  // end namespace chrono
176