Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Velocity-Implicit Euler Fixed Step - Second PR of #12528 #12543

Merged
merged 1 commit into from Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 29 additions & 1 deletion systems/analysis/BUILD.bazel
Expand Up @@ -35,6 +35,7 @@ drake_cc_package_library(
":simulator",
":simulator_status",
":stepwise_dense_output",
":velocity_implicit_euler_integrator",
],
)

Expand Down Expand Up @@ -215,6 +216,18 @@ drake_cc_library(
],
)

drake_cc_library(
name = "velocity_implicit_euler_integrator",
srcs = ["velocity_implicit_euler_integrator.cc"],
hdrs = [
"velocity_implicit_euler_integrator.h",
],
deps = [
":implicit_integrator",
"//math:compute_numerical_gradient",
],
)

drake_cc_library(
name = "implicit_integrator",
srcs = ["implicit_integrator.cc"],
Expand Down Expand Up @@ -435,7 +448,10 @@ drake_cc_googletest(
deps = [
":implicit_euler_integrator",
":radau_integrator",
"//systems/analysis/test_utilities",
"//systems/analysis/test_utilities:cubic_scalar_system",
"//systems/analysis/test_utilities:implicit_integrator_test",
"//systems/analysis/test_utilities:linear_scalar_system",
"//systems/analysis/test_utilities:quadratic_scalar_system",
"//systems/plants/spring_mass_system",
],
)
Expand Down Expand Up @@ -508,6 +524,18 @@ drake_cc_googletest(
],
)

drake_cc_googletest(
name = "velocity_implicit_euler_integrator_test",
# Note: if memcheck takes too long with Valgrind, disable
# memcheck (per Drake issue #9621).
timeout = "moderate",
shard_count = 2,
deps = [
":velocity_implicit_euler_integrator",
"//systems/analysis/test_utilities:implicit_integrator_test",
],
)

drake_cc_googletest(
name = "initial_value_problem_test",
timeout = "moderate",
Expand Down
14 changes: 14 additions & 0 deletions systems/analysis/implicit_integrator.h
Expand Up @@ -394,6 +394,20 @@ class ImplicitIntegrator : public IntegratorBase<T> {
/// @copydoc IntegratorBase::DoStep()
virtual bool DoImplicitIntegratorStep(const T& h) = 0;

// Methods for derived classes to increment the factorization and Jacobian
// evaluation counts.
void increment_num_iter_factorizations() {
++num_iter_factorizations_;
}

void increment_jacobian_computation_derivative_evaluations(int count) {
num_jacobian_function_evaluations_ += count;
}

void increment_jacobian_evaluations() {
++num_jacobian_evaluations_;
}

private:
bool DoStep(const T& h) final {
bool result = DoImplicitIntegratorStep(h);
Expand Down
2 changes: 0 additions & 2 deletions systems/analysis/test/radau_integrator_test.cc
Expand Up @@ -9,8 +9,6 @@
#include "drake/systems/analysis/test_utilities/implicit_integrator_test.h"
#include "drake/systems/analysis/test_utilities/linear_scalar_system.h"
#include "drake/systems/analysis/test_utilities/quadratic_scalar_system.h"
#include "drake/systems/analysis/test_utilities/robertson_system.h"
#include "drake/systems/analysis/test_utilities/stationary_system.h"

namespace drake {
namespace systems {
Expand Down
18 changes: 18 additions & 0 deletions systems/analysis/test/velocity_implicit_euler_integrator_test.cc
@@ -0,0 +1,18 @@
#include "drake/systems/analysis/velocity_implicit_euler_integrator.h"

#include <gtest/gtest.h>

#include "drake/systems/analysis/test_utilities/implicit_integrator_test.h"

namespace drake {
namespace systems {
namespace analysis_test {

// Test Velocity-Implicit Euler integrator on common implicit tests.
typedef ::testing::Types<VelocityImplicitEulerIntegrator<double>> MyTypes;
INSTANTIATE_TYPED_TEST_SUITE_P(My, ImplicitIntegratorTest, MyTypes);

} // namespace analysis_test

} // namespace systems
} // namespace drake
5 changes: 5 additions & 0 deletions systems/analysis/test_utilities/BUILD.bazel
Expand Up @@ -94,7 +94,12 @@ drake_cc_library(
testonly = 1,
hdrs = ["implicit_integrator_test.h"],
deps = [
":discontinuous_spring_mass_damper_system",
":linear_scalar_system",
":my_spring_mass_system",
":robertson_system",
":stationary_system",
":stiff_double_mass_spring_system",
"//common/test_utilities:expect_no_throw",
],
)
Expand Down
5 changes: 5 additions & 0 deletions systems/analysis/velocity_implicit_euler_integrator.cc
@@ -0,0 +1,5 @@
#include "drake/systems/analysis/velocity_implicit_euler_integrator.h"

DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS(
class ::drake::systems::VelocityImplicitEulerIntegrator)