Skip to content

Commit 3adb56d

Browse files
committed
add mesh_config
1 parent de19ff4 commit 3adb56d

File tree

5 files changed

+194
-3
lines changed

5 files changed

+194
-3
lines changed

demos/FiniteVolume/heat.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,6 @@ int main(int argc, char* argv[])
102102
app.add_option("--restart-file", restart_file, "Restart file")->capture_default_str()->group("Simulation parameters");
103103
app.add_option("--dt", dt, "Time step")->capture_default_str()->group("Simulation parameters");
104104
app.add_option("--cfl", cfl, "The CFL")->capture_default_str()->group("Simulation parameters");
105-
app.add_option("--min-level", min_level, "Minimum level of the multiresolution")->capture_default_str()->group("Multiresolution");
106-
app.add_option("--max-level", max_level, "Maximum level of the multiresolution")->capture_default_str()->group("Multiresolution");
107105
app.add_option("--path", path, "Output path")->capture_default_str()->group("Output");
108106
app.add_option("--filename", filename, "File name prefix")->capture_default_str()->group("Output");
109107
app.add_flag("--save-final-state-only", save_final_state_only, "Save final state only")->group("Output");
@@ -127,7 +125,8 @@ int main(int argc, char* argv[])
127125

128126
if (restart_file.empty())
129127
{
130-
mesh = {box, min_level, max_level};
128+
auto config = samurai::mesh_config<dim>().min_level(min_level).max_level(max_level);
129+
mesh = {config, box};
131130
u.resize();
132131
// Initial solution
133132
if (init_sol == "dirac")

include/samurai/arguments.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ namespace samurai
88
{
99
namespace args
1010
{
11+
// Mesh arguments
12+
static std::size_t min_level = std::numeric_limits<std::size_t>::infinity();
13+
static std::size_t max_level = std::numeric_limits<std::size_t>::infinity();
14+
1115
static bool timers = false;
1216
#ifdef SAMURAI_WITH_MPI
1317
static bool dont_redirect_output = false;
@@ -24,6 +28,9 @@ namespace samurai
2428

2529
inline void read_samurai_arguments(CLI::App& app, int& argc, char**& argv)
2630
{
31+
app.add_option("--min-level", args::min_level, "The minimum level of the mesh")->group("SAMURAI");
32+
app.add_option("--max-level", args::max_level, "The maximum level of the mesh")->group("SAMURAI");
33+
2734
#ifdef SAMURAI_WITH_MPI
2835
app.add_flag("--dont-redirect-output", args::dont_redirect_output, "Redirect the output for all ranks different of 0")
2936
->capture_default_str()

include/samurai/mesh.hpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "cell_array.hpp"
1212
#include "cell_list.hpp"
1313
#include "domain_builder.hpp"
14+
#include "mesh_config.hpp"
1415
#include "static_algorithm.hpp"
1516
#include "stencil.hpp"
1617
#include "subset/node.hpp"
@@ -156,6 +157,7 @@ namespace samurai
156157
Mesh_base(const cl_type& cl, const self_type& ref_mesh);
157158
Mesh_base(const cl_type& cl, std::size_t min_level, std::size_t max_level);
158159
Mesh_base(const ca_type& ca, std::size_t min_level, std::size_t max_level);
160+
Mesh_base(mesh_config<Config::dim>& config, const samurai::Box<double, dim>& b, std::size_t start_level);
159161
Mesh_base(const samurai::Box<double, dim>& b,
160162
std::size_t start_level,
161163
std::size_t min_level,
@@ -246,6 +248,35 @@ namespace samurai
246248
return *static_cast<derived_type*>(this);
247249
}
248250

251+
template <class D, class Config>
252+
inline Mesh_base<D, Config>::Mesh_base(mesh_config<Config::dim>& config, const samurai::Box<double, dim>& b, std::size_t start_level)
253+
: m_domain{start_level, b, (config.parse_args(), config.approx_box_tol()), config.scaling_factor()}
254+
, m_min_level{config.min_level()}
255+
, m_max_level{config.max_level()}
256+
{
257+
// config.parse_args();
258+
// m_min_level = config.min_level();
259+
// m_max_level = config.max_level();
260+
261+
assert(m_min_level <= m_max_level);
262+
263+
#ifdef SAMURAI_WITH_MPI
264+
partition_mesh(start_level, b);
265+
// load_balancing();
266+
#else
267+
this->m_cells[mesh_id_t::cells][start_level] = {start_level, b, config.approx_box_tol(), config.scaling_factor()};
268+
#endif
269+
construct_subdomain();
270+
construct_union();
271+
update_sub_mesh();
272+
construct_corners();
273+
renumbering();
274+
update_mesh_neighbour();
275+
276+
set_origin_point(origin_point());
277+
set_scaling_factor(config.scaling_factor());
278+
}
279+
249280
template <class D, class Config>
250281
inline Mesh_base<D, Config>::Mesh_base(const samurai::Box<double, dim>& b,
251282
std::size_t start_level,

include/samurai/mesh_config.hpp

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// Copyright 2018-2025 the samurai's authors
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
#pragma once
5+
6+
#include "arguments.hpp"
7+
#include <array>
8+
9+
namespace samurai
10+
{
11+
12+
template <std::size_t dim_>
13+
class mesh_config
14+
{
15+
public:
16+
17+
static constexpr std::size_t dim = dim_;
18+
19+
mesh_config()
20+
{
21+
m_periodic.fill(false);
22+
}
23+
24+
auto& max_stencil_width(std::size_t stencil_width)
25+
{
26+
m_max_stencil_width = stencil_width;
27+
return *this;
28+
}
29+
30+
auto& max_stencil_width() const
31+
{
32+
return m_max_stencil_width;
33+
}
34+
35+
auto& graduation_width(std::size_t grad_width)
36+
{
37+
m_graduation_width = grad_width;
38+
return *this;
39+
}
40+
41+
auto& graduation_width() const
42+
{
43+
return m_graduation_width;
44+
}
45+
46+
auto& min_level(std::size_t level)
47+
{
48+
m_min_level = level;
49+
return *this;
50+
}
51+
52+
auto& min_level() const
53+
{
54+
return m_min_level;
55+
}
56+
57+
auto& max_level(std::size_t level)
58+
{
59+
m_max_level = level;
60+
return *this;
61+
}
62+
63+
auto& max_level() const
64+
{
65+
return m_max_level;
66+
}
67+
68+
auto& approx_box_tol(double tol)
69+
{
70+
m_approx_box_tol = tol;
71+
return *this;
72+
}
73+
74+
auto& approx_box_tol() const
75+
{
76+
return m_approx_box_tol;
77+
}
78+
79+
auto& scaling_factor(double factor)
80+
{
81+
m_scaling_factor = factor;
82+
return *this;
83+
}
84+
85+
auto& scaling_factor() const
86+
{
87+
return m_scaling_factor;
88+
}
89+
90+
auto& periodic(std::array<bool, dim> const& periodicity)
91+
{
92+
m_periodic = periodicity;
93+
return *this;
94+
}
95+
96+
auto& periodic() const
97+
{
98+
return m_periodic;
99+
}
100+
101+
auto& periodic(std::size_t i) const
102+
{
103+
return m_periodic[i];
104+
}
105+
106+
void parse_args()
107+
{
108+
// if (args::max_stencil_width != std::numeric_limits<std::size_t>::max())
109+
// {
110+
// m_max_stencil_width = args::max_stencil_width;
111+
// }
112+
// if (args::graduation_width != std::numeric_limits<std::size_t>::max())
113+
// {
114+
// m_graduation_width = args::graduation_width;
115+
// }
116+
if (args::min_level != std::numeric_limits<std::size_t>::max())
117+
{
118+
m_min_level = args::min_level;
119+
}
120+
if (args::max_level != std::numeric_limits<std::size_t>::max())
121+
{
122+
m_max_level = args::max_level;
123+
}
124+
// if (args::approx_box_tol != std::numeric_limits<double>::infinity())
125+
// {
126+
// m_approx_box_tol = args::approx_box_tol;
127+
// }
128+
// if (args::scaling_factor != std::numeric_limits<double>::infinity())
129+
// {
130+
// m_scaling_factor = args::scaling_factor;
131+
// }
132+
}
133+
134+
private:
135+
136+
std::size_t m_max_stencil_width = 1;
137+
std::size_t m_graduation_width = 1;
138+
139+
std::size_t m_min_level;
140+
std::size_t m_max_level;
141+
142+
double m_approx_box_tol = 0.05;
143+
double m_scaling_factor = 0;
144+
145+
std::array<bool, dim> m_periodic;
146+
};
147+
}

include/samurai/mr/mesh.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ namespace samurai
7777
MRMesh(const cl_type& cl, const self_type& ref_mesh);
7878
MRMesh(const cl_type& cl, std::size_t min_level, std::size_t max_level);
7979
MRMesh(const ca_type& ca, std::size_t min_level, std::size_t max_level);
80+
MRMesh(mesh_config<Config::dim>& config, const samurai::Box<double, dim>& b);
8081
MRMesh(const samurai::Box<double, dim>& b,
8182
std::size_t min_level,
8283
std::size_t max_level,
@@ -124,6 +125,12 @@ namespace samurai
124125
{
125126
}
126127

128+
template <class Config>
129+
inline MRMesh<Config>::MRMesh(mesh_config<Config::dim>& config, const samurai::Box<double, dim>& b)
130+
: base_type(config, b, (config.parse_args(), config.max_level()))
131+
{
132+
}
133+
127134
template <class Config>
128135
inline MRMesh<Config>::MRMesh(const samurai::Box<double, dim>& b,
129136
std::size_t min_level,

0 commit comments

Comments
 (0)