{"id":32139425,"url":"https://github.com/hpc-maths/samurai","last_synced_at":"2026-03-04T19:02:49.919Z","repository":{"id":41502596,"uuid":"316234835","full_name":"hpc-maths/samurai","owner":"hpc-maths","description":"Intervals coupled with algebra of set to handle adaptive mesh refinement and operators on it.","archived":false,"fork":false,"pushed_at":"2026-02-17T20:11:19.000Z","size":21631,"stargazers_count":56,"open_issues_count":37,"forks_count":17,"subscribers_count":4,"default_branch":"main","last_synced_at":"2026-02-17T22:24:30.615Z","etag":null,"topics":["adaptive-mesh-refinement","amr","cartesian","scientific-computing"],"latest_commit_sha":null,"homepage":"https://hpc-math-samurai.readthedocs.io","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hpc-maths.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":"codemeta.json","zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-11-26T13:10:36.000Z","updated_at":"2026-02-17T20:11:26.000Z","dependencies_parsed_at":"2026-01-22T06:03:19.816Z","dependency_job_id":null,"html_url":"https://github.com/hpc-maths/samurai","commit_stats":null,"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"purl":"pkg:github/hpc-maths/samurai","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpc-maths%2Fsamurai","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpc-maths%2Fsamurai/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpc-maths%2Fsamurai/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpc-maths%2Fsamurai/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hpc-maths","download_url":"https://codeload.github.com/hpc-maths/samurai/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hpc-maths%2Fsamurai/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29629626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T18:02:07.722Z","status":"ssl_error","status_checked_at":"2026-02-19T18:01:46.144Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["adaptive-mesh-refinement","amr","cartesian","scientific-computing"],"created_at":"2025-10-21T05:46:52.947Z","updated_at":"2026-02-20T00:31:12.839Z","avatar_url":"https://github.com/hpc-maths.png","language":"C++","readme":"\u003ch1 align=\"center\"\u003e\n  \u003ca href=\"https://github.com/hpc-maths/samurai\"\u003e\n    \u003cpicture\u003e\n        \u003csource media=\"(prefers-color-scheme: dark)\" height=\"200\" srcset=\"./docs/source/logo/dark_logo.png\"\u003e\n        \u003cimg alt=\"Text changing depending on mode. Light: 'So light!' Dark: 'So dark!'\" height=200 src=\"./docs/source/logo/light_logo.png\"\u003e\n    \u003c/picture\u003e\n  \u003c/a\u003e\n\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003cbr /\u003e\n  \u003ca href=\"https://github.com/hpc-maths/samurai/issues/new?assignees=\u0026labels=bug\u0026template=01_BUG_REPORT.md\u0026title=bug%3A+\"\u003eReport a Bug\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/hpc-maths/samurai/issues/new?assignees=\u0026labels=enhancement\u0026template=02_FEATURE_REQUEST.md\u0026title=feat%3A+\"\u003eRequest a Feature\u003c/a\u003e\n  ·\n  \u003ca href=\"https://github.com/hpc-maths/samurai/discussions\"\u003eAsk a Question\u003c/a\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003cbr /\u003e\n\n[![Project license](https://img.shields.io/github/license/hpc-maths/samurai.svg?style=flat-square)](LICENSE)\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/9ea988d1c63344ca9a3d361a5459df2f)](https://app.codacy.com/gh/hpc-maths/samurai/dashboard?utm_source=gh\u0026utm_medium=referral\u0026utm_content=\u0026utm_campaign=Badge_grade)\n\n[![Pull Requests welcome](https://img.shields.io/badge/PRs-welcome-ff69b4.svg?style=flat-square)](https://github.com/hpc-maths/samurai/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22)\n[![code with love by hpc-maths](https://img.shields.io/badge/%3C%2F%3E%20with%20%E2%99%A5%20by-HPC@Maths-ff1414.svg?style=flat-square)](https://github.com/hpc-maths)\n\n\n\u003c/div\u003e\n\nThe use of mesh adaptation methods in numerical simulation allows to drastically reduce the memory footprint and the computational costs. There are different kinds of methods: AMR patch-based, AMR cell-based, multiresolution cell-based or point-based, ...\n\nDifferent open source software is available to the community to manage mesh adaptation: [AMReX](https://amrex-codes.github.io/amrex/) for patch-based AMR, [p4est](https://www.p4est.org/) and [pablo](https://optimad.github.io/PABLO/) for cell-based adaptation.\n\nThe strength of samurai is that it allows to implement all the above mentioned mesh adaptation methods from the same data structure. The mesh is represented as intervals and a set algebra allows to efficiently search for subsets among these intervals.\nSamurai also offers a flexible and pleasant interface to easily implement numerical methods.\n\n\u003cdetails\u003e\n\u003csummary\u003eTable of Contents\u003c/summary\u003e\n\n- [Get started](#get-started)\n  - [The advection equation](#the-advection-equation)\n  - [The projection operator](#the-projection-operator)\n  - [There's more](#theres-more)\n- [Features](#features)\n- [Installation](#installation)\n  - [From conda](#from-conda)\n  - [From Conan Center](#from-conan-center)\n  - [From source](#from-source)\n- [Get help](#get-help)\n- [Project assistance](#project-assistance)\n- [Contributing](#contributing)\n- [License](#license)\n\n\u003c/details\u003e\n\n## Get started\n\nIn this section, we propose two examples: the first one solves a 2D advection equation with mesh adaptation using multiresolution, the second one shows the use of set algebra on intervals.\n\n### The advection equation\n\nWe want to solve the 2D advection equation given by\n\n$$\n\\partial_t u + a \\cdot \\nabla u = 0 \\\\; \\text{in} \\\\; [0, 1]\\times [0, 1]\n$$\n\nwith homogeneous Dirichlet boundary conditions and $a = (1, 1)$. The initial solution is given by\n\n$$\nu_0(x, y) = \\left\\\\{\n\\begin{align*}\n1 \u0026 \\\\; \\text{in} \\\\; [0.4, 0.6]\\times [0.4, 0.6], \\\\\n0 \u0026 \\\\; \\text{elsewhere}.\n\\end{align*}\n\\right.\n$$\n\nTo solve this equation, we use the well known [upwind scheme](https://en.wikipedia.org/wiki/Upwind_scheme).\n\nThe following steps describe how to solve this problem with samurai. It is important to note that these steps are generally the same whatever the equations we want to solve.\n\n- Define the configuration of the problem\n\n    ```cpp\n    constexpr size_t dim = 2;\n    using Config = samurai::MRConfig\u003cdim\u003e;\n    std::size_t min_level = 2, max_level = 8;\n    ````\n\n- Create the Cartesian mesh\n\n    ```cpp\n    const samurai::Box\u003cdouble, dim\u003e box({0., 0.}, {1., 1.});\n    samurai::MRMesh\u003cConfig\u003e mesh(box, min_level, max_level);\n    ```\n\n- Create the field on this mesh\n\n    ```cpp\n    auto u = samurai::make_field\u003cdouble, 1\u003e(\"u\", mesh);\n    samurai::make_bc\u003csamurai::Dirichlet\u003c1\u003e\u003e(u, 0.);\n    ```\n\n- Initialization of this field\n\n    ```cpp\n    samurai::for_each_cell(mesh, [\u0026](const auto\u0026 cell)\n    {\n        double length = 0.2;\n        if (xt::all(xt::abs(cell.center() - 0.5) \u003c= 0.5*length))\n        {\n            u[cell] = 1;\n        }\n    });\n    ````\n\n- Create the adaptation method\n\n    ```cpp\n    auto MRadaptation = samurai::make_MRAdapt(u);\n    ```\n\n- Time loop\n\n    ```cpp\n    double dx = mesh.cell_length(max_level);\n    double dt = 0.5*dx;\n    auto unp1 = samurai::make_field\u003cdouble, 1\u003e(\"u\", mesh);\n\n    // Time loop\n    for (std::size_t nite = 0; nite \u003c 50; ++nite)\n    {\n        // adapt u\n        MRadaptation(1e-4, 2);\n\n        // update the ghosts used by the upwind scheme\n        samurai::update_ghost_mr(u);\n\n        // upwind scheme\n        samurai::for_each_interval(mesh, [\u0026](std::size_t level, const auto\u0026 i, const auto\u0026 index)\n        {\n            double dx = mesh.cell_length(level);\n            auto j = index[0];\n\n            unp1(level, i, j) = u(level, i, j) - dt / dx * (u(level, i, j) - u(level, i - 1, j)\n                                                          + u(level, i, j) - u(level, i, j - 1));\n        });\n\n        std::swap(unp1.array(), u.array());\n    }\n    ```\n\nThe whole example can be found [here](./demos/FiniteVolume/advection_2d.cpp).\n\n### The projection operator\n\nWhen manipulating grids of different resolution levels, it is often necessary to transmit the solution of a level $l$ to a level $l+1$ and vice versa. We are interested here in the projection operator defined by\n\n$$\nu(l, i, j) = \\frac{1}{4}\\sum_{k_i=0}^1\\sum_{k_j=0}^1 u(l+1, 2i + k_i, 2j + k_j)\n$$\n\nThis operator allows to compute the cell-average value of the solution at a grid node at level $l$ from cell-average values of the solution known on children-nodes at grid level $l + 1$ for a 2D problem.\n\nWe assume that we already have a samurai mesh with several level defined in the variable `mesh`. To access to a level, we use the operator `mesh[level]`. We also assume that we created a field on this mesh using the `make_field` and initialized it.\n\nThe following steps describe how to implement the projection operator with samurai.\n\n- Create a subset of the mesh using set algebra\n```cpp\nauto set = samurai::intersection(mesh[level], mesh[level+1]).on(level);\n```\n\n- Apply an operator on this subset\n\n```cpp\nset([\u0026](const auto\u0026 i, const auto index)\n{\n    auto j = index[0];\n    u(level, i, j) = 0.25*(u(level+1, 2*i, 2*j)\n                         + u(level+1, 2*i+1, 2*j)\n                         + u(level+1, 2*i, 2*j+1)\n                         + u(level+1, 2*i+1, 2*j+1));\n});\n```\n\nThe multi dimensional projection operator can be found [here](./include/samurai/numeric/projection.hpp).\n\n### There's more\n\nIf you want to learn more about samurai skills by looking at examples, we encourage you to browse the [demos](./demos) directory.\n\nThe [tutorial](./demos/tutorial/) directory is a good first step followed by the [FiniteVolume](./demos/FiniteVolume/) directory.\n\n## Features\n\n- [x] Facilitate data manipulation by using the formalism on a uniform Cartesian grid\n- [x] Facilitate the implementation of complex operators between grid levels\n- [x] High memory compression of an adapted mesh\n- [x] Complex mesh creation using a set of meshes\n- [x] Finite volume methods using flux construction\n- [x] Lattice Boltzmann methods examples\n- [ ] Finite difference methods\n- [ ] Discontinuous Galerkin methods\n- [x] Matrix assembling of the discrete operators using PETSc\n- [x] AMR cell-based methods\n- [ ] AMR patch-based and block-based methods\n- [x] MRA cell-based methods\n- [ ] MRA point-based methods\n- [x] HDF5 output format support\n- [ ] MPI implementation\n\n## Installation\n\n### From conda\n\n```bash\nmamba install samurai\n```\n\nFor compiling purposes, you have to install a C++ compiler, `cmake`, and (optionaly) `make`:\n\n```bash\nmamba install cxx-compiler cmake [make]\n```\n\nIf you have to use PETSc to assemble the matrix of your problem, you need to install it:\n\n```bash\nmamba install petsc pkg-config\n```\n\nFor parallel computation,\n\n```bash\nmamba install libboost-mpi libboost-devel libboost-headers 'hdf5=*=mpi*'\n```\n\n### From Conan Center\n\nIf you want to install samurai from Conan, you can use the following command:\n\n```bash\nconan install --requires=samurai/0.13.0\n```\n\n### From source\n\nRun the cmake configuration\n\n- With mamba or conda\n\n    First, you need to create the environment with all the dependencies\n    installed, run\n\n    ```bash\n    mamba env create --file conda/environment.yml\n    ```\n\n    for sequential computation, or\n\n    ```bash\n    mamba env create --file conda/mpi-environment.yml\n    ```\n\n    for parallel computation. Then\n\n    ```bash\n    mamba activate samurai-env\n    ```\n\n    ```bash\n    cmake . -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_DEMOS=ON\n    ```\n\n- With vcpkg\n\n    ```bash\n    cmake . -B ./build -DENABLE_VCPKG=ON -DBUILD_DEMOS=ON\n    ```\n\n- With conan\n\n    ```bash\n    cmake . -B ./build -DCMAKE_BUILD_TYPE=Release -DENABLE_CONAN_OPTION=ON -DBUILD_DEMOS=ON\n    ```\n\nBuild the demos\n\n```bash\ncmake --build ./build --config Release\n```\n\n## CMake configuration\n\nHere is a minimal example of `CMakeLists.txt`:\n\n```cmake\ncmake_minimum_required(VERSION 3.15)\nset(CMAKE_CXX_STANDARD 17)\n\nproject(my_samurai_project CXX)\n\nset(SAMURAI_WITH_MPI ON)\nset(SAMURAI_WITH_PETSC OFF)\nfind_package(samurai CONFIG REQUIRED)\n\nadd_executable(my_samurai_project main.cpp)\ntarget_link_libraries(my_samurai_project PRIVATE samurai::samurai)\n```\n\n## Get help\n\nFor a better understanding of all the components of samurai, you can consult the documentation https://hpc-math-samurai.readthedocs.io.\n\nIf you have any question or remark, you can write a message on [github discussions](https://github.com/hpc-maths/samurai/discussions) and we will be happy do help you or to discuss with you.\n\n\n## Project assistance\n\nIf you want to say **thank you** or/and support active development of samurai:\n\n- Add a [GitHub Star](https://github.com/hpc-maths/samurai) to the project.\n- Tweet about samurai.\n- Write interesting articles about the project on [Dev.to](https://dev.to/), [Medium](https://medium.com/) or your personal blog.\n\nTogether, we can make samurai **better**!\n\n## Contributing\n\nFirst off, thanks for taking the time to contribute! Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and are **greatly appreciated**.\n\n\nPlease read [our contribution guidelines](./docs/CONTRIBUTING.md), and thank you for being involved!\n\n## License\n\nThis project is licensed under the **BSD license**.\n\nSee [LICENSE](LICENSE) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhpc-maths%2Fsamurai","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhpc-maths%2Fsamurai","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhpc-maths%2Fsamurai/lists"}