From 2d9ae521f168a5841906dc1d3151d23d45dd8f4f Mon Sep 17 00:00:00 2001 From: Loic Gouarin Date: Mon, 2 Oct 2023 18:53:57 +0200 Subject: [PATCH] feat: Add direction on bc function (#131) --- .cppcheck | 2 +- .github/workflows/ci.yml | 12 ++-- demos/FiniteVolume/AMR_Burgers_Hat.cpp | 4 +- demos/FiniteVolume/advection_1d.cpp | 4 +- demos/FiniteVolume/advection_2d.cpp | 6 +- demos/FiniteVolume/advection_2d_user_bc.cpp | 6 +- demos/FiniteVolume/burgers.cpp | 6 +- demos/FiniteVolume/heat.cpp | 2 +- demos/FiniteVolume/heat_heterogeneous.cpp | 2 +- demos/FiniteVolume/level_set.cpp | 2 +- demos/FiniteVolume/level_set_from_scratch.cpp | 2 +- demos/FiniteVolume/lid_driven_cavity.cpp | 2 +- demos/FiniteVolume/linear_convection.cpp | 2 +- demos/FiniteVolume/scalar_burgers_2d.cpp | 2 +- demos/FiniteVolume/stencil_field.hpp | 3 +- demos/FiniteVolume/stokes_2d.cpp | 14 ++-- demos/from_obj/main.cpp | 2 +- demos/highorder/main.cpp | 4 +- demos/multigrid/test_cases.hpp | 10 +-- demos/p4est/simple_2d.cpp | 2 +- demos/pablo/bubble_2d.cpp | 4 +- demos/tutorial/2D_mesh.cpp | 2 +- demos/tutorial/AMR_1D_Burgers/step_0/main.cpp | 4 +- demos/tutorial/AMR_1D_Burgers/step_1/main.cpp | 4 +- demos/tutorial/AMR_1D_Burgers/step_2/main.cpp | 4 +- demos/tutorial/AMR_1D_Burgers/step_3/main.cpp | 2 +- demos/tutorial/AMR_1D_Burgers/step_4/main.cpp | 2 +- demos/tutorial/AMR_1D_Burgers/step_5/main.cpp | 2 +- demos/tutorial/AMR_1D_Burgers/step_6/main.cpp | 2 +- demos/tutorial/graduation_case_1.cpp | 2 +- demos/tutorial/graduation_case_2.cpp | 2 +- demos/tutorial/graduation_case_3.cpp | 6 +- demos/tutorial/interval.cpp | 2 +- demos/tutorial/reconstruction_1d.cpp | 2 +- demos/tutorial/reconstruction_2d.cpp | 2 +- demos/tutorial/reconstruction_3d.cpp | 2 +- include/samurai/algorithm/graduation.hpp | 2 +- include/samurai/bc.hpp | 69 ++++++++++--------- include/samurai/field_expression.hpp | 6 +- .../samurai/petsc/fv/FV_scheme_assembly.hpp | 6 +- include/samurai/stencil.hpp | 44 +++++++++++- include/samurai/subset/subset_node.hpp | 6 ++ 42 files changed, 159 insertions(+), 107 deletions(-) diff --git a/.cppcheck b/.cppcheck index 8ba3ed0e3..00ffea08b 100644 --- a/.cppcheck +++ b/.cppcheck @@ -1,3 +1,3 @@ noExplicitConstructor duplInheritedMember -missingInclude +missingIncludeSystem diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7821edf3a..2539a9572 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: with: path: | ~/.cache/ccache - ~/micromamba-root/envs/samurai-env + ~/micromamba/envs/samurai-env key: cppcheck - name: Mamba and samurai env installation @@ -39,21 +39,19 @@ jobs: cache-environment: true - name: cppcheck installation - shell: bash -l {0} + shell: bash -el {0} run: | conda install -y cppcheck cxx-compiler - pip install compdb - name: Configure - shell: bash -l {0} + shell: bash -el {0} run: | cmake . -Bbuild -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug -DBUILD_DEMOS=ON - compdb -p build list > compile_commands.json - name: Run cppcheck on samurai - shell: bash -l {0} + shell: bash -el {0} run: | - cppcheck --enable=all -q --project=compile_commands.json --suppressions-list=.cppcheck --inline-suppr 2> cppcheck_err.txt + cppcheck --enable=all -q --project=./build/compile_commands.json --suppressions-list=.cppcheck --inline-suppr 2> cppcheck_err.txt - name: Check for errors run: | diff --git a/demos/FiniteVolume/AMR_Burgers_Hat.cpp b/demos/FiniteVolume/AMR_Burgers_Hat.cpp index a8ef7be49..f8707b293 100644 --- a/demos/FiniteVolume/AMR_Burgers_Hat.cpp +++ b/demos/FiniteVolume/AMR_Burgers_Hat.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include @@ -171,7 +171,7 @@ void flux_correction(Field& phi_np1, const Field& phi_n, double dt) int main(int argc, char* argv[]) { - constexpr std::size_t dim = 1; + constexpr std::size_t dim = 1; // cppcheck-suppress unreadVariable using Config = samurai::amr::Config; // Simulation parameters diff --git a/demos/FiniteVolume/advection_1d.cpp b/demos/FiniteVolume/advection_1d.cpp index 517198626..dc2058498 100644 --- a/demos/FiniteVolume/advection_1d.cpp +++ b/demos/FiniteVolume/advection_1d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include @@ -111,7 +111,7 @@ void save(const fs::path& path, const std::string& filename, const Field& u, con int main(int argc, char* argv[]) { - constexpr std::size_t dim = 1; + constexpr std::size_t dim = 1; // cppcheck-suppress unreadVariable using Config = samurai::MRConfig; // Simulation parameters diff --git a/demos/FiniteVolume/advection_2d.cpp b/demos/FiniteVolume/advection_2d.cpp index 76d56a50e..2e89f792b 100644 --- a/demos/FiniteVolume/advection_2d.cpp +++ b/demos/FiniteVolume/advection_2d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include @@ -165,8 +165,8 @@ void save(const fs::path& path, const std::string& filename, const Field& u, con int main(int argc, char* argv[]) { - constexpr size_t dim = 2; - using Config = samurai::MRConfig; + constexpr std::size_t dim = 2; + using Config = samurai::MRConfig; // Simulation parameters xt::xtensor_fixed> min_corner = {0., 0.}; diff --git a/demos/FiniteVolume/advection_2d_user_bc.cpp b/demos/FiniteVolume/advection_2d_user_bc.cpp index 707620442..7c06ed020 100644 --- a/demos/FiniteVolume/advection_2d_user_bc.cpp +++ b/demos/FiniteVolume/advection_2d_user_bc.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include @@ -211,8 +211,8 @@ void save(const fs::path& path, const std::string& filename, const Field& u, con int main(int argc, char* argv[]) { - constexpr size_t dim = 2; - using Config = samurai::MRConfig; + constexpr std::size_t dim = 2; + using Config = samurai::MRConfig; // Simulation parameters xt::xtensor_fixed> min_corner = {0., 0.}; diff --git a/demos/FiniteVolume/burgers.cpp b/demos/FiniteVolume/burgers.cpp index 0fc246b8a..3dd79e44c 100644 --- a/demos/FiniteVolume/burgers.cpp +++ b/demos/FiniteVolume/burgers.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include @@ -186,7 +186,7 @@ int main_dim(int argc, char* argv[]) if (dim == 1 && init_sol == "linear") { samurai::make_bc(u, - [&](const auto&, const auto& coord) + [&](const auto&, const auto&, const auto& coord) { return exact_solution(coord, 0); }); @@ -272,7 +272,7 @@ int main_dim(int argc, char* argv[]) { u.get_bc().clear(); samurai::make_bc(u, - [&](const auto&, const auto& coord) + [&](const auto&, const auto&, const auto& coord) { return exact_solution(coord, t - dt); }); diff --git a/demos/FiniteVolume/heat.cpp b/demos/FiniteVolume/heat.cpp index 855c18b24..bb6575098 100644 --- a/demos/FiniteVolume/heat.cpp +++ b/demos/FiniteVolume/heat.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/FiniteVolume/heat_heterogeneous.cpp b/demos/FiniteVolume/heat_heterogeneous.cpp index 05663f4b2..767bef01c 100644 --- a/demos/FiniteVolume/heat_heterogeneous.cpp +++ b/demos/FiniteVolume/heat_heterogeneous.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/FiniteVolume/level_set.cpp b/demos/FiniteVolume/level_set.cpp index 196024f76..acbc16f03 100644 --- a/demos/FiniteVolume/level_set.cpp +++ b/demos/FiniteVolume/level_set.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/FiniteVolume/level_set_from_scratch.cpp b/demos/FiniteVolume/level_set_from_scratch.cpp index f6b99c883..8c646c354 100644 --- a/demos/FiniteVolume/level_set_from_scratch.cpp +++ b/demos/FiniteVolume/level_set_from_scratch.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/FiniteVolume/lid_driven_cavity.cpp b/demos/FiniteVolume/lid_driven_cavity.cpp index 70faf13a3..b2794e975 100644 --- a/demos/FiniteVolume/lid_driven_cavity.cpp +++ b/demos/FiniteVolume/lid_driven_cavity.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include #include diff --git a/demos/FiniteVolume/linear_convection.cpp b/demos/FiniteVolume/linear_convection.cpp index f1690056d..3d7c2ad67 100644 --- a/demos/FiniteVolume/linear_convection.cpp +++ b/demos/FiniteVolume/linear_convection.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/FiniteVolume/scalar_burgers_2d.cpp b/demos/FiniteVolume/scalar_burgers_2d.cpp index a9b93349e..758a350ce 100644 --- a/demos/FiniteVolume/scalar_burgers_2d.cpp +++ b/demos/FiniteVolume/scalar_burgers_2d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/FiniteVolume/stencil_field.hpp b/demos/FiniteVolume/stencil_field.hpp index f2a73fcae..043f727bc 100644 --- a/demos/FiniteVolume/stencil_field.hpp +++ b/demos/FiniteVolume/stencil_field.hpp @@ -19,14 +19,13 @@ namespace samurai template inline auto operator()(Dim<2>, const Field& phi, const Field& phi_0, const std::size_t max_level) const { - double dx = this->dx(); - auto out = xt::empty({i.size()}); out.fill(0.); if (level == max_level) { + double dx = this->dx(); // // First order one sided // auto dxp = (phi(level, i + 1, j) - phi(level, i , j))/dx; // auto dxm = (phi(level, i , j) - phi(level, i - 1, j))/dx; diff --git a/demos/FiniteVolume/stokes_2d.cpp b/demos/FiniteVolume/stokes_2d.cpp index d7163c3f4..c19cd1f3b 100644 --- a/demos/FiniteVolume/stokes_2d.cpp +++ b/demos/FiniteVolume/stokes_2d.cpp @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include #include @@ -236,7 +236,7 @@ int main(int argc, char* argv[]) // Boundary conditions samurai::make_bc(velocity, - [](const auto&, const auto& coord) + [](const auto&, const auto&, const auto& coord) { const auto& x = coord[0]; const auto& y = coord[1]; @@ -246,7 +246,7 @@ int main(int argc, char* argv[]) }); samurai::make_bc(pressure, - [](const auto&, const auto& coord) + [](const auto&, const auto&, const auto& coord) { const auto& x = coord[0]; const auto& y = coord[1]; @@ -404,12 +404,12 @@ int main(int argc, char* argv[]) // Boundary conditions samurai::make_bc(velocity_np1, - [&](const auto&, const auto& coord) + [&](const auto&, const auto&, const auto& coord) { return exact_velocity(0, coord); }); samurai::make_bc(pressure_np1, - [&](const auto&, const auto& coord) + [&](const auto&, const auto&, const auto& coord) { return exact_normal_grad_pressure(0, coord); }); @@ -497,13 +497,13 @@ int main(int argc, char* argv[]) // Boundary conditions velocity_np1.get_bc().clear(); samurai::make_bc(velocity_np1, - [&](const auto&, const auto& coord) + [&](const auto&, const auto&, const auto& coord) { return exact_velocity(t_np1, coord); }); pressure_np1.get_bc().clear(); samurai::make_bc(pressure_np1, - [&](const auto&, const auto& coord) + [&](const auto&, const auto&, const auto& coord) { return exact_normal_grad_pressure(t_np1, coord); }); diff --git a/demos/from_obj/main.cpp b/demos/from_obj/main.cpp index b0caec141..52e807b9d 100644 --- a/demos/from_obj/main.cpp +++ b/demos/from_obj/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include namespace fs = std::filesystem; diff --git a/demos/highorder/main.cpp b/demos/highorder/main.cpp index 0fdf1cd7d..d2fa1da4b 100644 --- a/demos/highorder/main.cpp +++ b/demos/highorder/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include #include @@ -266,7 +266,7 @@ int main(int argc, char* argv[]) auto u = samurai::make_field("u", mesh); samurai::make_bc(u, - [](const auto&, const auto& coord) + [](const auto&, const auto&, const auto& coord) { const auto& x = coord[0]; const auto& y = coord[1]; diff --git a/demos/multigrid/test_cases.hpp b/demos/multigrid/test_cases.hpp index f91afce02..6e883e657 100644 --- a/demos/multigrid/test_cases.hpp +++ b/demos/multigrid/test_cases.hpp @@ -42,12 +42,12 @@ class TestCase { if (solution_is_known()) { - return [&](const auto&, const auto& coords) + return [&](const auto&, const auto&, const auto& coords) { return solution()(coords); }; } - return [](const cell_t&, const coords_t&) + return [](const auto&, const cell_t&, const coords_t&) { if constexpr (Field::size == 1) { @@ -150,7 +150,7 @@ class PolynomialTestCase : public TestCase boundary_cond_t dirichlet() override { - return [](const cell_t&, const coords_t&) + return [](const auto&, const cell_t&, const coords_t&) { if constexpr (Field::size == 1) { @@ -169,7 +169,7 @@ class PolynomialTestCase : public TestCase { if constexpr (dim == 1) { - return [](const auto&, const coords_t& coord) + return [](const auto&, const auto&, const coords_t& coord) { const auto& x = coord[0]; if (x == 0 || x == 1) @@ -185,7 +185,7 @@ class PolynomialTestCase : public TestCase } else if constexpr (dim == 2) { - return [](const auto&, const auto& coord) + return [](const auto&, const auto&, const auto& coord) { const auto& x = coord[0]; const auto& y = coord[1]; diff --git a/demos/p4est/simple_2d.cpp b/demos/p4est/simple_2d.cpp index 9a40380b5..12570f5ca 100644 --- a/demos/p4est/simple_2d.cpp +++ b/demos/p4est/simple_2d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/pablo/bubble_2d.cpp b/demos/pablo/bubble_2d.cpp index 3b08d06f9..71ad84cc0 100644 --- a/demos/pablo/bubble_2d.cpp +++ b/demos/pablo/bubble_2d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include @@ -227,7 +227,7 @@ void make_graduation(samurai::CellArray& ca) int main(int argc, char* argv[]) { - constexpr std::size_t dim = 2; + constexpr std::size_t dim = 2; // cppcheck-suppress unreadVariable // Simulation parameters std::vector min_corner_v = {0., 0.}; diff --git a/demos/tutorial/2D_mesh.cpp b/demos/tutorial/2D_mesh.cpp index 903fa2f8f..99f1cc8d5 100644 --- a/demos/tutorial/2D_mesh.cpp +++ b/demos/tutorial/2D_mesh.cpp @@ -14,7 +14,7 @@ namespace fs = std::filesystem; int main(int argc, char* argv[]) { - constexpr std::size_t dim = 2; + constexpr std::size_t dim = 2; // cppcheck-suppress unreadVariable samurai::CellList cl; // Output parameters diff --git a/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp index 053e2b1a3..150993c86 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_0/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include @@ -37,7 +37,7 @@ int main(int argc, char* argv[]) fs::create_directory(path); } - constexpr std::size_t dim = 1; + constexpr std::size_t dim = 1; // cppcheck-suppress unreadVariable const std::size_t init_level = 4; /** diff --git a/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp index f3144e227..e9e577372 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_1/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include @@ -40,7 +40,7 @@ int main(int argc, char* argv[]) fs::create_directory(path); } - constexpr std::size_t dim = 1; + constexpr std::size_t dim = 1; // cppcheck-suppress unreadVariable const std::size_t init_level = 6; const samurai::Box box({-3}, {3}); diff --git a/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp index 87a8bf760..23bcb8f9c 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_2/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include @@ -48,7 +48,7 @@ int main(int argc, char* argv[]) fs::create_directory(path); } - constexpr std::size_t dim = 1; + constexpr std::size_t dim = 1; // cppcheck-suppress unreadVariable const std::size_t init_level = 6; const samurai::Box box({-3}, {3}); diff --git a/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp index 05ed9f403..49698d459 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_3/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include diff --git a/demos/tutorial/AMR_1D_Burgers/step_4/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_4/main.cpp index 2fa7a5b05..88cba9655 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_4/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_4/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include diff --git a/demos/tutorial/AMR_1D_Burgers/step_5/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_5/main.cpp index e7b74ccc9..0b75fb307 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_5/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_5/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include diff --git a/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp b/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp index 62559f52c..854917c82 100644 --- a/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp +++ b/demos/tutorial/AMR_1D_Burgers/step_6/main.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include diff --git a/demos/tutorial/graduation_case_1.cpp b/demos/tutorial/graduation_case_1.cpp index a73c24383..78115fb0f 100644 --- a/demos/tutorial/graduation_case_1.cpp +++ b/demos/tutorial/graduation_case_1.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include diff --git a/demos/tutorial/graduation_case_2.cpp b/demos/tutorial/graduation_case_2.cpp index 87ee5d90f..e710babeb 100644 --- a/demos/tutorial/graduation_case_2.cpp +++ b/demos/tutorial/graduation_case_2.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include diff --git a/demos/tutorial/graduation_case_3.cpp b/demos/tutorial/graduation_case_3.cpp index 432141d3e..84d0646d9 100644 --- a/demos/tutorial/graduation_case_3.cpp +++ b/demos/tutorial/graduation_case_3.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include @@ -18,7 +18,7 @@ namespace fs = std::filesystem; auto generate_mesh(std::size_t start_level) { - constexpr std::size_t dim = 2; + constexpr std::size_t dim = 2; // cppcheck-suppress unreadVariable const samurai::Box box({-(2 << start_level), -(2 << start_level)}, {2 << start_level, 2 << start_level}); samurai::CellArray ca; @@ -29,7 +29,7 @@ auto generate_mesh(std::size_t start_level) int main(int argc, char* argv[]) { - constexpr std::size_t dim = 2; + constexpr std::size_t dim = 2; // cppcheck-suppress unreadVariable std::size_t start_level = 1; std::size_t max_level = 6; bool with_graduation = true; diff --git a/demos/tutorial/interval.cpp b/demos/tutorial/interval.cpp index 343d08466..caeeea733 100644 --- a/demos/tutorial/interval.cpp +++ b/demos/tutorial/interval.cpp @@ -9,7 +9,7 @@ int main() { - constexpr std::size_t dim = 2; + constexpr std::size_t dim = 2; // cppcheck-suppress unreadVariable samurai::CellList cl; diff --git a/demos/tutorial/reconstruction_1d.cpp b/demos/tutorial/reconstruction_1d.cpp index bd4346d83..2f6e26c03 100644 --- a/demos/tutorial/reconstruction_1d.cpp +++ b/demos/tutorial/reconstruction_1d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/tutorial/reconstruction_2d.cpp b/demos/tutorial/reconstruction_2d.cpp index d3e69b706..65f882eeb 100644 --- a/demos/tutorial/reconstruction_2d.cpp +++ b/demos/tutorial/reconstruction_2d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/demos/tutorial/reconstruction_3d.cpp b/demos/tutorial/reconstruction_3d.cpp index da91c3047..7f83999e6 100644 --- a/demos/tutorial/reconstruction_3d.cpp +++ b/demos/tutorial/reconstruction_3d.cpp @@ -1,7 +1,7 @@ // Copyright 2021 SAMURAI TEAM. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -#include "CLI/CLI.hpp" +#include #include #include diff --git a/include/samurai/algorithm/graduation.hpp b/include/samurai/algorithm/graduation.hpp index cb54d7c3b..962ae14e6 100644 --- a/include/samurai/algorithm/graduation.hpp +++ b/include/samurai/algorithm/graduation.hpp @@ -114,7 +114,7 @@ namespace samurai std::size_t max_level = mesh.max_level(); - constexpr int ghost_width = mesh_t::config::graduation_width; + constexpr int ghost_width = mesh_t::config::graduation_width; // cppcheck-suppress unreadVariable for (std::size_t level = max_level; level > 0; --level) { diff --git a/include/samurai/bc.hpp b/include/samurai/bc.hpp index 96950dcdd..5291df875 100644 --- a/include/samurai/bc.hpp +++ b/include/samurai/bc.hpp @@ -86,6 +86,7 @@ namespace samurai static constexpr std::size_t dim = Field::dim; using value_t = detail::return_type_t; using coords_t = xt::xtensor_fixed>; + using direction_t = xt::xtensor_fixed>; using cell_t = typename Field::cell_t; virtual ~BcValue() = default; @@ -94,9 +95,9 @@ namespace samurai BcValue(BcValue&&) = delete; BcValue& operator=(BcValue&&) = delete; - virtual value_t get_value(const cell_t&, const coords_t&) const = 0; - virtual std::unique_ptr clone() const = 0; - virtual BCVType type() const = 0; + virtual value_t get_value(const direction_t& d, const cell_t&, const coords_t&) const = 0; + virtual std::unique_ptr clone() const = 0; + virtual BCVType type() const = 0; protected: @@ -108,17 +109,18 @@ namespace samurai { public: - using base_t = BcValue; - using value_t = typename base_t::value_t; - using coords_t = typename base_t::coords_t; - using cell_t = typename base_t::cell_t; + using base_t = BcValue; + using value_t = typename base_t::value_t; + using coords_t = typename base_t::coords_t; + using direction_t = typename base_t::direction_t; + using cell_t = typename base_t::cell_t; template ConstantBc(const CT... v); ConstantBc(); - value_t get_value(const cell_t&, const coords_t&) const override; + value_t get_value(const direction_t&, const cell_t&, const coords_t&) const override; std::unique_ptr clone() const override; BCVType type() const override; @@ -132,15 +134,16 @@ namespace samurai { public: - using base_t = BcValue; - using value_t = typename base_t::value_t; - using coords_t = typename base_t::coords_t; - using cell_t = typename base_t::cell_t; - using function_t = std::function; + using base_t = BcValue; + using value_t = typename base_t::value_t; + using coords_t = typename base_t::coords_t; + using direction_t = typename base_t::direction_t; + using cell_t = typename base_t::cell_t; + using function_t = std::function; FunctionBc(const function_t& f); - value_t get_value(const cell_t& cell_in, const coords_t& coords) const override; + value_t get_value(const direction_t& d, const cell_t& cell_in, const coords_t& coords) const override; std::unique_ptr clone() const override; BCVType type() const override; @@ -167,7 +170,7 @@ namespace samurai } template - inline auto ConstantBc::get_value(const cell_t&, const coords_t&) const -> value_t + inline auto ConstantBc::get_value(const direction_t&, const cell_t&, const coords_t&) const -> value_t { return m_v; } @@ -191,9 +194,9 @@ namespace samurai } template - inline auto FunctionBc::get_value(const cell_t& cell_in, const coords_t& coords) const -> value_t + inline auto FunctionBc::get_value(const direction_t& d, const cell_t& cell_in, const coords_t& coords) const -> value_t { - return m_func(cell_in, coords); + return m_func(d, cell_in, coords); } template @@ -515,10 +518,12 @@ namespace samurai static constexpr std::size_t dim = Field::dim; static constexpr std::size_t size = Field::size; + using mesh_t = typename Field::mesh_t; using interval_t = typename Field::interval_t; using bcvalue_t = BcValue; using bcvalue_impl = std::unique_ptr; + using direction_t = typename bcvalue_t::direction_t; using value_t = typename bcvalue_t::value_t; using coords_t = typename bcvalue_t::coords_t; using cell_t = typename bcvalue_t::cell_t; @@ -548,14 +553,14 @@ namespace samurai auto get_region() const; - template - void update_values(const Direction& d, + void update_values(const mesh_t& mesh, + const direction_t& d, std::size_t level, const interval_t& i, xt::xtensor_fixed> index); value_t constant_value(); - value_t value(const cell_t& cell_in, const coords_t& coords) const; + value_t value(const direction_t& d, const cell_t& cell_in, const coords_t& coords) const; const auto& value() const; BCVType get_value_type() const; @@ -631,8 +636,8 @@ namespace samurai } template - template - void Bc::update_values(const Direction& dir, + void Bc::update_values(const mesh_t& mesh, + const direction_t& dir, std::size_t level, const interval_t& i, xt::xtensor_fixed> index) @@ -651,7 +656,7 @@ namespace samurai { shift = dir[d] < 0 ? -dir[d] : -dir[d] + 1; coords[d] = dx * (index[d - 1] + shift); - cell_in.indices[d] = index[d - 1] + dir[d]; + cell_in.indices[d] = index[d - 1] - dir[d]; } if constexpr (size == 1) @@ -663,11 +668,13 @@ namespace samurai m_value.resize({i.size(), size}); } - cell_in.indices[0] = i.start + dir[0]; - cell_in.index = i.index; + cell_in.indices[0] = i.start - dir[0]; + cell_in.index = mesh.get_index(level, cell_in.indices); + cell_in.length = cell_length(level); + for (std::size_t ii = 0; ii < i.size(); ++ii) { - xt::view(m_value, ii) = p_bcvalue->get_value(cell_in, coords); + xt::view(m_value, ii) = p_bcvalue->get_value(dir, cell_in, coords); coords[0] += dx; ++cell_in.indices[0]; ++cell_in.index; @@ -678,7 +685,7 @@ namespace samurai template inline auto Bc::constant_value() -> value_t { - return p_bcvalue->get_value({}, {}); + return p_bcvalue->get_value({}, {}, {}); } template @@ -688,9 +695,9 @@ namespace samurai } template - inline auto Bc::value(const cell_t& cell_in, const coords_t& coords) const -> value_t + inline auto Bc::value(const direction_t& d, const cell_t& cell_in, const coords_t& coords) const -> value_t { - return p_bcvalue->get_value(cell_in, coords); + return p_bcvalue->get_value(d, cell_in, coords); } template @@ -838,7 +845,7 @@ namespace samurai } else if (bc.get_value_type() == BCVType::function) { - bc.update_values(direction[d], level, i, index); + bc.update_values(field.mesh(), direction[d], level, i, index); if constexpr (dim == 1) { @@ -928,7 +935,7 @@ namespace samurai } else if (bc.get_value_type() == BCVType::function) { - bc.update_values(direction[d], level, i, index); + bc.update_values(field.mesh(), direction[d], level, i, index); if constexpr (dim == 1) { diff --git a/include/samurai/field_expression.hpp b/include/samurai/field_expression.hpp index a91acee0b..6f9eeac2d 100644 --- a/include/samurai/field_expression.hpp +++ b/include/samurai/field_expression.hpp @@ -4,10 +4,10 @@ #pragma once -#include "xtl/xtype_traits.hpp" +#include -#include "xtensor/xexpression.hpp" -#include "xtensor/xmath.hpp" +#include +#include #include "cell.hpp" #include "interval.hpp" diff --git a/include/samurai/petsc/fv/FV_scheme_assembly.hpp b/include/samurai/petsc/fv/FV_scheme_assembly.hpp index 75c43c860..af4f1ca7d 100644 --- a/include/samurai/petsc/fv/FV_scheme_assembly.hpp +++ b/include/samurai/petsc/fv/FV_scheme_assembly.hpp @@ -592,12 +592,12 @@ namespace samurai double bc_value; if constexpr (field_size == 1) { - bc_value = bc->value({}, boundary_point); + bc_value = bc->value({}, {}, boundary_point); } else { - bc_value = bc->value({}, boundary_point)(field_i); // TODO: call get_value() only once instead of - // once per field_i + bc_value = bc->value({}, {}, boundary_point)(field_i); // TODO: call get_value() only once instead of + // once per field_i } if constexpr (dirichlet_enfcmt == DirichletEnforcement::Elimination) diff --git a/include/samurai/stencil.hpp b/include/samurai/stencil.hpp index a0efc7bb4..53b353265 100644 --- a/include/samurai/stencil.hpp +++ b/include/samurai/stencil.hpp @@ -337,7 +337,7 @@ namespace samurai template auto directional_stencils() { - static_assert(dim >= 1 && dim <= 2, "directional_stencils() not implemented for this dimension"); + static_assert(dim >= 1 && dim <= 3, "directional_stencils() not implemented for this dimension"); static_assert(neighbourhood_width >= 0 && neighbourhood_width <= 2, "directional_stencils() not implemented for this neighbourhood width"); @@ -378,6 +378,27 @@ namespace samurai dir_stencils[3].direction = {0, -1}; dir_stencils[3].stencil = {{0, 0 }, {0, 1 }, {0, -1}}; } + else if constexpr (dim == 3) + { + // Left + dir_stencils[0].direction = {-1, 0, 0}; + dir_stencils[0].stencil = {{0, 0, 0}, {1, 0, 0}, {-1, 0, 0}}; + // Top + dir_stencils[1].direction = {0, 1, 0}; + dir_stencils[1].stencil = {{0, 0 ,0}, {0, -1,0}, {0, 1,0 }}; + // Right + dir_stencils[2].direction = {1, 0,0}; + dir_stencils[2].stencil = {{0, 0,0}, {-1, 0,0}, {1, 0,0}}; + // Bottom + dir_stencils[3].direction = {0, -1,0}; + dir_stencils[3].stencil = {{0, 0,0 }, {0, 1,0 }, {0, -1,0}}; + // Back + dir_stencils[4].direction = {0, 0,-1}; + dir_stencils[4].stencil = {{0, 0,0}, {0, 0,1}, {0, 0,-1}}; + // Front + dir_stencils[5].direction = {0, 0, 1}; + dir_stencils[5].stencil = {{0, 0,0 }, {0, 0, -1}, {0, 0,1}}; + } // clang-format on } else if constexpr (neighbourhood_width == 2) @@ -407,6 +428,27 @@ namespace samurai dir_stencils[3].direction = {0, -1}; dir_stencils[3].stencil = {{0, 0 }, {0, 1 }, {0, 2 }, {0, -1}, {0, -2}}; } + else if constexpr (dim == 3) + { + // Left + dir_stencils[0].direction = {-1, 0, 0}; + dir_stencils[0].stencil = {{0, 0, 0}, {1, 0, 0}, {2, 0, 0}, {-1, 0, 0}, {-2, 0, 0}}; + // Top + dir_stencils[1].direction = {0, 1, 0}; + dir_stencils[1].stencil = {{0, 0 , 0}, {0, -1, 0}, {0, -2, 0}, {0, 1 , 0}, {0, 2 , 0}}; + // Right + dir_stencils[2].direction = {1, 0, 0}; + dir_stencils[2].stencil = {{0, 0, 0}, {-1, 0, 0}, {-2, 0, 0}, {1, 0, 0}, {2, 0, 0}}; + // Bottom + dir_stencils[3].direction = {0, -1, 0}; + dir_stencils[3].stencil = {{0, 0 , 0}, {0, 1 , 0}, {0, 2 , 0}, {0, -1, 0}, {0, -2, 0}}; + // Back + dir_stencils[4].direction = {0, 0, -1}; + dir_stencils[4].stencil = {{0, 0, 0}, {0, 0, 1}, {0, 0, 2}, {0, 0, -1}, {0, 0, -2}}; + // Front + dir_stencils[5].direction = {0, 0, 1}; + dir_stencils[5].stencil = {{0, 0, 0}, {0, 0, -1}, {0, 0, -2}, {0, 0, 1}, {0, 0, 2}}; + } // clang-format on } return dir_stencils; diff --git a/include/samurai/subset/subset_node.hpp b/include/samurai/subset/subset_node.hpp index 1c0e2c870..a50f0e994 100644 --- a/include/samurai/subset/subset_node.hpp +++ b/include/samurai/subset/subset_node.hpp @@ -104,6 +104,12 @@ namespace samurai inline subset_node::subset_node(T&& node) : m_node(std::forward(node)) { + m_index.fill(std::numeric_limits::infinity()); + m_ipos.fill(std::numeric_limits::infinity()); + m_start.fill(std::numeric_limits::infinity()); + m_end.fill(std::numeric_limits::infinity()); + m_start_offset.fill(std::numeric_limits::infinity()); + m_end_offset.fill(std::numeric_limits::infinity()); } /**