Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
536 commits
Select commit Hold shift + click to select a range
869e05c
adding bottom-top strat for init
Jun 11, 2026
f0680ce
refactor projection on leaf
Jun 11, 2026
9c0e215
more docu
Jun 11, 2026
eb334f7
testing bottom-top strat
Jun 11, 2026
1d89314
changed example
Jun 11, 2026
1d25f80
simplified output
Jun 11, 2026
33361aa
fixed 3d
Jun 11, 2026
2ab7b8d
proper 3d plots
Jun 11, 2026
43f6e45
add new example with 2 states
Jun 12, 2026
3638659
added balance method
Jun 12, 2026
316ce25
declared balancing from base class
Jun 12, 2026
8d5cb52
add balance to first example
Jun 12, 2026
d50e9dd
changed floor example
Jun 12, 2026
296d145
removed refine in triangle vs. quad
Jun 12, 2026
b77dd9a
add jump heuristic in initial data
Jun 12, 2026
58e6d7a
makes directory for examples
Jun 12, 2026
da159d9
refactoring refinement/coarsening routine (similar behaviour)
Jun 12, 2026
34cf53e
adding global normalization
Jun 12, 2026
eaf248c
data are now arrays
Jun 12, 2026
3fb89e3
adding global marks
Jun 12, 2026
c3d890a
added pull_up strategy for exchange neigh leafs which are not on same…
Jun 12, 2026
8d2d416
applying pull-up strat
Jun 12, 2026
2f5746b
adding ghost exchange
Jun 12, 2026
00eca34
adding repartition
Jun 12, 2026
42df2eb
adding mpi support
Jun 12, 2026
d556bd9
fixing mpi in tests
Jun 12, 2026
21a5d94
Merge upstream/main; enable set_for_coarsening in repartition
Jun 13, 2026
c001fc6
changed level in example
Jun 13, 2026
128d064
fixed coarsening with mpi
Jun 13, 2026
0b4752e
renaming of the mst routines
Jun 13, 2026
cf050d8
static linkage for gtest
Jun 13, 2026
976bcc7
refactored contains to find in lmi-map
Jun 13, 2026
773eb01
removed dead/old code
Jun 13, 2026
378396d
removed old comments
Jun 13, 2026
e15293e
refactored levelmulttindex, reduce codedup and easier abstractions
Jun 13, 2026
d0152d4
add shape_traits for different shapes
Jun 13, 2026
9d2caae
refactored shapes using shape_traits
Jun 13, 2026
5ff7891
refactored basis with new shape traits
Jun 13, 2026
8abc778
refactored vtk plotter by abstracting shapes/order
Jun 14, 2026
30e424c
add normalization to shapes
Jun 14, 2026
e6ea68c
renamed scaling to basis_normalization
Jun 14, 2026
e9d89bd
removed dead code
Jun 14, 2026
a26310b
simplified legendre basis
Jun 14, 2026
1f97858
moved tensor_dg into dg_basis
Jun 14, 2026
80adf62
add local leaf iterator
Jun 14, 2026
b774a03
add new function to create lmi_map using a projector
Jun 14, 2026
dbbd67d
replacing forest iteration by new helper function
Jun 14, 2026
1900ed6
cleaned up the cleanup
Jun 14, 2026
7ba64fe
aadd comments on the moved in function for the projector
Jun 14, 2026
d2ad8b2
add new data structure for details
Jun 14, 2026
a2fcc2d
using new detail data structure
Jun 14, 2026
98be28c
removed dead code and using std::sqrt instead of sqrt
Jun 14, 2026
b5e97d2
defaulted and removed dead code
Jun 14, 2026
aef70d7
removed dead code
Jun 14, 2026
1709d9b
using raii for gsl quadrature
Jun 14, 2026
318eff0
constexpr them all
Jun 14, 2026
45f036f
refactored legendre_basis using points on the stack
Jun 14, 2026
0af3ea0
adding new basis class to collect all different types
Jun 14, 2026
62c1814
removed basis stuff
Jun 14, 2026
01e8492
using new basis type
Jun 14, 2026
4dc0cf6
moving/renaming basis and quadrature
Jun 14, 2026
81722fb
add unified quadrature interface
Jun 14, 2026
83f0e81
add unified quadrature interface
Jun 14, 2026
19c2a52
replace quadrature by new interface
Jun 14, 2026
614d316
created dunavant table from old data
Jun 14, 2026
de41922
refactoring dunavant rule (more readable, modern c++)
Jun 14, 2026
e8bfd23
adding dunavant table
Jun 14, 2026
c61d6c5
new dunavant interface
Jun 14, 2026
c0b8c2a
refactored dubiner scaling functions using three-term recurrence
Jun 15, 2026
a1fa7aa
optimized triangle projection
Jun 15, 2026
6623f2a
some renaming
Jun 15, 2026
90e215e
got rid of inv_mask_coeffs
Jun 15, 2026
bd1d9ef
no inv_mask_coefficient needed anymore
Jun 15, 2026
90e4ac1
removed inv_mask_coeffs
Jun 15, 2026
7630013
generating maskmatrix via basis functions
Jun 15, 2026
0912f7d
removed old interface
Jun 15, 2026
d463909
changed some comments
Jun 15, 2026
61e5c8b
fixed ordering in mat
Jun 15, 2026
81c33ea
mask_coefficients now only uses the basis of the functions
Jun 15, 2026
7528ec0
removed old hardcoded mask coeffs
Jun 15, 2026
11a91a0
using new mask coeffs
Jun 15, 2026
8eae5fa
removed old mask coeffs
Jun 15, 2026
183b6a0
removed old vec code
Jun 15, 2026
4fd9585
cleaning of old geometry functions
Jun 15, 2026
9d021a5
get rid of old stuff
Jun 15, 2026
9f264bc
using new dg_basis
Jun 15, 2026
5376015
adding gradient dg on triangles
Jun 15, 2026
55445e2
add lmi tests
Jun 16, 2026
7dcfde7
add test to cmake
Jun 16, 2026
4c59a9d
add lmi_map/set tests
Jun 16, 2026
e2f4476
add element_data tests
Jun 16, 2026
393a21c
add test fixture for num tests
Jun 16, 2026
d29e38a
testing quadrature
Jun 16, 2026
0c718c6
header...
Jun 16, 2026
1e4f72f
std lib...
Jun 16, 2026
5bcd60d
testing gradient
Jun 16, 2026
8eda4ad
testing mask matrix
Jun 16, 2026
035b98a
testing affine trafos and trafo to ref elements
Jun 16, 2026
f58b74d
header...
Jun 16, 2026
6f575a5
testing mat + lu
Jun 16, 2026
94b10f8
adding test for ref/deref on cartesian
Jun 16, 2026
1b7d39c
adding ref/deref on triangles
Jun 16, 2026
1a3c364
add tests for eval/gradient
Jun 16, 2026
4a2605e
add missing test files
Jun 16, 2026
c7154a3
more tests for more shapes
Jun 16, 2026
3413b08
fixed testss with P_DIM = 1
Jun 22, 2026
40980a1
some comments and fixed eps for numerical tests
Jun 22, 2026
d551272
adding mst tests
Jun 22, 2026
33df8a2
add mst test
Jun 22, 2026
1c2bdcb
adding configs for testing general forest with mra
Jun 22, 2026
b0cdfbb
adding class for easy tests with mra + forest
Jun 22, 2026
98ea665
adding smooth, constant and discontinuous function for testing
Jun 22, 2026
4412fe8
adding equal operator for lmi maps
Jun 22, 2026
2b6eb2a
adding frame for mra_criteria
Jun 22, 2026
ef0759b
testing local treshold values
Jun 22, 2026
bffec5c
adding function to create solution on uniform grids
Jun 22, 2026
4193a82
detail scaling tests
Jun 22, 2026
1a18f9b
different hard_thresholding strategies
Jun 22, 2026
fa8ee7d
test hartens prediction (steep => neighbour)
Jun 22, 2026
601897b
adding sharp test for hard thresholding
Jul 1, 2026
0d6e5d6
testing grading
Jul 1, 2026
c5e7170
adding mra_criteria tests
Jul 1, 2026
bea59b5
added graded function
Jul 1, 2026
00066e1
added single poly functions
Jul 1, 2026
ab59b20
adding some projection tests
Jul 1, 2026
c7837d1
adding some conservation tests
Jul 1, 2026
5d54902
adding evaluation for cartesian meshes
Jul 1, 2026
f84b0ea
added evaluation for triangular meshes
Jul 1, 2026
43f7d7d
testing evaluation
Jul 1, 2026
6e93dc2
removed clamp from old bug
Jul 1, 2026
b828068
adding reference evaluation
Jul 1, 2026
9eef444
using reference evaluation
Jul 1, 2026
ddab9e5
using reference evaluation
Jul 1, 2026
81d09c9
overriding evaluate for global evaluation in basis
Jul 1, 2026
c948dd4
adding pure virtual function for evaluate
Jul 1, 2026
217915c
adding point_query struct for global search
Jul 1, 2026
d5add99
adding search query to search for the correct cell
Jul 1, 2026
c732c48
evaluating on global domain
Jul 1, 2026
80ec037
testing global domain evaluation
Jul 1, 2026
8bb4a01
adding mean values
Jul 1, 2026
2f4b9ec
adding test for mean vals
Jul 1, 2026
c157cd6
adding gradient eval
Jul 1, 2026
83c4ae7
testing gradient eval
Jul 1, 2026
9c1a124
adding 1d test functions
Jul 1, 2026
660b866
extend tests to 1d
Jul 1, 2026
1576880
refactored detect jumps, now using the mean_val function
Jul 1, 2026
d04bf43
refactored test using the new mean_val functions
Jul 1, 2026
ca7523b
fixed tresholding, using mean_val
Jul 1, 2026
b3dbda4
adding leaf iterator
Jul 7, 2026
17175da
using iterator + some refactoring
Jul 7, 2026
0aa36dc
refactored refine
Jul 7, 2026
3eec90b
balancing using new leaf iter
Jul 7, 2026
6193d1d
fixed ghost exchange
Jul 7, 2026
e8de9ff
global v_max
Jul 7, 2026
9cbd452
refactored adapation routine with new methods
Jul 7, 2026
d1f003d
adding globalize for comm
Jul 7, 2026
9796186
renaming/comments/cleaning
Jul 7, 2026
52af15b
updated inlcudes
Jul 7, 2026
5224fd6
bug: wrong include
Jul 7, 2026
3d1b045
adding mpi tests
Jul 7, 2026
44e2e45
adding mpi tests -> testing with different num procs
Jul 7, 2026
ca76377
formatting
Jul 7, 2026
05366d0
removing old comments
Jul 7, 2026
8392c61
static idx
Jul 7, 2026
2f8bd66
using 1ULL for bitshifts
Jul 7, 2026
181abe7
removed not needed triangle order
Jul 7, 2026
f39c6ba
refactoring, using a element_vertex_coords function to give correct c…
Jul 7, 2026
3589cab
refactoring element_vertex_coords for triangle
Jul 7, 2026
9ea1062
adding some DEBUG macros on idx check
Jul 7, 2026
50856bc
removed double lookup in local_detail_nrom
Jul 7, 2026
0317d7a
reduced allocs in reference quad points
Jul 7, 2026
bfb467b
fixed test with DEBUG
Jul 7, 2026
30c3d99
devirtualized the multiscale classes -> now using CRTP
Jul 7, 2026
516991c
optimized refinement (computing norm only once)
Jul 7, 2026
a2f12bb
using std::arrays instead of std::vector in ref values
Jul 7, 2026
46c2400
reserving of I_set and d_map in mst
Jul 7, 2026
ac261b9
optimized two_scale transformation
Jul 7, 2026
2feff92
optimized inverse two scale
Jul 7, 2026
c19b83e
single lookup for lmi+data in two_scale
Jul 7, 2026
59e5bd6
refactoring coarsening, sweeps only once through level
Jul 7, 2026
48bfd4a
refactored leaf iterator, has now a second lambda function for early …
Jul 7, 2026
4bd4c69
add simple nodal to modal function
Jul 8, 2026
e4a8f1b
add new modal to nodal header
Jul 8, 2026
e615f0a
simple nodal example
Jul 8, 2026
3773b41
adding new nodal-modal file
Jul 8, 2026
a1dcbe2
adding modal to nodal interface
Jul 8, 2026
5a0118e
adding header
Jul 8, 2026
5ebebee
refactored function to give modal representation for given nodal sets
Jul 8, 2026
ca66ce2
export adaptive modal solution to nodal forest
Jul 8, 2026
d8fbb15
updated example to perform nodal->modal->coarsening->nodal
Jul 8, 2026
1c473a6
adding test_suite for modal<->nodal test
Jul 8, 2026
ed6bc9c
testing nodal->modal->nodal
Jul 8, 2026
8de24f9
testing exactness of polynomials
Jul 8, 2026
167d743
adding chebyshev-lobatto quad points
Jul 8, 2026
d949eb5
starting nodal example form a nonuniform grid
Jul 8, 2026
56e850b
adding assert for nodal/modal on triangles
Jul 8, 2026
fed194c
adding mpirank to main plot
Jul 10, 2026
04a1dfe
disabled avalanching for better performance
Jul 10, 2026
09e1b97
extracted cell geometry operations and put it in one dedicated class
Jul 10, 2026
d5c804e
removed cell operations
Jul 10, 2026
69d6019
using new cell operation class
Jul 10, 2026
1884ecf
refactored mean
Jul 10, 2026
90e1ebb
shorten comments
Jul 10, 2026
aa99c6c
adding a function to compute the mean
Jul 10, 2026
64825b2
adding fac_neighbours lmi map (inverse direction of normal lmi map)
Jul 10, 2026
2fe8816
adding face_neighbour file
Jul 10, 2026
64ee432
adding missing headers
Jul 10, 2026
b918cd3
adding new tests
Jul 10, 2026
3454a92
fixed scaling issues in the detail norm
Jul 10, 2026
91f3c27
removed some comments
Jul 23, 2026
8c93c36
refactoring: add forest_backend to collect all call to t8_forest
Jul 23, 2026
2243de7
using new backend for t8_forest
Jul 23, 2026
d95ea1f
moved cell geometry to num
Jul 23, 2026
d273d9b
updated cell geometry header
Jul 23, 2026
c7106a7
updated cell geometry header
Jul 23, 2026
f45db76
updated cell geometry header
Jul 23, 2026
ec4cf54
using cell_geometry header + added max_level as public interface
Jul 23, 2026
ecad200
fixed bug: using comm method
Jul 23, 2026
fa2ce2f
adding shape traits and separate each shape into its own file
Jul 23, 2026
457cece
refactored lmi -> each shape has its own file
Jul 23, 2026
67635fa
refactore dg with separate shape files
Jul 23, 2026
c278196
removed old shape files
Jul 23, 2026
402ed14
refactoring num with shape separations
Jul 23, 2026
c6cdf79
outsourced main functions of adapation into their own file
Jul 23, 2026
47c323f
deleted old adapation file
Jul 23, 2026
40dbafc
deleted old base file
Jul 23, 2026
62d3ec8
refactoring of multiscale module to new structure
Jul 23, 2026
30de213
adding element_corner_coords
Jul 23, 2026
5f7e094
introducing shape traits
Jul 23, 2026
9b9d4ce
updating headers
Jul 23, 2026
8f16201
updating cmake to new data structure
Jul 23, 2026
3ab4314
cleaning + clangd
Jul 24, 2026
8a9fb5d
cleaning + comments
Jul 24, 2026
81b440a
using reference in multiscale_traof
Jul 24, 2026
ff33ff1
cleaning stuff
Jul 24, 2026
90320a7
smaller cleaning stuff
Jul 24, 2026
3bc31d1
smaller cleaning
Jul 24, 2026
f22a324
small refactoring/cleaning
Jul 24, 2026
ecd0d1e
small comments improvement
Jul 24, 2026
74c5726
small cleaning
Jul 24, 2026
ae032a5
small cleaning + clangd
Jul 24, 2026
ef536bf
modernize triangle_order
Jul 24, 2026
073a8ba
small modernization using std::arrays
Jul 24, 2026
1c22259
modernized vtk + some small cleaning
Jul 24, 2026
b674dac
some small refactorings + cleaning
Jul 24, 2026
be43e84
nodiscard/cont methods/better template type names
Jul 24, 2026
1f3153d
fixed tests
Jul 24, 2026
116825a
simple dg representation for given datasets
Jul 24, 2026
991bdfc
adding dataset
Jul 24, 2026
a42c667
simple example for datasets
Jul 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/

.deps/
.libs/
.cache/

libtool
config.log
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ project(
VERSION "${T8CODE_VERSION_MAJOR}.${T8CODE_VERSION_MINOR}.${T8CODE_VERSION_PATCH}"
)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include( GNUInstallDirs)
include( CTest )
include( CMakeDependentOption )
Expand All @@ -53,6 +55,7 @@ option( T8CODE_BUILD_FORTRAN_INTERFACE "Build t8code's Fortran interface" OFF )

option( T8CODE_ENABLE_MPI "Enable t8code's features which rely on MPI" ON )
option( T8CODE_ENABLE_VTK "Enable t8code's features which rely on VTK" OFF )
option( T8CODE_ENABLE_MRA "Enable t8code's features which rely on MRA" OFF )
option( T8CODE_ENABLE_OCC "Enable t8code's features which rely on OpenCASCADE" OFF )

option( T8CODE_USE_SYSTEM_SC "Use system-installed sc library" OFF )
Expand Down Expand Up @@ -218,6 +221,13 @@ if( T8CODE_ENABLE_VTK )
endif (VTK_FOUND)
endif( T8CODE_ENABLE_VTK )

if( T8CODE_ENABLE_MRA )
find_package(GSL REQUIRED)
if(GSL_FOUND)
message("Found GSL")
endif(GSL_FOUND)
endif( T8CODE_ENABLE_MRA )

if( T8CODE_ENABLE_OCC )
find_package( OpenCASCADE REQUIRED COMPONENTS
TKBO TKPrim TKTopAlgo
Expand Down
20 changes: 18 additions & 2 deletions cmake/thirdparty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ foreach(INDEX RANGE ${DEPS_RANGE})
message(WARNING "Unknown thirdparty library type '${DEP_TYPE}' for ${DEP_NAME}")
endif()

# 3. Populate the thirdparty library
FetchContent_MakeAvailable(${DEP_NAME})
# 3. Populate the thirdparty library.
# Build googletest statically even when t8code is a shared library: a shared
# libgtest.so collides at load time with a system libgtest.so of the same
# soname but different symbols (e.g. the DLR-SC MPI fork), causing runtime
# "undefined symbol" errors. A static gtest is baked into each test binary.
if(DEP_NAME STREQUAL "googletest")
set(_t8_saved_build_shared "${BUILD_SHARED_LIBS}")
set(_t8_saved_pic "${CMAKE_POSITION_INDEPENDENT_CODE}")
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
FetchContent_MakeAvailable(${DEP_NAME})
set(BUILD_SHARED_LIBS "${_t8_saved_build_shared}")
set(CMAKE_POSITION_INDEPENDENT_CODE "${_t8_saved_pic}")
unset(_t8_saved_build_shared)
unset(_t8_saved_pic)
else()
FetchContent_MakeAvailable(${DEP_NAME})
endif()
endforeach()
10 changes: 10 additions & 0 deletions cmake/thirdparty.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
"ref": "2296a990d8b6b54731a63be0ba5bc17b08cd1f3d",
"shallow": "TRUE"
}
},
{
"name": "unordered_dense",
"depends_on_cmake_option": "",
"source": {
"type": "git",
"url": "https://github.com/martinus/unordered_dense.git",
"ref": "v4.5.0",
"shallow": "TRUE"
}
}
]
}
103 changes: 103 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,109 @@ if( T8CODE_ENABLE_OCC )
)
endif()

if( T8CODE_ENABLE_MRA )
target_compile_definitions( T8 PUBLIC T8_ENABLE_MRA )

# Add GSL library
target_link_libraries( T8 PUBLIC GSL::gsl GSL::gslcblas )

# Add unordered_dense library https://github.com/martinus/unordered_dense
# Fetched via cmake/thirdparty.json; unordered_dense_SOURCE_DIR is set by FetchContent.
set( UNORDERED_DENSE_DIR "${unordered_dense_SOURCE_DIR}/include" )

target_include_directories(T8 PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${UNORDERED_DENSE_DIR}>
$<INSTALL_INTERFACE:include>
)

target_sources( T8 PRIVATE
t8_mra/num/basis/dubiner.cxx
t8_mra/num/quadrature/dunavant.cxx
)

install( FILES
t8_mra/t8_mra.hxx
DESTINATION include/t8_mra )

install( FILES
t8_mra/core/multiscale.hxx
t8_mra/core/forest_backend.hxx
t8_mra/core/mst.hxx
t8_mra/core/shape_traits.hxx
t8_mra/core/face_neighbor.hxx
DESTINATION include/t8_mra/core )

install( FILES
t8_mra/core/shape/mst_policy.hxx
t8_mra/core/shape/cartesian.hxx
t8_mra/core/shape/triangle.hxx
DESTINATION include/t8_mra/core/shape )

install( FILES
t8_mra/core/adapt/grading.hxx
t8_mra/core/adapt/coarsen.hxx
t8_mra/core/adapt/refine.hxx
t8_mra/core/adapt/balance.hxx
DESTINATION include/t8_mra/core/adapt )

install( FILES
t8_mra/io/vtk.hxx
t8_mra/io/dataset.hxx
DESTINATION include/t8_mra/io )

install( FILES
t8_mra/dg/dg_base.hxx
t8_mra/dg/cartesian.hxx
t8_mra/dg/triangle.hxx
DESTINATION include/t8_mra/dg )

install( FILES
t8_mra/criteria/coarsening_criterion.hxx
t8_mra/criteria/refinement_criterion.hxx
DESTINATION include/t8_mra/criteria )

install( FILES
t8_mra/data/element_data.hxx
t8_mra/data/levelindex_map.hxx
t8_mra/data/levelindex_set.hxx
t8_mra/data/levelmultiindex.hxx
t8_mra/data/triangle_order.hxx
DESTINATION include/t8_mra/data )

install( FILES
t8_mra/data/shape/cartesian.hxx
t8_mra/data/shape/triangle.hxx
DESTINATION include/t8_mra/data/shape )

install( FILES
t8_mra/num/cell_geometry.hxx
t8_mra/num/dg_basis.hxx
t8_mra/num/geometry.hxx
t8_mra/num/mask_coefficients.hxx
t8_mra/num/mat.hxx
t8_mra/num/nodal_to_modal.hxx
DESTINATION include/t8_mra/num )

install( FILES
t8_mra/num/shape/cartesian.hxx
t8_mra/num/shape/triangle.hxx
DESTINATION include/t8_mra/num/shape )

install( FILES
t8_mra/num/basis/basis.hxx
t8_mra/num/basis/legendre.hxx
t8_mra/num/basis/dubiner.hxx
DESTINATION include/t8_mra/num/basis )

install( FILES
t8_mra/num/quadrature/quadrature.hxx
t8_mra/num/quadrature/gauss_legendre.hxx
t8_mra/num/quadrature/dunavant.hxx
t8_mra/num/quadrature/dunavant_table.hxx
DESTINATION include/t8_mra/num/quadrature )
endif()

if( T8CODE_BUILD_PEDANTIC )
target_compile_options( T8 PUBLIC -pedantic )
set (T8_CXXFLAGS "${T8_CXXFLAGS} -Wpedantic")
Expand Down
90 changes: 90 additions & 0 deletions src/t8_mra/core/adapt/balance.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#pragma once

#ifdef T8_ENABLE_MRA

#include <cstddef>
#include <vector>

#include "sc_mpi.h"

#include "t8.h"
#include "t8_eclass/t8_eclass.h"
#include "t8_element/t8_element.h"

#include "t8_mra/core/adapt/grading.hxx"

namespace t8_mra::adapt
{

/**
* @brief One balancing round: refine covering leaves across faces
*
* Every leaf resolves its face neighbours to their covering leaf; a covering
* leaf more than one level coarser is refined one level (children data =
* inverse two-scale with zero details, so the data is unchanged).
*
* @return Number of leaves marked in this round
*/
template <typename TMultiscale>
[[nodiscard]] unsigned int
balance_round (TMultiscale &mra)
{
clear_state (mra);

int mpirank;
int mpisize;
sc_MPI_Comm_rank (mra.grid.comm, &mpirank);
sc_MPI_Comm_size (mra.grid.comm, &mpisize);
std::vector<std::vector<size_t>> outgoing (mpisize);

mra.grid.for_each_face_neigh (
[] (const auto &lmi) { return lmi.level () >= 2; },
[&] (const auto &, t8_eclass_t tree_class, t8_gloidx_t neigh_gtreeid, t8_element_t *neigh_element,
const auto &neigh_lmi) {
if (refine_covering_leaf (mra, neigh_lmi, 0, 1u, no_prior_marks {}) < 0 && mpisize > 1) {
const auto owner = mra.grid.find_owner (neigh_gtreeid, neigh_element, tree_class);

if (owner != mpirank)
outgoing[owner].push_back (neigh_lmi.index);
}
});

if (mpisize > 1)
exchange_refine_requests (mra, outgoing, 0, 1u, no_prior_marks {});

const auto num_marked = mra.grid.global_num_marks (num_refinement_marks (mra, 0, mra.grid.maximum_level));

if (num_marked == 0) {
clear_state (mra);
return 0;
}

apply_refinement (mra, 0, mra.grid.maximum_level, 0);
clear_state (mra);

return num_marked;
}

/**
* @brief Restore the 2:1 face balance of the grid
*
* Rounds iterate until no leaf has a face neighbour more than one level coarser;
* a jump of k levels resolves in k-1 rounds. Terminates: every round refines at
* least one leaf and levels are bounded by max_level.
*/
template <typename TMultiscale>
void
balance (TMultiscale &mra)
{
auto rounds = 0;

while (balance_round (mra) > 0)
t8_debugf ("MRA balance round %d\n", rounds++);

if (rounds > 0)
mra.grid.repartition ();
}

} // namespace t8_mra::adapt

#endif // T8_ENABLE_MRA
Loading