Skip to content

Commit

Permalink
Merge branch 'main' into add-NeckingReview-setups
Browse files Browse the repository at this point in the history
  • Loading branch information
tduretz authored Jun 23, 2024
2 parents a3a1dd0 + 3a21e0e commit 924d2ce
Show file tree
Hide file tree
Showing 184 changed files with 4,431 additions and 1,125 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Ignore all
*
# Unignore all with extensions
!*.*
# Unignore all dirs
!*/
.idea
__pycache__/
cmake-build**/
Expand All @@ -8,6 +14,8 @@ env.cmake
visualtests-out
build/
RUNS/
MDLIB/*/*.png
MDLIB/*/*/*.png
*.out
*.o
.vscode
Expand Down
2 changes: 1 addition & 1 deletion FindSuiteSparse.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ macro(SuiteSparse_FIND_COMPONENTS )
/usr/local/include/suitesparse
/usr/include/${suitesparseComp}
/usr/local/include/${suitesparseComp}
/opt/homebrew/Cellar/suite-sparse/7.6.1/include/suitesparse
/opt/homebrew/Cellar/suite-sparse/7.7.0/include/suitesparse
${SuiteSparse_DIR}/include
${SuiteSparse_DIR}/include/suitesparse
${SuiteSparse_DIR}/suitesparse/include
Expand Down
228 changes: 228 additions & 0 deletions JuliaVisualisation/Main_Visualisation_FaultSmearing_MD7.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
import Pkg
Pkg.activate(normpath(joinpath(@__DIR__, ".")))
using HDF5, Printf, Colors, ColorSchemes, MathTeXEngine, LinearAlgebra, FFMPEG, Statistics
using CairoMakie, GLMakie
const Mak = GLMakie
Makie.update_theme!(fonts = (regular = texfont(), bold = texfont(:bold), italic = texfont(:italic)))

const y = 365*24*3600
const My = 1e6*y
const cm_y = y*100.

function LoadField(path, istep)
name = @sprintf("Output%05d.gzip.h5", istep)
@info "Reading $(name)"
filename = string(path, name)

model = ExtractData( filename, "/Model/Params")
nvx = Int(model[4])
nvz = Int(model[5])
ncx, ncz = nvx-1, nvz-1

fields = (
model = ExtractData( filename, "/Model/Params"),
xc = ExtractData( filename, "/Model/xc_coord"),
zc = ExtractData( filename, "/Model/zc_coord"),
xv = ExtractData( filename, "/Model/xg_coord"),
zv = ExtractData( filename, "/Model/zg_coord"),
xvz = ExtractData( filename, "/Model/xvz_coord"),
zvx = ExtractData( filename, "/Model/zvx_coord"),
xv_hr = ExtractData( filename, "/VizGrid/xviz_hr"),
zv_hr = ExtractData( filename, "/VizGrid/zviz_hr"),
τzz_t = ExtractData( filename, "TimeSeries/szzd_mean_time"),
P_t = ExtractData( filename, "TimeSeries/P_mean_time"),
τxz_t = ExtractData( filename, "TimeSeries/sxz_mean_time"),
t_t = ExtractData( filename, "TimeSeries/Time_time"),
# ηc = ExtractField(filename, "/Centers/eta_n", centroids, true, mask_air),
ρc = Float64.(reshape(ExtractData( filename, "/Centers/rho_n"), ncx, ncz)),
P = Float64.(reshape(ExtractData( filename, "/Centers/P"), ncx, ncz)),
T = Float64.(reshape(ExtractData( filename, "/Centers/T"), ncx, ncz)) .- 273.15,
d = Float64.(reshape(ExtractData( filename, "/Centers/d"), ncx, ncz)),
ε̇pl = Float64.(reshape(ExtractData( filename, "/Centers/eII_pl"), ncx, ncz)),
Vx = Float64.(reshape(ExtractData( filename, "/VxNodes/Vx"), (ncx+1), (ncz+2))),
Vz = Float64.(reshape(ExtractData( filename, "/VzNodes/Vz"), (ncx+2), (ncz+1))),
τxx = Float64.(reshape(ExtractData( filename, "/Centers/sxxd"), ncx, ncz)),
τzz = Float64.(reshape(ExtractData( filename, "/Centers/szzd"), ncx, ncz)),
τxz = Float64.(reshape(ExtractData( filename, "/Vertices/sxz"), nvx, nvz)),
ε̇xx = Float64.(reshape(ExtractData( filename, "/Centers/exxd"), ncx, ncz)),
ε̇zz = Float64.(reshape(ExtractData( filename, "/Centers/ezzd"), ncx, ncz)),
ε̇xz = Float64.(reshape(ExtractData( filename, "/Vertices/exz"), nvx, nvz)),
)
dummy = (
t = fields.model[1],
τyy = -(fields.τzz .+ fields.τxx),
ε̇yy = -(fields.ε̇xx .+ fields.ε̇zz),
)
fields = merge(fields, dummy)
dummy = (
τII = sqrt.( 0.5*(fields.τxx.^2 .+ fields.τyy.^2 .+ fields.τzz.^2 .+ 0.5*(fields.τxz[1:end-1,1:end-1].^2 .+ fields.τxz[2:end,1:end-1].^2 .+ fields.τxz[1:end-1,2:end].^2 .+ fields.τxz[2:end,2:end].^2 ) ) ),
ε̇II = sqrt.( 0.5*(fields.ε̇xx.^2 .+ fields.ε̇yy.^2 .+ fields.ε̇zz.^2 .+ 0.5*(fields.ε̇xz[1:end-1,1:end-1].^2 .+ fields.ε̇xz[2:end,1:end-1].^2 .+ fields.ε̇xz[1:end-1,2:end].^2 .+ fields.ε̇xz[2:end,2:end].^2 ) ) ),
τxzc = 0.25*(fields.τxz[1:end-1,1:end-1] .+ fields.τxz[2:end,1:end-1] .+ fields.τxz[1:end-1,2:end] .+ fields.τxz[2:end,2:end]),
)
return merge(fields, dummy)
end

function ExtractField(filename, field, size, mask_air, mask)
field = try (Float64.(reshape(ExtractData( filename, field), size...)))
catch
@warn "$field not found"
end
mask_air ? field[mask] .= NaN : nothing
return field
end

function main()

# Set the path to your files
path = (
"/Users/tduretz/REPO/MDOODZ7.0/MDLIB/_p10_e18_t3/",
"/Users/tduretz/REPO/MDOODZ7.0/MDLIB/_p10_e18_t3_nonconv/",
"/Users/tduretz/REPO/MDOODZ7.0/MDLIB/_p10_e18_t2_nonconv/",
"/Users/tduretz/REPO/MDOODZ7.0/MDLIB/_p10_e18_t1_nonconv/",
)
names = (
"T3: Fully converged",
"T3: 1 iteration",
"T2: 1 iteration",
"T1: 1 iteration",
)
n_files = length(path)

# File numbers
file_start = 000
file_step = 10
file_end = 2000

# Select field to visualise
field = :Phases
# field = :Cohesion
# field = :Density
field = :Viscosity
# field = :PlasticStrainrate
# field = :Stress
# field = :StrainRate
# field = :Pressure
# field = :Divergence
# field = :Temperature
# field = :Velocity_x
# field = :Velocity_z
# field = :Velocity
# field = :GrainSize
# field = :Topography
# field = :TimeSeries
# field = :AnisotropyFactor
# field = :MeltFraction
# field = :TimeSeries
field = :EffectiveFrictionTime

# Switches
printfig = false # print figures to disk
printvid = false
framerate = 3
PlotOnTop = (
ph_contours = false, # add phase contours
T_contours = false, # add temperature contours
fabric = false, # add fabric quiver (normal to director)
topo = false,
σ1_axis = false,
vel_vec = false,
)
α_heatmap = 1.0 #0.85 # transparency of heatmap
vel_arrow = 5
vel_scale = 300000
nap = 0.1 # pause for animation
resol = 1000
Lx, Lz = 1.0, 1.0

# Scaling
# Lc = 1000.
# tc = My
# Vc = 1e-9

Lc = 1.0
tc = My
Vc = 1.0

probe = []
for i_file=1:n_files
probe_data = (ϕeff = Float64.([]), t = Float64.([]))
push!(probe, probe_data)
end
cm_yr = 100.0*3600.0*24.0*365.25

# Time loop
f = Figure(size = (Lx/Lz*resol*1.2, resol), fontsize=25)

for istep=file_start:file_step:file_end

dat = []
for i_file=1:n_files
data = LoadField(path[i_file], istep)
push!(dat, data)
end

#####################################
empty!(f)
f = Figure(size = (Lx/Lz*resol*1.2, resol), fontsize=25)

if field==:EffectiveFrictionTime
for i_file=1:n_files
ϕ_eff = -mean(dat[i_file].τxzc[:,end] ./ (dat[i_file].τzz[:,end] .- dat[i_file].P[:,end]) )
if istep==0 ϕ_eff = 0. end
push!(probe[i_file].ϕeff, ϕ_eff)
push!(probe[i_file].t, dat[i_file].t)
end
if istep==file_end
ax1 = Axis(f[1, 1], title = L"$ϕ_\mathrm{eff}$", xlabel = L"$t$", ylabel = L"$ϕ_\mathrm{eff}$")
for i_file=1:n_files
lines!(ax1, Float64.(probe[i_file].t), Float64.(probe[i_file].ϕeff), label=names[i_file])
end
axislegend(ax1, position = :rb)
end

end

if field!=:EffectiveFrictionTime || istep==file_end
DataInspector(f)
display(f)
sleep(nap)
end

end

yscale = Lz/Lx

if printfig && printvid
FFMPEG.ffmpeg_exe(`-framerate $(framerate) -f image2 -pattern_type glob -i $(path)_$(field)/'*'.png -vf "scale=1080:1080*$(yscale)" -c:v libx264 -pix_fmt yuv420p -y "$(mov_name).mov"`)
end

end

function PrincipalStress(τxx, τzz, τxz, P)
σ1 = (x=zeros(size(τxx)), z=zeros(size(τxx)) )
τxzc = 0.25*(τxz[1:end-1,1:end-1] .+ τxz[2:end-0,1:end-1] .+ τxz[1:end-1,2:end-0] .+ τxz[2:end-0,2:end-0])
for i in eachindex(τxzc)
if P[i]>1e-13
σ = [-P[i]+τxx[i] τxzc[i]; τxzc[i] -P[i]+τzz[i]]
v = eigvecs(σ)
σ1.x[i] = v[1,1]
σ1.z[i] = v[2,1]
end
end
return σ1
end

function ExtractData( file_path, data_path)
data = h5open(file_path, "r") do file
read(file, data_path)
end
return data
end

function Print2Disk( f, path, field, istep; res=4)
path1 = path*"/_$field/"
mkpath(path1)
save(path1*"$field"*@sprintf("%05d", istep)*".png", f, px_per_unit = res)
end

main()
52 changes: 21 additions & 31 deletions JuliaVisualisation/Main_Visualisation_Makie_ExtractDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ function main()

# File numbers
file_start = 00
file_step = 20
file_end = 500
file_step = 10
file_end = 50

# Select field to visualise
# field = :Phases
Expand All @@ -55,8 +55,8 @@ function main()
# field = :AnisotropyFactor

# Switches
printfig = false # print figures to disk
printvid = false
printfig = true # print figures to disk
printvid = true
framerate = 10
ph_contours = false # add phase contours
T_contours = false # add temperature contours
Expand Down Expand Up @@ -116,21 +116,24 @@ function main()



filenamenk = string(pathnk, @sprintf("Output%05d.gzip.h5", istep))
ρcnk = Float64.(reshape(ExtractData( filenamenk, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN
# filenamenk = string(pathnk, @sprintf("Output%05d.gzip.h5", istep))
# ρcnk = Float64.(reshape(ExtractData( filenamenk, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN

filename000 = string(path000, @sprintf("Output%05d.gzip.h5", istep))
ρc000 = Float64.(reshape(ExtractData( filename000, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN
# filename000 = string(path000, @sprintf("Output%05d.gzip.h5", istep))
# ρc000 = Float64.(reshape(ExtractData( filename000, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN

filename020 = string(path020, @sprintf("Output%05d.gzip.h5", istep))
ρc020 = Float64.(reshape(ExtractData( filename020, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN
# filename020 = string(path020, @sprintf("Output%05d.gzip.h5", istep))
# ρc020 = Float64.(reshape(ExtractData( filename020, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN

filename005 = string(path005, @sprintf("Output%05d.gzip.h5", istep))
ρc005 = Float64.(reshape(ExtractData( filename005, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN
# filename005 = string(path005, @sprintf("Output%05d.gzip.h5", istep))
# ρc005 = Float64.(reshape(ExtractData( filename005, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN

filename0e10 = string(path0e10, @sprintf("Output%05d.gzip.h5", istep))
ρc0e10 = Float64.(reshape(ExtractData( filename0e10, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN
# filename0e10 = string(path0e10, @sprintf("Output%05d.gzip.h5", istep))
# ρc0e10 = Float64.(reshape(ExtractData( filename0e10, "/Centers/rho_n"), ncx, ncz)); ρc[mask_air] .= NaN

tau0e10 = Extractρ("/Users/tduretz/REPO/MDOODZ7.0/MDLIB/qcoe_simp_tau0e10/", istep, ncx, ncz)
tau1e9 = Extractρ("/Users/tduretz/REPO/MDOODZ7.0/MDLIB/qcoe_simp_tau1e9/" , istep, ncx, ncz)
tau5e9 = Extractρ("/Users/tduretz/REPO/MDOODZ7.0/MDLIB/qcoe_simp_tau5e9/" , istep, ncx, ncz)
tau1e10 = Extractρ("/Users/tduretz/REPO/MDOODZ7.0/MDLIB/qcoe_simp_tau1e10/", istep, ncx, ncz)

P = Float64.(reshape(ExtractData( filename, "/Centers/P"), ncx, ncz)); P[mask_air] .= NaN
Expand Down Expand Up @@ -233,31 +236,18 @@ function main()
end

if field==:DensityProfs
ρ1D = zeros(size(ρc,1))
ρ1D000 = zeros(size(ρc,1))
ρ1D005 = zeros(size(ρc,1))
ρ1D020 = zeros(size(ρc,1))
ρ1D0e10 = zeros(size(ρc,1))
ρ1Dnk = zeros(size(ρc,1))
for i=1:size(ρc,1)
ρ1D[i] = ρc[i,i]
ρ1D000[i] = ρc000[i,i]
ρ1D005[i] = ρc005[i,i]
ρ1D020[i] = ρc020[i,i]
ρ1D0e10[i] = ρc0e10[i,i]
end
ax1 = Axis(f[1, 1], title = L"$ρ$ at $t$ = %$(tMy) Ma", xlabel = L"$x$ [m]", ylabel = L"$y$ [m]")
# l1=lines!(ax1, xc./Lc, ρ1D000)
# l2=lines!(ax1, xc./Lc, ρ1Dnk)
l1=lines!(ax1, xc./Lc, tau0e10.ρ1D)
l2=lines!(ax1, xc./Lc, tau1e9.ρ1D)
l3=lines!(ax1, xc./Lc, tau1e10.ρ1D)
l3=lines!(ax1, xc./Lc, tau5e9.ρ1D)
l4=lines!(ax1, xc./Lc, tau1e10.ρ1D)
# l2=lines!(ax1, xc./Lc, ρ1D005, label="nsm005")
# l3=lines!(ax1, xc./Lc, ρ1D, label="nsm010")
# l4=lines!(ax1, xc./Lc, ρ1D020, label="nsm020")

# Legend(f[1, 2],
# [l1, l2, l3],
# ["tk0", "tk0e10", "tk1e10"])
Legend(f[1, 2], [l1, l2, l3, l4], ["tk0", "tk1e9", "tk5e9", "tk1e10"])

# Legend(f[1, 2],
# [l1, l2, l3, l4],
Expand Down
Loading

0 comments on commit 924d2ce

Please sign in to comment.