DamBreak++ Wave Simulator 0.3
DamBreak++ Simulation Framework
Loading...
Searching...
No Matches
Testvs19_DamBreakSystem.h
Go to the documentation of this file.
1
2#pragma once
3
4#include <list>
5// boost include
6#include <boost/ptr_container/ptr_vector.hpp>
7// SfxBase19 lib includes
8#include "include/Sfx_PhysicalSystem.h"
9#include "include/Sfx_StateVector.h"
10#include "include/Sfx_Observable.h"
11// Nov19 package includes
15// BaseNumericlaTypes include
16#include "Sfx/Sfx_NodalValues.h"
17
18// forward declaration
19namespace Sfx {
20 class Observer;
21 class PhysicalObject;
22}
23
24namespace Testvs19
25{
29 class DamBreakSystem final : public Sfx::PhysicalSystem,
30 virtual public Sfx::Observable
31 {
32 public:
36 using ListSectionFlowPtr = std::shared_ptr<ListSectionsFlow<dbpp::SectionFlow>>;
37 using vecidx = std::vector<float64>::size_type;
38 using pair_vecarr = std::pair<std::vector<float64>, std::vector<float64>>;
39 using phystate = pair_vecarr; // state variables (A,Q)
40 using value_type = boost::ptr_vector<Sfx::Nodal_Value>::value_type;
41 using size_type = boost::ptr_vector<Sfx::Nodal_Value>::size_type;
42 using iterator = boost::ptr_vector<Sfx::Nodal_Value>::iterator;
43 using const_iterator = boost::ptr_vector<Sfx::Nodal_Value>::const_iterator;
44 // using riterator = std::reverse_iterator<iterator>;
45 // using criterator = std::reverse_iterator<const_iterator>;
46
50 iterator begin() { return m_Objs.begin(); }
51 iterator end() { return m_Objs.end(); }
52 const_iterator cbegin() const { return m_Objs.begin(); }
53 const_iterator cend() const { return m_Objs.end(); }
54 auto rbegin() { return m_Objs.rbegin(); }
55 auto rend() { return m_Objs.rend(); }
56 auto crbegin() const { return m_Objs.crbegin(); }
57 auto crend() const { return m_Objs.crend(); }
58
59 public:
64 explicit DamBreakSystem( std::string aName = "DamBreakSystem");
69 void add( Sfx::Object* aNval) override final;
75 bool contains( const Sfx::Object* aN2find) override final;
81 bool remove( const Sfx::Object* aN2find) override final;
86 [[nodiscard]] bool empty() const noexcept override final { return m_Objs.empty(); }
91 size_t size() const override final { return m_Objs.size(); }
92 // Design Note
93 // The reason for this, it's becausein the time stepping of
94 // the physical algorithm, predictor step we do not update
95 // H(water level), only state variables(A,Q). Then, corrector
96 // step we update final state of state variables, but also
97 // H (water level). We do it separetly, because the state
98 // variables are updated calling setState(state var).
99 void setH() // update list of sections H value
100 {
101 // consider (unit width and flat bottom)
102 std::for_each(m_listOfSections->begin(), m_listOfSections->end(),
103 [*this](dbpp::SectionFlow& aSectionFlow)
104 {
105 aSectionFlow.setH(std::get<2>(m_Objs[aSectionFlow.getId()].Values()));
106 });
107
108 // H-Variable
109 // consider (unit width and flat bottom)
110 //std::for_each(begin(), end(), [*this](Sfx::Nodal_Value& aPhyObj)
111 // {
112 // // NOTE considering flat bed Z=0, this is temp fix and must
113 // // be fix by computing the water depth using utility
114 // // Evaluation_H_fonction_A(A,Z,B=1) unit width
115 // aPhyObj.Values( std::make_tuple( m_phyState.first[aPhyObj.getIdX().first],
116 // m_phyState.second[aPhyObj.getIdX().first],
117 // m_phyState.first[aPhyObj.getIdX().first])); // assume Z=0 flat bed
118 /* }
119 // try
120 // {
121 // throw an exception
122 Sfx::Nodal_Value& w_Nvar =
123 dynamic_cast<Sfx::Nodal_Value&>(aPhyObj);
124
125 // FIX no choice to do that, since operator[] of Nodal_Value was
126 // removed, we have to use this method to modify (A,Q variables)
127 // we have already called setState() but we just overwrite it.
128 // modify at this stage state variables (A,Q), H: at final state
129 /*w_Nvar.Values(std::make_tuple(m_phyState.first[w_Nvar.getIdX().first],
130 m_phyState.second[w_Nvar.getIdX().first], m_phyState.first[w_Nvar.getIdX().first]));
131
132 catch( std::bad_cast& bc)
133 {
134 std::cerr << "Bad cast caught :" << bc.what() << "\n";
135 }*/
136// }/*Swe::Eval_H_InTerm_A(1., 0.)*/);
137 }
138
142 std::vector<float64> getH() const
143 {
144 std::vector<float64> w_vecH;
145 w_vecH.reserve(m_listOfSections->size());
146 for( const auto& w_sect : *m_listOfSections)
147 {
148 w_vecH.push_back(w_sect.H());
149 }
150 return w_vecH;
151 }
152
162 {
163 // set the physical state variables
164 m_phyState = aState;
165 }
166
171 Sfx::StateVector getSectionStateVector( vecidx aSectionIdx) const
172 {
173 return Sfx::StateVector{ m_phyState.first[aSectionIdx],
174 m_phyState.second[aSectionIdx] };
175 }
176
179 void update() // update nodal values
180 {
181 // consider (unit width and flat bottom)
182 std::for_each(begin(), end(), [*this](Sfx::Nodal_Value& aPhyObj)
183 {
184 // NOTE considering flat bed Z=0, unit width
185 aPhyObj.Values( std::make_tuple(m_phyState.first[aPhyObj.getIdX().first],
186 m_phyState.second[aPhyObj.getIdX().first], //assume Z=0 flat bed
187 dbpp::Evaluation_H_fonction_A(m_phyState.first[aPhyObj.getIdX().first],0.,1.)));
188 });
189 }
190
195
196 //
197 // Observeable Interface
198 //
199
204 void attach(Sfx::Observer* aObs2Attach) override final;
209 void detach(Sfx::Observer* aObs2Detach) override final;
213 void notify() override final;
214
215 private:
216 std::string m_name;
219 // pointer container for reference semantic (Nodal_Value)
220 //boost::ptr_vector<Sfx::Object> m_Objs;
221 boost::ptr_vector<Sfx::Nodal_Value> m_Objs;
222 std::list<Sfx::Observer*> m_listObs;
223 };
224}// End of namespace
DamBreakSystem(std::string aName="DamBreakSystem")
ctor
Definition Testvs19_DamBreakSystem.cpp:24
iterator begin()
STL-like interface.
Definition Testvs19_DamBreakSystem.h:50
std::list< Sfx::Observer * > m_listObs
Definition Testvs19_DamBreakSystem.h:222
void detach(Sfx::Observer *aObs2Detach) override final
Remove an observer.
Definition Testvs19_DamBreakSystem.cpp:16
iterator end()
Definition Testvs19_DamBreakSystem.h:51
std::shared_ptr< ListSectionsFlow< dbpp::SectionFlow > > ListSectionFlowPtr
Aliases.
Definition Testvs19_DamBreakSystem.h:36
void setPhysicalState(phystate aState)
Setter.
Definition Testvs19_DamBreakSystem.h:161
std::vector< float64 >::size_type vecidx
Definition Testvs19_DamBreakSystem.h:37
void update()
Update Nodal Values (flat bed Z=0, unit width)
Definition Testvs19_DamBreakSystem.h:179
bool remove(const Sfx::Object *aN2find) override final
Remove an object from system.
Definition Testvs19_DamBreakSystem.cpp:95
auto crbegin() const
Definition Testvs19_DamBreakSystem.h:56
void setH()
Definition Testvs19_DamBreakSystem.h:99
bool empty() const noexcept override final
check if system contains any object
Definition Testvs19_DamBreakSystem.h:86
void notify() override final
Notify all observers.
Definition Testvs19_DamBreakSystem.cpp:107
Sfx::StateVector getSectionStateVector(vecidx aSectionIdx) const
Retrieve state variables of a section flow.
Definition Testvs19_DamBreakSystem.h:171
ListSectionFlowPtr getListSectionFlow() const
Getter.
Definition Testvs19_DamBreakSystem.h:194
size_t size() const override final
Number of elements.
Definition Testvs19_DamBreakSystem.h:91
boost::ptr_vector< Sfx::Nodal_Value >::value_type value_type
Definition Testvs19_DamBreakSystem.h:40
std::string m_name
Definition Testvs19_DamBreakSystem.h:216
boost::ptr_vector< Sfx::Nodal_Value >::size_type size_type
Definition Testvs19_DamBreakSystem.h:41
boost::ptr_vector< Sfx::Nodal_Value > m_Objs
Definition Testvs19_DamBreakSystem.h:221
bool contains(const Sfx::Object *aN2find) override final
Check if object already added.
Definition Testvs19_DamBreakSystem.cpp:65
ListSectionFlowPtr m_listOfSections
Definition Testvs19_DamBreakSystem.h:218
const_iterator cend() const
Definition Testvs19_DamBreakSystem.h:53
const_iterator cbegin() const
Definition Testvs19_DamBreakSystem.h:52
void attach(Sfx::Observer *aObs2Attach) override final
Add an observer.
Definition Testvs19_DamBreakSystem.cpp:12
std::vector< float64 > getH() const
Water depth.
Definition Testvs19_DamBreakSystem.h:142
phystate m_phyState
Definition Testvs19_DamBreakSystem.h:217
boost::ptr_vector< Sfx::Nodal_Value >::const_iterator const_iterator
Definition Testvs19_DamBreakSystem.h:43
auto rend()
Definition Testvs19_DamBreakSystem.h:55
boost::ptr_vector< Sfx::Nodal_Value >::iterator iterator
Definition Testvs19_DamBreakSystem.h:42
pair_vecarr phystate
Definition Testvs19_DamBreakSystem.h:39
std::pair< std::vector< float64 >, std::vector< float64 > > pair_vecarr
Definition Testvs19_DamBreakSystem.h:38
phystate getPhysicalState() const
Getter.
Definition Testvs19_DamBreakSystem.h:156
auto rbegin()
Definition Testvs19_DamBreakSystem.h:54
void add(Sfx::Object *aNval) override final
Add object to the system.
Definition Testvs19_DamBreakSystem.cpp:47
auto crend() const
Definition Testvs19_DamBreakSystem.h:57
Cross-sectional flow (2-dimensional).
Definition dbpp_SectionFlow.h:16
Definition HydUtils.h:15
Definition Testvs19_BaseRhsPhysicsAlgorithm.cpp:19
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