Skip to content

Commit

Permalink
merge: Merge branch 'feat/allow_multiple_line_building_strategies' in…
Browse files Browse the repository at this point in the history
…to 'main'

Allow multiple anisotropic-line-building strategies

See merge request numerics/solver/comma!44
  • Loading branch information
Riccardo Milani committed Jun 17, 2024
2 parents 5c15252 + 92edeb8 commit 806f351
Show file tree
Hide file tree
Showing 19 changed files with 766 additions and 148 deletions.
9 changes: 8 additions & 1 deletion examples/cpp/ex_aniso_lines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ constexpr comma::CoMMASeedsPoolT seed_order =
comma::CoMMASeedsPoolT::BOUNDARY_PRIORITY;
constexpr IntT sing_card = 1;
constexpr std::optional<IntT> max_cells_in_line = std::nullopt;
constexpr comma::CoMMACellCouplingT aniso_cell_coupling =
comma::CoMMACellCouplingT::MAX_WEIGHT;
constexpr bool force_line_direction = true;
constexpr IntT fc_iter = 1;
constexpr comma::CoMMANeighbourhoodT neigh =
comma::CoMMANeighbourhoodT::EXTENDED;
Expand Down Expand Up @@ -144,6 +147,8 @@ void ex_agglomerate_one_level() {
AR,
sing_card,
max_cells_in_line,
aniso_cell_coupling,
force_line_direction,
fc_iter,
neigh
);
Expand Down Expand Up @@ -188,7 +193,9 @@ void ex_agglomerate_one_level_args() {
build_lines,
odd_line_length,
aniso_thresh,
max_cells_in_line
max_cells_in_line,
aniso_cell_coupling,
force_line_direction
);

// Prepare output containers
Expand Down
6 changes: 5 additions & 1 deletion examples/scripts/comma_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import numpy as np
import numpy.typing as npt
from CoMMA import AR, Neighbourhood, SeedsPool
from CoMMA import AR, CellCoupling, Neighbourhood, SeedsPool

AR_DESCRIPTIONS = {
AR.DIAMETER_OVER_RADIUS: "Diameter over radius",
Expand All @@ -37,6 +37,10 @@
SeedsPool.BOUNDARY_POINT_INIT: "Boundary priority with point initialization", # noqa: E501
SeedsPool.NEIGHBOURHOOD_POINT_INIT: "Neighbourhood priority with point initialization", # noqa: E501
}
CELL_COUPLING_DESCRIPTIONS = {
CellCoupling.MAX_WEIGHT: "Maximum edge weight",
CellCoupling.MIN_DISTANCE: "Minimum distance between cell centers",
}


def compute_neighbourhood_wall_distance(
Expand Down
13 changes: 13 additions & 0 deletions examples/scripts/ex_aniso_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from comma_tools import (
AR_DESCRIPTIONS,
CELL_COUPLING_DESCRIPTIONS,
NEIGHBOURHOOD_DESCRIPTIONS,
SEED_ORDERING_DESCRIPTIONS,
assign_anisotropic_line_data_to_cells,
Expand Down Expand Up @@ -71,6 +72,12 @@
sing_card = 1
# Max cells in an anisotropic line
max_cells_in_line = None # Or positive number
# Anisotropic cells coupling. Choices:
# - CellCoupling.MAX_WEIGHT = max edge weight (i.e., area)
# - CellCoupling.MIN_DISTANCE = minimum distance between cell centers
aniso_cell_coupling = CoMMA.CellCoupling.MAX_WEIGHT
# Whether to force aniso lines to have a straight direction
force_line_direction = True
# Number of iterations for iterative fine-cell research algorithm
fc_iter = 1

Expand Down Expand Up @@ -103,6 +110,10 @@
print(f" * seed_ordering={SEED_ORDERING_DESCRIPTIONS[seed_order]}")
print(f" * Threshold cardinality for singular cells={sing_card}")
print(f" * Max cells in anisotropic line={max_cells_in_line}")
print(
f" * Cell coupling for aniso cells={CELL_COUPLING_DESCRIPTIONS[aniso_cell_coupling]}"
)
print(f" * Force aniso lines direction={force_line_direction}")
print(f" * Fine-cell research iterations={fc_iter}")
print(" [Output]")
renum = renumber_coarse > 1
Expand Down Expand Up @@ -189,6 +200,8 @@
AR,
sing_card,
max_cells_in_line,
aniso_cell_coupling,
force_line_direction,
fc_iter,
neigh_type,
)
Expand Down
13 changes: 13 additions & 0 deletions examples/scripts/ex_default_dualGPy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from comma_tools import (
AR_DESCRIPTIONS,
CELL_COUPLING_DESCRIPTIONS,
NEIGHBOURHOOD_DESCRIPTIONS,
SEED_ORDERING_DESCRIPTIONS,
prepare_meshio_agglomeration_data,
Expand Down Expand Up @@ -75,6 +76,12 @@
sing_card = 1
# Max cells in an anisotropic line
max_cells_in_line = None # Or positive number
# Anisotropic cells coupling. Choices:
# - CellCoupling.MAX_WEIGHT = max edge weight (i.e., area)
# - CellCoupling.MIN_DISTANCE = minimum distance between cell centers
aniso_cell_coupling = CoMMA.CellCoupling.MAX_WEIGHT
# Whether to force aniso lines to have a straight direction
force_line_direction = True
# Number of iterations for iterative fine-cell research algorithm
fc_iter = 1

Expand Down Expand Up @@ -107,6 +114,10 @@
print(f" * seed_ordering={SEED_ORDERING_DESCRIPTIONS[seed_order]}")
print(f" * Threshold cardinality for singular cells={sing_card}")
print(f" * Max cells in anisotropic line={max_cells_in_line}")
print(
f" * Cell coupling for aniso cells={CELL_COUPLING_DESCRIPTIONS[aniso_cell_coupling]}"
)
print(f" * Force aniso lines direction={force_line_direction}")
print(f" * Fine-cell research iterations={fc_iter}")
print(" [Output]")
renum = renumber_coarse > 1
Expand Down Expand Up @@ -181,6 +192,8 @@
AR,
sing_card,
max_cells_in_line,
aniso_cell_coupling,
force_line_direction,
fc_iter,
neigh_type,
)
Expand Down
13 changes: 13 additions & 0 deletions examples/scripts/ex_rae.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

from comma_tools import (
AR_DESCRIPTIONS,
CELL_COUPLING_DESCRIPTIONS,
NEIGHBOURHOOD_DESCRIPTIONS,
SEED_ORDERING_DESCRIPTIONS,
assign_anisotropic_line_data_to_cells,
Expand Down Expand Up @@ -91,6 +92,12 @@ def limit_line_length(idxs, cells, max_cells_in_line):
sing_card = 1
# Max cells in an anisotropic line
max_cells_in_line = None # Or positive number
# Anisotropic cells coupling. Choices:
# - CellCoupling.MAX_WEIGHT = max edge weight (i.e., area)
# - CellCoupling.MIN_DISTANCE = minimum distance between cell centers
aniso_cell_coupling = CoMMA.CellCoupling.MAX_WEIGHT
# Whether to force aniso lines to have a straight direction
force_line_direction = True
# Number of iterations for iterative fine-cell research algorithm
fc_iter = 1
# Number of iteration steps to perform
Expand Down Expand Up @@ -129,6 +136,10 @@ def limit_line_length(idxs, cells, max_cells_in_line):
print(f" * seed_ordering={SEED_ORDERING_DESCRIPTIONS[seed_order]}")
print(f" * Threshold cardinality for singular cells={sing_card}")
print(f" * Max cells in anisotropic line={max_cells_in_line}")
print(
f" * Cell coupling for aniso cells={CELL_COUPLING_DESCRIPTIONS[aniso_cell_coupling]}"
)
print(f" * Force aniso lines direction={force_line_direction}")
print(f" * Fine-cell research iterations={fc_iter}")
print(f" * {agglomeration_levels=}")
print(" [Output]")
Expand Down Expand Up @@ -280,6 +291,8 @@ def limit_line_length(idxs, cells, max_cells_in_line):
AR,
sing_card,
max_cells_in_line,
aniso_cell_coupling,
force_line_direction,
fc_iter,
neigh_type,
)
Expand Down
13 changes: 13 additions & 0 deletions examples/scripts/ex_read_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from comma_tools import (
AR_DESCRIPTIONS,
CELL_COUPLING_DESCRIPTIONS,
NEIGHBOURHOOD_DESCRIPTIONS,
SEED_ORDERING_DESCRIPTIONS,
prepare_meshio_agglomeration_data,
Expand Down Expand Up @@ -80,6 +81,12 @@
sing_card = 1
# Max cells in an anisotropic line
max_cells_in_line = None # Or positive number
# Anisotropic cells coupling. Choices:
# - CellCoupling.MAX_WEIGHT = max edge weight (i.e., area)
# - CellCoupling.MIN_DISTANCE = minimum distance between cell centers
aniso_cell_coupling = CoMMA.CellCoupling.MAX_WEIGHT
# Whether to force aniso lines to have a straight direction
force_line_direction = True
# Number of iterations for iterative fine-cell research algorithm
fc_iter = 1

Expand Down Expand Up @@ -116,6 +123,10 @@
print(f" * seed_ordering={SEED_ORDERING_DESCRIPTIONS[seed_order]}")
print(f" * Threshold cardinality for singular cells={sing_card}")
print(f" * Max cells in anisotropic line={max_cells_in_line}")
print(
f" * Cell coupling for aniso cells={CELL_COUPLING_DESCRIPTIONS[aniso_cell_coupling]}"
)
print(f" * Force aniso lines direction={force_line_direction}")
print(f" * Fine-cell research iterations={fc_iter}")
print(" [Output]")
renum = renumber_coarse > 1
Expand Down Expand Up @@ -190,6 +201,8 @@
AR,
sing_card,
max_cells_in_line,
aniso_cell_coupling,
force_line_direction,
fc_iter,
neigh_type,
)
Expand Down
13 changes: 13 additions & 0 deletions examples/scripts/ex_several_agglo_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from comma_tools import (
AR_DESCRIPTIONS,
CELL_COUPLING_DESCRIPTIONS,
NEIGHBOURHOOD_DESCRIPTIONS,
SEED_ORDERING_DESCRIPTIONS,
build_coarse_graph,
Expand Down Expand Up @@ -75,6 +76,12 @@
sing_card = 1
# Max cells in an anisotropic line
max_cells_in_line = None # Or positive number
# Anisotropic cells coupling. Choices:
# - CellCoupling.MAX_WEIGHT = max edge weight (i.e., area)
# - CellCoupling.MIN_DISTANCE = minimum distance between cell centers
aniso_cell_coupling = CoMMA.CellCoupling.MAX_WEIGHT
# Whether to force aniso lines to have a straight direction
force_line_direction = True
# Number of iterations for iterative fine-cell research algorithm
fc_iter = 1
agglomeration_levels = 3
Expand Down Expand Up @@ -109,6 +116,10 @@
print(f" * seed_ordering={SEED_ORDERING_DESCRIPTIONS[seed_order]}")
print(f" * Threshold cardinality for singular cells={sing_card}")
print(f" * Max cells in anisotropic line={max_cells_in_line}")
print(
f" * Cell coupling for aniso cells={CELL_COUPLING_DESCRIPTIONS[aniso_cell_coupling]}"
)
print(f" * Force aniso lines direction={force_line_direction}")
print(f" * Fine-cell research iterations={fc_iter}")
print(f" * {agglomeration_levels=}")
print(" [Output]")
Expand Down Expand Up @@ -216,6 +227,8 @@
AR,
sing_card,
max_cells_in_line,
aniso_cell_coupling,
force_line_direction,
fc_iter,
neigh_type,
)
Expand Down
2 changes: 2 additions & 0 deletions examples/scripts/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ profile = "black"
[tool.ruff]
# Same as black
line-length = 88
# Disable line too long since Black is already on
extend-ignore = ["E501"]
[tool.pytest.ini_options]
addopts = [
"--ignore=deprecated",
Expand Down
4 changes: 4 additions & 0 deletions examples/scripts/test_CoMMA.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def agglomerate_aniso_lines():
neigh_type = CoMMA.Neighbourhood.EXTENDED
sing_card = 1
max_cells_in_line = None # Or positive number
aniso_cell_coupling = CoMMA.CellCoupling.MAX_WEIGHT
force_line_direction = True
fc_iter = 1
# fmt: off
adjMatrix_row_ptr = [
Expand Down Expand Up @@ -87,6 +89,8 @@ def agglomerate_aniso_lines():
AR,
sing_card,
max_cells_in_line,
aniso_cell_coupling,
force_line_direction,
fc_iter,
neigh_type,
)
Expand Down
Loading

0 comments on commit 806f351

Please sign in to comment.