Precount number of non-zeros for constraint Jacobian sparse matrix.

PiperOrigin-RevId: 512947632
Change-Id: I9605e81b4e51fbc90854c13153e4fee38ad48fb9
This commit is contained in:
Kyle Bayes
2023-02-28 08:57:01 -08:00
committed by Copybara-Service
parent 90b5dd14ca
commit 50bebcb4ee
15 changed files with 521 additions and 165 deletions
+38 -1
View File
@@ -27,8 +27,8 @@
namespace mujoco {
namespace {
using ::testing::Pointwise;
using ::testing::DoubleNear;
using ::testing::Pointwise;
using CoreConstraintTest = MujocoTest;
std::vector<mjtNum> AsVector(const mjtNum* array, int n) {
@@ -158,5 +158,42 @@ TEST_F(CoreConstraintTest, WeldRotJacobian) {
mj_deleteModel(model);
}
static const char* const kDoflessContactPath =
"engine/testdata/core_constraint/dofless_contact.xml";
static const char* const kDoflessTendonFrictionalPath =
"engine/testdata/core_constraint/dofless_tendon_frictional.xml";
static const char* const kDoflessTendonLimitedPath =
"engine/testdata/core_constraint/dofless_tendon_limited.xml";
static const char* const kDoflessTendonLimitedMarginPath =
"engine/testdata/core_constraint/dofless_tendon_limitedmargin.xml";
static const char* const kDoflessWeldPath =
"engine/testdata/core_constraint/dofless_weld.xml";
static const char* const kJointLimitedBilateralMarginPath =
"engine/testdata/core_constraint/joint_limited_bilateral_margin.xml";
static const char* const kTendonLimitedBilateralMarginPath =
"engine/testdata/core_constraint/tendon_limited_bilateral_margin.xml";
TEST_F(CoreConstraintTest, JacobianPreAllocate) {
for (const char* local_path :
{kDoflessContactPath, kDoflessTendonFrictionalPath,
kDoflessTendonLimitedPath, kDoflessTendonLimitedMarginPath,
kDoflessWeldPath, kJointLimitedBilateralMarginPath,
kTendonLimitedBilateralMarginPath}) {
const std::string xml_path = GetTestDataFilePath(local_path);
// iterate through dense and sparse
for (mjtJacobian sparsity : {mjJAC_DENSE, mjJAC_SPARSE}) {
mjModel* model = mj_loadXML(xml_path.c_str(), nullptr, nullptr, 0);
model->opt.jacobian = sparsity;
mjData* data = mj_makeData(model);
mj_step(model, data);
mj_deleteData(data);
mj_deleteModel(model);
}
}
}
} // namespace
} // namespace mujoco
@@ -0,0 +1,18 @@
<mujoco>
<default>
<geom rgba=".5 .5 .5 .5"/>
</default>
<worldbody>
<body>
<geom name="1" size="1"/>
</body>
<body>
<geom name="2" size="1" pos="1.5 0 0"/>
</body>
</worldbody>
<contact>
<pair geom1="1" geom2="2"/>
</contact>
</mujoco>
@@ -0,0 +1,13 @@
<mujoco>
<worldbody>
<site name="1"/>
<site name="2" pos="1 0 0"/>
</worldbody>
<tendon>
<spatial frictionloss="1">
<site site="1"/>
<site site="2"/>
</spatial>
</tendon>
</mujoco>
@@ -0,0 +1,13 @@
<mujoco>
<worldbody>
<site name="1"/>
<site name="2" pos="1 0 0"/>
</worldbody>
<tendon>
<spatial limited="true" range="0 0.5">
<site site="1"/>
<site site="2"/>
</spatial>
</tendon>
</mujoco>
@@ -0,0 +1,13 @@
<mujoco>
<worldbody>
<site name="1"/>
<site name="2" pos="1 0 0"/>
</worldbody>
<tendon>
<spatial limited="true" range="0.99 1.01" margin="0.1">
<site site="1"/>
<site site="2"/>
</spatial>
</tendon>
</mujoco>
+24
View File
@@ -0,0 +1,24 @@
<mujoco>
<worldbody>
<body name="1" >
<freejoint />
<geom size="1" pos="7 0 0"/>
</body>
<body name="2" >
<freejoint />
<geom size="1" pos="8.5 0 0"/>
</body>
<body name="3" >
<geom size="1"/>
</body>
<body name="4" >
<geom size="1" pos="1.5 0 0"/>
</body>
</worldbody>
<equality>
<weld body1="1" body2="2"/>
<weld body1="3" body2="4"/>
</equality>
</mujoco>
@@ -0,0 +1,8 @@
<mujoco>
<worldbody>
<body>
<joint axis="1 0 0" range="0 0.1" limited="true" margin="0.2"/>
<geom size="1"/>
</body>
</worldbody>
</mujoco>
@@ -0,0 +1,17 @@
<mujoco>
<worldbody>
<site name="1"/>
<body pos="1 0 0">
<site name="2"/>
<freejoint/>
<geom size=".01"/>
</body>
</worldbody>
<tendon>
<spatial limited="true" range="0.99 1.01" margin="0.1">
<site site="1"/>
<site site="2"/>
</spatial>
</tendon>
</mujoco>