Skip to content

Commit

Permalink
fix: adding option to spatially vary fold weight
Browse files Browse the repository at this point in the history
It doesn't give expected results so not recommended
  • Loading branch information
lachlangrose committed Sep 3, 2024
1 parent d15e0ad commit af970a0
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions LoopStructural/interpolators/_discrete_fold_interpolator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Piecewise linear interpolator using folds
"""

from typing import Optional
from typing import Optional, Callable

import numpy as np

Expand Down Expand Up @@ -64,6 +64,7 @@ def add_fold_constraints(
fold_normalisation=1.0,
fold_norm=1.0,
step=2,
mask_fn: Optional[Callable] = None,
):
"""
Expand Down Expand Up @@ -104,6 +105,10 @@ def add_fold_constraints(
# calculate element volume for weighting
vecs = nodes[:, 1:, :] - nodes[:, 0, None, :]
vol = np.abs(np.linalg.det(vecs)) / 6
weight = np.ones(self.support.n_elements, dtype=float)
if mask_fn is not None:
weight[mask_fn(self.support.barycentre)] = 0
weight = weight[::step]
if fold_orientation is not None:
"""
dot product between vector in deformed ori plane = 0
Expand All @@ -120,7 +125,7 @@ def add_fold_constraints(
B = np.zeros(A.shape[0])
idc = self.support.get_elements()[element_idx[::step], :]
self.add_constraints_to_least_squares(
A, B, idc, w=fold_orientation, name="fold orientation"
A, B, idc, w=weight * fold_orientation, name="fold orientation"
)

if fold_axis_w is not None:
Expand All @@ -139,7 +144,9 @@ def add_fold_constraints(
B = np.zeros(A.shape[0]).tolist()
idc = self.support.get_elements()[element_idx[::step], :]

self.add_constraints_to_least_squares(A, B, idc, w=fold_axis_w, name="fold axis")
self.add_constraints_to_least_squares(
A, B, idc, w=weight * fold_axis_w, name="fold axis"
)

if fold_normalisation is not None:
"""
Expand All @@ -160,7 +167,7 @@ def add_fold_constraints(
idc = self.support.get_elements()[element_idx[::step], :]

self.add_constraints_to_least_squares(
A, B, idc, w=fold_normalisation, name="fold normalisation"
A, B, idc, w=weight * fold_normalisation, name="fold normalisation"
)

if fold_regularisation is not None:
Expand Down

0 comments on commit af970a0

Please sign in to comment.