Skip to content

Commit f37fdb0

Browse files
committed
Merge branch 'variationalProblems' of github.com:lauraweigl/ManoptExamples.jl into variationalProblems
2 parents dbebe12 + 4681289 commit f37fdb0

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

test/test_variational_block_assembler.jl

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ using LinearAlgebra, SparseArrays, OffsetArrays, RecursiveArrayTools
117117
y_0 = copy(product, disc_point)
118118

119119
@testset "Test Variational Block Assembler (Inextensible rod) runs" begin # testset for result of the whole Newton iteration
120-
120+
121121
function (ne::NewtonEq)(M, VB, p)
122122
n1 = Int(manifold_dimension(submanifold(M, 1)))
123123
n2 = Int(manifold_dimension(submanifold(M, 2)))
@@ -157,26 +157,26 @@ using LinearAlgebra, SparseArrays, OffsetArrays, RecursiveArrayTools
157157

158158

159159
ne.A .= vcat(
160-
hcat(spzeros(n1, n1), spzeros(n1, n2), ne.A13),
161-
hcat(spzeros(n2, n1), ne.A22, ne.A32'),
162-
hcat(ne.A13', ne.A32, spzeros(n3, n3))
163-
)
160+
hcat(spzeros(n1, n1), spzeros(n1, n2), ne.A13),
161+
hcat(spzeros(n2, n1), ne.A22, ne.A32'),
162+
hcat(ne.A13', ne.A32, spzeros(n3, n3))
163+
)
164164
ne.b .= vcat(ne.b1, ne.b2, ne.b3)
165-
165+
166166
return
167167
end
168168

169169
NE = NewtonEq(product, integrand_yλ, integrand_vv, integrand_λv, test_spaces, ansatz_spaces, transport, discrete_time_interval)
170170

171171
st_res = vectorbundle_newton(
172-
product, TangentBundle(product), NE, y_0; sub_problem = solve_in_basis_repr, sub_state = AllocatingEvaluation(),
173-
stopping_criterion = (StopAfterIteration(15) | StopWhenChangeLess(product, 1.0e-12; outer_norm = Inf)),
174-
retraction_method = ProductRetraction(ExponentialRetraction(), ProjectionRetraction(), ExponentialRetraction()),
175-
return_state = true
176-
)
172+
product, TangentBundle(product), NE, y_0; sub_problem = solve_in_basis_repr, sub_state = AllocatingEvaluation(),
173+
stopping_criterion = (StopAfterIteration(15) | StopWhenChangeLess(product, 1.0e-12; outer_norm = Inf)),
174+
retraction_method = ProductRetraction(ExponentialRetraction(), ProjectionRetraction(), ExponentialRetraction()),
175+
return_state = true
176+
)
177177
res = get_solver_result(st_res)
178178

179-
@test norm(res[product, 1] - [[0.17939616371786352, 3.8563733738218966e-42, 0.09246128699172507], [0.3797679482303294, 0.0, -0.02544490371304304], [0.5795183336410239, 2.8698592549372254e-42, -0.10104793173942489]]) + norm(res[product, 1]) norm(res[product, 1])
179+
@test norm(res[product, 1] - [[0.17939616371786352, 3.8563733738218966e-42, 0.09246128699172507], [0.3797679482303294, 0.0, -0.02544490371304304], [0.5795183336410239, 2.8698592549372254e-42, -0.10104793173942489]]) + norm(res[product, 1]) norm(res[product, 1])
180180
@test norm(res[product, 2] - [[0.9879557142429503, 3.0850986990575173e-41, -0.15473689506611538], [0.615018561856777, -4.591774807899561e-41, -0.7885126305720296], [0.982984521428779, -2.2958874039497803e-41, 0.18368840636097478]]) + norm(res[product, 2]) norm(res[product, 2])
181181
@test norm(res[product, 3] - [[-32.46424394115326, -8.609577764811676e-41, 0.7280993274418598], [-32.46424394115326, -8.609577764811676e-41, 0.7280993274418598], [-32.46424394115326, -8.609577764811676e-41, 0.7280993274418598], [-32.46424394115326, -8.609577764811676e-41, 0.7280993274418598]]) + norm(res[product, 3]) norm(res[product, 3])
182182

@@ -222,16 +222,15 @@ using LinearAlgebra, SparseArrays, OffsetArrays, RecursiveArrayTools
222222

223223

224224
ne.A .= vcat(
225-
hcat(spzeros(n1, n1), spzeros(n1, n2), ne.A13),
226-
hcat(spzeros(n2, n1), ne.A22, ne.A32'),
227-
hcat(ne.A13', ne.A32, spzeros(n3, n3))
228-
)
225+
hcat(spzeros(n1, n1), spzeros(n1, n2), ne.A13),
226+
hcat(spzeros(n2, n1), ne.A22, ne.A32'),
227+
hcat(ne.A13', ne.A32, spzeros(n3, n3))
228+
)
229229
ne.b .= vcat(ne.b1, ne.b2, ne.b3)
230230

231231
@test norm(Matrix(ne.A22) - [5.380868154339828 0.0 -3.695518130045147 0.0 0.0 0.0; -9.316796552482789e-17 5.380868154339828 0.0 -4.0 0.0 0.0; -3.695518130045147 0.0 7.416036260090294 0.0 -3.695518130045147 0.0; 0.0 -4.0 0.0 7.416036260090294 0.0 -4.0; 0.0 0.0 -3.695518130045147 0.0 6.594762875032289 0.0; 0.0 0.0 0.0 -4.0 4.39376565883322e-17 6.5947628750322895]) + norm(Matrix(ne.A22)) norm(Matrix(ne.A22))
232232

233233

234-
235234
@test norm(Matrix(ne.A13) - [1.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 1.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 -1.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 -1.0]) + norm(Matrix(ne.A13)) norm(Matrix(ne.A13))
236235

237236

@@ -245,20 +244,20 @@ using LinearAlgebra, SparseArrays, OffsetArrays, RecursiveArrayTools
245244

246245

247246
@test norm(ne.b3 - [0.028613358998594428, -0.029085429045636227, -0.11180339887498948, -0.04048494156391083, -0.04158542904563624, 0.0, -0.040484941563910776, 0.0415854290456362, 0.0, -0.013093542744289671, 0.029085429045636213, -0.07808688094430304]) + norm(ne.b3) norm(ne.b3)
248-
247+
249248
return
250249
end
251250

252251
NE = NewtonEq(product, integrand_yλ, integrand_vv, integrand_λv, test_spaces, ansatz_spaces, transport, discrete_time_interval)
253252

254253
st_res = vectorbundle_newton(
255-
product, TangentBundle(product), NE, y_0; sub_problem = solve_in_basis_repr, sub_state = AllocatingEvaluation(),
256-
stopping_criterion = (StopAfterIteration(1) | StopWhenChangeLess(product, 1.0e-12; outer_norm = Inf)),
257-
retraction_method = ProductRetraction(ExponentialRetraction(), ProjectionRetraction(), ExponentialRetraction()),
258-
return_state = true
259-
)
254+
product, TangentBundle(product), NE, y_0; sub_problem = solve_in_basis_repr, sub_state = AllocatingEvaluation(),
255+
stopping_criterion = (StopAfterIteration(1) | StopWhenChangeLess(product, 1.0e-12; outer_norm = Inf)),
256+
retraction_method = ProductRetraction(ExponentialRetraction(), ProjectionRetraction(), ExponentialRetraction()),
257+
return_state = true
258+
)
260259
end
261-
260+
262261
@testset "Test assembly simplified right hand side for block system" begin # testset for assembling the right-hand side for simplified Newton (for damping) in the first iteration
263262
function (ne::NewtonEq)(M, VB, p)
264263
n1 = Int(manifold_dimension(submanifold(M, 1)))
@@ -299,12 +298,12 @@ using LinearAlgebra, SparseArrays, OffsetArrays, RecursiveArrayTools
299298

300299

301300
ne.A .= vcat(
302-
hcat(spzeros(n1, n1), spzeros(n1, n2), ne.A13),
303-
hcat(spzeros(n2, n1), ne.A22, ne.A32'),
304-
hcat(ne.A13', ne.A32, spzeros(n3, n3))
305-
)
301+
hcat(spzeros(n1, n1), spzeros(n1, n2), ne.A13),
302+
hcat(spzeros(n2, n1), ne.A22, ne.A32'),
303+
hcat(ne.A13', ne.A32, spzeros(n3, n3))
304+
)
306305
ne.b .= vcat(ne.b1, ne.b2, ne.b3)
307-
306+
308307
return
309308
end
310309

@@ -343,13 +342,13 @@ using LinearAlgebra, SparseArrays, OffsetArrays, RecursiveArrayTools
343342
end
344343

345344
NE = NewtonEq(product, integrand_yλ, integrand_vv, integrand_λv, test_spaces, ansatz_spaces, transport, discrete_time_interval)
346-
345+
347346
st_res2 = vectorbundle_newton(
348-
product, TangentBundle(product), NE, y_0; sub_problem = solve_in_basis_repr, sub_state = AllocatingEvaluation(),
349-
stopping_criterion = (StopAfterIteration(1) | StopWhenChangeLess(product, 1.0e-12; outer_norm = Inf)),
350-
retraction_method = ProductRetraction(ExponentialRetraction(), ProjectionRetraction(), ExponentialRetraction()),
351-
stepsize = Manopt.AffineCovariantStepsize(product, θ_des = 1.1, outer_norm = Inf),
352-
return_state = true
347+
product, TangentBundle(product), NE, y_0; sub_problem = solve_in_basis_repr, sub_state = AllocatingEvaluation(),
348+
stopping_criterion = (StopAfterIteration(1) | StopWhenChangeLess(product, 1.0e-12; outer_norm = Inf)),
349+
retraction_method = ProductRetraction(ExponentialRetraction(), ProjectionRetraction(), ExponentialRetraction()),
350+
stepsize = Manopt.AffineCovariantStepsize(product, θ_des = 1.1, outer_norm = Inf),
351+
return_state = true
353352
)
354-
end
355-
end
353+
end
354+
end

0 commit comments

Comments
 (0)