diff --git a/doc/XMLreference.rst b/doc/XMLreference.rst index 6c0ffcf2..2316ddf3 100644 --- a/doc/XMLreference.rst +++ b/doc/XMLreference.rst @@ -3746,6 +3746,23 @@ element is used to adjust the properties of all edges in the flex. Edge stiffness and damping, passed through to the automatically generated flex. +.. _flexcomp-elasticity: + +:el-prefix:`flexcomp/` |-| **elasticity** (*) +''''''''''''''''''''''''''''''''''''''''''''' + +.. _flexcomp-elasticity-young: +.. _flexcomp-elasticity-poisson: +.. _flexcomp-elasticity-damping: +.. _flexcomp-elasticity-thickness: + +.. |body/flexcomp/elasticity attrib list| replace:: + :at:`young`, :at:`poisson`, :at:`damping`, :at:`thickness` + +|body/flexcomp/elasticity attrib list| + Same as in :ref:`flex/elasticity`. + All attributes are passed through to the automatically-generated flex. + .. _flexcomp-pin: :el-prefix:`flexcomp/` |-| **pin** (*) @@ -4131,6 +4148,39 @@ these mechanisms to be combined as desired. :at:`damping`: :at-val:`real(1), "0"` Damping of all edges. + +.. _flex-elasticity: + +:el-prefix:`flex/` |-| **elasticity** (?) +''''''''''''''''''''''''''''''''''''''''' + +.. _flex-elasticity-young: + +:at:`young`: :at-val:`real(1), "0"` + Young's elastic modulus, a measure of tensile and compressive stiffness for continuum elastic materials. + Units of :math:`\textrm{pressure}=\textrm{force}/\textrm{area}`. + +.. _flex-elasticity-poisson: + +:at:`poisson`: :at-val:`real(1), "0"` + Poisson's ratio, the ratio of transverse deformation to applied longitudinal strain. + This unitless quantity is in the range :math:`[0, 0.5)`. + Small or large values imply compressibility or incompressiblity, respectively. + +.. _flex-elasticity-damping: + +:at:`damping`: :at-val:`real(1), "0"` + Rayleigh's damping coefficient, units of time. + This quantity scales the stiffness defined by Young's modulus to produce the damping matrix. + +.. _flex-elasticity-thickness: + +:at:`thickness`: :at-val:`real(1), "-1"` + Shell thickness, units of length; only for used 2D flexes. Used to scale the stretching stiffness. + This thickness can be set equal to 2 times the :ref:`radius ` in order to match the geometry, + but is exposed seperately since the radius might be constrained by considerations related to collision detection. + + .. _flex-contact: :el-prefix:`flex/` |-| **contact** (?) diff --git a/doc/XMLschema.rst b/doc/XMLschema.rst index 80b54614..d12ab310 100644 --- a/doc/XMLschema.rst +++ b/doc/XMLschema.rst @@ -514,6 +514,13 @@ | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_2| flexcomp |br| |_2| |L| | | .. table:: | +| :ref:`elasticity | ? | :class: mjcf-attributes | +| ` | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +| | | | :ref:`young` | :ref:`poisson` | :ref:`damping` | :ref:`thickness` | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | ++------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| |_2| flexcomp |br| |_2| |L| | | .. table:: | | :ref:`contact | ? | :class: mjcf-attributes | | ` | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | @@ -581,6 +588,13 @@ | | | | :ref:`stiffness` | :ref:`damping` | | | | | | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| |_2| flex |br| |_2| |L| | | .. table:: | +| :ref:`elasticity | ? | :class: mjcf-attributes | +| ` | | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | +| | | | :ref:`young` | :ref:`poisson` | :ref:`damping` | :ref:`thickness` | | +| | | +-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+-----------------------------------------------------------------+ | ++------------------------------------+----+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | |_| deformable |br| |_| |L| | | .. table:: | | :ref:`skin | \* | :class: mjcf-attributes | | ` | | | diff --git a/doc/includes/references.h b/doc/includes/references.h index 840faa3e..9f4bbef2 100644 --- a/doc/includes/references.h +++ b/doc/includes/references.h @@ -1961,6 +1961,10 @@ typedef struct mjsFlex_ { // flex specification double edgedamping; // edge damping float rgba[4]; // rgba when material is omitted mjString* material; // name of material used for rendering + double young; // Young's modulus + double poisson; // Poisson's ratio + double damping; // Rayleigh's damping + double thickness; // thickness (2D only) // mesh properties mjStringVec* vertbody; // vertex body names diff --git a/include/mujoco/mjspec.h b/include/mujoco/mjspec.h index 24b8c546..90bc6c9a 100644 --- a/include/mujoco/mjspec.h +++ b/include/mujoco/mjspec.h @@ -424,6 +424,10 @@ typedef struct mjsFlex_ { // flex specification double edgedamping; // edge damping float rgba[4]; // rgba when material is omitted mjString* material; // name of material used for rendering + double young; // Young's modulus + double poisson; // Poisson's ratio + double damping; // Rayleigh's damping + double thickness; // thickness (2D only) // mesh properties mjStringVec* vertbody; // vertex body names diff --git a/introspect/structs.py b/introspect/structs.py index d5216fd1..391725aa 100644 --- a/introspect/structs.py +++ b/introspect/structs.py @@ -9631,6 +9631,26 @@ STRUCTS: Mapping[str, StructDecl] = dict([ ), doc='name of material used for rendering', ), + StructFieldDecl( + name='young', + type=ValueType(name='double'), + doc="Young's modulus", + ), + StructFieldDecl( + name='poisson', + type=ValueType(name='double'), + doc="Poisson's ratio", + ), + StructFieldDecl( + name='damping', + type=ValueType(name='double'), + doc="Rayleigh's damping", + ), + StructFieldDecl( + name='thickness', + type=ValueType(name='double'), + doc='thickness (2D only)', + ), StructFieldDecl( name='vertbody', type=PointerType( diff --git a/model/plugin/elasticity/floppy_flex.xml b/model/plugin/elasticity/floppy_flex.xml index 8609e3fa..d2fc57f9 100644 --- a/model/plugin/elasticity/floppy_flex.xml +++ b/model/plugin/elasticity/floppy_flex.xml @@ -34,12 +34,8 @@ - - - - - - + + diff --git a/model/plugin/elasticity/jelly_flex.xml b/model/plugin/elasticity/jelly_flex.xml index 9a0af65d..056c14f2 100644 --- a/model/plugin/elasticity/jelly_flex.xml +++ b/model/plugin/elasticity/jelly_flex.xml @@ -46,11 +46,8 @@ radius=".005" rgba="0 .7 .7 1" mass="5" name="softbody"> - - - - - + + diff --git a/model/plugin/elasticity/press_flex.xml b/model/plugin/elasticity/press_flex.xml index c2545652..55ca510d 100644 --- a/model/plugin/elasticity/press_flex.xml +++ b/model/plugin/elasticity/press_flex.xml @@ -35,22 +35,16 @@ radius=".005" rgba="0 .7 .7 1" dim="3" mass="5"> - - - - - + + - - - - - + + diff --git a/model/plugin/elasticity/trampoline_flex.xml b/model/plugin/elasticity/trampoline_flex.xml index 106e37cc..7362327c 100644 --- a/model/plugin/elasticity/trampoline_flex.xml +++ b/model/plugin/elasticity/trampoline_flex.xml @@ -44,13 +44,9 @@ radius=".001" mass="10" name="plate" dim="2"> + - - - - - - + diff --git a/plugin/elasticity/README.md b/plugin/elasticity/README.md index 96bb5283..5158a536 100644 --- a/plugin/elasticity/README.md +++ b/plugin/elasticity/README.md @@ -37,11 +37,7 @@ Implemented in [membrane.cc](membrane.cc). The membrane plugin discretized an extensible 2D continuum. It is intended to simulate the stretching of membranes subjected to tensile stresses, where the bending is negligible. -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 stretching stiffness. +Parameters: see [flex parameters](mujoco.readthedocs.io/en/latest/XMLreference.html#flexcomp-elasticity) in the XML Reference docs. ### Solid @@ -49,8 +45,5 @@ Implemented in [solid.cc](solid.cc). The membrane plugin discretized an extensible 3D continuum. It is Saint Venant–Kirchhoff model intended to simulate the compression or elongation of hyperelastic materials subjected to large displacements (finite rotations) and small strains, since it uses a nonlinear strain-displacement but a linear stress-strain relationship. -Parameters: +Parameters: see [flex parameters](mujoco.readthedocs.io/en/latest/XMLreference.html#flexcomp-elasticity) in the XML Reference docs. - - `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). - - `damping` [Ns/m^2]: damping coefficient for Rayleigh damping. diff --git a/plugin/elasticity/shell.cc b/plugin/elasticity/shell.cc index cf272a04..30b02051 100644 --- a/plugin/elasticity/shell.cc +++ b/plugin/elasticity/shell.cc @@ -242,7 +242,7 @@ void Shell::RegisterPlugin() { plugin.capabilityflags |= mjPLUGIN_PASSIVE; const char* attributes[] = {"face", "edge", "young", - "poisson", "thickness"}; + "poisson", "thickness", "damping"}; plugin.nattribute = sizeof(attributes) / sizeof(attributes[0]); plugin.attributes = attributes; plugin.nstate = +[](const mjModel* m, int instance) { return 0; }; diff --git a/plugin/elasticity/solid.cc b/plugin/elasticity/solid.cc index 537ab714..de598f70 100644 --- a/plugin/elasticity/solid.cc +++ b/plugin/elasticity/solid.cc @@ -222,7 +222,7 @@ void Solid::RegisterPlugin() { plugin.name = "mujoco.elasticity.solid"; plugin.capabilityflags |= mjPLUGIN_PASSIVE; - const char* attributes[] = {"face", "edge", "young", "poisson", "damping"}; + const char* attributes[] = {"face", "edge", "young", "poisson", "damping", "thickness"}; plugin.nattribute = sizeof(attributes) / sizeof(attributes[0]); plugin.attributes = attributes; plugin.nstate = +[](const mjModel* m, int instance) { return 0; }; diff --git a/src/user/user_init.c b/src/user/user_init.c index e7028b75..4ae5de6c 100644 --- a/src/user/user_init.c +++ b/src/user/user_init.c @@ -236,6 +236,7 @@ void mjs_defaultFlex(mjsFlex* flex) { flex->activelayers = 1; flex->rgba[0] = flex->rgba[1] = flex->rgba[2] = 0.5f; flex->rgba[3] = 1.0f; + flex->thickness = -1; } diff --git a/src/user/user_mesh.cc b/src/user/user_mesh.cc index 28869b69..f69a7497 100644 --- a/src/user/user_mesh.cc +++ b/src/user/user_mesh.cc @@ -2675,6 +2675,18 @@ void mjCFlex::Compile(const mjVFS* vfs) { if (model->Bodies()[vbodyid]->plugin.instance) { mjCPlugin* plugin_instance = static_cast(model->Bodies()[vbodyid]->plugin.instance); + if (young > 0) { + plugin_instance->config_attribs["young"] = std::to_string(young); + } + if (poisson > 0) { + plugin_instance->config_attribs["poisson"] = std::to_string(poisson); + } + if (thickness > 0) { + plugin_instance->config_attribs["thickness"] = std::to_string(thickness); + } + if (damping > 0) { + plugin_instance->config_attribs["damping"] = std::to_string(damping); + } plugin_instance->config_attribs["face"] = userface; plugin_instance->config_attribs["edge"] = useredge; } diff --git a/src/xml/xml_native_reader.cc b/src/xml/xml_native_reader.cc index d3544d2d..bad6fa41 100644 --- a/src/xml/xml_native_reader.cc +++ b/src/xml/xml_native_reader.cc @@ -326,6 +326,7 @@ const char* MJCF[nMJCF][mjXATTRNUM] = { "flatskin", "pos", "quat", "axisangle", "xyaxes", "zaxis", "euler"}, {"<"}, {"edge", "?", "5", "equality", "solref", "solimp", "stiffness", "damping"}, + {"elasticity", "?", "4", "young", "poisson", "damping", "thickness"}, {"contact", "?", "13", "contype", "conaffinity", "condim", "priority", "friction", "solmix", "solref", "solimp", "margin", "gap", "internal", "selfcollide", "activelayers"}, @@ -346,6 +347,7 @@ const char* MJCF[nMJCF][mjXATTRNUM] = { "friction", "solmix", "solref", "solimp", "margin", "gap", "internal", "selfcollide", "activelayers"}, {"edge", "?", "2", "stiffness", "damping"}, + {"elasticity", "?", "4", "young", "poisson", "damping", "thickness"}, {">"}, {"skin", "*", "9", "name", "file", "material", "rgba", "inflate", "vertex", "texcoord", "face", "group"}, @@ -1388,6 +1390,15 @@ void mjXReader::OneFlex(XMLElement* elem, mjsFlex* flex) { ReadAttr(edge, "damping", 1, &flex->edgedamping, text); } + // elasticity subelement + XMLElement* elasticity = FirstChildElement(elem, "elasticity"); + if (elasticity) { + ReadAttr(elasticity, "young", 1, &flex->young, text); + ReadAttr(elasticity, "poisson", 1, &flex->poisson, text); + ReadAttr(elasticity, "thickness", 1, &flex->thickness, text); + ReadAttr(elasticity, "damping", 1, &flex->damping, text); + } + // write error info mjs_setString(flex->info, ("line " + std::to_string(elem->GetLineNum())).c_str()); } @@ -2674,6 +2685,15 @@ void mjXReader::OneFlexcomp(XMLElement* elem, mjsBody* body, const mjVFS* vfs) { ReadAttr(edge, "damping", 1, &dflex.edgedamping, text); } + // elasticity + XMLElement* elasticity = FirstChildElement(elem, "elasticity"); + if (elasticity) { + ReadAttr(elasticity, "young", 1, &dflex.young, text); + ReadAttr(elasticity, "poisson", 1, &dflex.poisson, text); + ReadAttr(elasticity, "damping", 1, &dflex.damping, text); + ReadAttr(elasticity, "thickness", 1, &dflex.thickness, text); + } + // contact XMLElement* cont = FirstChildElement(elem, "contact"); if (cont) { diff --git a/src/xml/xml_native_reader.h b/src/xml/xml_native_reader.h index cfa87961..c9f456bf 100644 --- a/src/xml/xml_native_reader.h +++ b/src/xml/xml_native_reader.h @@ -101,7 +101,7 @@ class mjXReader : public mjXBase { }; // MJCF schema -#define nMJCF 243 +#define nMJCF 245 extern const char* MJCF[nMJCF][mjXATTRNUM]; #endif // MUJOCO_SRC_XML_XML_NATIVE_READER_H_ diff --git a/test/plugin/elasticity/elasticity_test.cc b/test/plugin/elasticity/elasticity_test.cc index bc87203a..d902dc65 100644 --- a/test/plugin/elasticity/elasticity_test.cc +++ b/test/plugin/elasticity/elasticity_test.cc @@ -44,10 +44,8 @@ TEST_F(ElasticityTest, FlexCompatibility) { - - - - + + @@ -128,11 +126,8 @@ TEST_F(PluginTest, ElasticEnergyMembrane) { - - - - - + + @@ -214,10 +209,8 @@ TEST_F(ElasticityTest, ElasticEnergySolid) { - - - - + +