proteus  1.8.1
C/C++/Fortran libraries
ProtChBody.h
Go to the documentation of this file.
1 //#pragma once
2 
3 #include "chrono/physics/ChSystemSMC.h"
4 #include "chrono/physics/ChSystem.h"
5 #include "chrono/timestepper/ChTimestepper.h"
6 #include "chrono/solver/ChSolverPMINRES.h"
7 #include "chrono/core/ChTransform.h"
8 #include "chrono/physics/ChLinkSpring.h"
9 #include "chrono/geometry/ChTriangleMeshConnected.h"
10 #include <iostream>
11 #include <fstream>
12 
13 using namespace chrono;
14 using namespace chrono::collision;
15 using namespace std;
16 
17 class cppSystem {
18  public:
19  std::shared_ptr<ChSystemSMC> systemSMC;
20  std::shared_ptr<ChSystem> system;
21  double chrono_dt;
22  std::string directory;
23  cppSystem();
24  void step(double proteus_dt, int n_substeps);
25  void setDirectory(std::string dir);
26  void setTimestepperType(std::string tstype, bool verbose);
27  void setCollisionEnvelopeMargin(double envelope, double margin);
28  void addMesh(std::shared_ptr<ChMesh> mesh);
29 };
30 
31 
32 class cppRigidBody {
33  public:
34  ChVector<> free_x;
35  ChVector<> free_r;
36  ChVector<> pos;
37  ChVector<> pos_last;
38  ChVector<> pos0;
39  std::vector<ChVector<>> trimesh_pos;
40  std::vector<ChVector<>> trimesh_pos_last;
41  std::vector<ChVector<>> trimesh_pos0;
42  ChVector<> pos0_trimesh;
43  ChQuaternion<> rotq0_trimesh;
44  ChVector<> vel;
45  ChVector<> vel_last;
46  ChVector<> acc;
47  ChVector<> acc_last;
48  ChVector<> angvel;
49  ChVector<> angvel_last;
50  ChVector<> angacc;
51  ChVector<> angacc_last;
52  ChMatrix33<double> rotm;
53  ChMatrix33<double> rotm_last;
54  ChQuaternion<double> rotq;
55  ChQuaternion<double> rotq_last;
56  ChQuaternion<double> rotq0;
57  ChVector<> F;
58  ChVector<> F_last;
59  ChVector<> M;
60  ChVector<> M_last;
61  std::shared_ptr<ChLinkLockLock> lock_motion; // lock for prescribed motion
62  double lock_motion_t_max; // max time up to which lock motion is used
63  double mass;
65  std::shared_ptr<ChLinkSpring> spring;
66  /* ChVector <> inertia; */
67  double* inertia;
68  shared_ptr<ChTriangleMeshConnected> trimesh;
70  std::shared_ptr<ChBody> body;
72  cppRigidBody(cppSystem* system);
73  ChVector<double> hxyz(double* x, double t);
74  double hx(double* x, double t);
75  double hy(double* x, double t);
76  double hz(double* x, double t);
77  void calculate_init();
78  void prestep(double* force, double* torque);
79  void poststep();
80  void setConstraints(double* free_x, double* free_y);
81  void addSpring(double stiffness,
82  double damping,
83  double* fairlead,
84  double* anchor,
85  double rest_length);
86  void addPrismaticLinksWithSpring(double* pris1,
87  double* pris2,
88  double stiffness,
89  double damping,
90  double rest_length);
91  void addPrismaticLinkX(double* pris1);
92  void setName(std::string name);
93  void setPrescribedMotionPoly(double coeff1);
94  void setPrescribedMotionSine(double a, double f);
95  void setPrescribedMotionCustom(std::vector<double> t, std::vector<double> x,
96  std::vector<double> y, std::vector<double> z,
97  std::vector<double> ang, std::vector<double> ang2,
98  std::vector<double> ang3, double t_max);
99  void getTriangleMeshSDF(ChVector<> pos_node,
100  double* dist_n);
101  void getTriangleMeshVel(double *x,
102  double dt,
103  double *vel);
104  void updateTriangleMeshVisualisationPos();
105 };
106 
108 {
109  /* systemSMC_sharedptr = chrono_types::make_shared<ChSystemSMC>(); */
110  /* systemSMC = systemSMC_sharedptr.get(); */
111  /* system = systemSMC; */
112  chrono_dt = 0.000001;
113  directory = "./";
114  // SOLVER OPTIONS
115  /* system->SetSolverType(ChSolver::Type::MINRES); // SOLVER_MINRES: good convergence, supports FEA, does not support DVI yet */
116  /* auto msolver = std::static_pointer_cast<ChSolverMINRES>(system->GetSolver()); */
117  /* msolver->SetDiagonalPreconditioning(true); */
118  /* system->SetSolverWarmStarting(true); // this helps a lot to speedup convergence in this class of problems */
119  /* system->SetMaxItersSolverSpeed(100); // max iteration for iterative solvers */
120  /* system->SetMaxItersSolverStab(100); // max iteration for stabilization (iterative solvers) */
121  /* system->SetTolForce(1e-10); */
122  //system->SetMaxItersSolverSpeed(100);
123  //system->SetMaxItersSolverStab(100);
124  //system->SetTolForce(1e-14); // default: 0.001
125  //system->SetMaxiter(200); // default: 6. Max constraints to reach tolerance on constraints.
126  //system->SetTol(1e-10); // default: 0.0002. Tolerance for keeping constraints together.
127  /* system->SetTimestepperType(ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED); // used before: ChSystem::INT_EULER_IMPLICIT_LINEARIZED */
128  /* if (auto mystepper = std::dynamic_pointer_cast<ChTimestepperHHT>(system->GetTimestepper())) { */
129  /* mystepper->SetAlpha(-0.2); */
130  /* } */
131 }
132 
133 void cppSystem::setTimestepperType(std::string tstype, bool verbose=false) {
134  if (tstype == "HHT") {
135  system->SetTimestepperType(ChTimestepper::Type::HHT);
136  auto mystepper = std::dynamic_pointer_cast<ChTimestepperHHT>(system->GetTimestepper());
137  mystepper->SetAlpha(-0.2);
138  mystepper->SetMaxiters(10);
139  mystepper->SetAbsTolerances(1e-6);
140  mystepper->SetMode(ChTimestepperHHT::POSITION);
141  mystepper->SetScaling(false);
142  mystepper->SetVerbose(verbose);
143  mystepper->SetModifiedNewton(false);
144  }
145  else if (tstype == "Euler") {
146  system->SetTimestepperType(ChTimestepper::Type::EULER_IMPLICIT_LINEARIZED);
147  }
148  else if (tstype == "Trapezoidal") {
149  system->SetTimestepperType(ChTimestepper::Type::TRAPEZOIDAL);
150  }
151  }
152 
153 void cppSystem::step(double proteus_dt, int n_substeps=1)
154 {
155  double dt2 = proteus_dt/(double)n_substeps;
156  for (int i = 0; i < n_substeps; ++i) {
157  system->DoStepDynamics(dt2);
158  }
159 }
160 
161 void cppSystem::addMesh(std::shared_ptr<ChMesh> mesh) {
162  system->Add(mesh);
163 }
164 
166  system(system)
167 {
168 
169  body = chrono_types::make_shared<ChBody>();
170  // add body to system
171  /* system->system->AddBody(body); */ // now added externally in cython
172  // basic attributes of body
173  rotm = body->GetA();
174  rotm_last = body->GetA();
175  pos = body->GetPos();
176  pos_last = body->GetPos();
177  body->SetMass(mass);
178  free_x = ChVector<>(1., 1., 1.);
179  free_r = ChVector<>(1., 1., 1.);
180  lock_motion_t_max = 0.;
181  has_trimesh = false;
182 }
183 
184 void cppSystem::setDirectory(std::string dir) {
185  directory = dir;
186 }
187 
189  /* rotm = body->GetA(); */
190  for (int i = 0; i < trimesh_pos.size(); i++) {
191  ChVector<double> local = ChTransform<double>::TransformParentToLocal(trimesh_pos0[i],
192  pos0_trimesh,
193  rotq0_trimesh);
194  ChVector<double> xNew = ChTransform<double>::TransformLocalToParent(local,
195  pos,
196  rotq);
197  trimesh_pos[i].Set(xNew.x(), xNew.y(), xNew.z());
198  }
199 }
200 
201 ChVector<double> cppRigidBody::hxyz(double* x, double t)
202 {
203  /* rotm = body->GetA(); */
204  ChVector<double> xx = ChVector<double>(x[0], x[1], x[2]);
205  ChVector<double> local = ChTransform<double>::TransformParentToLocal(xx, pos_last, rotq_last);
206  ChVector<double> xNew = ChTransform<double>::TransformLocalToParent(local, pos, rotq);
207  return xNew - xx;
208 }
209 
210 
211 void cppSystem::setCollisionEnvelopeMargin(double envelope, double margin) {
212  collision::ChCollisionModel::SetDefaultSuggestedEnvelope(envelope);
213  collision::ChCollisionModel::SetDefaultSuggestedMargin(margin);
214 }
215 
216 double cppRigidBody::hx(double* x, double t)
217 {
218  /* rotm = body->GetA(); */
219  ChVector<double> local = ChTransform<double>::TransformParentToLocal(ChVector<double>(x[0],x[1],x[2]), pos_last, rotq_last);
220  ChVector<double> xNew = ChTransform<double>::TransformLocalToParent(local, pos, rotq);
221  return xNew.x() - x[0];
222 }
223 
224 double cppRigidBody::hy(double* x, double t)
225 {
226  /* rotm = body->GetA(); */
227  ChVector<double> local = ChTransform<double>::TransformParentToLocal(ChVector<double>(x[0],x[1],x[2]), pos_last, rotq_last);
228  ChVector<double> xNew = ChTransform<double>::TransformLocalToParent(local, pos, rotq);
229  return xNew.y() - x[1];
230 }
231 
232 double cppRigidBody::hz(double* x, double t)
233 {
234  /* rotm = body->GetA(); */
235  ChVector<double> local = ChTransform<double>::TransformParentToLocal(ChVector<double>(x[0],x[1],x[2]), pos_last, rotq_last);
236  ChVector<double> xNew = ChTransform<double>::TransformLocalToParent(local, pos, rotq);
237  return xNew.z() - x[2];
238 }
239 
241  pos0 = body->GetPos();
242  rotq0 = body->GetRot();
243  if (has_trimesh == true) {
244  trimesh_pos.clear();
245  trimesh_pos0.clear();
246  auto trimesh_coords = trimesh->getCoordsVertices();
247  for (int i = 0; i < trimesh_coords.size(); i++) {
248  trimesh_pos0.push_back(ChVector<double>(trimesh_coords[i].x(),
249  trimesh_coords[i].y(),
250  trimesh_coords[i].z()));
251  trimesh_pos.push_back(ChVector<double>(trimesh_coords[i].x(),
252  trimesh_coords[i].y(),
253  trimesh_coords[i].z()));
254  }
255  }
256 }
257 
258 void cppRigidBody::prestep(double* force, double* torque)
259 {
260  /* step to call before running chrono system step */
261  pos_last = body->GetPos();
262  vel_last = body->GetPos_dt();
263  if (has_trimesh == true) {
264  trimesh_pos_last = trimesh->getCoordsVertices();
265  }
266  acc_last = body->GetPos_dtdt();
267  rotm_last = body->GetA();
268  rotq_last = body->GetRot();
269  angacc_last = body->GetWacc_loc();
270  angvel_last = body->GetWvel_loc();
271  F_last = body->Get_accumulated_torque();
272  M_last = body->Get_accumulated_torque();
273  // apply external forces
274  body->Empty_forces_accumulators();
275  // calculate opposite force of gravity if free_x is 0
276  double forceG[3]={0.,0.,0.};
277  if (free_x.x() == 0) {forceG[0] = -system->system->Get_G_acc().x()*body->GetMass();}
278  if (free_x.y() == 0) {forceG[1] = -system->system->Get_G_acc().y()*body->GetMass();}
279  if (free_x.z() == 0) {forceG[2] = -system->system->Get_G_acc().z()*body->GetMass();}
280  body->Accumulate_force(ChVector<double>(forceG[0]+force[0]*free_x.x(),
281  forceG[1]+force[1]*free_x.y(),
282  forceG[2]+force[2]*free_x.z()),
283  pos_last,
284  false);
285  body->Accumulate_torque(ChVector<double>(torque[0]*free_r.x(),
286  torque[1]*free_r.y(),
287  torque[2]*free_r.z()),
288  false);
289  if (spring!=0) {
290  double spring_length = spring->Get_SpringLength();
291  if (spring_length < mooring_restlength) {
292  spring->SetDisabled(true);//Set_SpringRestLength(spring_length);
293  }
294  else {
295  spring->SetDisabled(false);//Set_SpringRestLength(mooring_restlength);
296  }
297  }
298  }
299 
300 
301 
303 {
304  pos = body->GetPos();
305  vel = body->GetPos_dt();
306  acc = body->GetPos_dtdt();
307  rotm = body->GetA();
308  rotq = body->GetRot();
309  angacc = body->GetWacc_loc();
310  angvel = body->GetWvel_loc();
311  F = body->Get_accumulated_force();
312  M = body->Get_accumulated_torque();
313  if (lock_motion_t_max > 0) {
314  double t = system->system->GetChTime();
315  if (lock_motion_t_max < t && lock_motion->IsDisabled() == false) {
316  lock_motion->SetDisabled(true);
317  }
318  }
319 }
320 
321 void cppRigidBody::setPrescribedMotionCustom(std::vector<double> t,
322  std::vector<double> x,
323  std::vector<double> y,
324  std::vector<double> z,
325  std::vector<double> ang,
326  std::vector<double> ang2,
327  std::vector<double> ang3,
328  double t_max) {
329  auto fixed_body = chrono_types::make_shared<ChBody>();
330  fixed_body->SetPos(body->GetPos());
331  fixed_body->SetBodyFixed(true);
332  system->system->Add(fixed_body);
333  lock_motion = chrono_types::make_shared<ChLinkLockLock>();
334  lock_motion_t_max = t_max;
335  lock_motion->Initialize(body, fixed_body, fixed_body->GetCoord());
336  system->system->Add(lock_motion);
337  if (x.size() > 0) {
338  auto forced_motion = chrono_types::make_shared<ChFunction_Recorder>();
339  for (int i = 0; i < x.size(); i++) {
340  forced_motion->AddPoint(t[i], x[i]);
341  }
342  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
343  lock_motion->SetMotion_X(forced_ptr);
344  }
345  if (y.size() > 0) {
346  auto forced_motion = chrono_types::make_shared<ChFunction_Recorder>();
347  for (int i = 0; i < y.size(); i++) {
348  forced_motion->AddPoint(t[i], y[i]);
349  }
350  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
351  lock_motion->SetMotion_Y(forced_ptr);
352  }
353  if (z.size() > 0) {
354  auto forced_motion = chrono_types::make_shared<ChFunction_Recorder>();
355  for (int i = 0; i < z.size(); i++) {
356  forced_motion->AddPoint(t[i], z[i]);
357  }
358  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
359  lock_motion->SetMotion_Z(forced_ptr);
360  }
361  if (ang.size() > 0) {
362  auto forced_motion = chrono_types::make_shared<ChFunction_Recorder>();
363  for (int i = 0; i < ang.size(); i++) {
364  forced_motion->AddPoint(t[i], ang[i]);
365  }
366  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
367  lock_motion->SetMotion_ang(forced_ptr);
368  }
369  if (ang2.size() > 0) {
370  auto forced_motion = chrono_types::make_shared<ChFunction_Recorder>();
371  for (int i = 0; i < ang2.size(); i++) {
372  forced_motion->AddPoint(t[i], ang2[i]);
373  }
374  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
375  lock_motion->SetMotion_ang2(forced_ptr);
376  }
377  if (ang3.size() > 0) {
378  auto forced_motion = chrono_types::make_shared<ChFunction_Recorder>();
379  for (int i = 0; i < ang3.size(); i++) {
380  forced_motion->AddPoint(t[i], ang3[i]);
381  }
382  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
383  lock_motion->SetMotion_ang3(forced_ptr);
384  }
385 }
386 
388  auto fixed_body = chrono_types::make_shared<ChBody>();
389  fixed_body->SetPos(body->GetPos());
390  fixed_body->SetBodyFixed(true);
391  system->system->Add(fixed_body);
392  auto lock = chrono_types::make_shared<ChLinkLockLock>();
393  lock->Initialize(body, fixed_body, fixed_body->GetCoord());
394  system->system->Add(lock);
395  auto forced_motion = chrono_types::make_shared<ChFunction_Poly>();
396  forced_motion->Set_order(1);
397  forced_motion->Set_coeff(coeff1, 1);
398  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
399  lock->SetMotion_X(forced_ptr);
400 }
401 
402 
403 void cppRigidBody::setPrescribedMotionSine(double a, double f) {
404  auto fixed_body = chrono_types::make_shared<ChBody>();
405  fixed_body->SetPos(body->GetPos());
406  fixed_body->SetBodyFixed(true);
407  system->system->Add(fixed_body);
408  auto lock = chrono_types::make_shared<ChLinkLockLock>();
409  lock->Initialize(body, fixed_body, fixed_body->GetCoord());
410  system->system->Add(lock);
411  auto forced_motion = chrono_types::make_shared<ChFunction_Sine>();
412  forced_motion->Set_amp(a);
413  forced_motion->Set_freq(f);
414  std::shared_ptr<ChFunction> forced_ptr = forced_motion;
415  lock->SetMotion_X(forced_ptr);
416 }
417 
418 void cppRigidBody::setConstraints(double* free_x_in, double* free_r_in){
419  free_x = ChVector<>(free_x_in[0], free_x_in[1], free_x_in[2]);
420  free_r = ChVector<>(free_r_in[0], free_r_in[1], free_r_in[2]);
421 }
422 
423 void cppRigidBody::addSpring(double stiffness,
424  double damping,
425  double* fairlead,
426  double* anchor,
427  double rest_length)
428 {
429  mooring_restlength = rest_length;
430  spring = chrono_types::make_shared<ChLinkSpring>();
431  std::shared_ptr<ChBody> anchor_body = chrono_types::make_shared<ChBody>();
432  anchor_body->SetPos(ChVector<>(anchor[0], anchor[1], anchor[2]));
433  anchor_body->SetBodyFixed(true);
434  system->system->AddBody(anchor_body);
435  spring->Initialize(body,
436  anchor_body,
437  true, // true for pos relative to bodies
438  ChVector<>(fairlead[0], fairlead[1], fairlead[2]),
439  ChVector<>(0.,0.,0.),
440  false, // true for auto rest length (distance between body1 and body2)
441  rest_length);
442  spring->Set_SpringK(stiffness);
443  spring->Set_SpringR(damping);
444  system->system->AddLink(spring);
445 }
446 
448 {
449  auto mybod2 = chrono_types::make_shared<ChBody>();
450  mybod2->SetName("PRIS1");
451  mybod2->SetPos(ChVector<>(pris1[0], pris1[1], pris1[2]));
452  mybod2->SetMass(0.00001);
453  mybod2->SetBodyFixed(true);
454  system->system->AddBody(mybod2);
455  auto mylink1 = chrono_types::make_shared<ChLinkLockPrismatic>();
456  auto mycoordsys1 = ChCoordsys<>(mybod2->GetPos(),Q_from_AngAxis(CH_C_PI/2., VECT_Y));//Q_from_AngAxis(CH_C_PI / 2, VECT_X));
457  mylink1->Initialize(mybod2, body, mycoordsys1);
458  system->system->AddLink(mylink1);
459 }
460 
462  double* pris2,
463  double stiffness,
464  double damping,
465  double rest_length)
466 {
467  mooring_restlength = rest_length;
468  auto fairlead = chrono_types::make_shared<ChBody>();
469  fairlead->SetName("PRIS3");
470  fairlead->SetPos(body->GetPos());
471  fairlead->SetMass(0.00001);
472  system->system->AddBody(fairlead);
473  auto mybod2 = chrono_types::make_shared<ChBody>();
474  mybod2->SetName("PRIS1");
475  mybod2->SetPos(ChVector<>(pris1[0], pris1[1], pris1[2]));
476  mybod2->SetMass(0.00001);
477  //mybod2->AddForce(-system->system->Get_G_acc());
478  //mybod2->SetBodyFixed(true);
479  system->system->AddBody(mybod2);
480  auto mybod3 = chrono_types::make_shared<ChBody>();
481  mybod3->SetName("PRIS2");
482  mybod3->SetPos(ChVector<>(pris2[0], pris2[1], pris2[2]));
483  mybod3->SetBodyFixed(true);
484  system->system->AddBody(mybod3);
485 
486  auto mylink1 = chrono_types::make_shared<ChLinkLockPrismatic>();
487  system->system->AddLink(mylink1);
488  auto mycoordsys1 = ChCoordsys<>(mybod2->GetPos(),Q_from_AngAxis(CH_C_PI/2., VECT_Y));//Q_from_AngAxis(CH_C_PI / 2, VECT_X));
489  mylink1->Initialize(fairlead, mybod2, mycoordsys1);
490 
491 
492 
493  auto mylink2 = chrono_types::make_shared<ChLinkLockPrismatic>();
494  system->system->AddLink(mylink2);
495  auto mycoordsys2 = ChCoordsys<>(mybod3->GetPos(),Q_from_AngAxis(CH_C_PI/2., VECT_X));//Q_from_AngAxis(CH_C_PI / 2, VECT_X));
496  mylink2->Initialize(mybod2, mybod3,mycoordsys2);
497 
498  auto mylink3 = chrono_types::make_shared<ChLinkLockSpherical>();
499  //auto mylink3 = chrono_types::make_shared<ChLinkLockRevolute>();
500  //mylink3->SetMotion_axis(ChVector<>(0.,1.,0.));
501  system->system->AddLink(mylink3);
502  mylink3->Initialize(fairlead, body, false, fairlead->GetCoord(), body->GetCoord());
503 
504 
505 
506  spring = chrono_types::make_shared<ChLinkSpring>();
507  spring->Initialize(fairlead,
508  mybod2,
509  true, // true for pos relative to bodies
510  ChVector<>(0.,0.,0.),
511  ChVector<>(0.,0.,0.),
512  false,
513  rest_length); // true for auto rest length (distance between body1 and body2));
514  spring->Set_SpringK(stiffness);
515  spring->Set_SpringR(damping);
516  spring->SetName("SPRING1");
517  system->system->AddLink(spring);
518 }
519 
520 void cppRigidBody::setName(std::string name) {
521  body->SetNameString(name);
522 }
523 
525  double* dist_n) {
526  auto xxs = trimesh->getCoordsVertices();
527  auto nns = trimesh->getCoordsNormals();
528  ChVector<> dist_vec;
529  double min_dist=1e10;
530  double dist;
531  for (int i = 0; i < xxs.size(); i++) {
532  dist_vec = pos-xxs[i];
533  dist = dist_vec.Length();
534  if (dist < min_dist) {
535  min_dist = dist;
536  }
537  if (dist_vec.Dot(nns[i]) > 0) { // outside
538  min_dist = min_dist;
539  }
540  else { // inside
541  min_dist = -min_dist;
542  }
543  }
544  dist_n[0] = min_dist;
545  // normal to shape
546  // actually just vector to closest node here
547  dist_n[1] = dist_vec[0];
548  dist_n[1] = dist_vec[1];
549  dist_n[2] = dist_vec[2];
550 };
551 
553  double dt,
554  double *vel) {
555  auto xxs = trimesh->getCoordsVertices();
556  auto nns = trimesh->getCoordsNormals();
557  double min_dist = 1e10;
558  ChVector<> p(x[0], x[1], x[2]);
559  ChVector<> d_vector(0.0);
560  ChVector<> ddlast;
561  // find closest node
562  int node_closest = -1;
563  for (int i = 0; i < xxs.size(); i++) {
564  double dist = (p - xxs[i]).Length();
565  if (dist < min_dist) {
566  min_dist = dist;
567  node_closest = i;
568  }
569  }
570  if (node_closest != -1) {
571  ddlast = xxs[node_closest]-trimesh_pos_last[node_closest];
572  vel[0] = ddlast.x()/dt;
573  vel[1] = ddlast.y()/dt;
574  vel[2] = ddlast.z()/dt;
575  }
576 }
577 
578 
580 {
581  return new cppSystem();
582 }
583 
584 
585 
587 {
588  return new cppRigidBody(system);
589 }
590 
591 
592 
593 void ChLinkLockBodies(std::shared_ptr<ChBody> body1,
594  std::shared_ptr<ChBody> body2,
595  std::shared_ptr<ChSystem> system,
596  ChCoordsys<> coordsys,
597  double limit_X=0.,
598  double limit_Y=0.,
599  double limit_Z=0.,
600  double limit_Rx=0.,
601  double limit_Ry=0.,
602  double limit_Rz=0.) {
603  auto mylink = chrono_types::make_shared<ChLinkLock>();
604  system->AddLink(mylink);
605  auto chlimit_X = mylink->GetLimit_X();
606  chlimit_X.SetActive(true);
607  chlimit_X.SetMax(limit_X);
608  auto chlimit_Y = mylink->GetLimit_Y();
609  chlimit_Y.SetActive(true);
610  chlimit_Y.SetMax(limit_Y);
611  auto chlimit_Z = mylink->GetLimit_Z();
612  chlimit_Z.SetActive(true);
613  chlimit_Z.SetMax(limit_Z);
614  auto chlimit_Rx = mylink->GetLimit_Rx();
615  chlimit_Rx.SetMax(limit_Rx);
616  chlimit_Rx.SetActive(true);
617  auto chlimit_Ry = mylink->GetLimit_Ry();
618  chlimit_Ry.SetActive(true);
619  chlimit_Ry.SetMax(limit_Ry);
620  auto chlimit_Rz = mylink->GetLimit_Rz();
621  chlimit_Rz.SetActive(true);
622  chlimit_Rz.SetMax(limit_Rz);
623  mylink->Initialize(body1, body2, coordsys);
624 }
625 
627 {
628  void operator()(void*) { }
629 };
630 
631 std::shared_ptr<ChPhysicsItem> getPhysicsItemSharedPtr(ChPhysicsItem* item) {
632  std::shared_ptr<ChPhysicsItem> sp(item, no_op_delete());
633  return sp;
634 }
635 static std::map<ChPhysicsItem*, std::shared_ptr<ChPhysicsItem>> spans;
636 
637 std::shared_ptr<ChPhysicsItem> getPhysicsItemSharedPtr2(ChPhysicsItem* item) {
638  std::shared_ptr<ChPhysicsItem> sp = spans.at(item);
639  /* std::shared_ptr<ChPhysicsItem> sp(item, no_op_delete()); */
640  return sp;
641 }
642 
cppSystem::setDirectory
void setDirectory(std::string dir)
Definition: ProtChBody.h:184
cppRigidBody::setPrescribedMotionPoly
void setPrescribedMotionPoly(double coeff1)
Definition: ProtChBody.h:387
cppRigidBody::pos0
ChVector pos0
Definition: ProtChBody.h:38
cppRigidBody::lock_motion
std::shared_ptr< ChLinkLockLock > lock_motion
Definition: ProtChBody.h:61
cppRigidBody::setConstraints
void setConstraints(double *free_x, double *free_y)
Definition: ProtChBody.h:418
cppRigidBody::acc
ChVector acc
Definition: ProtChBody.h:46
cppSystem::setTimestepperType
void setTimestepperType(std::string tstype, bool verbose)
Definition: ProtChBody.h:133
cppRigidBody::mooring_restlength
double mooring_restlength
Definition: ProtChBody.h:64
cppRigidBody::pos_last
ChVector pos_last
Definition: ProtChBody.h:37
cppRigidBody::pos0_trimesh
ChVector pos0_trimesh
Definition: ProtChBody.h:42
cppSystem::systemSMC
std::shared_ptr< ChSystemSMC > systemSMC
Definition: ProtChBody.h:19
cppRigidBody::trimesh_pos0
std::vector< ChVector<> > trimesh_pos0
Definition: ProtChBody.h:41
cppRigidBody::poststep
void poststep()
Definition: ProtChBody.h:302
cppRigidBody::trimesh
shared_ptr< ChTriangleMeshConnected > trimesh
Definition: ProtChBody.h:68
f
Double f
Definition: Headers.h:64
cppRigidBody::mass
double mass
Definition: ProtChBody.h:63
cppRigidBody::M_last
ChVector M_last
Definition: ProtChBody.h:60
cppRigidBody::angvel_last
ChVector angvel_last
Definition: ProtChBody.h:49
cppRigidBody::rotq0
ChQuaternion< double > rotq0
Definition: ProtChBody.h:56
cppRigidBody::inertia
double * inertia
Definition: ProtChBody.h:67
cppSystem::chrono_dt
double chrono_dt
Definition: ProtChBody.h:21
cppRigidBody::vel
ChVector vel
Definition: ProtChBody.h:44
cppRigidBody::addPrismaticLinkX
void addPrismaticLinkX(double *pris1)
Definition: ProtChBody.h:447
cppRigidBody::angacc_last
ChVector angacc_last
Definition: ProtChBody.h:51
vel
void vel(double rS, double norm_v, double r, double theta, double *vR, double *vTHETA)
Definition: analyticalSolutions.c:2163
cppRigidBody::angacc
ChVector angacc
Definition: ProtChBody.h:50
cppRigidBody::spring
std::shared_ptr< ChLinkSpring > spring
Definition: ProtChBody.h:65
getPhysicsItemSharedPtr2
std::shared_ptr< ChPhysicsItem > getPhysicsItemSharedPtr2(ChPhysicsItem *item)
Definition: ProtChBody.h:637
cppSystem::cppSystem
cppSystem()
Definition: ProtChBody.h:107
cppRigidBody::trimesh_pos_last
std::vector< ChVector<> > trimesh_pos_last
Definition: ProtChBody.h:40
cppRigidBody::free_x
ChVector free_x
Definition: ProtChBody.h:34
cppRigidBody::addPrismaticLinksWithSpring
void addPrismaticLinksWithSpring(double *pris1, double *pris2, double stiffness, double damping, double rest_length)
Definition: ProtChBody.h:461
cppRigidBody::body
std::shared_ptr< ChBody > body
Definition: ProtChBody.h:70
cppRigidBody::trimesh_pos
std::vector< ChVector<> > trimesh_pos
Definition: ProtChBody.h:39
cppRigidBody::setPrescribedMotionSine
void setPrescribedMotionSine(double a, double f)
Definition: ProtChBody.h:403
cppRigidBody::rotq_last
ChQuaternion< double > rotq_last
Definition: ProtChBody.h:55
z
Double * z
Definition: Headers.h:49
cppRigidBody::rotq
ChQuaternion< double > rotq
Definition: ProtChBody.h:54
cppRigidBody::M
ChVector M
Definition: ProtChBody.h:59
getPhysicsItemSharedPtr
std::shared_ptr< ChPhysicsItem > getPhysicsItemSharedPtr(ChPhysicsItem *item)
Definition: ProtChBody.h:631
ChLinkLockBodies
void ChLinkLockBodies(std::shared_ptr< ChBody > body1, std::shared_ptr< ChBody > body2, std::shared_ptr< ChSystem > system, ChCoordsys<> coordsys, double limit_X=0., double limit_Y=0., double limit_Z=0., double limit_Rx=0., double limit_Ry=0., double limit_Rz=0.)
Definition: ProtChBody.h:593
cppSystem::setCollisionEnvelopeMargin
void setCollisionEnvelopeMargin(double envelope, double margin)
Definition: ProtChBody.h:211
cppRigidBody::prestep
void prestep(double *force, double *torque)
Definition: ProtChBody.h:258
cppRigidBody::lock_motion_t_max
double lock_motion_t_max
Definition: ProtChBody.h:62
cppRigidBody::rotm
ChMatrix33< double > rotm
Definition: ProtChBody.h:52
cppRigidBody::F_last
ChVector F_last
Definition: ProtChBody.h:58
cppRigidBody::has_trimesh
bool has_trimesh
Definition: ProtChBody.h:69
cppRigidBody::vel_last
ChVector vel_last
Definition: ProtChBody.h:45
cppRigidBody::system
cppSystem * system
Definition: ProtChBody.h:71
cppRigidBody::hy
double hy(double *x, double t)
Definition: ProtChBody.h:224
newSystem
cppSystem * newSystem()
Definition: ProtChBody.h:579
cppRigidBody::cppRigidBody
cppRigidBody(cppSystem *system)
Definition: ProtChBody.h:165
cppRigidBody::hx
double hx(double *x, double t)
Definition: ProtChBody.h:216
cppRigidBody::updateTriangleMeshVisualisationPos
void updateTriangleMeshVisualisationPos()
Definition: ProtChBody.h:188
cppSystem::system
std::shared_ptr< ChSystem > system
Definition: ProtChBody.h:20
cppRigidBody::hz
double hz(double *x, double t)
Definition: ProtChBody.h:232
cppSystem::addMesh
void addMesh(std::shared_ptr< ChMesh > mesh)
Definition: ProtChBody.h:161
cppRigidBody::free_r
ChVector free_r
Definition: ProtChBody.h:35
no_op_delete
Definition: ProtChBody.h:627
cppRigidBody::angvel
ChVector angvel
Definition: ProtChBody.h:48
cppRigidBody::rotm_last
ChMatrix33< double > rotm_last
Definition: ProtChBody.h:53
chrono
Definition: ChBodyAddedMass.cpp:4
cppRigidBody
Definition: ProtChBody.h:32
cppRigidBody::addSpring
void addSpring(double stiffness, double damping, double *fairlead, double *anchor, double rest_length)
Definition: ProtChBody.h:423
cppRigidBody::getTriangleMeshSDF
void getTriangleMeshSDF(ChVector<> pos_node, double *dist_n)
Definition: ProtChBody.h:524
cppSystem::step
void step(double proteus_dt, int n_substeps)
Definition: ProtChBody.h:153
cppRigidBody::getTriangleMeshVel
void getTriangleMeshVel(double *x, double dt, double *vel)
Definition: ProtChBody.h:552
cppRigidBody::pos
ChVector pos
Definition: ProtChBody.h:36
cppRigidBody::F
ChVector F
Definition: ProtChBody.h:57
pos
double pos(double a)
Definition: testFMMandFSW.cpp:8
cppRigidBody::rotq0_trimesh
ChQuaternion rotq0_trimesh
Definition: ProtChBody.h:43
cppRigidBody::calculate_init
void calculate_init()
Definition: ProtChBody.h:240
cppSystem::directory
std::string directory
Definition: ProtChBody.h:22
cppRigidBody::hxyz
ChVector< double > hxyz(double *x, double t)
Definition: ProtChBody.h:201
cppSystem
Definition: ProtChBody.h:17
cppRigidBody::acc_last
ChVector acc_last
Definition: ProtChBody.h:47
cppRigidBody::setPrescribedMotionCustom
void setPrescribedMotionCustom(std::vector< double > t, std::vector< double > x, std::vector< double > y, std::vector< double > z, std::vector< double > ang, std::vector< double > ang2, std::vector< double > ang3, double t_max)
Definition: ProtChBody.h:321
cppRigidBody::setName
void setName(std::string name)
Definition: ProtChBody.h:520
newRigidBody
cppRigidBody * newRigidBody(cppSystem *system)
Definition: ProtChBody.h:586
no_op_delete::operator()
void operator()(void *)
Definition: ProtChBody.h:628