1% MBDyn (C) is a multibody analysis code.
2% http://www.mbdyn.org
3%
4% Copyright (C) 1996-2017
5%
6% Pierangelo Masarati	<masarati@aero.polimi.it>
7% Paolo Mantegazza	<mantegazza@aero.polimi.it>
8%
9% Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano
10% via La Masa, 34 - 20156 Milano, Italy
11% http://www.aero.polimi.it
12%
13% Changing this copyright notice is forbidden.
14%
15% This program is free software; you can redistribute it and/or modify
16% it under the terms of the GNU General Public License as published by
17% the Free Software Foundation (version 2 of the License).
18%
19%
20% This program is distributed in the hope that it will be useful,
21% but WITHOUT ANY WARRANTY; without even the implied warranty of
22% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23% GNU General Public License for more details.
24%
25% You should have received a copy of the GNU General Public License
26% along with this program; if not, write to the Free Software
27% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
28
29% AUTHOR: Reinhard Resch <r.resch@secop.com>
30%        Copyright (C) 2011(-2013) all rights reserved.
31%
32%        The copyright of this code is transferred
33%        to Pierangelo Masarati and Paolo Mantegazza
34%        for use in the software MBDyn as described
35%        in the GNU Public License version 2.1
36
37function elem = InLineFriction(pMbElem, pDM, HP)
38    elem.pMbElem = pMbElem;
39    elem.pDM = pDM;
40
41    if ( ~HP.IsKeyWord("node1") )
42        error("inline friction(%d): keyword node1 expected at line %s", pMbElem.GetLabel(), HP.GetLineData());
43    endif
44
45    elem.pNode1 = pDM.ReadNode(HP, "STRUCTURAL");
46
47    if ( HP.IsKeyWord("offset") )
48        elem.o1 = HP.GetPosRel(elem.pNode1);
49    else
50        elem.o1 = zeros(3,1);
51    endif
52
53    if ( HP.IsKeyWord("orientation") )
54        R1 = HP.GetRotRel(elem.pNode1);
55    else
56        R1 = eye(3);
57    endif
58
59    elem.e1 = R1(:,1);
60    elem.e2 = R1(:,2);
61    elem.e3 = R1(:,3);
62
63    if ( ~HP.IsKeyWord("node2") )
64        error("inline friction(%d): keyword node2 expected at line %s", pMbElem.GetLabel(), HP.GetLineData());
65    endif
66
67    elem.pNode2 = pDM.ReadNode(HP, "STRUCTURAL");
68
69    if ( HP.IsKeyWord("offset") )
70        elem.o2 = HP.GetPosRel(elem.pNode2);
71    else
72        elem.o2 = zeros(3,1);
73    endif
74
75    if ( HP.IsKeyWord("coulombfrictioncoefficient") )
76        elem.muc = HP.GetReal();
77    else
78        elem.muc = 0;
79    endif
80
81    if ( elem.muc < 0 )
82        error("inline friction(%d): friction coefficient must be greater than or equal to zero at line %s", pMbElem.GetLabel(), HP.GetLineData());
83    endif
84
85    if ( HP.IsKeyWord("staticfrictioncoefficient") )
86        elem.mus = HP.GetReal();
87    else
88        elem.mus = 0;
89    endif
90
91    if ( elem.mus < 0 )
92        error("inline friction(%d): friction coefficient must be greater than or equal to zero at line %s", pMbElem.GetLabel(), HP.GetLineData());
93    endif
94
95    if ( HP.IsKeyWord("slidingvelocitycoefficient") )
96        elem.vs = HP.GetReal();
97    else
98        elem.vs = 1;
99    endif
100
101    if ( elem.vs < 0 )
102        error("inline friction(%d): sliding velocity coefficient must be greater than or equal to zero at line %s", pMbElem.GetLabel(), HP.GetLineData());
103    endif
104
105    if ( HP.IsKeyWord("slidingvelocityexponent") )
106        elem.i = HP.GetReal();
107    else
108        elem.i = 1;
109    endif
110
111    if ( HP.IsKeyWord("microslipdisplacement") )
112        elem.delta = HP.GetReal();
113    else
114        elem.delta = 1;
115    endif
116
117    if ( elem.delta <= 0 )
118        error("inline friction(%d): micro slip displacement must be greater than zero at line %s", pMbElem.GetLabel(), HP.GetLineData());
119    endif
120
121    if ( HP.IsKeyWord("initialstictionstate") )
122        s0 = HP.GetReal();
123        if ( abs(s0) > 1 )
124            error("inline friction(%d): initial stiction state must be between -1 and 1 at line %s", pMbElem.GetLabel(), HP.GetLineData());
125        endif
126        elem.z = s0 * elem.delta;
127    else
128        elem.z = 0;
129    endif
130
131    if ( HP.IsKeyWord("initialstictionderivative") )
132        elem.zP = HP.GetReal();
133    else
134        elem.zP = 0;
135    endif
136
137    if ( HP.IsKeyWord("viscousfrictioncoefficient") )
138        elem.kv = HP.GetReal();
139    else
140        elem.kv = 0;
141    endif
142
143    if ( elem.kv < 0 )
144        error("inline friction(%d): viscous friction coefficient must be greater then zero at line %s", pMbElem.GetLabel(), HP.GetLineData());
145    endif
146
147    if ( HP.IsKeyWord("stictionstateequationscale") )
148        elem.PhiScale = HP.GetReal();
149    else
150        elem.PhiScale = 1;
151    endif
152
153    if ( elem.PhiScale == 0 )
154        error("inline friction(%s): stiction state equation scale must not be equal to zero at line %s", pMbElem.GetLabel(), HP.GetLineData());
155    endif
156
157    elem.lambda = zeros(2, 1);
158
159    elem = class(elem,"InLineFriction");
160endfunction
161