Skip to content

Commit

Permalink
fix Dirichlet T mask
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat committed Dec 11, 2024
1 parent cbde08f commit a56c5e8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 33 deletions.
69 changes: 37 additions & 32 deletions miniapps/benchmarks/stokes2D/Volcano2D/Caldera2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ else
end

# Load script dependencies
using GeoParams, CairoMakie, CellArrays, Statistics, Dates
using GeoParams, GLMakie, CellArrays, Statistics, Dates

# Load file with all the rheology configurations
include("Caldera_setup.jl")
Expand Down Expand Up @@ -92,25 +92,30 @@ function extract_topo_from_GMG_phases(phases_GMG, xvi, air_phase)
return topo_y
end

function thermal_anomaly!(Temp, mask, Ω_T, phases, particles, conduit_phase, magma_phase)
function thermal_anomaly!(Temp, mask, Ω_T, phase_ratios, conduit_phase, magma_phase)

@parallel_indices (i, j) function _thermal_anomaly!(Temp, mask, Ω_T, phases, index, conduit_phase, magma_phase)
@inbounds for ip in cellaxes(phases)
#quick escape
@index(index[ip, i, j]) == 0 && continue
phase_ij = @index phases[ip, i, j]
@parallel_indices (i, j) function _thermal_anomaly!(Temp, mask, Ω_T, vertex_ratio, conduit_phase, magma_phase)
# quick escape
conduit_ratio_ij = @index vertex_ratio[conduit_phase, i, j]
magma_ratio_ij = @index vertex_ratio[magma_phase, i, j]

if phase_ij == conduit_phase || phase_ij == magma_phase
Temp[i+1, j+1] = Ω_T
mask[i+1,j+1] = 1
end
if conduit_ratio_ij > 0.5 || magma_ratio_ij > 0.5
# if isone(conduit_ratio_ij) || isone(magma_ratio_ij)
Temp[i+1, j] = Ω_T
mask[i+1, j] = 1
end

return nothing
end

ni = size(phase_ratios.vertex)

@parallel _thermal_anomaly!(Temp, mask, Ω_T, phases, particles.index, conduit_phase, magma_phase)
@parallel (@idx ni) _thermal_anomaly!(Temp, mask, Ω_T, phase_ratios.vertex, conduit_phase, magma_phase)

return nothing
end


## BEGIN OF MAIN SCRIPT --------------------------------------------------------------
function main(li, origin, phases_GMG, T_GMG, igg; nx=16, ny=16, figdir="figs2D", do_vtk =false)

Expand Down Expand Up @@ -188,7 +193,7 @@ function main(li, origin, phases_GMG, T_GMG, igg; nx=16, ny=16, figdir="figs2D",
# Add thermal anomaly BC's
Ω_T = 1223e0 # inner BCs temperature
mask = @zeros(size(thermal.T)...)
thermal_anomaly!(thermal.T, mask, Ω_T, pPhases, particles, 5, 3)
thermal_anomaly!(thermal.T, mask, Ω_T, phase_ratios, 5, 3)
thermal_bc = TemperatureBoundaryConditions(;
no_flux = (left = true, right = true, top = false, bot = false),
dirichlet = (constant = Ω_T, mask=mask)
Expand Down Expand Up @@ -549,7 +554,7 @@ do_vtk = true # set to true to generate VTK files for ParaView
# figdir = "Caldera2D_noPguess"
figdir = "$(today())_Conduit"
n = 128
nx, ny = n, n #>>> 1
nx, ny = n, n >>> 1
li, origin, phases_GMG, T_GMG = setup2D(
nx+1, ny+1;
sticky_air = 4e0,
Expand All @@ -570,21 +575,21 @@ else
igg
end

main(li, origin, phases_GMG, T_GMG, igg; figdir = figdir, nx = nx, ny = ny, do_vtk = do_vtk);

function plot_particles(particles, pPhases, chain)
p = particles.coords
# pp = [argmax(p) for p in phase_ratios.center] #if you want to plot it in a heatmap rather than scatter
ppx, ppy = p
# pxv = ustrip.(dimensionalize(ppx.data[:], km, CharDim))
# pyv = ustrip.(dimensionalize(ppy.data[:], km, CharDim))
pxv = ppx.data[:]
pyv = ppy.data[:]
clr = pPhases.data[:]
# clr = pϕ.data[:]
idxv = particles.index.data[:]
f,ax,h=scatter(Array(pxv[idxv]), Array(pyv[idxv]), color=Array(clr[idxv]), colormap=:roma, markersize=1)

Colorbar(f[1,2], h)
f
end
# main(li, origin, phases_GMG, T_GMG, igg; figdir = figdir, nx = nx, ny = ny, do_vtk = do_vtk);

# function plot_particles(particles, pPhases, chain)
# p = particles.coords
# # pp = [argmax(p) for p in phase_ratios.center] #if you want to plot it in a heatmap rather than scatter
# ppx, ppy = p
# # pxv = ustrip.(dimensionalize(ppx.data[:], km, CharDim))
# # pyv = ustrip.(dimensionalize(ppy.data[:], km, CharDim))
# pxv = ppx.data[:]
# pyv = ppy.data[:]
# clr = pPhases.data[:]
# # clr = pϕ.data[:]
# idxv = particles.index.data[:]
# f,ax,h=scatter(Array(pxv[idxv]), Array(pyv[idxv]), color=Array(clr[idxv]), colormap=:roma, markersize=1)

# Colorbar(f[1,2], h)
# f
# end
2 changes: 1 addition & 1 deletion miniapps/benchmarks/stokes2D/Volcano2D/Caldera_setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function setup2D(

ph = Phases[:,1,:]
T = Temp[:,1,:] .+ 273
V = 4/3 * π * (chamber_radius*aspect_x) * chamber_radius * 1.0
V = 4/3 * π * (chamber_radius*aspect_x) * chamber_radius * 1.0
printstyled("Magma volume of the initial chamber: $(round(V; digits=3)) km³ \n"; bold=true, color=:red)
# write_paraview(Grid, "Volcano2D")
return li, origin, ph, T, Grid
Expand Down

0 comments on commit a56c5e8

Please sign in to comment.