DamBreak++ Wave Simulator 0.3
DamBreak++ Simulation Framework
Loading...
Searching...
No Matches
Sfx_UpwindScheme1st.hpp
Go to the documentation of this file.
1#pragma once
2
3// C++ includes
4#include <cassert>
5#include <vector>
6#include <ranges> // C++20 features
7// STL include
8#include <numeric> // adjacent_difference
9// SfxBase19 include
10#include "include/Sfx_UniversalConstants.h"
11
12namespace Sfx
13{
19 template<std::ranges::input_range Rng> // Range of values
20 requires std::same_as<Rng,std::vector<double>> // only support std::vector for now
21 auto UpwindDerivatr1st( Rng aRng) //bias forward stencil (left to right propagation)
22 {
23 static_assert(Sfx::EMCNEILNbSections::value==std::ranges::size(aRng));
24
25 using value_type = std::ranges::range_value_t<Rng>;
26 using diff_t = std::ranges::range_difference_t<Rng>;
27
28 if constexpr (std::ranges::range<decltype(aRng)>)
29 {
30 Rng w_deriValues;
31 w_rngOfValues.reserve(std::ranges::distance(aRng));
32
33 // compute derivative at first order (bias upwind forward stencil)
34 std::adjacent_difference(std::ranges::begin(aRng), std::ranges::end(aRng),
35 std::back_inserter(w_deriValues));
36
37 // adjacent_difference leave the first element as is, it shall not be considered
38 // in the computation since it doesn't correspond to any gradient (container value)
39 return std::move(w_deriValues) | std::views::drop(1);
40 }
41 else
42 {
43 Rng{}; // is that make sense???
44 }
45#if 0
46 //diff_t w_Length = std::distance( std::begin(aRng), std::end(aRng));
47 //const auto w_Length = std::distance(std::begin(aRng), std::end(aRng));
48 const auto w_Length = std::ranges::distance(aRng);
49
50 // create a vector of w_length initialized to zero, is it?
51 std::vector<value_type> w_Cont;
52 w_Cont.reserve(w_Length);
53
54 // NOTE:
55 // adjacent_difference leave the first element as is, it shall not be considered
56 // in the computation since it doesn't correspond to any gradient (container value)
57 // In our case, i do think we use it exclusively for flux derivative F = F_i - F_i-1
58 // cell face ... to be completed
59 // compute the gradient (U_i - U_i-1) at first order
60 std::adjacent_difference( std::ranges::begin(aRng), std::ranges::end(aRng), std::back_inserter(w_Cont));
61 assert( w_Cont.size() == w_Length); // really need it?
62
63 // w_Cont.pop_front(); // remove first element, not part of the result
64// assert( w_Cont.size()==w_Length-1);
65
66 // return value optimization (remove first element, not part of the result)
67 return std::vector<value_type>( std::next(w_Cont.cbegin()), w_Cont.cend());
68#endif // 0
69 }
70} // End of namespace
Definition HydUtils.h:15
auto UpwindDerivatr1st(Rng aRng)
Implementation of the upwind derivative scheme using generic programming.
Definition Sfx_UpwindScheme1st.hpp:21