├── version.txt ├── tests ├── pytest.ini ├── reference │ ├── p4est │ │ └── test_simple_2d.h5 │ ├── pablo │ │ └── test_2d_bubbles.h5 │ ├── tutorial │ │ ├── test_2d_mesh.h5 │ │ ├── test_burgers_0.h5 │ │ ├── test_burgers_1.h5 │ │ ├── test_burgers_2.h5 │ │ ├── test_burgers_3.h5 │ │ ├── test_burgers_4.h5 │ │ ├── test_burgers_5.h5 │ │ ├── test_burgers_6.h5 │ │ ├── test_graduation_3_extra0.h5 │ │ ├── test_graduation_3_extra1.h5 │ │ ├── test_burgers_4_criterion-0.h5 │ │ ├── test_burgers_4_criterion-1.h5 │ │ ├── test_burgers_4_criterion-2.h5 │ │ ├── test_burgers_4_criterion-3.h5 │ │ ├── test_burgers_4_criterion-4.h5 │ │ ├── test_burgers_4_criterion-5.h5 │ │ ├── test_burgers_4_criterion-6.h5 │ │ ├── test_burgers_5_criterion-0.h5 │ │ ├── test_burgers_5_criterion-1.h5 │ │ ├── test_burgers_5_criterion-2.h5 │ │ ├── test_burgers_5_criterion-3.h5 │ │ ├── test_burgers_5_criterion-4.h5 │ │ ├── test_burgers_5_criterion-5.h5 │ │ ├── test_burgers_5_criterion-6.h5 │ │ ├── test_reconstruction_extra0-tutorial-reconstruction-1d.h5 │ │ ├── test_reconstruction_extra0-tutorial-reconstruction-2d.h5 │ │ ├── test_reconstruction_extra0-tutorial-reconstruction-3d.h5 │ │ ├── test_reconstruction_extra1-tutorial-reconstruction-1d.h5 │ │ ├── test_reconstruction_extra1-tutorial-reconstruction-2d.h5 │ │ ├── test_reconstruction_extra1-tutorial-reconstruction-3d.h5 │ │ ├── test_reconstruction_extra2-tutorial-reconstruction-1d.h5 │ │ ├── test_reconstruction_extra2-tutorial-reconstruction-2d.h5 │ │ └── test_reconstruction_extra2-tutorial-reconstruction-3d.h5 │ └── finite_volume │ │ ├── test_finite_volume_demo_burgers.h5 │ │ ├── test_finite_volume_demo_heat_explicit.h5 │ │ ├── test_finite_volume_demo_heat_implicit.h5 │ │ ├── test_finite_volume_demo_mra_burgers_hat.h5 │ │ ├── test_finite_volume_demo_lid_driven_cavity.h5 │ │ ├── test_finite_volume_demo_stokes_stationary.h5 │ │ ├── test_finite_volume_demo_mra_burgers_hat_mlf.h5 │ │ ├── test_finite_volume_demo_stokes_nonstationary.h5 │ │ ├── test_finite_volume_demo_mra_burgers_hat_recons.h5 │ │ ├── test_finite_volume_demo_nagumo_exp_diff_exp_react.h5 │ │ ├── test_finite_volume_demo_nagumo_exp_diff_imp_react.h5 │ │ ├── test_finite_volume_demo_nagumo_imp_diff_exp_react.h5 │ │ ├── test_finite_volume_demo_nagumo_imp_diff_imp_react.h5 │ │ ├── test_finite_volume_demo_finite-volume-level-set-0.1.h5 │ │ ├── test_finite_volume_demo_heat_heterogeneous_explicit.h5 │ │ ├── test_finite_volume_demo_heat_heterogeneous_implicit.h5 │ │ ├── test_finite_volume_demo_linear_convection_explicit.h5 │ │ ├── test_finite_volume_demo_linear_convection_implicit.h5 │ │ ├── test_finite_volume_demo_mra_burgers_hat_mlf_recons.h5 │ │ ├── test_finite_volume_demo_obstacle_linear_convection.h5 │ │ ├── test_finite_volume_demo_finite-volume-advection-1d-0.1.h5 │ │ ├── test_finite_volume_demo_finite-volume-advection-2d-0.01.h5 │ │ ├── test_finite_volume_demo_finite-volume-amr-burgers-hat-1.h5 │ │ ├── test_finite_volume_demo_finite-volume-advection-1d-0.1_init.h5 │ │ ├── test_finite_volume_demo_finite-volume-advection-2d-0.01_init.h5 │ │ ├── test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.h5 │ │ ├── test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5 │ │ ├── test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.h5 │ │ ├── test_finite_volume_demo_lid_driven_cavity.xdmf │ │ ├── test_finite_volume_demo_mra_burgers_hat_recons.xdmf │ │ ├── test_finite_volume_demo_mra_burgers_hat_mlf_recons.xdmf │ │ ├── test_finite_volume_demo_heat_explicit.xdmf │ │ ├── test_finite_volume_demo_heat_implicit.xdmf │ │ ├── test_finite_volume_demo_mra_burgers_hat.xdmf │ │ ├── test_finite_volume_demo_mra_burgers_hat_mlf.xdmf │ │ ├── test_finite_volume_demo_linear_convection_explicit.xdmf │ │ ├── test_finite_volume_demo_stokes_stationary.xdmf │ │ ├── test_finite_volume_demo_nagumo_exp_diff_exp_react.xdmf │ │ ├── test_finite_volume_demo_nagumo_exp_diff_imp_react.xdmf │ │ ├── test_finite_volume_demo_nagumo_imp_diff_exp_react.xdmf │ │ ├── test_finite_volume_demo_nagumo_imp_diff_imp_react.xdmf │ │ ├── test_finite_volume_demo_stokes_nonstationary.xdmf │ │ ├── test_finite_volume_demo_linear_convection_implicit.xdmf │ │ ├── test_finite_volume_demo_obstacle_linear_convection.xdmf │ │ ├── test_finite_volume_demo_heat_heterogeneous_explicit.xdmf │ │ ├── test_finite_volume_demo_heat_heterogeneous_implicit.xdmf │ │ ├── test_finite_volume_demo_finite-volume-advection-1d-0.1.xdmf │ │ ├── test_finite_volume_demo_finite-volume-amr-burgers-hat-1.xdmf │ │ ├── test_finite_volume_demo_finite-volume-advection-2d-0.01.xdmf │ │ ├── test_finite_volume_demo_finite-volume-advection-1d-0.1_init.xdmf │ │ ├── test_finite_volume_demo_finite-volume-advection-2d-0.01_init.xdmf │ │ ├── test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.xdmf │ │ ├── test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.xdmf │ │ ├── test_finite_volume_demo_burgers.xdmf │ │ ├── test_finite_volume_demo_finite-volume-level-set-0.1.xdmf │ │ └── test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.xdmf ├── test_cell_list.cpp ├── main.cpp ├── test_level_cell_list.cpp ├── test_demo_p4est.py ├── test_demo_pablo.py ├── test_common.hpp ├── copyGTest.cmake.in ├── downloadGTest.cmake.in ├── test_utils.cpp ├── test_graduation.cpp ├── test_cell.cpp ├── test_domain_with_hole.cpp ├── test_stencil.cpp ├── test_find.cpp ├── test_adapt.cpp └── CMakeLists.txt ├── .release-please-manifest.json ├── benchmark ├── main.cpp └── CMakeLists.txt ├── docs ├── source │ ├── logo │ │ ├── logo.png │ │ ├── dark_logo.png │ │ ├── light_logo.png │ │ └── samurai_logo.png │ ├── LBM │ │ └── figures │ │ │ ├── D1Q2.pdf │ │ │ ├── D1Q2.png │ │ │ ├── D1Q5.pdf │ │ │ ├── D1Q5.png │ │ │ ├── D2Q9.png │ │ │ ├── D1Q222.pdf │ │ │ ├── D1Q222.png │ │ │ ├── D2Q4444.png │ │ │ ├── D2Q5444_Rayleigh_Taylor.png │ │ │ └── D2Q5444_Rayleigh_Taylor_cropped.png │ ├── _static │ │ ├── dark_logo.png │ │ ├── light_logo.png │ │ └── css │ │ │ └── custom.css │ ├── api │ │ ├── algorithm.rst │ │ ├── bc.rst │ │ ├── box.rst │ │ ├── cell.rst │ │ ├── interval.rst │ │ ├── index.rst │ │ └── subset.rst │ ├── tutorial │ │ ├── figures │ │ │ ├── 2D_mesh.png │ │ │ ├── interval.png │ │ │ ├── level_set.png │ │ │ ├── segments.png │ │ │ ├── subset_op.png │ │ │ ├── 2D_mesh_box.png │ │ │ ├── interval-2.png │ │ │ ├── interval-3.png │ │ │ ├── subset_op_proj.png │ │ │ ├── 2D_mesh_numbering.png │ │ │ ├── interval_example_1D.png │ │ │ ├── segments-resolution.png │ │ │ ├── graduation_case_1_after.png │ │ │ ├── graduation_case_1_before.png │ │ │ ├── graduation_case_2_after.png │ │ │ ├── graduation_case_2_before.png │ │ │ ├── interval_example_1D_field.png │ │ │ ├── segments-resolution-overlap.png │ │ │ ├── graduation_case_2_after_graduated.png │ │ │ ├── graduation_case_3_with_graduation.png │ │ │ ├── graduation_case_3_without_graduation.png │ │ │ └── subset_op.drawio │ │ ├── index.rst │ │ ├── snippet │ │ │ ├── interval_output.txt │ │ │ ├── 2d_mesh_box_output.txt │ │ │ ├── 2d_mesh_box.cpp │ │ │ ├── interval.cpp │ │ │ ├── 2d_mesh_representation_output.txt │ │ │ └── 2d_mesh_representation.cpp │ │ └── graduation.rst │ ├── reference │ │ ├── figures │ │ │ ├── subset_1d.png │ │ │ ├── subset_level.png │ │ │ ├── subset_1d_proj.png │ │ │ ├── interval_example_1D.jpg │ │ │ ├── subset_algorithm-init.png │ │ │ ├── subset_algorithm-step1.png │ │ │ ├── subset_algorithm-step2.png │ │ │ ├── subset_algorithm-step3.png │ │ │ ├── subset_algorithm-step4.png │ │ │ ├── subset_level.drawio │ │ │ └── subset_1d.drawio │ │ ├── index.rst │ │ └── snippet │ │ │ ├── subset_1d_output.txt │ │ │ └── subset_1d.cpp │ ├── howto │ │ ├── snippet │ │ │ ├── cmake │ │ │ │ ├── main.cpp │ │ │ │ └── CMakeLists.txt │ │ │ ├── box │ │ │ │ ├── 2d_box.cpp │ │ │ │ ├── 3d_box.cpp │ │ │ │ └── 2d_box_with_hole.cpp │ │ │ ├── options │ │ │ │ ├── predefined_options.cpp │ │ │ │ └── custom_options.cpp │ │ │ ├── CMakeLists.txt │ │ │ ├── mesh │ │ │ │ ├── mrmesh.cpp │ │ │ │ ├── amrmesh.cpp │ │ │ │ └── uniform.cpp │ │ │ ├── field │ │ │ │ ├── scalar_field.cpp │ │ │ │ └── vector_field.cpp │ │ │ ├── save │ │ │ │ ├── save_mesh.cpp │ │ │ │ ├── save_field.cpp │ │ │ │ ├── save_all_submeshes.cpp │ │ │ │ └── dump_mesh.cpp │ │ │ ├── loop │ │ │ │ ├── for_each_cell_mesh.cpp │ │ │ │ ├── for_each_interval_mesh.cpp │ │ │ │ ├── for_each_cell_field.cpp │ │ │ │ └── for_each_interval_field.cpp │ │ │ └── timers │ │ │ │ └── custom_timer.cpp │ │ ├── index.rst │ │ ├── cmake.md │ │ ├── timers.md │ │ ├── options.md │ │ ├── box.md │ │ └── field.md │ └── philosophy.rst ├── environment.yml ├── Doxyfile ├── Makefile ├── make.bat └── CONTRIBUTING.md ├── .cppcheck ├── demos ├── p4est │ └── CMakeLists.txt ├── pablo │ └── CMakeLists.txt ├── tutorial │ ├── AMR_1D_Burgers │ │ ├── step_0 │ │ │ ├── CMakeLists.txt │ │ │ └── main.cpp │ │ ├── step_1 │ │ │ ├── CMakeLists.txt │ │ │ ├── init_sol.hpp │ │ │ └── main.cpp │ │ ├── step_2 │ │ │ ├── CMakeLists.txt │ │ │ └── update_sol.hpp │ │ ├── step_3 │ │ │ ├── CMakeLists.txt │ │ │ ├── update_sol.hpp │ │ │ └── init_sol.hpp │ │ ├── step_4 │ │ │ └── CMakeLists.txt │ │ ├── step_5 │ │ │ └── CMakeLists.txt │ │ ├── step_6 │ │ │ ├── CMakeLists.txt │ │ │ └── update_sol.hpp │ │ └── CMakeLists.txt │ ├── interval.cpp │ ├── CMakeLists.txt │ └── 2D_mesh.cpp ├── FiniteVolume │ └── BZ │ │ ├── RockAndRadau │ │ ├── CMakeLists.txt │ │ └── Makefile │ │ └── CMakeLists.txt ├── CMakeLists.txt ├── highorder │ └── CMakeLists.txt ├── multigrid │ ├── CMakeLists.txt │ └── samurai_new │ │ ├── utils.cpp │ │ └── multigrid │ │ ├── coarsening.hpp │ │ └── LevelCtx.hpp ├── from_obj │ ├── CMakeLists.txt │ └── main.cpp ├── Weno │ └── CMakeLists.txt └── LBM │ └── CMakeLists.txt ├── include └── samurai │ ├── storage │ ├── containers.hpp │ ├── layout_config.hpp │ └── utils.hpp │ ├── bc.hpp │ ├── cell_flag.hpp │ ├── schemes │ ├── fv │ │ ├── operators │ │ │ ├── flux_divergence.hpp │ │ │ ├── identity.hpp │ │ │ └── zero_operator.hpp │ │ ├── utils.hpp │ │ ├── explicit_operator_sum.hpp │ │ ├── flux_based │ │ │ └── flux_based_scheme.hpp │ │ └── cell_based │ │ │ └── cell_based_scheme.hpp │ ├── explicit_scheme.hpp │ └── fv.hpp │ ├── petsc.hpp │ ├── subset │ └── concepts.hpp │ ├── samurai_config.hpp │ ├── mesh_interval.hpp │ ├── bc │ └── neumann.hpp │ ├── mr │ └── config.hpp │ ├── assert_log_trace.hpp │ ├── petsc │ ├── manual_assembly.hpp │ └── zero_block_assembly.hpp │ └── memory.hpp ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── new_features.yml │ └── question.yml ├── workflows │ ├── check-pr-title.yml │ └── release-please.yml └── PULL_REQUEST_TEMPLATE.md ├── .readthedocs.yml ├── conda ├── environment.yml └── mpi-environment.yml ├── release-please-config.json ├── cmake ├── addGoogleTest.cmake ├── addGoogleBench.cmake ├── addRapidCheck.cmake └── samuraiConfig.cmake.in ├── vcpkg.json ├── AUTHORS.txt ├── .pre-commit-config.yaml ├── .clang-tidy ├── .clang-format ├── conanfile.py └── LICENSE /version.txt: -------------------------------------------------------------------------------- 1 | 0.27.1 2 | -------------------------------------------------------------------------------- /tests/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | markers = 3 | h5diff 4 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | ".": "0.27.1" 3 | } 4 | -------------------------------------------------------------------------------- /benchmark/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | BENCHMARK_MAIN(); 4 | -------------------------------------------------------------------------------- /docs/source/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/logo/logo.png -------------------------------------------------------------------------------- /.cppcheck: -------------------------------------------------------------------------------- 1 | noExplicitConstructor 2 | duplInheritedMember 3 | missingIncludeSystem 4 | knownConditionTrueFalse 5 | -------------------------------------------------------------------------------- /docs/source/logo/dark_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/logo/dark_logo.png -------------------------------------------------------------------------------- /docs/source/LBM/figures/D1Q2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D1Q2.pdf -------------------------------------------------------------------------------- /docs/source/LBM/figures/D1Q2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D1Q2.png -------------------------------------------------------------------------------- /docs/source/LBM/figures/D1Q5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D1Q5.pdf -------------------------------------------------------------------------------- /docs/source/LBM/figures/D1Q5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D1Q5.png -------------------------------------------------------------------------------- /docs/source/LBM/figures/D2Q9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D2Q9.png -------------------------------------------------------------------------------- /docs/source/logo/light_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/logo/light_logo.png -------------------------------------------------------------------------------- /docs/source/LBM/figures/D1Q222.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D1Q222.pdf -------------------------------------------------------------------------------- /docs/source/LBM/figures/D1Q222.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D1Q222.png -------------------------------------------------------------------------------- /docs/source/LBM/figures/D2Q4444.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D2Q4444.png -------------------------------------------------------------------------------- /docs/source/_static/dark_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/_static/dark_logo.png -------------------------------------------------------------------------------- /docs/source/_static/light_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/_static/light_logo.png -------------------------------------------------------------------------------- /docs/source/api/algorithm.rst: -------------------------------------------------------------------------------- 1 | Algorithm 2 | ========= 3 | 4 | .. doxygenfile:: algorithm.hpp 5 | :project: samurai 6 | -------------------------------------------------------------------------------- /docs/source/logo/samurai_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/logo/samurai_logo.png -------------------------------------------------------------------------------- /demos/p4est/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(p4est-simple-2d simple_2d.cpp) 2 | target_link_libraries(p4est-simple-2d samurai) 3 | -------------------------------------------------------------------------------- /demos/pablo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(pablo-bubble-2d bubble_2d.cpp) 2 | target_link_libraries(pablo-bubble-2d samurai) 3 | -------------------------------------------------------------------------------- /docs/source/api/bc.rst: -------------------------------------------------------------------------------- 1 | Boundary condition 2 | =================== 3 | 4 | .. doxygenfile:: bc.hpp 5 | :project: samurai 6 | -------------------------------------------------------------------------------- /docs/source/api/box.rst: -------------------------------------------------------------------------------- 1 | Box class 2 | ========= 3 | 4 | .. doxygenclass:: samurai::Box 5 | :project: samurai 6 | :members: 7 | -------------------------------------------------------------------------------- /docs/source/tutorial/figures/2D_mesh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/2D_mesh.png -------------------------------------------------------------------------------- /tests/reference/p4est/test_simple_2d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/p4est/test_simple_2d.h5 -------------------------------------------------------------------------------- /tests/reference/pablo/test_2d_bubbles.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/pablo/test_2d_bubbles.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_2d_mesh.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_2d_mesh.h5 -------------------------------------------------------------------------------- /docs/source/api/cell.rst: -------------------------------------------------------------------------------- 1 | Cell class 2 | ========== 3 | 4 | .. doxygenclass:: samurai::Cell 5 | :project: samurai 6 | :members: 7 | -------------------------------------------------------------------------------- /docs/source/tutorial/figures/interval.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/interval.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/level_set.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/level_set.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/segments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/segments.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/subset_op.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/subset_op.png -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_0.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_0.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_1.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_2.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_2.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_3.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_3.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_6.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_6.h5 -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_1d.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_1d.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/2D_mesh_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/2D_mesh_box.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/interval-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/interval-2.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/interval-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/interval-3.png -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_level.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/subset_op_proj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/subset_op_proj.png -------------------------------------------------------------------------------- /docs/source/api/interval.rst: -------------------------------------------------------------------------------- 1 | Interval class 2 | ============== 3 | 4 | .. doxygenclass:: samurai::Interval 5 | :project: samurai 6 | :members: 7 | -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_1d_proj.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_1d_proj.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/2D_mesh_numbering.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/2D_mesh_numbering.png -------------------------------------------------------------------------------- /docs/source/LBM/figures/D2Q5444_Rayleigh_Taylor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D2Q5444_Rayleigh_Taylor.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/interval_example_1D.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/interval_example_1D.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/segments-resolution.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/segments-resolution.png -------------------------------------------------------------------------------- /tests/reference/tutorial/test_graduation_3_extra0.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_graduation_3_extra0.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_graduation_3_extra1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_graduation_3_extra1.h5 -------------------------------------------------------------------------------- /docs/source/reference/figures/interval_example_1D.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/interval_example_1D.jpg -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_algorithm-init.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_algorithm-init.png -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4_criterion-0.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4_criterion-0.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4_criterion-1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4_criterion-1.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4_criterion-2.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4_criterion-2.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4_criterion-3.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4_criterion-3.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4_criterion-4.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4_criterion-4.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4_criterion-5.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4_criterion-5.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_4_criterion-6.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_4_criterion-6.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5_criterion-0.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5_criterion-0.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5_criterion-1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5_criterion-1.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5_criterion-2.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5_criterion-2.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5_criterion-3.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5_criterion-3.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5_criterion-4.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5_criterion-4.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5_criterion-5.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5_criterion-5.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_burgers_5_criterion-6.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_burgers_5_criterion-6.h5 -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_algorithm-step1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_algorithm-step1.png -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_algorithm-step2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_algorithm-step2.png -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_algorithm-step3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_algorithm-step3.png -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_algorithm-step4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/reference/figures/subset_algorithm-step4.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/graduation_case_1_after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/graduation_case_1_after.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/graduation_case_1_before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/graduation_case_1_before.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/graduation_case_2_after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/graduation_case_2_after.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/graduation_case_2_before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/graduation_case_2_before.png -------------------------------------------------------------------------------- /docs/source/LBM/figures/D2Q5444_Rayleigh_Taylor_cropped.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/LBM/figures/D2Q5444_Rayleigh_Taylor_cropped.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/interval_example_1D_field.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/interval_example_1D_field.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/segments-resolution-overlap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/segments-resolution-overlap.png -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_burgers.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_burgers.h5 -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_0/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tutorial-burgers1d-step-0 main.cpp) 2 | target_link_libraries(tutorial-burgers1d-step-0 PRIVATE samurai CLI11::CLI11) 3 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tutorial-burgers1d-step-1 main.cpp) 2 | target_link_libraries(tutorial-burgers1d-step-1 PRIVATE samurai CLI11::CLI11) 3 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tutorial-burgers1d-step-2 main.cpp) 2 | target_link_libraries(tutorial-burgers1d-step-2 PRIVATE samurai CLI11::CLI11) 3 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_3/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tutorial-burgers1d-step-3 main.cpp) 2 | target_link_libraries(tutorial-burgers1d-step-3 PRIVATE samurai CLI11::CLI11) 3 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tutorial-burgers1d-step-4 main.cpp) 2 | target_link_libraries(tutorial-burgers1d-step-4 PRIVATE samurai CLI11::CLI11) 3 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_5/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tutorial-burgers1d-step-5 main.cpp) 2 | target_link_libraries(tutorial-burgers1d-step-5 PRIVATE samurai CLI11::CLI11) 3 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_6/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(tutorial-burgers1d-step-6 main.cpp) 2 | target_link_libraries(tutorial-burgers1d-step-6 PRIVATE samurai CLI11::CLI11) 3 | -------------------------------------------------------------------------------- /docs/source/tutorial/figures/graduation_case_2_after_graduated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/graduation_case_2_after_graduated.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/graduation_case_3_with_graduation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/graduation_case_3_with_graduation.png -------------------------------------------------------------------------------- /docs/source/tutorial/figures/graduation_case_3_without_graduation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/docs/source/tutorial/figures/graduation_case_3_without_graduation.png -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_explicit.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_heat_explicit.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_implicit.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_heat_implicit.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_lid_driven_cavity.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_lid_driven_cavity.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_stokes_stationary.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_stokes_stationary.h5 -------------------------------------------------------------------------------- /include/samurai/storage/containers.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include "collapsable_linear_algebra.hpp" 7 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_mlf.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_mlf.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_stokes_nonstationary.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_stokes_nonstationary.h5 -------------------------------------------------------------------------------- /docs/source/api/index.rst: -------------------------------------------------------------------------------- 1 | API 2 | === 3 | 4 | .. toctree:: 5 | :caption: API reference 6 | :maxdepth: 1 7 | 8 | algorithm 9 | interval 10 | bc 11 | box 12 | cell 13 | subset 14 | -------------------------------------------------------------------------------- /docs/source/api/subset.rst: -------------------------------------------------------------------------------- 1 | Define a subset of intervals 2 | ============================ 3 | 4 | .. doxygenclass:: samurai::subset_operator 5 | :project: samurai 6 | :members: 7 | :private-members: 8 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_recons.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_recons.h5 -------------------------------------------------------------------------------- /docs/environment.yml: -------------------------------------------------------------------------------- 1 | name: samurai-doc 2 | 3 | channels: 4 | - conda-forge 5 | 6 | dependencies: 7 | - breathe 8 | - doxygen 9 | - pydata-sphinx-theme 10 | - python=3.11 11 | - myst-parser 12 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_exp_diff_exp_react.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_nagumo_exp_diff_exp_react.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_exp_diff_imp_react.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_nagumo_exp_diff_imp_react.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_imp_diff_exp_react.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_nagumo_imp_diff_exp_react.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_imp_diff_imp_react.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_nagumo_imp_diff_imp_react.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra0-tutorial-reconstruction-1d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra0-tutorial-reconstruction-1d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra0-tutorial-reconstruction-2d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra0-tutorial-reconstruction-2d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra0-tutorial-reconstruction-3d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra0-tutorial-reconstruction-3d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra1-tutorial-reconstruction-1d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra1-tutorial-reconstruction-1d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra1-tutorial-reconstruction-2d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra1-tutorial-reconstruction-2d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra1-tutorial-reconstruction-3d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra1-tutorial-reconstruction-3d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra2-tutorial-reconstruction-1d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra2-tutorial-reconstruction-1d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra2-tutorial-reconstruction-2d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra2-tutorial-reconstruction-2d.h5 -------------------------------------------------------------------------------- /tests/reference/tutorial/test_reconstruction_extra2-tutorial-reconstruction-3d.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/tutorial/test_reconstruction_extra2-tutorial-reconstruction-3d.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-level-set-0.1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-level-set-0.1.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_heterogeneous_explicit.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_heat_heterogeneous_explicit.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_heterogeneous_implicit.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_heat_heterogeneous_implicit.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_linear_convection_explicit.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_linear_convection_explicit.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_linear_convection_implicit.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_linear_convection_implicit.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_mlf_recons.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_mlf_recons.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_obstacle_linear_convection.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_obstacle_linear_convection.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-1d-0.1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-1d-0.1.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-2d-0.01.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-2d-0.01.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-amr-burgers-hat-1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-amr-burgers-hat-1.h5 -------------------------------------------------------------------------------- /docs/source/howto/snippet/cmake/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char* argv[]) 4 | { 5 | samurai::initialize("MySamuraiProject", argc, argv); 6 | samurai::finalize(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-1d-0.1_init.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-1d-0.1_init.h5 -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Samurai Community Support 4 | url: https://github.com/hpc-maths/samurai/discussions 5 | about: Please ask and answer questions here. 6 | -------------------------------------------------------------------------------- /include/samurai/bc.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include "bc/apply_field_bc.hpp" 7 | #include "bc/dirichlet.hpp" 8 | #include "bc/neumann.hpp" 9 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-2d-0.01_init.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-2d-0.01_init.h5 -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.h5 -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(step_0) 2 | add_subdirectory(step_1) 3 | add_subdirectory(step_2) 4 | add_subdirectory(step_3) 5 | add_subdirectory(step_4) 6 | add_subdirectory(step_5) 7 | add_subdirectory(step_6) 8 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5 -------------------------------------------------------------------------------- /docs/source/howto/snippet/box/2d_box.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | static constexpr std::size_t dim = 2; 6 | 7 | samurai::Box box({-1.0, -1.0}, {1.0, 1.0}); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hpc-maths/samurai/HEAD/tests/reference/finite_volume/test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.h5 -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: "ubuntu-20.04" 5 | tools: 6 | python: "mambaforge-22.9" 7 | 8 | sphinx: 9 | configuration: docs/source/conf.py 10 | 11 | conda: 12 | environment: docs/environment.yml 13 | -------------------------------------------------------------------------------- /conda/environment.yml: -------------------------------------------------------------------------------- 1 | name: samurai-env 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - cmake 6 | - ninja 7 | - xtensor>0.25 8 | - highfive>=3.0 9 | - fmt 10 | - pugixml 11 | - cli11<2.5 12 | - pytest 13 | - h5py 14 | -------------------------------------------------------------------------------- /demos/FiniteVolume/BZ/RockAndRadau/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | enable_language (C Fortran) 2 | 3 | set(RADAU_SRC 4 | decsol.f 5 | dc_decsol.f 6 | integration_stiff.c 7 | radau5.f 8 | rock4.f 9 | ) 10 | add_library(radau ${RADAU_SRC}) 11 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/box/3d_box.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | static constexpr std::size_t dim = 3; 6 | 7 | samurai::Box box({0.0, 0.0, 0.0}, {1.0, 1.0, 1.0}); 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/options/predefined_options.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char** argv) 4 | { 5 | samurai::initialize("Simple example", argc, argv); 6 | 7 | samurai::finalize(); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/cmake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(MySamuraiProject) 3 | 4 | find_package(samurai REQUIRED) 5 | 6 | add_executable(my_executable main.cpp) 7 | target_link_libraries(my_executable PRIVATE samurai::samurai) 8 | -------------------------------------------------------------------------------- /release-please-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "release-type": "simple", 3 | "include-component-in-tag": false, 4 | "include-v-in-tag": true, 5 | "changelog-path": "CHANGELOG.md", 6 | "versioning-strategy": "always-bump-minor", 7 | "bump-minor-pre-major": true 8 | } 9 | -------------------------------------------------------------------------------- /tests/test_cell_list.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | namespace samurai 6 | { 7 | TEST(cell_list, constructor) 8 | { 9 | constexpr size_t dim = 2; 10 | 11 | CellList cell_list; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /docs/source/_static/css/custom.css: -------------------------------------------------------------------------------- 1 | p { 2 | text-align: justify; 3 | } 4 | 5 | .bd-main .bd-content .bd-article-container { 6 | max-width: 100%; 7 | /* default is 60em */ 8 | } 9 | 10 | .bd-page-width { 11 | max-width: 100%; 12 | /* default is 88rem */ 13 | } 14 | -------------------------------------------------------------------------------- /docs/source/tutorial/index.rst: -------------------------------------------------------------------------------- 1 | Tutorials 2 | ========= 3 | 4 | .. toctree:: 5 | :caption: Tutorial 6 | :maxdepth: 1 7 | 8 | interval 9 | field 10 | algorithm 11 | operator_on_subset 12 | graduation 13 | level_set 14 | 1d_burgers_amr 15 | reaction_diffusion 16 | -------------------------------------------------------------------------------- /docs/source/reference/index.rst: -------------------------------------------------------------------------------- 1 | Reference manual 2 | ================ 3 | 4 | .. toctree:: 5 | :caption: Reference 6 | :maxdepth: 1 7 | 8 | Boundary conditions 9 | Algebra of set 10 | Finite Volume schemes 11 | Local schemes 12 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/box/2d_box_with_hole.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | static constexpr std::size_t dim = 2; 6 | 7 | samurai::DomainBuilder domain({-1., -1.}, {1., 1.}); 8 | domain.remove({0.0, 0.0}, {0.4, 0.4}); 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /cmake/addGoogleTest.cmake: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | FetchContent_Declare(googletest 3 | GIT_REPOSITORY https://github.com/google/googletest.git 4 | GIT_TAG v1.16.0) 5 | FetchContent_GetProperties(googletest) 6 | if(NOT googletest_POPULATED) 7 | FetchContent_MakeAvailable(googletest) 8 | endif() 9 | -------------------------------------------------------------------------------- /cmake/addGoogleBench.cmake: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | FetchContent_Declare(googlebench 3 | GIT_REPOSITORY https://github.com/google/benchmark.git 4 | GIT_TAG v1.9.2) 5 | FetchContent_GetProperties(googlebench) 6 | if(NOT googlebench_POPULATED) 7 | FetchContent_MakeAvailable(googlebench) 8 | endif() 9 | -------------------------------------------------------------------------------- /demos/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(from_obj) 2 | add_subdirectory(FiniteVolume) 3 | # add_subdirectory(MPI) 4 | # add_subdirectory(LBM) 5 | add_subdirectory(p4est) 6 | add_subdirectory(pablo) 7 | add_subdirectory(tutorial) 8 | # add_subdirectory(Weno) 9 | add_subdirectory(multigrid) 10 | add_subdirectory(highorder) 11 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | file(GLOB snippet_list "**/*.cpp") 2 | 3 | foreach(snippet_file ${snippet_list}) 4 | get_filename_component(snippet_name ${snippet_file} NAME_WE) 5 | add_executable(${snippet_name} ${snippet_file}) 6 | target_link_libraries(${snippet_name} PRIVATE samurai) 7 | endforeach() 8 | -------------------------------------------------------------------------------- /tests/main.cpp: -------------------------------------------------------------------------------- 1 | #ifdef SAMURAI_WITH_MPI 2 | #include 3 | #endif 4 | #include 5 | 6 | int main(int argc, char* argv[]) 7 | { 8 | #ifdef SAMURAI_WITH_MPI 9 | boost::mpi::environment env(argc, argv); 10 | #endif 11 | ::testing::InitGoogleTest(&argc, argv); 12 | return RUN_ALL_TESTS(); 13 | } 14 | -------------------------------------------------------------------------------- /include/samurai/cell_flag.hpp: -------------------------------------------------------------------------------- 1 | 2 | // Copyright 2018-2025 the samurai's authors 3 | // SPDX-License-Identifier: BSD-3-Clause 4 | 5 | #pragma once 6 | 7 | namespace samurai 8 | { 9 | enum class CellFlag 10 | { 11 | keep = 1, 12 | coarsen = 2, 13 | refine = 4, 14 | enlarge = 8 15 | }; 16 | } // namespace samurai 17 | -------------------------------------------------------------------------------- /tests/test_level_cell_list.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | 6 | namespace samurai 7 | { 8 | TEST(level_cell_list, add_interval) 9 | { 10 | constexpr size_t dim = 2; 11 | LevelCellList lcl; 12 | lcl[{0}].add_interval({-3, 3}); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv/operators/flux_divergence.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../flux_based/flux_based_scheme__nonlin.hpp" 3 | 4 | namespace samurai 5 | { 6 | 7 | template 8 | auto make_divergence(const FluxDefinition& flux_definition) 9 | { 10 | return make_flux_based_scheme(flux_definition); 11 | } 12 | 13 | } // end namespace samurai 14 | -------------------------------------------------------------------------------- /.github/workflows/check-pr-title.yml: -------------------------------------------------------------------------------- 1 | name: "Lint PR" 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | 10 | jobs: 11 | main: 12 | name: Validate PR title 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: amannn/action-semantic-pull-request@v5 16 | env: 17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/mesh/mrmesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | static constexpr std::size_t dim = 2; 7 | 8 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 9 | 10 | auto config = samurai::mesh_config().min_level(2).max_level(5); 11 | auto mesh = samurai::mra::make_mesh(box, config); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /include/samurai/petsc.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | #include "schemes/fv.hpp" 6 | 7 | #error "Please replace '#include ' with '#include ' and activate the cmake option SAMURAI_WITH_PETSC by adding the line 'set(SAMURAI_WITH_PETSC On)' before the line 'find_package(samurai)' in your CMakeLists.txt file." 8 | -------------------------------------------------------------------------------- /demos/highorder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(${WITH_PETSC}) 2 | include(CMakeFindDependencyMacro) 3 | find_dependency(PkgConfig) 4 | pkg_check_modules(PETSC REQUIRED PETSc) 5 | 6 | include_directories(${PETSC_INCLUDE_DIRS}) 7 | 8 | add_executable(highorder main.cpp) 9 | target_compile_definitions(highorder PUBLIC SAMURAI_WITH_PETSC) 10 | target_link_libraries(highorder samurai ${PETSC_LINK_LIBRARIES}) 11 | endif() 12 | -------------------------------------------------------------------------------- /demos/multigrid/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(${WITH_PETSC}) 2 | include(CMakeFindDependencyMacro) 3 | find_dependency(PkgConfig) 4 | pkg_check_modules(PETSC REQUIRED PETSc) 5 | 6 | include_directories(${PETSC_INCLUDE_DIRS}) 7 | 8 | add_executable(multigrid main.cpp) 9 | target_compile_definitions(multigrid PUBLIC SAMURAI_WITH_PETSC) 10 | target_link_libraries(multigrid samurai ${PETSC_LINK_LIBRARIES}) 11 | endif() 12 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/mesh/amrmesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | static constexpr std::size_t dim = 2; 7 | 8 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 9 | 10 | auto config = samurai::mesh_config().min_level(2).max_level(5).start_level(4); 11 | auto mesh = samurai::amr::make_mesh(box, config); 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/mesh/uniform.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | static constexpr std::size_t dim = 2; 7 | using config_t = samurai::UniformConfig; 8 | 9 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 10 | samurai::UniformMesh mesh(box, 4); // 4 is the level of refinement 11 | 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /docs/Doxyfile: -------------------------------------------------------------------------------- 1 | PROJECT_NAME = "Samurai" 2 | XML_OUTPUT = xml 3 | INPUT = ../include 4 | GENERATE_LATEX = NO 5 | GENERATE_MAN = NO 6 | GENERATE_RTF = NO 7 | CASE_SENSE_NAMES = NO 8 | GENERATE_HTML = NO 9 | GENERATE_XML = YES 10 | RECURSIVE = YES 11 | QUIET = YES 12 | JAVADOC_AUTOBRIEF = YES 13 | WARN_IF_UNDOCUMENTED = NO 14 | MACRO_EXPANSION = YES 15 | PREDEFINED = IN_DOXYGEN 16 | -------------------------------------------------------------------------------- /.github/workflows/release-please.yml: -------------------------------------------------------------------------------- 1 | on: workflow_dispatch 2 | 3 | permissions: 4 | contents: write 5 | pull-requests: write 6 | 7 | name: release-please 8 | 9 | jobs: 10 | release-please: 11 | runs-on: ubuntu-24.04 12 | steps: 13 | - uses: googleapis/release-please-action@v4 14 | with: 15 | token: ${{ secrets.RELEASE_PLEASE }} 16 | release-type: simple 17 | -------------------------------------------------------------------------------- /demos/from_obj/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | option(WITH_CGAL "Activate cgal demos" OFF) 2 | 3 | if(WITH_CGAL) 4 | find_package(CGAL) 5 | find_package(Eigen3 3.1.0 REQUIRED) # (3.1.0 or greater) 6 | include(CGAL_Eigen3_support) 7 | 8 | add_executable(mesh-from-obj main.cpp) 9 | 10 | target_compile_definitions(mesh-from-obj PUBLIC _HAS_AUTO_PTR_ETC=0) 11 | target_link_libraries(mesh-from-obj samurai CGAL::CGAL CGAL::Eigen3_support) 12 | endif() 13 | -------------------------------------------------------------------------------- /conda/mpi-environment.yml: -------------------------------------------------------------------------------- 1 | name: samurai-mpi-2-env 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - cmake 6 | - ninja 7 | - xtensor>0.25 8 | - highfive>=3.0 9 | - fmt 10 | - pugixml 11 | - cli11<2.5 12 | - pytest 13 | - h5py 14 | - libboost-mpi #<1.87 # MPI seems broken with 1.87 with the error : symbol not found in flat namespace '_PyBaseObject_Type' 15 | - libboost-devel 16 | - libboost-headers 17 | - hdf5 * mpi_* 18 | - mpich 19 | -------------------------------------------------------------------------------- /docs/source/tutorial/snippet/interval_output.txt: -------------------------------------------------------------------------------- 1 | ┌────────────────────┐ 2 | │ Level 0 │ 3 | └────────────────────┘ 4 | dim 0 5 | cells = [0, 2[@0:1 [5, 6[@-3:1 6 | 7 | 8 | ┌────────────────────┐ 9 | │ Level 1 │ 10 | └────────────────────┘ 11 | dim 0 12 | cells = [4, 7[@-1:1 [8, 10[@-2:1 13 | 14 | 15 | ┌────────────────────┐ 16 | │ Level 2 │ 17 | └────────────────────┘ 18 | dim 0 19 | cells = [14, 16[@-6:1 20 | -------------------------------------------------------------------------------- /demos/FiniteVolume/BZ/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # add_subdirectory(RockAndRadau) 2 | 3 | enable_language (Fortran) 4 | 5 | set(RADAU_SRC 6 | RockAndRadau/decsol.f 7 | RockAndRadau/dc_decsol.f 8 | RockAndRadau/integration_stiff.cpp 9 | RockAndRadau/radau5.f 10 | RockAndRadau/rock4.f 11 | ) 12 | 13 | add_executable(bz_2d bz_2d.cpp ${RADAU_SRC}) 14 | target_link_libraries(bz_2d samurai) 15 | 16 | add_executable(bz_2d_AMR bz_2d_AMR.cpp ${RADAU_SRC}) 17 | target_link_libraries(bz_2d_AMR samurai) 18 | -------------------------------------------------------------------------------- /docs/source/tutorial/snippet/2d_mesh_box_output.txt: -------------------------------------------------------------------------------- 1 | ┌────────────────────┐ 2 | │ Level 3 │ 3 | └────────────────────┘ 4 | dim 0 5 | cells = [-8, 8[@8:1 [-8, 8[@24:1 [-8, 8[@40:1 [-8, 8[@56:1 [-8, 8[@72:1 [-8, 8[@88:1 [-8, 8[@104:1 [-8, 8[@120:1 [-8, 8[@136:1 [-8, 8[@152:1 [-8, 8[@168:1 [-8, 8[@184:1 [-8, 8[@200:1 [-8, 8[@216:1 [-8, 8[@232:1 [-8, 8[@248:1 6 | 7 | dim 1 8 | cells = [-8, 8[@8:1 9 | 10 | offsets = 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 11 | -------------------------------------------------------------------------------- /demos/FiniteVolume/BZ/RockAndRadau/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc -fPIC 2 | FC = gfortran -fPIC 3 | # -fno-underscoring 4 | LD = gcc 5 | 6 | CCFLAGS = 7 | LDFLAGS = 8 | 9 | OBJS = dc_decsol.o decsol.o radau5.o rock4.o integration_stiff.o 10 | LIB = libintegration_stiff.so 11 | 12 | all: $(LIB) 13 | 14 | $(LIB): $(OBJS) 15 | $(LD) -shared -o $@ $^ -lgfortran 16 | 17 | %.o: %.c 18 | $(CC) $(CCFLAGS) -c $< -o $@ 19 | 20 | %.o : %.f90 21 | $(FC) $(FCFLAGS) -c $< -o $@ 22 | 23 | clean: 24 | rm -f $(LIB) $(OBJS) 25 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/field/scalar_field.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | static constexpr std::size_t dim = 2; 8 | 9 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 10 | 11 | auto config = samurai::mesh_config().min_level(2).max_level(5); 12 | auto mesh = samurai::mra::make_mesh(box, config); 13 | 14 | auto field = samurai::make_scalar_field("u", mesh); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /vcpkg.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "samurai", 3 | "version-string": "0.0.1", 4 | "dependencies": [ 5 | "xtensor", 6 | { 7 | "name": "hdf5", 8 | "default-features": false, 9 | "features": [ "cpp" ] 10 | }, 11 | "highfive", 12 | "pugixml", 13 | "cxxopts", 14 | "fmt", 15 | "cli11", 16 | "rapidcheck" 17 | ], 18 | "builtin-baseline": "b51f391cd8f1f5a406b3baf9b014acff61702dc3", 19 | "overrides": [ 20 | { 21 | "name": "hdf5", "version": "1.12.2" 22 | } 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /cmake/addRapidCheck.cmake: -------------------------------------------------------------------------------- 1 | include(FetchContent) 2 | FetchContent_Declare(rapidcheck 3 | GIT_REPOSITORY https://github.com/emil-e/rapidcheck 4 | ) 5 | FetchContent_GetProperties(rapidcheck) 6 | if(NOT rapidcheck_POPULATED) 7 | FetchContent_Populate(rapidcheck) 8 | set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE BOOL "") 9 | set(RC_ENABLE_GTEST true CACHE BOOL "") 10 | add_subdirectory(${rapidcheck_SOURCE_DIR} ${rapidcheck_BINARY_DIR} EXCLUDE_FROM_ALL) 11 | unset(CMAKE_SUPPRESS_DEVELOPER_WARNINGS) 12 | endif() 13 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/field/vector_field.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | static constexpr std::size_t dim = 2; 8 | 9 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 10 | 11 | auto config = samurai::mesh_config().min_level(2).max_level(5); 12 | auto mesh = samurai::mra::make_mesh(box, config); 13 | 14 | auto field = samurai::make_vector_field("v", mesh); // 3 components 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /docs/source/tutorial/snippet/2d_mesh_box.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | constexpr std::size_t dim = 2; 10 | std::size_t start_level = 3; 11 | 12 | samurai::Box box({-1, -1}, {1, 1}); 13 | samurai::CellArray ca_box; 14 | 15 | ca_box[start_level] = {start_level, box}; 16 | 17 | std::cout << ca_box << std::endl; 18 | 19 | samurai::save("2d_mesh_box", ca_box); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /docs/source/tutorial/snippet/interval.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | constexpr std::size_t dim = 1; 9 | samurai::CellList cl; 10 | 11 | cl[0][{}].add_interval({0, 2}); 12 | cl[0][{}].add_interval({5, 6}); 13 | cl[1][{}].add_interval({4, 7}); 14 | cl[1][{}].add_interval({8, 10}); 15 | cl[2][{}].add_interval({14, 16}); 16 | 17 | samurai::CellArray ca{cl}; 18 | 19 | std::cout << ca << std::endl; 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/save/save_mesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | static constexpr std::size_t dim = 2; 8 | 9 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 10 | auto config = samurai::mesh_config().min_level(2).max_level(5); 11 | auto mesh = samurai::mra::make_mesh(box, config); 12 | 13 | samurai::save("output_path", "mesh_filename", mesh); 14 | // or 15 | samurai::save("mesh_filename", mesh); 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /demos/Weno/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(weno-weno5 weno5.cpp) 2 | target_link_libraries(weno-weno5 samurai) 3 | 4 | add_executable(weno-weno5-amr weno5_amr.cpp) 5 | target_link_libraries(weno-weno5-amr samurai) 6 | 7 | add_executable(weno-heat-weno5-amr heat_weno5_amr.cpp) 8 | target_link_libraries(weno-heat-weno5-amr samurai) 9 | 10 | add_executable(weno-VF-level-set-houc5-amr VF_level_set_houc5_amr.cpp) 11 | target_link_libraries(weno-VF-level-set-houc5-amr samurai) 12 | 13 | add_executable(weno-VF-level-set-os5-amr VF_level_set_os5_amr.cpp) 14 | target_link_libraries(weno-VF-level-set-os5-amr samurai) 15 | -------------------------------------------------------------------------------- /include/samurai/storage/layout_config.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | namespace samurai 7 | { 8 | enum class layout_type 9 | { 10 | /*! row major layout_type */ 11 | row_major = 0x00, 12 | /*! column major layout_type */ 13 | column_major = 0x01 14 | }; 15 | 16 | #if defined(SAMURAI_CONTAINER_LAYOUT_COL_MAJOR) 17 | #define SAMURAI_DEFAULT_LAYOUT ::samurai::layout_type::column_major 18 | #else 19 | #define SAMURAI_DEFAULT_LAYOUT ::samurai::layout_type::row_major 20 | #endif 21 | } 22 | -------------------------------------------------------------------------------- /AUTHORS.txt: -------------------------------------------------------------------------------- 1 | # This is the list of samurai's significant contributors. 2 | # 3 | # This does not necessarily list everyone who has contributed code, 4 | # especially since many employees of one corporation may be contributing. 5 | # To see the full list of contributors, see the revision history in 6 | # source control. 7 | 8 | Development contributors, in last name alphabetical order: 9 | 10 | Thomas Bellotti 11 | Loic Gouarin 12 | Pierre Matalon 13 | 14 | Scientific contributors, in last name alphabetical order: 15 | 16 | Thomas Bellotti 17 | Loic Gouarin 18 | Marc Massot 19 | Pierre Matalon 20 | -------------------------------------------------------------------------------- /docs/source/howto/index.rst: -------------------------------------------------------------------------------- 1 | How-to guides 2 | ================ 3 | 4 | In this section, we will cover various how-to guides on very simple tasks that you may want to perform with 5 | the software. These guides are intended to be straightforward and easy to follow, providing step-by-step instructions. If you want an how-to that is not listed here, please feel free to ask it by opening an issue or to contribute by creating a pull request. 6 | 7 | .. toctree:: 8 | :maxdepth: 1 9 | 10 | installation.md 11 | cmake.md 12 | box.md 13 | mesh.md 14 | field.md 15 | loop.md 16 | options.md 17 | save.md 18 | plot.md 19 | timers.md 20 | -------------------------------------------------------------------------------- /include/samurai/schemes/explicit_scheme.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace samurai 4 | { 5 | template 6 | class Explicit 7 | { 8 | template 9 | static constexpr bool dependent_false = false; 10 | 11 | static_assert(dependent_false, 12 | "Either the required file has not been included, or the Explicit class has not been specialized for this type of scheme."); 13 | }; 14 | 15 | template 16 | auto make_explicit(Scheme& s) 17 | { 18 | return Explicit>(s); 19 | } 20 | } // end namespace samurai 21 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SOURCEDIR = source 8 | BUILDDIR = build 9 | 10 | # Put it first so that "make" without argument is like "make help". 11 | help: 12 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 13 | 14 | .PHONY: help Makefile 15 | 16 | # Catch-all target: route all unknown targets to Sphinx using the new 17 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 18 | %: Makefile 19 | doxygen 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /tests/test_demo_p4est.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pytest 3 | import subprocess 4 | from pathlib import Path 5 | 6 | path = 'p4est' 7 | 8 | @pytest.fixture 9 | def config(): 10 | return {'path': path} 11 | 12 | def get_executable(path, filename): 13 | if os.path.exists(os.path.join(path, filename)): 14 | return os.path.join(path, filename) 15 | return os.path.join(path, 'Release', filename) 16 | 17 | @pytest.mark.h5diff() 18 | def test_simple_2d(config): 19 | cmd = [get_executable(Path("../build/demos/p4est/"), "p4est-simple-2d"), 20 | "--path", config['path'], 21 | '--filename', config['filename']] 22 | output = subprocess.run(cmd, check=True, capture_output=True) 23 | -------------------------------------------------------------------------------- /tests/test_demo_pablo.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pytest 3 | import subprocess 4 | from pathlib import Path 5 | 6 | path = 'pablo' 7 | 8 | @pytest.fixture 9 | def config(): 10 | return {'path': path} 11 | 12 | def get_executable(path, filename): 13 | if os.path.exists(os.path.join(path, filename)): 14 | return os.path.join(path, filename) 15 | return os.path.join(path, 'Release', filename) 16 | 17 | @pytest.mark.h5diff() 18 | def test_2d_bubbles(config): 19 | cmd = [get_executable(Path("../build/demos/pablo/"), "pablo-bubble-2d"), 20 | "--path", config['path'], 21 | '--filename', config['filename'], 22 | '--Tf', '3'] 23 | output = subprocess.run(cmd, check=True, capture_output=True) 24 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/loop/for_each_cell_mesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | static constexpr std::size_t dim = 2; 8 | 9 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 10 | auto config = samurai::mesh_config().min_level(2).max_level(5); 11 | auto mesh = samurai::mra::make_mesh(box, config); 12 | 13 | samurai::for_each_cell(mesh, 14 | [&](const auto& cell) 15 | { 16 | std::cout << "Cell level: " << cell.level << ", center: " << cell.center() << std::endl; 17 | }); 18 | 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/options/custom_options.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | int main(int argc, char** argv) 6 | { 7 | auto& app = samurai::initialize("Add my options", argc, argv); 8 | 9 | int my_option = 42; 10 | bool my_flag = false; 11 | 12 | app.add_option("--my-option", my_option, "An example of custom option")->capture_default_str()->group("Custom"); 13 | app.add_flag("--my-flag", my_flag, "An example of custom flag")->group("Custom"); 14 | 15 | SAMURAI_PARSE(argc, argv); 16 | 17 | std::cout << "my-option = " << my_option << std::endl; 18 | std::cout << "my-flag = " << std::boolalpha << my_flag << std::endl; 19 | 20 | samurai::finalize(); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/save/save_field.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | static constexpr std::size_t dim = 2; 9 | 10 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 11 | auto config = samurai::mesh_config().min_level(2).max_level(5); 12 | auto mesh = samurai::mra::make_mesh(box, config); 13 | 14 | auto field_1 = samurai::make_scalar_field("u", mesh); 15 | auto field_2 = samurai::make_vector_field("v", mesh); 16 | 17 | samurai::save("output_path", "fields", mesh, field_1, field_2); 18 | // or 19 | samurai::save("fields", mesh, field_1, field_2); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/loop/for_each_interval_mesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | static constexpr std::size_t dim = 2; 8 | 9 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 10 | auto config = samurai::mesh_config().min_level(2).max_level(5); 11 | auto mesh = samurai::mra::make_mesh(box, config); 12 | 13 | samurai::for_each_interval(mesh, 14 | [&](std::size_t level, const auto& interval, const auto& index) 15 | { 16 | auto y = index[0]; 17 | std::cout << "Level: " << level << ", x: " << interval << ", y: " << y << std::endl; 18 | }); 19 | 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_lid_driven_cavity.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_lid_driven_cavity.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_lid_driven_cavity.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_lid_driven_cavity.h5:/mesh/fields/ink 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv/operators/identity.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../cell_based/cell_based_scheme__lin_hom.hpp" 3 | 4 | namespace samurai 5 | { 6 | template 7 | auto make_identity() 8 | { 9 | static constexpr std::size_t n_comp = Field::n_comp; 10 | using field_value_type = typename Field::value_type; 11 | 12 | using cfg = LocalCellSchemeConfig; 13 | 14 | auto identity = make_cell_based_scheme("Identity"); 15 | 16 | identity.coefficients_func() = [](StencilCoeffs& sc, double) 17 | { 18 | sc = eye(); 19 | }; 20 | identity.is_symmetric(true); 21 | identity.is_spd(true); 22 | return identity; 23 | } 24 | 25 | } // end namespace samurai 26 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_recons.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_mra_burgers_hat_recons.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_mra_burgers_hat_recons.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_mra_burgers_hat_recons.h5:/mesh/fields/u 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/save/save_all_submeshes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace fs = std::filesystem; 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | static constexpr std::size_t dim = 2; 12 | 13 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 14 | auto config = samurai::mesh_config().min_level(2).max_level(5); 15 | auto mesh = samurai::mra::make_mesh(box, config); 16 | 17 | auto field_1 = samurai::make_scalar_field("u", mesh); 18 | auto field_2 = samurai::make_vector_field("v", mesh); 19 | 20 | samurai::save("output_path", "fields", {true, true}, mesh, field_1, field_2); 21 | // or 22 | samurai::save(fs::current_path(), "fields", {true, true}, mesh, field_1, field_2); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_mlf_recons.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_mra_burgers_hat_mlf_recons.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_mra_burgers_hat_mlf_recons.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_mra_burgers_hat_mlf_recons.h5:/mesh/fields/u 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v5.0.0 4 | hooks: 5 | # - id: check-added-large-files 6 | - id: check-case-conflict 7 | - id: end-of-file-fixer 8 | - id: trailing-whitespace 9 | - id: check-merge-conflict 10 | - id: check-yaml 11 | - id: check-json 12 | - id: no-commit-to-branch 13 | - id: mixed-line-ending 14 | args: ["--fix=lf"] 15 | description: Forces to replace line ending by the UNIX 'lf' character. 16 | - repo: https://github.com/Lucas-C/pre-commit-hooks 17 | rev: v1.5.5 18 | hooks: 19 | - id: forbid-tabs 20 | - id: remove-tabs 21 | args: [--whitespaces-count, "4"] 22 | - repo: https://github.com/pre-commit/mirrors-clang-format 23 | rev: v18.1.2 24 | hooks: 25 | - id: clang-format 26 | files: .*\.[hc]pp$ 27 | -------------------------------------------------------------------------------- /tests/test_common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace samurai 9 | { 10 | template 11 | bool operator==(const ListOfIntervals& li, const xt::xarray>& array) 12 | { 13 | auto ix = li.cbegin(); 14 | auto iy = array.cbegin(); 15 | while (ix != li.cend() && iy != array.cend()) 16 | { 17 | if (*ix != *iy) 18 | { 19 | return false; 20 | } 21 | ++ix; 22 | ++iy; 23 | } 24 | if (ix == li.cend() && iy == array.cend()) 25 | { 26 | return true; 27 | } 28 | else 29 | { 30 | return false; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_3/update_sol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | template 9 | void update_sol(double dt, Field& phi, Field& phi_np1) 10 | { 11 | using mesh_id_t = typename Field::mesh_t::mesh_id_t; // <----------------- 12 | auto& mesh = phi.mesh(); 13 | 14 | samurai::for_each_interval( 15 | mesh[mesh_id_t::cells], 16 | [&](std::size_t level, const auto& i, auto) // <----------------- 17 | { 18 | const double dx = mesh.cell_length(level); 19 | 20 | phi_np1(level, i) = phi(level, i) 21 | - .5 * dt / dx * (phi(level, i) * phi(level, i) - phi(level, i - 1) * phi(level, i - 1)); // <----------------- 22 | }); 23 | 24 | std::swap(phi.array(), phi_np1.array()); 25 | } 26 | -------------------------------------------------------------------------------- /docs/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | pushd %~dp0 4 | 5 | REM Command file for Sphinx documentation 6 | 7 | if "%SPHINXBUILD%" == "" ( 8 | set SPHINXBUILD=sphinx-build 9 | ) 10 | set SOURCEDIR=source 11 | set BUILDDIR=build 12 | 13 | if "%1" == "" goto help 14 | 15 | %SPHINXBUILD% >NUL 2>NUL 16 | if errorlevel 9009 ( 17 | echo. 18 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx 19 | echo.installed, then set the SPHINXBUILD environment variable to point 20 | echo.to the full path of the 'sphinx-build' executable. Alternatively you 21 | echo.may add the Sphinx directory to PATH. 22 | echo. 23 | echo.If you don't have Sphinx installed, grab it from 24 | echo.http://sphinx-doc.org/ 25 | exit /b 1 26 | ) 27 | 28 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 29 | goto end 30 | 31 | :help 32 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% 33 | 34 | :end 35 | popd 36 | -------------------------------------------------------------------------------- /docs/source/tutorial/snippet/2d_mesh_representation_output.txt: -------------------------------------------------------------------------------- 1 | ┌────────────────────┐ 2 | │ Level 0 │ 3 | └────────────────────┘ 4 | dim 0 5 | cells = [0, 4[@0:1 [0, 1[@4:1 [3, 4[@2:1 [0, 1[@6:1 [3, 4[@4:1 [0, 3[@8:1 6 | 7 | dim 1 8 | cells = [0, 4[@0:1 9 | 10 | offsets = 0 1 3 5 6 11 | 12 | 13 | ┌────────────────────┐ 14 | │ Level 1 │ 15 | └────────────────────┘ 16 | dim 0 17 | cells = [2, 6[@9:1 [2, 6[@13:1 [2, 4[@17:1 [5, 6[@16:1 [2, 6[@20:1 [6, 8[@20:1 [6, 7[@22:1 18 | 19 | dim 1 20 | cells = [2, 8[@-2:1 21 | 22 | offsets = 0 1 2 4 5 6 7 23 | 24 | 25 | ┌────────────────────┐ 26 | │ Level 2 │ 27 | └────────────────────┘ 28 | dim 0 29 | cells = [8, 10[@21:1 [8, 10[@23:1 [14, 16[@19:1 [14, 16[@21:1 30 | 31 | dim 1 32 | cells = [8, 10[@-8:1 [14, 16[@-12:1 33 | 34 | offsets = 0 1 2 3 4 35 | -------------------------------------------------------------------------------- /demos/tutorial/interval.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | constexpr std::size_t dim = 2; // cppcheck-suppress unreadVariable 12 | 13 | samurai::CellList cl; 14 | 15 | cl[0][{}].add_interval({0, 2}); 16 | cl[0][{}].add_interval({5, 6}); 17 | cl[1][{}].add_interval({4, 7}); 18 | cl[1][{}].add_interval({8, 10}); 19 | cl[2][{}].add_interval({15, 17}); 20 | 21 | const samurai::CellArray ca{cl}; 22 | 23 | std::cout << ca << std::endl; 24 | 25 | constexpr std::size_t start_level = 3; 26 | const samurai::Box box({-1, -1}, {1, 1}); 27 | samurai::CellArray ca_box; 28 | 29 | ca_box[start_level] = {start_level, box}; 30 | 31 | std::cout << ca_box << std::endl; 32 | 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/loop/for_each_cell_field.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | static constexpr std::size_t dim = 2; 9 | 10 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 11 | auto config = samurai::mesh_config().min_level(2).max_level(5); 12 | auto mesh = samurai::mra::make_mesh(box, config); 13 | 14 | auto field = samurai::make_scalar_field("u", mesh); 15 | 16 | samurai::for_each_cell(mesh, 17 | [&](const auto& cell) 18 | { 19 | auto x = cell.center(0); 20 | auto y = cell.center(1); 21 | 22 | field[cell] = std::exp(-((x - 0.5) * (x - 0.5) + (y - 0.5) * (y - 0.5)) * 20.0); 23 | }); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /docs/source/reference/snippet/subset_1d_output.txt: -------------------------------------------------------------------------------- 1 | before projection 2 | Field u 3 | level: 0 coords: { 0.5} value: 0. 4 | level: 0 coords: { 1.5} value: 1. 5 | level: 0 coords: { 2.5} value: 2. 6 | level: 0 coords: { 3.5} value: 3. 7 | level: 1 coords: { 0.25} value: 0. 8 | level: 1 coords: { 0.75} value: 1. 9 | level: 1 coords: { 1.25} value: 2. 10 | level: 1 coords: { 1.75} value: 3. 11 | level: 1 coords: { 3.25} value: 6. 12 | level: 1 coords: { 3.75} value: 7. 13 | 14 | after projection 15 | Field u 16 | level: 0 coords: { 0.5} value: 0.5 17 | level: 0 coords: { 1.5} value: 2.5 18 | level: 0 coords: { 2.5} value: 2. 19 | level: 0 coords: { 3.5} value: 6.5 20 | level: 1 coords: { 0.25} value: 0. 21 | level: 1 coords: { 0.75} value: 1. 22 | level: 1 coords: { 1.25} value: 2. 23 | level: 1 coords: { 1.75} value: 3. 24 | level: 1 coords: { 3.25} value: 6. 25 | level: 1 coords: { 3.75} value: 7. 26 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/save/dump_mesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace fs = std::filesystem; 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | static constexpr std::size_t dim = 2; 12 | 13 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 14 | auto config = samurai::mesh_config().min_level(2).max_level(5); 15 | auto mesh = samurai::mra::make_mesh(box, config); 16 | 17 | auto field_1 = samurai::make_scalar_field("u", mesh); 18 | auto field_2 = samurai::make_vector_field("v", mesh); 19 | 20 | samurai::dump(fs::current_path(), "restart_file", mesh, field_1, field_2); 21 | // or 22 | samurai::dump("fields", mesh, field_1, field_2); 23 | 24 | samurai::load("output_path", "restart_file", mesh, field_1, field_2); 25 | // or 26 | samurai::load("restart_file", mesh, field_1, field_2); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: "*, 3 | -android-*, 4 | -abseil-*, 5 | -altera-*, 6 | -google-*, 7 | -llvm*, 8 | -fuchsia-*, 9 | -readability-identifier-length, 10 | -readability-function-cognitive-complexity, 11 | -readability-magic-numbers, 12 | -readability-named-parameter, 13 | -modernize-use-nodiscard, 14 | -modernize-use-trailing-return-type, 15 | -bugprone-easily-swappable-parameters, 16 | -bugprone-exception-escape, 17 | -hicpp-signed-bitwise, 18 | -hicpp-explicit-conversions, 19 | -hicpp-named-parameter, 20 | -cppcoreguidelines-avoid-magic-numbers, 21 | -cppcoreguidelines-init-variables, 22 | " 23 | WarningsAsErrors: '*' 24 | HeaderFilterRegex: '' 25 | FormatStyle: none 26 | CheckOptions: 27 | - key: hicpp-signed-bitwise.IgnorePositiveIntegerLiterals 28 | value: true 29 | - key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic 30 | value: '1' 31 | -------------------------------------------------------------------------------- /tests/copyGTest.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | cmake_minimum_required(VERSION 2.8.2) 10 | 11 | project(googletest-download NONE) 12 | 13 | include(ExternalProject) 14 | ExternalProject_Add(googletest 15 | URL "${GTEST_SRC_DIR}" 16 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" 17 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" 18 | CONFIGURE_COMMAND "" 19 | BUILD_COMMAND "" 20 | INSTALL_COMMAND "" 21 | TEST_COMMAND "" 22 | ) 23 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv/operators/zero_operator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../cell_based/cell_based_scheme__lin_hom.hpp" 3 | 4 | namespace samurai 5 | { 6 | template 7 | auto make_zero_operator() 8 | { 9 | using field_value_type = typename input_field_t::value_type; 10 | 11 | using cfg = LocalCellSchemeConfig; 12 | 13 | auto zero = make_cell_based_scheme("Zero"); 14 | 15 | zero.coefficients_func() = [](StencilCoeffs& sc, double) 16 | { 17 | sc = zeros(); 18 | }; 19 | zero.is_symmetric(true); 20 | return zero; 21 | } 22 | 23 | template 24 | auto make_zero_operator() 25 | { 26 | using default_output_field_t = Field; 27 | return make_zero_operator(); 28 | } 29 | 30 | } // end namespace samurai 31 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_1/init_sol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | template 9 | auto init_sol(Mesh& mesh) 10 | { 11 | // create a field from the mesh 12 | auto phi = samurai::make_scalar_field("phi", mesh); 13 | 14 | samurai::for_each_cell(mesh, 15 | [&](auto& cell) 16 | { 17 | double x = cell.center(0); 18 | 19 | // Initial hat solution 20 | if (x < -1. || x > 1.) 21 | { 22 | phi[cell] = 0.; 23 | } 24 | else 25 | { 26 | phi[cell] = (x < 0.) ? (1 + x) : (1 - x); 27 | } 28 | }); 29 | 30 | return phi; 31 | } 32 | -------------------------------------------------------------------------------- /demos/multigrid/samurai_new/utils.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | template 5 | void print_mesh(Mesh& mesh) 6 | { 7 | std::cout << mesh << std::endl; 8 | samurai::for_each_cell(mesh, 9 | [](const auto& cell) 10 | { 11 | std::cout << "level: " << cell.level << ", cell index: " << cell.index << ", center: " << cell.center(0) 12 | << std::endl; 13 | }); 14 | } 15 | 16 | template 17 | bool check_nan_or_inf(const Field& f) 18 | { 19 | std::size_t n = f.mesh().nb_cells(); 20 | bool is_nan_or_inf = false; 21 | for (std::size_t i = 0; i < n * Field::n_comp; ++i) 22 | { 23 | double value = f.array().data()[i]; 24 | if (std::isnan(value) || std::isinf(value) || (abs(value) < 1e-300 && abs(value) != 0)) 25 | { 26 | is_nan_or_inf = true; 27 | break; 28 | } 29 | } 30 | return !is_nan_or_inf; 31 | } 32 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_explicit.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_heat_explicit.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_heat_explicit.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_heat_explicit.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_heat_explicit.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_implicit.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_heat_implicit.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_heat_implicit.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_heat_implicit.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_heat_implicit.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_mra_burgers_hat.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_mra_burgers_hat.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_mra_burgers_hat.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_mra_burgers_hat.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | - [ ] I have installed [pre-commit](https://pre-commit.com/) locally and use it to validate my commits. 5 | - [ ] The PR title follows the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) convention. 6 | Available tags: 'build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test' 7 | - [ ] This new PR is documented. 8 | - [ ] This new PR is tested. 9 | 10 | ## Description 11 | 12 | 13 | ## Related issue 14 | 15 | 16 | ## How has this been tested? 17 | 18 | 19 | ## Code of Conduct 20 | By submitting this PR, you agree to follow our [Code of Conduct](https://github.com/hpc-maths/samurai/blob/master/docs/CODE_OF_CONDUCT.md) 21 | - [ ] I agree to follow this project's Code of Conduct 22 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_mra_burgers_hat_mlf.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_mra_burgers_hat_mlf.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_mra_burgers_hat_mlf.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_mra_burgers_hat_mlf.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_mra_burgers_hat_mlf.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_linear_convection_explicit.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_linear_convection.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_linear_convection.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_linear_convection.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_linear_convection.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/downloadGTest.cmake.in: -------------------------------------------------------------------------------- 1 | ############################################################################ 2 | # Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht # 3 | # # 4 | # Distributed under the terms of the BSD 3-Clause License. # 5 | # # 6 | # The full license is in the file LICENSE, distributed with this software. # 7 | ############################################################################ 8 | 9 | cmake_minimum_required(VERSION 3.5) 10 | 11 | project(googletest-download NONE) 12 | 13 | include(ExternalProject) 14 | ExternalProject_Add(googletest 15 | GIT_REPOSITORY https://github.com/google/googletest.git 16 | GIT_TAG release-1.15.2 17 | SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-src" 18 | BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/googletest-build" 19 | CONFIGURE_COMMAND "" 20 | BUILD_COMMAND "" 21 | INSTALL_COMMAND "" 22 | TEST_COMMAND "" 23 | ) 24 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_stokes_stationary.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_stokes_stationary.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_stokes_stationary.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_stokes_stationary.h5:/mesh/fields/velocity_0 13 | 14 | 15 | test_finite_volume_demo_stokes_stationary.h5:/mesh/fields/velocity_1 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_exp_diff_exp_react.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_nagumo_exp_diff_exp_react.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_nagumo_exp_diff_exp_react.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_nagumo_exp_diff_exp_react.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_nagumo_exp_diff_exp_react.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_exp_diff_imp_react.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_nagumo_exp_diff_imp_react.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_nagumo_exp_diff_imp_react.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_nagumo_exp_diff_imp_react.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_nagumo_exp_diff_imp_react.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_imp_diff_exp_react.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_nagumo_imp_diff_exp_react.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_nagumo_imp_diff_exp_react.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_nagumo_imp_diff_exp_react.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_nagumo_imp_diff_exp_react.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_nagumo_imp_diff_imp_react.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_nagumo_imp_diff_imp_react.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_nagumo_imp_diff_imp_react.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_nagumo_imp_diff_imp_react.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_nagumo_imp_diff_imp_react.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_stokes_nonstationary.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_stokes_nonstationary.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_stokes_nonstationary.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_stokes_nonstationary.h5:/mesh/fields/velocity_0 13 | 14 | 15 | test_finite_volume_demo_stokes_nonstationary.h5:/mesh/fields/velocity_1 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv/utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../../storage/containers.hpp" 4 | 5 | namespace samurai 6 | { 7 | enum class SchemeType 8 | { 9 | NonLinear, 10 | LinearHeterogeneous, 11 | LinearHomogeneous 12 | }; 13 | 14 | template 15 | using StencilCells = CollapsStdArray; 16 | 17 | template 18 | using StencilValues = CollapsStdArray; 19 | 20 | template 21 | using JacobianMatrix = CollapsMatrix; 25 | 26 | template 27 | using StencilJacobian = collapsable_algebraic_std_array, cfg::stencil_size, true>; 28 | 29 | } // end namespace samurai 30 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_linear_convection_implicit.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_linear_convection_implicit.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_linear_convection_implicit.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_linear_convection_implicit.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_linear_convection_implicit.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_obstacle_linear_convection.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_obstacle_linear_convection.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_obstacle_linear_convection.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_obstacle_linear_convection.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_obstacle_linear_convection.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_heterogeneous_explicit.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_heat_heterogeneous_explicit.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_heat_heterogeneous_explicit.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_heat_heterogeneous_explicit.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_heat_heterogeneous_explicit.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_heat_heterogeneous_implicit.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_heat_heterogeneous_implicit.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_heat_heterogeneous_implicit.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_heat_heterogeneous_implicit.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_heat_heterogeneous_implicit.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-1d-0.1.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-advection-1d-0.1.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-advection-1d-0.1.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-advection-1d-0.1.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_finite-volume-advection-1d-0.1.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-amr-burgers-hat-1.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-amr-burgers-hat-1.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-amr-burgers-hat-1.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-amr-burgers-hat-1.h5:/mesh/fields/phi 13 | 14 | 15 | test_finite_volume_demo_finite-volume-amr-burgers-hat-1.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | #include "../numeric/error.hpp" 6 | #include "../samurai.hpp" 7 | 8 | #include "fv/cell_based/cell_based_scheme__nonlin.hpp" 9 | #include "fv/cell_based/explicit_cell_based_scheme.hpp" 10 | #include "fv/explicit_operator_sum.hpp" 11 | #include "fv/flux_based/explicit_flux_based_scheme__lin_het.hpp" 12 | #include "fv/flux_based/explicit_flux_based_scheme__lin_hom.hpp" 13 | #include "fv/flux_based/explicit_flux_based_scheme__nonlin.hpp" 14 | #include "fv/scheme_operators.hpp" 15 | 16 | #include "fv/operators/convection_lin.hpp" 17 | #include "fv/operators/convection_nonlin.hpp" 18 | #include "fv/operators/diffusion.hpp" 19 | #include "fv/operators/diffusion_cell_based.hpp" 20 | #include "fv/operators/divergence.hpp" 21 | #include "fv/operators/flux_divergence.hpp" 22 | #include "fv/operators/gradient.hpp" 23 | #include "fv/operators/identity.hpp" 24 | #include "fv/operators/zero_operator.hpp" 25 | 26 | #ifdef SAMURAI_WITH_PETSC 27 | #include "../petsc/manual_assembly.hpp" 28 | #include "../petsc/solver_helpers.hpp" 29 | #endif 30 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-2d-0.01.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-advection-2d-0.01.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-advection-2d-0.01.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-advection-2d-0.01.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_finite-volume-advection-2d-0.01.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/source/tutorial/snippet/2d_mesh_representation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | constexpr std::size_t dim = 2; 10 | samurai::CellList cl; 11 | 12 | cl[0][{0}].add_interval({0, 4}); 13 | cl[0][{1}].add_interval({0, 1}); 14 | cl[0][{1}].add_interval({3, 4}); 15 | cl[0][{2}].add_interval({0, 1}); 16 | cl[0][{2}].add_interval({3, 4}); 17 | cl[0][{3}].add_interval({0, 3}); 18 | 19 | cl[1][{2}].add_interval({2, 6}); 20 | cl[1][{3}].add_interval({2, 6}); 21 | cl[1][{4}].add_interval({2, 4}); 22 | cl[1][{4}].add_interval({5, 6}); 23 | cl[1][{5}].add_interval({2, 6}); 24 | cl[1][{6}].add_interval({6, 8}); 25 | cl[1][{7}].add_interval({6, 7}); 26 | 27 | cl[2][{8}].add_interval({8, 10}); 28 | cl[2][{8}].add_interval({8, 10}); 29 | cl[2][{14}].add_interval({14, 16}); 30 | cl[2][{15}].add_interval({14, 16}); 31 | 32 | samurai::CellArray ca{cl}; 33 | 34 | std::cout << ca << std::endl; 35 | 36 | samurai::save("2d_mesh_representation", ca); 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-1d-0.1_init.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-advection-1d-0.1_init.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-advection-1d-0.1_init.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-advection-1d-0.1_init.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_finite-volume-advection-1d-0.1_init.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /demos/tutorial/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(AMR_1D_Burgers) 2 | 3 | # List of tutorial demos with their corresponding executable names 4 | set(TUTORIAL_DEMOS 5 | 2D_mesh.cpp:tutorial-2d-mesh 6 | interval.cpp:tutorial-interval 7 | set_operator.cpp:tutorial-set-operator 8 | graduation_case_1.cpp:tutorial-graduation-case-1 9 | graduation_case_2.cpp:tutorial-graduation-case-2 10 | graduation_case_3.cpp:tutorial-graduation-case-3 11 | reconstruction_1d.cpp:tutorial-reconstruction-1d 12 | reconstruction_2d.cpp:tutorial-reconstruction-2d 13 | reconstruction_3d.cpp:tutorial-reconstruction-3d 14 | proj_on_mesh.cpp:tutorial-proj-on-mesh 15 | ) 16 | 17 | # Create executables for all tutorial demos 18 | foreach(demo_entry ${TUTORIAL_DEMOS}) 19 | string(REPLACE ":" ";" demo_parts ${demo_entry}) 20 | list(GET demo_parts 0 source_file) 21 | list(GET demo_parts 1 executable_name) 22 | 23 | add_executable(${executable_name} ${source_file}) 24 | target_link_libraries(${executable_name} PRIVATE samurai) 25 | endforeach() 26 | 27 | # Specific options for MSVC 28 | if(MSVC) 29 | target_compile_options(tutorial-reconstruction-3d PUBLIC /bigobj) 30 | endif() 31 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-advection-2d-0.01_init.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-advection-2d-0.01_init.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-advection-2d-0.01_init.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-advection-2d-0.01_init.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_finite-volume-advection-2d-0.01_init.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_3/init_sol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | template 10 | auto init_sol(Mesh& mesh) 11 | { 12 | using mesh_id_t = typename Mesh::mesh_id_t; // <----------------- 13 | auto phi = samurai::make_scalar_field("phi", mesh); 14 | phi.fill(0.); 15 | 16 | samurai::for_each_cell(mesh[mesh_id_t::cells_and_ghosts], 17 | [&](auto& cell) // <----------------- 18 | { 19 | double x = cell.center(0); 20 | 21 | // Initial hat solution 22 | if (x < -1. || x > 1.) 23 | { 24 | phi[cell] = 0.; 25 | } 26 | else 27 | { 28 | phi[cell] = (x < 0.) ? (1 + x) : (1 - x); 29 | } 30 | }); 31 | 32 | return phi; 33 | } 34 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.h5:/mesh/fields/u 13 | 14 | 15 | test_finite_volume_demo_finite-volume-scalar-burgers-2d-0.001_init.h5:/mesh/fields/level 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /docs/source/philosophy.rst: -------------------------------------------------------------------------------- 1 | Philosophy of |project| 2 | ======================= 3 | 4 | The main goal of |project| is to provide a data structure adapted to adaptive mesh refinement methods based on cartesian grid. Most of the data structures used for these kinds of applications are based on the construction of a tree (quadtree in 2d or octree in 3d). The main advantage when you use a tree data structure is that you can add or delete nodes in :math:`O(1)` if you know where they are or where to add them. But if you want to search for a given node inside the tree, it can take a lot of time. To improve this search time, you can use a space-filling curve to numbering your nodes in a certain way (see p4est_ for example). This allows being sure that the neighborhood of a given node is always near this node into the data structure. It's really important because you probably want to solve a PDE using numerical methods such as finite volume, finite element methods on your adaptive mesh. This means that you have a stencil and for each cell of your mesh you have to find its neighborhood to apply your operator. So you want to make it fast. 5 | 6 | The following figure tries to highlight the issue of the locality 7 | 8 | 9 | 10 | .. _p4est: http://www.p4est.org/ 11 | -------------------------------------------------------------------------------- /include/samurai/subset/concepts.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace samurai 10 | { 11 | template 12 | class LevelCellArray; 13 | // } 14 | 15 | // namespace samurai::experimental 16 | // { 17 | template 18 | class SetTraverser; 19 | 20 | template 21 | class IntervalListVisitor; 22 | 23 | template 24 | struct is_setop : std::false_type 25 | { 26 | }; 27 | 28 | template 29 | struct is_setop> : std::true_type 30 | { 31 | }; 32 | 33 | template 34 | constexpr bool is_setop_v{is_setop>::value}; 35 | 36 | template 37 | concept IsSetOp = is_setop_v; 38 | 39 | template 40 | concept IsIntervalListVisitor = std::is_base_of_v::container_t>, std::decay_t>; 41 | 42 | template 43 | concept IsLCA = std::same_as, T>; 44 | } 45 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/timers/custom_timer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char** argv) 9 | { 10 | static constexpr std::size_t dim = 2; 11 | 12 | samurai::initialize("Custom timer example", argc, argv); 13 | 14 | samurai::Box box({0.0, 0.0}, {1.0, 1.0}); 15 | auto config = samurai::mesh_config().min_level(2).max_level(5); 16 | auto mesh = samurai::mra::make_mesh(box, config); 17 | 18 | auto field = samurai::make_scalar_field("u", mesh); 19 | 20 | samurai::times::timers.start("init field"); 21 | 22 | samurai::for_each_cell(mesh, 23 | [&](const auto& cell) 24 | { 25 | auto x = cell.center(0); 26 | auto y = cell.center(1); 27 | 28 | field[cell] = std::exp(-((x - 0.5) * (x - 0.5) + (y - 0.5) * (y - 0.5)) * 20.0); 29 | }); 30 | 31 | samurai::times::timers.stop("init field"); 32 | 33 | samurai::finalize(); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /tests/test_utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace samurai 12 | { 13 | TEST(utils, is_field_function) 14 | { 15 | Box box{{0}, {1}}; 16 | using Config = UniformConfig<1>; 17 | auto mesh = UniformMesh(box, 3); 18 | 19 | auto u = make_scalar_field("u", mesh); 20 | 21 | static_assert(detail::is_field_function::value); 22 | static_assert(detail::is_field_function::value); 23 | } 24 | 25 | TEST(utils, compute_n_comp) 26 | { 27 | Box box{{0}, {1}}; 28 | using Config = UniformConfig<1>; 29 | auto mesh = UniformMesh(box, 3); 30 | 31 | auto u1 = make_scalar_field("u", mesh); 32 | auto u2 = make_vector_field("u", mesh); 33 | 34 | static_assert(detail::compute_n_comp() == 4); 35 | 36 | static_assert(std::is_same, double>::value); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_burgers.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_burgers.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_burgers.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_burgers.h5:/mesh/fields/u_0 13 | 14 | 15 | test_finite_volume_demo_burgers.h5:/mesh/fields/u_1 16 | 17 | 18 | test_finite_volume_demo_burgers.h5:/mesh/fields/level 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /tests/test_graduation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | namespace samurai 10 | { 11 | TEST(graduation, dim_1) 12 | { 13 | constexpr size_t dim = 1; 14 | CellList cl; 15 | cl[0][{}].add_interval({1, 2}); 16 | cl[5][{}].add_interval({0, 1}); 17 | CellArray ca{cl}; 18 | 19 | samurai::make_graduation(ca); 20 | EXPECT_TRUE(is_graduated(ca)); 21 | } 22 | 23 | TEST(graduation, dim_2) 24 | { 25 | constexpr size_t dim = 2; 26 | CellList cl; 27 | cl[0][{}].add_interval({1, 2}); 28 | cl[5][{}].add_interval({0, 1}); 29 | CellArray ca{cl}; 30 | 31 | samurai::make_graduation(ca); 32 | EXPECT_TRUE(is_graduated(ca)); 33 | } 34 | 35 | TEST(graduation, dim_3) 36 | { 37 | constexpr size_t dim = 3; 38 | CellList cl; 39 | cl[0][{1, 1}].add_interval({1, 2}); 40 | cl[5][{0, 0}].add_interval({0, 1}); 41 | CellArray ca{cl}; 42 | 43 | samurai::make_graduation(ca); 44 | EXPECT_TRUE(is_graduated(ca)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /docs/source/reference/snippet/subset_1d.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | int main() 8 | { 9 | constexpr std::size_t dim = 1; 10 | 11 | // Mesh creation 12 | samurai::CellList cl; 13 | cl[0][{}].add_interval({0, 4}); 14 | cl[1][{}].add_interval({0, 4}); 15 | cl[1][{}].add_interval({6, 8}); 16 | 17 | samurai::CellArray ca{cl}; 18 | 19 | // Initialize field u on this mesh 20 | auto u = samurai::make_scalar_field("u", ca); 21 | samurai::for_each_cell(ca, 22 | [&](auto cell) 23 | { 24 | u[cell] = cell.indices[0]; 25 | }); 26 | 27 | std::cout << "before projection" << std::endl; 28 | std::cout << u << std::endl; 29 | 30 | // Make projection on the intersection 31 | auto subset = samurai::intersection(ca[0], ca[1]).on(0); 32 | subset( 33 | [&](const auto& i, auto) 34 | { 35 | u(0, i) = 0.5 * (u(1, 2 * i) + u(1, 2 * i + 1)); 36 | }); 37 | 38 | std::cout << "after projection" << std::endl; 39 | std::cout << u << std::endl; 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /include/samurai/samurai_config.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | namespace samurai 7 | { 8 | static constexpr bool disable_color = true; 9 | 10 | template 11 | struct Interval; 12 | 13 | template 14 | inline auto prediction(T1& field_dest, const T2& field_src); 15 | 16 | namespace default_config 17 | { 18 | static constexpr std::size_t max_level = 20; 19 | static constexpr int ghost_width = 1; 20 | static constexpr int graduation_width = 1; 21 | static constexpr int prediction_stencil_radius = 1; 22 | 23 | using index_t = signed long long int; 24 | using value_t = int; 25 | using interval_t = Interval; 26 | 27 | inline auto default_prediction_fn = [](auto& new_field, const auto& old_field) // cppcheck-suppress constParameterReference 28 | { 29 | constexpr std::size_t pred_order = std::decay_t::mesh_t::config::prediction_stencil_radius; 30 | return prediction(new_field, old_field); 31 | }; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Mozilla 4 | AlignArrayOfStructures: Left 5 | AlignConsecutiveAssignments: 6 | Enabled: true 7 | AlignEscapedNewlines: Left 8 | AlignOperands: AlignAfterOperator 9 | AllowAllArgumentsOnNextLine: false 10 | AllowShortFunctionsOnASingleLine: None 11 | AllowShortLambdasOnASingleLine: Empty 12 | AlwaysBreakAfterDefinitionReturnType: None 13 | AlwaysBreakAfterReturnType: None 14 | BreakBeforeBinaryOperators: NonAssignment 15 | BreakBeforeBraces: Allman 16 | BreakInheritanceList: AfterComma 17 | BreakStringLiterals: false 18 | ColumnLimit: 140 19 | ConstructorInitializerIndentWidth: 4 20 | ContinuationIndentWidth: 4 21 | Cpp11BracedListStyle: true 22 | EmptyLineAfterAccessModifier: Always 23 | EmptyLineBeforeAccessModifier: Always 24 | ExperimentalAutoDetectBinPacking: true 25 | IndentWidth: 4 26 | InsertBraces: true 27 | InsertNewlineAtEOF: true 28 | KeepEmptyLinesAtTheStartOfBlocks: false 29 | NamespaceIndentation: All 30 | PackConstructorInitializers: Never 31 | PenaltyBreakAssignment: 100000000 32 | PenaltyBreakBeforeFirstCallParameter: 0 33 | PenaltyBreakComment: 10 34 | PenaltyBreakTemplateDeclaration: 0 35 | PenaltyExcessCharacter: 10 36 | PenaltyReturnTypeOnItsOwnLine: 10 37 | SeparateDefinitionBlocks: Always 38 | SpaceAfterTemplateKeyword: true 39 | SpacesInContainerLiterals: false 40 | -------------------------------------------------------------------------------- /docs/source/howto/snippet/loop/for_each_interval_field.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | static constexpr std::size_t dim = 2; 9 | 10 | samurai::Box box({-1.0, -1.0}, {1.0, 1.0}); 11 | auto config = samurai::mesh_config().min_level(0).max_level(2); 12 | auto mesh = samurai::mra::make_mesh(box, config); 13 | 14 | auto field = samurai::make_scalar_field("u", mesh); 15 | 16 | samurai::for_each_interval(mesh, 17 | [&](std::size_t level, const auto& i, const auto& index) 18 | { 19 | auto j = index[0]; 20 | auto x = mesh.cell_length(level) * (xt::arange(i.start, i.end) + 0.5) + mesh.origin_point()[0]; 21 | auto y = mesh.cell_length(level) * (j + 0.5) + mesh.origin_point()[1]; 22 | 23 | field(level, i, j) = xt::exp(-((x - 0.5) * (x - 0.5) + (y - 0.5) * (y - 0.5)) * 20.0); 24 | 25 | std::cout << "Level: " << level << ", x: " << x << ", y: " << y << std::endl; 26 | }); 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /include/samurai/mesh_interval.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | using namespace xt::placeholders; 6 | 7 | namespace samurai 8 | { 9 | /** 10 | * Stores the triplet (level, i, index) 11 | */ 12 | template 13 | struct MeshInterval 14 | { 15 | using interval_t = TInterval; 16 | using coord_type = xt::xtensor_fixed>; 17 | 18 | std::size_t level; 19 | interval_t i; 20 | coord_type index; 21 | 22 | MeshInterval() 23 | : level(0) 24 | { 25 | } 26 | 27 | MeshInterval(std::size_t _level) 28 | : level(_level) 29 | { 30 | } 31 | 32 | MeshInterval(std::size_t _level, const interval_t& _i, const coord_type& _index) 33 | : level(_level) 34 | , i(_i) 35 | , index(_index) 36 | { 37 | } 38 | }; 39 | 40 | template 41 | MeshInterval 42 | operator+(const MeshInterval& mi, const xt::xtensor_fixed>& translate) 43 | { 44 | return (mi.level, mi.i + translate(0), mi.index + xt::view(translate, xt::range(1, _))); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /include/samurai/storage/utils.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include "layout_config.hpp" 7 | 8 | namespace samurai 9 | { 10 | namespace detail 11 | { 12 | template 13 | struct static_size_first : std::false_type 14 | { 15 | }; 16 | 17 | template 18 | requires(size > 1) 19 | struct static_size_first : std::true_type 20 | { 21 | }; 22 | 23 | template 24 | requires(size > 1) 25 | struct static_size_first : std::true_type 26 | { 27 | }; 28 | 29 | template 30 | struct static_size_first<1, SOA, false, L> : std::true_type 31 | { 32 | }; 33 | 34 | template 35 | static constexpr bool static_size_first_v = static_size_first::value; 36 | } 37 | 38 | template 39 | struct range_t 40 | { 41 | T start; 42 | T end; 43 | T step = 1; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /docs/source/tutorial/graduation.rst: -------------------------------------------------------------------------------- 1 | Algorithm examples for the graduation of a mesh 2 | =============================================== 3 | 4 | .. toctree:: 5 | :hidden: 6 | 7 | graduation_case_1 8 | graduation_case_2 9 | graduation_case_3 10 | 11 | This tutorial will highlight three different ways to make the graduation of a mesh. A mesh is graduated when the neighbors of a cell at level :math:`l` are at most at the next or previous level. This process is important when we use adaptive mesh refinement techniques. The graduation ensures that the reconstruction of the ghost cell values of level `l` can be made with the previous or the next level. 12 | 13 | The three cases that will be considered in the following are: 14 | 15 | - :doc:`Case 1 <./graduation_case_1>` 16 | 17 | The mesh is constituted of cells at different levels but without overlap and we want a graduated mesh at the end. 18 | 19 | - :doc:`Case 2 <./graduation_case_2>` 20 | 21 | The mesh is constituted of cells at different levels with overlap and we want a graduated mesh at the end. 22 | 23 | - :doc:`Case 3 <./graduation_case_3>` 24 | 25 | The mesh is already graduated and a mesh adaptation algorithm is performed on it. A tag array indicates which cells must be refined or kept to build the new mesh. We want to modify the tag array to be sure that the new mesh created from the tag will be graduated. 26 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_2/update_sol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | template 9 | void update_sol(double dt, Field& phi, Field& phi_np1) 10 | { 11 | auto& mesh = phi.mesh(); 12 | 13 | samurai::for_each_interval(mesh, 14 | [&](std::size_t level, const auto& interval, auto) 15 | { 16 | using interval_t = decltype(interval); 17 | 18 | const double dx = mesh.cell_length(level); 19 | 20 | // remove the extrema to avoid problem with the boundaries 21 | auto ii = interval_t{interval.start + 1, interval.end - 1}; 22 | 23 | // upwind scheme 24 | phi_np1(level, ii) = phi(level, ii) 25 | - .5 * dt / dx * (pow(phi(level, ii), 2.) - pow(phi(level, ii - 1), 2.)); 26 | // phi_np1(level, ii) = phi(level, ii) - .5*dt/dx*(phi(level, 27 | // ii)*phi(level, ii) - phi(level, ii - 1)*phi(level, ii - 1)); 28 | }); 29 | 30 | std::swap(phi.array(), phi_np1.array()); 31 | } 32 | -------------------------------------------------------------------------------- /conanfile.py: -------------------------------------------------------------------------------- 1 | from conan import ConanFile 2 | from conan.tools.cmake import CMake, cmake_layout 3 | 4 | class SamuraiConan(ConanFile): 5 | settings = "os", "compiler", "build_type", "arch" 6 | options = { 7 | "build_demos": [True, False], 8 | "build_tests": [True, False], 9 | } 10 | default_options = { 11 | "build_demos": False, 12 | "build_tests": False, 13 | } 14 | generators = ["CMakeDeps", "CMakeToolchain"] 15 | default_options = { 16 | "hdf5/*:shared": False, 17 | "highfive/*:with_boost": False, 18 | "highfive/*:with_opencv": False, 19 | "highfive/*:with_eigen": False, 20 | "rapidcheck/*:enable_gtest": True, 21 | } 22 | 23 | def layout(self): 24 | cmake_layout(self) 25 | 26 | def requirements(self): 27 | self.requires("xtensor/0.24.7") 28 | self.requires("highfive/2.9.0") 29 | self.requires("hdf5/1.14.3") 30 | self.requires("pugixml/1.14") 31 | self.requires("cli11/2.4.2") 32 | self.requires("cxxopts/3.2.0") 33 | self.requires("fmt/10.2.1") 34 | self.requires("rapidcheck/cci.20230815") 35 | if self.options.build_demos: 36 | self.requires("cgal/5.6.1") 37 | if self.options.build_tests: 38 | self.requires("gtest/1.14.0") 39 | 40 | def build(self): 41 | cmake = CMake(self) 42 | cmake.configure() 43 | cmake.build() 44 | -------------------------------------------------------------------------------- /docs/source/howto/cmake.md: -------------------------------------------------------------------------------- 1 | # How-to: create a CMake project for samurai 2 | 3 | This how-to guide will show you how to create a simple CMake project that uses samurai. 4 | 5 | Before creating a CMake project, make sure you have samurai installed. If you haven't installed it yet, please refer to the installation guide [here](installation.md). 6 | 7 | ## Create a CMake project 8 | 9 | To create a CMake project that uses samurai, you need to create a `CMakeLists.txt` file in your project directory. Here is a simple example of a `CMakeLists.txt` file that includes samurai: 10 | 11 | ```{literalinclude} snippet/cmake/CMakeLists.txt 12 | :language: cmake 13 | ``` 14 | 15 | In this example, we first specify the minimum required version of CMake and the project name. Then, we use the `find_package` command to locate the samurai library. Finally, we create an executable target called `my_executable` and link it with the samurai library. 16 | 17 | ## Build the CMake project 18 | 19 | Let's create a simple `main.cpp` file to test our CMake project: 20 | 21 | ```{literalinclude} snippet/cmake/main.cpp 22 | :language: c++ 23 | ``` 24 | 25 | To build the CMake project, you can use the following commands: 26 | 27 | ```bash 28 | cmake -S . -B build 29 | cmake --build build 30 | ``` 31 | 32 | This will generate the build files in the `build` directory and then compile the project. 33 | 34 | And that's it! You have successfully created a CMake project that uses samurai. 35 | -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_level.drawio: -------------------------------------------------------------------------------- 1 | 7Zpbj+IgFIB/jY+btFA7+KjOZTeZTTbxYXfmjWnRksViEG/765daai90Umtqq5M+CQc4FL7D5RwZwOly/yLwKvjJfcIGwPL3A/g4AMC2EFI/keQQS0bIjQULQX1dKRXM6D+StNTSDfXJOldRcs4kXeWFHg9D4smcDAvBd/lqc87yva7wghiCmYeZKf1NfRloqe2O0oLvhC4C3TUCD3HBEieV9UjWAfb5LiOCTwM4FZzLOLXcTwmLJi+Zl7jd8yelpw8TJJTnNHjcjEfvzpOYkh8vr+9vEwDd8TetZYvZRg9Yf6w8JDNAQn8cTaTKhTxUwkkgl0zlbJVcS8H/nmYGKsmcMjbljItja+hjgubeqWamxPUQ+ZirkrhH4hsg0pHZp/lShkb4kkhxUFV2KZGhnuUgwyKRCcKwpNu8eqwNY3FSd+rhF6eqY2BpIwaW1qNNGCArr2LNN8IjulWWQEHREFQoklgsiDQUqURm2KnoCLgGbNDDrg0bWhfCNqzGbRc27GFXw0ZNwUbdwnZ62JWwodsQ7KKitmEPe9iVsB2nIdhFRW3DdnvYlbCL96qLYRsXtJZhP1wd9pAg3ymDjcAHdN07gF3cfZ1LYbuoQtGVYScebk+7Dm3Q0KENW/a97Ot72vdP21iSl9IuKmqd9vVd7funXTxtL6ZtnP9t0zZ9bcvALcleljFOyGkbyGLWIszoIlRZT2EjSj7ZEiGph9lYFyyp70fdTHYBlWS2wl7U507glZIJvgl9En2+FannoXzGS8qiqZqtiCcFZlqug6/ALbU/PUTVNdnXtafESy5er5K7dcbenBJ7K9pF1rRyLGuDM/1muwdngoPFWFbn4Ewf2Nxge3DpTngz4Ex/FvbgTHBOMcbUOTjTN+23yjJwxbuI2zU41G+V54AbouGNgRsZ4F7J9vj3ev2Vlw3nfRYA7AJlEyuueqe0QQk451rgks5KwNV3C7IO3Wcu4NcAV7bgWgbXbIwG1JhOsqfyj9YSpd8y6ce9ZnPMHHRmcKZ3r77+6EZXGmxnf9XYeTsYwoZCfG0HdBNr+VLmczOhwEvD/KjjMD9o9iFGHau4dcZFNPf7sKrZ9xe3sfLPODjiK+rdHxyVD/wuNh+VTR94xtXTZ7Lw6T8= 2 | -------------------------------------------------------------------------------- /docs/source/howto/timers.md: -------------------------------------------------------------------------------- 1 | # How-to: Timers in samurai 2 | 3 | In this how-to guide, we will show you how to use timers in samurai. Timers are useful for measuring the execution time of different parts of your code, which can help you identify performance bottlenecks and optimize your simulations. 4 | 5 | ## Get default timers output 6 | 7 | By default, samurai provides built-in timers that measure the execution time of various components, such as mesh refinement, field updates, and I/O operations. To print the default timers output, you can use the `--timers` command line option when running your simulation. This will print a summary of the timers to the console at the end of the simulation. 8 | 9 | ## Using timers 10 | 11 | You can also create your own timers to measure specific parts of your code. samurai provides a simple timer class that you can use to start and stop timers. Here is an example of how to use timers in your code: 12 | 13 | ```{literalinclude} snippet/timers/custom_timer.cpp 14 | :language: c++ 15 | ``` 16 | 17 | In this example, we create a 2D multi-resolution mesh and a scalar field on the mesh. We then use the `times::timers.start("init field")` and `times::timers.stop("init field")` functions to start and stop a timer named "init field" around the loop that initializes the field values. This will measure the time taken to initialize the field. 18 | 19 | ```{note} 20 | Make sure to include the header file `samurai/timers.hpp` to use the timer functionality. 21 | -------------------------------------------------------------------------------- /tests/test_cell.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | namespace samurai 9 | { 10 | TEST(cell, length) 11 | { 12 | auto indices = xt::xtensor_fixed>({1, 1}); 13 | double scaling_factor = 1; 14 | Cell<2, Interval> c{ 15 | {0, 0}, 16 | scaling_factor, 17 | 1, 18 | indices, 19 | 0 20 | }; 21 | EXPECT_EQ(c.length, 0.5); 22 | } 23 | 24 | TEST(cell, center) 25 | { 26 | auto indices = xt::xtensor_fixed>({1, 1}); 27 | double scaling_factor = 1; 28 | Cell<2, Interval> c{ 29 | {0, 0}, 30 | scaling_factor, 31 | 1, 32 | indices, 33 | 0 34 | }; 35 | xt::xarray expected{.75, .75}; 36 | EXPECT_EQ(c.center(), expected); 37 | } 38 | 39 | TEST(cell, first_corner) 40 | { 41 | auto indices = xt::xtensor_fixed>({1, 1}); 42 | double scaling_factor = 1; 43 | Cell<2, Interval> c{ 44 | {0, 0}, 45 | scaling_factor, 46 | 1, 47 | indices, 48 | 0 49 | }; 50 | xt::xarray expected{.5, .5}; 51 | EXPECT_EQ(c.corner(), expected); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /docs/source/reference/figures/subset_1d.drawio: -------------------------------------------------------------------------------- 1 | 7Ztbb5swFMc/TR4nAU4IeUzTdtMu0rRMm9Y3FxzizWDmOJf20880hoAdSkDEWSr6UMGx+Rv7d/Dl2BmAWbR7z2Cy/EIDRAaOFewG4HbgOI7nif+p4WlvAK40hAwHe5N9MMzxM5JGS1rXOECrUkZOKeE4KRt9GsfI5yUbZIxuy9kWlJRLTWCINMPch0S3/sQBX0qr7U4OCR8QDpeyaM8Z7xMimGWWNVktYUC3BRO4G4AZo5Tvr6LdDJG07bJ22T93X5GavxhDMT/lgemn2xA//Pj+7e8w+vg8ZeGvKX4nVTaQrGWF5cvyp6wFUBxM04YUdzGNhfFmySMi7mxxueKM/slbBgjLAhMyo4Syl6dBAJG38POchRTX99DjQqTsS0SBBuJQMztvL+FniEaIsyeRZXsgMpKtvCywyGwMEcjxpiwPpWOEuVxewleKRcGOJX3YkzLSgx3LKius6Jr5SD5UBKDoDK0aIQ5ZiLgmJC4KtT6YXvg2YO30rBuzdlqyVnRszyxq0KOuRW27HbFWhUzDHvawa2GLzrcb2KqQadijHnYtbOB0BFsVMg3b7WHXwtZmVW1hq0KmYY972LWwR12N2aqQadheD7sWttvVmK0KmYY96WHXwh53NWarQqZh231IpUU/3jamormN4ZiKff6gygh5wfAYbc95BK57BbSVYAjo6tPWhM4N+/xhlbcHe9gStqpj+sM+/0L7+lmrwZDWsDUh07TPv/i6ftrqArk1bU3INO3zr76un7Y6RWtNWxMyve1l9bQbL79a09aETNPWJ+Sf0eblTIKlYedox4+xPkawijkkOIyFzRcgkUi82SDGsQ/JVCZEOAjSAm+2S8zRPIF+WvqWwUTYGF3HAUorZKVl0JjfwwiTtPHmCfI5g0Ta5dEIYOXelBaEdk39KeM0ruBU8Dd7eMThVMco+lYJZmNy+uw6I2e3IZcvhquWz2+EXB7guBw5fQcyYfS3aARMY716LY6pOCfMz0JBJKlsX3k+CD5m2S39xV6pXCUNuypuVaDhHYGhRqW6g9Fs4eITuFphv3bEO9G/ta9wMrHE32kj4CvojY+LjbcKy25gOOjoNNsp7KGfFMJoPNO9rA+csKq5TB9ZearqYn1ksx2Z//9z8fo+sv5MXLN1YA/9DfaR4ITNucv0kW7VMZZL9ZFAX0hf9ecCLhNfubI+stkOVw/9qvpIcXv4uck+++E3O+DuHw== 2 | -------------------------------------------------------------------------------- /include/samurai/bc/neumann.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | #include "bc.hpp" 6 | 7 | namespace samurai 8 | { 9 | template 10 | struct NeumannImpl : public Bc 11 | { 12 | INIT_BC(NeumannImpl, 2 * order) // stencil_size = 2*order 13 | 14 | stencil_t get_stencil(constant_stencil_size_t) const override 15 | { 16 | return line_stencil(); 17 | } 18 | 19 | apply_function_t get_apply_function(constant_stencil_size_t, const direction_t&) const override 20 | { 21 | return [](Field& f, const stencil_cells_t& cells, const value_t& value) 22 | { 23 | if constexpr (order == 1) 24 | { 25 | static constexpr std::size_t in = 0; 26 | static constexpr std::size_t out = 1; 27 | 28 | double dx = f.mesh().cell_length(cells[out].level); 29 | f[cells[out]] = dx * value + f[cells[in]]; 30 | } 31 | else 32 | { 33 | static_assert(order <= 1, "The Neumann boundary conditions are only implemented at the first order."); 34 | } 35 | }; 36 | } 37 | }; 38 | 39 | template 40 | struct Neumann 41 | { 42 | template 43 | using impl_t = NeumannImpl; 44 | }; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021, the SAMURAI TEAM. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv/explicit_operator_sum.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "explicit_FV_scheme.hpp" 3 | #include "scheme_operators.hpp" 4 | 5 | namespace samurai 6 | { 7 | template 8 | class Explicit> : public ExplicitFVScheme> 9 | { 10 | public: 11 | 12 | using base_class = ExplicitFVScheme>; 13 | 14 | using scheme_t = typename base_class::scheme_t; 15 | using input_field_t = typename base_class::input_field_t; 16 | using output_field_t = typename base_class::output_field_t; 17 | using size_type = typename base_class::size_type; 18 | using base_class::scheme; 19 | 20 | explicit Explicit(scheme_t& sum_scheme) 21 | : base_class(sum_scheme) 22 | { 23 | } 24 | 25 | void apply(output_field_t& output_field, input_field_t& input_field) override 26 | { 27 | for_each(scheme().operators(), 28 | [&](auto& op) 29 | { 30 | op.apply(output_field, input_field); 31 | }); 32 | } 33 | 34 | void apply(std::size_t d, output_field_t& output_field, input_field_t& input_field) override 35 | { 36 | for_each(scheme().operators(), 37 | [&](auto& op) 38 | { 39 | op.apply(d, output_field, input_field); 40 | }); 41 | } 42 | }; 43 | 44 | } // end namespace samurai 45 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/new_features.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Ask for a new feature 3 | title: "[Feat]: " 4 | labels: ["enhancement", "triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to ask for a new feature! 10 | - type: textarea 11 | id: what 12 | attributes: 13 | label: What do you want? 14 | description: A clear and concise description of what you would like to be able to do with our software. 15 | validations: 16 | required: true 17 | - type: textarea 18 | id: code-example 19 | attributes: 20 | label: A possible usage 21 | description: A code example which shows how to use this new feature. 22 | render: cpp 23 | - type: textarea 24 | id: code-implementation 25 | attributes: 26 | label: A possible implementation 27 | description: A first idea of how this new feature could be implemented. 28 | render: cpp 29 | - type: textarea 30 | id: others 31 | attributes: 32 | label: Other informations 33 | description: Please feel free to provide any other information you feel may be useful for understanding and implementing this new feature. 34 | - type: checkboxes 35 | id: terms 36 | attributes: 37 | label: Code of Conduct 38 | description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/hpc-maths/samurai/blob/master/docs/CODE_OF_CONDUCT.md) 39 | options: 40 | - label: I agree to follow this project's Code of Conduct 41 | required: true 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.yml: -------------------------------------------------------------------------------- 1 | name: Question 2 | description: Ask for clarification of any unclear points. 3 | title: "[Question]: " 4 | labels: ["question", "triage"] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to ask for a new feature! 10 | - type: textarea 11 | id: what 12 | attributes: 13 | label: What do you want? 14 | description: A clear and concise description of what you would like to be able to do with our software. 15 | validations: 16 | required: true 17 | - type: textarea 18 | id: code-example 19 | attributes: 20 | label: A possible usage 21 | description: A code example which shows how to use this new feature. 22 | render: cpp 23 | - type: textarea 24 | id: code-implementation 25 | attributes: 26 | label: A possible implementation 27 | description: A first idea of how this new feature could be implemented. 28 | render: cpp 29 | - type: textarea 30 | id: others 31 | attributes: 32 | label: Other informations 33 | description: Please feel free to provide any other information you feel may be useful for understanding and implementing this new feature. 34 | - type: checkboxes 35 | id: terms 36 | attributes: 37 | label: Code of Conduct 38 | description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/hpc-maths/samurai/blob/master/docs/CODE_OF_CONDUCT.md) 39 | options: 40 | - label: I agree to follow this project's Code of Conduct 41 | required: true 42 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-level-set-0.1.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-level-set-0.1.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-level-set-0.1.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-level-set-0.1.h5:/mesh/fields/phi 13 | 14 | 15 | test_finite_volume_demo_finite-volume-level-set-0.1.h5:/mesh/fields/u_0 16 | 17 | 18 | test_finite_volume_demo_finite-volume-level-set-0.1.h5:/mesh/fields/u_1 19 | 20 | 21 | test_finite_volume_demo_finite-volume-level-set-0.1.h5:/mesh/fields/level 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /demos/multigrid/samurai_new/multigrid/coarsening.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace samurai_new 5 | { 6 | template 7 | Mesh coarsen(const Mesh& mesh) 8 | { 9 | using mesh_id_t = typename Mesh::mesh_id_t; 10 | 11 | typename Mesh::cl_type coarse_cell_list; 12 | if (Mesh::dim == 1) 13 | { 14 | samurai::for_each_interval(mesh[mesh_id_t::cells], 15 | [&](size_t level, const auto& i, const auto&) 16 | { 17 | coarse_cell_list[level - 1][{}].add_interval(i >> 1); 18 | }); 19 | } 20 | else if (Mesh::dim == 2) 21 | { 22 | samurai::for_each_interval(mesh[mesh_id_t::cells], 23 | [&](size_t level, const auto& i, const auto& index) 24 | { 25 | auto j = index[0]; 26 | if (j % 2 == 0) 27 | { 28 | coarse_cell_list[level - 1][{j / 2}].add_interval(i / 2); 29 | } 30 | }); 31 | } 32 | return Mesh(coarse_cell_list, mesh.min_level() - 1, mesh.max_level() - 1); 33 | } 34 | 35 | /*template 36 | Mesh refine(const Mesh& mesh) 37 | { 38 | assert(false && "refine() not implemented"); 39 | }*/ 40 | 41 | } // namespace samurai_new 42 | -------------------------------------------------------------------------------- /include/samurai/mr/config.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace samurai 9 | { 10 | class mra_config 11 | { 12 | public: 13 | 14 | auto& epsilon(double eps) 15 | { 16 | m_epsilon = eps; 17 | return *this; 18 | } 19 | 20 | auto& epsilon() const 21 | { 22 | return m_epsilon; 23 | } 24 | 25 | auto& regularity(double reg) 26 | { 27 | m_regularity = reg; 28 | return *this; 29 | } 30 | 31 | auto& regularity() const 32 | { 33 | return m_regularity; 34 | } 35 | 36 | auto& relative_detail(bool rel) 37 | { 38 | m_rel_detail = rel; 39 | return *this; 40 | } 41 | 42 | auto& relative_detail() const 43 | { 44 | return m_rel_detail; 45 | } 46 | 47 | void parse_args() 48 | { 49 | if (args::epsilon != std::numeric_limits::infinity()) 50 | { 51 | m_epsilon = args::epsilon; 52 | } 53 | if (args::regularity != std::numeric_limits::infinity()) 54 | { 55 | m_regularity = args::regularity; 56 | } 57 | if (args::rel_detail) 58 | { 59 | m_rel_detail = true; 60 | } 61 | } 62 | 63 | private: 64 | 65 | double m_epsilon = 1e-4; 66 | double m_regularity = 1.; 67 | bool m_rel_detail = false; 68 | }; 69 | } 70 | -------------------------------------------------------------------------------- /tests/reference/finite_volume/test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.xdmf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5:/mesh/connectivity 7 | 8 | 9 | test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5:/mesh/points 10 | 11 | 12 | test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5:/mesh/fields/phi 13 | 14 | 15 | test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5:/mesh/fields/u_0 16 | 17 | 18 | test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5:/mesh/fields/u_1 19 | 20 | 21 | test_finite_volume_demo_finite-volume-level-set-from-scratch-0.1.h5:/mesh/fields/level 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /tests/test_domain_with_hole.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace samurai 6 | { 7 | 8 | TEST(domain_with_hole, substract_box) 9 | { 10 | static constexpr std::size_t dim = 2; 11 | 12 | std::size_t level = 3; 13 | auto mesh_cfg = mesh_config().min_level(level).max_level(level); 14 | 15 | using Mesh = decltype(mra::make_empty_mesh(mesh_cfg)); 16 | using mesh_id_t = typename Mesh::mesh_id_t; 17 | using cl_t = typename Mesh::cl_type; 18 | using lca_t = typename Mesh::lca_type; 19 | using Box = samurai::Box; 20 | 21 | const Box domain_box({-1., -1.}, {1., 1.}); 22 | const Box hole_box({0.0, 0.0}, {0.2, 0.2}); 23 | 24 | auto origin_point = domain_box.min_corner(); 25 | double scaling_factor = 0.2; // this value ensures that the hole is representable at level 0 26 | 27 | auto domain_lca = lca_t(level, domain_box, -1, scaling_factor); 28 | auto hole_lca = lca_t(level, hole_box, origin_point, -1, scaling_factor); 29 | 30 | auto domain_with_hole_set = samurai::difference(domain_lca, hole_lca); 31 | 32 | cl_t domain_with_hole_cl(origin_point, scaling_factor); 33 | domain_with_hole_set( 34 | [&](const auto& interval, const auto& index_y) 35 | { 36 | domain_with_hole_cl[level][index_y].add_interval({interval}); 37 | }); 38 | 39 | auto mesh = samurai::mra::make_mesh(domain_with_hole_cl, mesh_cfg); 40 | 41 | EXPECT_EQ(mesh.nb_cells(mesh_id_t::cells), domain_lca.nb_cells() - hole_lca.nb_cells()); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /docs/source/howto/options.md: -------------------------------------------------------------------------------- 1 | # How-to: set options in samurai 2 | 3 | In this how-to guide, we will show you how to set various options in samurai. Options allow you to customize the behavior of samurai components. We use CLI11 library to handle options. Several options are already defined in samurai, but you can also define your own options. 4 | 5 | ## Setting predefined options 6 | 7 | samurai provides several predefined options. You have to parse them to use them. Here is an example of how to use predefined options: 8 | 9 | ```{literalinclude} snippet/options/predefined_options.cpp 10 | :language: c++ 11 | ``` 12 | 13 | To see the available predefined options, you can run the compiled program with the `--help` flag: 14 | 15 | ```bash 16 | ./your_program --help 17 | ``` 18 | 19 | or 20 | 21 | ```bash 22 | ./your_program -h 23 | ``` 24 | 25 | ## Defining custom options 26 | 27 | You can also define your own options using the CLI11 library. Here is an example of how to define and use custom options in samurai: 28 | 29 | ```{literalinclude} snippet/options/custom_options.cpp 30 | :language: c++ 31 | ``` 32 | 33 | For more information on how to use CLI11 to define options, please refer to the [CLI11 documentation](https://cliutils.github.io/CLI11/book/). 34 | 35 | ## Use a TOML configuration file 36 | 37 | With CLI11, you can also use a configuration file to set options. samurai supports TOML configuration files. Here is an example of how to use a TOML configuration file to set options: 38 | 39 | ```toml 40 | my-option = 2 41 | my-flag = true 42 | ``` 43 | 44 | In this example, we define two options: `my-option` and `my-flag`. The TOML file should be passed to the program using the `--config` flag: 45 | 46 | ```bash 47 | ./your_program --config config.toml 48 | ``` 49 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_1/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "init_sol.hpp" 13 | 14 | namespace fs = std::filesystem; 15 | 16 | /** 17 | * What will we learn ? 18 | * ==================== 19 | * 20 | * - create a field 21 | * - initialize this field 22 | * - save and plot a field 23 | * 24 | */ 25 | 26 | int main(int argc, char* argv[]) 27 | { 28 | auto& app = samurai::initialize("Tutorial AMR Burgers 1D step 1", argc, argv); 29 | 30 | // Output parameters 31 | fs::path path = fs::current_path(); 32 | std::string filename = "amr_1d_burgers_step_1"; 33 | 34 | app.add_option("--path", path, "Output path")->capture_default_str()->group("Output"); 35 | app.add_option("--filename", filename, "File name prefix")->capture_default_str()->group("Output"); 36 | SAMURAI_PARSE(argc, argv); 37 | 38 | if (!fs::exists(path)) 39 | { 40 | fs::create_directory(path); 41 | } 42 | 43 | constexpr std::size_t dim = 1; // cppcheck-suppress unreadVariable 44 | const std::size_t init_level = 6; 45 | 46 | const samurai::Box box({-3}, {3}); 47 | samurai::CellArray mesh; 48 | 49 | mesh[init_level] = {init_level, box, 0, 1}; 50 | 51 | ////////////////////////////////// 52 | auto phi = init_sol(mesh); 53 | ///////////////////////////////// 54 | 55 | std::cout << mesh << "\n"; 56 | 57 | samurai::save(path, filename, mesh, phi); 58 | 59 | samurai::finalize(); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_0/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace fs = std::filesystem; 12 | 13 | /** 14 | * What will we learn ? 15 | * ==================== 16 | * 17 | * - construct 1D uniform grid from a Box 18 | * - print mesh information 19 | * - save and plot a mesh 20 | * 21 | */ 22 | 23 | int main(int argc, char* argv[]) 24 | { 25 | auto& app = samurai::initialize("Tutorial AMR Burgers 1D step 0", argc, argv); 26 | 27 | // Output parameters 28 | fs::path path = fs::current_path(); 29 | std::string filename = "amr_1d_burgers_step_0"; 30 | 31 | app.add_option("--path", path, "Output path")->capture_default_str()->group("Output"); 32 | app.add_option("--filename", filename, "File name prefix")->capture_default_str()->group("Output"); 33 | SAMURAI_PARSE(argc, argv); 34 | 35 | if (!fs::exists(path)) 36 | { 37 | fs::create_directory(path); 38 | } 39 | 40 | constexpr std::size_t dim = 1; // cppcheck-suppress unreadVariable 41 | const std::size_t init_level = 4; 42 | 43 | /** 44 | * 45 | * level: 1 |--|--|--|--|--|--|--|--| 46 | * 47 | * level: 0 |-----|-----|-----|-----| 48 | * -2 -1 0 1 2 49 | */ 50 | 51 | const samurai::Box box({-2}, {2}); 52 | samurai::CellArray mesh; 53 | 54 | mesh[init_level] = {init_level, box, 0, 1}; 55 | 56 | std::cout << mesh << "\n"; 57 | 58 | samurai::save(path, filename, mesh); 59 | 60 | samurai::finalize(); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /include/samurai/assert_log_trace.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define SAMURAI_ASSERT(condition, msg) \ 6 | do \ 7 | { \ 8 | if (!(condition)) \ 9 | { \ 10 | std::cerr << "Assertion failed \nin " << __FILE__ << "\n @line " << __LINE__ << ": " << msg << std::endl; \ 11 | std::terminate(); \ 12 | } \ 13 | } while (false) 14 | 15 | // #ifdef NDEBUG 16 | #define SAMURAI_LOG(msg) \ 17 | do \ 18 | { \ 19 | std::cerr << "SMR::Log:: " << msg << std::endl; \ 20 | } while (0) 21 | 22 | #define SAMURAI_TRACE(msg) \ 23 | do \ 24 | { \ 25 | std::cerr << "SMR::Trace[line " << __LINE__ << "] :" << msg << std::endl; \ 26 | } while (0) 27 | // #else 28 | // #define MGS_LOG( msg ) 29 | // #endif 30 | -------------------------------------------------------------------------------- /include/samurai/petsc/manual_assembly.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "matrix_assembly.hpp" 3 | 4 | namespace samurai 5 | { 6 | namespace petsc 7 | { 8 | 9 | template 10 | class ManualAssembly : public MatrixAssembly 11 | { 12 | public: 13 | 14 | using scheme_t = ManualAssembly; 15 | using field_t = UnknownField; 16 | 17 | private: 18 | 19 | UnknownField* m_unknown = nullptr; 20 | 21 | public: 22 | 23 | UnknownField& unknown() const 24 | { 25 | return *m_unknown; 26 | } 27 | 28 | void set_unknown(UnknownField& unknown) 29 | { 30 | m_unknown = &unknown; 31 | } 32 | 33 | void sparsity_pattern_boundary(std::vector&) const override 34 | { 35 | } 36 | 37 | void sparsity_pattern_projection(std::vector&) const override 38 | { 39 | } 40 | 41 | void sparsity_pattern_prediction(std::vector&) const override 42 | { 43 | } 44 | 45 | void assemble_boundary_conditions(Mat&) override 46 | { 47 | } 48 | 49 | void assemble_projection(Mat&) override 50 | { 51 | } 52 | 53 | void assemble_prediction(Mat&) override 54 | { 55 | } 56 | 57 | void insert_value_on_diag_for_useless_ghosts(Mat&) override 58 | { 59 | } 60 | 61 | template 62 | void for_each_useless_ghost_row(Func&&) const 63 | { 64 | } 65 | }; 66 | 67 | } // end namespace petsc 68 | } // end namespace samurai 69 | -------------------------------------------------------------------------------- /docs/source/howto/box.md: -------------------------------------------------------------------------------- 1 | # How-to: create a samurai domain using boxes 2 | 3 | In this how-to guide, we will show you how to create a samurai domain using boxes. Boxes are a simple way to define a rectangular domain in samurai. You can create complex domains by combining multiple boxes and make differences between them. 4 | 5 | First, make sure you have samurai installed. If you haven't installed it yet, please refer to the installation guide [here](installation.md). 6 | 7 | ## A simple example 8 | 9 | Let's start with a simple example of creating a domain using one box. 10 | 11 | ```{literalinclude} snippet/box/3d_box.cpp 12 | :language: c++ 13 | ``` 14 | 15 | In this example, we create a 3D box with the lower corner at $(0.0, 0.0, 0.0)$ and the upper corner at $(1.0, 1.0, 1.0)$. 16 | 17 | If you want to create a 2D box, you can do it following the same principle as this: 18 | 19 | ```{literalinclude} snippet/box/2d_box.cpp 20 | :language: c++ 21 | ``` 22 | 23 | In this example, we create a 2D box with the lower corner at $(-1.0, -1.0)$ and the upper corner at $(1.0, 1.0)$. 24 | 25 | That's it! You have successfully created a samurai domain using boxes. You can now use this domain to create meshes, fields, and perform simulations. 26 | 27 | To create a mesh from the box, please refer to the mesh how-to guide [here](mesh.md). 28 | 29 | ## Combining multiple boxes 30 | 31 | You can also create more complex domains by combining multiple boxes. For example, you can create a domain that is the union of two boxes: 32 | 33 | ```{literalinclude} snippet/box/2d_box_with_hole.cpp 34 | :language: c++ 35 | ``` 36 | 37 | In this example, we first create a box from $(-1.0, -1.0)$ to $(1.0, 1.0)$, and then we remove a smaller box from $(0.0, 0.0)$ to $(0.4, 0.4)$. The `DomainBuilder` class allows you to easily add and remove boxes to create complex domains. 38 | -------------------------------------------------------------------------------- /tests/test_stencil.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | namespace samurai 7 | { 8 | template 9 | class stencil_test : public ::testing::Test 10 | { 11 | }; 12 | 13 | using stencil_test_types = ::testing:: 14 | Types, std::integral_constant, std::integral_constant>; 15 | 16 | TYPED_TEST_SUITE(stencil_test, stencil_test_types, ); 17 | 18 | TYPED_TEST(stencil_test, convert_for_direction) 19 | { 20 | static constexpr std::size_t dim = TypeParam::value; 21 | 22 | // Stencil in the x direction 23 | constexpr std::size_t x_direction = 0; 24 | constexpr std::size_t stencil_size = 2; 25 | auto stencil_in_x = samurai::line_stencil(); 26 | 27 | // Check that the second vector of the rotated stencil corresponds to the direction 28 | // (the first vector is 0, the stencil center) 29 | samurai::for_each_cartesian_direction( 30 | [&](const auto& direction) 31 | { 32 | auto rotated_stencil = samurai::convert_for_direction(stencil_in_x, direction); 33 | 34 | samurai::DirectionVector rotated_dir = xt::view(rotated_stencil, 1); 35 | EXPECT_EQ(rotated_dir, direction); 36 | }); 37 | 38 | samurai::for_each_diagonal_direction( 39 | [&](const auto& direction) 40 | { 41 | auto rotated_stencil = samurai::convert_for_direction(stencil_in_x, direction); 42 | 43 | samurai::DirectionVector rotated_dir = xt::view(rotated_stencil, 1); 44 | EXPECT_EQ(rotated_dir, direction); 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /include/samurai/memory.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include "level_cell_array.hpp" 11 | 12 | namespace samurai 13 | { 14 | // Compute the memory usage of samurai data structure for the mesh in bytes 15 | template 16 | std::size_t memory_usage(const LevelCellArray& lca) 17 | { 18 | std::size_t mem = lca.nb_intervals() * sizeof(TInterval); 19 | 20 | for (std::size_t d = 1; d < Dim; ++d) 21 | { 22 | mem += lca.offsets(d).size() * sizeof(std::size_t); 23 | } 24 | mem += sizeof(std::size_t); 25 | return mem; 26 | } 27 | 28 | template 29 | std::size_t memory_usage(const CellArray& ca) 30 | { 31 | std::size_t mem = 0; 32 | for (std::size_t level = ca.min_level(); level <= ca.max_level(); ++level) 33 | { 34 | mem += memory_usage(ca[level]); 35 | } 36 | return mem; 37 | } 38 | 39 | template 40 | std::size_t memory_usage(const Mesh_base& mesh, bool verbose = false) 41 | { 42 | using mesh_id_t = typename Mesh_base::mesh_id_t; 43 | std::size_t mem = 0; 44 | for (std::size_t i = 0; i < static_cast(mesh_id_t::count); ++i) 45 | { 46 | auto id = static_cast(i); 47 | std::size_t mem_id = memory_usage(mesh[id]); 48 | if (verbose) 49 | { 50 | std::cout << fmt::format("Mesh {}: {}", id, mem_id) << std::endl; 51 | } 52 | mem += mem_id; 53 | } 54 | return mem; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/test_find.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace samurai 9 | { 10 | TEST(find, test) 11 | { 12 | static constexpr std::size_t dim = 2; 13 | using Box = samurai::Box; 14 | Box box({-1., -1.}, {1., 1.}); 15 | 16 | auto mesh_cfg = mesh_config().min_level(2).max_level(6); 17 | auto mesh = mra::make_mesh(box, mesh_cfg); 18 | 19 | auto u = samurai::make_scalar_field("u", 20 | mesh, 21 | [](const auto& coords) 22 | { 23 | const auto& x = coords(0); 24 | const auto& y = coords(1); 25 | return (x >= -0.8 && x <= -0.3 && y >= 0.3 && y <= 0.8) ? 1. : 0.; 26 | }); 27 | 28 | auto MRadaptation = samurai::make_MRAdapt(u); 29 | auto mra_config = samurai::mra_config().epsilon(1e-3); 30 | MRadaptation(mra_config); 31 | 32 | using coords_t = typename decltype(mesh)::cell_t::coords_t; 33 | coords_t coords = {0.4, 0.8}; 34 | auto cell = samurai::find_cell(mesh, coords); 35 | 36 | EXPECT_TRUE(cell.length > 0); // cell found 37 | EXPECT_TRUE(static_cast(cell.index) < mesh.nb_cells()); // cell index makes sense 38 | EXPECT_TRUE(xt::all(cell.corner() <= coords && coords <= (cell.corner() + cell.length))); // coords in cell 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv/flux_based/flux_based_scheme.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../../arguments.hpp" 3 | #include "../../../interface.hpp" 4 | #include "../../../reconstruction.hpp" 5 | #include "../../explicit_scheme.hpp" 6 | #include "../FV_scheme.hpp" 7 | #include "flux_definition.hpp" 8 | 9 | namespace samurai 10 | { 11 | /** 12 | * @class FluxBasedScheme 13 | */ 14 | template 15 | class FluxBasedScheme 16 | { 17 | }; 18 | 19 | template 20 | auto make_flux_based_scheme(const FluxDefinition& flux_definition) 21 | { 22 | using bdry_cfg = BoundaryConfigFV; 23 | 24 | // cppcheck-suppress knownConditionTrueFalse 25 | if (args::finer_level_flux != 0 && cfg::dim > 1 && cfg::stencil_size > 4 && !args::refine_boundary) 26 | { 27 | std::cout << "Warning: for stencils larger than 4, computing fluxes at max_level may cause issues close to the boundary." 28 | << std::endl; 29 | } 30 | 31 | return FluxBasedScheme(flux_definition); 32 | } 33 | 34 | /** 35 | * is_FluxBasedScheme 36 | */ 37 | template 38 | struct is_FluxBasedScheme : std::false_type 39 | { 40 | }; 41 | 42 | template 43 | struct is_FluxBasedScheme, Scheme> 45 | || std::is_same_v, Scheme>>> 46 | : std::true_type 47 | { 48 | }; 49 | 50 | template 51 | inline constexpr bool is_FluxBasedScheme_v = is_FluxBasedScheme::value; 52 | 53 | } // end namespace samurai 54 | -------------------------------------------------------------------------------- /demos/LBM/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(cxxopts) 2 | 3 | # 1D Paper - Verification of the error estimates 4 | 5 | add_executable(lbm-test-D1Q2 test_D1Q2.cpp) 6 | target_link_libraries(lbm-test-D1Q2 samurai) 7 | 8 | add_executable(lbm-test-D1Q3 test_D1Q3.cpp) 9 | target_link_libraries(lbm-test-D1Q3 samurai) 10 | 11 | add_executable(lbm-test-D1Q5 test_D1Q5.cpp) 12 | target_link_libraries(lbm-test-D1Q5 samurai) 13 | 14 | add_executable(lbm-test-D1Q222 test_D1Q222.cpp) 15 | target_link_libraries(lbm-test-D1Q222 samurai) 16 | 17 | # 1D Paper - Plot solutions 18 | 19 | add_executable(lbm-D1Q2-advection-burgers D1Q2_Advection_and_Burgers.cpp) 20 | target_link_libraries(lbm-D1Q2-advection-burgers samurai) 21 | 22 | add_executable(lbm-D1Q3-shallow-waters-dam D1Q3_Shallow_Waters_Dam.cpp) 23 | target_link_libraries(lbm-D1Q3-shallow-waters-dam samurai) 24 | 25 | add_executable(lbm-D1Q5-shallow-waters-dam D1Q5_Shallow_Waters_Dam.cpp) 26 | target_link_libraries(lbm-D1Q5-shallow-waters-dam samurai) 27 | 28 | add_executable(lbm-D1Q222-euler-sod D1Q222_Euler_Sod.cpp) 29 | target_link_libraries(lbm-D1Q222-euler-sod samurai) 30 | 31 | 32 | # 2D Paper 33 | 34 | add_executable(lbm-D2Q4444-euler-lax-liu D2Q4444_Euler_Lax_Liu.cpp) 35 | target_link_libraries(lbm-D2Q4444-euler-lax-liu samurai) 36 | 37 | add_executable(lbm-D2Q4444-euler-lax-liu-uniform D2Q4444_Euler_Lax_Liu_uniform.cpp) 38 | target_link_libraries(lbm-D2Q4444-euler-lax-liu-uniform samurai) 39 | 40 | add_executable(lbm-D2Q9-navier-stokes-von-karman-street D2Q9_Navier_Stokes_von_Karman_street.cpp) 41 | target_link_libraries(lbm-D2Q9-navier-stokes-von-karman-street samurai) 42 | 43 | # Additional 2D tests 44 | 45 | add_executable(lbm-D2Q4444-euler-implosion D2Q4444_Euler_Implosion.cpp) 46 | target_link_libraries(lbm-D2Q4444-euler-implosion samurai) 47 | 48 | add_executable(lbm-D2Q5444-euler-rayleigh-taylor D2Q5444_Euler_Rayleigh_Taylor.cpp) 49 | target_link_libraries(lbm-D2Q5444-euler-rayleigh-taylor samurai) 50 | -------------------------------------------------------------------------------- /docs/source/howto/field.md: -------------------------------------------------------------------------------- 1 | # How-to: create a samurai field 2 | 3 | Before creating a samurai field, you have to create a mesh. If you don't know how to create a mesh, please refer to the mesh how-to guide [here](mesh.md). 4 | 5 | A samurai field is a data structure that allows you to store and manipulate data on a samurai mesh. Fields can be defined on different mesh types, such as uniform meshes, multi-resolution meshes, and adaptive meshes. 6 | 7 | Two types of fields are available in samurai: 8 | 9 | - **scalar fields**: Fields that store a single value per cell. 10 | - **vector fields**: Fields that store multiple values per cell (e.g., a vector with several components). 11 | 12 | ## Creating a scalar field 13 | 14 | To create a scalar field, you can use the `make_scalar_field` function. Here is a simple example of creating a scalar field on a multi-resolution mesh: 15 | 16 | ```{literalinclude} snippet/field/scalar_field.cpp 17 | :language: c++ 18 | ``` 19 | 20 | In this example, we first create a 2D multi-resolution mesh over the box defined from $(0.0, 0.0)$ to $(1.0, 1.0)$ with a minimum refinement level of 2 and a maximum refinement level of 5. Then, we create a scalar field named "u" on the mesh using the `make_scalar_field` function. The type of the field values is specified as `double`. You can replace `double` with any other data type as needed. 21 | 22 | ## Creating a vector field 23 | 24 | To create a vector field, you can use the `make_vector_field` function. Here is a simple example of creating a vector field with 3 components on a multi-resolution mesh: 25 | 26 | ```{literalinclude} snippet/field/vector_field.cpp 27 | :language: c++ 28 | ``` 29 | 30 | In this example, we create a vector field named "v" with 3 components on the same multi-resolution mesh. The type of the field values is specified as `double`. You can replace `double` with any other data type as needed, and change the number of components by modifying the second template parameter. 31 | -------------------------------------------------------------------------------- /tests/test_adapt.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace samurai 9 | { 10 | 11 | template 12 | class adapt_test : public ::testing::Test 13 | { 14 | }; 15 | 16 | #if __GNUC__ == 11 17 | // The 3d case is broken for gcc-11.4 with gtest for release build type and only in gtest. It works outside... 18 | using adapt_test_types = ::testing::Types, std::integral_constant>; //, 19 | // std::integral_constant>; 21 | #else 22 | using adapt_test_types = ::testing:: 23 | Types, std::integral_constant, std::integral_constant>; 24 | #endif 25 | 26 | TYPED_TEST_SUITE(adapt_test, adapt_test_types, ); 27 | 28 | TYPED_TEST(adapt_test, mutliple_fields) 29 | { 30 | ::samurai::initialize(); 31 | 32 | static constexpr std::size_t dim = TypeParam::value; 33 | 34 | using box_t = Box; 35 | auto mesh_cfg = mesh_config().min_level(2).max_level(4); 36 | auto mesh = mra::make_mesh(box_t{xt::zeros({dim}), xt::ones({dim})}, mesh_cfg); 37 | auto u_1 = make_scalar_field("u_1", mesh); 38 | auto u_2 = make_vector_field("u_2", mesh); 39 | auto u_3 = make_vector_field("u_3", mesh); 40 | 41 | auto adapt = make_MRAdapt(u_1, u_2, u_3); 42 | auto mra_config = samurai::mra_config().regularity(2.); 43 | adapt(mra_config); 44 | ::samurai::finalize(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /demos/tutorial/2D_mesh.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | namespace fs = std::filesystem; 14 | 15 | int main(int argc, char* argv[]) 16 | { 17 | auto& app = samurai::initialize("Create mesh from CellList and save it", argc, argv); 18 | 19 | constexpr std::size_t dim = 2; // cppcheck-suppress unreadVariable 20 | samurai::CellList cl; 21 | 22 | // Output parameters 23 | fs::path path = fs::current_path(); 24 | std::string filename = "2d_mesh_construction"; 25 | 26 | app.add_option("--path", path, "Output path")->capture_default_str()->group("Output"); 27 | app.add_option("--filename", filename, "File name prefix")->capture_default_str()->group("Output"); 28 | SAMURAI_PARSE(argc, argv); 29 | 30 | if (!fs::exists(path)) 31 | { 32 | fs::create_directory(path); 33 | } 34 | 35 | cl[0][{0}].add_interval({0, 4}); 36 | cl[0][{1}].add_interval({0, 1}); 37 | cl[0][{1}].add_interval({3, 4}); 38 | cl[0][{2}].add_interval({0, 1}); 39 | cl[0][{2}].add_interval({3, 4}); 40 | cl[0][{3}].add_interval({0, 3}); 41 | 42 | cl[1][{2}].add_interval({2, 6}); 43 | cl[1][{3}].add_interval({2, 6}); 44 | cl[1][{4}].add_interval({2, 4}); 45 | cl[1][{4}].add_interval({5, 6}); 46 | cl[1][{5}].add_interval({2, 6}); 47 | cl[1][{6}].add_interval({6, 8}); 48 | cl[1][{7}].add_interval({6, 7}); 49 | 50 | cl[2][{8}].add_interval({8, 10}); 51 | cl[2][{9}].add_interval({8, 10}); 52 | cl[2][{14}].add_interval({14, 16}); 53 | cl[2][{15}].add_interval({14, 16}); 54 | 55 | const samurai::CellArray ca{cl}; 56 | 57 | std::cout << ca << std::endl; 58 | 59 | samurai::save(path, filename, ca); 60 | samurai::finalize(); 61 | return 0; 62 | } 63 | -------------------------------------------------------------------------------- /benchmark/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.11) 2 | 3 | if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) 4 | project(samurai-benchmark) 5 | 6 | find_package(samurai REQUIRED CONFIG) 7 | set(SAMURAI_INCLUDE_DIR ${samurai_INCLUDE_DIRS}) 8 | endif () 9 | 10 | message(STATUS "Forcing benchmark build type to Release") 11 | set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) 12 | 13 | include(CheckCXXCompilerFlag) 14 | 15 | string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE) 16 | 17 | include(addGoogleTest) 18 | include(addGoogleBench) 19 | 20 | find_package(Threads) 21 | 22 | set(SAMURAI_BENCHMARKS 23 | benchmark_celllist_construction.cpp 24 | benchmark_search.cpp 25 | benchmark_set.cpp 26 | main.cpp 27 | ) 28 | 29 | # foreach(filename IN LISTS SAMURAI_BENCHMARKS) 30 | # string(REPLACE ".cpp" "" targetname ${filename}) 31 | # add_executable(${targetname} ${COMMON_BASE} ${filename} ${SAMURAI_HEADERS}) 32 | # target_include_directories(${targetname} PRIVATE ${SAMURAI_INCLUDE_DIR}) 33 | # target_link_libraries(${targetname} samurai benchmark::benchmark) 34 | # # gbenchk_add_tests(TARGET ${targetname}) 35 | # endforeach() 36 | 37 | add_executable(bench_samurai ${SAMURAI_BENCHMARKS}) 38 | # target_include_directories(bench_samurai PRIVATE ${SAMURAI_INCLUDE_DIR}) 39 | target_link_libraries(bench_samurai samurai benchmark::benchmark) 40 | 41 | # target_include_directories(bench_samurai_lib PRIVATE ${SAMURAI_INCLUDE_DIR}) 42 | # # if(DOWNLOAD_GTEST OR GTEST_SRC_DIR) 43 | # # add_dependencies(test_samurai_lib gtest_main) 44 | # # endif() 45 | # target_link_libraries(bench_samurai_lib samurai benchmark::benchmark) 46 | 47 | # # set(SAMURAI_BENCHMARK_TARGET benchmark_samurai) 48 | # # add_executable(${SAMURAI_BENCHMARK_TARGET} EXCLUDE_FROM_ALL ${SAMURAI_BENCHMARK} ${SAMURAI_HEADERS}) 49 | # add_executable(benchmark_set benchmark_set.cpp) 50 | # target_link_libraries(benchmark_set samurai benchmark::benchmark) 51 | 52 | # add_custom_target(xbenchmark 53 | # COMMAND benchmark_samurai 54 | # DEPENDS ${SAMURAI_BENCHMARK_TARGET}) 55 | -------------------------------------------------------------------------------- /demos/multigrid/samurai_new/multigrid/LevelCtx.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "coarsening.hpp" 3 | 4 | namespace samurai_new 5 | { 6 | enum TransferOperators : int 7 | { 8 | // P assembled, R = assembled 9 | Assembled = 1, 10 | // P assembled, R = P^T 11 | Assembled_PTranspose, 12 | // P mat-free, R mat-free (via double*) 13 | MatrixFree_Arrays, 14 | // P mat-free, R mat-free (via Fields) 15 | MatrixFree_Fields 16 | }; 17 | 18 | template 19 | class LevelContext 20 | { 21 | public: 22 | 23 | using Mesh = typename Dsctzr::Mesh; 24 | 25 | private: 26 | 27 | Mesh _mesh; 28 | Dsctzr _discretizer; 29 | 30 | public: 31 | 32 | int level; 33 | LevelContext* finer = nullptr; 34 | LevelContext* coarser = nullptr; 35 | TransferOperators transfer_ops; 36 | int prediction_stencil_radius; 37 | 38 | LevelContext(Dsctzr& d, Mesh& m, TransferOperators to, int pred_stencil_radius) 39 | : _mesh(m) 40 | , _discretizer(d) 41 | { 42 | level = 0; 43 | transfer_ops = to; 44 | prediction_stencil_radius = pred_stencil_radius; 45 | } 46 | 47 | LevelContext(LevelContext& fine_ctx) 48 | : _mesh(samurai_new::coarsen(fine_ctx.mesh())) 49 | , _discretizer(Dsctzr::create_coarse(fine_ctx.assembly(), _mesh)) 50 | { 51 | level = fine_ctx.level + 1; 52 | transfer_ops = fine_ctx.transfer_ops; 53 | prediction_stencil_radius = fine_ctx.prediction_stencil_radius; 54 | 55 | this->finer = &fine_ctx; 56 | fine_ctx.coarser = this; 57 | } 58 | 59 | Mesh& mesh() 60 | { 61 | return _mesh; 62 | } 63 | 64 | Dsctzr& assembly() 65 | { 66 | return _discretizer; 67 | } 68 | 69 | bool is_finest() 70 | { 71 | return level == 0; 72 | } 73 | }; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /include/samurai/petsc/zero_block_assembly.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "matrix_assembly.hpp" 3 | 4 | namespace samurai 5 | { 6 | namespace petsc 7 | { 8 | /** 9 | * Zero block 10 | */ 11 | template <> 12 | struct Assembly : public MatrixAssembly 13 | { 14 | using scheme_t = int; // deactivate compatibility test in block_operator.tie_unknowns() 15 | using field_t = void; // deactivate compatibility test during assembly 16 | 17 | explicit Assembly(int value) 18 | { 19 | if (value != 0) 20 | { 21 | std::cerr << "Unimplemented Assembly(" << value << ")" << std::endl; 22 | exit(EXIT_FAILURE); 23 | } 24 | this->fit_block_dimensions(true); 25 | this->set_name("0"); 26 | } 27 | 28 | void sparsity_pattern_scheme(std::vector&) const override 29 | { 30 | } 31 | 32 | void assemble_scheme(Mat&) override 33 | { 34 | } 35 | 36 | void sparsity_pattern_boundary(std::vector&) const override 37 | { 38 | } 39 | 40 | void sparsity_pattern_projection(std::vector&) const override 41 | { 42 | } 43 | 44 | void sparsity_pattern_prediction(std::vector&) const override 45 | { 46 | } 47 | 48 | void assemble_boundary_conditions(Mat&) override 49 | { 50 | } 51 | 52 | void assemble_projection(Mat&) override 53 | { 54 | } 55 | 56 | void assemble_prediction(Mat&) override 57 | { 58 | } 59 | 60 | void insert_value_on_diag_for_useless_ghosts(Mat&) override 61 | { 62 | } 63 | 64 | template 65 | void for_each_useless_ghost_row(Func&&) const 66 | { 67 | } 68 | }; 69 | 70 | } // end namespace petsc 71 | } // end namespace samurai 72 | -------------------------------------------------------------------------------- /include/samurai/schemes/fv/cell_based/cell_based_scheme.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../explicit_scheme.hpp" 3 | #include "../FV_scheme.hpp" 4 | #include "cell_based_scheme_definition.hpp" 5 | 6 | namespace samurai 7 | { 8 | /** 9 | * @class CellBasedScheme 10 | */ 11 | template 12 | class CellBasedScheme 13 | { 14 | template 15 | static constexpr bool dependent_false = false; 16 | 17 | static_assert( 18 | dependent_false, 19 | "Either the required file has not been included, or the CellBasedScheme class has not been specialized for this type of scheme."); 20 | }; 21 | 22 | template 23 | auto make_cell_based_scheme() 24 | { 25 | return CellBasedScheme(); 26 | } 27 | 28 | template 29 | auto make_cell_based_scheme(std::string name) 30 | { 31 | auto scheme = make_cell_based_scheme(); 32 | scheme.set_name(name); 33 | return scheme; 34 | } 35 | 36 | template 37 | auto make_cell_based_scheme() 38 | { 39 | using bdry_cfg = BoundaryConfigFV<1>; 40 | return make_cell_based_scheme(); 41 | } 42 | 43 | template 44 | auto make_cell_based_scheme(std::string name) 45 | { 46 | auto scheme = make_cell_based_scheme(); 47 | scheme.set_name(name); 48 | return scheme; 49 | } 50 | 51 | /** 52 | * is_CellBasedScheme 53 | */ 54 | template 55 | struct is_CellBasedScheme : std::false_type 56 | { 57 | }; 58 | 59 | template 60 | struct is_CellBasedScheme, Scheme>>> 62 | : std::true_type 63 | { 64 | }; 65 | 66 | template 67 | inline constexpr bool is_CellBasedScheme_v = is_CellBasedScheme::value; 68 | 69 | } // end namespace samurai 70 | -------------------------------------------------------------------------------- /docs/source/tutorial/figures/subset_op.drawio: -------------------------------------------------------------------------------- 1 | 7Z1dk5o6GMc/jZfd4d14Wbft6UU706mz055zFyEqcxAczK56Pv0JEhASkVcTu+Rq5SE8kfz+hCdPEndiPm+Pf8Vwt/keeSiYGJp3nJifJoahawCQP4nllFpmwEkN69j3aKGLYeH/h7IrqfXV99C+VBBHUYD9XdnoRmGIXFyywTiODuViqygo17qDa8QZFi4MeOsv38MbatWd2eXEV+SvN7RqYEzTE1uYFaZ3st9ALzoUTObnifkcRxFOP22PzyhIGi9rl/S6LxVn8y8WoxA3ueB0OL38tDB8+WcOF0vHftHd/Qfq5Q0Gr/SG6ZfFp6wFUOh9TBqSHIVRSIzzDd4G5EgnH/c4jv7NW8YilpUfBM9REMXnq00PIrBy85KFM44L0HJFzqQ1Io8DcbkzPW8vIjQUbRGOT6TI4ULEpq28KbDIbDEKIPbfyu4hFcY6d5fX8CPyScWGlonYoX6ohC1NK7vYR6+xi+hVRQKsI82q8YRhvEaY80Q+FO77YjoTbkHbULTb0za60mYcmUAsbFPBroVtsA9kV9isI9GwLQW7FrZpDASbdSQatq1g18LOX619YbOORMN2FOx62GAo2EAu7KmCXQvbHipAYx2Jhg0U7FrYzlABGutINOyZgl0LezpUgMY6Eg07S14p2jdog6EiNNaRcNoqidaA9lAhGutIOG1D0a6lPRsqRmMdCaetsmgNUqZcXrtzzpT1JJw3P9zWOOAYHfE1yhk7qoIiaGqCgb8OyaFLwCFin7+hGPsuDD7SE1vf85Jq5oeNj9FiB92kzkMMd8QWR6+hh5KvryXuoxB/gVs/SJpqsUMujmFA7XQezbBy9SQVoWNb/WQXVHXeBX1ZV/TFyqAopRK51pj4gbKuMBlVva4sTJnjAia++xwdJrOqt5SGiQ9gTYXJqhqNSsPER56WwmRXDSOlYeJDRlthsoH9YJj4KVNHYXIeLoTgJzunCtP04UIIftwEFCbwcCEEP26aKUyzhwsh+KnBbEph1JweLQ1h8rN639DbeQV0e1zFjF9VjvAPBVc1HVfgpmtXwFn3Apc5vgKufR6JAALG0nScK+BsBDzr3YDLE0zSwNkN5trWpLl2lTdPNwrAZVZca90oVoNWca60inO390Xf1QVNJVUl7ysPxDx9IPj5j/Sb3ZzNuIFe2hwHMzBqPcNRcd29F4H3XYnQVBk852pN/GEKyDdrtCQuCnHf5QcKcfVOn5bIWT+iJGAoCQy1SWD2ZA+igYsjUSLou1RBieCyomwQCYje8NV3E5ASQN6B60N1AwVPomTAZ8x5HbzD3FErGTFUpSWQ+LT5KGbeW7E6lsE8Cjo+lT6K2fgu6Crep9LQ8en1UczQd0Gns1NYktnZoqJcQakuuRtu2KQWG7E23l2l1Ti6945osaHv+6DPQjO7/q4JR19w+sPuuyF+jPTZZ78zfa4TEU2/7w75MdJ3uDxX96efcyVcAX23zY9SAew+us78geTnv+8++jHSn3IJru79P+dKuAL46e9sT+77HtDVrOWtiu9kjd0yWRQ58c/q+Dixex6lc+JnlPVRpCVrOFW9MaVxMnhOo8hB1iyOZ5cbSufE56xeQuzjgLSOoX2DJ9K43D1q5Zduo3raZUHcAO73vntLGyTIWQLbsrWrQU7HVNoKuMhNqkVHH/9O9PFkGzY9/jv5Hk8WPfp0pPI5H5wKBz9Q7BM6iSzPtgYB1002abRzo2A6rSYrXrPNsqbz49Y/VDmtWIsr6ufs2uVqlEZzjUpbEcOGJ12lZ9qs9Ayx0muXKFLSky49djdiZ+k5XK8nWHrtMlRKetKlZ7KD584v3JnkF2679JiSnnzpsePMzi9c2bFeu20pSnrSpTcdqtdz7tbrkcPL/0xJi1/+84z5+X8= 2 | -------------------------------------------------------------------------------- /demos/tutorial/AMR_1D_Burgers/step_6/update_sol.hpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | template 10 | void update_sol(double dt, Field& phi, Field& phi_np1) 11 | { 12 | using namespace samurai::math; 13 | using mesh_id_t = typename Field::mesh_t::mesh_id_t; 14 | auto& mesh = phi.mesh(); 15 | 16 | samurai::for_each_interval(mesh[mesh_id_t::cells], 17 | [&](std::size_t level, const auto& i, auto) 18 | { 19 | const double dx = mesh.cell_length(level); 20 | 21 | phi_np1(level, i) = phi(level, i) - .5 * dt / dx * (pow(phi(level, i), 2.) - pow(phi(level, i - 1), 2.)); 22 | }); 23 | 24 | ///////////////////////// 25 | 26 | /** 27 | * Flux correction 28 | * ~~~~~~~~~~~~~~~ 29 | * 30 | * Left flux example 31 | * 32 | * |----|----| |----|----| 33 | * -----------------> x 34 | * |=========|---------| |=========|---------| 35 | * x x x 36 | * 37 | */ 38 | for (std::size_t level = mesh.min_level(); level < mesh.max_level(); ++level) 39 | { 40 | const double dx = mesh.cell_length(level); 41 | 42 | int stencil = 1; 43 | auto subset_left = samurai::intersection(samurai::translate(mesh[mesh_id_t::cells][level + 1], stencil), 44 | mesh[mesh_id_t::cells][level]) 45 | .on(level); 46 | 47 | subset_left( 48 | [&](const auto& i, const auto&) 49 | { 50 | phi_np1(level, i) = phi_np1(level, i) - .5 * dt / dx * pow(phi(level, i - 1), 2.) 51 | + .5 * dt / dx * pow(phi(level + 1, 2 * i - 1), 2.); 52 | }); 53 | } 54 | ///////////////////////// 55 | 56 | std::swap(phi.array(), phi_np1.array()); 57 | } 58 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(addGoogleTest) 2 | include_directories(${GTEST_INCLUDE_DIRS} SYSTEM) 3 | 4 | find_package(rapidcheck QUIET) 5 | message(STATUS "Found Rapidcheck: ${rapidcheck_FOUND}") 6 | 7 | find_package(Threads) 8 | 9 | set(COMMON_BASE 10 | main.cpp 11 | ) 12 | 13 | set(SAMURAI_TESTS 14 | test_adapt.cpp 15 | test_bc.cpp 16 | test_box.cpp 17 | test_cell.cpp 18 | test_cell_array.cpp 19 | test_cell_list.cpp 20 | test_corner_projection.cpp 21 | test_domain_with_hole.cpp 22 | test_field.cpp 23 | test_find.cpp 24 | test_for_each.cpp 25 | test_graduation.cpp 26 | test_hdf5.cpp 27 | test_interval.cpp 28 | test_level_cell_list.cpp 29 | test_list_of_intervals.cpp 30 | test_mra.cpp 31 | test_periodic.cpp 32 | test_portion.cpp 33 | test_restart.cpp 34 | test_scaling.cpp 35 | test_stencil.cpp 36 | test_subset.cpp 37 | test_utils.cpp 38 | ) 39 | 40 | if(rapidcheck_FOUND) 41 | list(APPEND SAMURAI_TESTS test_operator_set.cpp) 42 | endif() 43 | 44 | if (SPLIT_TESTS) 45 | foreach(filename IN LISTS SAMURAI_TESTS) 46 | string(REPLACE ".cpp" "" targetname ${filename}) 47 | add_executable(${targetname} ${COMMON_BASE} ${filename} ${SAMURAI_HEADERS}) 48 | target_include_directories(${targetname} PRIVATE ${SAMURAI_INCLUDE_DIR}) 49 | 50 | if(MSVC) 51 | target_compile_options(${targetname} PUBLIC /bigobj) 52 | endif() 53 | 54 | if(rapidcheck_FOUND) 55 | target_link_libraries(${targetname} samurai gtest_main gtest rapidcheck rapidcheck_gtest) 56 | else() 57 | target_link_libraries(${targetname} samurai gtest_main gtest) 58 | endif() 59 | endforeach() 60 | endif() 61 | 62 | add_executable(test_samurai_lib ${COMMON_BASE} ${SAMURAI_TESTS} ${SAMURAI_HEADERS}) 63 | target_include_directories(test_samurai_lib PRIVATE ${SAMURAI_INCLUDE_DIR}) 64 | 65 | if(MSVC) 66 | target_compile_options(test_samurai_lib PUBLIC /bigobj) 67 | endif() 68 | 69 | if(rapidcheck_FOUND) 70 | target_link_libraries(test_samurai_lib samurai gtest_main gtest rapidcheck rapidcheck_gtest) 71 | else() 72 | target_link_libraries(test_samurai_lib samurai gtest_main gtest) 73 | endif() 74 | -------------------------------------------------------------------------------- /demos/from_obj/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2018-2025 the samurai's authors 2 | // SPDX-License-Identifier: BSD-3-Clause 3 | #include 4 | 5 | #include 6 | namespace fs = std::filesystem; 7 | 8 | #include 9 | #include 10 | 11 | template 12 | void save_mesh(const fs::path& path, const std::string& filename, const Mesh& mesh) 13 | { 14 | auto level = samurai::make_scalar_field("level", mesh); 15 | 16 | if (!fs::exists(path)) 17 | { 18 | fs::create_directory(path); 19 | } 20 | 21 | samurai::for_each_cell(mesh, 22 | [&](auto& cell) 23 | { 24 | level[cell] = cell.level; 25 | }); 26 | 27 | samurai::save(path, filename, mesh, level); 28 | } 29 | 30 | int main(int argc, char** argv) 31 | { 32 | constexpr std::size_t dim = 3; 33 | std::size_t initial_level = 1; 34 | std::size_t max_level = 8; 35 | bool keep_inside = false; 36 | bool keep_outside = false; 37 | 38 | // Output parameters 39 | fs::path path = fs::current_path(); 40 | std::string input_file; 41 | 42 | CLI::App app{"Create an adapted mesh from an OBJ file"}; 43 | app.add_option("--input", input_file, "input File")->required()->check(CLI::ExistingFile); 44 | app.add_option("--init-level", initial_level, "Start level of the output adaptive mesh")->capture_default_str(); 45 | app.add_flag("--keep-inside", keep_inside, "Keep the cells inside the object")->capture_default_str(); 46 | app.add_flag("--keep-outside", keep_outside, "Keep the cells outside the object")->capture_default_str(); 47 | app.add_option("--max-level", max_level, "Maximum level of the output adaptive mesh")->capture_default_str(); 48 | app.add_option("--path", path, "Output path")->capture_default_str(); 49 | CLI11_PARSE(app, argc, argv); 50 | 51 | std::string output_file = fs::path(input_file).stem(); 52 | 53 | auto mesh = samurai::from_geometry(input_file, initial_level, max_level, keep_outside, keep_inside); 54 | make_graduation(mesh); 55 | 56 | save_mesh(path, fmt::format("mesh_{}", output_file), mesh); 57 | 58 | return EXIT_SUCCESS; 59 | } 60 | -------------------------------------------------------------------------------- /cmake/samuraiConfig.cmake.in: -------------------------------------------------------------------------------- 1 | 2 | option(SAMURAI_WITH_OPENMP "Enable OpenMP" OFF) 3 | if(${SAMURAI_WITH_OPENMP}) 4 | message(STATUS "SAMURAI_WITH_OPENMP = ON") 5 | find_dependency(OpenMP) 6 | if(OpenMP_CXX_FOUND) 7 | target_link_libraries(samurai::samurai INTERFACE OpenMP::OpenMP_CXX) 8 | target_compile_definitions(samurai::samurai INTERFACE SAMURAI_WITH_OPENMP) 9 | else() 10 | message(FATAL_ERROR "OpenMP not found") 11 | endif() 12 | endif() 13 | 14 | 15 | option(SAMURAI_WITH_MPI "Enable MPI" OFF) 16 | if(SAMURAI_WITH_MPI) 17 | message(STATUS "SAMURAI_WITH_MPI = ON") 18 | if (NOT HDF5_IS_PARALLEL) 19 | message(FATAL_ERROR "HDF5 is not parallel. Please install a parallel version.") 20 | endif() 21 | find_dependency(Boost COMPONENTS serialization mpi) 22 | target_link_libraries(samurai::samurai INTERFACE Boost::serialization Boost::mpi) 23 | target_compile_definitions(samurai::samurai INTERFACE SAMURAI_WITH_MPI) 24 | endif() 25 | 26 | option(SAMURAI_WITH_PETSC "Enable PETSc" OFF) 27 | if(${SAMURAI_WITH_PETSC}) 28 | message(STATUS "SAMURAI_WITH_PETSC = ON") 29 | 30 | include(CMakeFindDependencyMacro) 31 | find_dependency(PkgConfig) 32 | 33 | pkg_check_modules(PETSC REQUIRED PETSc) 34 | include_directories(${PETSC_INCLUDE_DIRS}) 35 | 36 | target_compile_definitions(samurai::samurai INTERFACE SAMURAI_WITH_PETSC) 37 | target_link_libraries(samurai::samurai INTERFACE ${PETSC_LINK_LIBRARIES}) 38 | endif() 39 | 40 | 41 | option(SAMURAI_CHECK_NAN "Check NaN in computations" OFF) 42 | if(SAMURAI_CHECK_NAN) 43 | message(STATUS "SAMURAI_CHECK_NAN = ON") 44 | target_compile_definitions(samurai::samurai INTERFACE SAMURAI_CHECK_NAN) 45 | endif() 46 | 47 | 48 | set(FLUX_CONTAINER_LIST "array" "xtensor") 49 | set(SAMURAI_FLUX_CONTAINER "xtensor" CACHE STRING "Container to store fluxes: ${FLUX_CONTAINER_LIST}") 50 | set_property(CACHE SAMURAI_FLUX_CONTAINER PROPERTY STRINGS ${FLUX_CONTAINER_LIST}) 51 | if(NOT SAMURAI_FLUX_CONTAINER IN_LIST FLUX_CONTAINER_LIST) 52 | message(FATAL_ERROR "SAMURAI_FLUX_CONTAINER must be one of: ${FLUX_CONTAINER_LIST}") 53 | else() 54 | string(TOUPPER ${SAMURAI_FLUX_CONTAINER} SAMURAI_FLUX_CONTAINER) 55 | target_compile_definitions(samurai::samurai INTERFACE SAMURAI_FLUX_CONTAINER_${SAMURAI_FLUX_CONTAINER}) 56 | endif() 57 | -------------------------------------------------------------------------------- /docs/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change. 4 | Please note we have a [code of conduct](CODE_OF_CONDUCT.md), please follow it in all your interactions with the project. 5 | 6 | ## Development environment setup 7 | 8 | To set up a development environment, please follow these steps: 9 | 10 | 1. Clone the repo 11 | 12 | ```sh 13 | git clone https://github.com/hpc-maths/samurai 14 | ``` 15 | 16 | 2. Install the conda environment 17 | 18 | ```sh 19 | cd samurai 20 | mamba env create --file conda/environment.yml 21 | mamba activate samurai-env 22 | ``` 23 | 24 | 3. Install pre-commit 25 | 26 | ```sh 27 | mamba install pre-commit 28 | pre-commit install 29 | ``` 30 | 31 | ## Issues and feature requests 32 | 33 | You've found a bug in the source code, a mistake in the documentation or maybe you'd like a new feature? You can help us by [submitting an issue on GitHub](https://github.com/hpc-maths/samurai/issues). Before you create an issue, make sure to search the issue archive -- your issue may have already been addressed! 34 | 35 | Please try to create bug reports that are: 36 | 37 | - _Reproducible._ Include steps to reproduce the problem. 38 | - _Specific._ Include as much detail as possible: which version, what environment, etc. 39 | - _Unique._ Do not duplicate existing opened issues. 40 | - _Scoped to a Single Bug._ One bug per report. 41 | 42 | **Even better: Submit a pull request with a fix or new feature!** 43 | 44 | ### How to submit a Pull Request 45 | 46 | 1. Search our repository for open or closed 47 | [Pull Requests](https://github.com/hpc-maths/samurai/pulls) 48 | that relate to your submission. You don't want to duplicate effort. 49 | 2. Fork the project 50 | 3. Create your feature branch (`git checkout -b feat/amazing_feature`) 51 | 4. Commit your changes (`git commit -m 'feat: add amazing_feature'`) samurai uses [conventional commits](https://www.conventionalcommits.org), so please follow the specification in your commit messages. 52 | 5. Push to the branch (`git push origin feat/amazing_feature`) 53 | 6. [Open a Pull Request](https://github.com/hpc-maths/samurai/compare?expand=1) 54 | --------------------------------------------------------------------------------