7 #include "imstkCapsule.h" 8 #include "imstkCollisionHandling.h" 9 #include "imstkGeometry.h" 10 #include "imstkMath.h" 11 #include "imstkMeshIO.h" 12 #include "imstkPbdModel.h" 13 #include "imstkPbdModelConfig.h" 14 #include "imstkPbdObject.h" 15 #include "imstkPbdObjectCollision.h" 16 #include "imstkPointSetToCapsuleCD.h" 17 #include "imstkPointwiseMap.h" 18 #include "imstkRbdConstraint.h" 19 #include "imstkScene.h" 20 #include "imstkSphere.h" 21 #include "imstkSurfaceMesh.h" 22 #include "imstkSurfaceMeshToCapsuleCD.h" 23 #include "imstkTetrahedralMesh.h" 25 #include <benchmark/benchmark.h> 27 using namespace imstk;
35 static std::shared_ptr<TetrahedralMesh>
36 makeTetGrid(
const Vec3d& size,
const Vec3i& dim,
const Vec3d& center)
38 auto prismMesh = std::make_shared<TetrahedralMesh>();
39 auto verticesPtr = std::make_shared<VecDataArray<double, 3>>(dim[0] * dim[1] * dim[2]);
42 const Vec3d dx = size.cwiseQuotient((dim - Vec3i(1, 1, 1)).cast<double>());
43 for (
int z = 0; z < dim[2]; z++)
45 for (
int y = 0; y < dim[1]; y++)
47 for (
int x = 0; x < dim[0]; x++)
49 vertices[x + dim[0] * (y + dim[1] * z)] = Vec3i(x, y, z).
cast<
double>().cwiseProduct(dx) - size * 0.5 + center;
55 auto indicesPtr = std::make_shared<VecDataArray<int, 4>>();
58 for (
int z = 0; z < dim[2] - 1; z++)
60 for (
int y = 0; y < dim[1] - 1; y++)
62 for (
int x = 0; x < dim[0] - 1; x++)
66 x + dim[0] * (y + dim[1] * z),
67 (x + 1) + dim[0] * (y + dim[1] * z),
68 (x + 1) + dim[0] * (y + dim[1] * (z + 1)),
69 x + dim[0] * (y + dim[1] * (z + 1)),
70 x + dim[0] * ((y + 1) + dim[1] * z),
71 (x + 1) + dim[0] * ((y + 1) + dim[1] * z),
72 (x + 1) + dim[0] * ((y + 1) + dim[1] * (z + 1)),
73 x + dim[0] * ((y + 1) + dim[1] * (z + 1))
77 if ((z % 2 ^ x % 2) ^ y % 2)
79 indices.
push_back(Vec4i(cubeIndices[0], cubeIndices[7], cubeIndices[5], cubeIndices[4]));
80 indices.push_back(Vec4i(cubeIndices[3], cubeIndices[7], cubeIndices[2], cubeIndices[0]));
81 indices.push_back(Vec4i(cubeIndices[2], cubeIndices[7], cubeIndices[5], cubeIndices[0]));
82 indices.push_back(Vec4i(cubeIndices[1], cubeIndices[2], cubeIndices[0], cubeIndices[5]));
83 indices.push_back(Vec4i(cubeIndices[2], cubeIndices[6], cubeIndices[7], cubeIndices[5]));
87 indices.push_back(Vec4i(cubeIndices[3], cubeIndices[7], cubeIndices[6], cubeIndices[4]));
88 indices.push_back(Vec4i(cubeIndices[1], cubeIndices[3], cubeIndices[6], cubeIndices[4]));
89 indices.push_back(Vec4i(cubeIndices[3], cubeIndices[6], cubeIndices[2], cubeIndices[1]));
90 indices.push_back(Vec4i(cubeIndices[1], cubeIndices[6], cubeIndices[5], cubeIndices[4]));
91 indices.push_back(Vec4i(cubeIndices[0], cubeIndices[3], cubeIndices[1], cubeIndices[4]));
97 auto uvCoordsPtr = std::make_shared<VecDataArray<float, 2>>(dim[0] * dim[1] * dim[2]);
100 for (
int z = 0; z < dim[2]; z++)
102 for (
int y = 0; y < dim[1]; y++)
104 for (
int x = 0; x < dim[0]; x++)
106 uvCoords[x + dim[0] * (y + dim[1] * z)] = Vec2f(static_cast<float>(x) / dim[0],
static_cast<float>(z) / dim[2]) * 3.0;
112 for (
int i = 0; i < indices.size(); i++)
114 if (tetVolume(vertices[indices[i][0]], vertices[indices[i][1]], vertices[indices[i][2]], vertices[indices[i][3]]) < 0.0)
116 std::swap(indices[i][0], indices[i][2]);
120 prismMesh->initialize(verticesPtr, indicesPtr);
121 prismMesh->setVertexTCoords(
"uvs", uvCoordsPtr);
130 BM_DistanceVolume(benchmark::State& state)
133 std::shared_ptr<Scene> scene = std::make_shared<Scene>(
"PbdBenchmark");
138 std::shared_ptr<PbdObject> prismObj = std::make_shared<PbdObject>(
"Prism");
141 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
142 Vec3d(4.0, 4.0, 4.0),
143 Vec3i(state.range(0), state.range(0), state.range(0)),
144 Vec3d(0.0, 0.0, 0.0));
147 std::shared_ptr<PbdModelConfig> pbdParams = std::make_shared<PbdModelConfig>();
149 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Volume, 1.0);
150 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Distance, 1.0);
151 pbdParams->m_doPartitioning =
false;
152 pbdParams->m_gravity = Vec3d(0.0, -1.0, 0.0);
153 pbdParams->m_dt = dt;
154 pbdParams->m_iterations = state.range(1);
155 pbdParams->m_linearDampingCoeff = 0.03;
158 auto pbdModel = std::make_shared<PbdModel>();
159 pbdModel->configure(pbdParams);
162 prismObj->setPhysicsGeometry(prismMesh);
163 prismObj->setDynamicalModel(pbdModel);
164 prismObj->getPbdBody()->uniformMassValue = 0.05;
166 for (
int z = 0; z < state.range(0); z++)
168 for (
int y = 0; y < state.range(0); y++)
170 for (
int x = 0; x < state.range(0); x++)
172 if (y == state.range(0) - 1)
174 prismObj->getPbdBody()->fixedNodeIds.push_back(x + state.range(0) * (y + state.range(0) * z));
181 scene->addSceneObject(prismObj);
185 state.counters[
"DOFs"] = state.range(0) * state.range(0) * state.range(0);
186 state.counters[
"Tets"] = prismMesh->getNumTetrahedra();
187 state.counters[
"Iterations"] = state.range(1);
196 BENCHMARK(BM_DistanceVolume)
197 ->Unit(benchmark::kMillisecond)
198 ->Name(
"Distance and Volume Constraints: Tet Mesh")
199 ->ArgsProduct({ { 4, 6, 8, 10, 16, 20 }, { 2, 5, 8 } });
205 BM_DistanceDihedral(benchmark::State& state)
208 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
211 auto prismObj = std::make_shared<PbdObject>(
"Prism");
214 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
215 Vec3d(4.0, 4.0, 4.0),
216 Vec3i(state.range(0), state.range(0), state.range(0)),
217 Vec3d(0.0, 0.0, 0.0));
219 std::shared_ptr<SurfaceMesh> surfMesh = prismMesh->extractSurfaceMesh();
222 auto pbdParams = std::make_shared<PbdModelConfig>();
224 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Dihedral, 1.0);
225 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Distance, 1.0);
226 pbdParams->m_doPartitioning =
false;
227 pbdParams->m_gravity = Vec3d(0.0, -8.0, 0.0);
228 pbdParams->m_dt = dt;
229 pbdParams->m_iterations = state.range(1);
230 pbdParams->m_linearDampingCoeff = 0.03;
233 auto pbdModel = std::make_shared<PbdModel>();
234 pbdModel->configure(pbdParams);
237 prismObj->setPhysicsGeometry(surfMesh);
238 prismObj->setDynamicalModel(pbdModel);
239 prismObj->getPbdBody()->uniformMassValue = 0.05;
241 for (
int vert_id = 0; vert_id < surfMesh->getNumVertices(); vert_id++)
243 auto position = surfMesh->getVertexPosition(vert_id);
244 if (position.y() == 2.0)
246 prismObj->getPbdBody()->fixedNodeIds.push_back(vert_id);
250 scene->addSceneObject(prismObj);
254 state.counters[
"DOFs"] = surfMesh->getNumVertices();
255 state.counters[
"Tris"] = surfMesh->getNumTriangles();
256 state.counters[
"Iterations"] = state.range(1);
265 BENCHMARK(BM_DistanceDihedral)
266 ->Unit(benchmark::kMillisecond)
267 ->Name(
"Distance and Dihedral Constraints: Surface Mesh")
268 ->ArgsProduct({ { 4, 8, 10, 16, 26, 38 }, { 2, 5, 8 } });
275 BM_PbdFemStVK(benchmark::State& state)
278 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
283 auto prismObj = std::make_shared<PbdObject>(
"Prism");
286 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
287 Vec3d(4.0, 4.0, 4.0),
288 Vec3i(state.range(0), state.range(0), state.range(0)),
289 Vec3d(0.0, 0.0, 0.0));
292 auto pbdParams = std::make_shared<PbdModelConfig>();
294 pbdParams->m_femParams->m_YoungModulus = 5.0;
295 pbdParams->m_femParams->m_PoissonRatio = 0.4;
296 pbdParams->enableFemConstraint(PbdFemConstraint::MaterialType::StVK);
297 pbdParams->m_doPartitioning =
false;
298 pbdParams->m_gravity = Vec3d(0.0, -1.0, 0.0);
299 pbdParams->m_dt = dt;
300 pbdParams->m_iterations = state.range(1);
301 pbdParams->m_linearDampingCoeff = 0.03;
304 auto pbdModel = std::make_shared<PbdModel>();
305 pbdModel->configure(pbdParams);
308 prismObj->setPhysicsGeometry(prismMesh);
309 prismObj->setDynamicalModel(pbdModel);
310 prismObj->getPbdBody()->uniformMassValue = 0.05;
313 for (
int z = 0; z < state.range(0); z++)
315 for (
int y = 0; y < state.range(0); y++)
317 for (
int x = 0; x < state.range(0); x++)
319 if (y == state.range(0) - 1)
321 prismObj->getPbdBody()->fixedNodeIds.push_back(x + state.range(0) * (y + state.range(0) * z));
328 scene->addSceneObject(prismObj);
332 state.counters[
"DOFs"] = prismMesh->getNumVertices();
333 state.counters[
"Tets"] = prismMesh->getNumTetrahedra();
334 state.counters[
"Iterations"] = state.range(1);
343 BENCHMARK(BM_PbdFemStVK)
344 ->Unit(benchmark::kMillisecond)
345 ->Name(
"FEM StVK Constraints: Tet Mesh")
346 ->ArgsProduct({ { 4, 6, 8, 10, 16, 20 }, { 2, 5, 8 } });
352 BM_PbdFemCorotation(benchmark::State& state)
355 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
360 auto prismObj = std::make_shared<PbdObject>(
"Prism");
363 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
364 Vec3d(4.0, 4.0, 4.0),
365 Vec3i(state.range(0), state.range(0), state.range(0)),
366 Vec3d(0.0, 0.0, 0.0));
369 auto pbdParams = std::make_shared<PbdModelConfig>();
371 pbdParams->m_femParams->m_YoungModulus = 5.0;
372 pbdParams->m_femParams->m_PoissonRatio = 0.4;
373 pbdParams->enableFemConstraint(PbdFemConstraint::MaterialType::Corotation);
374 pbdParams->m_doPartitioning =
false;
375 pbdParams->m_gravity = Vec3d(0.0, -1.0, 0.0);
376 pbdParams->m_dt = dt;
377 pbdParams->m_iterations = state.range(1);
378 pbdParams->m_linearDampingCoeff = 0.03;
381 auto pbdModel = std::make_shared<PbdModel>();
382 pbdModel->configure(pbdParams);
385 prismObj->setPhysicsGeometry(prismMesh);
386 prismObj->setDynamicalModel(pbdModel);
387 prismObj->getPbdBody()->uniformMassValue = 0.05;
390 for (
int z = 0; z < state.range(0); z++)
392 for (
int y = 0; y < state.range(0); y++)
394 for (
int x = 0; x < state.range(0); x++)
396 if (y == state.range(0) - 1)
398 prismObj->getPbdBody()->fixedNodeIds.push_back(x + state.range(0) * (y + state.range(0) * z));
405 scene->addSceneObject(prismObj);
409 state.counters[
"DOFs"] = prismMesh->getNumVertices();
410 state.counters[
"Tets"] = prismMesh->getNumTetrahedra();
411 state.counters[
"Iterations"] = state.range(1);
420 BENCHMARK(BM_PbdFemCorotation)
421 ->Unit(benchmark::kMillisecond)
422 ->Name(
"FEM Corotation Constraints: Tet Mesh")
423 ->ArgsProduct({ { 4, 6, 8, 10, 16, 20 }, { 2, 5, 8 } });
429 BM_PbdFemNeoHookean(benchmark::State& state)
432 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
437 auto prismObj = std::make_shared<PbdObject>(
"Prism");
440 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
441 Vec3d(4.0, 4.0, 4.0),
442 Vec3i(state.range(0), state.range(0), state.range(0)),
443 Vec3d(0.0, 0.0, 0.0));
446 auto pbdParams = std::make_shared<PbdModelConfig>();
448 pbdParams->m_femParams->m_YoungModulus = 5.0;
449 pbdParams->m_femParams->m_PoissonRatio = 0.4;
450 pbdParams->enableFemConstraint(PbdFemConstraint::MaterialType::NeoHookean);
451 pbdParams->m_doPartitioning =
false;
452 pbdParams->m_gravity = Vec3d(0.0, -1.0, 0.0);
453 pbdParams->m_dt = dt;
454 pbdParams->m_iterations = state.range(1);
455 pbdParams->m_linearDampingCoeff = 0.03;
458 auto pbdModel = std::make_shared<PbdModel>();
459 pbdModel->configure(pbdParams);
462 prismObj->setPhysicsGeometry(prismMesh);
463 prismObj->setDynamicalModel(pbdModel);
464 prismObj->getPbdBody()->uniformMassValue = 0.05;
467 for (
int z = 0; z < state.range(0); z++)
469 for (
int y = 0; y < state.range(0); y++)
471 for (
int x = 0; x < state.range(0); x++)
473 if (y == state.range(0) - 1)
475 prismObj->getPbdBody()->fixedNodeIds.push_back(x + state.range(0) * (y + state.range(0) * z));
482 scene->addSceneObject(prismObj);
486 state.counters[
"DOFs"] = prismMesh->getNumVertices();
487 state.counters[
"Tets"] = prismMesh->getNumTetrahedra();
488 state.counters[
"Iterations"] = state.range(1);
497 BENCHMARK(BM_PbdFemNeoHookean)
498 ->Unit(benchmark::kMillisecond)
499 ->Name(
"FEM NeoHookean Constraints: Tet Mesh")
500 ->ArgsProduct({ { 4, 6, 8, 10, 16, 20 }, { 2, 5, 8 } });
506 BM_PbdFemLinear(benchmark::State& state)
509 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
514 auto prismObj = std::make_shared<PbdObject>(
"Prism");
517 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
518 Vec3d(4.0, 4.0, 4.0),
519 Vec3i(state.range(0), state.range(0), state.range(0)),
520 Vec3d(0.0, 0.0, 0.0));
523 auto pbdParams = std::make_shared<PbdModelConfig>();
525 pbdParams->m_femParams->m_YoungModulus = 5.0;
526 pbdParams->m_femParams->m_PoissonRatio = 0.4;
527 pbdParams->enableFemConstraint(PbdFemConstraint::MaterialType::Linear);
528 pbdParams->m_doPartitioning =
false;
529 pbdParams->m_gravity = Vec3d(0.0, -1.0, 0.0);
530 pbdParams->m_dt = dt;
531 pbdParams->m_iterations = state.range(1);
532 pbdParams->m_linearDampingCoeff = 0.03;
535 auto pbdModel = std::make_shared<PbdModel>();
536 pbdModel->configure(pbdParams);
539 prismObj->setPhysicsGeometry(prismMesh);
540 prismObj->setDynamicalModel(pbdModel);
541 prismObj->getPbdBody()->uniformMassValue = 0.05;
544 for (
int z = 0; z < state.range(0); z++)
546 for (
int y = 0; y < state.range(0); y++)
548 for (
int x = 0; x < state.range(0); x++)
550 if (y == state.range(0) - 1)
552 prismObj->getPbdBody()->fixedNodeIds.push_back(x + state.range(0) * (y + state.range(0) * z));
559 scene->addSceneObject(prismObj);
563 state.counters[
"DOFs"] = prismMesh->getNumVertices();
564 state.counters[
"Tets"] = prismMesh->getNumTetrahedra();
565 state.counters[
"Iterations"] = state.range(1);
574 BENCHMARK(BM_PbdFemLinear)
575 ->Unit(benchmark::kMillisecond)
576 ->Name(
"FEM Linear Constraints: Tet Mesh")
577 ->ArgsProduct({ { 4, 6, 8, 10, 16, 20 }, { 2, 5, 8 } });
584 BM_PbdContactDistanceVol(benchmark::State& state)
587 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
592 auto prismObj = std::make_shared<PbdObject>(
"Prism");
595 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
596 Vec3d(4.0, 4.0, 4.0),
597 Vec3i(state.range(0), state.range(0), state.range(0)),
598 Vec3d(0.0, 0.0, 0.0));
601 std::shared_ptr<SurfaceMesh> surfMesh = prismMesh->extractSurfaceMesh();
604 prismObj->setCollidingGeometry(surfMesh);
607 prismObj->setPhysicsToCollidingMap(std::make_shared<PointwiseMap>(prismMesh, surfMesh));
610 auto pbdParams = std::make_shared<PbdModelConfig>();
612 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Volume, 0.9);
613 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Distance, 0.9);
614 pbdParams->m_doPartitioning =
false;
615 pbdParams->m_gravity = Vec3d(0.0, -1.0 / (
double)state.range(0), 0.0);
616 pbdParams->m_dt = 0.05;
617 pbdParams->m_iterations = state.range(1);
618 pbdParams->m_linearDampingCoeff = 0.03;
621 auto pbdModel = std::make_shared<PbdModel>();
622 pbdModel->configure(pbdParams);
625 prismObj->setPhysicsGeometry(prismMesh);
626 prismObj->setDynamicalModel(pbdModel);
627 prismObj->getPbdBody()->uniformMassValue = 0.05;
629 for (
int z = 0; z < state.range(0); z++)
631 for (
int y = 0; y < state.range(0); y++)
633 for (
int x = 0; x < state.range(0); x++)
635 if (y == state.range(0) - 1)
637 prismObj->getPbdBody()->fixedNodeIds.push_back(x + state.range(0) * (y + state.range(0) * z));
644 auto capsule = std::make_shared<Capsule>();
645 capsule->setRadius(0.5);
646 capsule->setLength(2);
647 capsule->setPosition(Vec3d(0.0, -2.6, 0.0));
648 capsule->setOrientation(Quatd(0.707, 0.0, 0.0, 0.707));
651 std::shared_ptr<CollidingObject> collisionObj = std::make_shared<CollidingObject>(
"CollidingObject");
652 collisionObj->setCollidingGeometry(capsule);
653 collisionObj->setVisualGeometry(capsule);
654 scene->addSceneObject(collisionObj);
656 std::shared_ptr<PbdObjectCollision> pbdInteraction =
657 std::make_shared<PbdObjectCollision>(prismObj, collisionObj,
"SurfaceMeshToCapsuleCD");
658 pbdInteraction->setFriction(0.0);
659 pbdInteraction->setRestitution(0.0);
661 scene->addInteraction(pbdInteraction);
664 scene->addSceneObject(prismObj);
668 state.counters[
"DOFs"] = prismMesh->getNumVertices();
669 state.counters[
"Tets"] = prismMesh->getNumTetrahedra();
670 state.counters[
"Iterations"] = state.range(1);
679 BENCHMARK(BM_PbdContactDistanceVol)
680 ->Unit(benchmark::kMillisecond)
681 ->Name(
"Distance and Volume Constraints with Contact: Tet Mesh")
682 ->ArgsProduct({ { 4, 6, 8, 10, 16, 20 }, { 2, 5, 8 } });
688 BM_PbdContactDistanceDihedral(benchmark::State& state)
691 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
694 auto prismObj = std::make_shared<PbdObject>(
"Prism");
697 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
698 Vec3d(4.0, 4.0, 4.0),
699 Vec3i(state.range(0), state.range(0), state.range(0)),
700 Vec3d(0.0, 0.0, 0.0));
703 std::shared_ptr<SurfaceMesh> surfMesh = prismMesh->extractSurfaceMesh();
706 prismObj->setCollidingGeometry(surfMesh);
709 auto pbdParams = std::make_shared<PbdModelConfig>();
711 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Dihedral, 0.9);
712 pbdParams->enableConstraint(PbdModelConfig::ConstraintGenType::Distance, 0.9);
713 pbdParams->m_doPartitioning =
false;
714 pbdParams->m_gravity = Vec3d(0.0, -2.0 / (
double)state.range(0), 0.0);
715 pbdParams->m_dt = dt;
716 pbdParams->m_iterations = state.range(1);
717 pbdParams->m_linearDampingCoeff = 0.03;
720 auto pbdModel = std::make_shared<PbdModel>();
721 pbdModel->configure(pbdParams);
724 prismObj->setPhysicsGeometry(surfMesh);
725 prismObj->setDynamicalModel(pbdModel);
726 prismObj->getPbdBody()->uniformMassValue = 0.05;
728 for (
int vert_id = 0; vert_id < surfMesh->getNumVertices(); vert_id++)
730 auto position = surfMesh->getVertexPosition(vert_id);
733 if (position.y() == 2.0)
735 prismObj->getPbdBody()->fixedNodeIds.push_back(vert_id);
740 auto capsule = std::make_shared<Capsule>();
741 capsule->setRadius(0.5);
742 capsule->setLength(2);
743 capsule->setPosition(Vec3d(0.0, -2.6, 0.0));
744 capsule->setOrientation(Quatd(0.707, 0.0, 0.0, 0.707));
747 std::shared_ptr<CollidingObject> collisionObj = std::make_shared<CollidingObject>(
"CollidingObject");
748 collisionObj->setCollidingGeometry(capsule);
749 collisionObj->setVisualGeometry(capsule);
750 scene->addSceneObject(collisionObj);
752 std::shared_ptr<PbdObjectCollision> pbdInteraction =
753 std::make_shared<PbdObjectCollision>(prismObj, collisionObj,
"SurfaceMeshToCapsuleCD");
754 pbdInteraction->setFriction(0.0);
755 pbdInteraction->setRestitution(0.0);
757 scene->addInteraction(pbdInteraction);
759 scene->addSceneObject(prismObj);
763 state.counters[
"DOFs"] = surfMesh->getNumVertices();
764 state.counters[
"Tris"] = surfMesh->getNumTriangles();
765 state.counters[
"Iterations"] = state.range(1);
777 BENCHMARK(BM_PbdContactDistanceDihedral)
778 ->Unit(benchmark::kMillisecond)
779 ->Name(
"Distance and Dihedral Angle Constraints with Contact: Surface Mesh")
780 ->ArgsProduct({ { 4, 8, 10, 16, 26, 38 }, { 2, 5, 8 } });
787 BM_PbdFemContact(benchmark::State& state)
790 auto scene = std::make_shared<Scene>(
"PbdBenchmark");
795 auto prismObj = std::make_shared<PbdObject>(
"Prism");
798 std::shared_ptr<TetrahedralMesh> prismMesh = makeTetGrid(
799 Vec3d(4.0, 4.0, 4.0),
800 Vec3i(state.range(0), state.range(0), state.range(0)),
801 Vec3d(0.0, 0.0, 0.0));
804 std::shared_ptr<SurfaceMesh> surfMesh = prismMesh->extractSurfaceMesh();
807 prismObj->setCollidingGeometry(surfMesh);
810 prismObj->setPhysicsToCollidingMap(std::make_shared<PointwiseMap>(prismMesh, surfMesh));
813 auto pbdParams = std::make_shared<PbdModelConfig>();
815 pbdParams->m_femParams->m_YoungModulus = 5.0;
816 pbdParams->m_femParams->m_PoissonRatio = 0.4;
817 pbdParams->enableFemConstraint(PbdFemConstraint::MaterialType::StVK);
818 pbdParams->m_doPartitioning =
false;
819 pbdParams->m_gravity = Vec3d(0.0, -1.0, 0.0);
820 pbdParams->m_dt = dt;
821 pbdParams->m_iterations = state.range(1);
822 pbdParams->m_linearDampingCoeff = 0.03;
825 auto pbdModel = std::make_shared<PbdModel>();
826 pbdModel->configure(pbdParams);
829 prismObj->setPhysicsGeometry(prismMesh);
830 prismObj->setDynamicalModel(pbdModel);
831 prismObj->getPbdBody()->uniformMassValue = 0.05;
833 for (
int z = 0; z < state.range(0); z++)
835 for (
int y = 0; y < state.range(0); y++)
837 for (
int x = 0; x < state.range(0); x++)
839 if (y == state.range(0) - 1)
841 prismObj->getPbdBody()->fixedNodeIds.push_back(x + state.range(0) * (y + state.range(0) * z));
848 auto capsule = std::make_shared<Capsule>();
849 capsule->setRadius(0.5);
850 capsule->setLength(2);
851 capsule->setPosition(Vec3d(0.0, -2.6, 0.0));
852 capsule->setOrientation(Quatd(0.707, 0.0, 0.0, 0.707));
855 std::shared_ptr<CollidingObject> collisionObj = std::make_shared<CollidingObject>(
"CollidingObject");
856 collisionObj->setCollidingGeometry(capsule);
857 collisionObj->setVisualGeometry(capsule);
858 scene->addSceneObject(collisionObj);
860 std::shared_ptr<PbdObjectCollision> pbdInteraction =
861 std::make_shared<PbdObjectCollision>(prismObj, collisionObj,
"SurfaceMeshToCapsuleCD");
862 pbdInteraction->setFriction(0.0);
863 pbdInteraction->setRestitution(0.0);
865 scene->addInteraction(pbdInteraction);
868 scene->addSceneObject(prismObj);
872 state.counters[
"DOFs"] = prismMesh->getNumVertices();
873 state.counters[
"Tets"] = prismMesh->getNumTetrahedra();
874 state.counters[
"Iterations"] = state.range(1);
883 BENCHMARK(BM_PbdFemContact)
884 ->Unit(benchmark::kMillisecond)
885 ->Name(
"FEM Constraints with contact: Tet Mesh")
886 ->ArgsProduct({ { 4, 6, 8, 10, 16, 20 }, { 2, 5, 8 } });
void push_back(const ValueType &val)
Append the data array to hold the new value, resizes if neccesary.
VecDataArray< U, N > cast()
Templated copy the current array with a new internal data type, does not change the number of compone...