Skip to content

Commit afd78a3

Browse files
authored
Merge pull request #83 from sintefmath/dev
Hysteretic parameters and MPI memory usage improvements
2 parents 4ac8cd6 + 2ee720a commit afd78a3

File tree

13 files changed

+88
-21
lines changed

13 files changed

+88
-21
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Jutul"
22
uuid = "2b460a1a-8a2b-45b2-b125-b5c536396eb9"
33
authors = ["Olav Møyner <[email protected]>"]
4-
version = "0.2.34"
4+
version = "0.2.35"
55

66
[deps]
77
AlgebraicMultigrid = "2169fc97-5a83-5252-b627-83903c6c433c"
@@ -78,9 +78,9 @@ LayeredLayouts = "0.2.5"
7878
LinearOperators = "2.3.2"
7979
LoopVectorization = "0.12.115"
8080
MAT = "0.10.3"
81-
Makie = "0.20.0"
81+
Makie = "0.21.0"
8282
MappedArrays = "0.4.1"
83-
Meshes = "0.28 - 0.41, 0.46"
83+
Meshes = "0.28 - 0.41"
8484
Metis = "1.1.0"
8585
NetworkLayout = "0.4.5"
8686
OrderedCollections = "1.4.1"

ext/JutulMakieExt/interactive_3d.jl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ function plot_interactive_impl(grid, states;
392392
"batlowK",
393393
"berlin",
394394
"brg",
395+
"commercial",
395396
"gnuplot",
396397
"gray1",
397398
"hawaii",
@@ -553,7 +554,6 @@ function plot_interactive_impl(grid, states;
553554
tri = primitives.triangulation
554555
scat = Makie.mesh!(ax, pts, tri; color = ys,
555556
colorrange = lims,
556-
size = 60,
557557
backlight = 1,
558558
colormap = cmap,
559559
transparency = transparency,
@@ -675,7 +675,11 @@ function unpack(buffer, x::AbstractVector, ix)
675675
end
676676

677677
function generate_colormap(colormap_name, alphamap_name, base_alpha, low, high)
678-
cmap = to_colormap(colormap_name)
678+
if colormap_name == :commercial
679+
cmap = commercial_colormap()
680+
else
681+
cmap = to_colormap(colormap_name)
682+
end
679683
n = length(cmap)
680684
if alphamap_name != :no_alpha_map
681685
if alphamap_name == :linear
@@ -878,3 +882,27 @@ function Jutul.plotting_check_interactive(; warn = true)
878882
end
879883
return true
880884
end
885+
886+
function commercial_colormap()
887+
blue = (0, 0, 1)
888+
cyan = (0, 1, 1)
889+
green = (0, 1, 0)
890+
yellow = (1, 1, 0)
891+
red = (1, 0, 0)
892+
893+
function simple_interp(F_0, F_1, x)
894+
v = F_0 .+ (F_1 .- F_0).*x
895+
return Makie.RGB(v...)
896+
end
897+
cmap = Vector{typeof(Makie.RGB(0, 0, 0))}()
898+
nsteps = [30, 25, 25, 20]
899+
colors = (blue, cyan, green, yellow, red)
900+
for (i, nstep) in enumerate(nsteps)
901+
c1 = colors[i]
902+
c2 = colors[i+1]
903+
for dx in range(0.0, 1.0, nstep)
904+
push!(cmap, simple_interp(c1, c2, dx))
905+
end
906+
end
907+
return cmap
908+
end

ext/JutulMeshesExt/JutulMeshesExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module JutulMeshesExt
88
# Global neighborship
99
N = zeros(Int64, 2, nf)
1010
# Normals and centroids
11-
normals = Vector{Vec3}(undef, nf)
11+
normals = Vector{Meshes.Vec3}(undef, nf)
1212
cell_centroids = centroid.(grid)
1313
face_centroids = Vector{Point3}(undef, nf)
1414
# Measures

ext/JutulPartitionedArraysExt/io.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
function consolidate_distributed_results_on_disk!(pth, np, steps; cleanup = true)
1+
function Jutul.consolidate_distributed_results_on_disk!(pth, np, steps; cleanup = true, verbose = false)
22
@assert isdir(pth)
33
partitions = []
4+
function print_msg(x)
5+
if verbose
6+
jutul_message("IO", x)
7+
end
8+
end
49
for rank in 1:np
10+
print_msg("Reading partition for process $rank/$np")
511
proc_pth = rank_folder(pth, rank)
612
part_path = joinpath(proc_pth, "partition.jld2")
713
p = load(part_path)
814
push!(partitions, p)
915
end
1016
allpaths = []
1117
for step in steps
18+
print_msg("Reading result for state $step/$(length(steps))")
1219
step::Int
1320
states, reports, paths = read_step(pth, step, np)
1421
state, report = consolidate_distributed_results(states, reports, partitions)
@@ -17,6 +24,7 @@ function consolidate_distributed_results_on_disk!(pth, np, steps; cleanup = true
1724
GC.gc()
1825
end
1926
if cleanup
27+
print_msg("Cleaning up files...")
2028
# Delete the parallel results after consolidation.
2129
for paths in allpaths
2230
for path in paths

ext/JutulPartitionedArraysExt/overloads.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,12 @@ function Jutul.retrieve_output!(sim::PArraySimulator, states, reports, config, n
283283
if config[:consolidate_results]
284284
MPI.Barrier(comm)
285285
if np > 1 && is_main && pth isa String
286-
consolidate_distributed_results_on_disk!(pth, np, 1:n, cleanup = config[:delete_on_consolidate])
286+
Jutul.consolidate_distributed_results_on_disk!(pth, np, 1:n, cleanup = config[:delete_on_consolidate], verbose = config[:info_level] > 0)
287287
end
288288
MPI.Barrier(comm)
289289
end
290-
Jutul.retrieve_output!(states, reports, config, n)
290+
states, reports = Jutul.retrieve_output!(states, reports, config, n, read_states = config[:output_states] && is_main)
291+
return (states, reports)
291292
end
292293

293294
function Jutul.simulator_reports_per_step(psim::PArraySimulator)

src/conservation/conservation.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ function update_lsys_sources_theaded!(nz, r, acc, src, rv_src, nz_src, cp, conte
366366
pos = get_jacobian_pos(acc, cell, e, d, cp)
367367
@inbounds nz[pos] += v.partials[d]
368368
end
369-
# @info "Entry $e, $cell ($nc x $np): $(v.value)"
370369
end
371370
end
372371
end

src/core_types/contexts/interface.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
export minbatch
2-
minbatch(::Any) = 1000
3-
nthreads(::Any) = Threads.nthreads()
2+
3+
function minbatch(x::Any)
4+
nt = nthreads(x)
5+
if nt == 1
6+
nb = typemax(Int)
7+
else
8+
nb = 1000
9+
end
10+
return nb
11+
end
12+
13+
function nthreads(::Any)
14+
Threads.nthreads()
15+
end
16+
417
minbatch(x, n) = max(n ÷ nthreads(x), minbatch(x))
518

619
function jacobian_eltype(context, layout, block_size)

src/ext/partitionedarrays_ext.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ function mpi_scalar_allreduce
2828

2929
end
3030

31+
function consolidate_distributed_results_on_disk!
32+
33+
end
34+
3135
abstract type PArrayBackend <: JutulBackend end
3236

3337
struct DebugPArrayBackend <: PArrayBackend end

src/interpolation.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function get_dependencies(var::UnaryTabulatedVariable, model)
284284
return [var.x_symbol]
285285
end
286286

287-
function update_secondary_variable!(V, var::UnaryTabulatedVariable, model, state)
287+
function update_secondary_variable!(V, var::UnaryTabulatedVariable, model, state, ix = entity_eachindex(V))
288288
update_unary_tabulated!(V, var, model, state[var.x_symbol], entity_eachindex(V))
289289
end
290290

src/models.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,10 @@ function update_before_step!(storage, model, dt, forces; kwarg...)
930930
end
931931

932932
function update_before_step!(storage, ::Any, model, dt, forces; time = NaN, recorder = ProgressRecorder(), update_explicit = true)
933-
# Do nothing
933+
state = storage.state
934+
for (k, prm) in pairs(storage.variable_definitions.parameters)
935+
update_parameter_before_step!(state[k], prm, storage, model, dt, forces)
936+
end
934937
end
935938

936939
function update_after_step!(storage, model, dt, forces; kwarg...)
@@ -963,10 +966,20 @@ function update_after_step!(storage, model, dt, forces; kwarg...)
963966
return report
964967
end
965968

969+
"""
970+
update_parameter_before_step!(prm_val, prm, storage, model, dt, forces)
971+
972+
Update parameters before time-step. Used for hysteretic parameters.
973+
"""
974+
function update_parameter_before_step!(prm_val, prm, storage, model, dt, forces)
975+
# Do nothing by default.
976+
return prm_val
977+
end
978+
966979
function variable_change_report(X::AbstractArray, X0::AbstractArray{T}, pvar) where T<:Real
967980
max_dv = max_v = sum_dv = sum_v = zero(T)
968981
@inbounds @simd for i in eachindex(X)
969-
x = value(X[i])
982+
x = value(X[i])::T
970983
dx = x - value(X0[i])
971984

972985
dx_abs = abs(dx)

0 commit comments

Comments
 (0)