DamBreak++ Wave Simulator 0.3
DamBreak++ Simulation Framework
Loading...
Searching...
No Matches
dbpp_SimulationUtilities.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include <cmath>
5// C++ include
6#include <iostream>
7#include <concepts>
8#include <type_traits>
9#include <ranges> // C++20 feature
10// STL numeric
11#include <numeric>
12// SfxBase19 include
13#include "include/Sfx_UniversalConstants.h"
14// App include
15#include "../SfxBase/Sfx_Logger.h" // emcil::Logger
16#include "../include/HydUtils.h" // Hydraulic utility
17// vs19 includes
18#include "dbpp_CellFace.h"
20// Dsn package incude
21//#include "HydUtils/Dsn_HydroUtils.h"
22
23 //template<typename T1, typename... TN>
24 //constexpr bool isHomogeneous(T1, TN ...)
25 //{
26 // // return fold expression
27 // return (std::is_same_v<T1, TN> && ...);
28 //}
29
30namespace dbpp
31{
40 template<typename T, typename... TN>
42 // using fold expression (C++17 new features)
43 static constexpr bool value = (std::is_same_v<T, TN> && ...);
44 };
45
46 // just trying to implement a print function with C++17 feature
47 // variadic template and fold expression
48#if 0
56 template<auto Sep = ' ', typename First, typename... Args>
57 void print17(const First& aFirst2Print, const Args&... aArgs)
58 {
59 std::cout << aFirst2Print;
60
61 // use auto keyword in lambda expression
62 auto outWithSep = [](const auto& arg)
63 {
64 std::cout << Sep << "arg";
65 }
66
67 // use folder expression to return
68 // IMPORTANT the expansion '...' must have no white space
69 // with comma and lambda, stick all together, otherwise
70 // it doesn't compile!!!
71 (... , outWithSep(aArgs)) << '\n';
72
73 //std::cout << '\n';
74 }
75#endif
76
77 template<typename T>
78 concept dbl_arg_type = std::is_floating_point_v<T>;
79
86 template<typename T>
87 requires dbl_arg_type<T>
89 {
90 public:
91 // return type ...
92 // something has to do with decay!!
93 constexpr auto operator() (T aVal1, T aVal2)
94 {
95 using namespace std::string_literals;
96
97 if (aVal1 * aVal2 <= 0.)
98 return 0.;
99
100 else if ((std::abs(aVal1) < std::abs(aVal2)) && (aVal1 * aVal2 > 0.))
101 return aVal1;
102
103 else if ((std::abs(aVal2) < std::abs(aVal1)) && (aVal1 * aVal2 > 0.))
104 return aVal2;
105
106 else if (std::abs(aVal2) == std::abs(aVal1)) // ATTENTION, mis pour v�rification !!!! sanity check!!
107 return aVal1;
108 else
109 {
110 // NO!!! hard to debug
111 std::cerr << "Fonction MINMOD: situation ne correspondant pas a celle attendue\n";
112 Sfx::Logger::instance()->OutputError("Fonction MINMOD: situation ne correspondant pas a celle attendue"s.data());
113 exit(EXIT_FAILURE); // what else to do? throw an exception
114 }
115 }
116 };
117
122 {
123 public:
125 using argument_type = std::pair<float64,float64>;
131 ManningFormula(float64 aRoughnessCoeff) : m_N{ aRoughnessCoeff } {}
138 {
139 // structured binding C++17
140 auto [A, Q] = aNval;
141
142 // Hydraulic radius (unit width).
143 //HydroUtils::R w_R;
144 //const auto Rh = Dsn::R(A, 1.); // A
145 const auto Rh = Sfx::HydRadius(A, 1.); // A
146
147 // define some for clarity (check doc for Manning relation ())
148 const auto gNN = Sfx::cGravity<float64>*m_N * m_N;
149 const auto V = Q / A; // velocity (Q/A)
150 const auto Vsquaredivh = V * std::fabs(V) / ((A * A) * std::pow(Rh, 4. / 3.));
151
152 return gNN * Vsquaredivh;
153 }
154 private:
156 };
157
165 {
166 return (A / B + Z);
167 }
168
176 {
177 return (H - Z) * B;
178 }
179
180 // Usage
181 // auto w_funcAfromH = []( const SectFlow* aSectFlow)
182 // {
183 // return HydroUtils::Evaluation_A_fonction_H(aSectFlow->H(),aSectFlow->Z(),aSectFlow->B());
184 // }
185 // just experimenting
186 template<typename UnaryFunctor> //could be a lambda or callable
187 decltype(auto) Evaluation_A_fonction_H14( const ListSectionsFlow& aSectF, UnaryFunctor aFunctor)
188 {
189 // Not sure if it is working, ListSectFlow has member begin/end
190 return std::for_each(std::begin(aSectF), std::end(aSectF), aFunctor);
191 }
192
198 template<typename Range>
199 std::ranges::range_value_t<Range> maxValue(Range&& aRng)
200 {
201 // NOTE
202 // pass range as universal reference because cannot iterate
203 // on some lightweight range (views) when they are constant
204 if constexpr (std::ranges::empty(aRng))
205 {
206 return std::ranges::range_value_t<Range>{};
207 }
208 // init max value
209 auto maxValue = *std::ranges::begin(aRng);
210 // search for max value
211 for(auto pos = std::ranges::begin(aRng);
212 pos!=std::ranges::end(aRng);++pos)
213 {
214 if (*pos>maxValue)
215 {
216 maxValue = *pos;
217 }
218 }
219 return maxValue;
220 }
221
228 template<typename CB>
230 {
231 public:
236 callCounter(CB aCallBack) : m_callBack{ aCallBack } {}
243 template<typename ...Args>
244 decltype(auto) operator() (Args&& ...args)
245 {
246 ++m_count;
247 return m_callBack(std::forward<Args>(args)...);
248 }
249
253 long count() const { return m_count; }
254 private:
256 long m_count{};
257 std::atomic_long m_parCounter{};
258 };
259} // End of namespace
List of cross-section flow (itereable)
Definition dbpp_ListSectionsFlow.h:15
float64 result_type
Definition dbpp_SimulationUtilities.hpp:126
result_type operator()(const argument_type &aNval) const
Compute friction according to Manning friction law.
Definition dbpp_SimulationUtilities.hpp:137
ManningFormula(float64 aRoughnessCoeff)
ctor fro roughness coefficient
Definition dbpp_SimulationUtilities.hpp:131
float64 m_N
Definition dbpp_SimulationUtilities.hpp:155
std::pair< float64, float64 > argument_type
Definition dbpp_SimulationUtilities.hpp:125
Minmod limiter function for slope limiting gradient evaluation.
Definition dbpp_SimulationUtilities.hpp:89
constexpr auto operator()(T aVal1, T aVal2)
Definition dbpp_SimulationUtilities.hpp:93
long count() const
Counter.
Definition dbpp_SimulationUtilities.hpp:253
callCounter(CB aCallBack)
Ctor enables deduction of calback type as the template parameter.
Definition dbpp_SimulationUtilities.hpp:236
long m_count
Definition dbpp_SimulationUtilities.hpp:256
std::atomic_long m_parCounter
Definition dbpp_SimulationUtilities.hpp:257
CB m_callBack
Definition dbpp_SimulationUtilities.hpp:255
Definition dbpp_SimulationUtilities.hpp:78
constexpr float64 HydRadius(float64 aArea, float64 aWidth=1.)
Function specific to a rectangular channel of width B Perimeter established according to a flow area ...
Definition HydUtils.h:70
Definition DamBreakProb.h:15
@ A
Definition dbpp_Enumerations.h:16
@ Q
Definition dbpp_Enumerations.h:17
@ H
Definition dbpp_Enumerations.h:18
double float64
Definition dbpp_LDeltaOperator.h:12
constexpr float64 Evaluation_A_fonction_H(float64 H, float64 Z, float64 B=1.)
Function that evaluate wetted area in terms of section parameters (H,B,Z)
Definition dbpp_SimulationUtilities.hpp:175
decltype(auto) Evaluation_A_fonction_H14(const ListSectionsFlow &aSectF, UnaryFunctor aFunctor)
Definition dbpp_SimulationUtilities.hpp:187
constexpr float64 Evaluation_H_fonction_A(float64 A, float64 Z, float64 B=1.)
Function that evaluate water level in terms section width and bathymetry.
Definition dbpp_SimulationUtilities.hpp:164
std::ranges::range_value_t< Range > maxValue(Range &&aRng)
find maximum value of a range
Definition dbpp_SimulationUtilities.hpp:199
Check if types are identical using fold expression.
Definition dbpp_SimulationUtilities.hpp:41
static constexpr bool value
Definition dbpp_SimulationUtilities.hpp:43