@@ -31,6 +31,9 @@ def __init__(self, interpolator: DiscreteInterpolator,basetype):
31
31
self .random_subset = False
32
32
self .norm_length = 1.0
33
33
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 = []
34
37
def add_constant_norm (self , w :float ):
35
38
"""Add a constraint to the interpolator to constrain the norm of the gradient
36
39
to be a set value
@@ -60,9 +63,13 @@ def add_constant_norm(self, w:float):
60
63
)
61
64
62
65
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 ]))
63
67
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
+
65
71
b = np .zeros (A1 .shape [0 ]) + self .norm_length
72
+ b = b / volume # normalise by element size
66
73
idc = np .hstack (
67
74
[
68
75
self .support .elements [elements ],
@@ -99,6 +106,9 @@ def solve_system(
99
106
# Ensure the interpolator is cast to P1Interpolator before calling solve_system
100
107
if isinstance (self .interpolator , self .basetype ):
101
108
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 )
102
112
else :
103
113
raise TypeError ("self.interpolator is not an instance of P1Interpolator" )
104
114
if not success :
0 commit comments