Skip to content

Commit

Permalink
Implemented non-performant compute_normal_displacement
Browse files Browse the repository at this point in the history
  • Loading branch information
ericneiva committed Sep 23, 2024
1 parent 5554b16 commit 3db2efc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
16 changes: 16 additions & 0 deletions src/AlgoimUtils/AlgoimUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,22 @@ function compute_normal_displacement(
disps
end

function compute_normal_displacement(
cps::AbstractArray,
phi::AlgoimCallLevelSetFunction,
fun::DistributedCellField,
dt::Float64,
Ω::DistributedTriangulation)
# TO-DO: Optimize this function such that it reuses caches
map(cps) do cp
fun_xs = evaluate(fun,cp)
nΓ_xs = evaluate(normal(phi,Ω),cp)
lazy_map(fun_xs,nΓ_xs) do fun_x,nΓ_x
dt * ( fun_x nΓ_x )
end
end
end

function compute_normal_displacement!(
cache,
cps::AbstractVector{<:Point},
Expand Down
40 changes: 15 additions & 25 deletions test/AlgoimUtilsTests/ClosestPointTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,35 @@ const CUT = 0
function run_case(distribute,parts,degree)

ranks = distribute(LinearIndices((prod(parts),)))
cells = Int32[32,32,32]
cells = Int32[4,4]

domain = (-1.1,1.1,-1.1,1.1,-1.1,1.1)
domain = (-1.1,1.1,-1.1,1.1)
bgmodel = CartesianDiscreteModel(ranks,parts,domain,cells)
Ω = Triangulation(bgmodel)

order = 2
reffeᵠ = ReferenceFE(lagrangian,Float64,order)
V = TestFESpace(Ω,reffeᵠ)

# f(x) = x[1]*x[1]+x[2]*x[2] - 0.25
f(x) = x[1]*x[1]+x[2]*x[2]+x[3]*x[3] - 0.25
f(x) = x[1]*x[1]+x[2]*x[2] - 0.25
# f(x) = x[1]*x[1]+x[2]*x[2]+x[3]*x[3] - 0.25
∇f(x) = (f)(x)
phi = AlgoimCallLevelSetFunction(f,∇f)

fₕ = compute_distance_fe_function(bgmodel,V,phi,order,cppdegree=degree)
writevtk(Ω,"distance",cellfields=["f"=>fₕ])

# coords = map(local_views(bgmodel)) do t
# _p = reduce(vcat,collect(get_node_coordinates(t)))
# [ Point(_p[i]...) for i in 1:length(_p) ]
# end
# _cpps = map(coords) do c
# [ p-f(p)*∇f(p) for p in c ]
# end
# cpps = compute_closest_point_projections(bgmodel,phi,cppdegree=degree)
# map(coords,cpps,_cpps,ranks) do c,p,_p,i
# writevtk(c,"cpps_$i",nodaldata=["f"=>f.(p),"cp1"=>p,"cp2"=>_p])
# end

# partials = map(cpps) do c
# maximum(f.(c))
# end
# maxf = reduce(max,partials,init=typemin(Float64))
# partials = map(cpps) do c
# minimum(f.(c))
# end
# minf = reduce(min,partials,init=typemax(Float64))
# @show maxf,minf
φₕ = AlgoimCallLevelSetFunction(fₕ,(fₕ))

# cp₋ = compute_closest_point_projections(V,φₕ,order)
cpps = compute_closest_point_projections(V,phi,order)
= normal(phi,Ω)
dt = 0.1

dₕ = compute_normal_displacement(cpps,phi,nΓ,dt,Ω)
map(dₕ) do d
@show d
end

end

Expand Down

0 comments on commit 3db2efc

Please sign in to comment.