Skip to content

Commit f9930e7

Browse files
committed
Implemented compute FE distance functions for algoim distributed fields
1 parent 3408d5d commit f9930e7

3 files changed

Lines changed: 63 additions & 30 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
Manifest.toml
99
LocalPreferences.toml
1010
.vscode/
11+
data/
1112
*.swp
1213
data

src/AlgoimUtils/AlgoimUtils.jl

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -590,8 +590,7 @@ function compute_closest_point_projections(model::OctreeDistributedDiscreteModel
590590
fgrid = vec(map(i->xmin+Point((Tuple(i).-1).*fsizes),
591591
CartesianIndices((fcells...,))))
592592
fvals = φ.(fgrid)
593-
@show length(fvals)
594-
593+
595594
# Coordinates of free DoFs on each local partition
596595
coords = interpolate_everywhere(identity,V)
597596
coords_vals = get_free_dof_values(coords)
@@ -604,14 +603,15 @@ function compute_closest_point_projections(model::OctreeDistributedDiscreteModel
604603
FEFunction(V,PVector(cpps,partition(V.gids)))
605604
end
606605

607-
function compute_closest_point_projections(model::OctreeDistributedDiscreteModel,
608-
V::DistributedFESpace,
609-
φ::DistributedAlgoimCallLevelSetFunction,
610-
order::Int,
611-
max_refinement_level::Int;
612-
cppdegree::Int=2,
613-
trim::Bool=false,
614-
limitstol::Float64=1.0e-8)
606+
function compute_closest_point_projections(
607+
model::OctreeDistributedDiscreteModel,
608+
V::DistributedFESpace,
609+
φ::DistributedAlgoimCallLevelSetFunction,
610+
order::Int,
611+
max_refinement_level::Int;
612+
cppdegree::Int=2,
613+
trim::Bool=false,
614+
limitstol::Float64=1.0e-8)
615615

616616
# Uniform partition at the maximum refinement level
617617
coarse_desc = get_cartesian_descriptor(model.coarse_model)
@@ -624,11 +624,10 @@ function compute_closest_point_projections(model::OctreeDistributedDiscreteModel
624624
# The level set values at the maximum refinement level
625625
fsizes =
626626
coarse_desc.sizes ./ ( Int32(2^max_refinement_level) * Int32(order) )
627-
fcells = fine_partition.+1
627+
fcells = fine_partition .+ 1
628628
fgrid = vec(map(i->xmin+Point((Tuple(i).-1).*fsizes),
629629
CartesianIndices((fcells...,))))
630-
631-
# This is a hack to evaluate the LS function on 2D
630+
# A hack follows to evaluate the LS function on 2D
632631
# OctreeDistributedDiscreteModels, as the current
633632
# implementation of Interpolable is not using the
634633
# NonConformingGridapTopology, so the list of cells
@@ -1127,6 +1126,34 @@ function compute_distance_fe_function(
11271126
FEFunction(fespace_scalar_type,dists)
11281127
end
11291128

1129+
function compute_distance_fe_function(
1130+
bgmodel::OctreeDistributedDiscreteModel,
1131+
fespace_scalar_type::DistributedFESpace,
1132+
fespace_vector_type::DistributedFESpace,
1133+
φ::DistributedAlgoimCallLevelSetFunction,
1134+
order::Int,
1135+
max_refinement_level::Int;
1136+
cppdegree::Int=2)
1137+
1138+
cps = compute_closest_point_projections(
1139+
bgmodel,fespace_vector_type,φ,order,
1140+
max_refinement_level,cppdegree=cppdegree)
1141+
cps_vals = get_free_dof_values(cps)
1142+
1143+
coords = interpolate_everywhere(identity,fespace_vector_type)
1144+
coords_vals = get_free_dof_values(coords)
1145+
1146+
_dists = map(local_views(fespace_scalar_type),
1147+
local_views(cps_vals),
1148+
local_views(coords_vals),
1149+
local_views(φ)) do fs,cp,cos,φl
1150+
_compute_signed_distance(φl,cp,cos,num_free_dofs(fs),
1151+
num_dims(bgmodel.coarse_model))
1152+
end
1153+
dists = PVector(_dists,partition(fespace_scalar_type.gids))
1154+
FEFunction(fespace_scalar_type,dists)
1155+
end
1156+
11301157
function compute_distance_fe_function(
11311158
fespace_scalar_type::FESpace,
11321159
fespace_vector_type::FESpace,

test/dev/cpp_dev.jl

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,32 +57,37 @@ with_mpi() do distribute
5757

5858
max_refinement_level = num_levels_initial_refinement
5959

60-
# # RMK: Algoim CPP algorithms work on uniform grids
61-
# # In order to use them on non-uniform grids, we work
62-
# # on an upper bound grid, corresponding to the uniform
63-
# # mesh obtained at maximum refinement level. On this
64-
# # maximal grid, the working arrays for the CPP are
65-
# # computed using the coordinates of the grid points
66-
# # and its level set values.
67-
# cpps = compute_closest_point_projections(
68-
# fmodel,Vₕ,φ_fun,order,max_refinement_level,cppdegree=3)
69-
# dists = compute_distance_fe_function(
70-
# fmodel,Qₕ,Vₕ,φ_fun,order,max_refinement_level,cppdegree=3)
71-
72-
# writevtk(Ω,"Ω",cellfields=["cpp"=>cpps,"dist"=>dists],nsubcells=3)
60+
# RMK: Algoim CPP algorithms work on uniform grids
61+
# In order to use them on non-uniform grids, we work
62+
# on an upper bound grid, corresponding to the uniform
63+
# mesh obtained at maximum refinement level. On this
64+
# maximal grid, the working arrays for the CPP are
65+
# computed using the coordinates of the grid points
66+
# and its level set values.
67+
cpps = compute_closest_point_projections(
68+
fmodel,Vₕ,φ_fun,order,max_refinement_level)
69+
dists = compute_distance_fe_function(
70+
fmodel,Qₕ,Vₕ,φ_fun,order,max_refinement_level)
71+
72+
writevtk(Ω,"Ω_fun",cellfields=["cpp"=>cpps,"dist"=>dists],nsubcells=3)
7373

7474
= interpolate_everywhere(val,Qₕ)
7575
φ_field = AlgoimCallLevelSetFunction(_φ,(_φ))
76-
sm = Gridap.CellData.KDTreeSearch(num_nearest_vertices=3)
76+
77+
sm = Gridap.CellData.KDTreeSearch(num_nearest_vertices=5)
7778
iφ_field = map(local_views(φ_field.values)) do
7879
Gridap.CellData.Interpolable(iφ,searchmethod=sm)
7980
end |> GridapDistributed.DistributedInterpolable
81+
8082
cpps = compute_closest_point_projections(
8183
fmodel,Vₕ,φ_field,order,max_refinement_level)
82-
writevtk(Ω,"Ω",cellfields=["cpp"=>cpps,"phi"=>iφ_fieldcpps],nsubcells=3)
84+
dists = compute_distance_fe_function(
85+
fmodel,Qₕ,Vₕ,φ_field,order,max_refinement_level)
86+
87+
writevtk(Ω,"Ω_field",cellfields=["cpp"=>cpps,"dist"=>dists,"phi"=>iφ_fieldcpps],nsubcells=1)
8388

84-
# [TODO]: Compute distance function
85-
# [TODO]: Check visualisation of cpp and distance function
89+
# [TODO]: Visualization for order >= 3 and num_subcells > 1 is strange.
90+
# This might be due to oscillations of the polynomial, but not sure.
8691

8792
true
8893
end

0 commit comments

Comments
 (0)