Skip to content

Commit fd05085

Browse files
committed
Fix bug in computation of stiffness matrix
We need to scale the stiffness matrix with the (original) length of the segment as it represents an infitesimal quantity
1 parent 375d5f7 commit fd05085

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

examples/simulate_planar_pcs.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,20 @@
2626

2727
# set parameters
2828
rho = 1070 * jnp.ones((num_segments,)) # Volumetric density of Dragon Skin 20 [kg/m^3]
29-
D = 1e-4 * jnp.diag(
30-
jnp.repeat(
31-
jnp.array([[1e0, 1e3, 1e3]]), num_segments, axis=0
32-
).flatten(),
33-
)
3429
params = {
3530
"th0": jnp.array(0.0), # initial orientation angle [rad]
3631
"l": 1e-1 * jnp.ones((num_segments,)),
3732
"r": 2e-2 * jnp.ones((num_segments,)),
3833
"rho": rho,
3934
"g": jnp.array([0.0, 9.81]),
40-
"E": 2e2 * jnp.ones((num_segments,)), # Elastic modulus [Pa]
41-
"G": 1e2 * jnp.ones((num_segments,)), # Shear modulus [Pa]
42-
"D": D,
35+
"E": 2e3 * jnp.ones((num_segments,)), # Elastic modulus [Pa]
36+
"G": 1e3 * jnp.ones((num_segments,)), # Shear modulus [Pa]
4337
}
38+
params["D"] = 1e-3 * jnp.diag(
39+
jnp.repeat(
40+
jnp.array([[1e0, 1e3, 1e3]]), num_segments, axis=0
41+
).flatten(),
42+
) * params["l"]
4443

4544
# activate all strains (i.e. bending, shear, and axial)
4645
strain_selector = jnp.ones((3 * num_segments,), dtype=bool)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ name = "jsrm" # Required
1717
#
1818
# For a discussion on single-sourcing the version, see
1919
# https://packaging.python.org/guides/single-sourcing-package-version/
20-
version = "0.0.11" # Required
20+
version = "0.0.12" # Required
2121

2222
# This is a one-line description or tagline of what your project does. This
2323
# corresponds to the "Summary" metadata field:

src/jsrm/symbolic_derivation/planar_pcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def symbolically_derive_planar_pcs_model(
7979
kappa = xi[3 * i]
8080
# shear strain
8181
sigma_x = xi[3 * i + 1]
82-
# elongation strain
82+
# axial strain
8383
sigma_y = xi[3 * i + 2]
8484

8585
# compute the cross-sectional area of the rod

src/jsrm/systems/planar_pcs.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def select_params_for_lambdify_fn(params: Dict[str, Array]) -> List[Array]:
141141
)
142142

143143
compute_stiffness_matrix_for_all_segments_fn = vmap(
144-
compute_planar_stiffness_matrix, in_axes=(0, 0, 0, 0), out_axes=0
144+
compute_planar_stiffness_matrix
145145
)
146146

147147
@jit
@@ -214,14 +214,16 @@ def stiffness_fn(
214214
Returns:
215215
K: elastic matrix of shape (n_q, n_q) if formulate_in_strain_space is False or (n_xi, n_xi) otherwise
216216
"""
217+
# length of the segments
218+
l = params["l"]
217219
# cross-sectional area and second moment of area
218220
A = jnp.pi * params["r"] ** 2
219221
Ib = A**2 / (4 * jnp.pi)
220222

221223
# elastic and shear modulus
222224
E, G = params["E"], params["G"]
223225
# stiffness matrix of shape (num_segments, 3, 3)
224-
S = compute_stiffness_matrix_for_all_segments_fn(A, Ib, E, G)
226+
S = compute_stiffness_matrix_for_all_segments_fn(l, A, Ib, E, G)
225227
# we define the elastic matrix of shape (n_xi, n_xi) as K(xi) = K @ xi where K is equal to
226228
K = blk_diag(S)
227229

src/jsrm/systems/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ def compute_strain_basis(
108108

109109

110110
@jit
111-
def compute_planar_stiffness_matrix(A: Array, Ib: Array, E: Array, G: Array) -> Array:
111+
def compute_planar_stiffness_matrix(l: Array, A: Array, Ib: Array, E: Array, G: Array) -> Array:
112112
"""
113113
Compute the stiffness matrix of the system.
114114
Args:
115+
l: length of the segment of shape ()
115116
A: cross-sectional area of shape ()
116117
Ib: second moment of area of shape ()
117118
E: Elastic modulus of shape ()
@@ -120,6 +121,6 @@ def compute_planar_stiffness_matrix(A: Array, Ib: Array, E: Array, G: Array) ->
120121
Returns:
121122
S: stiffness matrix of shape (3, 3)
122123
"""
123-
S = jnp.diag(jnp.stack([Ib * E, 4 / 3 * A * G, A * E], axis=0))
124+
S = l* jnp.diag(jnp.stack([Ib * E, 4 / 3 * A * G, A * E], axis=0))
124125

125126
return S

tests/test_planar_pcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ def test_planar_pcs_one_segment():
2121
"r": jnp.array([2e-2]),
2222
"rho": 1000 * jnp.ones((1,)),
2323
"g": jnp.array([0.0, -9.81]),
24-
"E": 1e7 * jnp.ones((1,)), # Elastic modulus [Pa]
25-
"G": 1e6 * jnp.ones((1,)), # Shear modulus [Pa]
24+
"E": 1e8 * jnp.ones((1,)), # Elastic modulus [Pa]
25+
"G": 1e7 * jnp.ones((1,)), # Shear modulus [Pa]
2626
}
2727
# activate all strains (i.e. bending, shear, and axial)
2828
strain_selector = jnp.ones((3,), dtype=bool)

0 commit comments

Comments
 (0)