-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fem] Allow velocity to be the unknown variable in NewmarkScheme (#15593
) * Update NewmarkScheme so that it only stores the parameters and delegates the DoFoo() methods to concrete derived classes. * Add AccelerationNewmarkScheme which implements the original NewmarkScheme with `a` as the unknown variable. * Add VelocityNewmarkScheme that implements the NewmarkScheme with `v` as the unknown variable. * Restrict `gamma` to be greater than or equal to 0.5. The scheme is unstable otherwise.
- Loading branch information
1 parent
5c7f033
commit 1df1c47
Showing
11 changed files
with
489 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "drake/multibody/fixed_fem/dev/acceleration_newmark_scheme.h" | ||
|
||
namespace drake { | ||
namespace multibody { | ||
namespace fem { | ||
namespace internal { | ||
|
||
template <typename T> | ||
void AccelerationNewmarkScheme<T>::DoUpdateStateFromChangeInUnknowns( | ||
const VectorX<T>& dz, FemStateBase<T>* state) const { | ||
const VectorX<T>& a = state->qddot(); | ||
const VectorX<T>& v = state->qdot(); | ||
const VectorX<T>& x = state->q(); | ||
state->SetQddot(a + dz); | ||
state->SetQdot(v + dt() * gamma() * dz); | ||
state->SetQ(x + dt() * dt() * beta() * dz); | ||
} | ||
|
||
template <typename T> | ||
void AccelerationNewmarkScheme<T>::DoAdvanceOneTimeStep( | ||
const FemStateBase<T>& prev_state, const VectorX<T>& unknown_variable, | ||
FemStateBase<T>* state) const { | ||
const VectorX<T>& an = prev_state.qddot(); | ||
const VectorX<T>& vn = prev_state.qdot(); | ||
const VectorX<T>& xn = prev_state.q(); | ||
const VectorX<T>& a = unknown_variable; | ||
state->SetQddot(a); | ||
state->SetQdot(vn + dt() * (gamma() * a + (1.0 - gamma()) * an)); | ||
state->SetQ(xn + dt() * vn + | ||
dt() * dt() * (beta() * a + (0.5 - beta()) * an)); | ||
} | ||
|
||
} // namespace internal | ||
} // namespace fem | ||
} // namespace multibody | ||
} // namespace drake | ||
|
||
DRAKE_DEFINE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS( | ||
class ::drake::multibody::fem::internal::AccelerationNewmarkScheme) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#pragma once | ||
|
||
#include "drake/common/default_scalars.h" | ||
#include "drake/multibody/fixed_fem/dev/newmark_scheme.h" | ||
|
||
namespace drake { | ||
namespace multibody { | ||
namespace fem { | ||
namespace internal { | ||
|
||
/* Implements NewmarkScheme with acceleration as the unknown variable. | ||
Given the value for the current time step acceleration `a`, the current state | ||
can be calculated from the state from the previous time step according to the | ||
following equations: | ||
v = vₙ + dt ⋅ (γ ⋅ a + (1−γ) ⋅ aₙ) | ||
x = xₙ + dt ⋅ vₙ + dt² ⋅ [β ⋅ a + (0.5−β) ⋅ aₙ]. | ||
See NewmarkScheme for the reference to the Newmark-beta integration scheme. | ||
See VelocityNewmarkScheme for the same integration scheme implemented with | ||
velocity as the unknown variable. | ||
@tparam_nonsymbolic_scalar */ | ||
template <typename T> | ||
class AccelerationNewmarkScheme final : public NewmarkScheme<T> { | ||
public: | ||
DRAKE_NO_COPY_NO_MOVE_NO_ASSIGN(AccelerationNewmarkScheme); | ||
|
||
/* Constructs a Newmark scheme with acceleration as the unknown variable. | ||
@pre dt_in > 0. | ||
@pre 0.5 <= gamma_in <= 1. | ||
@pre 0 <= beta_in <= 0.5. */ | ||
AccelerationNewmarkScheme(double dt_in, double gamma_in, double beta_in) | ||
: NewmarkScheme<T>(dt_in, gamma_in, beta_in) {} | ||
|
||
~AccelerationNewmarkScheme() = default; | ||
|
||
private: | ||
using NewmarkScheme<T>::dt; | ||
using NewmarkScheme<T>::gamma; | ||
using NewmarkScheme<T>::beta; | ||
|
||
Vector3<T> do_get_weights() const final { | ||
return {beta() * dt() * dt(), gamma() * dt(), 1.0}; | ||
} | ||
|
||
const VectorX<T>& DoGetUnknowns(const FemStateBase<T>& state) const final { | ||
return state.qddot(); | ||
} | ||
|
||
void DoUpdateStateFromChangeInUnknowns(const VectorX<T>& dz, | ||
FemStateBase<T>* state) const final; | ||
|
||
void DoAdvanceOneTimeStep(const FemStateBase<T>& prev_state, | ||
const VectorX<T>& unknown_variable, | ||
FemStateBase<T>* state) const final; | ||
}; | ||
|
||
} // namespace internal | ||
} // namespace fem | ||
} // namespace multibody | ||
} // namespace drake | ||
|
||
DRAKE_DECLARE_CLASS_TEMPLATE_INSTANTIATIONS_ON_DEFAULT_NONSYMBOLIC_SCALARS( | ||
class ::drake::multibody::fem::internal::AccelerationNewmarkScheme) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.