Skip to content

Commit

Permalink
Add stress boundary conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
tduretz committed Jul 1, 2024
1 parent 5eb610c commit f1303b2
Show file tree
Hide file tree
Showing 11 changed files with 419 additions and 658 deletions.
15 changes: 11 additions & 4 deletions JuliaVisualisation/Main_MatrixCheckSolve_MD7.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ end


function main()

solve = false
γ = 2.1e7

# File
path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB/"
filename = string(path, "Stokes_01cpu_step1429_iter00.gzip.h5")
filename = string(path, "Stokes_01cpu_step01_iter01.gzip.h5")
# path ="/Users/tduretz/REPO/MDOODZ7.0/RUNS/RiverTom/"
# filename = string(path, "Stokes_01cpu_step229_iter00.gzip.h5")
# Matrix block A
Expand Down Expand Up @@ -75,13 +74,21 @@ function main()
model = ExtractData(filename,"/model/params");
nx, nz, Δx, Δz = model

display(reshape(equ, Int64(nx), Int64(nz+1))[:,end:-1:1]')
display(reshape(eqv, Int64(nx+1), Int64(nz))[:,end:-1:1]')

# Spies
Msc = MA - MB*(MD*MC);
@show norm(MA-MA')
@show norm(MB+MC')
@show norm(Msc-Msc')
p = spy(MA-MA')
display(p)
if norm(Msc-Msc')>0
p = spy(MA-MA')
# p = spy(MA)
@show MA[11,101]
@show MA[101,11]
display(p)
end


# Solve
Expand Down
14 changes: 7 additions & 7 deletions JuliaVisualisation/Main_Visualisation_Makie_MD7.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Pkg
Pkg.activate(normpath(joinpath(@__DIR__, ".")))
using HDF5, Printf, Colors, ColorSchemes, MathTeXEngine, LinearAlgebra, FFMPEG, Statistics
using CairoMakie#, GLMakie
const Mak = CairoMakie
Mak = CairoMakie
Makie.update_theme!(fonts = (regular = texfont(), bold = texfont(:bold), italic = texfont(:italic)))

const y = 365*24*3600
Expand Down Expand Up @@ -47,7 +47,7 @@ function main()
path ="/home/larafriedrichs/repositories/MDOODZ7.0/MDLIB/"
#path=raw"C:\Users\49176\OneDrive\Desktop\Test_c_code\\"
path="/home/larafriedrichs/repositories/MDOODZ7.0/runs/firstmodel/"
#path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB/"
path ="/Users/tduretz/REPO/MDOODZ7.0/MDLIB/"

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

# File numbers
file_start = 100
file_start = 1
file_step = 10
file_end = 100
file_end = 1

# Select field to visualise
# field = :Phases
Expand All @@ -72,10 +72,10 @@ function main()
# field = :PlasticStrainrate
# field = :Stress
# field = :StrainRate
field = :Pressure
# field = :Pressure
# field = :Divergence
# field = :Temperature
# field = :Velocity_x
field = :Velocity_x
# field = :Velocity_z
# field = :Velocity
# field = :GrainSize
Expand All @@ -97,7 +97,7 @@ function main()
fabric = false, # add fabric quiver (normal to director)
topo = false,
σ1_axis = false,
vel_vec = true,
vel_vec = false,
)
α_heatmap = 1.0 #0.85 # transparency of heatmap
vel_arrow = 5
Expand Down
161 changes: 161 additions & 0 deletions JuliaVisualisation/Main_Visualisation_Makie_MD7_Residuals.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
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 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
`d`
function main()

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

# File numbers
istep = 1

# Select field to visualise
field = :Residual_x
# field = :Divergence

# Switches
printfig = false # print figures to disk
printvid = false
framerate = 3
PlotOnTop = (
ph_contours = false, # add phase contours
T_contours = true, # 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 = 500
mov_name = "$(path)/_$(field)/$(field)" # Name of the movie
Lx, Lz = 1.0, 1.0

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

Lc = 1.0
tc = My
Vc = 1.0

probe = (ϕeff = Float64.([]), t = Float64.([]))

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

name = @sprintf("Output%05d.gzip.h5", istep)
filename = string(path, name)
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")
t = model[1]
tMy = round(t/tc, digits=6)
nvx = Int(model[4])
nvz = Int(model[5])
ncx, ncz = nvx-1, nvz-1
centroids, vertices = (ncx, ncz), (nvx, nvz)

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

Vx = Float64.(reshape(ExtractData( filename, "/VxNodes/ru"), (ncx+1), (ncz+2)))
Vz = Float64.(reshape(ExtractData( filename, "/VzNodes/rv"), (ncx+2), (ncz+1)))
divu = ExtractField(filename, "/Centers/rp", centroids, false, 0)

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

if field==:Residual_x
ax1 = Axis(f[1, 1], title = L"$Vx$ at $t$ = %$(tMy) Ma", xlabel = L"$x$ [km]", ylabel = L"$y$ [km]")
hm = heatmap!(ax1, xv, zvx, Vx[:,:], colormap = (:jet, α_heatmap))#, colorrange=(0., 0.6)
colsize!(f.layout, 1, Aspect(1, Lx/Lz))
Mak.Colorbar(f[1, 2], hm, label = L"$Vx$ [cm.yr$^{-1}$]", width = 20, labelsize = 25, ticklabelsize = 14 )
# Mak.colgap!(f.layout, 20)
if printfig Print2Disk( f, path, string(field), istep) end
end

if field==:Residual_z
ax2 = Axis(f[1, 1], title = L"$Vz$ at $t$ = %$(tMy) Ma", xlabel = L"$x$ [km]", ylabel = L"$y$ [km]")
hm = heatmap!(ax2, xvz, zv, Vz, colormap = (:jet, α_heatmap))#, colorrange=(0., 0.6)
# colsize!(f.layout, 1, Aspect(1, Lx/Lz))
Mak.Colorbar(f[1, 2], hm, label = L"$Vz$ [cm.yr$^{-1}$]", width = 20, labelsize = 25, ticklabelsize = 14 )
# Mak.colgap!(f.layout, 20)
if printfig Print2Disk( f, path, string(field), istep) end
end

if field==:Divergence
ax3 = Axis(f[1, 1], title = L"∇⋅V at $t$ = %$(tMy) Ma", xlabel = L"$x$ [km]", ylabel = L"$y$ [km]")
hm = heatmap!(ax3, xc./Lc, zc./Lc, divu, colormap = (:turbo, α_heatmap))
colsize!(f.layout, 1, Aspect(1, Lx/Lz))
Mak.Colorbar(f[1, 2], hm, label = L"∇⋅V [s$^{-1}$]", width = 20, labelsize = 25, ticklabelsize = 14 )
Mak.colgap!(f.layout, 20)
if printfig Print2Disk( f, path, string(field), istep) end
end

DataInspector(f)
display(f)
sleep(nap)

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()
3 changes: 3 additions & 0 deletions MDLIB/Main_DOODZ.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,9 @@ void RunMDOODZ(char *inputFileName, MdoodzSetup *setup) {

if (input.model.writer_debug == 1 ) WriteResiduals( mesh, input.model, Nmodel, input.scaling );

// Print2DArrayChar( mesh.BCu.type, input.model.Nx, input.model.Nz+1, 1 );
// Print2DArrayDouble( mesh.ru, input.model.Nx, input.model.Nz+1, 1.0 );

// if pass --> clear matrix break
if ( (Nmodel.resx < Nmodel.nonlin_abs_mom || Nmodel.resx/Nmodel.resx0 < Nmodel.nonlin_rel_mom) && (Nmodel.resz < Nmodel.nonlin_abs_mom || Nmodel.resz/Nmodel.resz0 < Nmodel.nonlin_rel_mom) && (Nmodel.resp < Nmodel.nonlin_abs_div || Nmodel.resp/Nmodel.resp0 < Nmodel.nonlin_rel_div) ) {
printf( "Non-linear solver converged to nonlin_abs_mom = %2.2e nonlin_abs_div = %2.2e nonlin_rel_mom = %2.2e nonlin_rel_div = %2.2e\n", Nmodel.nonlin_abs_mom, Nmodel.nonlin_abs_div, Nmodel.nonlin_rel_mom, Nmodel.nonlin_rel_div );
Expand Down
5 changes: 3 additions & 2 deletions MDLIB/RheologyDensity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1712,8 +1712,9 @@ void StrainRateComponents( grid* mesh, scale scaling, params* model ) {
mesh->div_u[c0] = dvxdx + dvzdz + dvydy;

// Normal strain rates
mesh->exxd[c0] = dvxdx - 1.0/3.0*mesh->div_u[c0];
mesh->ezzd[c0] = dvzdz - 1.0/3.0*mesh->div_u[c0];
mesh->exxd[c0] = dvxdx - model->compressible*1.0/3.0*mesh->div_u[c0];
mesh->ezzd[c0] = dvzdz - model->compressible*1.0/3.0*mesh->div_u[c0];

}
}

Expand Down
4 changes: 2 additions & 2 deletions MDLIB/Solvers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,8 @@ void KillerSolver( SparseMat *matA, SparseMat *matB, SparseMat *matC, SparseM
L = cs_di_multiply( Dc, Cc );

// //----- test - in case C' != B (assume B is deficient)
// B1 = cs_di_transpose( Cc, 1);
//
// cs_di *B1 = cs_di_transpose( Cc, 1);

// // minus sign: B = -C'
// for (k=0; k<B1->nzmax; k++) B1->x[k] *= -1.0; // could be implicitly included in the next lines

Expand Down
Loading

0 comments on commit f1303b2

Please sign in to comment.