1 /*!
2  * \file   StudyCurrentState.cxx
3  * \brief
4  * \author Thomas Helfer
5  * \date   11 nov. 2015
6  * \copyright Copyright (C) 2006-2018 CEA/DEN, EDF R&D. All rights
7  * reserved.
8  * This project is publicly released under either the GNU GPL Licence
9  * or the CECILL-A licence. A copy of thoses licences are delivered
10  * with the sources of TFEL. CEA or EDF may also distribute this
11  * project under specific licensing conditions.
12  */
13 
14 #include"TFEL/Raise.hxx"
15 #include"MTest/StudyCurrentState.hxx"
16 #include"MTest/StructureCurrentState.hxx"
17 
18 namespace mtest{
19 
20   StudyCurrentState::StudyCurrentState() = default;
21 
22   StudyCurrentState::StudyCurrentState(StudyCurrentState&&)      = default;
23 
24   StudyCurrentState::StudyCurrentState(const StudyCurrentState&) = default;
25 
26   StudyCurrentState&
27   StudyCurrentState::operator=(const StudyCurrentState&) = default;
28 
29   StudyCurrentState&
30   StudyCurrentState::operator=(StudyCurrentState&&) = default;
31 
initialize(const StudyCurrentState::size_type psz)32   void StudyCurrentState::initialize(const StudyCurrentState::size_type psz){
33     this->u_1.clear();
34     this->u0.clear();
35     this->u1.clear();
36     this->u10.clear();
37     this->u_1.resize(psz,real(0));
38     this->u0.resize(psz,real(0));
39     this->u1.resize(psz,real(0));
40     this->u10.resize(psz,real(0));
41     this->s.clear();
42   } // end of StudyCurrentState::initialize
43 
update(const real dt)44   void StudyCurrentState::update(const real dt){
45     this->dt_1 = dt;
46     this->u_1  = this->u0;
47     this->u0   = this->u1;
48     this->u10  = this->u1;
49     for(auto& p: this->s){
50       auto& ss = *(p.second);
51       mtest::update(ss);
52     }
53   } // end of StudyCurrentState::update
54 
revert()55   void StudyCurrentState::revert(){
56     this->u1  = this->u0;
57     this->u10 = this->u0;
58     for(auto& p: this->s){
59       auto& ss = *(p.second);
60       mtest::revert(ss);
61     }
62   } // end of StudyCurrentState::revert
63 
64   StructureCurrentState&
getStructureCurrentState(const std::string & n)65   StudyCurrentState::getStructureCurrentState(const std::string& n)
66   {
67     auto p = this->s.find(n);
68     if(p==this->s.end()){
69       const auto ps = std::make_shared<StructureCurrentState>();
70       p = this->s.insert({n,ps}).first;
71     }
72     return *(p->second);
73   } // end of StudyCurrentState::getStructureCurrentState
74 
75   const StructureCurrentState&
getStructureCurrentState(const std::string & n) const76   StudyCurrentState::getStructureCurrentState(const std::string& n) const
77   {
78     const auto p = this->s.find(n);
79     tfel::raise_if(p==this->s.end(),
80 		   "StudyCurrentState::getStructureCurrentState: "
81 		   "no state associated to structure '"+n+"'");
82     return *(p->second);
83   }
84 
containsParameter(const std::string & n) const85   bool StudyCurrentState::containsParameter(const std::string& n) const{
86     return this->parameters.count(n)!=0;
87   } // end of StudyCurrentState::containsParameter
88 
89   void
throwUnknownParameterException(const std::string & n)90   StudyCurrentState::throwUnknownParameterException(const std::string& n){
91     tfel::raise("StudyCurrentState::throwUnknownParameterException:"
92 		"no parameter '"+n+"' declared");
93   }
94 
95   void
throwAlreadyDeclaredParameterException(const std::string & n)96   StudyCurrentState::throwAlreadyDeclaredParameterException(const std::string& n){
97     tfel::raise("StudyCurrentState::throwAlreadyDeclaredParameterException:"
98 		"parameter '"+n+"' already declared");
99   }
100 
containsEvolution(const std::string & n) const101   bool StudyCurrentState::containsEvolution(const std::string& n) const{
102     return this->evs.find(n)!=this->evs.end();
103   }
104 
addEvolution(const std::string & n,std::shared_ptr<Evolution> e)105   void StudyCurrentState::addEvolution(const std::string& n,
106 				       std::shared_ptr<Evolution> e){
107     auto p = this->evs.find(n);
108     if(p!=this->evs.end()){
109       tfel::raise("StudyCurrentState::getEvolution: "
110 		  "evolution '"+n+"' already defined");
111     }
112     this->evs[n]=e;
113   }
114 
115   Evolution&
getEvolution(const std::string & n)116   StudyCurrentState::getEvolution(const std::string& n){
117     auto p = this->evs.find(n);
118     if(p==this->evs.end()){
119       tfel::raise("StudyCurrentState::getEvolution: "
120 		  "no evolution named '"+n+"'");
121     }
122     return *(p->second);
123   }
124 
125   const Evolution&
getEvolution(const std::string & n) const126   StudyCurrentState::getEvolution(const std::string& n) const{
127     auto p = this->evs.find(n);
128     if(p==this->evs.end()){
129       tfel::raise("StudyCurrentState::getEvolution: "
130 		  "no evolution named '"+n+"'");
131     }
132     return *(p->second);
133   }
134 
135   StudyCurrentState::~StudyCurrentState() = default;
136 
137 } // end of namespace mtest
138