Skip to content

Commit

Permalink
Fix pythoncall issue
Browse files Browse the repository at this point in the history
  • Loading branch information
vavrines committed Jul 3, 2024
1 parent 9a171b7 commit 21f80fd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
12 changes: 6 additions & 6 deletions example/cavity_sim.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
To execute the code:
- from the main directory: mpiexecjl -n N --project=. julia example/cavity_sim.jl
- from the file directory: mpiexecjl -n N --project=.. julia cavity_sim.jl
To execute the code (assuming 16 cores are going to be used):
- from the main directory: mpiexecjl -n 16 --project=. julia example/cavity_sim.jl
- from the file directory: mpiexecjl -n 16 --project=.. julia cavity_sim.jl
"""

using KitAMR, MPI, CairoMakie
Expand Down Expand Up @@ -58,21 +58,21 @@ end
KitAMR.save_VS_final(DVM_data)
meshes = KitAMR.collect_mesh(DVM_data)
solutions = KitAMR.collect_solution(ps4est, DVM_data)
# write_result!(ps4est,DVM_data,"write_test")

if MPI.Comm_rank(MPI.COMM_WORLD) == 0
x, y = KitAMR.reshape_mesh(meshes)
f = Figure()
ax = Axis(f[1, 1])
KitAMR.mesh_plot(x, y, ax)
save("mesh.png", f)

#=x, y, variable = KitAMR.reshape_solutions(solutions, DVM_data.global_data, :prim, 4)
x, y, variable = KitAMR.reshape_solutions(solutions, DVM_data.global_data, :prim, 4)
variable = 1 ./ variable
f = Figure()
ax = Axis(f[1, 1])
co = contourf!(x, y, variable)
Colorbar(f[1, 2], co)
save("test_vs_adaptive.png", f)=#
save("test_vs_adaptive.png", f)
end

KitAMR.finalize!(ps4est, DVM_data)
Expand Down
12 changes: 8 additions & 4 deletions src/KitAMR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ using LinearAlgebra
using Parameters
using SpecialFunctions
using StaticArrays
using PythonCall

using Reexport
@reexport using P4est

using PythonCall
scipy = pyimport("scipy")
np = pyimport("numpy")

include("../lib/P4estTypes/src/P4estTypes.jl")
using .P4estTypes

Expand All @@ -39,4 +36,11 @@ include("partition.jl")
include("postprocess.jl")
include("finalize.jl")

const np = Ref{Py}()
const scipy = Ref{Py}()
function __init__()
np[] = pyimport("numpy")
scipy[] = pyimport("scipy")
end

end # module
8 changes: 4 additions & 4 deletions src/postprocess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ function reshape_solutions(
midpoints[i, :] .= solutions[i].midpoint
z[i] = getfield(solutions[i], field)[index]
end
itp = scipy.interpolate.CloughTocher2DInterpolator(midpoints, z)
itp = scipy[].interpolate.CloughTocher2DInterpolator(midpoints, z)
dx = (xmax - xmin) / Nx / 2^DVM_PS_MAXLEVEL
dy = (ymax - ymin) / Ny / 2^DVM_PS_MAXLEVEL
X = collect(xmin+EPS+dx/2:dx:xmax-EPS-dx/2)
Y = collect(ymin+EPS+dy/2:dy:ymax-EPS-dy/2)
pyZ = np.zeros((length(X), length(Y)))
pyZ = np[].zeros((length(X), length(Y)))
for i in eachindex(X)
for j in eachindex(Y)
pyZ[i-1, j-1] = itp(X[i], Y[j])[]
Expand Down Expand Up @@ -495,12 +495,12 @@ function reshape_solutions_vs(midpoint::AM, df::AM, global_data::Global_Data)
Nx, Ny = global_data.vs_trees_num
xmin, xmax, ymin, ymax = global_data.quadrature
z = @view(df[:, 1])
itp = scipy.interpolate.CloughTocher2DInterpolator(midpoint, PyArray(z))
itp = scipy[].interpolate.CloughTocher2DInterpolator(midpoint, PyArray(z))
dx = (xmax - xmin) / Nx / 2^DVM_VS_MAXLEVEL
dy = (ymax - ymin) / Ny / 2^DVM_VS_MAXLEVEL
X = collect(xmin+EPS+dx/2:dx:xmax-EPS-dx/2)
Y = collect(ymin+EPS+dy/2:dy:ymax-EPS-dy/2)
pyZ = np.zeros((length(X), length(Y)))
pyZ = np[].zeros((length(X), length(Y)))
for i in eachindex(X)
for j in eachindex(Y)
pyZ[i-1, j-1] = itp(X[i], Y[j])[]
Expand Down

0 comments on commit 21f80fd

Please sign in to comment.