1 //#**************************************************************
2 //# filename:             body2D.h
3 //#
4 //# author:               Gerstmayr, Vetyukov
5 //#
6 //# generated:
7 //# description:
8 //# comments:
9 //#
10 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
11 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
12 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
13 //#
14 //# This file is part of HotInt.
15 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
16 //# the HOTINT license. See folder 'licenses' for more details.
17 //#
18 //# bug reports are welcome!!!
19 //# WWW:		www.hotint.org
20 //# email:	bug_reports@hotint.org or support@hotint.org
21 //#***************************************************************************************
22 
23 
24 #pragma once
25 
26 #include "element.h"
27 
28 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 //   Body2D   Body2D   Body2D   Body2D   Body2D   Body2D   Body2D   Body2D
30 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31 
32 
33 class Body2D: public Element //$EDC$[beginclass,classname=Body2D,parentclassname=Element]
34 {
35 public:
36 	//Body2D():Element() {mbs = NULL;};
Body2D(MBS * mbsi)37 	Body2D(MBS* mbsi):Element(mbsi) //, pref3D(0.,0.,0.), rotref3D(1.,1.,1.)
38 	{
39 		Body2D::ElementDefaultConstructorInitialization();
40 		//type = TBody;
41 	};
Body2D(const Body2D & e)42 	Body2D(const Body2D& e):Element(e.mbs) {CopyFrom(e);};
43 	//To be overwritten in derived class:
GetCopy()44 	virtual Element* GetCopy()
45 	{
46 		Element* ec = new Body2D(*this);
47 		return ec;
48 	}
49 	//To be overwritten in derived class:
CopyFrom(const Element & e)50 	virtual void CopyFrom(const Element& e)
51 	{
52 		Element::CopyFrom(e);
53 		const Body2D& ce = (const Body2D&)e;
54 		pref3D = ce.pref3D;
55 		rotref3D = ce.rotref3D;
56 		size = ce.size;
57 	}
58 
59 	//this function assigns default values to the element variables
ElementDefaultConstructorInitialization()60 	virtual void ElementDefaultConstructorInitialization()
61 	{
62 		type = TBody;
63 		pref3D = Vector3D(0.,0.,0.);
64 		rotref3D = Matrix3D(1.);
65 		size = Vector3D(0.,0.,0.);
66 	}
67 
Initialize()68 	virtual void Initialize()
69 	{
70 		Element::Initialize();
71 	};
72 
73 	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
74 	//for load/save/edit:
GetElementSpec()75 	virtual const char* GetElementSpec() const {return "Body2D";}
76 	virtual void GetElementData(ElementDataContainer& edc); 		//fill in all element data
77 	virtual int SetElementData(ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
78 	virtual void GetElementDataAuto(ElementDataContainer& edc); 		//fill in all element data
79 	virtual int SetElementDataAuto(ElementDataContainer& edc); //set element data acc. to ElementDataContainer, return 0 if failed or values invalid!
80 	virtual int ReadSingleElementDataAuto(ReadWriteElementDataVariableType& RWdata); 		//automatically generated function from EDC_converter
81 	virtual int WriteSingleElementDataAuto(const ReadWriteElementDataVariableType& RWdata); //automatically generated function from EDC_converter
82   virtual int GetAvailableSpecialValuesAuto(TArrayDynamic<ReadWriteElementDataVariableType>& available_variables); //automatically generated function from EDC_converter
83 	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
84 
85 
GetSize()86 	virtual const Vector3D& GetSize() const {return size;}
87 
GetElementBox()88 	virtual Box3D GetElementBox() const	//$ DR 2013-09-23
89 	{
90 		return Box3D(ToP3D(GetPos2D(Vector2D(-0.5*GetSize().X())))+pref3D,ToP3D(GetPos2D(Vector2D(0.5*GetSize().X())))+pref3D); //$ DR 2013-09-23
91 	}
92 
GetElementBoxD()93 	virtual Box3D GetElementBoxD() const //$ DR 2013-09-23
94 	{
95 		return Box3D(ToP3D(GetPos2DD(Vector2D(-0.5*GetSize().X())))+pref3D,ToP3D(GetPos2DD(Vector2D(0.5*GetSize().X())))+pref3D); //$ DR 2013-09-23
96 	}
97 
EvalF(Vector & f,double t)98 	virtual void EvalF(Vector& f, double t) {};
EvalG(Vector & f,double t)99 	virtual void EvalG(Vector& f, double t) {};
EvalM(Matrix & m,double t)100 	virtual void EvalM(Matrix& m, double t) {};
EvalF2(Vector & f,double t)101 	virtual void EvalF2(Vector& f, double t)
102 	{
103 		Element::EvalF2(f,t);
104 	};
105 
106 
IS()107 	virtual int IS() const {return 0;};  //implicit (algebraic) size
SOS()108 	virtual int SOS() const {return 0;}; //size of second order equations, len(u)
ES()109 	virtual int ES() const {return 0;};  //size of first order explicit equations
SS()110 	virtual int SS() const {return 2*SOS()+ES()+IS();};  //system size
111 
112 	//# Timeint specific derived functions: for discontinuities
PostNewtonStep(double t)113 	virtual double PostNewtonStep(double t) {return 0;};
PostprocessingStep()114 	virtual void PostprocessingStep() {};
GetError()115 	virtual double GetError() const
116 	{
117 		return Element::GetError();
118 	};
119 
Dim()120 	virtual int Dim() const {return 2;} //default value
IsRigid()121 	virtual int IsRigid() const {return 0;} //default value
122 
123 	//get angle in 2D
GetAngle2D()124 	virtual double GetAngle2D() const {return XG(3);};
GetAngle2D(const Vector2D & p_loc)125 	virtual double GetAngle2D(const Vector2D& p_loc) const {return XG(3);};
GetAngle2DP(const Vector2D & p_loc)126 	virtual double GetAngle2DP(const Vector2D& p_loc) const {return XGP(3);};
127 
GetCurvature2D(const Vector2D & p_loc)128 	virtual double GetCurvature2D(const Vector2D& p_loc) const {return 0.;};
GetCurvature2DP(const Vector2D & p_loc)129 	virtual double GetCurvature2DP(const Vector2D& p_loc) const {return 0.;};
GetCurvature2DD(const Vector2D & p_loc)130 	virtual double GetCurvature2DD(const Vector2D& p_loc) const {return 0.;};
131 
132 
GetRefPos2D()133 	virtual Vector2D GetRefPos2D() const {return Vector2D(XG(1),XG(2));};
134 	//virtual Vector2D GetRefPos2DD() const {return Vector2D(XGD(1),XGD(2));};
GetRefPos2DD()135 	virtual Vector2D GetRefPos2DD() const
136 	{
137 		if (GetMBS()->GetIOption(151) && IsRigid() && GetMBS()->GetDOption(105) != 1.)
138 		{
139 			Vector2D p = Vector2D(XGD(1),XGD(2));
140 			Vector2D p0 = GetRefPosInit2D();
141 			return (p - p0)*GetMBS()->GetDOption(105) + p0;
142 		}
143 		else
144 		{
145 			return Vector2D(XGD(1),XGD(2));
146 		}
147 	};
GetRefVel2D()148 	virtual Vector2D GetRefVel2D() const {return Vector2D(XGP(1),XGP(2));};
GetRefVel2DD()149 	virtual Vector2D GetRefVel2DD() const {return Vector2D(XGPD(1),XGPD(2));};
150 
151 
GetRefPos()152 	virtual Vector3D GetRefPos() const
153 	{
154 		Vector2D p = GetRefPos2D();
155 		return ToP3D(Vector3D(p.X(), p.Y(), 0.));
156 	}
GetRefPosD()157 	virtual Vector3D GetRefPosD() const
158 	{
159 		Vector2D p = GetRefPos2DD();
160 		return ToP3D(Vector3D(p.X(), p.Y(), 0.));
161 	}
162 	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
163 	//transform 2D into 3D points for drawing and constraints:
GetPos(const Vector3D & p_loc)164 	virtual Vector3D GetPos(const Vector3D& p_loc) const
165 	{
166 		Vector2D p = GetPos2D(Vector2D(p_loc.X(), p_loc.Y()));
167 		return ToP3D(Vector3D(p.X(), p.Y(), p_loc.Z()));
168 	}
GetPosD(const Vector3D & p_loc)169 	virtual Vector3D GetPosD(const Vector3D& p_loc) const
170 	{
171 		Vector2D p = GetPos2DD(Vector2D(p_loc.X(), p_loc.Y()));
172 		return ToP3D(Vector3D(p.X(), p.Y(), p_loc.Z()));
173 	}
GetVel(const Vector3D & p_loc)174 	virtual Vector3D GetVel(const Vector3D& p_loc) const
175 	{
176 		Vector2D p = GetVel2D(Vector2D(p_loc.X(), p_loc.Y()));
177 		return ToV3D(p);
178 	}
179 	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
180 
181 
182 
183 	//get the rotated and translated position of a local point at the body
GetPos2D(const Vector2D & p_loc)184 	virtual Vector2D GetPos2D(const Vector2D& p_loc) const
185   {
186 		return GetRotMatrix2D()*p_loc+GetRefPos2D();
187 	};
GetVel2D(const Vector2D & p_loc)188 	virtual Vector2D GetVel2D(const Vector2D& p_loc) const
189   {
190 		return GetRotMatrix2DP()*p_loc+GetRefVel2D();
191 	};
192 
193 	//get the rotated and translated position of a local point at the body
GetPos2DD(const Vector2D & p_loc)194 	virtual Vector2D GetPos2DD(const Vector2D& p_loc) const
195   {
196 	//if (GetMBS()->GetIOption(151) && IsRigid() && GetMBS()->GetDOption(105) != 1.) //for deformation scaling
197 	//{
198 	//	Matrix3D A = GetRotMatrix2DD();
199 	//	Matrix3D A0= GetRotMatrixInit2D();
200 	//	double fact = GetMBS()->GetDOption(105);
201 
202 	//	return (fact*A-(fact-1.)*A0)*p_loc+GetRefPos2DD();
203 	//}
204 	//else
205 	//{
206 		return GetRotMatrix2DD()*p_loc+GetRefPos2DD();
207 	//}
208 	};
209 
210 	//get angle in 2D
GetAngle2DD()211 	virtual double GetAngle2DD() const {return XGD(3);};
212 
213 	//for loads:
GetIntDuxDq(Vector & dudq)214 	virtual void GetIntDuxDq(Vector& dudq) {};
GetIntDuyDq(Vector & dudq)215 	virtual void GetIntDuyDq(Vector& dudq) {};
GetIntDuzDq(Vector & dudq)216 	virtual void GetIntDuzDq(Vector& dudq) {};
GetIntDuDqFCentrifugal(Matrix & dudq,const Vector3D & omega,const Vector3D & r0)217 	virtual void GetIntDuDqFCentrifugal(Matrix& dudq, const Vector3D& omega, const Vector3D& r0) {UO() << "ERROR:called Body2D::EmptyFunction\n";};
ApplyDprefdq(Vector & f,const Vector2D & x)218 	virtual void ApplyDprefdq(Vector& f, const Vector2D& x) {};
ApplyDrotrefdq(Vector & f,const double & x)219 	virtual void ApplyDrotrefdq(Vector& f, const double& x) {};
220 
GetdAngle2DdqT(const Vector2D & ploc,Matrix & dpdqi)221 	virtual void GetdAngle2DdqT(const Vector2D& ploc, Matrix& dpdqi) {assert(0);};
222 
GetdPosdqT(const Vector2D & ploc,Matrix & dpdqi)223 	virtual void GetdPosdqT(const Vector2D& ploc, Matrix& dpdqi) {assert(0);};
GetdRotvdqT(const Vector2D & vloc,const Vector2D & ploc,Matrix & d)224 	virtual void GetdRotvdqT(const Vector2D& vloc, const Vector2D& ploc, Matrix& d) {assert(0);};
GetdPosdx(const Vector2D & ploc,Vector2D & dpdx)225 	virtual void GetdPosdx(const Vector2D& ploc, Vector2D& dpdx) {assert(0);};
GetdAngle2Ddx(const Vector2D & ploc,double & dphidx)226 	virtual void GetdAngle2Ddx(const Vector2D& ploc, double& dphidx) {assert(0);};
227 
GetNodedPosdqT(int node,Matrix & dpdqi)228 	virtual void GetNodedPosdqT(int node, Matrix& dpdqi) {assert(0);}; //get matrix with derivatives
AddNodedPosdqTLambda(int node,const Vector2D & lambda,Vector & f)229 	virtual void AddNodedPosdqTLambda(int node, const Vector2D& lambda, Vector& f) {assert(0);};   // f += dpdq*lambda
230 
GetRotMatrix2D()231 	virtual Matrix3D GetRotMatrix2D() const
232 	{
233 		//assumes ordering of DOFS: x,y,phi
234 		Matrix3D rot;
235     rot.SetSize(Dim(),Dim());
236 		double cosphi = cos(XG(3));
237 		double sinphi = sin(XG(3));
238 		rot(1,1) = cosphi;
239 		rot(1,2) =-sinphi;
240 		rot(2,1) = sinphi;
241 		rot(2,2) = cosphi;
242 
243 		return rot;
244 	}
GetRotMatrix2DP()245 	virtual Matrix3D GetRotMatrix2DP() const
246 	{
247 		Matrix3D rot;
248     rot.SetSize(Dim(),Dim());
249 		double cosphi = cos(XG(3));
250 		double sinphi = sin(XG(3));
251 		double phip = XGP(3);
252 		rot(1,1) =-phip*sinphi;
253 		rot(1,2) =-phip*cosphi;
254 		rot(2,1) = phip*cosphi;
255 		rot(2,2) =-phip*sinphi;
256 
257 		return rot;
258 	}
259 	//$ SW 2013-10-18: added function GetRotMatrix2DPP
GetRotMatrix2DPP()260 	virtual Matrix2D GetRotMatrix2DPP() const
261 	{
262 		Matrix2D rot;
263     rot.SetSize(Dim(),Dim());
264 		double cosphi = cos(XG(3));
265 		double sinphi = sin(XG(3));
266 		double phip = XGP(3);
267 		double phip2 = phip*phip;
268 		double phipp = XGPP(3);
269 
270 		rot(1,1) =-phipp*sinphi-phip2*cosphi;
271 		rot(1,2) =-phipp*cosphi+phip2*sinphi;
272 		rot(2,1) = phipp*cosphi-phip2*sinphi;
273 		rot(2,2) =-phipp*sinphi-phip2*cosphi;
274 		return rot;
275 	}
276 
GetRotMatrix()277 	virtual Matrix3D GetRotMatrix() const
278 	{
279 		//assumes ordering of DOFS: x,y,phi
280 		Matrix3D rot;
281 		double cosphi = cos(XG(3));
282 		double sinphi = sin(XG(3));
283 		rot.Get0(0,0) = cosphi;
284 		rot.Get0(0,1) =-sinphi;
285 		rot.Get0(0,2) = 0;
286 		rot.Get0(1,0) = sinphi;
287 		rot.Get0(1,1) = cosphi;
288 		rot.Get0(1,2) = 0;
289 		rot.Get0(2,0) = 0;
290 		rot.Get0(2,1) = 0;
291 		rot.Get0(2,2) = 1;
292 
293 		return rot;
294 	}
GetRotMatrixP()295 	virtual Matrix3D GetRotMatrixP() const
296 	{
297 		//assumes ordering of DOFS: x,y,phi
298 		Matrix3D rot;
299 		double phi  = XG(3);
300 		double phip = XGP(3);
301 		rot.Get0(0,0) =-phip*sin(phi);
302 		rot.Get0(0,1) =-phip*cos(phi);
303 		rot.Get0(0,2) = 0;
304 		rot.Get0(1,0) = phip*cos(phi);
305 		rot.Get0(1,1) =-phip*sin(phi);
306 		rot.Get0(1,2) = 0;
307 		rot.Get0(2,0) = 0;
308 		rot.Get0(2,1) = 0;
309 		rot.Get0(2,2) = 0;
310 
311 		return rot;
312 	}
313 
314 	//drawing matrices:
GetRotMatrix2DD()315 	virtual Matrix3D GetRotMatrix2DD() const
316 	{
317 		//assumes ordering of DOFS: x,y,phi
318 		Matrix3D rot;
319     rot.SetSize(Dim(),Dim());
320 
321 		double phi = XGD(3);
322 		if (GetMBS()->GetIOption(151) && IsRigid() && GetMBS()->GetDOption(105) != 1.) //for deformation scaling
323 		{
324 			double fact = GetMBS()->GetDOption(105);
325 			phi = fact*XGD(3) - (fact-1.)*x_init(3);
326 		}
327 
328 		rot(1,1) = cos(phi);
329 		rot(1,2) =-sin(phi);
330 		rot(2,1) = sin(phi);
331 		rot(2,2) = cos(phi);
332 
333 		return rot;
334 	}
335 	////get initial rotation matrix; for drawing and computation:
336 	//virtual Matrix3D GetRotMatrixInit2D() const
337 	//{
338 	//	//assumes ordering of DOFS: x,y,phi
339 	//	Matrix3D rot;
340  //   rot.SetSize(Dim(),Dim());
341 	//	double phi = x_init(3);
342 	//	rot(1,1) = cos(phi);
343 	//	rot(1,2) =-sin(phi);
344 	//	rot(2,1) = sin(phi);
345 	//	rot(2,2) = cos(phi);
346 
347 	//	return rot;
348 	//}
349 	//virtual Matrix3D GetRotMatrixInit() const
350 	//{
351 	//	//assumes ordering of DOFS: x,y,phi
352 	//	Matrix3D rot(0.);
353 	//	double phi = x_init(3);
354 	//	rot(1,1) = cos(phi);
355 	//	rot(1,2) =-sin(phi);
356 	//	rot(2,1) = sin(phi);
357 	//	rot(2,2) = cos(phi);
358 
359 	//	return rot;
360 	//}
361 	//
GetRotMatrixD()362 	virtual Matrix3D GetRotMatrixD() const
363 	{
364 		//assumes ordering of DOFS: x,y,phi
365 		Matrix3D rot;
366 		double phi = XGD(3);
367 
368 		if (GetMBS()->GetIOption(151) && IsRigid() && GetMBS()->GetDOption(105) != 1.) //for deformation scaling
369 		{
370 			double fact = GetMBS()->GetDOption(105);
371 			phi = fact*XGD(3) - (fact-1.)*x_init(3);
372 		}
373 
374 		rot.Get0(0,0) = cos(phi);
375 		rot.Get0(0,1) =-sin(phi);
376 		rot.Get0(0,2) = 0;
377 		rot.Get0(1,0) = sin(phi);
378 		rot.Get0(1,1) = cos(phi);
379 		rot.Get0(1,2) = 0;
380 		rot.Get0(2,0) = 0;
381 		rot.Get0(2,1) = 0;
382 		rot.Get0(2,2) = 1;
383 
384 		return rot;
385 	}
GetRotMatrixPD()386 	virtual Matrix3D GetRotMatrixPD() const
387 	{
388 		//assumes ordering of DOFS: x,y,phi
389 		Matrix3D rot;
390 		double phi  = XGD(3);
391 		double phip = XGPD(3);
392 		rot.Get0(0,0) =-phip*sin(phi);
393 		rot.Get0(0,1) =-phip*cos(phi);
394 		rot.Get0(0,2) = 0;
395 		rot.Get0(1,0) = phip*cos(phi);
396 		rot.Get0(1,1) =-phip*sin(phi);
397 		rot.Get0(1,2) = 0;
398 		rot.Get0(2,0) = 0;
399 		rot.Get0(2,1) = 0;
400 		rot.Get0(2,2) = 0;
401 
402 		return rot;
403 	}
404 
405 	//transform 2D points
ToP3D(const Vector2D & p)406 	virtual Vector3D ToP3D(const Vector2D& p) const
407 	{
408 		return Vector3D(p.X(),p.Y(),0)*rotref3D+pref3D;
409 	}
410 	//set offset for 3D drawing and computation
SetPRef3D(const Vector3D & p)411 	virtual void SetPRef3D(const Vector3D& p) {pref3D = p;}
412 	//set rotation for 3D transformation
SetRotRef3D(const Matrix3D & rot)413 	virtual void SetRotRef3D(const Matrix3D& rot) {rotref3D = rot;}
414 
415 	//for velocities
ToV3D(const Vector2D & v)416 	virtual Vector3D ToV3D(const Vector2D& v) const
417 	{
418 		return Vector3D(v.X(),v.Y(),0)*rotref3D;
419 	}
420 	//transform 2D points (including virtual z-ccordinate), makes no sense for velocities
ToP3D(const Vector3D & p)421 	virtual Vector3D ToP3D(const Vector3D& p) const
422 	{
423 		return Vector3D(p.X(),p.Y(),p.Z())*rotref3D+pref3D;
424 	}
425 
DrawElement()426 	virtual void DrawElement()
427 	{
428 		Element::DrawElement();
429 	};
430 
431 protected:
432 	Vector3D pref3D;   //$EDC$[varaccess,EDCvarname="reference_position",EDCfolder="Geometry",tooltiptext="Reference point for transformation of planar objects to 3D; p = [X, Y, Z]"]
433 	Matrix3D rotref3D; //$EDC$[varaccess,EDCvarname="rotation_matrix",EDCfolder="Geometry",tooltiptext="Rotation matrix for transformation of planar objects to 3D"]
434 	Vector3D size;     //$EDC$[varaccess,EDCvarname="general_size",EDCfolder="Geometry",tooltiptext="Dimensions of a regular cube [L_x, L_y, L_z]"]
435 	//Vector3D pref3D;
436 	//Matrix3D rotref3D;
437 	//Vector3D size;
438 }; //$EDC$[endclass,Body2D]