From 7edbdd0ad6a6e9fd99d6bc906037b2334f5f9da1 Mon Sep 17 00:00:00 2001 From: Alessio Quaglino Date: Mon, 19 May 2025 10:50:27 -0700 Subject: [PATCH] Remove the Shell plugin and integrate it into the engine. PiperOrigin-RevId: 760688502 Change-Id: Ia70988d42b7edf571d7cb4a4f48f8fc50b51667d --- doc/XMLreference.rst | 6 +- doc/changelog.rst | 2 + model/flex/bunny.xml | 2 +- model/flex/bunny_with_uv.xml | 2 +- .../flag_flex.xml => flex/flag.xml} | 7 +- .../{plugin/elasticity => flex}/mannequin.xml | 0 .../pancake_flex.xml => flex/pancake.xml} | 6 +- .../plate_flex.xml => flex/plate.xml} | 7 +- .../poncho_flex.xml => flex/poncho.xml} | 7 +- .../poncho_vertcollide.xml | 7 +- model/flex/trampoline.xml | 2 +- plugin/elasticity/CMakeLists.txt | 2 - plugin/elasticity/README.md | 12 -- plugin/elasticity/register.cc | 2 - plugin/elasticity/shell.cc | 154 ------------------ plugin/elasticity/shell.h | 61 ------- src/engine/engine_passive.c | 43 ++++- src/user/user_init.c | 1 - src/user/user_mesh.cc | 17 +- src/user/user_model.cc | 2 +- src/xml/xml_base.h | 1 + src/xml/xml_native_reader.cc | 13 +- src/xml/xml_native_writer.cc | 2 +- .../engine_util_sparse_benchmark_test.cc | 2 +- test/benchmark/parse_benchmark_test.cc | 2 +- test/benchmark/step_benchmark_test.cc | 2 +- test/engine/engine_plugin_test.cc | 2 +- test/plugin/elasticity/elasticity_test.cc | 15 +- 28 files changed, 90 insertions(+), 291 deletions(-) rename model/{plugin/elasticity/flag_flex.xml => flex/flag.xml} (88%) rename model/{plugin/elasticity => flex}/mannequin.xml (100%) rename model/{plugin/elasticity/pancake_flex.xml => flex/pancake.xml} (90%) rename model/{plugin/elasticity/plate_flex.xml => flex/plate.xml} (87%) rename model/{plugin/elasticity/poncho_flex.xml => flex/poncho.xml} (99%) rename model/{plugin/elasticity => flex}/poncho_vertcollide.xml (99%) delete mode 100644 plugin/elasticity/shell.cc delete mode 100644 plugin/elasticity/shell.h diff --git a/doc/XMLreference.rst b/doc/XMLreference.rst index 1f479369..a57f1a1f 100644 --- a/doc/XMLreference.rst +++ b/doc/XMLreference.rst @@ -4073,9 +4073,9 @@ stress-strain relationship.. See also :ref:`deformable ` objects. .. _flex-elasticity-elastic2d: -:at:`elastic2d`: :at-val:`int, "1"` - Elastic contribution to passive forces of 2D flexes. 0: none, 1: bending only, 2: stretching only, 3: bending and - stretching +:at:`elastic2d`: :at-val:`[none, bend, stretch, both], "none"` + Elastic contribution to passive forces of 2D flexes. "none": none, "bend": bending only, "stretch": stretching only, + "both": bending and stretching. .. _flex-contact: diff --git a/doc/changelog.rst b/doc/changelog.rst index 4255c8f0..9e0329f4 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -9,6 +9,8 @@ General ^^^^^^^ - Refactored island implementation so that island data is memory-contiguous. This speeds up island processing in the solver and clears the way for the addition of the Newton and PGS solvers (currently only CG is supported). +- Removed the :at:`shell` plugin. This is now supported by :ref:`flexcomp` and is active depending on + the :ref:`elastic2d` attribute (on by default). simulate ^^^^^^^^ diff --git a/model/flex/bunny.xml b/model/flex/bunny.xml index 64e081ef..ec31684e 100644 --- a/model/flex/bunny.xml +++ b/model/flex/bunny.xml @@ -31,7 +31,7 @@ - + diff --git a/model/flex/bunny_with_uv.xml b/model/flex/bunny_with_uv.xml index 5b9e42e4..c3cde418 100644 --- a/model/flex/bunny_with_uv.xml +++ b/model/flex/bunny_with_uv.xml @@ -37,7 +37,7 @@ - + diff --git a/model/plugin/elasticity/flag_flex.xml b/model/flex/flag.xml similarity index 88% rename from model/plugin/elasticity/flag_flex.xml rename to model/flex/flag.xml index 9e37edab..c7bfa371 100644 --- a/model/plugin/elasticity/flag_flex.xml +++ b/model/flex/flag.xml @@ -26,10 +26,6 @@ - - - - @@ -37,8 +33,7 @@ - - + diff --git a/model/plugin/elasticity/mannequin.xml b/model/flex/mannequin.xml similarity index 100% rename from model/plugin/elasticity/mannequin.xml rename to model/flex/mannequin.xml diff --git a/model/plugin/elasticity/pancake_flex.xml b/model/flex/pancake.xml similarity index 90% rename from model/plugin/elasticity/pancake_flex.xml rename to model/flex/pancake.xml index fb390e34..8e3d1ec1 100644 --- a/model/plugin/elasticity/pancake_flex.xml +++ b/model/flex/pancake.xml @@ -16,10 +16,6 @@ - - - - diff --git a/model/plugin/elasticity/plate_flex.xml b/model/flex/plate.xml similarity index 87% rename from model/plugin/elasticity/plate_flex.xml rename to model/flex/plate.xml index e39ec427..9278c7fe 100644 --- a/model/plugin/elasticity/plate_flex.xml +++ b/model/flex/plate.xml @@ -16,10 +16,6 @@ - - - - diff --git a/model/plugin/elasticity/poncho_flex.xml b/model/flex/poncho.xml similarity index 99% rename from model/plugin/elasticity/poncho_flex.xml rename to model/flex/poncho.xml index 9400d106..c2462e56 100644 --- a/model/plugin/elasticity/poncho_flex.xml +++ b/model/flex/poncho.xml @@ -19,10 +19,6 @@ - - - - @@ -1418,9 +1414,8 @@ 398 399 418 398 376 378"> - + - diff --git a/model/plugin/elasticity/poncho_vertcollide.xml b/model/flex/poncho_vertcollide.xml similarity index 99% rename from model/plugin/elasticity/poncho_vertcollide.xml rename to model/flex/poncho_vertcollide.xml index 16e572bb..cb75a7cd 100644 --- a/model/plugin/elasticity/poncho_vertcollide.xml +++ b/model/flex/poncho_vertcollide.xml @@ -19,10 +19,6 @@ - - - - @@ -1418,9 +1414,8 @@ 398 399 418 398 376 378"> - + - diff --git a/model/flex/trampoline.xml b/model/flex/trampoline.xml index 16775a82..bb538201 100644 --- a/model/flex/trampoline.xml +++ b/model/flex/trampoline.xml @@ -39,7 +39,7 @@ radius=".001" mass="10" name="plate" dim="2"> - + diff --git a/plugin/elasticity/CMakeLists.txt b/plugin/elasticity/CMakeLists.txt index f6186261..97b2f412 100644 --- a/plugin/elasticity/CMakeLists.txt +++ b/plugin/elasticity/CMakeLists.txt @@ -22,8 +22,6 @@ set(MUJOCO_ELASTICITY_SRCS elasticity.cc elasticity.h register.cc - shell.cc - shell.h ) add_library(elasticity SHARED) diff --git a/plugin/elasticity/README.md b/plugin/elasticity/README.md index 2e86c1a7..7ccf5712 100644 --- a/plugin/elasticity/README.md +++ b/plugin/elasticity/README.md @@ -18,15 +18,3 @@ Parameters: - `bend` [Pa]: bending stiffness. - `flat` [bool]: if true, the stress-equilibrium configuration is that of a straight cable; if false or unspecified, it is the configuration defined in the XML. - `vmax` [N/m^2]: If greater than zero, the cable is colored using mechanical stresses; the value represent the maximum stress in the color scale. - -### Shell - -Implemented in [shell.cc](shell.cc). - -The shell plugin discretizes an inextensible 2D continuum. It is intended to simulate the bending of plates where the stretching is negligible compared to other deformation modes. - -Parameters: - - - `young` [Pa]: Young's modulus. - - `poisson` [Pa]: Poisson's ratio; if 0, then the material only opposed shear deformations; if near 0.5, then the material is nearly incompressible (rubber-like). - - `thickness` [m]: shell thickness, used to scale the bending stiffness. diff --git a/plugin/elasticity/register.cc b/plugin/elasticity/register.cc index edde5252..ab8d283a 100644 --- a/plugin/elasticity/register.cc +++ b/plugin/elasticity/register.cc @@ -14,13 +14,11 @@ #include #include "cable.h" -#include "shell.h" namespace mujoco::plugin::elasticity { mjPLUGIN_LIB_INIT { Cable::RegisterPlugin(); - Shell::RegisterPlugin(); } } // namespace mujoco::plugin::elasticity diff --git a/plugin/elasticity/shell.cc b/plugin/elasticity/shell.cc deleted file mode 100644 index 699040c6..00000000 --- a/plugin/elasticity/shell.cc +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright 2023 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include "elasticity.h" -#include "shell.h" - - -namespace mujoco::plugin::elasticity { -namespace { - -// local tetrahedron numbering -constexpr int kNumVerts = Stencil2D::kNumVerts; - - - -} // namespace - -// factory function -std::optional Shell::Create(const mjModel* m, mjData* d, int instance) { - return Shell(m, d, instance); -} - -// plugin constructor -Shell::Shell(const mjModel* m, mjData* d, int instance) - : f0(-1) { - // count plugin bodies - nv = 0; - for (int i = 1; i < m->nbody; i++) { - if (m->body_plugin[i] == instance) { - if (!nv++) { - i0 = i; - } - } - } - - // count flexes - for (int i = 0; i < m->nflex; i++) { - for (int j = 0; j < m->flex_vertnum[i]; j++) { - if (m->flex_vertbodyid[m->flex_vertadr[i]+j] == i0) { - f0 = i; - nv = m->flex_vertnum[f0]; - if (m->flex_dim[i] != 2) { // SHOULD NOT OCCUR - mju_error("mujoco.elasticity.shell requires a 2D mesh"); - } - } - } - } - - // loop over all triangles - for (int t = 0; t < m->flex_elemnum[f0]; t++) { - int* v = m->flex_elem + 3*(t+m->flex_elemadr[f0]); - for (int i = 0; i < kNumVerts; i++) { - if (m->body_plugin[i0+v[i]] != instance) { - mju_error("This body does not have the requested plugin instance"); - } - } - } - - // allocate array - position.assign(nv*3, 0); - - // store previous positions - mju_copy(position.data(), m->body_pos+3*i0, 3*nv); -} - -void Shell::Compute(const mjModel* m, mjData* d, int instance) { - for (int e = 0; e < m->flex_edgenum[f0]; e++) { - int* edge = m->flex_edge + 2*(e+m->flex_edgeadr[f0]); - int* flap = m->flex_edgeflap + 2*(e+m->flex_edgeadr[f0]); - int v[4] = {edge[0], edge[1], flap[0], flap[1]}; - mjtNum force[12] = {0}; - if (v[3] == -1) { - // skip boundary edges - continue; - } - mjtNum* k = m->flex_bending + 16*m->flex_edgeadr[f0]; - for (int i = 0; i < StencilFlap::kNumVerts; i++) { - for (int j = 0; j < StencilFlap::kNumVerts; j++) { - for (int x = 0; x < 3; x++) { - force[3*i+x] += k[16*e+4*i+j] * d->xpos[3*(i0+v[j])+x]; - } - } - } - - // update stored positions - mju_copy(position.data(), d->xpos+3*i0, 3*nv); - - // insert into global force - for (int i = 0; i < StencilFlap::kNumVerts; i++) { - for (int x = 0; x < 3; x++) { - d->qfrc_passive[m->body_dofadr[i0]+3*v[i]+x] -= force[3*i+x]; - } - } - } -} - - - -void Shell::RegisterPlugin() { - mjpPlugin plugin; - mjp_defaultPlugin(&plugin); - - plugin.name = "mujoco.elasticity.shell"; - plugin.capabilityflags |= mjPLUGIN_PASSIVE; - - const char* attributes[] = {"damping"}; - plugin.nattribute = sizeof(attributes) / sizeof(attributes[0]); - plugin.attributes = attributes; - plugin.nstate = +[](const mjModel* m, int instance) { return 0; }; - - plugin.init = +[](const mjModel* m, mjData* d, int instance) { - auto elasticity_or_null = Shell::Create(m, d, instance); - if (!elasticity_or_null.has_value()) { - return -1; - } - d->plugin_data[instance] = reinterpret_cast( - new Shell(std::move(*elasticity_or_null))); - return 0; - }; - plugin.destroy = +[](mjData* d, int instance) { - delete reinterpret_cast(d->plugin_data[instance]); - d->plugin_data[instance] = 0; - }; - plugin.compute = +[](const mjModel* m, mjData* d, int instance, int type) { - auto* elasticity = reinterpret_cast(d->plugin_data[instance]); - elasticity->Compute(m, d, instance); - }; - - mjp_registerPlugin(&plugin); -} - -} // namespace mujoco::plugin::elasticity diff --git a/plugin/elasticity/shell.h b/plugin/elasticity/shell.h deleted file mode 100644 index aa1e0191..00000000 --- a/plugin/elasticity/shell.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2023 DeepMind Technologies Limited -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef MUJOCO_PLUGIN_ELASTICITY_SHELL_H_ -#define MUJOCO_PLUGIN_ELASTICITY_SHELL_H_ - -#include -#include - -#include -#include -#include -#include "elasticity.h" - - -namespace mujoco::plugin::elasticity { - -struct StencilFlap { - static constexpr int kNumVerts = 4; - int vertices[kNumVerts]; -}; - -class Shell { - public: - // Returns a new Shell instance or nullopt on failure. - static std::optional Create(const mjModel* m, mjData* d, - int instance); - Shell(Shell&&) = default; - - Shell& operator=(Shell&& other) = default; - - void Compute(const mjModel* m, mjData* d, int instance); - - static void RegisterPlugin(); - - int i0; // index of first body - int f0; // index of corresponding flex - int nc; // number of quads in the grid - int nv; // number of vertices (bodies) in the Shell - - // precomputed quantities - std::vector position; // previous-step positions (nv x 3) - - private: - Shell(const mjModel* m, mjData* d, int instance); -}; - -} // namespace mujoco::plugin::elasticity - -#endif // MUJOCO_PLUGIN_ELASTICITY_SHELL_H_ diff --git a/src/engine/engine_passive.c b/src/engine/engine_passive.c index 3c025804..5b0d1b5b 100644 --- a/src/engine/engine_passive.c +++ b/src/engine/engine_passive.c @@ -116,9 +116,50 @@ static void mj_springdamper(const mjModel* m, mjData* d) { // flex elasticity for (int f=0; f < m->nflex; f++) { mjtNum* k = m->flex_stiffness + 21*m->flex_elemadr[f]; + mjtNum* b = m->flex_bending + 16*m->flex_edgeadr[f]; int dim = m->flex_dim[f]; - if (dim == 1 || m->flex_rigid[f] || k[0] == 0) { + if (dim == 1 || m->flex_rigid[f]) { + continue; + } + + // add bending forces to qfrc_spring + if (dim == 2) { + mjtNum* xpos = d->flexvert_xpos + 3*m->flex_vertadr[f]; + int* bodyid = m->flex_vertbodyid + m->flex_vertadr[f]; + + for (int e = 0; e < m->flex_edgenum[f]; e++) { + const int* edge = m->flex_edge + 2*(e+m->flex_edgeadr[f]); + const int* flap = m->flex_edgeflap + 2*(e+m->flex_edgeadr[f]); + int v[4] = {edge[0], edge[1], flap[0], flap[1]}; + if (v[3] == -1) { + // skip boundary edges + continue; + } + mjtNum force[12] = {0}; + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + for (int x = 0; x < 3; x++) { + force[3*i+x] += b[16*e+4*i+j] * xpos[3*v[j]+x]; + } + } + } + + // TODO: add damping + + // insert into global force + for (int i = 0; i < 4; i++) { + int bid = bodyid[v[i]]; + int body_dofnum = m->body_dofnum[bid]; + int body_dofadr = m->body_dofadr[bid]; + for (int x = 0; x < body_dofnum; x++) { + d->qfrc_spring[body_dofadr+x] -= force[3*i+x]; + } + } + } + } + + if (k[0] == 0) { continue; } diff --git a/src/user/user_init.c b/src/user/user_init.c index 3a55af25..01f4a8b9 100644 --- a/src/user/user_init.c +++ b/src/user/user_init.c @@ -238,7 +238,6 @@ void mjs_defaultFlex(mjsFlex* flex) { flex->rgba[0] = flex->rgba[1] = flex->rgba[2] = 0.5f; flex->rgba[3] = 1.0f; flex->thickness = -1; - flex->elastic2d = 1; } diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index 49230914..03ad956c 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -3382,9 +3382,13 @@ void mjCFlex::ResolveReferences(const mjCModel* m) { vertbodyid.clear(); nodebodyid.clear(); for (const auto& vertbody : vertbody_) { - mjCBase* pbody = m->FindObject(mjOBJ_BODY, vertbody); + mjCBody* pbody = static_cast(m->FindObject(mjOBJ_BODY, vertbody)); if (pbody) { vertbodyid.push_back(pbody->id); + if (pbody->joints.size() != 3 && dim == 2 && (elastic2d == 1 || elastic2d == 3)) { + // TODO(quaglino): add support for pins + throw mjCError(this, "pins are not supported for bending"); + } } else { throw mjCError(this, "unknown body '%s' in flex", vertbody.c_str()); } @@ -3658,7 +3662,10 @@ void mjCFlex::Compile(const mjVFS* vfs) { } // bending stiffness (2D only) - if (dim == 2 && (elastic2d == 1 || elastic2d == 3) && thickness > 0) { + if (dim == 2 && (elastic2d == 1 || elastic2d == 3)) { + if (thickness < 0) { + throw mjCError(this, "thickness must be positive for bending stiffness"); + } bending.assign(nedge*16, 0); for (unsigned int e = 0; e < nedge; e++) { @@ -3668,7 +3675,7 @@ void mjCFlex::Compile(const mjVFS* vfs) { } } - // add plugins + // placeholder for setting plugins parameters, currently not used for (const auto& vbodyid : vertbodyid) { if (vbodyid < 0) { continue; @@ -3676,8 +3683,8 @@ void mjCFlex::Compile(const mjVFS* vfs) { if (model->Bodies()[vbodyid]->plugin.element) { mjCPlugin* plugin_instance = static_cast(model->Bodies()[vbodyid]->plugin.element); - if (damping > 0) { - plugin_instance->config_attribs["damping"] = std::to_string(damping); + if (!plugin_instance) { + throw mjCError(this, "plugin instance not found"); } } } diff --git a/src/user/user_model.cc b/src/user/user_model.cc index 9e516380..49f79ead 100644 --- a/src/user/user_model.cc +++ b/src/user/user_model.cc @@ -3165,7 +3165,7 @@ void mjCModel::CopyObjects(mjModel* m) { for (int k=0; k < pfl->nedge; k++) { m->flex_edge[2*(edge_adr+k)] = pfl->edge[k].first; m->flex_edge[2*(edge_adr+k)+1] = pfl->edge[k].second; - if (pfl->dim == 2) { + if (pfl->dim == 2 && (pfl->elastic2d == 1 || pfl->elastic2d == 3)) { m->flex_edgeflap[2*(edge_adr+k)+0] = pfl->flaps[k].vertices[2]; m->flex_edgeflap[2*(edge_adr+k)+1] = pfl->flaps[k].vertices[3]; } else { diff --git a/src/xml/xml_base.h b/src/xml/xml_base.h index ba914229..3651d31c 100644 --- a/src/xml/xml_base.h +++ b/src/xml/xml_base.h @@ -71,6 +71,7 @@ extern const mjMap datatype_map[]; extern const mjMap meshtype_map[]; extern const mjMap meshinertia_map[]; extern const mjMap flexself_map[]; +extern const mjMap elastic2d_map[]; //---------------------------------- Base XML class ------------------------------------------------ diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index 8e2874aa..f2b5f1e9 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -807,6 +807,15 @@ const mjMap flexself_map[5] = { }; +// flex elastic 2d type +const mjMap elastic2d_map[5] = { + {"none", 0}, + {"bend", 1}, + {"stretch", 2}, + {"both", 3}, +}; + + //---------------------------------- class mjXReader implementation -------------------------------- @@ -1401,7 +1410,7 @@ void mjXReader::OneFlex(XMLElement* elem, mjsFlex* flex) { ReadAttr(elasticity, "poisson", 1, &flex->poisson, text); ReadAttr(elasticity, "thickness", 1, &flex->thickness, text); ReadAttr(elasticity, "damping", 1, &flex->damping, text); - ReadAttr(elasticity, "elastic2d", 1, &flex->elastic2d, text); + MapValue(elasticity, "elastic2d", &flex->elastic2d, elastic2d_map, 4); } // write error info @@ -2665,7 +2674,7 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjsBody* body, const mjVFS* vfs) { ReadAttr(elasticity, "poisson", 1, &dflex.poisson, text); ReadAttr(elasticity, "damping", 1, &dflex.damping, text); ReadAttr(elasticity, "thickness", 1, &dflex.thickness, text); - ReadAttr(elasticity, "elastic2d", 1, &dflex.elastic2d, text); + MapValue(elasticity, "elastic2d", &dflex.elastic2d, elastic2d_map, 4); } // check errors diff --git a/src/xml/xml_native_writer.cc b/src/xml/xml_native_writer.cc index 14905144..b6464cd1 100644 --- a/src/xml/xml_native_writer.cc +++ b/src/xml/xml_native_writer.cc @@ -194,7 +194,7 @@ void mjXWriter::OneFlex(XMLElement* elem, const mjCFlex* flex) { WriteAttr(elastic, "poisson", 1, &flex->poisson, &defflex.poisson); WriteAttr(elastic, "thickness", 1, &flex->thickness, &defflex.thickness); WriteAttr(elastic, "damping", 1, &flex->damping, &defflex.damping); - WriteAttr(elastic, "elastic2d", 1, &flex->elastic2d, &defflex.elastic2d); + WriteAttrKey(elastic, "elastic2d", elastic2d_map, 2, flex->elastic2d, defflex.elastic2d); // edge subelement XMLElement* edge = InsertEnd(elem, "edge"); diff --git a/test/benchmark/engine_util_sparse_benchmark_test.cc b/test/benchmark/engine_util_sparse_benchmark_test.cc index 82a04a3f..fdeadb31 100644 --- a/test/benchmark/engine_util_sparse_benchmark_test.cc +++ b/test/benchmark/engine_util_sparse_benchmark_test.cc @@ -343,7 +343,7 @@ void ABSL_ATTRIBUTE_NOINLINE mulMatVecSparse_8(mjtNum* res, // ----------------------------- benchmark ------------------------------------ static void BM_MatVecSparse(benchmark::State& state, int unroll) { - static mjModel* m = LoadModelFromPath("plugin/elasticity/flag_flex.xml"); + static mjModel* m = LoadModelFromPath("flex/flag.xml"); mjData* d = mj_makeData(m); // warm-up rollout to get a typical state diff --git a/test/benchmark/parse_benchmark_test.cc b/test/benchmark/parse_benchmark_test.cc index 059f0c58..95471c01 100644 --- a/test/benchmark/parse_benchmark_test.cc +++ b/test/benchmark/parse_benchmark_test.cc @@ -73,7 +73,7 @@ static void run_parse_benchmark(const std::string xml_path, // run_parse_benchmark). void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_ParseFlagPlugin(benchmark::State& state) { - run_parse_benchmark(GetModelPath("plugin/elasticity/flag_flex.xml"), state); + run_parse_benchmark(GetModelPath("flex/flag.xml"), state); } BENCHMARK(BM_ParseFlagPlugin); diff --git a/test/benchmark/step_benchmark_test.cc b/test/benchmark/step_benchmark_test.cc index 551e312c..1d34f2c9 100644 --- a/test/benchmark/step_benchmark_test.cc +++ b/test/benchmark/step_benchmark_test.cc @@ -73,7 +73,7 @@ static void run_step_benchmark(const mjModel* model, benchmark::State& state) { void ABSL_ATTRIBUTE_NO_TAIL_CALL BM_StepFlagPlugin(benchmark::State& state) { MujocoErrorTestGuard guard; - static mjModel* model = LoadModelFromPath("plugin/elasticity/flag_flex.xml"); + static mjModel* model = LoadModelFromPath("flex/flag.xml"); run_step_benchmark(model, state); } BENCHMARK(BM_StepFlagPlugin); diff --git a/test/engine/engine_plugin_test.cc b/test/engine/engine_plugin_test.cc index a1b5f959..5463f1e2 100644 --- a/test/engine/engine_plugin_test.cc +++ b/test/engine/engine_plugin_test.cc @@ -37,7 +37,7 @@ using ::testing::DoubleNear; using ::testing::HasSubstr; using ::testing::NotNull; -constexpr int kNumTruePlugins = 11; +constexpr int kNumTruePlugins = 10; constexpr int kNumFakePlugins = 30; constexpr int kNumTestPlugins = 4; diff --git a/test/plugin/elasticity/elasticity_test.cc b/test/plugin/elasticity/elasticity_test.cc index 754fa46e..ea4df2e3 100644 --- a/test/plugin/elasticity/elasticity_test.cc +++ b/test/plugin/elasticity/elasticity_test.cc @@ -22,7 +22,6 @@ #include #include #include "test/fixture.h" -#include "plugin/elasticity/shell.h" namespace mujoco { namespace { @@ -58,15 +57,10 @@ TEST_F(ElasticityTest, FlexCompatibility) { TEST_F(ElasticityTest, ElasticEnergyShell) { static constexpr char cantilever_xml[] = R"( - - - - - @@ -76,7 +70,8 @@ TEST_F(ElasticityTest, ElasticEnergyShell) { mjModel* m = LoadModelFromString(cantilever_xml, error, sizeof(error)); ASSERT_THAT(m, testing::NotNull()) << error; mjData* d = mj_makeData(m); - auto* shell = reinterpret_cast(d->plugin_data[0]); + mj_kinematics(m, d); + mj_flex(m, d); // check that a plane is in the kernel of the energy for (mjtNum scale = 1; scale < 4; scale++) { @@ -92,8 +87,8 @@ TEST_F(ElasticityTest, ElasticEnergyShell) { for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int x = 0; x < 3; x++) { - mjtNum elongation1 = scale * shell->position[3*v[i]+x]; - mjtNum elongation2 = scale * shell->position[3*v[j]+x]; + mjtNum elongation1 = scale * d->flexvert_xpos[3*v[i]+x]; + mjtNum elongation2 = scale * d->flexvert_xpos[3*v[j]+x]; energy += m->flex_bending[16*e+4*i+j] * elongation1 * elongation2; } } @@ -114,7 +109,7 @@ TEST_F(PluginTest, ElasticEnergyMembrane) { - +