Skip to content

Commit

Permalink
Add smearing setup (#130)
Browse files Browse the repository at this point in the history
* add new smearing setup

* fix CI

* modif smearing setup
  • Loading branch information
tduretz authored Jun 11, 2024
1 parent 75e5611 commit a596fed
Show file tree
Hide file tree
Showing 14 changed files with 664 additions and 32 deletions.
226 changes: 226 additions & 0 deletions JuliaVisualisation/Main_Visualisation_FaultSmearing_MD7.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
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/",
)
names = (
"T3: Fully converged",
"T3: 1 iteration",
"T2: 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(resolution = (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(resolution = (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()
51 changes: 37 additions & 14 deletions JuliaVisualisation/Main_Visualisation_Makie_MD7.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function AddCountourQuivers!(PlotOnTop, ax1, xc, xv, zc, V, T, σ1, Fab, height,
arrows!(ax1, xc./Lc, zc./Lc, Fab.x, Fab.z, arrowsize = 0, lengthscale=Δ/1.5)
end
if PlotOnTop.σ1_axis
arrows!(ax1, xc./Lc, zc./Lc, σ1.x, σ1.z, arrowsize = 0, lengthscale=Δ/1.5)
arrows!(ax1, xc./Lc, zc./Lc, σ1.x, σ1.z, arrowsize = 0, lengthscale=Δ/1.5, color=:white)
end
if PlotOnTop.vel_vec
arrows!(ax1, xc./Lc, zc./Lc, V.x*cm_y, V.z*cm_y, arrowsize = V.arrow, lengthscale = V.scale)
Expand All @@ -43,7 +43,8 @@ function main()

# Set the path to your files
path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB/TEST_ROMAN_ANI3_00_MR/"
path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB//"
path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB/_p10_e18_t3/"
path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB/_p10_e18_t1_nonconv/"

# path ="/Users/tduretz/Downloads/"
# path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB/DoubleSubduction_OMP16/"
Expand All @@ -56,15 +57,15 @@ function main()
# path ="/Users/tduretz/REPO/MDOODZ7.0/RUNS/1_NR09/"

# File numbers
file_start = 00
file_step = 50
file_end = 200
file_start = 000
file_step = 100
file_end = 2000

# Select field to visualise
# field = :Phases
field = :Phases
# field = :Cohesion
# field = :Density
field = :Viscosity
# field = :Viscosity
# field = :PlasticStrainrate
# field = :Stress
# field = :StrainRate
Expand All @@ -79,6 +80,8 @@ function main()
# field = :TimeSeries
# field = :AnisotropyFactor
# field = :MeltFraction
# field = :TimeSeries
# field = :EffectiveFrictionTime

# Switches
printfig = false # print figures to disk
Expand All @@ -95,7 +98,7 @@ function main()
α_heatmap = 1.0 #0.85 # transparency of heatmap
vel_arrow = 5
vel_scale = 300000
nap = 0.3 # pause for animation
nap = 0.1 # pause for animation
resol = 1000
mov_name = "$(path)/_$(field)/$(field)" # Name of the movie
Lx, Lz = 1.0, 1.0
Expand All @@ -109,6 +112,7 @@ function main()
tc = My
Vc = 1.0

probe = (ϕeff = Float64.([]), t = Float64.([]))
cm_yr = 100.0*3600.0*24.0*365.25

# Time loop
Expand All @@ -128,8 +132,10 @@ function main()
zvx = ExtractData( filename, "/Model/zvx_coord")
xv_hr = ExtractData( filename, "/VizGrid/xviz_hr")
zv_hr = ExtractData( filename, "/VizGrid/zviz_hr")
# τxz_t = ExtractData( filename, "TimeSeries/sxz_mean_time")
# t_t = ExtractData( filename, "TimeSeries/Time_time")
τ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")

xc_hr = 0.5.*(xv_hr[1:end-1] .+ xv_hr[2:end])
zc_hr = 0.5.*(zv_hr[1:end-1] .+ zv_hr[2:end])
Expand Down Expand Up @@ -174,6 +180,7 @@ function main()
ε̇xz = Float64.(reshape(ExtractData( filename, "/Vertices/exz"), nvx, nvz))
τII = sqrt.( 0.5*(τxx.^2 .+ τyy.^2 .+ τzz.^2 .+ 0.5*(τxz[1:end-1,1:end-1].^2 .+ τxz[2:end,1:end-1].^2 .+ τxz[1:end-1,2:end].^2 .+ τxz[2:end,2:end].^2 ) ) ); τII[mask_air] .= NaN
ε̇II = sqrt.( 0.5*(ε̇xx.^2 .+ ε̇yy.^2 .+ ε̇zz.^2 .+ 0.5*(ε̇xz[1:end-1,1:end-1].^2 .+ ε̇xz[2:end,1:end-1].^2 .+ ε̇xz[1:end-1,2:end].^2 .+ ε̇xz[2:end,2:end].^2 ) ) ); ε̇II[mask_air] .= NaN
τxzc = 0.25*(τxz[1:end-1,1:end-1] .+ τxz[2:end,1:end-1] .+ τxz[1:end-1,2:end] .+ τxz[2:end,2:end])
C = Float64.(reshape(ExtractData( filename, "/Centers/cohesion"), ncx, ncz))
ϕ = ExtractField(filename, "/Centers/phi", centroids, false, 0)
divu = ExtractField(filename, "/Centers/divu", centroids, false, 0)
Expand Down Expand Up @@ -425,12 +432,28 @@ function main()

if field==:TimeSeries
ax1 = Axis(f[1, 1], title = L"$τ_{xz}$", xlabel = L"$t$", ylabel = L"$\tau_{xz}$")
lines!(ax1, t_t, τxz_t)
τxz_t[1] = 0.
@show .-τxz_t
lines!(ax1, t_t, .-τxz_t./(.-P_t.+τzz_t))
end

DataInspector(f)
display(f)
sleep(nap)
if field==:EffectiveFrictionTime
ϕ_eff = -mean(τxzc[:,end] ./ (τzz[:,end] .- P[:,end]) )
if istep==0 ϕ_eff = 0. end
push!(probe.ϕeff, ϕ_eff)
push!(probe.t, t)
if istep==file_end
ax1 = Axis(f[1, 1], title = L"$ϕ_\mathrm{eff}$", xlabel = L"$t$", ylabel = L"$ϕ_\mathrm{eff}$")
lines!(ax1, Float64.(probe.t), Float64.(probe.ϕeff))
end

end

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

end

Expand Down
4 changes: 4 additions & 0 deletions MDLIB/InputOutput.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,10 @@ Input ReadInputFile( char *fileName ) {
materials.psi[k] = ReadMatProps( fin, "psi", k, 0.0 ) * M_PI/ 180.0;
if (materials.psi[k]>0.0 && model.compressible==0) { printf("Set compressible=1 to activate dilation\n"); exit(1); }
materials.Slim[k] = ReadMatProps( fin, "Slim" ,k, 1.0e90 ) / scaling.S;
if (materials.Slim[k]<materials.C[k]) {
printf("Upper stress limiter of phase %d is lower than cohesion: it makes no sense, please correct!\n", k);
exit(1);
}
// Viscoplasticity
materials.n_vp[k] = ReadMatProps( fin, "n_vp", k, 1.0 ) ;
materials.eta_vp[k] = ReadMatProps( fin, "eta_vp", k, 0.0 ) / scaling.S / pow(scaling.t, 1.0/materials.n_vp[k]);
Expand Down
5 changes: 3 additions & 2 deletions MDLIB/RheologyDensity.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@ double ViscosityConcise( int phase, double G, double T, double P, double d, doub
*Pcorr = P;

//------------------------------------------------------------------------//
// printf("%d\n", materials->cstv[phase]);

// Activate deformation mechanisms
if ( materials->cstv[phase] !=0 ) constant = 1;
Expand Down Expand Up @@ -628,7 +629,7 @@ double ViscosityConcise( int phase, double G, double T, double P, double d, doub
// Check yield stress
F_trial = Tii - Tyield;

// if (F_trial>0) printf("%2.2e %2.2e %2.2e %2.2e %2.2e\n", F_trial*scaling->S, C*scaling->S, cos_fric, P*scaling->S, sin_fric);
// if (F_trial>0) printf("F=%2.2e C=%2.2e cos_fric=%2.2e P=%2.2e sin_fric=%2.2e\n", F_trial*scaling->S, C*scaling->S, cos_fric, P*scaling->S, sin_fric);

double Tiic;
double Pc_chk;
Expand Down Expand Up @@ -775,7 +776,7 @@ double ViscosityConcise( int phase, double G, double T, double P, double d, doub
if (is_pl == 1) inv_eta_diss += (1.0/eta_pl );
eta = 1.0/(inv_eta_diss);
// if (T*scaling->T<673.0) {
// printf("constant = %d %2.2e %2.2e %2.2e %2.2e\n", constant, eta*scaling->eta, eta_pwl*scaling->eta, eta_pl*scaling->eta, eta_cst*scaling->eta);
// printf("constant = %d eta = %2.2e eta_pl = %2.2e %2.2e %2.2e %2.2e\n", constant, eta*scaling->eta, eta_pl*scaling->eta, eta_pwl*scaling->eta, eta_pl*scaling->eta, eta_cst*scaling->eta);
// }

// Viscoplastic overstress
Expand Down
Loading

0 comments on commit a596fed

Please sign in to comment.