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