Skip to content

Commit cb21f2e

Browse files
committed
Enhanced testing
1 parent 54c16e3 commit cb21f2e

File tree

6 files changed

+312
-30
lines changed

6 files changed

+312
-30
lines changed

src/discretization/bond_system.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ function calc_force_density!(chunk::AbstractBodyChunk{<:AbstractBondSystem}, t,
273273
return nothing
274274
end
275275

276+
# a placeholder function for all force density calculations with multiple parameters that
277+
# are not specifially handled by the material
278+
function force_density_point!(storage::AbstractStorage, system::AbstractBondSystem,
279+
mat::AbstractBondSystemMaterial,
280+
paramhandler::AbstractParameterHandler, t, Δt, i)
281+
params = get_params(paramhandler, i)
282+
force_density_point!(storage, system, mat, params, t, Δt, i)
283+
return nothing
284+
end
285+
276286
function calc_failure!(storage::AbstractStorage, system::AbstractBondSystem,
277287
mat::AbstractMaterial, dmgmodel::CriticalStretch,
278288
paramsetup::AbstractParameterSetup, i)

src/physics/ba_correspondence.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,6 @@ function init_field(::BACMaterial, ::AbstractTimeSolver, system::BondAssociatedS
189189
return zeros(get_n_loc_points(system))
190190
end
191191

192-
function force_density_point!(storage::BACStorage, system::BondAssociatedSystem,
193-
mat::BACMaterial, paramhandler::AbstractParameterHandler,
194-
t, Δt, i)
195-
params = get_params(paramhandler, i)
196-
force_density_point!(storage, system, mat, params, t, Δt, i)
197-
return nothing
198-
end
199-
200192
function force_density_point!(storage::BACStorage, system::BondAssociatedSystem,
201193
mat::BACMaterial, params::BACPointParameters, t, Δt, i)
202194
for bond_idx in each_bond_idx(system, i)

src/physics/correspondence.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,6 @@ function init_field(::CMaterial, ::AbstractTimeSolver, system::BondSystem,
199199
return zeros(get_n_loc_points(system))
200200
end
201201

202-
function force_density_point!(storage::AbstractStorage, system::AbstractSystem,
203-
mat::AbstractCorrespondenceMaterial,
204-
paramhandler::AbstractParameterHandler, t, Δt, i)
205-
params = get_params(paramhandler, i)
206-
force_density_point!(storage, system, mat, params, t, Δt, i)
207-
return nothing
208-
end
209-
210202
function force_density_point!(storage::AbstractStorage, system::AbstractSystem,
211203
mat::AbstractCorrespondenceMaterial,
212204
params::AbstractPointParameters, t, Δt, i)

src/physics/rk_correspondence.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -457,14 +457,6 @@ function calc_force_density!(chunk::BodyChunk{<:BondSystem,<:AbstractRKCMaterial
457457
return nothing
458458
end
459459

460-
function force_density_point!(storage::AbstractStorage, system::AbstractSystem,
461-
mat::AbstractRKCMaterial,
462-
paramhandler::AbstractParameterHandler, t, Δt, i)
463-
params = get_params(paramhandler, i)
464-
force_density_point!(storage, system, mat, params, t, Δt, i)
465-
return nothing
466-
end
467-
468460
function force_density_point!(storage::AbstractStorage, system::AbstractSystem,
469461
mat::AbstractRKCMaterial, params::AbstractPointParameters, t,
470462
Δt, i)

test/integration/mpi_threads_comparison.jl

Lines changed: 87 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@testitem "MPI-Threads comparison BBMaterial{NoCorrection}" tags=[:mpi] begin
2+
force_threads_run!()
23
root = mktempdir()
34
path_threads = joinpath(root, "results_threads")
45
path_threads_vtk = joinpath(path_threads, "vtk")
@@ -48,9 +49,10 @@
4849
sim_bb(30, "$path_mpi")
4950
"""
5051
mpiexec = Peridynamics.MPI.mpiexec()
52+
nprocs = get(ENV, "CI", "false") == "true" ? 2 : Sys.CPU_THREADS
5153
jlcmd = Base.julia_cmd()
5254
pdir = pkgdir(Peridynamics)
53-
run(`$(mpiexec) -n 2 $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
55+
run(`$(mpiexec) -n $(nprocs) $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
5456

5557
@test isdir(path_threads_vtk)
5658
@test isdir(path_mpi_vtk)
@@ -67,6 +69,7 @@
6769
end
6870

6971
@testitem "MPI-Threads comparison BBMaterial{NoCorrection} DynamicRelaxation" tags=[:mpi] begin
72+
force_threads_run!()
7073
root = mktempdir()
7174
path_threads = joinpath(root, "results_threads")
7275
path_threads_vtk = joinpath(path_threads, "vtk")
@@ -116,9 +119,10 @@ end
116119
sim_bb(30, "$path_mpi")
117120
"""
118121
mpiexec = Peridynamics.MPI.mpiexec()
122+
nprocs = get(ENV, "CI", "false") == "true" ? 2 : Sys.CPU_THREADS
119123
jlcmd = Base.julia_cmd()
120124
pdir = pkgdir(Peridynamics)
121-
run(`$(mpiexec) -n 2 $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
125+
run(`$(mpiexec) -n $(nprocs) $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
122126

123127
@test isdir(path_threads_vtk)
124128
@test isdir(path_mpi_vtk)
@@ -140,6 +144,7 @@ end
140144
end
141145

142146
@testitem "MPI-Threads comparison BBMaterial{EnergySurfaceCorrection}" tags=[:mpi,:skipci] begin
147+
force_threads_run!()
143148
root = mktempdir()
144149
path_threads = joinpath(root, "results_threads")
145150
path_threads_vtk = joinpath(path_threads, "vtk")
@@ -189,9 +194,10 @@ end
189194
sim_bb(30, "$path_mpi")
190195
"""
191196
mpiexec = Peridynamics.MPI.mpiexec()
197+
nprocs = get(ENV, "CI", "false") == "true" ? 2 : Sys.CPU_THREADS
192198
jlcmd = Base.julia_cmd()
193199
pdir = pkgdir(Peridynamics)
194-
run(`$(mpiexec) -n 2 $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
200+
run(`$(mpiexec) -n $(nprocs) $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
195201

196202
@test isdir(path_threads_vtk)
197203
@test isdir(path_mpi_vtk)
@@ -208,6 +214,7 @@ end
208214
end
209215

210216
@testitem "MPI-Threads comparison OSBMaterial" tags=[:mpi,:skipci] begin
217+
force_threads_run!()
211218
root = mktempdir()
212219
path_threads = joinpath(root, "results_threads")
213220
path_threads_vtk = joinpath(path_threads, "vtk")
@@ -257,9 +264,10 @@ end
257264
sim_osb(30, "$path_mpi")
258265
"""
259266
mpiexec = Peridynamics.MPI.mpiexec()
267+
nprocs = get(ENV, "CI", "false") == "true" ? 2 : Sys.CPU_THREADS
260268
jlcmd = Base.julia_cmd()
261269
pdir = pkgdir(Peridynamics)
262-
run(`$(mpiexec) -n 2 $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
270+
run(`$(mpiexec) -n $(nprocs) $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
263271

264272
@test isdir(path_threads_vtk)
265273
@test isdir(path_mpi_vtk)
@@ -276,6 +284,7 @@ end
276284
end
277285

278286
@testitem "MPI-Threads comparison CMaterial" tags=[:mpi] begin
287+
force_threads_run!()
279288
root = mktempdir()
280289
path_threads = joinpath(root, "results_threads")
281290
path_threads_vtk = joinpath(path_threads, "vtk")
@@ -325,9 +334,10 @@ end
325334
sim_cc(30, "$path_mpi")
326335
"""
327336
mpiexec = Peridynamics.MPI.mpiexec()
337+
nprocs = get(ENV, "CI", "false") == "true" ? 2 : Sys.CPU_THREADS
328338
jlcmd = Base.julia_cmd()
329339
pdir = pkgdir(Peridynamics)
330-
run(`$(mpiexec) -n 2 $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
340+
run(`$(mpiexec) -n $(nprocs) $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
331341

332342
@test isdir(path_threads_vtk)
333343
@test isdir(path_mpi_vtk)
@@ -343,8 +353,78 @@ end
343353
end
344354
end
345355

356+
@testitem "MPI-Threads comparison RKCRMaterial" tags=[:mpi] begin
357+
force_threads_run!()
358+
root = mktempdir()
359+
path_threads = joinpath(root, "results_threads")
360+
path_threads_vtk = joinpath(path_threads, "vtk")
361+
path_mpi = joinpath(root, "results_mpi")
362+
path_mpi_vtk = joinpath(path_mpi, "vtk")
363+
364+
function sim_cc(N::Int, path::String)
365+
l, Δx, δ, a = 1.0, 1/N, 3.015/N, 0.5
366+
pos, vol = uniform_box(l, l, 0.1l, Δx)
367+
ids = sortperm(pos[2,:])
368+
b = Body(RKCRMaterial(), pos[:, ids], vol[ids])
369+
material!(b; horizon=3.015Δx, E=2.1e5, nu=0.25, rho=8e-6, Gc=2.7)
370+
point_set!(p -> p[1] -l/2+a && 0 p[2] 2δ, b, :set_a)
371+
point_set!(p -> p[1] -l/2+a && -2δ p[2] < 0, b, :set_b)
372+
precrack!(b, :set_a, :set_b)
373+
point_set!(p -> p[2] > l/2-Δx, b, :set_top)
374+
point_set!(p -> p[2] < -l/2+Δx, b, :set_bottom)
375+
velocity_bc!(t -> -30, b, :set_bottom, :y)
376+
velocity_bc!(t -> 30, b, :set_top, :y)
377+
vv = VelocityVerlet(steps=100)
378+
job = Job(b, vv; path=path, freq=50)
379+
submit(job)
380+
return nothing
381+
end
382+
sim_cc(30, path_threads)
383+
384+
mpi_cmd = """
385+
using Peridynamics
386+
function sim_cc(N::Int, path::String)
387+
l, Δx, δ, a = 1.0, 1/N, 3.015/N, 0.5
388+
pos, vol = uniform_box(l, l, 0.1l, Δx)
389+
ids = sortperm(pos[2,:])
390+
b = Body(RKCRMaterial(), pos[:, ids], vol[ids])
391+
material!(b; horizon=3.015Δx, E=2.1e5, nu=0.25, rho=8e-6, Gc=2.7)
392+
point_set!(p -> p[1] ≤ -l/2+a && 0 ≤ p[2] ≤ 2δ, b, :set_a)
393+
point_set!(p -> p[1] ≤ -l/2+a && -2δ ≤ p[2] < 0, b, :set_b)
394+
precrack!(b, :set_a, :set_b)
395+
point_set!(p -> p[2] > l/2-Δx, b, :set_top)
396+
point_set!(p -> p[2] < -l/2+Δx, b, :set_bottom)
397+
velocity_bc!(t -> -30, b, :set_bottom, :y)
398+
velocity_bc!(t -> 30, b, :set_top, :y)
399+
vv = VelocityVerlet(steps=100)
400+
job = Job(b, vv; path=path, freq=50)
401+
submit(job)
402+
return nothing
403+
end
404+
sim_cc(30, "$path_mpi")
405+
"""
406+
mpiexec = Peridynamics.MPI.mpiexec()
407+
nprocs = get(ENV, "CI", "false") == "true" ? 2 : Sys.CPU_THREADS
408+
jlcmd = Base.julia_cmd()
409+
pdir = pkgdir(Peridynamics)
410+
run(`$(mpiexec) -n $(nprocs) $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
411+
412+
@test isdir(path_threads_vtk)
413+
@test isdir(path_mpi_vtk)
414+
vtk_files_threads = Peridynamics.find_vtk_files(path_threads_vtk)
415+
vtk_files_mpi = Peridynamics.find_vtk_files(path_mpi_vtk)
416+
@test length(vtk_files_mpi) == length(vtk_files_threads) == 3
417+
for i in eachindex(vtk_files_threads, vtk_files_mpi)
418+
res_threads = read_vtk(vtk_files_threads[i])
419+
res_mpi = read_vtk(vtk_files_mpi[i])
420+
for key in keys(res_threads)
421+
@test res_threads[key] res_mpi[key]
422+
end
423+
end
424+
end
346425

347426
@testitem "MPI-Threads comparison BACMaterial" tags=[:mpi,:skipci] begin
427+
force_threads_run!()
348428
root = mktempdir()
349429
path_threads = joinpath(root, "results_threads")
350430
path_threads_vtk = joinpath(path_threads, "vtk")
@@ -394,9 +474,10 @@ end
394474
sim_bac(30, "$path_mpi")
395475
"""
396476
mpiexec = Peridynamics.MPI.mpiexec()
477+
nprocs = get(ENV, "CI", "false") == "true" ? 2 : Sys.CPU_THREADS
397478
jlcmd = Base.julia_cmd()
398479
pdir = pkgdir(Peridynamics)
399-
run(`$(mpiexec) -n 2 $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
480+
run(`$(mpiexec) -n $(nprocs) $(jlcmd) --project=$(pdir) -e $(mpi_cmd)`)
400481

401482
@test isdir(path_threads_vtk)
402483
@test isdir(path_mpi_vtk)

0 commit comments

Comments
 (0)