Skip to content

Commit

Permalink
Relocated some procedures
Browse files Browse the repository at this point in the history
  • Loading branch information
ericneiva committed Dec 18, 2023
1 parent e29f592 commit 26a8e8a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 74 deletions.
1 change: 1 addition & 0 deletions src/AgFEM/AgFEM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using GridapEmbedded.Interfaces: compute_subcell_to_inout

export aggregate
export color_aggregates
export aggregate_narrow_band
export AggregateAllCutCells
export compute_cell_bboxes
export compute_cell_to_dface_bboxes
Expand Down
12 changes: 12 additions & 0 deletions src/AgFEM/AggregateBoundingBoxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ function init_bboxes(cell_to_coords,cut::EmbeddedDiscretization;in_or_out=IN)
bgcell_to_cbboxes
end

function init_bboxes(cell_to_coords,cut_measure::Measure)
bgcell_to_cbboxes = init_bboxes(cell_to_coords)
quad = get_cell_quadrature(cut_measure)
trian = get_triangulation(quad)
model = get_active_model(trian)
ccell_to_bgcell = get_cell_to_parent_cell(model)
for (cc,bc) in enumerate(ccell_to_bgcell)
bgcell_to_cbboxes[bc] = compute_subcell_bbox(quad.cell_point[cc])
end
bgcell_to_cbboxes
end

function init_cut_bboxes(cut,ccell_to_bgcell,in_or_out)
subcell_to_inout = compute_subcell_to_inout(cut,cut.geo)
subcell_is_in = lazy_map(i->i==in_or_out,subcell_to_inout)
Expand Down
57 changes: 57 additions & 0 deletions src/AgFEM/CellAggregation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,60 @@ function _color_aggregates_barrier(cell_to_cellin,cell_to_faces,face_to_cells)

cell_to_color
end

# Specialised methods for Algoim quadratures

function aggregate(bgtrian,cell_to_is_active,cell_to_is_cut,in_or_out)
n_cells = length(cell_to_is_active)
@assert n_cells == length(cell_to_is_cut)

cell_to_unit_cut_meas = lazy_map(cell_to_is_active,cell_to_is_cut) do isa, isc
!isa ? 0.0 : (isc ? 0.0 : 1.0)
end

cell_to_inoutcut = lazy_map(cell_to_is_active,cell_to_is_cut) do isa, isc
!isa ? OUT : (isc ? CUT : IN)
end

cell_to_coords = get_cell_coordinates(bgtrian)
model = get_background_model(bgtrian)
topo = get_grid_topology(model)
D = num_cell_dims(model)
cell_to_faces = get_faces(topo,D,D-1)
face_to_cells = get_faces(topo,D-1,D)
# A hack follows to avoid constructing the actual facet_to_inoutcut array
facet_to_inoutcut = fill(in_or_out,num_faces(model,D-1))

threshold = 1.0
_aggregate_by_threshold_barrier(
threshold,cell_to_unit_cut_meas,facet_to_inoutcut,cell_to_inoutcut,
in_or_out,cell_to_coords,cell_to_faces,face_to_cells)
end

function aggregate_narrow_band(bgtrian,cell_to_is_in_narrow,cell_to_is_active,cell_to_is_cut,in_or_out)
n_cells = length(cell_to_is_in_narrow)
@assert n_cells == length(cell_to_is_active)
@assert n_cells == length(cell_to_is_cut)

cell_to_unit_cut_meas = lazy_map(cell_to_is_active,cell_to_is_cut) do isa, isc
( isa & !isc ) ? 1.0 : 0.0
end

cell_to_inoutcut = lazy_map(cell_to_is_in_narrow,cell_to_is_active,cell_to_is_cut) do isn, isa, isc
!isn ? OUT : ( ( isa & !isc ) ? IN : CUT )
end

cell_to_coords = get_cell_coordinates(bgtrian)
model = get_background_model(bgtrian)
topo = get_grid_topology(model)
D = num_cell_dims(model)
cell_to_faces = get_faces(topo,D,D-1)
face_to_cells = get_faces(topo,D-1,D)
# A hack follows to avoid constructing the actual facet_to_inoutcut array
facet_to_inoutcut = fill(in_or_out,num_faces(model,D-1))

threshold = 1.0
_aggregate_by_threshold_barrier(
threshold,cell_to_unit_cut_meas,facet_to_inoutcut,cell_to_inoutcut,
in_or_out,cell_to_coords,cell_to_faces,face_to_cells)
end
73 changes: 0 additions & 73 deletions src/AlgoimUtils/AlgoimUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ using Gridap.Geometry

using GridapEmbedded.Interfaces
using GridapEmbedded.Interfaces: Simplex
using GridapEmbedded.AgFEM: _aggregate_by_threshold_barrier

using MiniQhull
using FillArrays
Expand All @@ -32,15 +31,12 @@ import Algoim: CachedLevelSetGradient
import Algoim: AlgoimCallLevelSetFunction
import Algoim: normal
import Gridap.ReferenceFEs: Quadrature
import GridapEmbedded.AgFEM: aggregate

export TriangulationAndMeasure
export algoim
export Quadrature
export is_cell_active
export restrict_measure
export aggregate_narrow_band
export init_bboxes
export fill_cpp_data
export fill_cpp_data_raw
export compute_closest_point_projections
Expand Down Expand Up @@ -177,77 +173,8 @@ function TriangulationAndMeasure(Ωbg::Triangulation,quad::Tuple)
Ωᵃ,dΩᵃ,cell_to_is_active
end

function aggregate(bgtrian,cell_to_is_active,cell_to_is_cut,in_or_out)
n_cells = length(cell_to_is_active)
@assert n_cells == length(cell_to_is_cut)

cell_to_unit_cut_meas = lazy_map(cell_to_is_active,cell_to_is_cut) do isa, isc
!isa ? 0.0 : (isc ? 0.0 : 1.0)
end

cell_to_inoutcut = lazy_map(cell_to_is_active,cell_to_is_cut) do isa, isc
!isa ? OUT : (isc ? CUT : IN)
end

cell_to_coords = get_cell_coordinates(bgtrian)
model = get_background_model(bgtrian)
topo = get_grid_topology(model)
D = num_cell_dims(model)
cell_to_faces = get_faces(topo,D,D-1)
face_to_cells = get_faces(topo,D-1,D)
# A hack follows to avoid constructing the actual facet_to_inoutcut array
facet_to_inoutcut = fill(in_or_out,num_faces(model,D-1))

threshold = 1.0
_aggregate_by_threshold_barrier(
threshold,cell_to_unit_cut_meas,facet_to_inoutcut,cell_to_inoutcut,
in_or_out,cell_to_coords,cell_to_faces,face_to_cells)
end

function aggregate_narrow_band(bgtrian,cell_to_is_in_narrow,cell_to_is_active,cell_to_is_cut,in_or_out)
n_cells = length(cell_to_is_in_narrow)
@assert n_cells == length(cell_to_is_active)
@assert n_cells == length(cell_to_is_cut)

cell_to_unit_cut_meas = lazy_map(cell_to_is_active,cell_to_is_cut) do isa, isc
( isa & !isc ) ? 1.0 : 0.0
end

cell_to_inoutcut = lazy_map(cell_to_is_in_narrow,cell_to_is_active,cell_to_is_cut) do isn, isa, isc
!isn ? OUT : ( ( isa & !isc ) ? IN : CUT )
end

cell_to_coords = get_cell_coordinates(bgtrian)
model = get_background_model(bgtrian)
topo = get_grid_topology(model)
D = num_cell_dims(model)
cell_to_faces = get_faces(topo,D,D-1)
face_to_cells = get_faces(topo,D-1,D)
# A hack follows to avoid constructing the actual facet_to_inoutcut array
facet_to_inoutcut = fill(in_or_out,num_faces(model,D-1))

threshold = 1.0
_aggregate_by_threshold_barrier(
threshold,cell_to_unit_cut_meas,facet_to_inoutcut,cell_to_inoutcut,
in_or_out,cell_to_coords,cell_to_faces,face_to_cells)
end

using Gridap.Geometry: get_cell_to_parent_cell
using Gridap.CellData: get_cell_quadrature
using GridapEmbedded.AgFEM: compute_subcell_bbox
import GridapEmbedded.AgFEM: init_bboxes

function init_bboxes(cell_to_coords,cut_measure::Measure)
bgcell_to_cbboxes = init_bboxes(cell_to_coords)
quad = get_cell_quadrature(cut_measure)
trian = get_triangulation(quad)
model = get_active_model(trian)
ccell_to_bgcell = get_cell_to_parent_cell(model)
for (cc,bc) in enumerate(ccell_to_bgcell)
bgcell_to_cbboxes[bc] = compute_subcell_bbox(quad.cell_point[cc])
end
bgcell_to_cbboxes
end

function compute_closest_point_projections::Triangulation,φ;
cppdegree::Int=2,trim::Bool=false,limitstol::Float64=1.0e-8)
Expand Down
2 changes: 1 addition & 1 deletion src/Exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ end
@publish AgFEM AgFEMSpace
@publish AgFEM aggregate
@publish AgFEM color_aggregates
@publish AgFEM aggregate_narrow_band
@publish AgFEM AggregateCutCellsByThreshold
@publish AgFEM AggregateAllCutCells
@publish AgFEM compute_cell_bboxes
Expand All @@ -54,7 +55,6 @@ end
@publish AlgoimUtils AlgoimCallLevelSetFunction
@publish AlgoimUtils TriangulationAndMeasure
@publish AlgoimUtils normal
@publish AlgoimUtils init_bboxes
@publish AlgoimUtils fill_cpp_data
@publish AlgoimUtils fill_cpp_data_raw
@publish AlgoimUtils compute_closest_point_projections
Expand Down

0 comments on commit 26a8e8a

Please sign in to comment.