@@ -54,9 +54,7 @@ def test_tlm_assemble():
5454 h = Function (V )
5555 h .vector ()[:] = rand (h .dof_dset .size )
5656 g = f .copy (deepcopy = True )
57- f .block_variable .tlm_value = h
58- tape .evaluate_tlm ()
59- assert (taylor_test (Jhat , g , h , dJdm = J .block_variable .tlm_value ) > 1.9 )
57+ assert (taylor_test (Jhat , g , h , dJdm = Jhat .tlm (h )) > 1.9 )
6058
6159
6260@pytest .mark .skipcomplex
@@ -80,12 +78,7 @@ def test_tlm_bc():
8078 J = assemble (c ** 2 * u * dx )
8179 Jhat = ReducedFunctional (J , Control (c ))
8280
83- # Need to specify the domain for the constant as `ufl.action`, which requires `ufl.Constant`
84- # to have a function space, will be applied on the tlm value.
85- c .block_variable .tlm_value = Function (R , val = 1 )
86- tape .evaluate_tlm ()
87-
88- assert (taylor_test (Jhat , c , Function (R , val = 1 ), dJdm = J .block_variable .tlm_value ) > 1.9 )
81+ assert (taylor_test (Jhat , c , Function (R , val = 1 ), dJdm = Jhat .tlm (Function (R , val = 1 ))) > 1.9 )
8982
9083
9184@pytest .mark .skipcomplex
@@ -113,10 +106,8 @@ def test_tlm_func():
113106 h = Function (V )
114107 h .vector ()[:] = rand (h .dof_dset .size )
115108 g = c .copy (deepcopy = True )
116- c .block_variable .tlm_value = h
117- tape .evaluate_tlm ()
118109
119- assert (taylor_test (Jhat , g , h , dJdm = J . block_variable . tlm_value ) > 1.9 )
110+ assert (taylor_test (Jhat , g , h , dJdm = Jhat . tlm ( h ) ) > 1.9 )
120111
121112
122113@pytest .mark .parametrize ("solve_type" ,
@@ -170,9 +161,7 @@ def test_time_dependent(solve_type):
170161 Jhat = ReducedFunctional (J , control )
171162 h = Function (V )
172163 h .vector ()[:] = rand (h .dof_dset .size )
173- u_1 .tlm_value = h
174- tape .evaluate_tlm ()
175- assert (taylor_test (Jhat , control .tape_value (), h , dJdm = J .block_variable .tlm_value ) > 1.9 )
164+ assert (taylor_test (Jhat , control .tape_value (), h , dJdm = Jhat .tlm (h )) > 1.9 )
176165
177166
178167@pytest .mark .skipcomplex
@@ -224,9 +213,7 @@ def Dt(u, u_, timestep):
224213 h = Function (V )
225214 h .vector ()[:] = rand (h .dof_dset .size )
226215 g = ic .copy (deepcopy = True )
227- ic .block_variable .tlm_value = h
228- tape .evaluate_tlm ()
229- assert (taylor_test (Jhat , g , h , dJdm = J .block_variable .tlm_value ) > 1.9 )
216+ assert (taylor_test (Jhat , g , h , dJdm = Jhat .tlm (h )) > 1.9 )
230217
231218
232219@pytest .mark .skipcomplex
@@ -255,9 +242,7 @@ def test_projection():
255242 J = assemble (u_ ** 2 * dx )
256243 Jhat = ReducedFunctional (J , Control (k ))
257244
258- k .block_variable .tlm_value = Constant (1 )
259- tape .evaluate_tlm ()
260- assert (taylor_test (Jhat , k , Function (R , val = 1 ), dJdm = J .block_variable .tlm_value ) > 1.9 )
245+ assert (taylor_test (Jhat , k , Function (R , val = 1 ), dJdm = Jhat .tlm (Constant (1 ))) > 1.9 )
261246
262247
263248@pytest .mark .skipcomplex
@@ -268,7 +253,6 @@ def test_projection_function():
268253 V = FunctionSpace (mesh , "CG" , 1 )
269254
270255 bc = DirichletBC (V , Constant (1 ), "on_boundary" )
271- # g = Function(V)
272256 x , y = SpatialCoordinate (mesh )
273257 g = project (sin (x )* sin (y ), V , annotate = False )
274258 expr = sin (g * x )
@@ -289,6 +273,4 @@ def test_projection_function():
289273 h = Function (V )
290274 h .vector ()[:] = rand (h .dof_dset .size )
291275 m = g .copy (deepcopy = True )
292- g .block_variable .tlm_value = h
293- tape .evaluate_tlm ()
294- assert (taylor_test (Jhat , m , h , dJdm = J .block_variable .tlm_value ) > 1.9 )
276+ assert (taylor_test (Jhat , m , h , dJdm = Jhat .tlm (h )) > 1.9 )
0 commit comments