Skip to content

Commit 66eb035

Browse files
committed
adding option to store solutions for each iteration and constraints
1 parent dca4e7d commit 66eb035

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

LoopStructural/interpolators/_constant_norm.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(self, interpolator: DiscreteInterpolator,basetype):
3131
self.random_subset = False
3232
self.norm_length = 1.0
3333
self.n_iterations = 20
34+
self.store_solution_history = False
35+
self.solution_history = []#np.zeros((self.n_iterations, self.support.n_nodes))
36+
self.gradient_constraint_store = []
3437
def add_constant_norm(self, w:float):
3538
"""Add a constraint to the interpolator to constrain the norm of the gradient
3639
to be a set value
@@ -60,9 +63,13 @@ def add_constant_norm(self, w:float):
6063
)
6164

6265
v_t = v_t / np.linalg.norm(v_t, axis=1)[:, np.newaxis]
66+
self.gradient_constraint_store.append(np.hstack([self.support.barycentre[element_indices],v_t]))
6367
A1 = np.einsum("ij,ijk->ik", v_t, t_g)
64-
68+
volume = self.support.element_size[element_indices]
69+
A1 = A1 / volume[:, np.newaxis] # normalise by element size
70+
6571
b = np.zeros(A1.shape[0]) + self.norm_length
72+
b = b / volume # normalise by element size
6673
idc = np.hstack(
6774
[
6875
self.support.elements[elements],
@@ -99,6 +106,9 @@ def solve_system(
99106
# Ensure the interpolator is cast to P1Interpolator before calling solve_system
100107
if isinstance(self.interpolator, self.basetype):
101108
success = self.basetype.solve_system(self.interpolator, solver=solver, tol=tol, solver_kwargs=solver_kwargs)
109+
if self.store_solution_history:
110+
111+
self.solution_history.append(self.interpolator.c)
102112
else:
103113
raise TypeError("self.interpolator is not an instance of P1Interpolator")
104114
if not success:

0 commit comments

Comments
 (0)